cm-product-doc.vue 23 KB

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