Skip to content

Commit 3484dfc

Browse files
committed
feat: update
1 parent 87361a4 commit 3484dfc

File tree

4 files changed

+192
-11
lines changed

4 files changed

+192
-11
lines changed

src/api/User/index.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import request from '@/utils/request'
44
export function postCode(account) {
55
return request({
66
url: '/smscode?account=' + account,
7-
method: 'post',
7+
method: 'post'
88
// data,
99
// params
1010
// headers: {
@@ -17,7 +17,7 @@ export function verifyCode(phone, code, username, password) {
1717
return request({
1818
url: `/verify_code?account=${phone}&code=${code}&username=${username}&password=${password}`,
1919
method: 'post',
20-
data:{},
20+
data: {}
2121
// params
2222
// headers: {
2323
// "Content-Type": "text/plain"
@@ -32,15 +32,15 @@ export function login(data) {
3232
method: 'post',
3333
data,
3434
headers: {
35-
"Content-Type": "text/plain"
36-
35+
'Content-Type': 'text/plain'
36+
3737
}
3838
})
3939
}
4040
export function Roletree() {
4141
return request({
4242
url: '/roletree',
43-
method: 'get',
43+
method: 'get'
4444
})
4545
}
4646
export function getToken(params) {
@@ -54,14 +54,11 @@ export function getToken(params) {
5454
export function putUserInfo(objectId, data) {
5555
return request({
5656
url: `/amis/_User/${objectId}`,
57-
method: "put",
57+
method: 'put',
5858
data
5959
})
6060
}
6161

62-
63-
64-
6562
export function getInfo(token) {
6663
return request({
6764
url: '/vue-admin-template/user/info',

src/permission.js

+78-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import NProgress from 'nprogress' // progress bar
55
import 'nprogress/nprogress.css' // progress bar style
66
import { getToken } from '@/utils/auth' // get token from cookie
77
import getPageTitle from '@/utils/get-page-title'
8+
import Cookies from 'js-cookie'
9+
import { getNavigation } from '@/api/Navigation'
10+
import { Roletree } from '@/api/User/index'
11+
import { postCookie } from '@/api/Dashboard/index'
12+
import VueRouter from 'vue-router'
813

914
NProgress.configure({ showSpinner: false }) // NProgress Configuration
1015

@@ -18,8 +23,80 @@ router.beforeEach(async(to, from, next) => {
1823
document.title = getPageTitle(to.meta.title)
1924

2025
// determine whether the user has logged in
21-
const hasToken = getToken()
2226
// console.log('路由拦截',hasToken);
27+
console.error('to.query', to.query)
28+
if (to.query.username) {
29+
// http://192.168.2.132:3333/#/dashboard?username=ailiandata&password=fJYjEFg59H
30+
// https://work.dgiotcloud.com/#/dashboard?username=ailiandata&password=fJYjEFg59H
31+
// https://work.dgiotcloud.com/#/amis/View/f864c8f234?username=ailiandata&password=fJYjEFg59H
32+
await store.dispatch('user/login', {
33+
username: to.query.username || '',
34+
password: to.query.password || ''
35+
})
36+
.then(async() => {
37+
Vue.prototype.$FileServe = Cookies.get('fileServer') || ''
38+
const res = await getNavigation()
39+
console.log('路由', res)
40+
const list = []
41+
const item = {
42+
path: '/',
43+
url: '/',
44+
// component: Layout,
45+
redirect: '/dashboard',
46+
meta: {
47+
title: '首页',
48+
icon: 'dashboard',
49+
hidden: false
50+
},
51+
children: [
52+
{
53+
path: '/dashboard',
54+
url: '/dashboard',
55+
name: 'Dashboard',
56+
// component: () => import("@/views/dashboard/index"),
57+
meta: { title: '首页', icon: 'el-icon-s-home', hidden: false }
58+
}
59+
]
60+
}
61+
list.push(item)
62+
res.results.forEach((item) => {
63+
if (item.url != '/' && item.url != '/roles') {
64+
list.push(item)
65+
}
66+
})
67+
store.dispatch('user/initRoutes', list).then(res => {
68+
const routelist = []
69+
// 过滤admin 中的路由
70+
res.forEach((element, index) => {
71+
if (element.children) {
72+
if (
73+
element.children[0].url.indexOf('amis') >= 0 ||
74+
element.children[0].name.indexOf('Dashboard') >= 0
75+
) {
76+
routelist.push(element)
77+
}
78+
} else {
79+
routelist.push(element)
80+
}
81+
})
82+
localStorage.setItem('routes', JSON.stringify(routelist)) // 路由列表
83+
})
84+
const roletree = await Roletree()
85+
localStorage.setItem(
86+
'dgiotroletree',
87+
JSON.stringify(roletree.results)
88+
)
89+
// 设置使用什么地图
90+
const data = {
91+
UserSession: getToken() || '',
92+
cookie: {
93+
mapType: 'baidu'
94+
}
95+
}
96+
await postCookie(data)
97+
})
98+
}
99+
const hasToken = getToken()
23100
if (hasToken) {
24101
if (to.path === '/login') {
25102
// if is logged in, redirect to the home page

src/store/modules/user.js

+107
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { login, logout, getInfo, verifyCode } from '@/api/User/index'
22
import { getToken, setToken, removeToken } from '@/utils/auth'
33
import { resetRouter } from '@/router'
44
import Cookies from 'js-cookie'
5+
import store from '@/store'
56

67
const getDefaultState = () => {
78
return {
@@ -97,7 +98,113 @@ const actions = {
9798
})
9899
})
99100
},
101+
initRoutes({ commit }, routes) {
102+
// console.error('routes', routes)
103+
return new Promise((resolve, reject) => {
104+
routes.forEach((item, i) => {
105+
item.path = item.url
106+
if (item.children) {
107+
store.dispatch('user/initRoutes', item.children)
108+
}
109+
if (item.meta && item.meta.icon.indexOf('dgiot_file') < 0) {
110+
if (item.meta.title.indexOf('云') >= 0) {
111+
item.meta.icon = 'el-icon-cloudy'
112+
}
113+
if (item.meta.title.indexOf('管理') >= 0) {
114+
item.meta.icon = 'el-icon-s-management'
115+
}
116+
117+
if (item.meta.title.indexOf('设备管理') >= 0) {
118+
item.meta.icon = 'el-icon-monitor'
119+
}
120+
if (
121+
item.meta.title.indexOf('运维') >= 0 ||
122+
item.meta.title.indexOf('设置') >= 0
123+
) {
124+
item.meta.icon = 'el-icon-setting'
125+
}
126+
if (item.meta.title.indexOf('工单') >= 0) {
127+
item.meta.icon = 'el-icon-s-order'
128+
}
129+
if (item.meta.title.indexOf('系统') >= 0) {
130+
item.meta.icon = 'el-icon-s-help'
131+
}
132+
if (item.meta.title.indexOf('告警') >= 0) {
133+
item.meta.icon = 'el-icon-bell'
134+
}
135+
// if (item.meta.title.indexOf("数据") >= 0) {
136+
// item.meta.icon = "el-icon-s-data";
137+
// }
138+
if (item.meta.title.indexOf('日志') >= 0) {
139+
item.meta.icon = 'el-icon-notebook-1'
140+
}
141+
if (
142+
item.meta.title.indexOf('园区') >= 0 ||
143+
item.meta.title.indexOf('建筑') >= 0
144+
) {
145+
item.meta.icon = 'el-icon-office-building'
146+
}
147+
148+
if (item.meta.title.indexOf('工厂') >= 0) {
149+
item.meta.icon = 'el-icon-school'
150+
}
151+
if (
152+
item.meta.title.indexOf('人') >= 0 ||
153+
item.meta.title.indexOf('员工') >= 0
154+
) {
155+
item.meta.icon = 'el-icon-user-solid'
156+
} else if (item.meta.title.indexOf('工序') >= 0) {
157+
item.meta.icon = 'el-icon-s-operation'
158+
} else if (item.meta.title.indexOf('场景') >= 0) {
159+
item.meta.icon = 'el-icon-picture-outline'
160+
} else if (item.meta.title.indexOf('质检') >= 0) {
161+
item.meta.icon = 'el-icon-circle-check'
162+
} else if (item.meta.title.indexOf('监控') >= 0) {
163+
item.meta.icon = 'el-icon-camera'
164+
} else if (item.meta.title.indexOf('票') >= 0) {
165+
item.meta.icon = 'el-icon-s-ticket'
166+
} else if (item.meta.title.indexOf('信息') >= 0) {
167+
item.meta.icon = 'el-icon-info'
168+
} else if (item.meta.title.indexOf('系统') >= 0) {
169+
item.meta.icon = 'el-icon-data-analysis'
170+
} else if (item.meta.title.indexOf('控制') >= 0) {
171+
item.meta.icon = 'el-icon-eleme'
172+
} else if (
173+
item.meta.title.indexOf('光') >= 0 ||
174+
item.meta.title.indexOf('支路') >= 0
175+
) {
176+
item.meta.icon = 'el-icon-cpu'
177+
} else if (item.meta.title.indexOf('照明') >= 0) {
178+
item.meta.icon = 'el-icon-s-opportunity'
179+
} else if (item.meta.title.indexOf('空调') >= 0) {
180+
item.meta.icon = 'el-icon-receiving'
181+
} else if (item.meta.title.indexOf('能耗') >= 0) {
182+
item.meta.icon = 'el-icon-magic-stick'
183+
} else if (item.meta.title.indexOf('机械') >= 0) {
184+
item.meta.icon = 'material'
185+
} else if (item.meta.title.indexOf('停车') >= 0) {
186+
item.meta.icon = 'stop'
187+
}
188+
if (item.meta.title.indexOf('对战') >= 0) {
189+
item.meta.icon = 'fight'
190+
} else if (item.meta.title.indexOf('射击') >= 0) {
191+
item.meta.icon = 'shooting'
192+
} else if (item.meta.title.indexOf('跑') >= 0) {
193+
item.meta.icon = 'run'
194+
} else if (item.meta.title.indexOf('跳') >= 0) {
195+
item.meta.icon = 'jump'
196+
} else if (item.meta.title.indexOf('投') >= 0) {
197+
item.meta.icon = 'throw'
198+
}
100199

200+
// console.log("mata", item.meta);
201+
// el-icon-cloudy
202+
}
203+
})
204+
// console.log('routes', routes)
205+
resolve(routes)
206+
})
207+
},
101208
// get user info
102209
getInfo({ commit, state }) {
103210
return new Promise((resolve, reject) => {

src/views/login/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export default {
362362
// el-icon-cloudy
363363
}
364364
})
365-
console.log('routes', routes)
365+
// console.log('routes', routes)
366366
return routes
367367
},
368368
async defaultSet() {

0 commit comments

Comments
 (0)