cm-product-doc.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <view class="product-doc hasBottom" :style="{ paddingBottom: isIphoneX ? '60rpx' : 0 }">
  3. <view class="category">
  4. <view class="category-title">图片资料</view>
  5. <view class="content">
  6. <view class="cm-none" v-if="imageArchiveList.length === 0">暂无相关资料</view>
  7. <template v-else>
  8. <view class="section" v-for="(item, index) in imageArchiveList" :key="index">
  9. <view class="cm-title">{{ item.title }}</view>
  10. <view class="cm-time">{{ $reg.formatDate('', item.addTime) }}</view>
  11. <view class="cm-img-list cm-list">
  12. <template v-if="item.imageList">
  13. <image
  14. :src="image.url"
  15. @click="previewImage(i, item.imageList)"
  16. mode="aspectFill"
  17. v-for="(image, i) in imageFormat(item.imageList)"
  18. :key="i"
  19. :style="image.style"
  20. ></image>
  21. </template>
  22. <template v-else>
  23. <image
  24. :src="defaultImage"
  25. mode="aspectFill"
  26. v-for="i in item.imageNum"
  27. :key="i"
  28. @click="checkPermission"
  29. ></image>
  30. </template>
  31. </view>
  32. </view>
  33. </template>
  34. </view>
  35. </view>
  36. <view class="category">
  37. <view class="category-title">视频资料</view>
  38. <view class="content">
  39. <view class="cm-none" v-if="videoArchiveList.length === 0">暂无相关资料</view>
  40. <template v-else>
  41. <view class="section" v-for="(item, index) in videoArchiveList" :key="index">
  42. <view class="cm-title">{{ item.title }}</view>
  43. <view class="cm-time">{{ $reg.formatDate('', item.addTime) }}</view>
  44. <view class="cm-video-list">
  45. <video
  46. :id="'myVideo' + index"
  47. :src="item.fileUrl"
  48. controls
  49. show-fullscreen-btn
  50. show-mute-btn
  51. @play="handlePlayer('myVideo' + index)"
  52. v-if="item.fileUrl"
  53. ></video>
  54. <view class="cm-video-section" v-else>
  55. <image class="cm-video-cover" :src="videoCover"></image>
  56. <text class="cm-player-btn" @click="checkPermission()"></text>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. </view>
  62. </view>
  63. <view class="category cm-file">
  64. <view class="category-title">文件资料</view>
  65. <view class="content">
  66. <view class="cm-none" v-if="fileArchiveList.length === 0">暂无相关资料</view>
  67. <template v-else>
  68. <view class="section" v-for="(item, index) in fileArchiveList" :key="index">
  69. <image
  70. src="https://static.caimei365.com/app/img/icon2/PDF-app.png"
  71. v-if="/\.pdf$/.test(item.fileName)"
  72. ></image>
  73. <image
  74. src="https://static.caimei365.com/app/img/icon2/DOC-app.png"
  75. v-else-if="/\.doc$/.test(item.fileName)"
  76. ></image>
  77. <image src="https://static.caimei365.com/app/img/icon2/PPT-app.png" v-else></image>
  78. <view class="cm-desc">
  79. <view class="cm-title">{{ item.title }}</view>
  80. <view class="cm-bottom">
  81. <view class="cm-time">{{ $reg.formatDate('', item.addTime) }}</view>
  82. <view class="cm-preview" @click="previewFile(item)">预览文件</view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. </view>
  88. </view>
  89. <view
  90. class="cm-login"
  91. :class="{ maxBottom: !bottom && isIphoneX }"
  92. :style="{ bottom: bottom }"
  93. v-if="TipStatus"
  94. >
  95. <text>{{ TipStatus.text }}</text>
  96. <view class="cm-btn" @click="nextAction(TipStatus.redirect)">{{ TipStatus.btn }}</view>
  97. </view>
  98. <tui-modal
  99. :show="showModal"
  100. :content="TipStatus.text"
  101. shape="circle"
  102. :button="modalButton"
  103. fadeIn
  104. @click="handleModalClick"
  105. ></tui-modal>
  106. </view>
  107. </template>
  108. <script>
  109. import { mapState } from 'vuex'
  110. export default {
  111. props: {
  112. product: {
  113. type: Object,
  114. default: () => {}
  115. },
  116. archiveId: {
  117. type: Number,
  118. default: 0
  119. },
  120. bottom: {
  121. type: String,
  122. default: ''
  123. }
  124. },
  125. data() {
  126. return {
  127. userId: -1,
  128. prevVideoId: '',
  129. currentVideoId: '',
  130. videoContexts: [],
  131. modalButton: [
  132. {
  133. text: '取消',
  134. type: 'gray',
  135. plain: true //是否空心
  136. },
  137. {
  138. text: '确认',
  139. customStyle: {
  140. color: '#fff',
  141. bgColor: 'linear-gradient(90deg, #F28F31 0%, #E15616 100%)'
  142. },
  143. plain: false
  144. }
  145. ],
  146. showModal: false,
  147. //用户信息相关
  148. permission: 5, //用户权限 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  149. imageArchiveList: [], // 图片资料列表
  150. videoArchiveList: [], // 视频资料列表
  151. fileArchiveList: [], // 文件资料列表
  152. defaultImage: 'https://static.caimei365.com/app/img/icon2/PC-default.png', // 默认图片
  153. videoCover: 'https://static.caimei365.com/app/img/icon2/video-cover.png', //默认视频封面
  154. }
  155. },
  156. computed: {
  157. ...mapState(['isIphoneX']),
  158. //资料查看状态提示
  159. TipStatus: function() {
  160. // 资料权限
  161. const statusText = [
  162. false,
  163. { text: '请登录后查看!', btn: '去登录', redirect: '/pages/login/login' },
  164. { text: '请升级成为会员机构后方可查看!', btn: '去升级', redirect: '/pages/login/apply' },
  165. { text: '请升级成为医美会员机构后方可查看!', btn: '去升级', redirect: '/pages/login/apply' },
  166. { text: '需抵扣100采美豆方可查看!', btn: '去查看', redirect: 10 },
  167. { text: '无权限查看!', btn: '' }
  168. ]
  169. // 0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  170. return statusText[this.permission]
  171. }
  172. },
  173. created() {
  174. this.userId = uni.getStorageSync('userInfo').userId || -1
  175. // uni.createVideoContext()
  176. this.getDetail()
  177. },
  178. methods: {
  179. // 获取商品资料详情
  180. getDetail() {
  181. console.log(this.userId)
  182. this.BeautyArchive.GetProdcutArchiveDetails({
  183. userId: this.userId,
  184. archiveId: this.archiveId
  185. }).then(res => {
  186. console.log(res)
  187. if (res.code) return
  188. this.imageArchiveList = res.data.imageArchiveList
  189. this.videoArchiveList = res.data.videoArchiveList
  190. this.fileArchiveList = res.data.fileArchiveList
  191. this.permission = res.data.permission
  192. })
  193. },
  194. // 视频播放
  195. handlePlayer(id) {
  196. if (this.checkPermission()) {
  197. this.handleStop(id)
  198. return
  199. }
  200. if (this.prevVideoId === id) return
  201. this.prevVideoId = this.currentVideoId
  202. // 暂停上一个播放器
  203. this.handelPause(this.prevVideoId)
  204. // 保存当前播放器id
  205. this.currentVideoId = id
  206. },
  207. // 开始播放
  208. handelPlay(id) {
  209. if (!id) return
  210. const vContext = uni.createVideoContext(id, this)
  211. vContext.play()
  212. },
  213. // 暂停播放
  214. handelPause(id) {
  215. if (!id) return
  216. const vContext = uni.createVideoContext(id, this)
  217. vContext.pause()
  218. },
  219. // 停止视频
  220. handleStop(id) {
  221. if (!id) return
  222. const vContext = uni.createVideoContext(id, this)
  223. vContext.stop()
  224. },
  225. // 预览图片
  226. previewImage(index, previewImageList) {
  227. if (this.checkPermission()) return
  228. uni.previewImage({
  229. current: index,
  230. indicator: 'number',
  231. urls: previewImageList,
  232. loop: true
  233. })
  234. },
  235. //用户权限校验拦截
  236. checkPermission() {
  237. //permission:查看权限:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
  238. const _self = this
  239. // 如果 TipStatus 返回false 就放行
  240. if (!_self.TipStatus) return 0
  241. this.modalButton[1].text = this.TipStatus.btn
  242. this.showModal = true
  243. return -1
  244. },
  245. // modal 按钮点击
  246. handleModalClick(e) {
  247. // 点击确认按钮
  248. if (e.index === 1) {
  249. this.showModal = false
  250. this.nextAction(this.TipStatus.redirect)
  251. } else {
  252. this.showModal = false
  253. }
  254. },
  255. //图片列表处理
  256. imageFormat(list) {
  257. const imageList = []
  258. if (list.length > 2) {
  259. list.forEach((item, index) => {
  260. imageList.push({ url: item, style: '' })
  261. })
  262. }
  263. if (list.length === 1) {
  264. try {
  265. const strArr = list[0]
  266. .split('?')[1]
  267. .replace(/\&|\=/g, '-')
  268. .split('-')
  269. const w = strArr[1] // 图片长
  270. const h = strArr[3] // 图片高
  271. let style = ''
  272. if (w > h) {
  273. style = `width:600rpx;height:${(600 / w) * h}rpx`
  274. } else {
  275. style = `height:600rpx;width:${(600 * w) / h}rpx`
  276. }
  277. imageList.push({ url: list[0], style: style })
  278. } catch (e) {
  279. //TODO handle the exception
  280. console.error(
  281. '图片链接格式不正确,返回未处理图片,请设置正确的链接:http://image/text.png?width=xx&height=xx '
  282. )
  283. imageList.push({ url: list[0], style: '' })
  284. }
  285. }
  286. if (list.length === 2) {
  287. const style = 'width:300rpx;height:300rpx;'
  288. imageList.push({ url: list[0], style })
  289. imageList.push({ url: list[1], style })
  290. }
  291. return imageList
  292. },
  293. // 点击按钮后要做的事
  294. nextAction(redirect) {
  295. const _self = this
  296. if (typeof redirect == 'string') {
  297. // 跳转链接
  298. console.log('链接跳转')
  299. this.$api.navigateTo(redirect)
  300. }
  301. if (redirect === 10) {
  302. console.log('调用接口')
  303. }
  304. },
  305. // 文件预览
  306. previewFile(file) {
  307. // 获取文件后缀
  308. const index = file.fileName.lastIndexOf('.')
  309. const suffix = file.fileName.substring(index)
  310. if (suffix === '.doc' || suffix === '.ppt') {
  311. this.$api.navigateTo(
  312. `/pages/h5/article/path?link=${file.fileUrl}`
  313. )
  314. } else if (suffix === '.pdf') {
  315. this.$api.navigateTo(
  316. `/pages/h5/article/path?type=1&link=${file.fileUrl}`
  317. )
  318. } else {
  319. // 不支持的文件
  320. return uni.showModal({
  321. content: `${suffix}类型文件暂不支持预览`,
  322. cancelColor: '#666',
  323. confirmColor: '#E15616'
  324. })
  325. }
  326. }
  327. }
  328. }
  329. </script>
  330. <style lang="scss" scoped>
  331. .product-doc {
  332. background: #f7f7f7;
  333. }
  334. .hasBottom {
  335. padding-bottom: 90rpx;
  336. }
  337. .cm-login {
  338. position: fixed;
  339. left: 24rpx;
  340. bottom: 115rpx; // 包含商品导航
  341. display: flex;
  342. justify-content: space-between;
  343. align-items: center;
  344. padding: 0 32rpx;
  345. width: 702rpx;
  346. height: 90rpx;
  347. background: #ffe6dc;
  348. border-radius: 16px;
  349. box-sizing: border-box;
  350. &.maxBottom {
  351. bottom: 175rpx;
  352. }
  353. text {
  354. font-size: 26rpx;
  355. color: #e15616;
  356. }
  357. .cm-btn {
  358. width: 136rpx;
  359. height: 48rpx;
  360. background: #e15616;
  361. border-radius: 28px;
  362. font-size: 26rpx;
  363. text-align: center;
  364. line-height: 48rpx;
  365. color: #ffffff;
  366. }
  367. }
  368. .category {
  369. padding: 0 24rpx;
  370. margin-bottom: 20rpx;
  371. background: #fff;
  372. .cm-video-section {
  373. position: relative;
  374. width: 702rpx;
  375. height: 402rpx;
  376. .cm-video-cover {
  377. width: 702rpx;
  378. height: 402rpx;
  379. }
  380. .cm-player-btn {
  381. position: absolute;
  382. left: 50%;
  383. top: 50%;
  384. transform: translate(-50%, -50%);
  385. z-index: 5;
  386. width: 56rpx;
  387. height: 56rpx;
  388. background: url(https://static.caimei365.com/app/img/icon2/H5-plalyer.png) center no-repeat;
  389. background-size: 56rpx 56rpx;
  390. }
  391. }
  392. .category-title {
  393. padding-top: 24rpx;
  394. padding-bottom: 8rpx;
  395. font-size: 28rpx;
  396. font-weight: 500;
  397. color: #333333;
  398. border-bottom: 1px solid #f0f0f0;
  399. }
  400. .cm-none {
  401. height: 37rpx;
  402. margin: 24rpx 0 0 0;
  403. padding-bottom: 48rpx;
  404. font-size: 26rpx;
  405. font-weight: 400;
  406. line-height: 37rpx;
  407. color: #333333;
  408. }
  409. &.cm-file {
  410. .section {
  411. display: flex;
  412. justify-content: space-between;
  413. align-items: center;
  414. image {
  415. width: 88rpx;
  416. height: 88rpx;
  417. }
  418. .cm-desc {
  419. width: 582rpx;
  420. }
  421. .cm-bottom {
  422. display: flex;
  423. justify-content: space-between;
  424. align-items: center;
  425. padding: 16rpx 0 0;
  426. .cm-preview {
  427. font-size: 26rpx;
  428. font-weight: 400;
  429. color: #e15616;
  430. }
  431. .cm-time {
  432. padding: 0;
  433. }
  434. }
  435. }
  436. }
  437. .section {
  438. padding-bottom: 24rpx;
  439. border-bottom: 1px solid #f0f0f0;
  440. &:last-child {
  441. border-bottom: 0;
  442. }
  443. .cm-title {
  444. display: -webkit-box;
  445. height: 74rpx;
  446. margin-top: 24rpx;
  447. font-size: 26rpx;
  448. font-weight: 400;
  449. line-height: 1.5;
  450. color: #333333;
  451. -webkit-box-orient: vertical;
  452. -webkit-line-clamp: 2;
  453. overflow: hidden;
  454. word-break: break-all;
  455. text-align: justify;
  456. }
  457. .cm-time {
  458. padding: 8rpx 0;
  459. font-size: 22rpx;
  460. font-weight: 400;
  461. color: #b2b2b2;
  462. }
  463. .cm-img-list {
  464. display: flex;
  465. justify-content: flex-start;
  466. flex-wrap: wrap;
  467. &.cm-list {
  468. image {
  469. width: 162rpx;
  470. height: 162rpx;
  471. margin: 18rpx 18rpx 0 0;
  472. box-sizing: border-box;
  473. border-radius: 6rpx;
  474. border: 1px solid #e1e1e1;
  475. &:nth-child(4n) {
  476. margin-right: 0;
  477. }
  478. }
  479. }
  480. &.cm-one {
  481. max-width: 400rpx;
  482. max-height: 400rpx;
  483. image {
  484. box-sizing: border-box;
  485. border-radius: 6rpx;
  486. border: 1px solid #e1e1e1;
  487. }
  488. }
  489. }
  490. .cm-video-list {
  491. margin-top: 18rpx;
  492. video {
  493. width: 702rpx;
  494. height: 420rpx;
  495. background: #000;
  496. }
  497. }
  498. }
  499. }
  500. </style>