FileList.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <route lang="yaml">
  2. meta:
  3. enabled: false
  4. </route>
  5. <script lang="ts" setup>
  6. import { ElMessage, ElMessageBox } from 'element-plus'
  7. import { deleteFileById, getFileByPage } from '@/api/system/docApi'
  8. import { uploadFile } from '@/api/system/uploadApi'
  9. const state = reactive({
  10. listLoading: false,
  11. dataList: [],
  12. search: {
  13. dirId: -1,
  14. keywords: '',
  15. },
  16. })
  17. // 获取数据
  18. const getData = async () => {
  19. if (state.search.dirId > 0) {
  20. state.listLoading = true
  21. const { data } = await getFileByPage(state.search)
  22. state.listLoading = false
  23. state.dataList = data
  24. }
  25. }
  26. const fileTableRef = ref()
  27. // 查询
  28. const onSearch = () => {
  29. getData()
  30. }
  31. // 下载
  32. const onDownload = (row: any) => {
  33. }
  34. // 删除
  35. const onDelete = (row: any) => {
  36. const { fileId, fileTitle } = row
  37. ElMessageBox.confirm(`确认删除「${fileTitle}」吗?`, '确认信息').then(async () => {
  38. const { msg } = await deleteFileById(fileId)
  39. ElMessage.success(msg)
  40. await getData()
  41. })
  42. }
  43. function beforeFileUpload(file: any) {
  44. const isLt5M = file.size / 1024 / 1024 < 5
  45. if (!isLt5M) {
  46. ElMessage.error('上传文件大小不能超过 5MB!')
  47. }
  48. return isLt5M
  49. }
  50. // 上传文件
  51. const onUpload = async (param: any) => {
  52. const formData = new FormData()
  53. formData.append('uploadfile', param.file)
  54. if (state.search.dirId) {
  55. formData.append('dirId', state.search.dirId.toString())
  56. }
  57. await uploadFile(formData)
  58. await getData()
  59. }
  60. defineExpose({
  61. loadData(dirId: number) {
  62. state.search.dirId = dirId
  63. getData()
  64. },
  65. })
  66. </script>
  67. <template>
  68. <div class="container">
  69. <tool-bar>
  70. <template #left>
  71. <span />
  72. </template>
  73. <template #right>
  74. <el-input v-model="state.search.keywords" placeholder="请输入名称,支持模糊查询" clearable />
  75. <el-button type="primary" style="padding-right: 10px;" @click="onSearch">
  76. <template #icon>
  77. <el-icon>
  78. <svg-icon name="i-ep:search" />
  79. </el-icon>
  80. </template>
  81. </el-button>
  82. <el-upload
  83. action
  84. multiple
  85. :http-request="onUpload"
  86. :before-upload="beforeFileUpload"
  87. :show-file-list="false"
  88. >
  89. <el-button type="primary" style="padding-left: 10px;">
  90. 上传
  91. </el-button>
  92. </el-upload>
  93. </template>
  94. </tool-bar>
  95. <el-table ref="fileTableRef" v-loading="state.loading" class="list-table" size="small" :data="state.dataList" border stripe highlight-current-row>
  96. <el-table-column type="index" align="center" label="序号" width="70" />
  97. <el-table-column prop="fileTitle" label="文件名称" align="center" header-align="center">
  98. <template #default="scope">
  99. <el-link target="_blank" :href="scope.row.fileUrl" dowload>
  100. <i class="el-icon-document" />
  101. {{ scope.row.fileTitle }}
  102. </el-link>
  103. </template>
  104. </el-table-column>
  105. <el-table-column prop="uploaderName" width="160" label="上传人" header-align="center" align="center">
  106. <template #default="scope">
  107. <span>{{ scope.row.uploaderName }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column prop="uploadedAt" width="180" label="上传时间" header-align="center" align="center">
  111. <template #default="scope">
  112. <span><i class="el-icon-time" /> {{ scope.row.uploadedAt }}</span>
  113. </template>
  114. </el-table-column>
  115. <el-table-column label="操作" width="180" align="center" fixed="right">
  116. <template #default="scope">
  117. <div>
  118. <el-button plain size="small" @click="open('{{ scope.row.fileUrl }}')">
  119. <template #icon>
  120. <el-icon>
  121. <svg-icon name="i-ep:link" />
  122. </el-icon>
  123. </template>
  124. 下载
  125. </el-button>
  126. <el-button v-if="!scope.row.isFixed" type="danger" size="small" plain @click="onDelete(scope.row)">
  127. <template #icon>
  128. <el-icon>
  129. <svg-icon name="ep:delete" />
  130. </el-icon>
  131. </template>
  132. 删除
  133. </el-button>
  134. </div>
  135. </template>
  136. </el-table-column>
  137. </el-table>
  138. </div>
  139. </template>