FileList.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="content-container">
  3. <el-row class="tool-bar">
  4. <el-col :span="12" class="left">
  5. <div class="content-title">
  6. <i class="el-icon-folder" /> {{ title }}
  7. </div>
  8. </el-col>
  9. <el-col :span="8" class="right">
  10. <el-input v-model="conditions.keywords" class="search-input m-right-15" placeholder="请输入内容">
  11. <el-button slot="append" icon="el-icon-search" @click="getData()" />
  12. </el-input>
  13. </el-col>
  14. <el-col :span="4" class="right">
  15. <el-upload
  16. multiple
  17. :http-request="handleUploadFile"
  18. :before-upload="beforeFileUpload"
  19. :show-file-list="false"
  20. action=""
  21. >
  22. <el-button size="small" type="primary">上传</el-button>
  23. </el-upload>
  24. </el-col>
  25. </el-row>
  26. <el-row class="content-body">
  27. <el-table v-loading="listLoading" class="page-table" border :data="dataList" height="calc(100vh - 260px)">
  28. <el-table-column type="index" label="序号" width="80" header-align="center" align="center" />
  29. <el-table-column prop="fileTitle" label="文件名称" header-align="left" align="left">
  30. <template v-slot="{row}">
  31. <el-link target="_blank" :href="row.fileUrl" dowload>
  32. <i class="el-icon-document" />
  33. {{ row.fileTitle }}
  34. </el-link>
  35. </template>
  36. </el-table-column>
  37. <el-table-column prop="uploaderName" width="160" label="上传人" header-align="center" align="center">
  38. <template v-slot="{row}">
  39. <span>{{ row.uploaderName }}</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column prop="uploadedAt" width="180" label="上传时间" header-align="center" align="center">
  43. <template v-slot="{row}">
  44. <span><i class="el-icon-time" /> {{ row.uploadedAt }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="操作" width="180" header-align="center" align="center">
  48. <template v-slot="{row}">
  49. <label style="display:inline-block;margin-right:5px">
  50. <el-button size="mini" type="primary" icon="el-icon-download">
  51. <a target="_blank" :href="row.fileUrl" dowload>下载</a>
  52. </el-button>
  53. </label>
  54. <el-button size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <div class="pagination-container">
  59. <pagination v-show="total>0" :total="total" :page.sync="conditions.page" :limit.sync="conditions.limit" @pagination="getData" />
  60. </div>
  61. </el-row>
  62. <File ref="AddFile" @formSuccess="getData" />
  63. <File ref="UpdateFile" title="修改文件" @formSuccess="getData" />
  64. </div>
  65. </template>
  66. <script>
  67. import File from './File'
  68. import { getFileByPage, deleteFile } from '@/api/system/docApi'
  69. import { mapGetters } from 'vuex'
  70. import Pagination from '@/components/Pagination'
  71. import { uploadFile } from '@/api/system/uploadApi'
  72. export default {
  73. name: 'FileList',
  74. components: {
  75. Pagination,
  76. File
  77. },
  78. data() {
  79. return {
  80. title: '',
  81. dataList: [],
  82. listLoading: false,
  83. total: 0,
  84. conditions: {
  85. page: 1,
  86. limit: 10,
  87. keywords: '',
  88. dirId: ''
  89. }
  90. }
  91. },
  92. computed: {
  93. ...mapGetters([
  94. 'userData'
  95. ])
  96. },
  97. methods: {
  98. loadData(dirId, dirTitle) {
  99. this.title = dirTitle
  100. this.conditions.dirId = dirId
  101. this.getData()
  102. },
  103. getData() {
  104. this.listLoading = true
  105. getFileByPage(this.conditions).then((resp) => {
  106. this.listLoading = false
  107. const { data, total } = resp
  108. this.total = total
  109. this.dataList = data
  110. }).catch((error) => {
  111. console.log(error)
  112. })
  113. },
  114. // 添加
  115. handleAdd() {
  116. this.$refs['AddFile'].showAddModel(this.conditions.dirId)
  117. },
  118. // 编辑
  119. handleEdit(data) {
  120. this.$refs['UpdateFile'].showEditModel(data.fileId)
  121. },
  122. // 删除/
  123. handleDelete(data) {
  124. this.$confirm(`此操作将删除该数据${data.fileTitle}, 是否继续?`, '提示', {
  125. confirmButtonText: '确定',
  126. cancelButtonText: '取消',
  127. type: 'warning'
  128. }).then(() => {
  129. deleteFile(data.fileId).then((resp) => {
  130. this.getData()
  131. })
  132. }).catch(() => {
  133. this.$message({ type: 'info', message: '已取消删除' })
  134. })
  135. },
  136. beforeFileUpload(file) {
  137. const isLt5M = file.size / 1024 / 1024 < 5
  138. if (!isLt5M) {
  139. this.$message.error('上传文件大小不能超过 5MB!')
  140. }
  141. return isLt5M
  142. },
  143. // 上传文件
  144. handleUploadFile({ file }) {
  145. const formData = new FormData()
  146. formData.append('file', file)
  147. this.listLoading = true
  148. if (this.conditions.dirId) { formData.append('dirId', this.conditions.dirId) }
  149. uploadFile(formData).then((resp) => {
  150. this.listLoading = false
  151. this.getData()
  152. }).catch(() => {
  153. this.listLoading = false
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. </style>
  161. <style lang="scss" scoped>
  162. .content-container {
  163. margin: 10px 10px 10px 10px;
  164. height: calc(100vh - 86px);
  165. }
  166. .right{
  167. display: flex;
  168. justify-content: flex-end;
  169. flex-wrap: wrap;
  170. align-items: center;
  171. }
  172. </style>