oss.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page.sync="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-video-play"
  33. size="small"
  34. v-if="userInfo.role_name.includes('admin')"
  35. @click="handleDebug(scope.row)">调试
  36. </el-button>
  37. <el-button type="text"
  38. icon="el-icon-circle-check"
  39. size="small"
  40. v-if="permission.oss_enable"
  41. @click.stop="handleEnable(scope.row)">启用
  42. </el-button>
  43. </template>
  44. <template slot-scope="{row}"
  45. slot="status">
  46. <el-tag>{{row.statusName}}</el-tag>
  47. </template>
  48. <template slot-scope="{row}"
  49. slot="category">
  50. <el-tag>{{row.categoryName}}</el-tag>
  51. </template>
  52. </avue-crud>
  53. <el-dialog title="对象存储上传调试"
  54. append-to-body
  55. :visible.sync="box"
  56. width="550px">
  57. <avue-form ref="form" :option="debugOption" v-model="debugForm" @submit="handleSubmit"/>
  58. </el-dialog>
  59. </basic-container>
  60. </template>
  61. <script>
  62. import {getList, getDetail, add, update, remove, enable} from "@/api/resource/oss";
  63. import {mapGetters} from "vuex";
  64. import func from "@/util/func";
  65. export default {
  66. data() {
  67. return {
  68. form: {},
  69. query: {},
  70. loading: true,
  71. box: false,
  72. page: {
  73. pageSize: 10,
  74. currentPage: 1,
  75. total: 0
  76. },
  77. selectionList: [],
  78. option: {
  79. height: 'auto',
  80. calcHeight: 30,
  81. tip: false,
  82. searchShow: true,
  83. searchMenuSpan: 6,
  84. border: true,
  85. index: true,
  86. viewBtn: true,
  87. selection: true,
  88. menuWidth: 300,
  89. labelWidth: 100,
  90. dialogWidth: 880,
  91. dialogClickModal: false,
  92. column: [
  93. {
  94. label: "分类",
  95. type: "radio",
  96. value: 1,
  97. span: 24,
  98. width: 100,
  99. searchLabelWidth: 50,
  100. row: true,
  101. dicUrl: "/api/blade-system/dict/dictionary?code=oss",
  102. props: {
  103. label: "dictValue",
  104. value: "dictKey"
  105. },
  106. dataType: "number",
  107. slot: true,
  108. prop: "category",
  109. search: true,
  110. rules: [{
  111. required: true,
  112. message: "请选择分类",
  113. trigger: "blur"
  114. }]
  115. },
  116. {
  117. label: "租户号",
  118. prop: "tenantId",
  119. span: 24,
  120. width: 120,
  121. search: true,
  122. rules: [{
  123. required: true,
  124. message: "请输入租户号",
  125. trigger: "blur"
  126. }]
  127. },
  128. {
  129. label: "资源编号",
  130. prop: "ossCode",
  131. span: 24,
  132. width: 120,
  133. search: true,
  134. rules: [{
  135. required: true,
  136. message: "请输入资源编号",
  137. trigger: "blur"
  138. }]
  139. },
  140. {
  141. label: "资源地址",
  142. prop: "endpoint",
  143. span: 24,
  144. rules: [{
  145. required: true,
  146. message: "请输入资源地址",
  147. trigger: "blur"
  148. }]
  149. },
  150. {
  151. label: "空间名",
  152. prop: "bucketName",
  153. span: 24,
  154. width: 120,
  155. rules: [{
  156. required: true,
  157. message: "请输入空间名",
  158. trigger: "blur"
  159. }]
  160. },
  161. {
  162. label: "accessKey",
  163. prop: "accessKey",
  164. span: 24,
  165. search: true,
  166. width: 200,
  167. overHidden: true,
  168. rules: [{
  169. required: true,
  170. message: "请输入accessKey",
  171. trigger: "blur"
  172. }]
  173. },
  174. {
  175. label: "secretKey",
  176. prop: "secretKey",
  177. span: 24,
  178. width: 200,
  179. overHidden: true,
  180. rules: [{
  181. required: true,
  182. message: "请输入secretKey",
  183. trigger: "blur"
  184. }]
  185. },
  186. {
  187. label: "appId",
  188. prop: "appId",
  189. span: 24,
  190. hide: true,
  191. display: false,
  192. },
  193. {
  194. label: "region",
  195. prop: "region",
  196. span: 24,
  197. hide: true,
  198. display: false,
  199. },
  200. {
  201. label: "是否启用",
  202. prop: "status",
  203. span: 24,
  204. width: 80,
  205. align: "center",
  206. slot: true,
  207. addDisplay: false,
  208. editDisplay: false,
  209. viewDisplay: false,
  210. },
  211. {
  212. label: "备注",
  213. prop: "remark",
  214. span: 24,
  215. hide: true,
  216. },
  217. ]
  218. },
  219. data: [],
  220. debugForm: {
  221. code: '',
  222. },
  223. debugOption: {
  224. submitText: "提交",
  225. column: [
  226. {
  227. label: "资源编号",
  228. prop: "code",
  229. disabled: true,
  230. span: 24,
  231. },
  232. {
  233. label: "上传背景",
  234. prop: "backgroundUrl",
  235. type: 'upload',
  236. listType: 'picture-img',
  237. dataType: 'string',
  238. action: '/api/blade-resource/oss/endpoint/put-file',
  239. propsHttp: {
  240. res: 'data',
  241. url: 'link',
  242. },
  243. span: 24,
  244. },
  245. ]
  246. }
  247. };
  248. },
  249. watch: {
  250. 'form.category'() {
  251. const category = func.toInt(this.form.category);
  252. this.$refs.crud.option.column.filter(item => {
  253. if (item.prop === "appId") {
  254. item.display = category === 4;
  255. }
  256. if (item.prop === "region") {
  257. item.display = category === 4;
  258. }
  259. });
  260. },
  261. 'debugForm.code'() {
  262. const column = this.findObject(this.debugOption.column, "backgroundUrl");
  263. column.action = `/api/blade-resource/oss/endpoint/put-file?code=${this.debugForm.code}`;
  264. }
  265. },
  266. computed: {
  267. ...mapGetters(["userInfo", "permission"]),
  268. permissionList() {
  269. return {
  270. addBtn: this.vaildData(this.permission.oss_add),
  271. viewBtn: this.vaildData(this.permission.oss_view),
  272. delBtn: this.vaildData(this.permission.oss_delete),
  273. editBtn: this.vaildData(this.permission.oss_edit)
  274. };
  275. },
  276. ids() {
  277. let ids = [];
  278. this.selectionList.forEach(ele => {
  279. ids.push(ele.id);
  280. });
  281. return ids.join(",");
  282. }
  283. },
  284. methods: {
  285. rowSave(row, done, loading) {
  286. add(row).then(() => {
  287. this.onLoad(this.page);
  288. this.$message({
  289. type: "success",
  290. message: "操作成功!"
  291. });
  292. done();
  293. }, error => {
  294. window.console.log(error);
  295. loading();
  296. });
  297. },
  298. rowUpdate(row, index, done, loading) {
  299. update(row).then(() => {
  300. this.onLoad(this.page);
  301. this.$message({
  302. type: "success",
  303. message: "操作成功!"
  304. });
  305. done();
  306. }, error => {
  307. window.console.log(error);
  308. loading();
  309. });
  310. },
  311. rowDel(row) {
  312. this.$confirm("确定将选择数据删除?", {
  313. confirmButtonText: "确定",
  314. cancelButtonText: "取消",
  315. type: "warning"
  316. })
  317. .then(() => {
  318. return remove(row.id);
  319. })
  320. .then(() => {
  321. this.onLoad(this.page);
  322. this.$message({
  323. type: "success",
  324. message: "操作成功!"
  325. });
  326. });
  327. },
  328. searchReset() {
  329. this.query = {};
  330. this.onLoad(this.page);
  331. },
  332. searchChange(params, done) {
  333. this.query = params;
  334. this.page.currentPage = 1;
  335. this.onLoad(this.page, params);
  336. done();
  337. },
  338. selectionChange(list) {
  339. this.selectionList = list;
  340. },
  341. selectionClear() {
  342. this.selectionList = [];
  343. this.$refs.crud.toggleSelection();
  344. },
  345. handleEnable(row) {
  346. this.$confirm("是否确定启用这条配置?", {
  347. confirmButtonText: "确定",
  348. cancelButtonText: "取消",
  349. type: "warning"
  350. })
  351. .then(() => {
  352. return enable(row.id);
  353. })
  354. .then(() => {
  355. this.onLoad(this.page);
  356. this.$message({
  357. type: "success",
  358. message: "操作成功!"
  359. });
  360. this.$refs.crud.toggleSelection();
  361. });
  362. },
  363. handleDebug(row) {
  364. this.box = true;
  365. this.debugForm.code = row.ossCode;
  366. this.debugForm.backgroundUrl = '';
  367. },
  368. handleSubmit(form, done) {
  369. this.$message({
  370. type: "success",
  371. message: `获取到图片地址:[${form.backgroundUrl}]`
  372. });
  373. done();
  374. },
  375. handleDelete() {
  376. if (this.selectionList.length === 0) {
  377. this.$message.warning("请选择至少一条数据");
  378. return;
  379. }
  380. this.$confirm("确定将选择数据删除?", {
  381. confirmButtonText: "确定",
  382. cancelButtonText: "取消",
  383. type: "warning"
  384. })
  385. .then(() => {
  386. return remove(this.ids);
  387. })
  388. .then(() => {
  389. this.onLoad(this.page);
  390. this.$message({
  391. type: "success",
  392. message: "操作成功!"
  393. });
  394. this.$refs.crud.toggleSelection();
  395. });
  396. },
  397. beforeOpen(done, type) {
  398. if (["edit", "view"].includes(type)) {
  399. getDetail(this.form.id).then(res => {
  400. this.form = res.data.data;
  401. });
  402. }
  403. done();
  404. },
  405. currentChange(currentPage) {
  406. this.page.currentPage = currentPage;
  407. },
  408. sizeChange(pageSize) {
  409. this.page.pageSize = pageSize;
  410. },
  411. refreshChange() {
  412. this.onLoad(this.page, this.query);
  413. },
  414. onLoad(page, params = {}) {
  415. this.loading = true;
  416. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  417. const data = res.data.data;
  418. this.page.total = data.total;
  419. this.data = data.records;
  420. this.loading = false;
  421. this.selectionClear();
  422. });
  423. }
  424. }
  425. };
  426. </script>