index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <div class="tenant">
  3. <!-- <Banner /> -->
  4. <div class="content">
  5. <byTable
  6. :source="sourceList.data"
  7. :pagination="sourceList.pagination"
  8. :config="config"
  9. :loading="loading"
  10. highlight-current-row
  11. :selectConfig="selectConfig"
  12. :table-events="{
  13. //element talbe事件都能传
  14. select: select,
  15. }"
  16. :action-list="[
  17. {
  18. text: '权限配置',
  19. plain: true,
  20. //type: 'warning',
  21. action: () => openRoomModal(),
  22. disabled: selection.data.length != 1,
  23. },
  24. {
  25. text: '添加租户',
  26. action: () => openModal('add'),
  27. },
  28. ]"
  29. @get-list="getList">
  30. <template #slotName="{ item }">
  31. {{ item.createTime }}
  32. </template>
  33. </byTable>
  34. </div>
  35. <el-dialog :title="modalType == 'add' ? '新增' : '编辑'" v-model="dialogVisible" width="800" v-loading="loading">
  36. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform"> </byForm>
  37. <template #footer>
  38. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  39. <el-button type="primary" @click="submitForm('byform')" size="large" :loading="submitLoading">确 定</el-button>
  40. </template>
  41. </el-dialog>
  42. <el-dialog title="权限配置" v-if="roomDialogVisible" v-model="roomDialogVisible" width="500" :before-close="handleClose" v-loading="loading">
  43. <el-tree :data="treeData" show-checkbox node-key="id" :default-checked-keys="formData.treeData" :props="defaultProps" ref="tree"> </el-tree>
  44. <template #footer>
  45. <el-button @click="roomDialogVisible = false" size="large">取 消</el-button>
  46. <el-button type="primary" @click="submitTree()" size="large" :loading="submitLoading">确 定</el-button>
  47. </template>
  48. </el-dialog>
  49. </div>
  50. </template>
  51. <script setup>
  52. /* eslint-disable vue/no-unused-components */
  53. import { ElMessage, ElMessageBox } from "element-plus";
  54. import byTable from "@/components/byTable/index";
  55. import byForm from "@/components/byForm/index";
  56. import { computed, defineComponent, ref } from "vue";
  57. const loading = ref(false);
  58. const submitLoading = ref(false);
  59. const defaultProps = {
  60. children: "children",
  61. label: "label",
  62. };
  63. const tree = ref(null);
  64. const sourceList = ref({
  65. data: [],
  66. pagination: {
  67. total: 3,
  68. pageNum: 1,
  69. pageSize: 10,
  70. },
  71. });
  72. let dialogVisible = ref(false);
  73. let roomDialogVisible = ref(false);
  74. let modalType = ref("add");
  75. let rules = ref({
  76. tenantId: [{ pattern: /^\w+$/, message: "请输入正确的租户号,禁止下划线外的其他符号,不区分大小写" }],
  77. password: [{ required: true, message: "请输入密码", trigger: "blur" }],
  78. enterpriseName: [{ required: true, message: "请输入企业名称", trigger: "blur" }],
  79. });
  80. const { proxy } = getCurrentInstance();
  81. const selectConfig = computed(() => {
  82. return [
  83. {
  84. label: "审核状态",
  85. prop: "flowStatus",
  86. data: [
  87. {
  88. label: "审核中",
  89. value: "1",
  90. },
  91. {
  92. label: "审核通过",
  93. value: "2",
  94. },
  95. {
  96. label: "审核不通过",
  97. value: "3",
  98. },
  99. ],
  100. },
  101. {
  102. label: "启用状态",
  103. prop: "status",
  104. data: [
  105. {
  106. label: "启用",
  107. value: "1",
  108. },
  109. {
  110. label: "禁用",
  111. value: "0",
  112. },
  113. ],
  114. },
  115. ];
  116. });
  117. const config = computed(() => {
  118. return [
  119. {
  120. type: "selection",
  121. attrs: {
  122. label: "多选",
  123. prop: "remark",
  124. },
  125. },
  126. {
  127. attrs: {
  128. label: "企业名称",
  129. prop: "enterpriseName",
  130. },
  131. },
  132. {
  133. attrs: {
  134. label: "租户id",
  135. prop: "tenantId",
  136. align: "center",
  137. },
  138. },
  139. {
  140. attrs: {
  141. label: "已创建账号数",
  142. prop: "accountCount",
  143. align: "center",
  144. },
  145. },
  146. {
  147. attrs: {
  148. label: "审核状态",
  149. width: 100,
  150. prop: "flowStatus",
  151. },
  152. render(flowStatus) {
  153. //1审核中 2审核通过 3审核不通过
  154. return flowStatus == 1 ? "审核中" : flowStatus == 2 ? "审核通过" : "审核不通过";
  155. },
  156. },
  157. {
  158. attrs: {
  159. label: "启用状态",
  160. prop: "status",
  161. },
  162. render(status) {
  163. return status ? "启用" : "禁用";
  164. },
  165. },
  166. {
  167. attrs: {
  168. label: "操作",
  169. width: "200",
  170. align: "right",
  171. },
  172. // 渲染 el-button,一般用在最后一列。
  173. renderHTML(row) {
  174. return [
  175. // {
  176. // attrs: {
  177. // label: "修改",
  178. // type: "primary",
  179. // text: true,
  180. // },
  181. // el: "button",
  182. // click() {
  183. // getDtl(row);
  184. // },
  185. // },
  186. {
  187. attrs: {
  188. label: row.status == 1 ? "禁用" : "启用",
  189. type: "primary",
  190. text: true,
  191. },
  192. el: "button",
  193. click() {
  194. changeStatus(row);
  195. },
  196. },
  197. // {
  198. // attrs: {
  199. // label: "发布",
  200. // type: "primary",
  201. // text: true,
  202. // bg: true,
  203. // },
  204. // el: "button",
  205. // click() {
  206. // setPublish(row);
  207. // },
  208. // },
  209. // {
  210. // attrs: {
  211. // label: '删除',
  212. // type: 'danger',
  213. // text: true,
  214. // disabled:true,
  215. // },
  216. // el: 'button',
  217. // click() {
  218. // // 弹窗提示是否删除
  219. // ElMessageBox.confirm('此操作将永久删除该数据, 是否继续?', '提示', {
  220. // confirmButtonText: '确定',
  221. // cancelButtonText: '取消',
  222. // type: 'warning',
  223. // })
  224. // .then(() => {
  225. // // 删除
  226. // proxy.post('/tenantInfo/delete', {
  227. // id: row.id,
  228. // }).then((res) => {
  229. // ElMessage({
  230. // message: '删除成功',
  231. // type: 'success',
  232. // })
  233. // getList()
  234. // })
  235. // })
  236. // },
  237. // },
  238. ];
  239. },
  240. },
  241. ];
  242. });
  243. let formData = reactive({
  244. data: {},
  245. treeData: [],
  246. });
  247. const formOption = reactive({
  248. inline: true,
  249. labelWidth: 100,
  250. itemWidth: 100,
  251. rules: [],
  252. });
  253. const byform = ref(null);
  254. const treeData = ref([]);
  255. const formConfig = computed(() => {
  256. return [
  257. {
  258. type: "input",
  259. prop: "tenantId",
  260. label: "租户id",
  261. required: true,
  262. itemWidth: 100,
  263. //disabled:true,
  264. itemType: "text",
  265. },
  266. {
  267. type: "input",
  268. prop: "enterpriseName",
  269. label: "企业名称",
  270. maxlength: 50,
  271. },
  272. {
  273. type: "radio",
  274. prop: "status",
  275. label: "启用状态",
  276. border: true,
  277. data: [
  278. {
  279. label: "启用",
  280. value: 1,
  281. },
  282. {
  283. label: "禁用",
  284. value: 0,
  285. },
  286. ],
  287. },
  288. {
  289. type: "title",
  290. title: "管理员信息",
  291. },
  292. {
  293. type: "input",
  294. itemType: "password",
  295. prop: "password",
  296. label: "密码",
  297. },
  298. ];
  299. });
  300. const getList = async (req) => {
  301. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  302. loading.value = true;
  303. proxy.post("/tenantInfo/page", sourceList.value.pagination).then((message) => {
  304. sourceList.value.data = message.rows;
  305. sourceList.value.pagination.total = message.total;
  306. setTimeout(() => {
  307. loading.value = false;
  308. }, 200);
  309. });
  310. };
  311. const openModal = () => {
  312. dialogVisible.value = true;
  313. modalType.value = "add";
  314. formData.data = {};
  315. };
  316. const selection = ref({
  317. data: [],
  318. });
  319. const select = (_selection, row) => {
  320. selection.value.data = _selection;
  321. };
  322. const getSubset = (list, data) => {
  323. for (let i = 0; i < list.length; i++) {
  324. if (list[i].children && list[i].children.length > 0) {
  325. getSubset(list[i].children, data);
  326. } else {
  327. data.push(list[i].id);
  328. }
  329. }
  330. return data;
  331. };
  332. const openRoomModal = () => {
  333. proxy.get("/tenantInfo/roleMenuTreeSelect/" + selection.value.data[0].tenantId).then((res) => {
  334. if (res.code == 200) {
  335. treeData.value = res.menus;
  336. let data = getSubset(res.menus, []);
  337. formData.treeData = res.checkedKeys.filter((item) => {
  338. return data.some((i) => item == i);
  339. });
  340. roomDialogVisible.value = true;
  341. }
  342. });
  343. };
  344. const noRepeat = (arr) => {
  345. var newArr = [...new Set(arr)];
  346. return newArr;
  347. };
  348. const submitTree = () => {
  349. let data = noRepeat(tree.value.getHalfCheckedKeys().concat(tree.value.getCheckedKeys()));
  350. if(data.length == 0) {
  351. ElMessage({
  352. message: "请至少选择一个菜单",
  353. type: "error",
  354. });
  355. return;
  356. }
  357. proxy
  358. .post("/tenantInfo/bindingMenu", {
  359. tenantId: selection.value.data[0].tenantId,
  360. menuIdList: data,
  361. })
  362. .then((res) => {
  363. ElMessage({
  364. message: "保存成功",
  365. type: "success",
  366. });
  367. roomDialogVisible.value = false;
  368. });
  369. };
  370. const submitForm = () => {
  371. byform.value.handleSubmit((valid) => {
  372. submitLoading.value = true;
  373. proxy
  374. .post("/tenantInfo/" + modalType.value, formData.data)
  375. .then((res) => {
  376. ElMessage({
  377. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  378. type: "success",
  379. });
  380. dialogVisible.value = false;
  381. submitLoading.value = false;
  382. getList();
  383. })
  384. .catch((err) => {
  385. submitLoading.value = false;
  386. });
  387. });
  388. };
  389. const getDtl = (row) => {
  390. proxy.post("/tenantInfo/detail", { id: row.id }).then((res) => {
  391. formData.data = res;
  392. modalType.value = "edit";
  393. dialogVisible.value = true;
  394. });
  395. };
  396. const changeStatus = (row) => {
  397. modalType.value = "edit";
  398. let status = row.status ? 0 : 1;
  399. proxy.post("/tenantInfo/detail", { id: row.id }).then((res) => {
  400. res.status = status;
  401. formData.data = res;
  402. ElMessageBox.confirm("你是否确认此操作?", "提示", {
  403. confirmButtonText: "确定",
  404. cancelButtonText: "取消",
  405. type: "warning",
  406. }).then(() => {
  407. // 删除
  408. proxy.post("/tenantInfo/" + modalType.value, formData.data).then((res) => {
  409. ElMessage({
  410. message: "操作成功",
  411. type: "success",
  412. });
  413. getList();
  414. });
  415. });
  416. });
  417. };
  418. getList();
  419. </script>
  420. <style lang="scss" scoped>
  421. .tenant {
  422. padding: 20px;
  423. }
  424. </style>