cm-product-doc.vue 26 KB

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