bookDetail.vue 13.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
<template>
  <div class="book-detail-page content-bg">
    <div class="modify-top" />
    <div style="height: 1.5rem;" />
    <div class="book-detail">
      <div style="text-align: center;">
        <van-image width="220" height="220" fit="contain" lazy-load :src="bookInfo.cover" />
      </div>
      <div class="book-intro">
        <p class="book-post">{{ bookInfo.name }}</p>
        <div id="book-intro" :class="{ 'van-multi-ellipsis--l3': isToggle }">{{ bookInfo.note }}</div>
        <div v-if="hasToggle">
          <div v-if="isToggle" class="book-toggle-icon" @click="isToggle = false">
            展开&nbsp;
            <van-icon style="vertical-align: middle;" size="0.9rem" :name="icon_down" />
          </div>
          <div v-else class="book-toggle-icon" @click="isToggle = true">
            折叠&nbsp;
            <van-icon style="vertical-align: middle;" size="0.9rem" :name="icon_up" />
          </div>
        </div>
      </div>

      <van-sticky>
        <div class="book-video-title">
          <van-row>
            <van-col span="12">
              <span class="bg-gradient">作品演绎</span>
              <!-- <div style="background-color: #F9D95C; width: 70px; height: 4px;"></div> -->
            </van-col>
            <van-col span="12">
              <div style="font-size: 1rem; color: #999999; text-align: right;">
                <van-icon :name="icon_video" />
                {{ bookInfo.total ? bookInfo.total : 0 }}个作品
              </div>
            </van-col>
          </van-row>
        </div>
        <div class="book-video-language">
          <van-row>
            <van-col span="6">
              <div :class="[checkMandarin ? 'checked' : 'uncheck']" @click="toggleLanguage('mandarin')">普通话</div>
            </van-col>
            <van-col span="6">
              <div :class="[checkLocalism ? 'checked' : 'uncheck']" @click="toggleLanguage('localism')">方言</div>
            </van-col>
            <van-col v-if="checkLocalism" span="12" @click="showPicker = true">
              <div class="choose-wrapper">
                <div class="text">
                  &nbsp;{{ chooseLanguage.text }}
                </div>
                <div class="icon">
                  <van-icon name="arrow-down" />&nbsp;
                </div>
              </div>
            </van-col>
          </van-row>
          <van-popup v-model:show="showPicker" round position="bottom">
            <van-picker 
              :columns="columns" :columns-field-names="{ text: 'text', value: 'val', children: 'children' }" @cancel="showPicker = false" @confirm="onConfirm"
            />
          </van-popup>
        </div>
      </van-sticky>

      <div class="book-video-list">
        <van-list v-model:loading="loading" :finished="finished" :finished-text="finishedTextStatus ? '没有更多了' : ''" @load="onLoad">
          <template v-for="item in prod_list" :key="item">
            <video-card :item="item">
              <template #bookDetailSub>
                <div style="color: #999999; padding: 0px 1rem 0.5rem;" @click="goToDetail(item)">
                  {{ item.kg_name }} | {{ item.localism_type }}
                </div>
              </template>
            </video-card>
          </template>
        </van-list>
      </div>
      <div style="height: 2rem;" />
      <van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无作品信息" />
    </div>
    <div style="height: 6rem;" />
    <div class="book-bar">
      <div class="text" @click="onSubscribe">
        <template v-if="!bookInfo.is_subscribe">
          <van-icon :name="icon_subscribed" size="1.25rem" style="margin: 0 auto;" />
          <span style="font-size: 0.85rem;">订阅</span>
        </template>
        <template v-else>
          <van-icon :name="icon_unsubscribe" size="1.25rem" style="margin: 0 auto;" />
          <span style="font-size: 0.85rem;">已订阅</span>
        </template>
      </div>
      <div class="button">
        <my-button type="primary" @on-click="uploadVideo">上传作品</my-button>
      </div>
      <div class="button">
        <my-button type="plain" @on-click="toDonate">爱心助力</my-button>
      </div>
    </div>
    <shortcut-fixed type="C" :item="shortcutItem" />
  </div>

  <!-- 上传时,如果没有默认儿童提示弹框, 如果没有实名认证提示弹框 -->
  <notice-overlay :show="showNotice" :text="noticeText" @on-submit="onSubmit" @on-close="onClose">
    <div style="color: #333333;">
      <div v-html="noticeHtml" />
    </div>
  </notice-overlay>

  <donate-flower :user-type="donateType" :show-popup="showDonate" :item="donateInfo" @on-close="closeDonate" />

  <van-overlay :show="show" z-index="9999">
    <div class="wrapper" @click.stop>
      <van-loading size="24px">跳转中...</van-loading>
    </div>
  </van-overlay>
