| | |
| | | import { login, getMenuAdmin } from "@/api/login"; |
| | | import Cookies from 'js-cookie'; |
| | | import {Base64} from "js-base64"; |
| | | import {getAreaWithUserIfo} from "@/api/user"; |
| | | |
| | | |
| | | export default { |
| | |
| | | Cookies.set('resTk', res.data.data.tk); |
| | | Cookies.set('resUid', res.data.data.uid); |
| | | Cookies.set('userInfo',JSON.stringify(res.data.data),{expires: 7}) |
| | | await this.getAreaUsers(res.data.data.districtId) |
| | | if (this.saveAccount) { |
| | | localStorage.setItem('userName', this.form.name) |
| | | localStorage.setItem('userPassword', Base64.encode(this.form.pwd)) |
| | |
| | | }); |
| | | }, |
| | | |
| | | async getAreaUsers(districtId) { |
| | | let t = this |
| | | let res = await getAreaWithUserIfo() |
| | | if (res.data.code == 100) { |
| | | if (res.data.data) { |
| | | t.userTitTree(res.data.data) |
| | | const areaUsers = t.findNodeById(res.data.data, districtId).children |
| | | localStorage.removeItem('areaUsers') |
| | | localStorage.setItem('areaUsers',JSON.stringify(areaUsers)) |
| | | } else { |
| | | console.log('暂无数据') |
| | | } |
| | | } else { |
| | | this.$message.warning(res.data.msg); |
| | | } |
| | | }, |
| | | |
| | | // 根据id查对象 |
| | | findNodeById(data, value) { |
| | | for (const node of data) { |
| | | if (node.id === value) { |
| | | return node; |
| | | } |
| | | if (node.children) { |
| | | const foundNode = this.findNodeById(node.children, value); |
| | | if (foundNode) { |
| | | return foundNode; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | }, |
| | | |
| | | // 将树状数据name字段放入users的姓名电话 |
| | | userTitTree(treeData) { |
| | | for (const node of treeData) { |
| | | if (node.users) { |
| | | node.users = node.users.filter(i => i.roleId == 3) |
| | | node.users = node.users.map((i) => { |
| | | return { |
| | | ...i, |
| | | unittype: node.type, |
| | | districtId: node.id |
| | | } |
| | | }) |
| | | node.name = node.name + '(' + node.users.map(i => i.realName + ' ' + i.phone).join(',') + ')' |
| | | } |
| | | if (node.children) { |
| | | this.userTitTree(node.children) |
| | | } |
| | | } |
| | | return treeData |
| | | } |
| | | }, |
| | | }; |
| | | </script> |