index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <button type="default" size="mini" v-if="route&&route.length>0" @click="toBack()">上一层</button>
  6. <button type="default" size="mini" v-if="is_file==true" @click="dialogOpen('dialogShow')">时间范围删除</button>
  7. </view>
  8. <view class="two">
  9. <scroll-view scroll-y="true" class="scroll-view">
  10. <view class="list-scroll-view">
  11. <view class="list" v-for="(item,index) in list" :key="index">
  12. <view class="name">
  13. {{item.name}}
  14. </view>
  15. <view class="other">
  16. <view class="other_1">
  17. <text>创建时间:</text>
  18. <text>{{item.create_time}}</text>
  19. </view>
  20. <view class="other_1">
  21. <text>文件类型:</text>
  22. <text>{{item.type=='file'?'文件':item.type=='dir'?'目录':'未知'}}</text>
  23. </view>
  24. <view class="other_1">
  25. <text>文件大小(KB):</text>
  26. <text>{{item.size}}</text>
  27. </view>
  28. </view>
  29. <view class="btn">
  30. <button type="default" size="mini" v-if="item.type=='dir'" @click="toDir(item)">进入目录</button>
  31. <button class="del" type="default" size="mini" @click="toDel(item)">删除文件</button>
  32. </view>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. </view>
  38. <uni-popup background-color="#ffffff" ref="dialogShow" type="dialog">
  39. <uni-popup-dialog title="时间选择" mode="base" @confirm="dialogFirm">
  40. <uni-datetime-picker v-model="dateArray" type="daterange" @change="dateChange" />
  41. </uni-popup-dialog>
  42. </uni-popup>
  43. </mobile-frame>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. list: [],
  50. route: [],
  51. is_file: false,
  52. dateArray: [],
  53. times: {}
  54. };
  55. },
  56. onShow: function() {
  57. const that = this;
  58. that.search();
  59. },
  60. methods: {
  61. dialogOpen(e) {
  62. const that = this;
  63. that.$refs[e].open();
  64. },
  65. async search() {
  66. const that = this;
  67. let res = await that.$api(`/dir`, 'POST', {
  68. route: that.route,
  69. });
  70. if (res.errcode == '0') {
  71. let is_file = res.data.every(function(item) {
  72. return item.type == 'file'
  73. });
  74. that.$set(that, `is_file`, is_file)
  75. that.$set(that, `list`, res.data)
  76. }
  77. },
  78. // 进入目录
  79. async toDir(e) {
  80. const that = this;
  81. let route = [...that.route, e.name];
  82. that.$set(that, `route`, route);
  83. that.search();
  84. },
  85. // 时间范围选择
  86. dateChange(e) {
  87. const that = this;
  88. that.$set(that, `dateArray`, e)
  89. },
  90. // 确认选择
  91. dialogFirm() {
  92. const that = this;
  93. let date = that.dateArray;
  94. that.$set(that, `times`, {
  95. start_time: date[0],
  96. end_time: date[1]
  97. })
  98. that.toDel()
  99. },
  100. // 删除文件
  101. async toDel(e) {
  102. const that = this;
  103. let route = that.route;
  104. // 文件
  105. let file = e;
  106. // 时间范围
  107. let times = that.times;
  108. uni.showModal({
  109. title: '温馨提示',
  110. content: '数据删除后不可恢复,您确认吗?',
  111. success: async function(res) {
  112. if (res.confirm) {
  113. let arr;
  114. if (file && file.name) {
  115. arr = await that.$api(`/delFile`, 'POST', {
  116. route,
  117. target: file.name
  118. })
  119. } else {
  120. arr = await that.$api(`/delFile`, 'POST', {
  121. route,
  122. times
  123. })
  124. }
  125. if (arr.errcode == '0') {
  126. uni.showToast({
  127. title: '删除成功',
  128. icon: 'error',
  129. duration: 2000
  130. });
  131. that.search();
  132. } else {
  133. uni.showToast({
  134. title: arr.errmsg,
  135. icon: 'error',
  136. duration: 2000
  137. });
  138. }
  139. } else if (res.cancel) {
  140. console.log('用户点击取消');
  141. }
  142. }
  143. });
  144. },
  145. // 上一层
  146. toBack() {
  147. const that = this;
  148. let route = that.route;
  149. route.pop();
  150. that.$set(that, `route`, route);
  151. that.search()
  152. },
  153. }
  154. }
  155. </script>
  156. <style lang="scss">
  157. .main {
  158. display: flex;
  159. flex-direction: column;
  160. width: 96vw;
  161. height: 100vh;
  162. margin: 0 2vw;
  163. .one {
  164. text-align: center;
  165. margin: 2vw 0 2vw 0;
  166. button {
  167. margin: 0 2vw;
  168. background-color: var(--f35BColor);
  169. color: var(--fffColor);
  170. font-size: var(--font14Size);
  171. }
  172. button:nth-child(2) {
  173. background-color: var(--ff0Color);
  174. color: var(--fffColor)
  175. }
  176. }
  177. .two {
  178. position: relative;
  179. flex-grow: 1;
  180. padding: 0 2vw;
  181. margin: 0 0 2vw 0;
  182. .list {
  183. border: 1px solid var(--ff0Color);
  184. padding: 2vw;
  185. margin: 0 0 2vw 0;
  186. border-radius: 5px;
  187. .name {
  188. font-size: var(--font16Size);
  189. font-weight: bold;
  190. margin: 0 0 2vw 0;
  191. }
  192. .other {
  193. margin: 0 0 2vw 0;
  194. .other_1 {
  195. margin: 0 0 1vw 0;
  196. font-size: var(--font14Size);
  197. color: var(--f85Color);
  198. text:last-child {
  199. color: var(--f00Color);
  200. font-weight: bold;
  201. }
  202. }
  203. }
  204. .btn {
  205. text-align: center;
  206. button {
  207. margin: 0 2vw;
  208. background-color: var(--f35BColor);
  209. color: var(--fffColor);
  210. font-size: var(--font14Size);
  211. }
  212. .del {
  213. background-color: var(--ff0Color);
  214. }
  215. }
  216. }
  217. }
  218. }
  219. .scroll-view {
  220. position: absolute;
  221. top: 0;
  222. left: 0;
  223. right: 0;
  224. bottom: 0;
  225. .list-scroll-view {
  226. display: flex;
  227. flex-direction: column;
  228. }
  229. }
  230. .uni-dialog-content {
  231. padding: 2vw !important;
  232. }
  233. .uni-forms {
  234. width: 100vw !important;
  235. }
  236. </style>