index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 v-permission="['add_account_button']" size="default" @click="addApp" plain>新增</el-button>
  8. </div>
  9. </div>
  10. <div class="application-content flex">
  11. <div class="box account-tree">
  12. <el-tree :data="data" :props="defaultProps" node-key="user_group_id" default-expand-all :expand-on-click-node="false" @node-click="handleNodeClick" />
  13. </div>
  14. <Table class="account-table" btnGroupWidth="250px" :tableHeader="tableHeader" @btnClick="btnClick" :tableBtnGroup="tableBtnGroup" :tableData="tableData" />
  15. </div>
  16. <!--删除弹框-->
  17. <Dialog :flag="flag" msgTitle="删除账号" type="del" :delName="title" @delRest="delRest" @delRemove="remove" />
  18. <!--新增/编辑-->
  19. <Dialog :flag="editDialogVisible" :msgTitle="editDialogTitle" @submitForm="submitForm(ruleFormRef)" @resetForm="resetForm(ruleFormRef)" :show-flag="true">
  20. <el-form ref="ruleFormRef" :model="ruleForm" label-width="110px" class="demo-ruleForm">
  21. <el-form-item label="账号名称" :rules="[{required: true,message: '请输入账号名称',trigger: 'blur',}]" prop="user_name">
  22. <el-input :disabled="dT == 'edit'" v-model="ruleForm.user_name" size="default" placeholder="请输入账号名称" />
  23. </el-form-item>
  24. <el-form-item label="账号密码" :rules="[{required: true,message: '请输入账号密码',trigger: 'blur',}]" prop="user_pwd">
  25. <el-input v-model="ruleForm.user_pwd" type="password" show-password size="default" placeholder="请输入账号密码" />
  26. </el-form-item>
  27. <el-form-item label="账号组关联" prop="user_gropu_id">
  28. <el-select size="default" style="width: 100%" v-model="ruleForm.user_group_id" placeholder="请选择">
  29. <el-option v-for="item in options" :key="item.v" :label="item.k" :value="item.v"> </el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="账号描述" prop="user_comment">
  33. <el-input v-model="ruleForm.user_comment" size="default" type="textarea" :rows="3" placeholder="请输入账号描述" />
  34. </el-form-item>
  35. <el-form-item label="是否启用" :rules="[{required: true,message: '请选择是否启用',trigger: 'change',}]" prop="user_status">
  36. <el-radio-group v-model="ruleForm.user_status">
  37. <el-radio :label="ruleForm.user_status || 2">启用</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, reactive, 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 Dialog from "@/components/dialog/index.vue";
  51. import { translateDataToTreeAll } from "@/utils/validate";
  52. import { GeneralDataReception, Query } from "@/api/webApi";
  53. import * as _ from "lodash";
  54. import MD5 from "blueimp-md5";
  55. import table from "../hooks/useTable";
  56. const router = useRouter();
  57. const ruleFormRef = ref<FormInstance>();
  58. const tableHeader = ref<any>([]);
  59. const tableData = ref<any>([]);
  60. const tableBtnGroup = <any>[
  61. {
  62. name: "编辑",
  63. className: "editBtn",
  64. param: "edit",
  65. is: "account_editing_button",
  66. },
  67. {
  68. name: "查看权限",
  69. className: "editBtn",
  70. param: "auth",
  71. is: "account_authorization_button",
  72. },
  73. {
  74. name: "删除",
  75. className: "delBtn",
  76. param: "del",
  77. is: "account_deletion_button",
  78. },
  79. ];
  80. const flag = ref(false);
  81. const title = ref("");
  82. const dT = ref("add");
  83. const editDialogVisible = ref(false);
  84. const editDialogTitle = ref("新增账号");
  85. const ruleForm = ref<any>({
  86. user_name: "",
  87. user_comment: "",
  88. user_status: "",
  89. user_pwd: "",
  90. user_group_id: "",
  91. });
  92. const rowIndex = ref<any>({});
  93. const data = ref<any>([]);
  94. const options = ref<any>([]);
  95. const msgId = ref(null);
  96. const msgType = ref("all");
  97. const PageIndex = ref(1);
  98. const searchInfo = ref("");
  99. const pwdInfo = ref(null);
  100. //获取用户组
  101. const getGroup = async () => {
  102. const { code, returnData } = await Query({
  103. id: DATACONTENT_ID.accountGroupTableId,
  104. dataContent: [""],
  105. });
  106. if (code == 0 && returnData.listValues) {
  107. const dataObj = {
  108. user_group_id: -1,
  109. up_user_group_id: -2,
  110. user_group_name: "全部用户组",
  111. children: translateDataToTreeAll(
  112. returnData.listValues,
  113. "up_user_group_id",
  114. "user_group_id"
  115. ),
  116. };
  117. data.value = [dataObj];
  118. } else {
  119. const dataObj = {
  120. user_group_id: -1,
  121. up_user_group_id: -2,
  122. user_group_name: "全部用户组",
  123. children: [],
  124. };
  125. data.value = [dataObj];
  126. }
  127. };
  128. //获取table
  129. const accountList = async () => {
  130. let result: any = null;
  131. if (msgType.value == "all") {
  132. result = await Query({
  133. id: DATACONTENT_ID.accountTableId,
  134. needPage: PageIndex.value,
  135. dataContent: [searchInfo.value],
  136. });
  137. } else {
  138. result = await Query({
  139. id: DATACONTENT_ID.accountGroupDetailsId,
  140. dataContent: [msgId.value],
  141. needPage: PageIndex.value,
  142. });
  143. }
  144. const { code, returnData, message } = result;
  145. if (code == 0) {
  146. const { columnSet, listValues } = returnData;
  147. tableHeader.value = columnSet;
  148. tableData.value = listValues;
  149. } else {
  150. ElMessage.error(message);
  151. }
  152. };
  153. // 回到第一页
  154. const pageInit = () => {
  155. PageIndex.value = 1;
  156. tableHeader.value = [];
  157. tableData.value = [];
  158. accountList();
  159. };
  160. //增删改
  161. const dataChange = async (event, data) => {
  162. const { code, message } = await table.dataChange(
  163. SERVICE_ID.accountScId,
  164. event,
  165. {
  166. ...data,
  167. user_status: data.user_status != 0 ? 2 : 0
  168. }
  169. );
  170. if (code == 0) {
  171. ElMessage.success(message);
  172. pageInit();
  173. } else {
  174. ElMessage.error(message);
  175. }
  176. };
  177. //获取账号组
  178. const getGroupSelect = async () => {
  179. const res = await Query({
  180. id: DATACONTENT_ID.accountGroupSelId,
  181. dataContent: [],
  182. });
  183. if (res.code == 0) {
  184. const { listValues } = res.returnData;
  185. options.value = listValues;
  186. } else {
  187. ElMessage.error(res.message);
  188. }
  189. };
  190. onBeforeMount(() => {
  191. getGroup();
  192. accountList();
  193. getGroupSelect();
  194. });
  195. const handleNodeClick = (data) => {
  196. tableHeader.value = [];
  197. tableData.value = [];
  198. if (data.user_group_id != -1 && data.up_user_group_id != -2) {
  199. PageIndex.value = 1;
  200. msgType.value = "cld";
  201. msgId.value = data.user_group_id;
  202. accountList();
  203. } else {
  204. msgType.value = "all";
  205. clear();
  206. }
  207. };
  208. const defaultProps = {
  209. children: "children",
  210. label: "user_group_name",
  211. };
  212. const search = (val) => {
  213. searchInfo.value = val;
  214. pageInit();
  215. };
  216. const clear = () => {
  217. searchInfo.value = "";
  218. pageInit();
  219. };
  220. const btnClick = (index, row, param) => {
  221. rowIndex.value = row;
  222. if (param == "del") {
  223. flag.value = true;
  224. title.value = row.user_name;
  225. } else if (param == "edit") {
  226. dT.value = "edit";
  227. editDialogVisible.value = true;
  228. pwdInfo.value = row.user_pwd;
  229. editDialogTitle.value = "编辑账号";
  230. ruleForm.value = _.cloneDeep(row);
  231. } else {
  232. router.push({
  233. path: "/userManagement/account/accountAuth",
  234. query: {
  235. id: row.user_id,
  236. },
  237. });
  238. }
  239. };
  240. const delRest = () => {
  241. flag.value = false;
  242. };
  243. const remove = () => {
  244. dataChange(3, rowIndex.value);
  245. flag.value = false;
  246. };
  247. const addApp = () => {
  248. editDialogVisible.value = true;
  249. editDialogTitle.value = "新增账号";
  250. dT.value = "add";
  251. ruleForm.value = {};
  252. };
  253. const submitForm = async (formEl: FormInstance | undefined) => {
  254. if (!formEl) return;
  255. await formEl.validate((valid, fields) => {
  256. if (valid) {
  257. if (dT.value == "add") {
  258. ruleForm.value.user_pwd = MD5(ruleForm.value.user_pwd);
  259. dataChange(1, ruleForm.value);
  260. } else {
  261. if (ruleForm.value.user_pwd === pwdInfo.value) {
  262. dataChange(2, ruleForm.value);
  263. } else {
  264. ruleForm.value.user_pwd = MD5(ruleForm.value.user_pwd);
  265. dataChange(2, ruleForm.value);
  266. }
  267. }
  268. editDialogVisible.value = false;
  269. } else {
  270. console.log("error submit!", fields);
  271. }
  272. });
  273. };
  274. const resetForm = (formEl: FormInstance | undefined) => {
  275. if (!formEl) return;
  276. formEl.resetFields();
  277. editDialogVisible.value = false;
  278. };
  279. </script>
  280. <style lang="scss" scoped>
  281. .application {
  282. &-content {
  283. margin-top: 24px;
  284. height: calc(100% - 56px);
  285. }
  286. }
  287. .account {
  288. &-tree {
  289. width: 488px;
  290. margin-right: 24px;
  291. }
  292. &-table {
  293. flex: 1;
  294. }
  295. }
  296. </style>