index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="application scroll-y">
  3. <div class="application-head flex">
  4. <div class="manageTitle">账号组管理</div>
  5. <div class="flex-wrap">
  6. <Search @clear="clear" @search="search" />
  7. <el-button v-permission="['add_account_group_button']" size="default" @click="addApp" plain>新增</el-button>
  8. </div>
  9. </div>
  10. <div class="application-content">
  11. <Table :tableHeader="tableHeader" @btnClick="btnClick" :tableBtnGroup="tableBtnGroup" :tableData="tableData" />
  12. </div>
  13. <!--删除弹框-->
  14. <Dialog :flag="flag" msgTitle="删除账号组" type="del" :delName="title" @delRest="delRest" @delRemove="remove" />
  15. <!--新增/编辑-->
  16. <Dialog :flag="editDialogVisible" :msgTitle="editDialogTitle" @submitForm="submitForm(ruleFormRef)" @resetForm="resetForm(ruleFormRef)" :show-flag="true">
  17. <el-form ref="ruleFormRef" :model="ruleForm" label-width="110px" class="demo-ruleForm">
  18. <el-form-item label="账号组名称" :rules="[{required: true,message: '请输入账号组名称',trigger: 'blur',}]" prop="user_group_name">
  19. <el-input v-model="ruleForm.user_group_name" size="default" placeholder="请输入账号组名称" />
  20. </el-form-item>
  21. <el-form-item label="账号组描述" prop="user_group_comment">
  22. <el-input v-model="ruleForm.user_group_comment" size="default" type="textarea" :rows="3" placeholder="请输入账号组描述" />
  23. </el-form-item>
  24. </el-form>
  25. </Dialog>
  26. </div>
  27. </template>
  28. <script setup lang="ts">
  29. import { ref, onBeforeMount } from "vue";
  30. import { ElMessage, FormInstance, FormRules } from "element-plus";
  31. import Table from "@/components/tableTemp/index.vue";
  32. import Search from "@/components/search/index.vue";
  33. import * as _ from "lodash";
  34. import table from "../hooks/useTable";
  35. const ruleFormRef = ref<FormInstance>();
  36. const tableHeader = ref<any>([]);
  37. const tableData = ref<any>([]);
  38. const tableBtnGroup = <any>[
  39. {
  40. name: "编辑",
  41. className: "editBtn",
  42. param: "edit",
  43. is: "account_group_editing_button",
  44. },
  45. {
  46. name: "删除",
  47. className: "delBtn",
  48. param: "del",
  49. is: "account_group_deletion_button",
  50. },
  51. ];
  52. const flag = ref(false);
  53. const title = ref("");
  54. const searchInfo = ref("");
  55. const dT = ref("add");
  56. const submitID = ref(0);
  57. const editDialogVisible = ref(false);
  58. const editDialogTitle = ref("新增账号组");
  59. const ruleForm = ref<any>({
  60. user_group_name: "",
  61. user_group_comment: "",
  62. });
  63. const rowIndex = ref<any>({});
  64. onBeforeMount(() => {
  65. accountList();
  66. });
  67. //获取账号组数据
  68. const accountList = async () => {
  69. const res = await table.getTable(DATACONTENT_ID.accountGroupTableId, [
  70. searchInfo.value,
  71. ]);
  72. tableHeader.value = res.tableHeader.value;
  73. tableData.value = res.tableData.value;
  74. submitID.value = res.msgId.value;
  75. };
  76. const search = (val) => {
  77. searchInfo.value = val;
  78. accountList();
  79. };
  80. const clear = () => {
  81. searchInfo.value = "";
  82. accountList();
  83. };
  84. const btnClick = (index, row, param) => {
  85. rowIndex.value = _.cloneDeep(row);
  86. if (param == "del") {
  87. flag.value = true;
  88. title.value = row.user_group_name;
  89. } else {
  90. dT.value = "edit";
  91. editDialogVisible.value = true;
  92. editDialogTitle.value = "编辑账号组";
  93. ruleForm.value = _.cloneDeep(row);
  94. }
  95. };
  96. const delRest = () => {
  97. flag.value = false;
  98. };
  99. const remove = async () => {
  100. if (rowIndex.value.user_count != undefined) {
  101. delete rowIndex.value.user_count;
  102. }
  103. try {
  104. const { code, message } = await table.dataChange(
  105. submitID.value,
  106. 3,
  107. rowIndex.value,
  108. "account_group_deletion_button"
  109. );
  110. if (code == 0) {
  111. ElMessage.success(message);
  112. accountList();
  113. } else {
  114. ElMessage.error(message);
  115. }
  116. } catch (err: any) {}
  117. flag.value = false;
  118. };
  119. const addApp = () => {
  120. editDialogVisible.value = true;
  121. editDialogTitle.value = "新增账号组";
  122. dT.value = "add";
  123. ruleForm.value = {};
  124. };
  125. // 新增/编辑账号
  126. const saveAddAccount = async (event) => {
  127. try {
  128. const { code, message } = await table.dataChange(
  129. submitID.value,
  130. event,
  131. ruleForm.value,
  132. event == 1 ? "add_account_group_button" : "account_group_editing_button"
  133. );
  134. if (code == 0) {
  135. ElMessage.success(message);
  136. accountList();
  137. } else {
  138. ElMessage.error(message);
  139. }
  140. } catch (error) {}
  141. };
  142. const submitForm = async (formEl: FormInstance | undefined) => {
  143. if (!formEl) return;
  144. await formEl.validate((valid, fields) => {
  145. if (valid) {
  146. if (dT.value == "add") {
  147. saveAddAccount(1);
  148. } else {
  149. // ruleForm.value = rowIndex.value;
  150. saveAddAccount(2);
  151. }
  152. editDialogVisible.value = false;
  153. } else {
  154. console.log("error submit!", fields);
  155. }
  156. });
  157. };
  158. const resetForm = (formEl: FormInstance | undefined) => {
  159. if (!formEl) return;
  160. formEl.resetFields();
  161. editDialogVisible.value = false;
  162. };
  163. </script>
  164. <style lang="scss" scoped>
  165. .application {
  166. &-content {
  167. margin-top: 24px;
  168. height: calc(100% - 56px);
  169. }
  170. }
  171. </style>