bookDetail.vue 11 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
<template>
  <div class="book-detail-page content-bg">
    <div class="modify-top"></div>
    <div class="book-detail">
      <div style="text-align: center;">
        <van-image width="220" height="220"
          src="https://lanhu.oss-cn-beijing.aliyuncs.com/SketchPngc434046fdf1f9499d251b280af2568ddbe64839799d00a9aee226edbeb710aed" />
      </div>
      <div class="book-intro">
        <p class="book-post">逃家小兔绘本</p>
        <div id="book-intro" :class="{ 'van-multi-ellipsis--l3': isToggle }">
          从前有一只小兔子,总是想要离家出走。有一天他对妈妈说:“我要跑走啦!”“如果你跑走了我就去追你,因为你是我的小宝贝呀!”妈妈说。
          一场爱的捉迷藏就此展开了
        </div>
        <div v-if="hasToggle">
          <div v-if="isToggle" @click="onToggle(false)" class="book-toggle-icon">展开&nbsp;
            <van-icon style="vertical-align: middle;" size="0.9rem" :name="icon_down" />
          </div>
          <div v-else @click="onToggle(true)" class="book-toggle-icon">折叠&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">
              作品演绎
              <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" />
                54个作品
              </div>
            </van-col>
          </van-row>
        </div>
        <div class="book-video-language">
          <van-row>
            <van-col span="6">
              <div @click="toggleLanguage" :class="[check_mandarin ? 'checked' : 'uncheck']">普通话</div>
            </van-col>
            <van-col span="6">
              <div @click="toggleLanguage" :class="[check_localism ? 'checked' : 'uncheck']">方言</div>
            </van-col>
            <van-col span="12" v-if="check_localism" @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="没有更多了" @load="onLoad">
          <template v-for="item in dataList" :key="item" style="height: 3rem;">
            <video-card :item="item"></video-card>
          </template>
        </van-list>
      </div>
    </div>
    <div style="height: 5rem;"></div>
    <div class="book-bar">
      <div @click="onSubscribe" class="text">
        <van-icon v-if="!is_subscribe" :name="icon_subscribed" size="1.25rem" style="margin: 0 auto;" />
        <van-icon v-else :name="icon_unsubscribe" size="1.25rem" style="margin: 0 auto;" />
        <span style="font-size: 0.85rem;">订阅</span>
      </div>
      <div class="button">
        <my-button @on-click="payFor" type="plain">爱心捐书</my-button>
      </div>
      <div class="button">
        <my-button @on-click="uploadVideo" type="primary">上传作品</my-button>
      </div>
    </div>
    <to-me @on-click="gotoMe()"></to-me>
  </div>

  <!-- 上传作品时,如果没有实名认证提示弹框 -->
  <van-overlay :show="showNotice" z-index="1000">
    <div class="wrapper" @click.stop>
      <div class="block">
        <div>
          <van-image width="100" height="100" :src="icon_notice" />
          <p style="margin: 1rem; font-size: 1.15rem; font-weight: bold; color: #222222;">温馨提示</p>
        </div>
        <div style="color: #333333;">
          <p>您还没有实名认证</p>
          <p>请点击 <van-icon :name="icon_me" /> 进行实名认证</p>
          <p>实名认证之后再上传</p>
        </div>
        <div style="margin: 3rem 0;">
          <my-button @on-click="closeNotice" type="primary">返回</my-button>
        </div>
      </div>
    </div>
  </van-overlay>
</template>

<script setup>
import dataList from '@/mock/video_list'

import MyButton from '@/components/MyButton/index.vue'
import VideoCard from '@/components/VideoCard/index.vue'

import icon_video from '@images/video.png'
import icon_up from '@images/icon-guanbi@2x.png'
import icon_down from '@images/icon-zhankai@2x.png'
import icon_subscribed from '@images/icon-dingyue01@2x.png'
import icon_unsubscribe from '@images/icon-dingyue02@2x.png'
import icon_me from '@images/icon-my@2x.png'
import icon_notice from '@images/que-tishi@2x.png'

import ToMe from '@/components/ToMe/index.vue'
import tools from '@/common/tool'
import { ref, reactive, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from '@/utils/axios';
import $ from 'jquery'
import _ from 'lodash'
import { Toast } from 'vant';
const $route = useRoute();
const $router = useRouter();

const items = reactive([])

const gotoMe = () => {
  console.warn('跳转我的地址');
}

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

const onToggle = (v) => { // 展开/折叠
  isToggle.value = v
}

// 切换视频语言
const check_mandarin = ref(true);
const check_localism = ref(false);
const chooseLanguage = ref({ text: '普通话', val: '00' }); // 默认选中普通话
const toggleLanguage = () => {
  check_mandarin.value = !check_mandarin.value;
  check_localism.value = !check_localism.value;
  // 修改默认语言绑定数据
  if (check_localism.value) {
    chooseLanguage.value = { text: columns[0]['text'], val: columns[0]['val'] }
  } else {
    chooseLanguage.value = { text: '普通话', val: '00' };
  }
}
// 方言选择项
const columns = [
  { text: '所有方言', val: '00' },
  { text: '沪语', val: '01' },
  { text: '粤语', val: '02' },
];

const showPicker = ref(false);

const onConfirm = ({ selectedOptions }) => {
  showPicker.value = false;
  chooseLanguage.value = {
    text: selectedOptions[0].text,
    val: selectedOptions[0].val
  }
};

onMounted(() => {
  // 判断是否显示简介的展开图标
  hasToggle.value = tools.hasEllipsis('book-intro');
  for (let index = 0; index < 20; index++) {
    items.push({
      id: index,
      avatar: 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg'
    })
  }
})

// 处理书籍下作品列表
const list = ref([]);
const loading = ref(false);
const finished = ref(false);

const onLoad = () => {
  // 异步更新数据
  // setTimeout 仅做示例,真实场景中一般为 ajax 请求
  setTimeout(() => {
    for (let i = 0; i < 20; i++) {
      list.value.push(list.value.length + 1);
    }

    // 加载状态结束
    loading.value = false;

    // 数据全部加载完成
    if (list.value.length >= 100) {
      finished.value = true;
    }
  }, 1000);
};

// 书籍订阅
let is_subscribe = ref(false);
const onSubscribe = () => {
  is_subscribe.value = !is_subscribe.value
}

// 爱心捐书
const payFor = () => {
  console.warn('弹出框');
}

// 上传作品
const showNotice = ref(false)
const closeNotice = () => {
  showNotice.value = false;
}
const uploadVideo = () => {
  // 如果没有实名认证需要提示用户实名认证
  showNotice.value = true;
  // 实名认证之后直接跳转上传页面
}
</script>

<script>
import mixin from 'common/mixin';

function transCaseList(url, pic) {
  return { url, pic }
}

export default {
  mixins: [mixin.init],
  data() {
    return {

    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      _.each(this.dataList, item => {
        let video = item.video && item.video.url ? item.video.url : 'http://static.smartisanos.cn/common/video/t1-ui.mp4';
        let cover = item.cover && item.cover.url ? item.cover.url : 'http://static.smartisanos.cn/pr/img/video/video_03_cc87ce5bdb.jpg';
        item.options = { video: transCaseList(video, cover), autoplay: false, preload: 'none' }
      })
    }
  }
}
</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;
      }

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

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

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

    .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: #F9D95C;
        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-video-list {
      // height: 20rem;
      // overflow: scroll;
    }
  }

  .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;
}

.block {
  width: 80%;
  // height: 25rem;
  background-color: #fff;
  border-radius: 10px;
  padding: 1rem;
}
</style>