</template>

<script setup>
import { ref, onActivated, nextTick, onMounted, computed } from 'vue'
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
import { Cookies, _, storeToRefs, mainStore, Toast, hasEllipsis } from '@/utils/generatePackage'
import { MyButton, VideoCard, NoticeOverlay, DonateFlower, ShortcutFixed } from '@/utils/generateModules'
import { icon_video, icon_up, icon_down, icon_subscribed, icon_unsubscribe, no_image } from '@/utils/generateIcons'
import { JSJ_FORM_C } from '@/constant'
import { useVideoList, useDefaultPerf, useShortcutBar, useScrollTop } from '@/composables';
import { addSubscribeAPI } from '@/api/C/book.js'
import { prepareDonateAPI } from '@/api/C/donate.js'

const { shortcutItem } = useShortcutBar(['home', 'me']); // 配置快捷跳转条
const { resetScrollTop } = useScrollTop(); // 页面滚动恢复
resetScrollTop('scrollTop');

const $route = useRoute();
const $router = useRouter();

const { toggleLanguage, onLoad, columns, prod_list, finished, loading, bookInfo, showPicker, checkLocalism, checkMandarin, onConfirm, chooseLanguage, finishedTextStatus, emptyStatus } = useVideoList($route);
const { userInfo } = useDefaultPerf($route.query.id);

const donateInfo = ref({})
const userType = Cookies.get('userType')
// 判断是访客进入还是幼儿园进入
const donateType = computed(() => {
  return userType === 'client' ? 'K' : 'V';
})
onMounted(async () => {
  const { data } = await prepareDonateAPI({ kg_id: $route.query.kg_id });
  donateInfo.value = data;
})

// 判断是否显示简介的展开图标
const hasToggle = ref(false); // 判断是否有展开文字,默认没有
const isToggle = ref(true); // 判断展开状态,默认展开

nextTick(() => {
  // 判断是否显示简介的展开图标
  hasToggle.value = hasEllipsis('book-intro');
})

/**
 * 书籍订阅
 */
const onSubscribe = async () => {
  const { msg } = await addSubscribeAPI({ book_id: $route.query.id });
  if (msg === 'add subscribe OK') {
    bookInfo.value.is_subscribe = true;
    Toast.success('订阅成功')
  } else {
    bookInfo.value.is_subscribe = false;
    Toast.success('取消订阅')
  }
}

/*************** 捐书模块START ***************/

// 弹出捐赠弹框模块
const showDonate = ref(false);

const toDonate = () => {
  showDonate.value = true;
}

const closeDonate = (v) => {
  showDonate.value = v;
}
/*******************************************/


/**
 * 上传作品回调
 */

// 不能上传提示原因弹框
const showNotice = ref(false)
const onClose = () => { // 关闭提示框回调
  showNotice.value = false;
}
// 跳转个人中心
const onSubmit = () => {
  $router.push({
    path: '/me/index'
  });
}

const noticeText = ref('')
const noticeHtml = ref('')
const show = ref(false); // 跳转等待提示
const uploadVideo = () => {
  if (userInfo.value.can_upload === 1) { // 可以上传
    show.value = true;
    // x_field_1 是金数据表单传入的参数,家长上传的格式为:user_id-book_id-perf_id,perf_id是当前缺省的儿童id
    const str = `${userInfo.value.user_id}-${$route.query.id}-${userInfo.value.perf_id}`;
    // 已读隐私条例,直接跳转上传页面
    // $router.push({
    //   path: '/client/privacyNotice',
    //   query: {
    //     str
    //   }
    // })
    if (Cookies.get('privacy_notice')) {
      location.href = `${JSJ_FORM_C}?x_field_1=${str}`;
      // BUG: 关闭loading临时处理
      setTimeout(() => {
        show.value = false;
      }, 2000);
    } else { // 跳转个人隐私阅读
      $router.push({
        path: '/client/privacyNotice',
        query: {
          str
        }
      })
    }
  } else if (userInfo.value.can_upload === -1) { // 未实名认证
    showNotice.value = true;
    noticeText.value = '前往认证'
    noticeHtml.value = `
      <p>您还没有实名认证</p>
      <p>请前往个人中心进行实名认证</p>
    `
  } else if (userInfo.value.can_upload === -2) { // 没有默认儿童
    showNotice.value = true;
    noticeText.value = '前往新增'
    noticeHtml.value = `
      <p>您还没有新增儿童</p>
      <p>请前往个人中心进行新增</p>
    `
  }
}

