tenant.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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. <el-button type="primary"
  42. size="small"
  43. icon="el-icon-delete"
  44. plain
  45. @click="CopyPopupfun">复 制
  46. </el-button>
  47. </template>
  48. <template slot-scope="{row}"
  49. slot="accountNumber">
  50. <el-tag>{{ row.accountNumber > 0 ? row.accountNumber : '不限制' }}</el-tag>
  51. </template>
  52. <template slot-scope="{row}"
  53. slot="expireTime">
  54. <el-tag>{{ row.expireTime ? row.expireTime : '不限制' }}</el-tag>
  55. </template>
  56. </avue-crud>
  57. <el-dialog title="租户授权配置"
  58. append-to-body
  59. :visible.sync="box"
  60. width="450px">
  61. <avue-form :option="settingOption" v-model="settingForm" @submit="handleSubmit"/>
  62. </el-dialog>
  63. <el-dialog title="租户数据源配置"
  64. append-to-body
  65. :visible.sync="datasourceBox"
  66. width="450px">
  67. <avue-form :option="datasourceOption" v-model="datasourceForm" @submit="handleDatasourceSubmit"/>
  68. </el-dialog>
  69. <el-dialog title="租户复制"
  70. append-to-body
  71. :visible.sync="CopyVisible"
  72. width="450px">
  73. <avue-form ref="CopyRef" :option="CopyOption" v-model="CopyForm" @submit="copyTenantfun"/>
  74. </el-dialog>
  75. </basic-container>
  76. </template>
  77. <script>
  78. import {getList, getDetail, remove, update, add, setting, datasource, tenantCopyData} from "@/api/system/tenant";
  79. import {mapGetters} from "vuex";
  80. import error from "@/views/monitor/log/error.vue";
  81. export default {
  82. data() {
  83. return {
  84. form: {},
  85. selectionList: [],
  86. query: {},
  87. loading: true,
  88. box: false,
  89. datasourceBox: false,
  90. CopyVisible:false, // 复制租户弹窗
  91. page: {
  92. pageSize: 10,
  93. currentPage: 1,
  94. total: 0
  95. },
  96. option: {
  97. align: 'center',
  98. height: 'auto',
  99. calcHeight: 30,
  100. tip: false,
  101. searchShow: true,
  102. searchMenuSpan: 6,
  103. border: true,
  104. index: true,
  105. selection: true,
  106. viewBtn: true,
  107. dialogWidth: 900,
  108. dialogClickModal: false,
  109. column: [
  110. {
  111. label: "租户ID",
  112. prop: "tenantId",
  113. width: 100,
  114. search: true,
  115. addDisplay: false,
  116. editDisplay: false,
  117. span: 24,
  118. rules: [{
  119. required: true,
  120. message: "请输入租户ID",
  121. trigger: "blur"
  122. }]
  123. },
  124. {
  125. label: "租户名称",
  126. prop: "tenantName",
  127. search: true,
  128. width: 180,
  129. span: 24,
  130. rules: [{
  131. required: true,
  132. message: "请输入参数名称",
  133. trigger: "blur"
  134. }]
  135. },
  136. {
  137. label: "联系人",
  138. prop: "linkman",
  139. width: 100,
  140. search: true,
  141. rules: [{
  142. required: true,
  143. message: "请输入联系人",
  144. trigger: "blur"
  145. }]
  146. },
  147. {
  148. label: "联系电话",
  149. prop: "contactNumber",
  150. width: 150,
  151. },
  152. {
  153. label: "联系地址",
  154. prop: "address",
  155. span: 24,
  156. minRows: 2,
  157. type: "textarea",
  158. hide: true,
  159. },
  160. {
  161. label: "账号额度",
  162. prop: "accountNumber",
  163. width: 90,
  164. slot: true,
  165. addDisplay: false,
  166. editDisplay: false,
  167. },
  168. {
  169. label: "过期时间",
  170. prop: "expireTime",
  171. width: 180,
  172. slot: true,
  173. addDisplay: false,
  174. editDisplay: false,
  175. },
  176. {
  177. label: "绑定域名",
  178. prop: "domain",
  179. width: 160,
  180. span: 24,
  181. overHidden: true,
  182. },{
  183. label: "公司类型",
  184. type: "select",
  185. dicUrl: "/api/blade-system/dict/dictionary?code=company_type",
  186. props: {
  187. label: "dictValue",
  188. value: "dictKey"
  189. },
  190. dataType: "number",
  191. width: 80,
  192. prop: "billType",
  193. slot: true,
  194. overHidden: true,
  195. rules: [{
  196. required: true,
  197. message: "请输入机构类型",
  198. trigger: "blur"
  199. }]
  200. },
  201. {
  202. label: "平台客户编码",
  203. prop: "corpCode",
  204. width: 120,
  205. span: 12,
  206. overHidden: true,
  207. },
  208. {
  209. label: "对应平台(租户id)",
  210. prop: "terrace",
  211. labelWidth: 140,
  212. width: 140,
  213. span: 12,
  214. overHidden: true,
  215. },
  216. {
  217. label: "微信AppId",
  218. prop: "appId",
  219. width: 100,
  220. span: 12,
  221. overHidden: true
  222. },
  223. {
  224. label: "系统背景",
  225. prop: "backgroundUrl",
  226. type: 'upload',
  227. listType: 'picture-img',
  228. dataType: 'string',
  229. action: '/api/blade-resource/oss/endpoint/put-file',
  230. propsHttp: {
  231. res: 'data',
  232. url: 'link',
  233. },
  234. hide: true,
  235. span: 24,
  236. },
  237. ]
  238. },
  239. data: [],
  240. settingForm: {},
  241. settingOption: {
  242. column: [
  243. {
  244. label: "账号额度",
  245. prop: "accountNumber",
  246. type: "number",
  247. span: 24,
  248. },
  249. {
  250. label: "过期时间",
  251. prop: "expireTime",
  252. type: "date",
  253. format: "yyyy-MM-dd hh:mm:ss",
  254. valueFormat: "yyyy-MM-dd hh:mm:ss",
  255. span: 24,
  256. },
  257. ]
  258. },
  259. CopyOption: {
  260. column: [
  261. {
  262. label: "租户",
  263. prop: "tenantIdCopy",
  264. dicData:[],
  265. type: "select",
  266. filterable:true,
  267. remote:true,
  268. dicUrl: "/api/blade-system/tenant/list?tenantId={{key}}",
  269. props: {
  270. label: "tenantId",
  271. value: "tenantId",
  272. res:'data.records'
  273. },
  274. span: 24,
  275. rules: [{
  276. required: true,
  277. message: "请选择租户",
  278. trigger: "blur"
  279. }]
  280. },
  281. {
  282. label: "类型",
  283. prop: "type",
  284. multiple:true,
  285. type: 'select',
  286. dicData:[
  287. {
  288. label:'业务字典',
  289. value:'1',
  290. },
  291. {
  292. label:'角色',
  293. value:'2',
  294. },
  295. {
  296. label:'审批流程',
  297. value:'3',
  298. },
  299. {
  300. label:'编号配置',
  301. value:'4',
  302. },
  303. {
  304. label:'业务类型',
  305. value:'5',
  306. }
  307. ],
  308. span: 24,
  309. rules: [{
  310. required: true,
  311. message: "请选择类型",
  312. trigger: "blur"
  313. }]
  314. },
  315. ]
  316. }, // 复制弹窗配置项
  317. CopyForm:{}, // 复制弹窗表单数据
  318. datasourceForm: {},
  319. datasourceOption: {
  320. column: [
  321. {
  322. label: "数据源",
  323. prop: "datasourceId",
  324. search: true,
  325. span: 24,
  326. type: "select",
  327. dicUrl: "/api/blade-develop/datasource/select",
  328. props: {
  329. label: "name",
  330. value: "id"
  331. },
  332. rules: [{
  333. required: true,
  334. message: "请选择数据源",
  335. trigger: "blur"
  336. }]
  337. },
  338. ]
  339. }
  340. };
  341. },
  342. computed: {
  343. ...mapGetters(["userInfo", "permission"]),
  344. permissionList() {
  345. return {
  346. addBtn: this.vaildData(this.permission.tenant_add, false),
  347. viewBtn: this.vaildData(this.permission.tenant_view, false),
  348. delBtn: this.vaildData(this.permission.tenant_delete, false),
  349. editBtn: this.vaildData(this.permission.tenant_edit, false)
  350. };
  351. },
  352. ids() {
  353. let ids = [];
  354. this.selectionList.forEach(ele => {
  355. ids.push(ele.id);
  356. });
  357. return ids.join(",");
  358. },
  359. tenantId() {
  360. return this.selectionList[0].tenantId;
  361. }
  362. },
  363. methods: {
  364. // 复制租户
  365. copyTenantfun(form, done, loading){
  366. tenantCopyData({
  367. tenantId:this.selectionList[0].tenantId,
  368. tenantIdCopy:this.CopyForm.tenantIdCopy,
  369. type:this.CopyForm.type.join(',')
  370. }).then(res=>{
  371. this.$message({
  372. type: "success",
  373. message: "操作成功!"
  374. });
  375. done();
  376. this.CopyVisible = false
  377. },error => {
  378. window.console.log(error);
  379. loading();
  380. })
  381. },
  382. rowSave(row, done, loading) {
  383. add(row).then(() => {
  384. this.onLoad(this.page);
  385. this.$message({
  386. type: "success",
  387. message: "操作成功!"
  388. });
  389. done();
  390. }, error => {
  391. window.console.log(error);
  392. loading();
  393. });
  394. },
  395. rowUpdate(row, index, done, loading) {
  396. update(row).then(() => {
  397. this.onLoad(this.page);
  398. this.$message({
  399. type: "success",
  400. message: "操作成功!"
  401. });
  402. done();
  403. }, error => {
  404. window.console.log(error);
  405. loading();
  406. });
  407. },
  408. rowDel(row) {
  409. this.$confirm("确定将选择数据删除?", {
  410. confirmButtonText: "确定",
  411. cancelButtonText: "取消",
  412. type: "warning"
  413. })
  414. .then(() => {
  415. return remove(row.id);
  416. })
  417. .then(() => {
  418. this.onLoad(this.page);
  419. this.$message({
  420. type: "success",
  421. message: "操作成功!"
  422. });
  423. });
  424. },
  425. beforeOpen(done, type) {
  426. if (["view"].includes(type)) {
  427. getDetail(this.form.id).then(res => {
  428. const data = res.data.data;
  429. if (!(data.accountNumber > 0)) {
  430. data.accountNumber = "不限制";
  431. }
  432. if (!data.expireTime) {
  433. data.expireTime = "不限制";
  434. }
  435. this.form = data;
  436. });
  437. }
  438. done();
  439. },
  440. searchReset() {
  441. this.query = {};
  442. this.onLoad(this.page);
  443. },
  444. searchChange(params, done) {
  445. this.query = params;
  446. this.page.currentPage = 1;
  447. this.onLoad(this.page, params);
  448. done();
  449. },
  450. selectionChange(list) {
  451. this.selectionList = list;
  452. },
  453. selectionClear() {
  454. this.selectionList = [];
  455. this.$refs.crud.toggleSelection();
  456. },
  457. handleDelete() {
  458. if (this.selectionList.length === 0) {
  459. this.$message.warning("请选择至少一条数据");
  460. return;
  461. }
  462. this.$confirm("确定将选择数据删除?", {
  463. confirmButtonText: "确定",
  464. cancelButtonText: "取消",
  465. type: "warning"
  466. })
  467. .then(() => {
  468. return remove(this.ids);
  469. })
  470. .then(() => {
  471. this.onLoad(this.page);
  472. this.$message({
  473. type: "success",
  474. message: "操作成功!"
  475. });
  476. this.$refs.crud.toggleSelection();
  477. });
  478. },
  479. // 复制弹窗开启
  480. CopyPopupfun(){
  481. if (this.selectionList.length === 0) {
  482. this.$message.warning("请选择至少一条数据");
  483. return;
  484. }
  485. this.CopyForm.tenantIdCopy = ''
  486. this.CopyForm.type = null
  487. this.CopyVisible = true
  488. },
  489. handleSetting() {
  490. if (this.selectionList.length === 0) {
  491. this.$message.warning("请选择至少一条数据");
  492. return;
  493. }
  494. if (this.selectionList.length === 1) {
  495. getDetail(this.selectionList[0].id).then(res => {
  496. const data = res.data.data;
  497. this.settingForm.accountNumber = data.accountNumber;
  498. this.settingForm.expireTime = data.expireTime;
  499. });
  500. } else {
  501. this.settingForm.accountNumber = -1;
  502. this.settingForm.expireTime = '';
  503. }
  504. this.box = true;
  505. },
  506. handleDatasource() {
  507. if (this.selectionList.length === 0) {
  508. this.$message.warning("请选择至少一条数据");
  509. return;
  510. }
  511. if (this.selectionList.length !== 1) {
  512. this.$message.warning("只能选择一条数据");
  513. return;
  514. }
  515. getDetail(this.selectionList[0].id).then(res => {
  516. const data = res.data.data;
  517. this.datasourceForm.datasourceId = data.datasourceId;
  518. });
  519. this.datasourceBox = true;
  520. },
  521. handleSubmit(form, done, loading) {
  522. setting(this.ids, form).then(() => {
  523. this.onLoad(this.page);
  524. this.$message({
  525. type: "success",
  526. message: "配置成功!"
  527. });
  528. done();
  529. this.box = false;
  530. }, error => {
  531. window.console.log(error);
  532. loading();
  533. });
  534. },
  535. handleDatasourceSubmit(form, done, loading) {
  536. datasource(this.tenantId, form.datasourceId).then(() => {
  537. this.$message({
  538. type: "success",
  539. message: "配置成功!"
  540. });
  541. done();
  542. this.datasourceBox = false;
  543. }, error => {
  544. window.console.log(error);
  545. loading();
  546. });
  547. },
  548. currentChange(currentPage) {
  549. this.page.currentPage = currentPage;
  550. },
  551. sizeChange(pageSize) {
  552. this.page.pageSize = pageSize;
  553. },
  554. refreshChange() {
  555. this.onLoad(this.page, this.query);
  556. },
  557. onLoad(page, params = {}) {
  558. this.loading = true;
  559. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  560. const data = res.data.data;
  561. this.page.total = data.total;
  562. this.data = data.records;
  563. this.loading = false;
  564. this.selectionClear();
  565. });
  566. }
  567. }
  568. };
  569. </script>
  570. <style>
  571. </style>