index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. <div v-permission="['new_role_button']">
  8. <el-button size="default" @click="addApp" plain>新增</el-button>
  9. </div>
  10. </div>
  11. </div>
  12. <div class="application-content">
  13. <Table :tableHeader="tableHeader" @btnClick="btnClick" :tableBtnGroup="tableBtnGroup" :tableData="tableData" />
  14. </div>
  15. <!--删除弹框-->
  16. <Dialog :flag="flag" msgTitle="删除角色" type="del" :delName="title" @delRest="delRest" @delRemove="remove" />
  17. <!--新增/编辑-->
  18. <Dialog :flag="editDialogVisible" :msgTitle="editDialogTitle" @submitForm="submitForm(ruleFormRef)" @resetForm="resetForm(ruleFormRef)" :show-flag="true">
  19. <el-form ref="ruleFormRef" :model="ruleForm" label-width="110px" class="demo-ruleForm">
  20. <el-form-item label="角色ID" :rules="[{required: true,message: '请输入角色ID',trigger: 'blur',}]" prop="role_id">
  21. <el-input :disabled="msgFlag" v-model="ruleForm.role_id" size="default" placeholder="请输入角色名称" />
  22. </el-form-item>
  23. <el-form-item label="角色名称" :rules="[{required: true,message: '请输入角色名称',trigger: 'blur',}]" prop="role_name">
  24. <el-input v-model="ruleForm.role_name" size="default" placeholder="请输入角色名称" />
  25. </el-form-item>
  26. <el-form-item label="角色描述" prop="role_comment">
  27. <el-input v-model="ruleForm.role_comment" size="default" type="textarea" :rows="3" placeholder="请输入角色描述" />
  28. </el-form-item>
  29. <el-form-item label="是否启用" :rules="[{required: true,message: '请选择是否启用',trigger: 'change',}]" prop="role_status">
  30. <el-radio-group v-model="ruleForm.role_status">
  31. <el-radio :label="1">启用</el-radio>
  32. <el-radio :label="2"> 禁用</el-radio>
  33. </el-radio-group>
  34. </el-form-item>
  35. <el-form-item label="是否存在互斥" prop="repel">
  36. <el-radio-group v-model="ruleForm.repel">
  37. <el-radio :label="1">是</el-radio>
  38. <el-radio :label="0"> 否</el-radio>
  39. </el-radio-group>
  40. </el-form-item>
  41. </el-form>
  42. </Dialog>
  43. </div>
  44. </template>
  45. <script setup lang="ts">
  46. import { ref, onBeforeMount } from "vue";
  47. import { ElMessage, FormInstance, FormRules } from "element-plus";
  48. import Table from "@/components/tableTemp/index.vue";
  49. import Search from "@/components/search/index.vue";
  50. import table from "../hooks/useTable";
  51. import * as _ from "lodash";
  52. const router = useRouter();
  53. const ruleFormRef = ref<FormInstance>();
  54. const tableHeader = ref([]);
  55. const tableData = ref([]);
  56. const tableBtnGroup = <any>[
  57. {
  58. name: "编辑",
  59. className: "editBtn",
  60. param: "edit",
  61. is: "role_editing_button",
  62. },
  63. {
  64. name: "查看权限",
  65. className: "editBtn",
  66. param: "auth",
  67. is: "role_authorization_button",
  68. },
  69. {
  70. name: "删除",
  71. className: "delBtn",
  72. param: "del",
  73. is: "role_deletion_button",
  74. },
  75. ];
  76. const flag = ref(false);
  77. const msgFlag = ref(false);
  78. const title = ref("");
  79. const dT = ref("add");
  80. const editDialogVisible = ref(false);
  81. const editDialogTitle = ref("新增角色");
  82. const ruleForm = ref<any>({
  83. role_id: "",
  84. role_name: "",
  85. role_comment: "",
  86. role_status: "",
  87. repel: "",
  88. });
  89. const submitID = ref("");
  90. const searchInfo = ref("");
  91. const rowIndex = ref<any>({});
  92. onBeforeMount(() => {
  93. gueryRole();
  94. });
  95. const gueryRole = async () => {
  96. const res = await table.getTable(DATACONTENT_ID.roleTableNId, [
  97. searchInfo.value,
  98. sessionStorage.getItem("User_Id"),
  99. ]);
  100. tableHeader.value = res.tableHeader.value;
  101. tableData.value = res.tableData.value;
  102. submitID.value = res.msgId.value;
  103. };
  104. const search = (val) => {
  105. searchInfo.value = val;
  106. gueryRole();
  107. };
  108. const clear = () => {
  109. searchInfo.value = "";
  110. gueryRole();
  111. };
  112. const btnClick = (index, row, param) => {
  113. rowIndex.value = _.cloneDeep(row);
  114. if (param == "del") {
  115. flag.value = true;
  116. title.value = row.role_name;
  117. } else if (param == "edit") {
  118. msgFlag.value = true;
  119. dT.value = "edit";
  120. editDialogVisible.value = true;
  121. editDialogTitle.value = "编辑角色";
  122. ruleForm.value = _.cloneDeep(row);
  123. } else {
  124. router.push({
  125. path: "/userManagement/role/auth",
  126. query: {
  127. role_id: row.role_id,
  128. },
  129. });
  130. }
  131. };
  132. const delRest = () => {
  133. flag.value = false;
  134. };
  135. const remove = async () => {
  136. rowIndex.value.operator_id = sessionStorage.getItem("User_Id");
  137. if (rowIndex.value.AuthCount != undefined) {
  138. delete rowIndex.value.AuthCount;
  139. }
  140. //UserCount
  141. if (rowIndex.value.UserCount != undefined) {
  142. delete rowIndex.value.UserCount;
  143. }
  144. saveRole(3, rowIndex.value);
  145. flag.value = false;
  146. };
  147. const addApp = () => {
  148. editDialogVisible.value = true;
  149. editDialogTitle.value = "新增角色";
  150. dT.value = "add";
  151. msgFlag.value = false;
  152. ruleForm.value = {};
  153. };
  154. // 新增/编辑角色
  155. const saveRole = async (event, data) => {
  156. try {
  157. const { code, message } = await table.dataChange(
  158. submitID.value,
  159. event,
  160. data
  161. );
  162. if (code == 0) {
  163. ElMessage.success(message);
  164. gueryRole();
  165. } else {
  166. ElMessage.error(message);
  167. }
  168. } catch (error) {}
  169. };
  170. const submitForm = async (formEl: FormInstance | undefined) => {
  171. if (!formEl) return;
  172. await formEl.validate((valid, fields) => {
  173. if (valid) {
  174. if (dT.value == "add") {
  175. ruleForm.value.operator_id = sessionStorage.getItem("User_Id");
  176. saveRole(1, ruleForm.value);
  177. } else {
  178. ruleForm.value.operator_id = sessionStorage.getItem("User_Id");
  179. saveRole(2, ruleForm.value);
  180. }
  181. editDialogVisible.value = false;
  182. } else {
  183. console.log("error submit!", fields);
  184. }
  185. });
  186. };
  187. const resetForm = (formEl: FormInstance | undefined) => {
  188. if (!formEl) return;
  189. formEl.resetFields();
  190. editDialogVisible.value = false;
  191. };
  192. </script>
  193. <style lang="scss" scoped>
  194. .application {
  195. &-content {
  196. margin-top: 24px;
  197. height: calc(100% - 56px);
  198. }
  199. }
  200. </style>