FileList.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <el-row>
  3. <el-row>
  4. <el-form :inline="true" :model="searchForm" class="demo-form-inline">
  5. <el-form-item>
  6. <el-select v-model="searchForm.fileType" placeholder="文件类型" @change="search">
  7. <el-option label="全部" value="0" />
  8. <el-option label="图片" value="1" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-input v-model="searchForm.filename" placeholder="" />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button size="mini" type="warning" @click="search">查询</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-form :inline="true" class="demo-form-inline" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  19. <el-button size="mini" type="danger" @click="goToUpload">上传</el-button>
  20. <el-button size="mini" type="danger" @click="downloadFile">下载</el-button>
  21. <el-button size="mini" type="danger" @click="deleteMultiple">删除</el-button>
  22. <el-button size="mini" type="danger" @click="createNewFolder">新建文件夹</el-button>
  23. <el-button size="mini" type="danger" @click="move">移动</el-button>
  24. <el-button size="mini" type="danger" @click="move">复制</el-button>
  25. <el-button size="mini" type="danger" @click="share">分享</el-button>
  26. </el-form>
  27. <el-breadcrumb separator-class="el-icon-arrow-right" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  28. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  29. <el-breadcrumb-item :to="{ path: '/1' }">图片</el-breadcrumb-item>
  30. <el-breadcrumb-item :to="{ path: '/1/2' }">照片</el-breadcrumb-item>
  31. <el-breadcrumb-item v-text="this.$router.currentRoute.name"></el-breadcrumb-item>
  32. </el-breadcrumb>
  33. <el-table
  34. ref="multipleTable"
  35. :data="dataList"
  36. border
  37. style="width: 100%"
  38. @selection-change="handleSelectionChange"
  39. >
  40. <el-table-column
  41. type="selection"
  42. />
  43. <el-table-column
  44. prop="filename"
  45. label="文件名"
  46. width="400px"
  47. >
  48. <template slot-scope="scope">
  49. <a :href="scope.row.filename" style="text-decoration-line: none" target="_blank">
  50. <el-tooltip
  51. :content="scope.row.filename"
  52. raw-content
  53. placement="top-start"
  54. >
  55. <span v-if="scope.row.filename.length <= 60">
  56. {{ scope.row.filename }}
  57. </span>
  58. <span v-else>
  59. {{ scope.row.filename.substr(0, 55) + "..." }}
  60. </span>
  61. </el-tooltip>
  62. </a>
  63. </template>
  64. </el-table-column>
  65. <el-table-column
  66. prop="owner"
  67. label="修改时间"
  68. />
  69. <el-table-column
  70. prop="size"
  71. label="大小"
  72. />
  73. <el-table-column
  74. prop="fileType"
  75. label="文件类型"
  76. >
  77. <template slot-scope="scope">
  78. <el-tag v-if="scope.row.fileType === 1000" :type="'warning'" disable-transitions>
  79. 目录
  80. </el-tag>
  81. <el-tag v-if="scope.row.fileType === 1001" :type="'warning'" disable-transitions>
  82. 图片
  83. </el-tag>
  84. <el-tag v-else-if="scope.row.fileType === 1002" :type="'success'" disable-transitions>
  85. 视频
  86. </el-tag>
  87. <el-tag v-else-if="scope.row.fileType === 1003" :type="'danger'" disable-transitions>
  88. 音频
  89. </el-tag>
  90. <el-tag v-else-if="scope.row.fileType === 1004" :type="'danger'" disable-transitions>
  91. 文本
  92. </el-tag>
  93. <el-tag v-else :type="'danger'" disable-transitions>
  94. 其他
  95. </el-tag>
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. label="操作"
  100. >
  101. <template slot-scope="scope">
  102. <el-button
  103. size="mini"
  104. @click="cache(scope.row)"
  105. >详情</el-button>
  106. <el-button
  107. size="mini"
  108. @click="cache(scope.row)"
  109. >分享</el-button>
  110. <el-button
  111. size="mini"
  112. @click="cache(scope.row)"
  113. >删除</el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. </el-row>
  118. <el-row>
  119. <el-pagination
  120. background
  121. :small="screenWidth <= 768"
  122. layout="prev, pager, next"
  123. :page-size="pageSize"
  124. :current-page="currentPage"
  125. :total="totalSize"
  126. @current-change="handleCurrentChange"
  127. @prev-click="handleCurrentChange"
  128. @next-click="handleCurrentChange"
  129. />
  130. </el-row>
  131. <!--登录弹窗-->
  132. <el-dialog
  133. title="创建新目录"
  134. append-to-body
  135. :visible.sync="newFolderDialog"
  136. width="30%"
  137. center
  138. >
  139. <el-form ref="form" :model="newFolderForm">
  140. <el-form-item label="目录名">
  141. <el-input
  142. v-model="newFolderForm.newFolderName"
  143. placeholder="新目录名"
  144. style="width: 70%; padding-right: 2px"
  145. clearable
  146. />
  147. </el-form-item>
  148. <el-form-item>
  149. <el-button
  150. type="primary"
  151. @click.native="loginBtn"
  152. >创建</el-button>
  153. </el-form-item>
  154. </el-form>
  155. </el-dialog>
  156. </el-row>
  157. </template>
  158. <script>
  159. import { getFileList, deleteDiskFile } from '@/api/disk'
  160. export default {
  161. name: 'FileList',
  162. data() {
  163. return {
  164. // 屏幕宽度, 为了控制分页条的大小
  165. screenWidth: document.body.clientWidth,
  166. currentPage: 1,
  167. pageSize: 10,
  168. totalSize: 0,
  169. dataList: [],
  170. searchForm: {
  171. page: 1,
  172. fileType: '0',
  173. filename: null
  174. },
  175. multipleSelection: [],
  176. parentDirs: ['图片', '照片', '2023'],
  177. newFolderDialog: false,
  178. newFolderForm: {
  179. newFolderName: null
  180. }
  181. }
  182. },
  183. created() {
  184. document.title = '文件列表'
  185. this.getData()
  186. },
  187. methods: {
  188. handleCurrentChange(pageNumber) {
  189. this.currentPage = pageNumber
  190. this.searchForm.page = this.currentPage
  191. this.getData()
  192. // 回到顶部
  193. scrollTo(0, 0)
  194. },
  195. getData() {
  196. this.dataList = []
  197. getFileList(this.searchForm).then(resp => {
  198. if (resp.code === 0) {
  199. this.dataList = resp.data.list
  200. this.totalSize = resp.data.totalSize
  201. } else {
  202. this.$notify({
  203. title: '提示',
  204. message: resp.msg,
  205. type: 'warning',
  206. duration: 3000
  207. })
  208. }
  209. }).catch(error => {
  210. this.$notify({
  211. title: '提示',
  212. message: error.message,
  213. type: 'error',
  214. duration: 3000
  215. })
  216. })
  217. },
  218. cache(row) {
  219. },
  220. search() {
  221. this.currentPage = 1
  222. this.searchForm.page = this.currentPage
  223. this.getData(this.searchForm)
  224. },
  225. handleSelectionChange(val) {
  226. this.multipleSelection = val
  227. },
  228. goToUpload() {
  229. const path = '/disk/upload'
  230. if (this.$route.path === path) {
  231. this.$router.go(0)
  232. return
  233. }
  234. this.$router.push(path)
  235. },
  236. downloadFile() {
  237. console.log('下载文件')
  238. },
  239. deleteMultiple() {
  240. if (this.multipleSelection.length === 0) {
  241. this.$notify({
  242. message: '至少应选中一行',
  243. type: 'warning',
  244. duration: 3000
  245. })
  246. return
  247. }
  248. var fileIds = []
  249. for (const item of this.multipleSelection) {
  250. fileIds.push(item.fileId)
  251. }
  252. this.$confirm('确定要删除文件?', '提示', {
  253. confirmButtonText: '确定',
  254. cancelButtonText: '取消',
  255. type: 'warning'
  256. }).then(() => {
  257. deleteDiskFile(fileIds).then(resp => {
  258. if (resp.code === 0) {
  259. this.$refs.multipleTable.clearSelection()
  260. this.$notify({
  261. message: resp.msg,
  262. type: 'warning',
  263. duration: 3000
  264. })
  265. } else {
  266. this.$notify({
  267. title: '提示',
  268. message: resp.msg,
  269. type: 'warning',
  270. duration: 3000
  271. })
  272. }
  273. }).catch(error => {
  274. this.$notify({
  275. title: '提示',
  276. message: error.message,
  277. type: 'error',
  278. duration: 3000
  279. })
  280. })
  281. }).catch(() => {
  282. this.$message({
  283. type: 'info',
  284. message: '已取消'
  285. })
  286. })
  287. },
  288. createNewFolder() {
  289. this.newFolderDialog = true
  290. },
  291. move() {
  292. console.log('移动/复制文件')
  293. },
  294. share() {
  295. console.log('分享文件')
  296. }
  297. }
  298. }
  299. </script>
  300. <style>
  301. </style>