index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="messageDetail-v u-p-l-20 u-p-r-20">
  3. <view class="u-flex-col u-border-bottom u-p-b-40 u-m-b-40">
  4. <text class="u-m-b-16 u-font-32 txt">{{info.title}}</text>
  5. <view>
  6. <text class="releaseUser u-font-24 ">{{info.releaseUser}}</text>
  7. <text
  8. class="releaseUser u-font-24 u-m-l-16">{{ info.releaseTime?$u.timeFormat(info.releaseTime, 'yyyy-mm-dd hh:MM:ss'):''}}</text>
  9. </view>
  10. </view>
  11. <view class="u-p-b-16 excerpt" v-if="info.excerpt">
  12. {{info.excerpt}}
  13. </view>
  14. <view class="messageDetail-content u-p-b-20 ">
  15. <mp-html :content="info.bodyText" />
  16. </view>
  17. <view class="file-box">
  18. <view class="file-list u-flex" v-for="(item,index) in fileList" :key="index">
  19. <view class="file-list-l">
  20. <u-icon name="attach" color="#969799"></u-icon>
  21. <text class="fileName">{{item.name}}</text>
  22. </view>
  23. <u-icon name="download" color="#969799" @click="openFile(item)"></u-icon>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. const imgTypeList = ['png', 'jpg', 'jpeg', 'bmp', 'gif']
  30. import {
  31. getMessageDetail
  32. } from '@/api/message.js'
  33. import {
  34. getDownloadUrl
  35. } from '@/api/common'
  36. export default {
  37. data() {
  38. return {
  39. info: {},
  40. fileList: []
  41. }
  42. },
  43. computed: {
  44. baseURL() {
  45. return this.define.baseURL
  46. }
  47. },
  48. onLoad(option) {
  49. this.initDetail(option.id)
  50. },
  51. methods: {
  52. initDetail(id) {
  53. getMessageDetail(id).then(res => {
  54. this.info = res.data;
  55. this.fileList = JSON.parse(this.info.files)
  56. uni.$emit('initUnReadMsgNum')
  57. })
  58. },
  59. previewImage(item) {
  60. if (!item.url) return
  61. const url = this.baseURL + item.url
  62. uni.previewImage({
  63. urls: [url],
  64. current: url,
  65. success: () => {},
  66. fail: () => {
  67. uni.showToast({
  68. title: '预览图片失败',
  69. icon: 'none'
  70. });
  71. }
  72. });
  73. },
  74. openFile(item) {
  75. if (item.fileExtension && imgTypeList.includes(item.fileExtension)) return this.previewImage(item)
  76. // #ifdef MP
  77. this.previewFile(item)
  78. // #endif
  79. // #ifndef MP
  80. getDownloadUrl('annex', item.fileId).then(res => {
  81. // #ifdef H5
  82. window.location.href = this.baseURL + res.data.url + '&name=' + item.name;
  83. // #endif
  84. // #ifndef H5
  85. uni.downloadFile({
  86. url: this.baseURL + res.data.url + '&name=' + item.name,
  87. success: function(res) {
  88. var filePath = res.tempFilePath;
  89. uni.openDocument({
  90. filePath: encodeURI(filePath),
  91. showMenu: true,
  92. success: function(res) {
  93. }
  94. });
  95. }
  96. });
  97. // #endif
  98. })
  99. // #endif
  100. },
  101. previewFile(item) {
  102. let url = item.url
  103. uni.downloadFile({
  104. url: this.baseURL + url,
  105. success: (res) => {
  106. var filePath = res.tempFilePath;
  107. uni.openDocument({
  108. filePath: encodeURI(filePath),
  109. success: (res) => {
  110. console.log('打开文档成功');
  111. }
  112. });
  113. }
  114. });
  115. },
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. .messageDetail-v {
  121. .excerpt {
  122. word-break: break-all;
  123. }
  124. .txt {
  125. font-weight: 700;
  126. }
  127. .messageDetail-content {
  128. color: #606266;
  129. word-break: break-all;
  130. }
  131. .releaseUser {
  132. color: #606266;
  133. }
  134. .file-box {
  135. .file-list {
  136. margin-top: 20rpx;
  137. justify-content: space-between;
  138. .file-list-l {
  139. .fileName {
  140. margin-left: 10rpx;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. </style>