/****************** keepAlive 模块 *******************/

// TAG: keepAlive 缓存页面
const store = mainStore();
/**
 * 大菠萝的修改数据方式 3种
 */
// 简单数据修改
// store.keepPages.push($route.meta.name);
// 多条数据修改
store.$patch((state) => {
  state.keepPages = [...state.keepPages, $route.meta.name];
})
// 通过action修改
// store.keepThisPage($route.meta.name);
// 调用返回其他store的数据
// store.getTestStoreList

onActivated(() => { // keepAlive 重置后执行回调
  // TAG: pinia应用,动态刷新数据
  // 处理数据未刷新数据显示问题
  const { video_detail } = storeToRefs(store);
  // 如果作品信息有变化及时修正
  const arr = ref([]);
  _.each(prod_list.value, (item) => {
    if (item.id === video_detail.value.id) {
      item = video_detail.value
    }
    arr.value.push(item);
  })
  // 触发更新
  prod_list.value = arr.value;
  // 滚动恢复
  resetScrollTop('scrollTop');

  // 更新页面名称,因为不刷新副作用~
  document.title = $route.meta.title;
});

onBeforeRouteLeave(() => {
  // 监听记录滚动位置
  store.changeScrollTop(window.scrollY)
})

/****************** 视频组件相关操作 *******************/
const goToDetail = (v) => { // 跳转作品详情页
  $router.push({
    path: '/client/videoDetail',
    query: {
      prod_id: v.id,
      book_id: v.book_id,
      type: v.type, // 特殊标识,判断入口 为keepAlive使用
      perf_id: v.perf_id
    }
  });
}
/*****************************************************/
</script>

<style lang="less" scoped>
@import url('@css/content-bg.less');

.book-detail-page {
  // overflow: auto;

  .book-detail {
    margin: 1rem;
    // margin-top: 1.25rem;
    margin-top: 0;
    padding-top: 1rem;
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 1);
    box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.13);

    .book-intro {
      padding: 1rem;

      .book-post {
        color: #222222;
        font-size: 1.25rem;
        font-weight: bold;
        margin-bottom: 0.5rem;
      }

      #book-intro {
        color: #333333;
        margin-top: 0.25rem;
        line-height: 1.7;
      }

      .book-toggle-icon {
        text-align: right;
        color: #713610;
        font-size: 1rem;
      }
    }

    .book-video-title {
      background-color: #F7F7F7;
      padding: 1rem 1.5rem;

      .bg-gradient {
        background: linear-gradient(@base-color, @base-color) no-repeat;
        /*调整下划线的宽度占百分之百  高度是3px */
        background-size: 100% 3px;
        /* 调整下划线的起始位置 左侧是0 上边是1.15em */
        background-position: 0 1rem;
      }
    }

    .book-video-language {
      padding: 1rem;
      background-color: white;

      .uncheck {
        background: #F7F7F7;
        border-radius: 15px;
        padding: 0.5rem;
        text-align: center;
        color: #222222;
        margin: 0 0.25rem;
      }

      .checked {
        background: @base-color;
        border-radius: 15px;
        padding: 0.5rem;
        text-align: center;
        color: #222222;
        margin: 0 0.25rem;
      }

      .choose-wrapper {
        background: #F7F7F7;
        border-radius: 15px;
        padding: 0.5rem;
        text-align: center;
        color: #B0B0B0;
        margin: 0 0.25rem;

        .text {
          display: inline-block;
          text-align: left;
          width: 80%;
        }

        .icon {
          display: inline-block;
          text-align: right;
          width: 20%;
        }
      }
    }
  }

  .book-bar {
    z-index: 999;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    box-sizing: content-box;
    background-color: white;
    padding: 1rem;

    .text {
      display: flex;
      flex-direction: column;
      justify-content: center;
      min-width: 3rem;
      color: #713610;
      text-align: center;
    }

    .button {
      display: flex;
      flex-direction: column;
      justify-content: center;
      flex: 1;
      padding: 0 0.5rem;
    }
  }
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: auto;
  text-align: center;
}
</style>