tenant.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. ref="crud"
  7. v-model="form"
  8. :page.sync="page"
  9. :permission="permissionList"
  10. :before-open="beforeOpen"
  11. @row-del="rowDel"
  12. @row-update="rowUpdate"
  13. @row-save="rowSave"
  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. v-if="permission.tenant_delete"
  26. plain
  27. @click="handleDelete">删 除
  28. </el-button>
  29. <el-button size="small"
  30. plain
  31. v-if="userInfo.role_name.includes('administrator')"
  32. icon="el-icon-setting"
  33. @click="handleSetting">授权配置
  34. </el-button>
  35. <el-button size="small"
  36. plain
  37. v-if="userInfo.role_name.includes('administrator')"
  38. icon="el-icon-coin"
  39. @click="handleDatasource">数据源配置
  40. </el-button>
  41. </template>
  42. <template slot-scope="{row}"
  43. slot="accountNumber">
  44. <el-tag>{{ row.accountNumber > 0 ? row.accountNumber : '不限制' }}</el-tag>
  45. </template>
  46. <template slot-scope="{row}"
  47. slot="expireTime">
  48. <el-tag>{{ row.expireTime ? row.expireTime : '不限制' }}</el-tag>
  49. </template>
  50. </avue-crud>
  51. <el-dialog title="租户授权配置"
  52. append-to-body
  53. :visible.sync="box"
  54. width="450px">
  55. <avue-form :option="settingOption" v-model="settingForm" @submit="handleSubmit"/>
  56. </el-dialog>
  57. <el-dialog title="租户数据源配置"
  58. append-to-body
  59. :visible.sync="datasourceBox"
  60. width="450px">
  61. <avue-form :option="datasourceOption" v-model="datasourceForm" @submit="handleDatasourceSubmit"/>
  62. </el-dialog>
  63. </basic-container>
  64. </template>
  65. <script>
  66. import {getList, getDetail, remove, update, add, setting, datasource} from "@/api/system/tenant";
  67. import {mapGetters} from "vuex";
  68. export default {
  69. data() {
  70. return {
  71. form: {},
  72. selectionList: [],
  73. query: {},
  74. loading: true,
  75. box: false,
  76. datasourceBox: false,
  77. page: {
  78. pageSize: 10,
  79. currentPage: 1,
  80. total: 0
  81. },
  82. option: {
  83. height: 'auto',
  84. calcHeight: 30,
  85. tip: false,
  86. searchShow: true,
  87. searchMenuSpan: 6,
  88. border: true,
  89. index: true,
  90. selection: true,
  91. viewBtn: true,
  92. dialogWidth: 900,
  93. dialogClickModal: false,
  94. column: [
  95. {
  96. label: "租户ID",
  97. prop: "tenantId",
  98. width: 100,
  99. search: true,
  100. addDisplay: false,
  101. editDisplay: false,
  102. span: 24,
  103. rules: [{
  104. required: true,
  105. message: "请输入租户ID",
  106. trigger: "blur"
  107. }]
  108. },
  109. {
  110. label: "租户名称",
  111. prop: "tenantName",
  112. search: true,
  113. width: 180,
  114. span: 24,
  115. rules: [{
  116. required: true,
  117. message: "请输入参数名称",
  118. trigger: "blur"
  119. }]
  120. },
  121. {
  122. label: "联系人",
  123. prop: "linkman",
  124. width: 100,
  125. search: true,
  126. rules: [{
  127. required: true,
  128. message: "请输入联系人",
  129. trigger: "blur"
  130. }]
  131. },
  132. {
  133. label: "联系电话",
  134. prop: "contactNumber",
  135. width: 150,
  136. },
  137. {
  138. label: "联系地址",
  139. prop: "address",
  140. span: 24,
  141. minRows: 2,
  142. type: "textarea",
  143. hide: true,
  144. },
  145. {
  146. label: "账号额度",
  147. prop: "accountNumber",
  148. width: 90,
  149. slot: true,
  150. addDisplay: false,
  151. editDisplay: false,
  152. },
  153. {
  154. label: "过期时间",
  155. prop: "expireTime",
  156. width: 180,
  157. slot: true,
  158. addDisplay: false,
  159. editDisplay: false,
  160. },
  161. {
  162. label: "绑定域名",
  163. prop: "domain",
  164. span: 24,
  165. },
  166. {
  167. label: "系统背景",
  168. prop: "backgroundUrl",
  169. type: 'upload',
  170. listType: 'picture-img',
  171. dataType: 'string',
  172. action: '/api/blade-resource/oss/endpoint/put-file',
  173. propsHttp: {
  174. res: 'data',
  175. url: 'link',
  176. },
  177. hide: true,
  178. span: 24,
  179. },
  180. ]
  181. },
  182. data: [],
  183. settingForm: {},
  184. settingOption: {
  185. column: [
  186. {
  187. label: "账号额度",
  188. prop: "accountNumber",
  189. type: "number",
  190. span: 24,
  191. },
  192. {
  193. label: "过期时间",
  194. prop: "expireTime",
  195. type: "date",
  196. format: "yyyy-MM-dd hh:mm:ss",
  197. valueFormat: "yyyy-MM-dd hh:mm:ss",
  198. span: 24,
  199. },
  200. ]
  201. },
  202. datasourceForm: {},
  203. datasourceOption: {
  204. column: [
  205. {
  206. label: "数据源",
  207. prop: "datasourceId",
  208. search: true,
  209. span: 24,
  210. type: "select",
  211. dicUrl: "/api/blade-develop/datasource/select",
  212. props: {
  213. label: "name",
  214. value: "id"
  215. },
  216. rules: [{
  217. required: true,
  218. message: "请选择数据源",
  219. trigger: "blur"
  220. }]
  221. },
  222. ]
  223. }
  224. };
  225. },
  226. computed: {
  227. ...mapGetters(["userInfo", "permission"]),
  228. permissionList() {
  229. return {
  230. addBtn: this.vaildData(this.permission.tenant_add, false),
  231. viewBtn: this.vaildData(this.permission.tenant_view, false),
  232. delBtn: this.vaildData(this.permission.tenant_delete, false),
  233. editBtn: this.vaildData(this.permission.tenant_edit, false)
  234. };
  235. },
  236. ids() {
  237. let ids = [];
  238. this.selectionList.forEach(ele => {
  239. ids.push(ele.id);
  240. });
  241. return ids.join(",");
  242. },
  243. tenantId() {
  244. return this.selectionList[0].tenantId;
  245. }
  246. },
  247. methods: {
  248. rowSave(row, done, loading) {
  249. add(row).then(() => {
  250. this.onLoad(this.page);
  251. this.$message({
  252. type: "success",
  253. message: "操作成功!"
  254. });
  255. done();
  256. }, error => {
  257. window.console.log(error);
  258. loading();
  259. });
  260. },
  261. rowUpdate(row, index, done, loading) {
  262. update(row).then(() => {
  263. this.onLoad(this.page);
  264. this.$message({
  265. type: "success",
  266. message: "操作成功!"
  267. });
  268. done();
  269. }, error => {
  270. window.console.log(error);
  271. loading();
  272. });
  273. },
  274. rowDel(row) {
  275. this.$confirm("确定将选择数据删除?", {
  276. confirmButtonText: "确定",
  277. cancelButtonText: "取消",
  278. type: "warning"
  279. })
  280. .then(() => {
  281. return remove(row.id);
  282. })
  283. .then(() => {
  284. this.onLoad(this.page);
  285. this.$message({
  286. type: "success",
  287. message: "操作成功!"
  288. });
  289. });
  290. },
  291. beforeOpen(done, type) {
  292. if (["view"].includes(type)) {
  293. getDetail(this.form.id).then(res => {
  294. const data = res.data.data;
  295. if (!(data.accountNumber > 0)) {
  296. data.accountNumber = "不限制";
  297. }
  298. if (!data.expireTime) {
  299. data.expireTime = "不限制";
  300. }
  301. this.form = data;
  302. });
  303. }
  304. done();
  305. },
  306. searchReset() {
  307. this.query = {};
  308. this.onLoad(this.page);
  309. },
  310. searchChange(params, done) {
  311. this.query = params;
  312. this.page.currentPage = 1;
  313. this.onLoad(this.page, params);
  314. done();
  315. },
  316. selectionChange(list) {
  317. this.selectionList = list;
  318. },
  319. selectionClear() {
  320. this.selectionList = [];
  321. this.$refs.crud.toggleSelection();
  322. },
  323. handleDelete() {
  324. if (this.selectionList.length === 0) {
  325. this.$message.warning("请选择至少一条数据");
  326. return;
  327. }
  328. this.$confirm("确定将选择数据删除?", {
  329. confirmButtonText: "确定",
  330. cancelButtonText: "取消",
  331. type: "warning"
  332. })
  333. .then(() => {
  334. return remove(this.ids);
  335. })
  336. .then(() => {
  337. this.onLoad(this.page);
  338. this.$message({
  339. type: "success",
  340. message: "操作成功!"
  341. });
  342. this.$refs.crud.toggleSelection();
  343. });
  344. },
  345. handleSetting() {
  346. if (this.selectionList.length === 0) {
  347. this.$message.warning("请选择至少一条数据");
  348. return;
  349. }
  350. if (this.selectionList.length === 1) {
  351. getDetail(this.selectionList[0].id).then(res => {
  352. const data = res.data.data;
  353. this.settingForm.accountNumber = data.accountNumber;
  354. this.settingForm.expireTime = data.expireTime;
  355. });
  356. } else {
  357. this.settingForm.accountNumber = -1;
  358. this.settingForm.expireTime = '';
  359. }
  360. this.box = true;
  361. },
  362. handleDatasource() {
  363. if (this.selectionList.length === 0) {
  364. this.$message.warning("请选择至少一条数据");
  365. return;
  366. }
  367. if (this.selectionList.length !== 1) {
  368. this.$message.warning("只能选择一条数据");
  369. return;
  370. }
  371. getDetail(this.selectionList[0].id).then(res => {
  372. const data = res.data.data;
  373. this.datasourceForm.datasourceId = data.datasourceId;
  374. });
  375. this.datasourceBox = true;
  376. },
  377. handleSubmit(form, done, loading) {
  378. setting(this.ids, form).then(() => {
  379. this.onLoad(this.page);
  380. this.$message({
  381. type: "success",
  382. message: "配置成功!"
  383. });
  384. done();
  385. this.box = false;
  386. }, error => {
  387. window.console.log(error);
  388. loading();
  389. });
  390. },
  391. handleDatasourceSubmit(form, done, loading) {
  392. datasource(this.tenantId, form.datasourceId).then(() => {
  393. this.$message({
  394. type: "success",
  395. message: "配置成功!"
  396. });
  397. done();
  398. this.datasourceBox = false;
  399. }, error => {
  400. window.console.log(error);
  401. loading();
  402. });
  403. },
  404. currentChange(currentPage) {
  405. this.page.currentPage = currentPage;
  406. },
  407. sizeChange(pageSize) {
  408. this.page.pageSize = pageSize;
  409. },
  410. refreshChange() {
  411. this.onLoad(this.page, this.query);
  412. },
  413. onLoad(page, params = {}) {
  414. this.loading = true;
  415. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  416. const data = res.data.data;
  417. this.page.total = data.total;
  418. this.data = data.records;
  419. this.loading = false;
  420. this.selectionClear();
  421. });
  422. }
  423. }
  424. };
  425. </script>
  426. <style>
  427. </style>