index.vue 6.9 KB

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