attach.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. v-model="form"
  10. ref="crud"
  11. @row-del="rowDel"
  12. @search-change="searchChange"
  13. @search-reset="searchReset"
  14. @selection-change="selectionChange"
  15. @current-change="currentChange"
  16. @size-change="sizeChange"
  17. @refresh-change="refreshChange"
  18. @on-load="onLoad">
  19. <template slot="menuLeft">
  20. <el-button type="primary"
  21. size="small"
  22. plain
  23. v-if="permission.attach_upload"
  24. icon="el-icon-upload2"
  25. @click="handleUpload">上 传
  26. </el-button>
  27. <el-button type="danger"
  28. size="small"
  29. icon="el-icon-delete"
  30. plain
  31. v-if="permission.attach_delete"
  32. @click="handleDelete">删 除
  33. </el-button>
  34. </template>
  35. <template slot-scope="scope" slot="menu">
  36. <el-button type="text"
  37. icon="el-icon-download"
  38. size="small"
  39. v-if="permission.attach_download"
  40. @click="handleDownload(scope.row)">下载
  41. </el-button>
  42. </template>
  43. <template slot-scope="{row}"
  44. slot="attachSize">
  45. <el-tag>{{`${row.attachSize} KB`}}</el-tag>
  46. </template>
  47. </avue-crud>
  48. <el-dialog title="附件管理"
  49. append-to-body
  50. :visible.sync="attachBox"
  51. width="555px">
  52. <avue-form ref="form" :option="attachOption" v-model="attachForm" :upload-after="uploadAfter">
  53. </avue-form>
  54. </el-dialog>
  55. </basic-container>
  56. </template>
  57. <script>
  58. import {getList, getDetail, remove} from "@/api/resource/attach";
  59. import {mapGetters} from "vuex";
  60. export default {
  61. data() {
  62. return {
  63. form: {},
  64. query: {},
  65. loading: true,
  66. page: {
  67. pageSize: 10,
  68. currentPage: 1,
  69. total: 0
  70. },
  71. attachBox: false,
  72. selectionList: [],
  73. option: {
  74. height: 'auto',
  75. calcHeight: 30,
  76. tip: false,
  77. searchShow: true,
  78. searchMenuSpan: 6,
  79. border: true,
  80. index: true,
  81. viewBtn: true,
  82. selection: true,
  83. dialogClickModal: false,
  84. column: [
  85. {
  86. label: "附件地址",
  87. prop: "link",
  88. rules: [{
  89. required: true,
  90. message: "请输入附件地址",
  91. trigger: "blur"
  92. }]
  93. },
  94. {
  95. label: "附件域名",
  96. prop: "domain",
  97. search: true,
  98. rules: [{
  99. required: true,
  100. message: "请输入附件域名",
  101. trigger: "blur"
  102. }]
  103. },
  104. {
  105. label: "附件名称",
  106. prop: "name",
  107. search: true,
  108. rules: [{
  109. required: true,
  110. message: "请输入附件名称",
  111. trigger: "blur"
  112. }]
  113. },
  114. {
  115. label: "附件原名",
  116. prop: "originalName",
  117. search: true,
  118. rules: [{
  119. required: true,
  120. message: "请输入附件原名",
  121. trigger: "blur"
  122. }]
  123. },
  124. {
  125. label: "附件拓展名",
  126. prop: "extension",
  127. rules: [{
  128. required: true,
  129. message: "请输入附件拓展名",
  130. trigger: "blur"
  131. }]
  132. },
  133. {
  134. label: "附件大小",
  135. prop: "attachSize",
  136. slot: true,
  137. rules: [{
  138. required: true,
  139. message: "请输入附件大小",
  140. trigger: "blur"
  141. }]
  142. },
  143. ]
  144. },
  145. data: [],
  146. attachForm: {},
  147. attachOption: {
  148. submitBtn: false,
  149. emptyBtn: false,
  150. column: [
  151. {
  152. label: '附件上传',
  153. prop: 'attachFile',
  154. type: 'upload',
  155. drag: true,
  156. loadText: '模板上传中,请稍等',
  157. span: 24,
  158. propsHttp: {
  159. res: 'data'
  160. },
  161. action: "/api/blade-resource/oss/endpoint/put-file-attach"
  162. }
  163. ]
  164. }
  165. };
  166. },
  167. computed: {
  168. ...mapGetters(["permission"]),
  169. permissionList() {
  170. return {
  171. addBtn: false,
  172. editBtn: false,
  173. viewBtn: false,
  174. delBtn: this.vaildData(this.permission.attach_delete, false)
  175. };
  176. },
  177. ids() {
  178. let ids = [];
  179. this.selectionList.forEach(ele => {
  180. ids.push(ele.id);
  181. });
  182. return ids.join(",");
  183. }
  184. },
  185. methods: {
  186. handleUpload() {
  187. this.attachBox = true;
  188. },
  189. uploadAfter(res, done, loading, column) {
  190. window.console.log(column);
  191. this.attachBox = false;
  192. this.refreshChange();
  193. done();
  194. },
  195. handleDownload(row) {
  196. window.open(`${row.link}`);
  197. },
  198. rowDel(row) {
  199. this.$confirm("确定将选择数据删除?", {
  200. confirmButtonText: "确定",
  201. cancelButtonText: "取消",
  202. type: "warning"
  203. })
  204. .then(() => {
  205. return remove(row.id);
  206. })
  207. .then(() => {
  208. this.onLoad(this.page);
  209. this.$message({
  210. type: "success",
  211. message: "操作成功!"
  212. });
  213. });
  214. },
  215. handleDelete() {
  216. if (this.selectionList.length === 0) {
  217. this.$message.warning("请选择至少一条数据");
  218. return;
  219. }
  220. this.$confirm("确定将选择数据删除?", {
  221. confirmButtonText: "确定",
  222. cancelButtonText: "取消",
  223. type: "warning"
  224. })
  225. .then(() => {
  226. return remove(this.ids);
  227. })
  228. .then(() => {
  229. this.onLoad(this.page);
  230. this.$message({
  231. type: "success",
  232. message: "操作成功!"
  233. });
  234. this.$refs.crud.toggleSelection();
  235. });
  236. },
  237. beforeOpen(done, type) {
  238. if (["edit", "view"].includes(type)) {
  239. getDetail(this.form.id).then(res => {
  240. this.form = res.data.data;
  241. });
  242. }
  243. done();
  244. },
  245. searchReset() {
  246. this.query = {};
  247. this.onLoad(this.page);
  248. },
  249. searchChange(params, done) {
  250. this.query = params;
  251. this.page.currentPage = 1;
  252. this.onLoad(this.page, params);
  253. done();
  254. },
  255. selectionChange(list) {
  256. this.selectionList = list;
  257. },
  258. selectionClear() {
  259. this.selectionList = [];
  260. this.$refs.crud.toggleSelection();
  261. },
  262. currentChange(currentPage) {
  263. this.page.currentPage = currentPage;
  264. },
  265. sizeChange(pageSize) {
  266. this.page.pageSize = pageSize;
  267. },
  268. refreshChange() {
  269. this.onLoad(this.page, this.query);
  270. },
  271. onLoad(page, params = {}) {
  272. this.loading = true;
  273. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  274. const data = res.data.data;
  275. this.page.total = data.total;
  276. this.data = data.records;
  277. this.loading = false;
  278. this.selectionClear();
  279. });
  280. }
  281. }
  282. };
  283. </script>
  284. <style>
  285. </style>