index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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
  14. :tableHeader="tableHeader"
  15. @btnClick="btnClick"
  16. :tableBtnGroup="tableBtnGroup"
  17. :tableData="tableData"
  18. />
  19. </div>
  20. <!--删除弹框-->
  21. <Dialog
  22. :flag="flag"
  23. msgTitle="删除角色"
  24. type="del"
  25. :delName="title"
  26. @delRest="delRest"
  27. @delRemove="remove"
  28. />
  29. <!--新增/编辑-->
  30. <Dialog
  31. :flag="editDialogVisible"
  32. :msgTitle="editDialogTitle"
  33. @submitForm="submitForm(ruleFormRef)"
  34. @resetForm="resetForm(ruleFormRef)"
  35. :show-flag="true"
  36. >
  37. <el-form
  38. ref="ruleFormRef"
  39. :model="ruleForm"
  40. label-width="110px"
  41. class="demo-ruleForm"
  42. >
  43. <el-form-item
  44. label="角色ID"
  45. :rules="[
  46. { required: true, message: '请输入角色ID', trigger: 'blur' },
  47. ]"
  48. prop="role_id"
  49. >
  50. <el-input
  51. :disabled="msgFlag"
  52. v-model="ruleForm.role_id"
  53. size="default"
  54. placeholder="请输入角色名称"
  55. />
  56. </el-form-item>
  57. <el-form-item
  58. label="角色名称"
  59. :rules="[
  60. { required: true, message: '请输入角色名称', trigger: 'blur' },
  61. ]"
  62. prop="role_name"
  63. >
  64. <el-input
  65. v-model="ruleForm.role_name"
  66. size="default"
  67. placeholder="请输入角色名称"
  68. />
  69. </el-form-item>
  70. <el-form-item label="角色描述" prop="role_comment">
  71. <el-input
  72. v-model="ruleForm.role_comment"
  73. size="default"
  74. type="textarea"
  75. :rows="3"
  76. placeholder="请输入角色描述"
  77. />
  78. </el-form-item>
  79. <el-form-item
  80. label="是否启用"
  81. :rules="[
  82. { required: true, message: '请选择是否启用', trigger: 'change' },
  83. ]"
  84. prop="role_status"
  85. >
  86. <el-radio-group v-model="ruleForm.role_status">
  87. <el-radio :label="1">启用</el-radio>
  88. <el-radio :label="2"> 禁用</el-radio>
  89. </el-radio-group>
  90. </el-form-item>
  91. <el-form-item label="是否存在互斥" prop="repel">
  92. <el-radio-group v-model="ruleForm.repel">
  93. <el-radio :label="1">是</el-radio>
  94. <el-radio :label="0"> 否</el-radio>
  95. </el-radio-group>
  96. </el-form-item>
  97. </el-form>
  98. </Dialog>
  99. </div>
  100. </template>
  101. <script setup lang="ts">
  102. import { ref, onBeforeMount } from "vue";
  103. import { ElMessage, FormInstance, FormRules } from "element-plus";
  104. import Table from "@/components/tableTemp/index.vue";
  105. import Search from "@/components/search/index.vue";
  106. import table from "../hooks/useTable";
  107. import { useUserStore } from "@/store/user";
  108. import * as _ from "lodash";
  109. const router = useRouter();
  110. const ruleFormRef = ref<FormInstance>();
  111. const tableHeader = ref([]);
  112. const tableData = ref([]);
  113. const conditonLisy = ref<any>([]);
  114. const tableBtnGroup = <any>[
  115. {
  116. name: "编辑",
  117. className: "editBtn",
  118. param: "edit",
  119. is: "role_editing_button",
  120. },
  121. {
  122. name: "查看权限",
  123. className: "editBtn",
  124. param: "auth",
  125. is: "role_authorization_button",
  126. },
  127. {
  128. name: "删除",
  129. className: "delBtn",
  130. param: "del",
  131. is: "role_deletion_button",
  132. },
  133. ];
  134. const flag = ref(false);
  135. const msgFlag = ref(false);
  136. const title = ref("");
  137. const dT = ref("add");
  138. const editDialogVisible = ref(false);
  139. const editDialogTitle = ref("新增角色");
  140. const ruleForm = ref<any>({
  141. role_id: "",
  142. role_name: "",
  143. role_comment: "",
  144. role_status: "",
  145. repel: "",
  146. });
  147. const submitID = ref("");
  148. const conditon = ref("");
  149. const searchInfo = ref("");
  150. const rowIndex = ref<any>({});
  151. onBeforeMount(() => {
  152. gueryRoles();
  153. });
  154. const gueryRoles = async () => {
  155. const route = router.currentRoute;
  156. const authMap = useUserStore().authMap;
  157. const role = route.value.meta?.roles?.[0];
  158. const res = await table.getTable(DATACONTENT_ID.allId, [
  159. authMap[role],
  160. sessionStorage.getItem("User_Id"),
  161. ]);
  162. conditon.value = res.tableData.value[0].query_col_conditon;
  163. conditonLisy.value = res.tableData.value[0].query_row_condition
  164. ? JSON.parse(res.tableData.value[0].query_row_condition)
  165. : null;
  166. gueryRole();
  167. };
  168. const gueryRole = async () => {
  169. const res = await table.getTable(DATACONTENT_ID.roleTableNId, [
  170. searchInfo.value,
  171. sessionStorage.getItem("User_Id"),
  172. ]);
  173. tableData.value = [];
  174. if (conditonLisy.value == null) {
  175. tableData.value = res.tableData.value;
  176. } else {
  177. let art = [];
  178. let arts = [];
  179. let art2 = [];
  180. let art3 = [];
  181. conditonLisy.value.forEach((element) => {
  182. if (element.conn == "%") {
  183. res.tableData.value.forEach((res) => {
  184. if (res[element.key].includes(element.val)) {
  185. art.push(res);
  186. }
  187. });
  188. }
  189. if (element.conn == "=") {
  190. if (art.length == 0) {
  191. art = res.tableData.value;
  192. }
  193. art.forEach((res) => {
  194. if (res[element.key] == element.val) {
  195. arts.push(res);
  196. }
  197. });
  198. }
  199. setTimeout(() => {
  200. if (element.conn == ">") {
  201. if (arts.length == 0) {
  202. arts = res.tableData.value;
  203. }
  204. arts.forEach((res) => {
  205. if (Number(res[element.key]) - Number(element.val) > 0) {
  206. art2.push(res);
  207. }
  208. });
  209. }
  210. });
  211. setTimeout(() => {
  212. if (element.conn == "<") {
  213. if (art2.length == 0) {
  214. art2 = res.tableData.value;
  215. }
  216. art2.forEach((res) => {
  217. if (Number(res[element.key]) - Number(element.val) < 0) {
  218. art3.push(res);
  219. }
  220. });
  221. }
  222. tableData.value = art3.length > 0 ? art3 : art2;
  223. });
  224. });
  225. }
  226. submitID.value = res.msgId.value;
  227. if (conditon.value == null) {
  228. tableHeader.value = res.tableHeader.value;
  229. } else {
  230. tableHeader.value = [];
  231. conditon.value.split(",").forEach((element) => {
  232. res.tableHeader.value.forEach((res) => {
  233. if (element === res.columnName) {
  234. tableHeader.value.push(res);
  235. }
  236. });
  237. });
  238. }
  239. };
  240. const search = (val) => {
  241. searchInfo.value = val;
  242. gueryRole();
  243. };
  244. const clear = () => {
  245. searchInfo.value = "";
  246. gueryRole();
  247. };
  248. const btnClick = (index, row, param) => {
  249. rowIndex.value = _.cloneDeep(row);
  250. if (param == "del") {
  251. flag.value = true;
  252. title.value = row.role_name;
  253. } else if (param == "edit") {
  254. msgFlag.value = true;
  255. dT.value = "edit";
  256. editDialogVisible.value = true;
  257. editDialogTitle.value = "编辑角色";
  258. ruleForm.value = _.cloneDeep(row);
  259. } else {
  260. router.push({
  261. path: "/userManagement/role/auth",
  262. query: {
  263. role_id: row.role_id,
  264. },
  265. });
  266. }
  267. };
  268. const delRest = () => {
  269. flag.value = false;
  270. };
  271. const remove = async () => {
  272. rowIndex.value.operator_id = sessionStorage.getItem("User_Id");
  273. if (rowIndex.value.AuthCount != undefined) {
  274. delete rowIndex.value.AuthCount;
  275. }
  276. //UserCount
  277. if (rowIndex.value.UserCount != undefined) {
  278. delete rowIndex.value.UserCount;
  279. }
  280. saveRole(3, rowIndex.value);
  281. flag.value = false;
  282. };
  283. const addApp = () => {
  284. editDialogVisible.value = true;
  285. editDialogTitle.value = "新增角色";
  286. dT.value = "add";
  287. msgFlag.value = false;
  288. ruleForm.value = {};
  289. };
  290. const btnAuthMap = [
  291. ,
  292. "new_role_button",
  293. "role_editing_button",
  294. "role_deletion_button",
  295. ];
  296. // 新增/编辑/删除角色
  297. const saveRole = async (event, data) => {
  298. try {
  299. const { code, message } = await table.dataChange(
  300. submitID.value,
  301. event,
  302. data,
  303. btnAuthMap[event]
  304. );
  305. if (code == 0) {
  306. ElMessage.success(`操作成功`);
  307. gueryRole();
  308. } else {
  309. ElMessage.error(`操作失败`);
  310. }
  311. } catch (error) {}
  312. };
  313. const submitForm = async (formEl: FormInstance | undefined) => {
  314. if (!formEl) return;
  315. await formEl.validate((valid, fields) => {
  316. if (valid) {
  317. if (dT.value == "add") {
  318. ruleForm.value.operator_id = sessionStorage.getItem("User_Id");
  319. saveRole(1, ruleForm.value);
  320. } else {
  321. ruleForm.value.operator_id = sessionStorage.getItem("User_Id");
  322. saveRole(2, ruleForm.value);
  323. }
  324. editDialogVisible.value = false;
  325. } else {
  326. console.log("error submit!", fields);
  327. }
  328. });
  329. };
  330. const resetForm = (formEl: FormInstance | undefined) => {
  331. if (!formEl) return;
  332. formEl.resetFields();
  333. editDialogVisible.value = false;
  334. };
  335. </script>
  336. <style lang="scss" scoped>
  337. .application {
  338. &-content {
  339. margin-top: 24px;
  340. height: calc(100% - 56px);
  341. }
  342. }
  343. </style>