index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div class="application account 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
  8. v-permission="['add_account_button']"
  9. size="default"
  10. @click="addApp"
  11. plain
  12. >新增</el-button
  13. >
  14. </div>
  15. </div>
  16. <div class="application-content flex">
  17. <div class="box account-tree">
  18. <el-tree
  19. :data="data"
  20. :props="defaultProps"
  21. node-key="user_group_id"
  22. default-expand-all
  23. :expand-on-click-node="false"
  24. @node-click="handleNodeClick"
  25. />
  26. </div>
  27. <Table
  28. class="account-table"
  29. btnGroupWidth="250px"
  30. :tableHeader="tableHeader"
  31. @btnClick="btnClick"
  32. :tableBtnGroup="tableBtnGroup"
  33. :tableData="tableData"
  34. />
  35. </div>
  36. <!--删除弹框-->
  37. <Dialog
  38. :flag="flag"
  39. msgTitle="删除账号"
  40. type="del"
  41. :delName="title"
  42. @delRest="delRest"
  43. @delRemove="remove"
  44. />
  45. <!--新增/编辑-->
  46. <Dialog
  47. :flag="editDialogVisible"
  48. :msgTitle="editDialogTitle"
  49. @submitForm="submitForm(ruleFormRef)"
  50. @resetForm="resetForm(ruleFormRef)"
  51. :show-flag="true"
  52. >
  53. <el-form
  54. ref="ruleFormRef"
  55. :model="ruleForm"
  56. label-width="110px"
  57. class="demo-ruleForm"
  58. >
  59. <el-form-item
  60. label="账号名称"
  61. :rules="[
  62. { required: true, message: '请输入账号名称', trigger: 'blur' },
  63. ]"
  64. prop="user_name"
  65. >
  66. <el-input
  67. :disabled="dT == 'edit'"
  68. v-model="ruleForm.user_name"
  69. size="default"
  70. placeholder="请输入账号名称"
  71. />
  72. </el-form-item>
  73. <el-form-item
  74. label="账号密码"
  75. :rules="[
  76. { required: true, message: '请输入账号密码', trigger: 'blur' },
  77. ]"
  78. prop="user_pwd"
  79. >
  80. <el-input
  81. v-model="ruleForm.user_pwd"
  82. type="password"
  83. show-password
  84. size="default"
  85. placeholder="请输入账号密码"
  86. />
  87. </el-form-item>
  88. <el-form-item label="账号组关联" prop="user_gropu_id">
  89. <el-select
  90. size="default"
  91. style="width: 100%"
  92. v-model="ruleForm.user_group_id"
  93. placeholder="请选择"
  94. >
  95. <el-option
  96. v-for="item in options"
  97. :key="item.v"
  98. :label="item.k"
  99. :value="item.v"
  100. >
  101. </el-option>
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="账号描述" prop="user_comment">
  105. <el-input
  106. v-model="ruleForm.user_comment"
  107. size="default"
  108. type="textarea"
  109. :rows="3"
  110. placeholder="请输入账号描述"
  111. />
  112. </el-form-item>
  113. <el-form-item
  114. label="是否启用"
  115. :rules="[
  116. { required: true, message: '请选择是否启用', trigger: 'change' },
  117. ]"
  118. prop="user_status"
  119. >
  120. <el-radio-group v-model="ruleForm.user_status">
  121. <el-radio
  122. :label="
  123. ruleForm.user_status != '0' && ruleForm.user_status == '1'
  124. ? '1'
  125. : '2'
  126. "
  127. >启用</el-radio
  128. >
  129. <el-radio label="0">禁用</el-radio>
  130. </el-radio-group>
  131. </el-form-item>
  132. </el-form>
  133. </Dialog>
  134. </div>
  135. </template>
  136. <script setup lang="ts">
  137. import { ref, reactive, onBeforeMount } from "vue";
  138. import { ElMessage, FormInstance, FormRules } from "element-plus";
  139. import Table from "@/components/tableTemp/index.vue";
  140. import Search from "@/components/search/index.vue";
  141. import Dialog from "@/components/dialog/index.vue";
  142. import { translateDataToTreeAll } from "@/utils/validate";
  143. import { GeneralDataReception, Query } from "@/api/webApi";
  144. import * as _ from "lodash";
  145. import MD5 from "blueimp-md5";
  146. import table from "../hooks/useTable";
  147. const router = useRouter();
  148. const ruleFormRef = ref<FormInstance>();
  149. const tableHeader = ref<any>([]);
  150. const tableData = ref<any>([]);
  151. const conditon = ref("");
  152. const tableBtnGroup = <any>[
  153. {
  154. name: "编辑",
  155. className: "editBtn",
  156. param: "edit",
  157. is: "account_editing_button",
  158. },
  159. {
  160. name: "查看权限",
  161. className: "editBtn",
  162. param: "auth",
  163. is: "account_authorization_button",
  164. },
  165. {
  166. name: "删除",
  167. className: "delBtn",
  168. param: "del",
  169. is: "account_deletion_button",
  170. },
  171. ];
  172. const flag = ref(false);
  173. const title = ref("");
  174. const dT = ref("add");
  175. const editDialogVisible = ref(false);
  176. const editDialogTitle = ref("新增账号");
  177. const ruleForm = ref<any>({
  178. user_name: "",
  179. user_comment: "",
  180. user_status: "",
  181. user_pwd: "",
  182. user_group_id: "",
  183. });
  184. const rowIndex = ref<any>({});
  185. const data = ref<any>([]);
  186. const options = ref<any>([]);
  187. const msgId = ref(null);
  188. const msgType = ref("all");
  189. const PageIndex = ref(1);
  190. const searchInfo = ref("");
  191. const pwdInfo = ref(null);
  192. const submitID = ref<any>("");
  193. //获取用户组
  194. const getGroup = async () => {
  195. const { code, returnData } = await Query({
  196. id: DATACONTENT_ID.accountGroupTableId,
  197. dataContent: [""],
  198. });
  199. if (code == 0 && returnData.listValues) {
  200. const dataObj = {
  201. user_group_id: -1,
  202. up_user_group_id: -2,
  203. user_group_name: "全部用户组",
  204. children: translateDataToTreeAll(
  205. returnData.listValues,
  206. "up_user_group_id",
  207. "user_group_id"
  208. ),
  209. };
  210. data.value = [dataObj];
  211. } else {
  212. const dataObj = {
  213. user_group_id: -1,
  214. up_user_group_id: -2,
  215. user_group_name: "全部用户组",
  216. children: [],
  217. };
  218. data.value = [dataObj];
  219. }
  220. };
  221. const gueryRoles = async () => {
  222. const res = await table.getTable(DATACONTENT_ID.allId, [
  223. sessionStorage.getItem("auth-id"),
  224. sessionStorage.getItem("User_Id"),
  225. ]);
  226. conditon.value = res.tableData.value[0].query_col_conditon;
  227. accountList();
  228. };
  229. //获取table
  230. const accountList = async (type?: string) => {
  231. let result: any = null;
  232. if (msgType.value == "all") {
  233. result = await Query({
  234. id: DATACONTENT_ID.accountTableId,
  235. needPage: PageIndex.value,
  236. dataContent: [searchInfo.value],
  237. });
  238. } else {
  239. result = await Query({
  240. id:
  241. type == "tree"
  242. ? DATACONTENT_ID.accountGroupDetailsId
  243. : DATACONTENT_ID.accountTableId,
  244. dataContent: type == "tree" ? [msgId.value] : [searchInfo.value],
  245. needPage: PageIndex.value,
  246. });
  247. }
  248. const { code, returnData, message } = result;
  249. if (code == 0) {
  250. const { columnSet, listValues } = returnData;
  251. let arr = columnSet.map((column) => ({
  252. ...column,
  253. formatter:
  254. column.columnName === "user_status"
  255. ? function (row, column, cellValue, index) {
  256. return ["1", "2"].includes(String(cellValue)) ? "启用" : "禁用";
  257. }
  258. : undefined,
  259. }));
  260. if (conditon.value == null) {
  261. tableHeader.value = arr;
  262. } else {
  263. tableHeader.value = [];
  264. conditon.value.split(",").forEach((element) => {
  265. arr.forEach((res) => {
  266. if (element === res.columnName) {
  267. tableHeader.value.push(res);
  268. }
  269. });
  270. });
  271. }
  272. tableData.value = listValues;
  273. submitID.value = returnData.submitID;
  274. } else {
  275. ElMessage.error(message);
  276. }
  277. };
  278. // 回到第一页
  279. const pageInit = () => {
  280. PageIndex.value = 1;
  281. tableHeader.value = [];
  282. tableData.value = [];
  283. gueryRoles();
  284. // accountList();
  285. };
  286. const btnAuthMap = [
  287. ,
  288. "add_account_button",
  289. "account_editing_button",
  290. "account_deletion_button",
  291. ];
  292. //增删改
  293. const dataChange = async (event, data) => {
  294. const { code, message } = await table.dataChange(
  295. submitID.value,
  296. event,
  297. {
  298. ...data,
  299. user_status: data.user_status != 0 ? 2 : 0,
  300. },
  301. btnAuthMap[event]
  302. );
  303. if (code == 0) {
  304. ElMessage.success(message);
  305. pageInit();
  306. } else {
  307. ElMessage.error(message);
  308. }
  309. };
  310. //获取账号组
  311. const getGroupSelect = async () => {
  312. const res = await Query({
  313. id: DATACONTENT_ID.accountGroupSelId,
  314. dataContent: [],
  315. });
  316. if (res.code == 0) {
  317. const { listValues } = res.returnData;
  318. options.value = listValues;
  319. } else {
  320. ElMessage.error(res.message);
  321. }
  322. };
  323. onBeforeMount(() => {
  324. getGroup();
  325. gueryRoles();
  326. // accountList();
  327. getGroupSelect();
  328. });
  329. const handleNodeClick = (data) => {
  330. tableHeader.value = [];
  331. tableData.value = [];
  332. if (data.user_group_id != -1 && data.up_user_group_id != -2) {
  333. PageIndex.value = 1;
  334. msgType.value = "cld";
  335. msgId.value = data.user_group_id;
  336. gueryRoles();
  337. accountList("tree");
  338. } else {
  339. msgType.value = "all";
  340. clear();
  341. }
  342. };
  343. const defaultProps = {
  344. children: "children",
  345. label: "user_group_name",
  346. };
  347. const search = (val) => {
  348. searchInfo.value = val;
  349. pageInit();
  350. };
  351. const clear = () => {
  352. searchInfo.value = "";
  353. pageInit();
  354. };
  355. const btnClick = (index, row, param) => {
  356. rowIndex.value = row;
  357. if (param == "del") {
  358. flag.value = true;
  359. title.value = row.user_name;
  360. } else if (param == "edit") {
  361. dT.value = "edit";
  362. editDialogVisible.value = true;
  363. pwdInfo.value = row.user_pwd;
  364. editDialogTitle.value = "编辑账号";
  365. ruleForm.value = _.cloneDeep(row);
  366. console.log(ruleForm.value);
  367. } else {
  368. router.push({
  369. path: "/userManagement/account/accountAuth",
  370. query: {
  371. id: row.user_id,
  372. },
  373. });
  374. }
  375. };
  376. const delRest = () => {
  377. flag.value = false;
  378. };
  379. const remove = () => {
  380. if (rowIndex.value.AuthCount != undefined) {
  381. delete rowIndex.value.AuthCount;
  382. }
  383. dataChange(3, rowIndex.value);
  384. flag.value = false;
  385. };
  386. const addApp = () => {
  387. editDialogVisible.value = true;
  388. editDialogTitle.value = "新增账号";
  389. dT.value = "add";
  390. ruleForm.value = {};
  391. };
  392. const submitForm = async (formEl: FormInstance | undefined) => {
  393. if (!formEl) return;
  394. await formEl.validate((valid, fields) => {
  395. if (valid) {
  396. if (dT.value == "add") {
  397. ruleForm.value.user_pwd = MD5(ruleForm.value.user_pwd);
  398. dataChange(1, ruleForm.value);
  399. } else {
  400. if (ruleForm.value.user_pwd === pwdInfo.value) {
  401. dataChange(2, ruleForm.value);
  402. } else {
  403. ruleForm.value.user_pwd = MD5(ruleForm.value.user_pwd);
  404. dataChange(2, ruleForm.value);
  405. }
  406. }
  407. editDialogVisible.value = false;
  408. } else {
  409. console.log("error submit!", fields);
  410. }
  411. });
  412. };
  413. const resetForm = (formEl: FormInstance | undefined) => {
  414. if (!formEl) return;
  415. formEl.resetFields();
  416. editDialogVisible.value = false;
  417. };
  418. </script>
  419. <style lang="scss" scoped>
  420. .application {
  421. &-content {
  422. margin-top: 24px;
  423. height: calc(100% - 56px);
  424. }
  425. }
  426. .account {
  427. &-tree {
  428. width: 488px;
  429. margin-right: 24px;
  430. }
  431. &-table {
  432. flex: 1;
  433. }
  434. }
  435. </style>