detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view>
  3. <block v-if="detail.typestr == '图片' && painter.imageUrl" style="">
  4. <l-painter ref="painter" isCanvasToTempFilePath hidden :css="painter.css" @success="imageSuccess">
  5. <!-- 背景图片 -->
  6. <l-painter-image :src="painter.imageUrl" :css="painter.css" />
  7. <!-- 二维码 -->
  8. <l-painter-qrcode v-if="detail.isqrcode" :text="detail.qrcodecontent"
  9. css="width: 84px; height: 84px;position: absolute;bottom: 24px;right:24px;z-index: 2;background:#fff;" />
  10. </l-painter>
  11. </block>
  12. <view class="orientation" />
  13. <view class="head" v-if="detail.candownload_c || detail.candownload">
  14. <view class="sendmail" hover-class="navigator-hover" @click="toEmailPage">
  15. <text class="iconfont icon-fayouxiang" />
  16. 发送文件到邮箱
  17. </view>
  18. <view class="download" v-if="detail.type != 4" hover-class="navigator-hover" @click="download">
  19. <text class="iconfont icon-xiazai" />
  20. 下载
  21. </view>
  22. </view>
  23. <!-- 图片和视频类型使用swiper -->
  24. <swiper v-if="detail.typestr == '图片' || detail.typestr == '视频'" class="swiper" :current="current"
  25. :style="{ height: tovw(height) }" @change="swiperChange">
  26. <swiper-item class="swipeout-item" v-for="(item, index) in detail.attinfos_pic" :key="item.attachmentid">
  27. <image v-if="detail.typestr == '图片'" class="image" :style="{ height: tovw(height - 47) }"
  28. :src="item.cover" mode="aspectFit" lazy-load="true" @click="previewImage(index)" />
  29. <video :custom-cache="item.customCache" :id="'myVideo' + index" v-else-if="detail.typestr == '视频'"
  30. class="image" :style="{ height: tovw(height - 47) }" :src="item.url" :poster="item.cover" />
  31. <view class="paging">
  32. {{ index + 1 + '/' + detail.attinfos_pic.length }}
  33. </view>
  34. </swiper-item>
  35. </swiper>
  36. <!-- 文档类型使用列表显示 -->
  37. <scroll-view v-else-if="detail.typestr == '文档'" class="doc-list" :style="{ height: tovw(height) }"
  38. scroll-y="true">
  39. <view class="doc-item" v-for="(item, index) in detail.attinfos" :key="item.attachmentid"
  40. @click="openDoc(index)">
  41. <view class="doc-info">
  42. <view class="doc-name">{{ item.document }}</view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. <view class="bottom">
  47. {{ detail.title }}
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import lPainter from "../../uni_modules/lime-painter/components/l-painter/l-painter.vue"
  53. import lPainterImage from "../../uni_modules/lime-painter/components/l-painter-image/l-painter-image.vue"
  54. import lPainterQrcode from "../../uni_modules/lime-painter/components/l-painter-qrcode/l-painter-qrcode.vue"
  55. import { wxSaveFile } from "../../utils/settleFiles";
  56. export default {
  57. components: { lPainter, lPainterImage, lPainterQrcode },
  58. data() {
  59. return {
  60. current: 0,
  61. sat_sharematerialid: 0,
  62. detail: { attinfos_pic: [], typestr: '' },
  63. height: 0,
  64. painter: { imageUrl: "" },
  65. }
  66. },
  67. onLoad(options) {
  68. this.sat_sharematerialid = options.id;
  69. this.getDetail();
  70. },
  71. methods: {
  72. getDetail() {
  73. this.$Http.basic({
  74. "id": 20240407094602,
  75. "content": {
  76. "sat_sharematerialid": this.sat_sharematerialid
  77. }
  78. }).then(res => {
  79. console.log("装备资源库详情", res)
  80. if (this.cutoff(res.msg)) return;
  81. if (res.data.attinfos_pic.length == 0) {
  82. res.data.attinfos_pic = res.data.attinfos.filter(v => {
  83. return v.usetype != "avatar" && this.attinfosType(v.postfix) == res.data.typestr
  84. }).map(v => {
  85. return {
  86. attinfos: [v]
  87. }
  88. })
  89. }
  90. res.data.attinfos_pic = res.data.attinfos_pic.map(v => {
  91. if (res.data.typestr == '视频') {
  92. v.cover = this.getSpecifiedImage(v.attinfos[0], "cover")
  93. v = this.getVideoUrl(v.attinfos[0])
  94. } else {
  95. v.cover = this.getSpecifiedImage(v.attinfos[0], "compressed")
  96. }
  97. return v
  98. })
  99. this.detail = res.data;
  100. this.setHeight();
  101. uni.setNavigationBarTitle({
  102. title: res.data.title
  103. })
  104. })
  105. },
  106. toEmailPage() {
  107. uni.navigateTo({
  108. url: `/pages/email/index?type=resource&id=${this.detail.sat_sharematerialid}`
  109. });
  110. this.$Http.attinfos = this.detail.attinfos;
  111. },
  112. /* 设置组件高度 */
  113. setHeight() {
  114. this.getHeight(".orientation", this).then(res => {
  115. let info = uni.getSystemInfoSync(),
  116. safeAreaBottom = info.screenHeight - info.safeArea.bottom;
  117. if (this.detail.candownload_c == 1) safeAreaBottom += 40;
  118. this.height = res - safeAreaBottom - 40
  119. });
  120. },
  121. swiperChange(e) {
  122. uni.createVideoContext('myVideo' + this.current).pause()
  123. this.current = e.detail.current;
  124. },
  125. download() {
  126. let that = this,
  127. file = that.detail.attinfos_pic[that.current].attinfos[0];
  128. uni.showModal({
  129. title: '提示',
  130. content: `是否确定将当前${this.detail.typestr}保存到相册`,
  131. success: ({ confirm }) => {
  132. if (confirm) {
  133. if (that.detail.typestr == '视频') {
  134. wxSaveFile(file)
  135. } else {
  136. uni.getImageInfo({
  137. src: file.url,
  138. success: res => {
  139. console.log("getImageInfo", res)
  140. let upperLimit = 4080;
  141. if (uni.getSystemInfoSync().platform == 'ios') upperLimit = 1360;
  142. let arr = [res.width, res.height];
  143. let maxNum = Math.max(...arr);
  144. if (maxNum > upperLimit) {
  145. let MP = (maxNum / upperLimit).toFixed(2);
  146. console.log("缩小倍率", MP)
  147. res.width = res.width / MP;
  148. res.height = res.height / MP;
  149. }
  150. that.painter = {
  151. imageUrl: file.url,
  152. css: `position: relative;width: ${res.width}px; height: ${res.height}px;object-fit:cover;`
  153. }
  154. console.log("that.painter", that.painter)
  155. }
  156. })
  157. }
  158. }
  159. },
  160. })
  161. },
  162. imageSuccess() {
  163. let that = this;
  164. that.$refs.painter.canvasToTempFilePathSync({
  165. fileType: "jpg",
  166. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  167. pathType: 'url',
  168. quality: 1,
  169. success: (res) => {
  170. console.log(res.tempFilePath);
  171. // 非H5 保存到相册
  172. // H5 提示用户长按图另存
  173. uni.saveImageToPhotosAlbum({
  174. filePath: res.tempFilePath,
  175. success: function (e) {
  176. uni.showModal({
  177. title: '提示',
  178. content: '图片已保存到系统相册',
  179. showCancel: false
  180. })
  181. that.loading = false;
  182. that.$Http.basic({
  183. "id": 20240319142702,
  184. "content": {
  185. sat_sharematerialid: that.detail.sat_sharematerialid, type: 1
  186. }
  187. }).then(res => {
  188. console.log(type, '记录', res)
  189. })
  190. },
  191. fail: ({ errMsg }) => {
  192. if (errMsg == 'saveImageToPhotosAlbum:fail auth deny') {
  193. uni.showModal({
  194. title: '提示',
  195. content: '请授权添加到相册权限后再试!',
  196. showCancel: false,
  197. complete: (complete) => {
  198. uni.openSetting({
  199. success: res => {
  200. that.loading = false;
  201. if (res.authSetting['scope.writePhotosAlbum']) {
  202. this.saveTheImage()
  203. } else {
  204. uni.showModal({
  205. title: '提示',
  206. content: '未获取授权!已取消保存',
  207. showCancel: false,
  208. })
  209. }
  210. }
  211. })
  212. },
  213. })
  214. } else {
  215. that.loading = false;
  216. uni.showModal({
  217. title: '提示',
  218. content: '已取消保存',
  219. showCancel: false,
  220. })
  221. }
  222. },
  223. });
  224. },
  225. });
  226. },
  227. /* 预览图片 */
  228. previewImage(index) {
  229. const urls = this.detail.attinfos_pic.map(item => item.cover);
  230. uni.previewImage({
  231. urls: urls,
  232. current: index,
  233. success: () => {
  234. console.log('预览图片成功');
  235. },
  236. fail: (err) => {
  237. console.error('预览图片失败', err);
  238. uni.showToast({
  239. title: '预览失败',
  240. icon: 'none'
  241. });
  242. }
  243. });
  244. },
  245. /* 打开文档 */
  246. openDoc(index) {
  247. let file = this.detail.attinfos[index];
  248. const filename = file.filename || file.document || '';
  249. const fileType = this.getFileExtension(filename);
  250. // uni.openDocument 支持的文件类型
  251. const supportedFileTypes = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt'];
  252. if (!supportedFileTypes.includes(fileType)) {
  253. uni.showToast({
  254. title: '该文件类型暂不支持在线预览',
  255. icon: 'none',
  256. });
  257. return;
  258. }
  259. uni.showLoading({
  260. title: '加载中...',
  261. });
  262. uni.downloadFile({
  263. url: file.url,
  264. success: (res) => {
  265. uni.openDocument({
  266. filePath: res.tempFilePath,
  267. fileType: fileType,
  268. success: () => {
  269. uni.hideLoading();
  270. },
  271. fail: (err) => {
  272. console.log("openDocument", err);
  273. uni.hideLoading();
  274. uni.showToast({
  275. title: "读取失败,请稍后再试",
  276. icon: "none",
  277. });
  278. },
  279. });
  280. },
  281. fail: (err) => {
  282. console.log("downloadFile", err);
  283. uni.hideLoading();
  284. uni.showToast({
  285. title: "下载失败,请稍后再试",
  286. icon: "none",
  287. });
  288. },
  289. });
  290. },
  291. /* 获取文件扩展名 */
  292. getFileExtension(filename) {
  293. if (!filename) return '';
  294. let lastDotIndex = filename.lastIndexOf('.');
  295. return lastDotIndex !== -1 ? filename.substring(lastDotIndex + 1).toLowerCase() : '';
  296. }
  297. }
  298. }
  299. </script>
  300. <style lang="scss" scoped>
  301. .head {
  302. display: flex;
  303. justify-content: space-between;
  304. background: #333333;
  305. width: 100vw;
  306. height: 40px;
  307. .sendmail {
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. width: 160px;
  312. height: 40px;
  313. background: #C30D23;
  314. font-family: PingFang SC, PingFang SC;
  315. font-weight: 500;
  316. font-size: 14px;
  317. color: #FFFFFF;
  318. .iconfont {
  319. margin-right: 5px;
  320. }
  321. }
  322. .download {
  323. font-size: 12px;
  324. color: #FFFFFF;
  325. line-height: 40px;
  326. padding-right: 10px;
  327. .iconfont {
  328. margin-right: 5px;
  329. }
  330. }
  331. }
  332. .swiper {
  333. width: 100vw;
  334. background: #333333;
  335. .swipeout-item {
  336. width: 100%;
  337. height: 100%;
  338. .image {
  339. width: 100%;
  340. }
  341. .paging {
  342. width: 100vw;
  343. text-align: center;
  344. line-height: 17px;
  345. font-family: Source Han Sans SC, Source Han Sans SC;
  346. font-size: 12px;
  347. color: #FFFFFF;
  348. margin-top: 10px;
  349. }
  350. }
  351. }
  352. .doc-list {
  353. width: 100vw;
  354. background: #f5f5f5;
  355. padding: 10px;
  356. box-sizing: border-box;
  357. .doc-item {
  358. display: flex;
  359. align-items: center;
  360. background: #ffffff;
  361. padding: 15px;
  362. margin-bottom: 10px;
  363. border-radius: 8px;
  364. .doc-icon {
  365. width: 50px;
  366. height: 50px;
  367. background: #E8F3FF;
  368. border-radius: 8px;
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. margin-right: 15px;
  373. .iconfont {
  374. font-size: 24px;
  375. color: #1890FF;
  376. }
  377. }
  378. .doc-info {
  379. flex: 1;
  380. .doc-name {
  381. font-size: 14px;
  382. color: #333333;
  383. margin-bottom: 5px;
  384. overflow: hidden;
  385. text-overflow: ellipsis;
  386. white-space: nowrap;
  387. }
  388. .doc-type {
  389. font-size: 12px;
  390. color: #999999;
  391. }
  392. }
  393. .doc-arrow {
  394. .iconfont {
  395. font-size: 16px;
  396. color: #999999;
  397. }
  398. }
  399. }
  400. }
  401. .slot-content {
  402. width: 100%;
  403. text-align: center;
  404. .slot-title {
  405. height: 26px;
  406. font-family: Source Han Sans SC, Source Han Sans SC;
  407. font-weight: bold;
  408. font-size: 18px;
  409. color: #000000;
  410. }
  411. .slot-tips {
  412. line-height: 20px;
  413. font-family: Source Han Sans SC, Source Han Sans SC;
  414. font-size: 14px;
  415. color: #666666;
  416. margin-bottom: 30px;
  417. margin-top: 10px;
  418. }
  419. }
  420. .bottom {
  421. min-height: 40px;
  422. display: flex;
  423. align-items: center;
  424. justify-content: center;
  425. width: 100vw;
  426. padding: 0 10px;
  427. box-sizing: border-box;
  428. font-size: 14px;
  429. color: #333333;
  430. }
  431. </style>