download.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="download">
  3. <mescroll-empty v-if="list.length === 0"></mescroll-empty>
  4. <view class="down-list" v-else>
  5. <view class="down-item" v-for="(item,index) in list" :key="item.id">
  6. <view class="down-content">
  7. <view class="down-icon">
  8. <uv-icon color="#fff" size="26" name="file-text-fill">
  9. </uv-icon>
  10. </view>
  11. <view class="content">
  12. <view class="title hui-ellipsis">{{item.fileName}}</view>
  13. <view class="date">{{item.date}}</view>
  14. </view>
  15. </view>
  16. <view class="down-operation">
  17. <view class="down-operation-item" @tap="openDocument(index)">
  18. <uv-icon color="#8c8c8c" size="20" name="order">
  19. </uv-icon>
  20. <text class="text">打开</text>
  21. </view>
  22. <view class="down-operation-item" @tap="shareFile(index)">
  23. <uv-icon color="#8c8c8c" size="20" name="share">
  24. </uv-icon>
  25. <text class="text">分享</text>
  26. </view>
  27. <view class="down-operation-item" @tap="deleteFile(index)">
  28. <uv-icon color="#8c8c8c" size="20" name="trash">
  29. </uv-icon>
  30. <text class="text">删除</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. list: [],
  42. deviceId: ''
  43. }
  44. },
  45. onLoad() {
  46. this.init();
  47. },
  48. methods: {
  49. init() {
  50. let file = !uni.getStorageSync('downliadFile') ? [] : JSON.parse(uni.getStorageSync(
  51. 'downliadFile'));
  52. this.list = file.filter(node => node.userId === this.$store.getters.user.userId);
  53. },
  54. deleteFile(index) {
  55. let _self = this;
  56. let file = !uni.getStorageSync('downliadFile') ? [] : JSON.parse(uni
  57. .getStorageSync('downliadFile'));
  58. let item = _self.list[index];
  59. uni.showModal({
  60. title: '有极提示',
  61. content: '是否删除该文件?',
  62. success: res => {
  63. if (res.confirm) {
  64. console.log(file);
  65. console.log(item);
  66. let index = file.findIndex(node => node.wxUrl === item.wxUrl);
  67. file.splice(index, 1);
  68. uni.setStorageSync('downliadFile', JSON.stringify(file));
  69. _self.init();
  70. }
  71. }
  72. });
  73. },
  74. shareFile(index) {
  75. let item = this.list[index];
  76. wx.shareFileMessage({
  77. filePath: item.wxUrl,
  78. fileName: item.fileName,
  79. success(data) {}
  80. })
  81. },
  82. openDocument(index) {
  83. let item = this.list[index];
  84. uni.openDocument({
  85. filePath: item.wxUrl,
  86. fileType: item.type,
  87. success: (res) => {},
  88. fail: (error) => {
  89. this.$toast('打开失败')
  90. }
  91. });
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. .down-list {
  98. padding: 30rpx;
  99. .down-item {
  100. padding: 20rpx 20rpx 0px 20rpx;
  101. background: #fff;
  102. border-radius: 12rpx;
  103. box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
  104. margin-bottom: 30rpx;
  105. }
  106. .down-operation {
  107. border-top: 2rpx solid $uni-border-1;
  108. display: flex;
  109. align-items: center;
  110. }
  111. .down-operation-item {
  112. display: flex;
  113. align-items: center;
  114. color: $uni-secondary-color;
  115. flex: 1;
  116. justify-content: center;
  117. padding: 20rpx 0;
  118. }
  119. .down-content {
  120. display: flex;
  121. align-items: center;
  122. padding-bottom: 20rpx;
  123. }
  124. .content {
  125. margin-left: 12rpx;
  126. flex: 1;
  127. width: 0;
  128. overflow: hidden;
  129. }
  130. .title {
  131. font-size: 32rpx;
  132. font-weight: 600;
  133. margin-bottom: 10rpx;
  134. width: 100%;
  135. }
  136. .date {
  137. font-weight: 300;
  138. font-size: 24rpx;
  139. margin-top: 10rpx;
  140. color: $uni-secondary-color;
  141. }
  142. .down-icon {
  143. width: 80rpx;
  144. height: 80rpx;
  145. border-radius: 12rpx;
  146. background: $uni-primary;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. }
  151. }
  152. </style>