index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <anji-crud ref="listPage" :option="crudOption">
  3. <template v-slot:buttonLeftOnTable>
  4. <el-upload class="el-upload" ref="upload" :action="uploadUrl" :headers="headers" :on-success="handleUpload" :on-error="handleError" :show-file-list="false" :limit="1">
  5. <el-button type="primary" icon="el-icon" v-permission="'fileManage:upload'">文件上传</el-button>
  6. </el-upload>
  7. </template>
  8. <template slot="rowButton" slot-scope="props">
  9. <el-button type="text" @click="customButtom(props)">下载</el-button>
  10. </template>
  11. </anji-crud>
  12. </template>
  13. <script>
  14. import { fileList, fileAdd, fileDel, fileUpdate, fileDetail } from '@/api/file'
  15. import { getToken } from '@/utils/auth'
  16. export default {
  17. name: 'File',
  18. components: {
  19. anjiCrud: require('@/components/AnjiPlus/anji-crud/anji-crud').default,
  20. },
  21. data() {
  22. return {
  23. selectedList: [],
  24. uploadUrl: process.env.BASE_API + '/file/upload',
  25. crudOption: {
  26. // 使用菜单做为页面标题
  27. title: '文件管理',
  28. // 详情页中输入框左边文字宽度
  29. labelWidth: '120px',
  30. // 查询表单条件
  31. queryFormFields: [
  32. {
  33. inputType: 'input',
  34. label: '文件路径',
  35. field: 'filePath',
  36. },
  37. ],
  38. // 操作按钮
  39. buttons: {
  40. query: {
  41. api: fileList,
  42. permission: 'fileManage:query',
  43. sort: 'create_time',
  44. order: 'DESC',
  45. },
  46. queryByPrimarykey: {
  47. api: fileDetail,
  48. permission: 'fileManage:query',
  49. },
  50. add: {
  51. api: fileAdd,
  52. permission: 'fileManage:upload',
  53. isShow: false,
  54. },
  55. delete: {
  56. api: fileDel,
  57. permission: 'fileManage:delete',
  58. },
  59. edit: {
  60. api: fileUpdate,
  61. permission: 'fileManage:update',
  62. isShow: false,
  63. },
  64. // 自定义按钮
  65. customButton: {
  66. operationWidth: 100, // row自定义按钮表格宽度
  67. },
  68. },
  69. // 表格列
  70. columns: [
  71. {
  72. label: '',
  73. field: 'id',
  74. primaryKey: true, // 根据主键查询详情或者根据主键删除时, 主键的
  75. tableHide: true, // 表格中不显示
  76. editHide: true, // 编辑弹框中不显示
  77. },
  78. {
  79. // 以下为表格的配置
  80. label: '图片缩略图', // 列名称,必填
  81. field: 'urlPath', // 字段名,必填
  82. columnType: 'imgPreview', // 图片 不设置默认text
  83. editHide: true, // 编辑弹框中不显示
  84. // 以下为编辑查看弹框的配置
  85. // inputType: 'input', // 编辑查看表单组件类型 input anji-select
  86. placeholder: '',
  87. disabled: false,
  88. },
  89. {
  90. label: '文件标识', // 文件标识
  91. placeholder: '',
  92. field: 'fileId',
  93. editField: 'fileId',
  94. tableHide: true, // 表格中不显示
  95. inputType: 'input',
  96. rules: [{ min: 1, max: 64, message: '不超过64个字符', trigger: 'blur' }],
  97. disabled: false,
  98. },
  99. {
  100. label: '文件类型', // 文件路径
  101. placeholder: '',
  102. field: 'fileType',
  103. editField: 'fileType',
  104. inputType: 'input',
  105. rules: [{ min: 1, max: 1024, message: '不超过1024个字符', trigger: 'blur' }],
  106. disabled: false,
  107. },
  108. {
  109. label: '文件路径', // 文件路径
  110. placeholder: '',
  111. field: 'filePath',
  112. editField: 'filePath',
  113. inputType: 'input',
  114. rules: [{ min: 1, max: 1024, message: '不超过1024个字符', trigger: 'blur' }],
  115. disabled: false,
  116. },
  117. {
  118. label: 'url路径', // url路径
  119. placeholder: '',
  120. field: 'urlPath',
  121. editField: 'urlPath',
  122. inputType: 'input',
  123. rules: [{ min: 1, max: 1024, message: '不超过1024个字符', trigger: 'blur' }],
  124. disabled: false,
  125. },
  126. {
  127. label: '内容说明', // 内容说明
  128. placeholder: '',
  129. field: 'fileInstruction',
  130. editField: 'fileInstruction',
  131. inputType: 'input',
  132. rules: [{ min: 1, max: 1024, message: '不超过1024个字符', trigger: 'blur' }],
  133. disabled: false,
  134. },
  135. {
  136. label: '创建人',
  137. field: 'createByView',
  138. columnType: 'expand', // 表格中放在可展开行中
  139. inputType: 'input', // 编辑和查看详情中显示的input
  140. disabled: true, // 编辑和查看详情中不可编辑
  141. },
  142. {
  143. label: '创建时间',
  144. field: 'createTime',
  145. columnType: 'expand',
  146. inputType: 'input',
  147. disabled: true,
  148. },
  149. ],
  150. },
  151. }
  152. },
  153. computed: {
  154. headers() {
  155. return {
  156. Authorization: getToken(), // 直接从本地获取token就行
  157. }
  158. },
  159. },
  160. created() {},
  161. methods: {
  162. // 上传成功的回调
  163. handleUpload(response, file, fileList) {
  164. console.log(this)
  165. // 触发查询按钮
  166. this.$refs.listPage.handleQueryForm()
  167. //清除el-upload组件中的文件
  168. this.$refs.upload.clearFiles()
  169. },
  170. handleError() {
  171. this.$message({
  172. message: '上传失败!',
  173. type: 'error',
  174. })
  175. },
  176. async downloadFile(row) {
  177. window.open(row.urlPath)
  178. },
  179. customButtom(val) {
  180. this.downloadFile(val.msg)
  181. },
  182. },
  183. }
  184. </script>
  185. <style scoped lang="scss">
  186. .el-upload {
  187. display: inline-block;
  188. }
  189. </style>