oss.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page="page"
  7. :permission="permissionList"
  8. v-model="form"
  9. ref="crud"
  10. @row-update="rowUpdate"
  11. @row-save="rowSave"
  12. @row-del="rowDel"
  13. :before-open="beforeOpen"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad">
  21. <template slot="menuLeft">
  22. <el-button type="danger"
  23. size="small"
  24. icon="el-icon-delete"
  25. plain
  26. v-if="permission.oss_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot-scope="scope" slot="menu">
  31. <el-button type="text"
  32. icon="el-icon-check"
  33. size="small"
  34. v-if="permission.oss_enable"
  35. @click.stop="handleEnable(scope.row)">启用
  36. </el-button>
  37. </template>
  38. <template slot-scope="{row}"
  39. slot="status">
  40. <el-tag>{{row.statusName}}</el-tag>
  41. </template>
  42. <template slot-scope="{row}"
  43. slot="category">
  44. <el-tag>{{row.categoryName}}</el-tag>
  45. </template>
  46. </avue-crud>
  47. </basic-container>
  48. </template>
  49. <script>
  50. import {getList, getDetail, add, update, remove, enable} from "@/api/resource/oss";
  51. import {mapGetters} from "vuex";
  52. import func from "@/util/func";
  53. export default {
  54. data() {
  55. return {
  56. form: {},
  57. query: {},
  58. loading: true,
  59. page: {
  60. pageSize: 10,
  61. currentPage: 1,
  62. total: 0
  63. },
  64. selectionList: [],
  65. option: {
  66. height: 'auto',
  67. calcHeight: 30,
  68. tip: false,
  69. searchShow: true,
  70. searchMenuSpan: 6,
  71. border: true,
  72. index: true,
  73. viewBtn: true,
  74. selection: true,
  75. labelWidth: 100,
  76. dialogWidth: 880,
  77. column: [
  78. {
  79. label: "分类",
  80. type: "radio",
  81. value: 1,
  82. span: 24,
  83. width: 100,
  84. searchLabelWidth: 50,
  85. row: true,
  86. dicUrl: "/api/blade-system/dict/dictionary?code=oss",
  87. props: {
  88. label: "dictValue",
  89. value: "dictKey"
  90. },
  91. dataType: "number",
  92. slot: true,
  93. prop: "category",
  94. search: true,
  95. rules: [{
  96. required: true,
  97. message: "请选择分类",
  98. trigger: "blur"
  99. }]
  100. },
  101. {
  102. label: "资源编号",
  103. prop: "ossCode",
  104. span: 24,
  105. width: 120,
  106. search: true,
  107. rules: [{
  108. required: true,
  109. message: "请输入资源编号",
  110. trigger: "blur"
  111. }]
  112. },
  113. {
  114. label: "资源地址",
  115. prop: "endpoint",
  116. span: 24,
  117. rules: [{
  118. required: true,
  119. message: "请输入资源地址",
  120. trigger: "blur"
  121. }]
  122. },
  123. {
  124. label: "空间名",
  125. prop: "bucketName",
  126. span: 24,
  127. width: 120,
  128. rules: [{
  129. required: true,
  130. message: "请输入空间名",
  131. trigger: "blur"
  132. }]
  133. },
  134. {
  135. label: "accessKey",
  136. prop: "accessKey",
  137. span: 24,
  138. search: true,
  139. width: 200,
  140. overHidden: true,
  141. rules: [{
  142. required: true,
  143. message: "请输入accessKey",
  144. trigger: "blur"
  145. }]
  146. },
  147. {
  148. label: "secretKey",
  149. prop: "secretKey",
  150. span: 24,
  151. width: 200,
  152. overHidden: true,
  153. rules: [{
  154. required: true,
  155. message: "请输入secretKey",
  156. trigger: "blur"
  157. }]
  158. },
  159. {
  160. label: "appId",
  161. prop: "appId",
  162. span: 24,
  163. hide: true,
  164. display: false,
  165. },
  166. {
  167. label: "region",
  168. prop: "region",
  169. span: 24,
  170. hide: true,
  171. display: false,
  172. },
  173. {
  174. label: "是否启用",
  175. prop: "status",
  176. span: 24,
  177. width: 80,
  178. slot: true,
  179. addDisplay: false,
  180. editDisplay: false,
  181. viewDisplay: false,
  182. },
  183. {
  184. label: "备注",
  185. prop: "remark",
  186. span: 24,
  187. hide: true,
  188. },
  189. ]
  190. },
  191. data: []
  192. };
  193. },
  194. watch: {
  195. 'form.category'() {
  196. const category = func.toInt(this.form.category);
  197. this.$refs.crud.option.column.filter(item => {
  198. if (item.prop === "appId") {
  199. item.display = category === 4;
  200. }
  201. if (item.prop === "region") {
  202. item.display = category === 4;
  203. }
  204. });
  205. }
  206. },
  207. computed: {
  208. ...mapGetters(["permission"]),
  209. permissionList() {
  210. return {
  211. addBtn: this.vaildData(this.permission.oss_add),
  212. viewBtn: this.vaildData(this.permission.oss_view),
  213. delBtn: this.vaildData(this.permission.oss_delete),
  214. editBtn: this.vaildData(this.permission.oss_edit)
  215. };
  216. },
  217. ids() {
  218. let ids = [];
  219. this.selectionList.forEach(ele => {
  220. ids.push(ele.id);
  221. });
  222. return ids.join(",");
  223. }
  224. },
  225. methods: {
  226. rowSave(row, loading, done) {
  227. add(row).then(() => {
  228. loading();
  229. this.onLoad(this.page);
  230. this.$message({
  231. type: "success",
  232. message: "操作成功!"
  233. });
  234. }, error => {
  235. done();
  236. console.log(error);
  237. });
  238. },
  239. rowUpdate(row, index, loading, done) {
  240. update(row).then(() => {
  241. loading();
  242. this.onLoad(this.page);
  243. this.$message({
  244. type: "success",
  245. message: "操作成功!"
  246. });
  247. }, error => {
  248. done();
  249. console.log(error);
  250. });
  251. },
  252. rowDel(row) {
  253. this.$confirm("确定将选择数据删除?", {
  254. confirmButtonText: "确定",
  255. cancelButtonText: "取消",
  256. type: "warning"
  257. })
  258. .then(() => {
  259. return remove(row.id);
  260. })
  261. .then(() => {
  262. this.onLoad(this.page);
  263. this.$message({
  264. type: "success",
  265. message: "操作成功!"
  266. });
  267. });
  268. },
  269. searchReset() {
  270. this.query = {};
  271. this.onLoad(this.page);
  272. },
  273. searchChange(params, done) {
  274. this.query = params;
  275. this.page.currentPage = 1;
  276. this.onLoad(this.page, params);
  277. done();
  278. },
  279. selectionChange(list) {
  280. this.selectionList = list;
  281. },
  282. selectionClear() {
  283. this.selectionList = [];
  284. this.$refs.crud.toggleSelection();
  285. },
  286. handleEnable(row) {
  287. this.$confirm("是否确定启用这条配置?", {
  288. confirmButtonText: "确定",
  289. cancelButtonText: "取消",
  290. type: "warning"
  291. })
  292. .then(() => {
  293. return enable(row.id);
  294. })
  295. .then(() => {
  296. this.onLoad(this.page);
  297. this.$message({
  298. type: "success",
  299. message: "操作成功!"
  300. });
  301. this.$refs.crud.toggleSelection();
  302. });
  303. },
  304. handleDelete() {
  305. if (this.selectionList.length === 0) {
  306. this.$message.warning("请选择至少一条数据");
  307. return;
  308. }
  309. this.$confirm("确定将选择数据删除?", {
  310. confirmButtonText: "确定",
  311. cancelButtonText: "取消",
  312. type: "warning"
  313. })
  314. .then(() => {
  315. return remove(this.ids);
  316. })
  317. .then(() => {
  318. this.onLoad(this.page);
  319. this.$message({
  320. type: "success",
  321. message: "操作成功!"
  322. });
  323. this.$refs.crud.toggleSelection();
  324. });
  325. },
  326. beforeOpen(done, type) {
  327. if (["edit", "view"].includes(type)) {
  328. getDetail(this.form.id).then(res => {
  329. this.form = res.data.data;
  330. });
  331. }
  332. done();
  333. },
  334. currentChange(currentPage) {
  335. this.page.currentPage = currentPage;
  336. },
  337. sizeChange(pageSize) {
  338. this.page.pageSize = pageSize;
  339. },
  340. refreshChange() {
  341. this.onLoad(this.page, this.query);
  342. },
  343. onLoad(page, params = {}) {
  344. this.loading = true;
  345. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  346. const data = res.data.data;
  347. this.page.total = data.total;
  348. this.data = data.records;
  349. this.loading = false;
  350. this.selectionClear();
  351. });
  352. }
  353. }
  354. };
  355. </script>