cm-product-doc.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <view
  3. class="product-doc "
  4. :class="{ hasBottom: TipStatus }"
  5. :style="{ paddingBottom: isIphoneX && TipStatus ? '60rpx' : 0 }"
  6. >
  7. <view class="category">
  8. <view class="category-title">图片资料</view>
  9. <view class="content">
  10. <view class="cm-none" v-if="imageArchiveList.length === 0">暂无相关资料</view>
  11. <template v-else>
  12. <view class="section" v-for="(item, index) in imageArchiveList" :key="index">
  13. <view class="cm-title">{{ item.title }}</view>
  14. <view class="cm-time">{{ $api.easyFormatData(item.addTime) }}</view>
  15. <view class="cm-img-list cm-list">
  16. <template v-if="item.imageList">
  17. <image
  18. :src="image.url"
  19. @click="previewImage(i, item.imageList, item)"
  20. mode="aspectFill"
  21. v-for="(image, i) in imageFormat(item.imageList, index)"
  22. :key="i"
  23. :style="image.style"
  24. ></image>
  25. </template>
  26. <template v-else>
  27. <image
  28. :src="defaultImage"
  29. mode="aspectFill"
  30. v-for="i in item.imageNum"
  31. :key="i"
  32. @click="checkPermission"
  33. ></image>
  34. </template>
  35. </view>
  36. </view>
  37. </template>
  38. </view>
  39. </view>
  40. <view class="category">
  41. <view class="category-title">视频资料</view>
  42. <view class="content">
  43. <view class="cm-none" v-if="videoArchiveList.length === 0">暂无相关资料</view>
  44. <template v-else>
  45. <view class="section" v-for="(item, index) in videoArchiveList" :key="index">
  46. <view class="cm-title">{{ item.title }}</view>
  47. <view class="cm-time">{{ $api.easyFormatData(item.addTime) }}</view>
  48. <view class="cm-video-list">
  49. <video
  50. class="cm-video"
  51. ref="myVideo"
  52. :id="'myVideo' + index"
  53. :src="myDecrypt([item.fileUrl])[0]"
  54. :style="videoStyle['myVideo' + index]"
  55. controls
  56. show-fullscreen-btn
  57. show-mute-btn
  58. play-btn-position="center"
  59. @timeupdate="onPlayVideo($event)"
  60. @play="handlePlayer('myVideo' + index, item)"
  61. v-if="item.fileUrl"
  62. @loadedmetadata="loadedmetadata"
  63. ></video>
  64. <view class="cm-video-section" v-else>
  65. <image class="cm-video-cover" :src="videoCover"></image>
  66. <text class="cm-player-btn" @click="checkPermission()"></text>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. </view>
  72. </view>
  73. <view class="category cm-file">
  74. <view class="category-title">文件资料</view>
  75. <view class="content">
  76. <view class="cm-none" v-if="fileArchiveList.length === 0">暂无相关资料</view>
  77. <template v-else>
  78. <view class="section" v-for="(item, index) in fileArchiveList" :key="index">
  79. <image
  80. src="https://static.caimei365.com/app/img/icon2/PDF-app.png"
  81. v-if="/\.pdf/.test(item.fileName)"
  82. ></image>
  83. <image
  84. src="https://static.caimei365.com/app/img/icon2/DOC-app.png"
  85. v-else-if="/\.doc/.test(item.fileName)"
  86. ></image>
  87. <image src="https://static.caimei365.com/app/img/icon2/PPT-app.png" v-else></image>
  88. <view class="cm-desc">
  89. <view class="cm-title">{{ item.title }}</view>
  90. <view class="cm-bottom">
  91. <view class="cm-time">{{ $api.easyFormatData(item.addTime) }}</view>
  92. <view class="cm-preview" @click="previewFile(item)">预览文件</view>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. </view>
  98. </view>
  99. <view
  100. class="cm-login"
  101. :class="{ maxBottom: !bottom && isIphoneX }"
  102. :style="{ bottom: bottom }"
  103. v-if="TipStatus && tipStatus"
  104. >
  105. <text>{{ TipStatus.text }}</text>
  106. <view class="cm-btn" @click="nextAction(TipStatus.redirect)">{{ TipStatus.btn }}</view>
  107. </view>
  108. <tui-modal
  109. :show="showModal"
  110. :content="TipStatus.text"
  111. shape="circle"
  112. :button="modalButton"
  113. :fadeIn="true"
  114. @click="handleModalClick"
  115. ></tui-modal>
  116. </view>
  117. </template>
  118. <script>
  119. import { mapState } from 'vuex'
  120. import CryptoJS from '@/utils/crypto-js/crypto.js'
  121. export default {
  122. props: {
  123. product: {
  124. type: Object,
  125. default: () => {}
  126. },
  127. archiveId: {
  128. type: Number,
  129. default: 0
  130. },
  131. bottom: {
  132. type: String,
  133. default: ''
  134. }
  135. },
  136. data() {
  137. return {
  138. userId: -1,
  139. prevVideoId: '',
  140. currentVideoId: '',
  141. videoContexts: [],
  142. modalButton: [
  143. {
  144. text: '取消',
  145. type: 'gray',
  146. plain: true //是否空心
  147. },
  148. {
  149. text: '确认',
  150. customStyle: {
  151. color: '#fff',
  152. bgColor: 'linear-gradient(90deg, #F28F31 0%, #FF5B00 100%)'
  153. },
  154. plain: false
  155. }
  156. ],
  157. showModal: false,
  158. //用户信息相关
  159. permission: 5, //用户权限 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  160. imageArchiveList: [], // 图片资料列表
  161. videoArchiveList: [], // 视频资料列表
  162. fileArchiveList: [], // 文件资料列表
  163. defaultImage: 'https://static.caimei365.com/app/img/icon2/PC-default.png', // 默认图片
  164. videoCover: 'https://static.caimei365.com/app/img/icon2/video-cover.png', //默认视频封面
  165. videoStyle: {},
  166. timer: null,
  167. tipStatus: true, // 状态
  168. userInfo: {}, // 用户信息
  169. num: 0
  170. }
  171. },
  172. computed: {
  173. ...mapState(['isIphoneX']),
  174. //资料查看状态提示
  175. TipStatus() {
  176. // 资料权限
  177. const statusText = [
  178. false, // 正常访问
  179. { text: '请登录后查看!', btn: '去登录', redirect: '/pages/login/login' },
  180. { text: '请升级成为会员机构后方可查看!', btn: '去升级', redirect: '/pages/login/apply' },
  181. { text: '请升级成为医美会员机构后方可查看!', btn: '去升级', redirect: '/pages/login/apply' },
  182. { text: '需抵扣100采美豆方可查看!', btn: '去查看', redirect: 10 },
  183. { text: '无权限查看!', btn: '确认' }
  184. ]
  185. // 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  186. return statusText[this.permission]
  187. }
  188. },
  189. watch: {
  190. TipStatus(val) {
  191. if (this.TipStatus) {
  192. this.timer = setTimeout(() => {
  193. this.tipStatus = false
  194. clearTimeout(this.timer)
  195. }, 10000)
  196. }
  197. this.$emit('tipStatus', this.TipStatus)
  198. }
  199. },
  200. created() {
  201. this.userId = uni.getStorageSync('userInfo').userId || -1
  202. this.getDetail()
  203. this.userInfo = uni.getStorageSync('userInfo')
  204. console.log(uni.getStorageSync('userInfo'))
  205. },
  206. methods: {
  207. // 获取商品资料详情
  208. getDetail() {
  209. this.BeautyArchive.GetProdcutArchiveDetails({
  210. userId: this.userId,
  211. archiveId: this.archiveId
  212. }).then(res => {
  213. this.imageArchiveList = res.data.imageArchiveList
  214. this.videoArchiveList = res.data.videoArchiveList
  215. this.fileArchiveList = res.data.fileArchiveList
  216. this.permission = res.data.permission
  217. this.imageArchiveList.forEach((item, index) => {
  218. if (item.imageNum !== item.imageList.length) {
  219. this.num = item.imageNum - item.imageList.length
  220. for (let i = 0; i < this.num; i++) {
  221. item.imageList.push(this.defaultImage)
  222. }
  223. }
  224. })
  225. this.videoArchiveList.forEach(item => {
  226. item.fileUrl = decodeURIComponent(item.fileUrl)
  227. })
  228. // console.log(res.data.videoArchiveList)
  229. })
  230. },
  231. //采美豆抵扣
  232. searchArchiveByBean() {
  233. this.BeautyArchive.SearchArchiveByBeans({
  234. userId: this.userId,
  235. archiveId: this.archiveId
  236. })
  237. .then(res => {
  238. uni.showToast({
  239. duration: 1500,
  240. title: res.msg
  241. })
  242. setTimeout(() => {
  243. //刷新资料列表
  244. this.getDetail()
  245. }, 1500)
  246. })
  247. .catch(err => {
  248. uni.showToast({
  249. icon: 'none',
  250. duration: 1500,
  251. title: err.msg
  252. })
  253. })
  254. },
  255. // 获取视频源信息
  256. loadedmetadata(e) {
  257. // 获取视频长宽
  258. const w = e.detail.width //视频真实宽度
  259. const h = e.detail.height //视频真实高度
  260. let rw = 0 //视频展示宽度
  261. let rh = 0 //视频展示宽度
  262. // 视频宽大于等于高时
  263. if (w >= h) {
  264. rw = 702
  265. rh = (rh * h) / w
  266. } else {
  267. rw = 400
  268. rh = (rw * h) / w
  269. }
  270. // 使用set向videoStyle添加样式信息
  271. this.$set(this.videoStyle, e.currentTarget.id, `width:${rw}rpx;height:${rh}rpx;`)
  272. },
  273. // 视频播放
  274. handlePlayer(id, info) {
  275. // if (this.checkPermission()) {
  276. // this.handleStop(id)
  277. // return
  278. // }
  279. console.log('视频播放id', id)
  280. if (info) {
  281. this.GetStatisticsAddPv(1, info.archiveContentId)
  282. }
  283. // 如果点击同一个播放器,就
  284. if (this.prevVideoId === id) return
  285. // this.handleFullScreen(id) // 点击播放时全屏
  286. // 暂停上一个播放器
  287. this.handelPause(this.prevVideoId)
  288. // 保存当前播放器id
  289. this.prevVideoId = id
  290. },
  291. // 监听video时长
  292. onPlayVideo(e) {
  293. this.checkPermission()
  294. },
  295. // 开始播放
  296. handelPlay(id) {
  297. if (!id) return
  298. const vContext = uni.createVideoContext(id, this)
  299. vContext.play()
  300. },
  301. // 暂停播放
  302. handelPause(id) {
  303. if (!id) return
  304. const vContext = uni.createVideoContext(id, this)
  305. vContext.pause()
  306. },
  307. // 停止视频
  308. handleStop(id) {
  309. if (!id) return
  310. const vContext = uni.createVideoContext(id, this)
  311. vContext.stop()
  312. },
  313. // 进入全屏
  314. handleFullScreen(id) {
  315. if (!id) return
  316. const vContext = uni.createVideoContext(id, this)
  317. vContext.requestFullScreen()
  318. },
  319. // 浏览记录
  320. async GetStatisticsAddPv(type, authorId) {
  321. try {
  322. await this.BeautyArchive.GetStatisticsAddPv({ type, authorId })
  323. console.log('记录成功')
  324. } catch (e) {
  325. //TODO handle the exception
  326. }
  327. },
  328. // 预览图片
  329. previewImage(index, previewImageList, info) {
  330. if (info) {
  331. this.GetStatisticsAddPv(1, info.archiveContentId)
  332. }
  333. if (this.checkPermission()) return
  334. const that = this
  335. uni.previewImage({
  336. current: index,
  337. indicator: 'number',
  338. urls: previewImageList,
  339. loop: true,
  340. success() {
  341. that.$emit('previewImage', true)
  342. }
  343. })
  344. },
  345. //用户权限校验拦截
  346. checkPermission() {
  347. //permission:查看权限:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  348. const _self = this
  349. // 如果 TipStatus 返回false 就放行
  350. if (!_self.TipStatus) return 0
  351. this.modalButton[1].text = this.TipStatus.btn
  352. this.showModal = true
  353. return -1
  354. },
  355. myDecrypt(
  356. word,
  357. iv = CryptoJS.enc.Utf8.parse('caimei--20240103'),
  358. key = CryptoJS.enc.Utf8.parse('caimei--20240103')
  359. ) {
  360. if (word) {
  361. return word.map(e => {
  362. if (e) {
  363. const encryptedHexStr = CryptoJS.enc.Base64.parse(e)
  364. const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
  365. const decrypt = CryptoJS.AES.decrypt(srcs, key, {
  366. iv,
  367. mode: CryptoJS.mode.CBC,
  368. padding: CryptoJS.pad.NoPadding
  369. })
  370. const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
  371. return decryptedStr.toString()
  372. } else return ''
  373. })
  374. } else return []
  375. },
  376. // modal 按钮点击
  377. handleModalClick(e) {
  378. // 点击确认按钮
  379. if (e.index === 1) {
  380. this.showModal = false
  381. this.nextAction(this.TipStatus.redirect) //执行下一步
  382. } else {
  383. this.showModal = false
  384. }
  385. },
  386. //图片列表处理
  387. imageFormat(list, index) {
  388. const imageList = []
  389. if (list.length > 2) {
  390. list.forEach((item, index) => {
  391. imageList.push({ url: item, style: '' })
  392. })
  393. }
  394. if (list.length === 1) {
  395. try {
  396. const strArr = list[0]
  397. .split('?')[1]
  398. .replace(/\&|\=/g, '-')
  399. .split('-')
  400. const w = strArr[1] // 图片长
  401. const h = strArr[3] // 图片高
  402. let style = ''
  403. if (w > h) {
  404. style = `width:600rpx;height:${(600 / w) * h}rpx`
  405. } else {
  406. style = `height:600rpx;width:${(600 * w) / h}rpx`
  407. }
  408. imageList.push({ url: list[0], style: style })
  409. } catch (e) {
  410. console.error(
  411. '图片链接格式不正确,返回未处理图片,请设置正确的链接:http://image/text.png?width=xx&height=xx'
  412. )
  413. imageList.push({ url: list[0], style: '' })
  414. }
  415. }
  416. if (list.length === 2) {
  417. const style = 'width:300rpx;height:300rpx;'
  418. imageList.push({ url: list[0], style })
  419. imageList.push({ url: list[1], style })
  420. }
  421. return imageList
  422. },
  423. // 点击按钮后要做的事
  424. nextAction(redirect) {
  425. const _self = this
  426. if (typeof redirect == 'string') {
  427. // 跳转链接
  428. this.$api.navigateTo(redirect)
  429. }
  430. if (redirect === 10) {
  431. this.searchArchiveByBean()
  432. }
  433. },
  434. // 文件预览
  435. previewFile(file) {
  436. if (this.checkPermission()) return
  437. const link = this.myDecrypt([file.fileUrl])[0].split('?')[0] || ''
  438. const domainUrl = process.env.NODE_ENV === 'development' ? 'https://material-b.caimei365.com' : 'https://material.caimei365.com'
  439. const url = `${domainUrl}/preview?t=3&url=${link}&isSp=1`
  440. uni.setStorageSync('databaseurl', url)
  441. console.log(link, url)
  442. uni.navigateTo({
  443. url: `/pages/h5/article/path?databaseurl=1`
  444. })
  445. },
  446. // 打开文档
  447. openDocument(file) {
  448. uni.showLoading({
  449. title: '加载中'
  450. })
  451. if (this.permission !== 0) {
  452. this.$api.navigateTo(
  453. `/pages/goods/goods-file-preview?userId=${this.userId}&archiveId=${this.archiveId}&permission=${
  454. this.permission
  455. }&fileName=${file.fileName}`
  456. )
  457. return
  458. }
  459. // 获取文件后缀
  460. const index = file.fileName.lastIndexOf('.')
  461. const suffix = file.fileName.substring(index + 1)
  462. // 下载文件
  463. uni.downloadFile({
  464. url: file.fileUrl,
  465. success(res) {
  466. const filePath = res.tempFilePath
  467. console.log(filePath)
  468. console.log(file, res, '文件数据')
  469. // 打开文件
  470. uni.openDocument({
  471. filePath: filePath,
  472. fileType: suffix,
  473. showMenu: true,
  474. success(res) {
  475. console.log(res)
  476. uni.showToast({
  477. icon: 'success',
  478. title: '打开成功',
  479. duration: 1200
  480. })
  481. uni.hideLoading()
  482. },
  483. fail(err) {
  484. if (err.errMsg.indexOf('fail filetype not supported')) {
  485. uni.showModal({
  486. content: '不支持的文件预览',
  487. cancelColor: '#666',
  488. confirmColor: '#FF5B00'
  489. })
  490. }
  491. uni.hideLoading()
  492. }
  493. })
  494. },
  495. fail(err) {
  496. uni.showToast({
  497. title: JSON.stringify(err),
  498. icon: 'none',
  499. duration: 5000
  500. })
  501. uni.hideLoading()
  502. }
  503. })
  504. }
  505. }
  506. }
  507. </script>
  508. <style lang="scss" scoped>
  509. .product-doc {
  510. background: #f7f7f7;
  511. }
  512. .hasBottom {
  513. padding-bottom: 90rpx;
  514. }
  515. .cm-login {
  516. position: fixed;
  517. left: 24rpx;
  518. bottom: 115rpx; // 包含商品导航
  519. display: flex;
  520. justify-content: space-between;
  521. align-items: center;
  522. padding: 0 32rpx;
  523. width: 702rpx;
  524. height: 90rpx;
  525. background: #ffe6dc;
  526. border-radius: 16px;
  527. box-sizing: border-box;
  528. z-index: 9;
  529. &.maxBottom {
  530. bottom: -100rpx;
  531. z-index: 999;
  532. animation: permiMove 0.3s ease-in-out;
  533. animation-fill-mode: forwards;
  534. }
  535. text {
  536. font-size: 26rpx;
  537. color: #ff5b00;
  538. }
  539. .cm-btn {
  540. width: 136rpx;
  541. height: 48rpx;
  542. background: #ff5b00;
  543. border-radius: 28px;
  544. font-size: 26rpx;
  545. text-align: center;
  546. line-height: 48rpx;
  547. color: #ffffff;
  548. }
  549. }
  550. .category {
  551. padding: 0 24rpx;
  552. margin-bottom: 20rpx;
  553. background: #fff;
  554. .cm-video-section {
  555. position: relative;
  556. width: 702rpx;
  557. height: 402rpx;
  558. .cm-video-cover {
  559. width: 702rpx;
  560. height: 402rpx;
  561. }
  562. .cm-player-btn {
  563. position: absolute;
  564. left: 50%;
  565. top: 50%;
  566. transform: translate(-50%, -50%);
  567. z-index: 5;
  568. width: 56rpx;
  569. height: 56rpx;
  570. background: url(https://static.caimei365.com/app/img/icon2/H5-plalyer.png) center no-repeat;
  571. background-size: 56rpx 56rpx;
  572. }
  573. }
  574. .category-title {
  575. padding-top: 24rpx;
  576. padding-bottom: 8rpx;
  577. font-size: 28rpx;
  578. font-weight: 500;
  579. color: #333333;
  580. border-bottom: 1px solid #f0f0f0;
  581. }
  582. .cm-none {
  583. height: 37rpx;
  584. margin: 24rpx 0 0 0;
  585. padding-bottom: 48rpx;
  586. font-size: 26rpx;
  587. font-weight: 400;
  588. line-height: 37rpx;
  589. color: #333333;
  590. }
  591. &.cm-file {
  592. .section {
  593. display: flex;
  594. justify-content: space-between;
  595. align-items: center;
  596. image {
  597. width: 88rpx;
  598. height: 88rpx;
  599. }
  600. .cm-title {
  601. height: 74rpx;
  602. }
  603. .cm-desc {
  604. width: 582rpx;
  605. }
  606. .cm-bottom {
  607. display: flex;
  608. justify-content: space-between;
  609. align-items: center;
  610. padding: 16rpx 0 0;
  611. .cm-preview {
  612. font-size: 26rpx;
  613. font-weight: 400;
  614. color: #ff5b00;
  615. }
  616. .cm-time {
  617. padding: 0;
  618. }
  619. }
  620. }
  621. }
  622. .section {
  623. padding-bottom: 24rpx;
  624. border-bottom: 1px solid #f0f0f0;
  625. &:last-child {
  626. border-bottom: 0;
  627. }
  628. .cm-title {
  629. display: -webkit-box;
  630. max-height: 74rpx;
  631. margin-top: 24rpx;
  632. font-size: 26rpx;
  633. font-weight: 400;
  634. line-height: 1.5;
  635. color: #333333;
  636. -webkit-box-orient: vertical;
  637. -webkit-line-clamp: 2;
  638. overflow: hidden;
  639. word-break: break-all;
  640. text-align: justify;
  641. }
  642. .cm-time {
  643. padding: 8rpx 0;
  644. font-size: 22rpx;
  645. font-weight: 400;
  646. color: #b2b2b2;
  647. }
  648. .cm-img-list {
  649. display: grid;
  650. grid-template-columns: repeat(3, 1fr);
  651. &.cm-list {
  652. image {
  653. width: 210rpx;
  654. height: 210rpx;
  655. margin: 18rpx 18rpx 0 0;
  656. box-sizing: border-box;
  657. border-radius: 6rpx;
  658. border: 1px solid #e1e1e1;
  659. &:nth-child(4n) {
  660. margin-right: 0;
  661. }
  662. }
  663. }
  664. &.cm-one {
  665. max-width: 400rpx;
  666. max-height: 400rpx;
  667. image {
  668. box-sizing: border-box;
  669. border-radius: 6rpx;
  670. border: 1px solid #e1e1e1;
  671. }
  672. }
  673. }
  674. .cm-video-list {
  675. margin-top: 18rpx;
  676. // // width: 702rpx;
  677. // // height: 420rpx;
  678. // width: 544rpx;
  679. // height: 960rpx;
  680. // .cm-video {
  681. // width: 100% !important;
  682. // max-width: 100%;
  683. // min-width: 100%;
  684. // display: flex;
  685. // // max-height: 420rpx;
  686. // // width: 100%;
  687. // height: 100%;
  688. // background: #000;
  689. // }
  690. }
  691. }
  692. }
  693. @keyframes permiMove {
  694. 0% {
  695. bottom: -100rpx;
  696. }
  697. 100% {
  698. bottom: 180rpx;
  699. }
  700. }
  701. </style>