FileList.vue 5.7 KB

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