fileDetail.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="fileDetail">
  3. <uni-menubar title="文件详情" />
  4. <view class="" v-if="detail">
  5. <tm-sheet>
  6. <tm-images v-if="detail.thumb" :src="detail.thumb"></tm-images>
  7. <view class="detailTitle">文件详情</view>
  8. <view class="detailRow">
  9. <view class="detailLeft">文件名称</view>
  10. <view class="detailRight">{{detail.name}}</view>
  11. </view>
  12. <view class="detailRow">
  13. <view class="detailLeft">文件类型</view>
  14. <view class="detailRight">{{detail.ext}}</view>
  15. </view>
  16. <view class="detailRow">
  17. <view class="detailLeft">文件大小</view>
  18. <view class="detailRight">{{detail.size}}</view>
  19. </view>
  20. <view class="detailRow">
  21. <view class="detailLeft">上传时间</view>
  22. <view class="detailRight">{{detail.update_time}}</view>
  23. </view>
  24. <view class="detailTitle">文件操作</view>
  25. <view>
  26. <tm-row>
  27. <tm-col :grid="3" v-if="detail.is_edit">
  28. <tm-button theme="blue" size="m" @click="editClick">更新</tm-button>
  29. </tm-col>
  30. <tm-col :grid="3">
  31. <tm-button theme="blue" size="m" @click="lookFile">查看</tm-button>
  32. </tm-col>
  33. <tm-col :grid="3" v-if="detail.is_edit">
  34. <tm-button theme="blue" size="m" @click="removeDialog = true">删除</tm-button>
  35. </tm-col>
  36. <tm-col :grid="3">
  37. <tm-button theme="blue" size="m" @click="download">下载</tm-button>
  38. </tm-col>
  39. </tm-row>
  40. </view>
  41. </tm-sheet>
  42. </view>
  43. <view style="height: 100rpx;"></view>
  44. <view class="shareBtn" v-if="detail.card_id == userInfo.card_id">
  45. <tm-button openType="share" block theme="blue">分享</tm-button>
  46. </view>
  47. <tm-dialog v-model="removeDialog" confirmColor="blue" @confirm="remove" content="您确定删除?"></tm-dialog>
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. data() {
  53. return {
  54. detail: {},
  55. iOS: false,
  56. removeDialog: false,
  57. fileId: "",
  58. card_id:""
  59. }
  60. },
  61. onLoad(option) {
  62. if (option)
  63. this.card_id = option.card_id
  64. this.$tm.vx.commit('card/cardId', option.card_id)
  65. this.fileId = option.fileId
  66. this.$tm.request.post('file/detail', {
  67. id: this.fileId
  68. }).then(res => {
  69. this.detail = res.data
  70. this.$point.point(5,this.fileId,this.card_id)
  71. })
  72. },
  73. onShareAppMessage(res) {
  74. return {
  75. title: this.detail.name + '.' + this.detail.ext,
  76. path: '/pages/file/fileDetail?fileId=' +this.fileId+'&card_id='+this.card_id,
  77. success:()=>{
  78. this.$point.point(6, this.fileId, this.card_id)
  79. }
  80. }
  81. },
  82. methods: {
  83. download() {
  84. let that = this
  85. const downloadTask = uni.downloadFile({
  86. url: that.detail.path,
  87. success: (data) => {
  88. if (data.statusCode === 200) {
  89. uni.saveFile({ //文件保存到本地
  90. tempFilePath: data.tempFilePath, //临时路径
  91. success: function(res) {
  92. uni.showToast({
  93. icon: 'none',
  94. mask: true,
  95. title: '文件已保存!',
  96. duration: 3000,
  97. });
  98. that.$point.point(7, that.fileId, that.card_id)
  99. }
  100. });
  101. }
  102. },
  103. fail: (err) => {
  104. uni.showToast({
  105. icon: 'none',
  106. mask: true,
  107. title: '失败请重新下载',
  108. });
  109. },
  110. });
  111. downloadTask.onProgressUpdate((res) => {
  112. if (res.progress < 101) {
  113. uni.showToast({
  114. icon: 'none',
  115. mask: true,
  116. title: '当前下载' + res.progress + '%',
  117. });
  118. } else {
  119. downloadTask.abort() // 取消下载任务
  120. }
  121. })
  122. },
  123. lookFile() {
  124. let that = this
  125. wx.downloadFile({
  126. // 示例 url,并非真实存在
  127. url: that.detail.path,
  128. success: function(res) {
  129. const filePath = res.tempFilePath
  130. wx.openDocument({
  131. filePath: filePath,
  132. success: function(res) {
  133. if(that.detail.card_id !== that.userInfo.card_id){
  134. that.$point.point(5, that.detail.id, that.userInfo.card_id)
  135. }
  136. }
  137. })
  138. }
  139. })
  140. },
  141. remove() {
  142. let params = {
  143. isdel: true,
  144. id: this.detail.id,
  145. name: this.detail.name,
  146. pid: this.detail.pid,
  147. path: this.detail.path
  148. }
  149. this.$tm.request.post('file/update', params).then(res => {
  150. uni.showToast({
  151. title: "删除成功",
  152. icon: "success",
  153. duration: 1000
  154. })
  155. setTimeout(() => {
  156. uni.navigateBack({
  157. success: () => {
  158. uni.$emit('refresh')
  159. }
  160. })
  161. }, 1000)
  162. })
  163. },
  164. editClick() {
  165. uni.navigateTo({
  166. url: '/pages/file/uploadFile?id=' + this.detail.id
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .shareBtn {
  174. width: 100%;
  175. padding: 15rpx 20rpx;
  176. position: fixed;
  177. bottom: 0;
  178. box-sizing: border-box;
  179. }
  180. .detailTitle {
  181. font-size: 34rpx;
  182. font-weight: bolder;
  183. color: #2196F3;
  184. margin: 40rpx 0;
  185. }
  186. .detailRow {
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. color: "#eeeeee";
  191. font-size: 28rpx;
  192. margin-top: 40rpx;
  193. .detailLeft {
  194. width: 30%;
  195. }
  196. .detailRight {
  197. flex: 1;
  198. }
  199. }
  200. </style>