vue2-client 1.2.112 → 1.2.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/pages/login/Login.vue +273 -274
- package/src/store/mutation-types.js +2 -1
- package/src/utils/request.js +225 -270
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
> 所有关于本项目的变化都在该文档里。
|
|
3
3
|
|
|
4
|
+
**1.2.113 - 1.2.115 -2022-09-02 @江超**
|
|
5
|
+
- 功能修改:
|
|
6
|
+
- 修改请求后只有当返回的token有值时才设置store
|
|
7
|
+
|
|
8
|
+
**1.2.112 -2022-09-02 @江超**
|
|
9
|
+
- 功能修改:
|
|
10
|
+
- 依赖更新
|
|
11
|
+
- 物联网设备监控组件拆分到IotDeviceView项目
|
|
12
|
+
|
|
4
13
|
**1.2.111 -2022-09-01 @江超**
|
|
5
14
|
- 修复获取字典数据时错误的v4版本判断
|
|
6
15
|
|
package/package.json
CHANGED
|
@@ -1,274 +1,273 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<common-layout>
|
|
3
|
-
<div class="top">
|
|
4
|
-
<div class="header">
|
|
5
|
-
<img alt="logo" class="logo" src="@vue2-client/assets/img/logo.png" />
|
|
6
|
-
<span class="title">{{ systemName }}</span>
|
|
7
|
-
</div>
|
|
8
|
-
<div class="desc">{{ systemDesc }}</div>
|
|
9
|
-
</div>
|
|
10
|
-
<div class="login">
|
|
11
|
-
<a-form
|
|
12
|
-
<a-tabs
|
|
13
|
-
<a-tab-pane
|
|
14
|
-
<a-alert
|
|
15
|
-
|
|
16
|
-
:closable="true"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
<a-form-item>
|
|
22
|
-
<a-input
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
placeholder="admin"
|
|
26
|
-
|
|
27
|
-
>
|
|
28
|
-
<a-icon slot="prefix" type="user" />
|
|
29
|
-
</a-input>
|
|
30
|
-
</a-form-item>
|
|
31
|
-
<a-form-item>
|
|
32
|
-
<a-input
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
>
|
|
39
|
-
<a-icon slot="prefix" type="lock" />
|
|
40
|
-
</a-input>
|
|
41
|
-
</a-form-item>
|
|
42
|
-
</a-tab-pane>
|
|
43
|
-
</a-tabs>
|
|
44
|
-
<div>
|
|
45
|
-
<a-checkbox :checked="true" >自动登录</a-checkbox>
|
|
46
|
-
</div>
|
|
47
|
-
<a-form-item>
|
|
48
|
-
<a-button :loading="logging" style="width: 100%;margin-top: 24px"
|
|
49
|
-
</a-form-item>
|
|
50
|
-
</a-form>
|
|
51
|
-
</div>
|
|
52
|
-
</common-layout>
|
|
53
|
-
</template>
|
|
54
|
-
|
|
55
|
-
<script>
|
|
56
|
-
import CommonLayout from '@vue2-client/layouts/CommonLayout'
|
|
57
|
-
import { getRoutesConfig, login, V4Login } from '@vue2-client/services/user'
|
|
58
|
-
import { setAuthorization } from '@vue2-client/utils/request'
|
|
59
|
-
import { loadRoutes, funcToRouter } from '@vue2-client/utils/routerUtil'
|
|
60
|
-
import { mapMutations, mapState } from 'vuex'
|
|
61
|
-
import JSEncrypt from 'jsencrypt'
|
|
62
|
-
import { ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
63
|
-
import { positions } from '@vue2-client/mock/common'
|
|
64
|
-
import { timeFix } from '@vue2-client/utils/util'
|
|
65
|
-
import { loginStart } from '@vue2-client/base-client/plugins/compatible/LoginServiceOA'
|
|
66
|
-
|
|
67
|
-
export default {
|
|
68
|
-
name: 'Login',
|
|
69
|
-
components: { CommonLayout },
|
|
70
|
-
data () {
|
|
71
|
-
return {
|
|
72
|
-
logging: false,
|
|
73
|
-
error: '',
|
|
74
|
-
form: this.$form.createForm(this)
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
computed: {
|
|
78
|
-
...mapState('setting', ['systemName', 'systemDesc', 'homePage', 'ticketPage', 'compatible'])
|
|
79
|
-
},
|
|
80
|
-
methods: {
|
|
81
|
-
...mapMutations('account', ['setUser', 'setPermissions', 'setRoles']),
|
|
82
|
-
onSubmit (e) {
|
|
83
|
-
e.preventDefault()
|
|
84
|
-
this.form.validateFields((err) => {
|
|
85
|
-
if (!err) {
|
|
86
|
-
this.logging = true
|
|
87
|
-
const name = this.form.getFieldValue('name')
|
|
88
|
-
const password = this.form.getFieldValue('password')
|
|
89
|
-
switch (this.compatible) {
|
|
90
|
-
case 'V3': {
|
|
91
|
-
login(name, password).then(this.afterLogin)
|
|
92
|
-
break
|
|
93
|
-
}
|
|
94
|
-
case 'OA' : {
|
|
95
|
-
loginStart(name, password).then(this.afterLoginOA).finally(() => { this.logging = false })
|
|
96
|
-
break
|
|
97
|
-
}
|
|
98
|
-
case 'V4' : {
|
|
99
|
-
V4Login(name, password).then(this.afterLoginV4)
|
|
100
|
-
break
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
},
|
|
106
|
-
afterLoginOA (result) {
|
|
107
|
-
// 默认第一个是旧OA地址
|
|
108
|
-
result.functions[0].navigate = result.functions[0].link
|
|
109
|
-
result.functions[0].link = null
|
|
110
|
-
this.afterGeneral(result)
|
|
111
|
-
this.
|
|
112
|
-
this.$router.push(this.homePage).catch(() => {})
|
|
113
|
-
},
|
|
114
|
-
afterLoginV4 (res) {
|
|
115
|
-
const name = this.form.getFieldValue('name')
|
|
116
|
-
const password = this.form.getFieldValue('password')
|
|
117
|
-
this.logging = false
|
|
118
|
-
const loginRes = res
|
|
119
|
-
// 如果这是用户首次打开本系统,localStorage无法初始化,改用code判断
|
|
120
|
-
let pass = false
|
|
121
|
-
let V4Token = {}
|
|
122
|
-
// 判断是否是第一次使用本系统
|
|
123
|
-
if (res.code) {
|
|
124
|
-
if (res.code === 200) {
|
|
125
|
-
pass = true
|
|
126
|
-
// 如果返回值有code,证明是第一次使用系统,localStorage判断compatible失效
|
|
127
|
-
// token需要从.data中获取
|
|
128
|
-
V4Token = { token: res.data.access_token, expire: res.data.expires_in }
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
V4Token = { token: res.access_token, expire: res.expires_in }
|
|
132
|
-
}
|
|
133
|
-
this.setV4AccessToken(V4Token)
|
|
134
|
-
// 向本地缓存中临时存储compatible
|
|
135
|
-
if (loginRes.access_token || pass) {
|
|
136
|
-
const encrypt = new JSEncrypt()
|
|
137
|
-
encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqPvovSfXcwBbW8cKMCgwqNpsYuzF8RPAPFb7LGsnVo44JhM/xxzDyzoYtdfNmtbIuKVi9PzIsyp6rg+09gbuI6UGwBZ5DWBDBMqv5MPdOF5dCQkB2Bbr5yPfURPENypUz+pBFBg41d+BC+rwRiXELwKy7Y9caD/MtJyHydj8OUwIDAQAB')
|
|
138
|
-
const data = encrypt.encrypt(JSON.stringify({ username: name, password: password }))
|
|
139
|
-
// 获取路由配置
|
|
140
|
-
getRoutesConfig(data).then(result => {
|
|
141
|
-
this.$login.login(result).then(() => {
|
|
142
|
-
this.afterGeneral(result)
|
|
143
|
-
if (result.deps === '用户工单登记') {
|
|
144
|
-
this.$router.push(this.ticketPage).catch(() => {})
|
|
145
|
-
} else {
|
|
146
|
-
this.$router.push(this.homePage).catch(() => {})
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
} else {
|
|
151
|
-
this.error = loginRes.msg
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
afterLogin (res) {
|
|
155
|
-
const name = this.form.getFieldValue('name')
|
|
156
|
-
const password = this.form.getFieldValue('password')
|
|
157
|
-
this.logging = false
|
|
158
|
-
const loginRes = res.states
|
|
159
|
-
if (loginRes === '登录成功') {
|
|
160
|
-
const encrypt = new JSEncrypt()
|
|
161
|
-
encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqPvovSfXcwBbW8cKMCgwqNpsYuzF8RPAPFb7LGsnVo44JhM/xxzDyzoYtdfNmtbIuKVi9PzIsyp6rg+09gbuI6UGwBZ5DWBDBMqv5MPdOF5dCQkB2Bbr5yPfURPENypUz+pBFBg41d+BC+rwRiXELwKy7Y9caD/MtJyHydj8OUwIDAQAB')
|
|
162
|
-
const data = encrypt.encrypt(JSON.stringify({ username: name, password: password }))
|
|
163
|
-
// 获取路由配置
|
|
164
|
-
getRoutesConfig(data).then(result => {
|
|
165
|
-
this.$login.login(result).then(() => {
|
|
166
|
-
// V3任何情况首位加入资源管理
|
|
167
|
-
const resourceManageMain = {
|
|
168
|
-
name: '资源管理',
|
|
169
|
-
icon: 'api',
|
|
170
|
-
position: 1,
|
|
171
|
-
link: 'resourceManageMain'
|
|
172
|
-
}
|
|
173
|
-
result.functions.unshift(resourceManageMain)
|
|
174
|
-
this.afterGeneral(result)
|
|
175
|
-
this.
|
|
176
|
-
if (result.deps === '用户工单登记') {
|
|
177
|
-
this.$router.push(this.ticketPage).catch(() => {})
|
|
178
|
-
} else {
|
|
179
|
-
this.$router.push(this.homePage).catch(() => {})
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
} else {
|
|
184
|
-
this.error = loginRes
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
afterGeneral (result) {
|
|
188
|
-
const user = Object.assign({
|
|
189
|
-
username: result.ename,
|
|
190
|
-
name: result.name,
|
|
191
|
-
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
|
|
192
|
-
address: '西安市',
|
|
193
|
-
position: positions[0]
|
|
194
|
-
}, result)
|
|
195
|
-
this.setUser(user)
|
|
196
|
-
this.setPermissions([{ id: 'queryForm', operation: ['add', 'edit'] }])
|
|
197
|
-
this.setRoles([{ id: 'admin', operation: ['add', 'edit', 'delete'] }])
|
|
198
|
-
loadRoutes(funcToRouter(user.functions))
|
|
199
|
-
this.$message.success(timeFix().CN + `,${result.name} 欢迎回来`, 3)
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
localStorage.setItem(ACCESS_TOKEN, data)
|
|
203
|
-
let timestamp = new Date().getTime()// 当前的时间戳
|
|
204
|
-
timestamp = timestamp + 12 * 60 * 60 * 1000
|
|
205
|
-
// 格式化时间获取年月日, 登陆过期时间
|
|
206
|
-
const dateAfter = new Date(timestamp)
|
|
207
|
-
setAuthorization({ token: data, expireAt: dateAfter })
|
|
208
|
-
},
|
|
209
|
-
setV4AccessToken (data) {
|
|
210
|
-
localStorage.setItem(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
height: 44px;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
font-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
margin-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<common-layout>
|
|
3
|
+
<div class="top">
|
|
4
|
+
<div class="header">
|
|
5
|
+
<img alt="logo" class="logo" src="@vue2-client/assets/img/logo.png" />
|
|
6
|
+
<span class="title">{{ systemName }}</span>
|
|
7
|
+
</div>
|
|
8
|
+
<div class="desc">{{ systemDesc }}</div>
|
|
9
|
+
</div>
|
|
10
|
+
<div class="login">
|
|
11
|
+
<a-form :form="form" @submit="onSubmit">
|
|
12
|
+
<a-tabs :tabBarStyle="{textAlign: 'center'}" size="large" style="padding: 0 2px;">
|
|
13
|
+
<a-tab-pane key="1" tab="账户密码登录">
|
|
14
|
+
<a-alert
|
|
15
|
+
v-show="error"
|
|
16
|
+
:closable="true"
|
|
17
|
+
:message="error"
|
|
18
|
+
showIcon
|
|
19
|
+
style="margin-bottom: 24px;"
|
|
20
|
+
type="error" />
|
|
21
|
+
<a-form-item>
|
|
22
|
+
<a-input
|
|
23
|
+
v-decorator="['name', {rules: [{ required: true, message: '请输入账户名', whitespace: true}]}]"
|
|
24
|
+
autocomplete="autocomplete"
|
|
25
|
+
placeholder="admin"
|
|
26
|
+
size="large"
|
|
27
|
+
>
|
|
28
|
+
<a-icon slot="prefix" type="user" />
|
|
29
|
+
</a-input>
|
|
30
|
+
</a-form-item>
|
|
31
|
+
<a-form-item>
|
|
32
|
+
<a-input
|
|
33
|
+
v-decorator="['password', {rules: [{ required: true, message: '请输入密码', whitespace: true}]}]"
|
|
34
|
+
autocomplete="autocomplete"
|
|
35
|
+
placeholder="888888"
|
|
36
|
+
size="large"
|
|
37
|
+
type="password"
|
|
38
|
+
>
|
|
39
|
+
<a-icon slot="prefix" type="lock" />
|
|
40
|
+
</a-input>
|
|
41
|
+
</a-form-item>
|
|
42
|
+
</a-tab-pane>
|
|
43
|
+
</a-tabs>
|
|
44
|
+
<div>
|
|
45
|
+
<a-checkbox :checked="true" >自动登录</a-checkbox>
|
|
46
|
+
</div>
|
|
47
|
+
<a-form-item>
|
|
48
|
+
<a-button :loading="logging" htmlType="submit" size="large" style="width: 100%;margin-top: 24px" type="primary">登录</a-button>
|
|
49
|
+
</a-form-item>
|
|
50
|
+
</a-form>
|
|
51
|
+
</div>
|
|
52
|
+
</common-layout>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
import CommonLayout from '@vue2-client/layouts/CommonLayout'
|
|
57
|
+
import { getRoutesConfig, login, V4Login } from '@vue2-client/services/user'
|
|
58
|
+
import { setAuthorization } from '@vue2-client/utils/request'
|
|
59
|
+
import { loadRoutes, funcToRouter } from '@vue2-client/utils/routerUtil'
|
|
60
|
+
import { mapMutations, mapState } from 'vuex'
|
|
61
|
+
import JSEncrypt from 'jsencrypt'
|
|
62
|
+
import { ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
63
|
+
import { positions } from '@vue2-client/mock/common'
|
|
64
|
+
import { timeFix } from '@vue2-client/utils/util'
|
|
65
|
+
import { loginStart } from '@vue2-client/base-client/plugins/compatible/LoginServiceOA'
|
|
66
|
+
|
|
67
|
+
export default {
|
|
68
|
+
name: 'Login',
|
|
69
|
+
components: { CommonLayout },
|
|
70
|
+
data () {
|
|
71
|
+
return {
|
|
72
|
+
logging: false,
|
|
73
|
+
error: '',
|
|
74
|
+
form: this.$form.createForm(this)
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
computed: {
|
|
78
|
+
...mapState('setting', ['systemName', 'systemDesc', 'homePage', 'ticketPage', 'compatible'])
|
|
79
|
+
},
|
|
80
|
+
methods: {
|
|
81
|
+
...mapMutations('account', ['setUser', 'setPermissions', 'setRoles']),
|
|
82
|
+
onSubmit (e) {
|
|
83
|
+
e.preventDefault()
|
|
84
|
+
this.form.validateFields((err) => {
|
|
85
|
+
if (!err) {
|
|
86
|
+
this.logging = true
|
|
87
|
+
const name = this.form.getFieldValue('name')
|
|
88
|
+
const password = this.form.getFieldValue('password')
|
|
89
|
+
switch (this.compatible) {
|
|
90
|
+
case 'V3': {
|
|
91
|
+
login(name, password).then(this.afterLogin)
|
|
92
|
+
break
|
|
93
|
+
}
|
|
94
|
+
case 'OA' : {
|
|
95
|
+
loginStart(name, password).then(this.afterLoginOA).finally(() => { this.logging = false })
|
|
96
|
+
break
|
|
97
|
+
}
|
|
98
|
+
case 'V4' : {
|
|
99
|
+
V4Login(name, password).then(this.afterLoginV4)
|
|
100
|
+
break
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
afterLoginOA (result) {
|
|
107
|
+
// 默认第一个是旧OA地址
|
|
108
|
+
result.functions[0].navigate = result.functions[0].link
|
|
109
|
+
result.functions[0].link = null
|
|
110
|
+
this.afterGeneral(result)
|
|
111
|
+
this.setAccessToken(result.password)
|
|
112
|
+
this.$router.push(this.homePage).catch(() => {})
|
|
113
|
+
},
|
|
114
|
+
afterLoginV4 (res) {
|
|
115
|
+
const name = this.form.getFieldValue('name')
|
|
116
|
+
const password = this.form.getFieldValue('password')
|
|
117
|
+
this.logging = false
|
|
118
|
+
const loginRes = res
|
|
119
|
+
// 如果这是用户首次打开本系统,localStorage无法初始化,改用code判断
|
|
120
|
+
let pass = false
|
|
121
|
+
let V4Token = {}
|
|
122
|
+
// 判断是否是第一次使用本系统
|
|
123
|
+
if (res.code) {
|
|
124
|
+
if (res.code === 200) {
|
|
125
|
+
pass = true
|
|
126
|
+
// 如果返回值有code,证明是第一次使用系统,localStorage判断compatible失效
|
|
127
|
+
// token需要从.data中获取
|
|
128
|
+
V4Token = { token: res.data.access_token, expire: res.data.expires_in }
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
V4Token = { token: res.access_token, expire: res.expires_in }
|
|
132
|
+
}
|
|
133
|
+
this.setV4AccessToken(V4Token)
|
|
134
|
+
// 向本地缓存中临时存储compatible
|
|
135
|
+
if (loginRes.access_token || pass) {
|
|
136
|
+
const encrypt = new JSEncrypt()
|
|
137
|
+
encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqPvovSfXcwBbW8cKMCgwqNpsYuzF8RPAPFb7LGsnVo44JhM/xxzDyzoYtdfNmtbIuKVi9PzIsyp6rg+09gbuI6UGwBZ5DWBDBMqv5MPdOF5dCQkB2Bbr5yPfURPENypUz+pBFBg41d+BC+rwRiXELwKy7Y9caD/MtJyHydj8OUwIDAQAB')
|
|
138
|
+
const data = encrypt.encrypt(JSON.stringify({ username: name, password: password }))
|
|
139
|
+
// 获取路由配置
|
|
140
|
+
getRoutesConfig(data).then(result => {
|
|
141
|
+
this.$login.login(result).then(() => {
|
|
142
|
+
this.afterGeneral(result)
|
|
143
|
+
if (result.deps === '用户工单登记') {
|
|
144
|
+
this.$router.push(this.ticketPage).catch(() => {})
|
|
145
|
+
} else {
|
|
146
|
+
this.$router.push(this.homePage).catch(() => {})
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
} else {
|
|
151
|
+
this.error = loginRes.msg
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
afterLogin (res) {
|
|
155
|
+
const name = this.form.getFieldValue('name')
|
|
156
|
+
const password = this.form.getFieldValue('password')
|
|
157
|
+
this.logging = false
|
|
158
|
+
const loginRes = res.states
|
|
159
|
+
if (loginRes === '登录成功') {
|
|
160
|
+
const encrypt = new JSEncrypt()
|
|
161
|
+
encrypt.setPublicKey('MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqPvovSfXcwBbW8cKMCgwqNpsYuzF8RPAPFb7LGsnVo44JhM/xxzDyzoYtdfNmtbIuKVi9PzIsyp6rg+09gbuI6UGwBZ5DWBDBMqv5MPdOF5dCQkB2Bbr5yPfURPENypUz+pBFBg41d+BC+rwRiXELwKy7Y9caD/MtJyHydj8OUwIDAQAB')
|
|
162
|
+
const data = encrypt.encrypt(JSON.stringify({ username: name, password: password }))
|
|
163
|
+
// 获取路由配置
|
|
164
|
+
getRoutesConfig(data).then(result => {
|
|
165
|
+
this.$login.login(result).then(() => {
|
|
166
|
+
// V3任何情况首位加入资源管理
|
|
167
|
+
const resourceManageMain = {
|
|
168
|
+
name: '资源管理',
|
|
169
|
+
icon: 'api',
|
|
170
|
+
position: 1,
|
|
171
|
+
link: 'resourceManageMain'
|
|
172
|
+
}
|
|
173
|
+
result.functions.unshift(resourceManageMain)
|
|
174
|
+
this.afterGeneral(result)
|
|
175
|
+
this.setAccessToken(data)
|
|
176
|
+
if (result.deps === '用户工单登记') {
|
|
177
|
+
this.$router.push(this.ticketPage).catch(() => {})
|
|
178
|
+
} else {
|
|
179
|
+
this.$router.push(this.homePage).catch(() => {})
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
} else {
|
|
184
|
+
this.error = loginRes
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
afterGeneral (result) {
|
|
188
|
+
const user = Object.assign({
|
|
189
|
+
username: result.ename,
|
|
190
|
+
name: result.name,
|
|
191
|
+
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
|
|
192
|
+
address: '西安市',
|
|
193
|
+
position: positions[0]
|
|
194
|
+
}, result)
|
|
195
|
+
this.setUser(user)
|
|
196
|
+
this.setPermissions([{ id: 'queryForm', operation: ['add', 'edit'] }])
|
|
197
|
+
this.setRoles([{ id: 'admin', operation: ['add', 'edit', 'delete'] }])
|
|
198
|
+
loadRoutes(funcToRouter(user.functions))
|
|
199
|
+
this.$message.success(timeFix().CN + `,${result.name} 欢迎回来`, 3)
|
|
200
|
+
},
|
|
201
|
+
setAccessToken (data) {
|
|
202
|
+
localStorage.setItem(ACCESS_TOKEN, data)
|
|
203
|
+
let timestamp = new Date().getTime()// 当前的时间戳
|
|
204
|
+
timestamp = timestamp + 12 * 60 * 60 * 1000
|
|
205
|
+
// 格式化时间获取年月日, 登陆过期时间
|
|
206
|
+
const dateAfter = new Date(timestamp)
|
|
207
|
+
setAuthorization({ token: data, expireAt: dateAfter })
|
|
208
|
+
},
|
|
209
|
+
setV4AccessToken (data) {
|
|
210
|
+
localStorage.setItem(ACCESS_TOKEN, data.token)
|
|
211
|
+
setAuthorization({ token: data.token, expire: data.expire })
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
</script>
|
|
216
|
+
|
|
217
|
+
<style lang="less" scoped>
|
|
218
|
+
.common-layout{
|
|
219
|
+
.top {
|
|
220
|
+
text-align: center;
|
|
221
|
+
.header {
|
|
222
|
+
height: 44px;
|
|
223
|
+
line-height: 44px;
|
|
224
|
+
a {
|
|
225
|
+
text-decoration: none;
|
|
226
|
+
}
|
|
227
|
+
.logo {
|
|
228
|
+
height: 44px;
|
|
229
|
+
vertical-align: top;
|
|
230
|
+
margin-right: 16px;
|
|
231
|
+
}
|
|
232
|
+
.title {
|
|
233
|
+
font-size: 33px;
|
|
234
|
+
color: @title-color;
|
|
235
|
+
font-family: 'Myriad Pro', 'Helvetica Neue', Arial, Helvetica, sans-serif;
|
|
236
|
+
font-weight: 600;
|
|
237
|
+
position: relative;
|
|
238
|
+
top: 2px;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
.desc {
|
|
242
|
+
font-size: 14px;
|
|
243
|
+
color: @text-color-second;
|
|
244
|
+
margin-top: 12px;
|
|
245
|
+
margin-bottom: 40px;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
.login{
|
|
249
|
+
width: 368px;
|
|
250
|
+
margin: 0 auto;
|
|
251
|
+
@media screen and (max-width: 576px) {
|
|
252
|
+
width: 95%;
|
|
253
|
+
}
|
|
254
|
+
@media screen and (max-width: 320px) {
|
|
255
|
+
.captcha-button{
|
|
256
|
+
font-size: 14px;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
.icon {
|
|
260
|
+
font-size: 24px;
|
|
261
|
+
color: @text-color-second;
|
|
262
|
+
margin-left: 16px;
|
|
263
|
+
vertical-align: middle;
|
|
264
|
+
cursor: pointer;
|
|
265
|
+
transition: color 0.3s;
|
|
266
|
+
|
|
267
|
+
&:hover {
|
|
268
|
+
color: @primary-color;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
</style>
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const ACCESS_TOKEN = 'Access-Token'
|
|
1
|
+
export const ACCESS_TOKEN = 'Access-Token'
|
|
2
|
+
export const V4_ACCESS_TOKEN = 'Authorization'
|
package/src/utils/request.js
CHANGED
|
@@ -1,270 +1,225 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import Cookie from 'js-cookie'
|
|
3
|
-
import Vue from 'vue'
|
|
4
|
-
import { ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
5
|
-
import notification from 'ant-design-vue/es/notification'
|
|
6
|
-
|
|
7
|
-
let compatible
|
|
8
|
-
|
|
9
|
-
// 跨域认证信息 header 名
|
|
10
|
-
const xsrfHeaderName = 'Authorization'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
axios.defaults.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
case AUTH_TYPE.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
break
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
case AUTH_TYPE.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
break
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
})
|
|
227
|
-
} else {
|
|
228
|
-
notification.error({
|
|
229
|
-
message: '数据异常',
|
|
230
|
-
description: data
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return Promise.reject(error)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* 解析 url 中的参数
|
|
239
|
-
* @param url
|
|
240
|
-
* @returns {Object}
|
|
241
|
-
*/
|
|
242
|
-
function parseUrlParams (url) {
|
|
243
|
-
const params = {}
|
|
244
|
-
if (!url || url === '' || typeof url !== 'string') {
|
|
245
|
-
return params
|
|
246
|
-
}
|
|
247
|
-
const paramsStr = url.split('?')[1]
|
|
248
|
-
if (!paramsStr) {
|
|
249
|
-
return params
|
|
250
|
-
}
|
|
251
|
-
const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
|
|
252
|
-
for (let i = 0; i < paramsArr.length / 2; i++) {
|
|
253
|
-
const value = paramsArr[i * 2 + 1]
|
|
254
|
-
params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
|
|
255
|
-
}
|
|
256
|
-
return params
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export {
|
|
260
|
-
METHOD,
|
|
261
|
-
AUTH_TYPE,
|
|
262
|
-
request,
|
|
263
|
-
setAuthorization,
|
|
264
|
-
removeAuthorization,
|
|
265
|
-
checkAuthorization,
|
|
266
|
-
loadInterceptors,
|
|
267
|
-
parseUrlParams,
|
|
268
|
-
setAuthorizationV4,
|
|
269
|
-
removeAuthorizationV4
|
|
270
|
-
}
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import Cookie from 'js-cookie'
|
|
3
|
+
import Vue from 'vue'
|
|
4
|
+
import { ACCESS_TOKEN, V4_ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
5
|
+
import notification from 'ant-design-vue/es/notification'
|
|
6
|
+
|
|
7
|
+
let compatible
|
|
8
|
+
|
|
9
|
+
// 跨域认证信息 header 名
|
|
10
|
+
const xsrfHeaderName = 'Authorization'
|
|
11
|
+
|
|
12
|
+
axios.defaults.timeout = 5000
|
|
13
|
+
axios.defaults.withCredentials = true
|
|
14
|
+
axios.defaults.xsrfHeaderName = xsrfHeaderName
|
|
15
|
+
axios.defaults.xsrfCookieName = xsrfHeaderName
|
|
16
|
+
|
|
17
|
+
// 认证类型
|
|
18
|
+
const AUTH_TYPE = {
|
|
19
|
+
BEARER: 'Bearer',
|
|
20
|
+
BASIC: 'basic',
|
|
21
|
+
AUTH1: 'auth1',
|
|
22
|
+
AUTH2: 'auth2'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// http method
|
|
26
|
+
const METHOD = {
|
|
27
|
+
GET: 'get',
|
|
28
|
+
POST: 'post'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* axios请求
|
|
33
|
+
* @param url 请求地址
|
|
34
|
+
* @param method {METHOD} http method
|
|
35
|
+
* @param params 请求参数
|
|
36
|
+
* @param config
|
|
37
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
38
|
+
*/
|
|
39
|
+
async function request (url, method, params, config) {
|
|
40
|
+
switch (method) {
|
|
41
|
+
case METHOD.GET:
|
|
42
|
+
return axios.get(url, { params, ...config })
|
|
43
|
+
case METHOD.POST:
|
|
44
|
+
return axios.post(url, params, config)
|
|
45
|
+
default:
|
|
46
|
+
return axios.get(url, { params, ...config })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 设置认证信息
|
|
52
|
+
* @param auth {Object}
|
|
53
|
+
* @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
|
|
54
|
+
*/
|
|
55
|
+
function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
|
|
56
|
+
switch (authType) {
|
|
57
|
+
case AUTH_TYPE.BEARER:
|
|
58
|
+
if (auth.token) {
|
|
59
|
+
Cookie.set(xsrfHeaderName, 'Bearer ' + auth.token, { expires: auth.expireAt })
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
case AUTH_TYPE.BASIC:
|
|
63
|
+
case AUTH_TYPE.AUTH1:
|
|
64
|
+
case AUTH_TYPE.AUTH2:
|
|
65
|
+
default:
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 移出认证信息
|
|
72
|
+
* @param authType {AUTH_TYPE} 认证类型
|
|
73
|
+
*/
|
|
74
|
+
function removeAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
75
|
+
switch (authType) {
|
|
76
|
+
case AUTH_TYPE.BEARER:
|
|
77
|
+
Cookie.remove(xsrfHeaderName)
|
|
78
|
+
break
|
|
79
|
+
case AUTH_TYPE.BASIC:
|
|
80
|
+
case AUTH_TYPE.AUTH1:
|
|
81
|
+
case AUTH_TYPE.AUTH2:
|
|
82
|
+
default:
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 检查认证信息
|
|
89
|
+
* @param authType
|
|
90
|
+
* @returns {boolean}
|
|
91
|
+
*/
|
|
92
|
+
function checkAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
93
|
+
switch (authType) {
|
|
94
|
+
case AUTH_TYPE.BEARER:
|
|
95
|
+
if (Cookie.get(xsrfHeaderName)) {
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
break
|
|
99
|
+
case AUTH_TYPE.BASIC:
|
|
100
|
+
case AUTH_TYPE.AUTH1:
|
|
101
|
+
case AUTH_TYPE.AUTH2:
|
|
102
|
+
default:
|
|
103
|
+
break
|
|
104
|
+
}
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 加载 axios 拦截器
|
|
110
|
+
* @param interceptors
|
|
111
|
+
* @param options
|
|
112
|
+
*/
|
|
113
|
+
function loadInterceptors () {
|
|
114
|
+
// 加载请求拦截器
|
|
115
|
+
axios.interceptors.request.use(config => {
|
|
116
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
117
|
+
// 如果 token 存在
|
|
118
|
+
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
119
|
+
if (token) {
|
|
120
|
+
// 如果是首次使用系统LocalStorage需要初始化,在登陆之后重新获取一次compatible
|
|
121
|
+
if (compatible === null) {
|
|
122
|
+
compatible = localStorage.getItem('compatible')
|
|
123
|
+
}
|
|
124
|
+
// 判断是否为V4环境
|
|
125
|
+
if (compatible === 'V4') {
|
|
126
|
+
// V4 环境则添加 V4请求头
|
|
127
|
+
config.headers[V4_ACCESS_TOKEN] = token
|
|
128
|
+
} else {
|
|
129
|
+
config.headers[ACCESS_TOKEN] = token
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!config.headers['Content-Type']) {
|
|
133
|
+
config.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
|
134
|
+
}
|
|
135
|
+
return config
|
|
136
|
+
}, errorHandler)
|
|
137
|
+
// 加载响应拦截器
|
|
138
|
+
axios.interceptors.response.use((response) => {
|
|
139
|
+
// 判断是否为V4环境,不为compatible赋初始值
|
|
140
|
+
// 其有可能是undefined未定义,或第一次使用本系统LocalStorage在初始化,获得的值为null
|
|
141
|
+
if (compatible === null || compatible === undefined) {
|
|
142
|
+
compatible = localStorage.getItem('compatible')
|
|
143
|
+
}
|
|
144
|
+
if (compatible === 'V4') {
|
|
145
|
+
if (response.data.data) {
|
|
146
|
+
return response.data.data
|
|
147
|
+
} else {
|
|
148
|
+
return response.data
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
return response.data
|
|
152
|
+
}
|
|
153
|
+
}, errorHandler)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 异常拦截处理器
|
|
157
|
+
const errorHandler = (error) => {
|
|
158
|
+
if (error.response) {
|
|
159
|
+
const data = error.response.data
|
|
160
|
+
// 从 localstorage 获取 token
|
|
161
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
162
|
+
if (error.response.status === 403 || data.code === 403) {
|
|
163
|
+
notification.error({
|
|
164
|
+
message: '禁止访问',
|
|
165
|
+
description: data
|
|
166
|
+
})
|
|
167
|
+
} else if ((error.response.status === 401 || data.code === 401) && !(data.result && data.result.isLogin)) {
|
|
168
|
+
notification.error({
|
|
169
|
+
message: '鉴权失败',
|
|
170
|
+
description: data
|
|
171
|
+
})
|
|
172
|
+
if (token) {
|
|
173
|
+
Vue.$store.dispatch('Logout').then(() => {
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
window.location.reload()
|
|
176
|
+
}, 1500)
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
} else if (error.response.status === 500 || data.code === 500) {
|
|
180
|
+
notification.error({
|
|
181
|
+
message: '系统异常',
|
|
182
|
+
description: data
|
|
183
|
+
})
|
|
184
|
+
} else {
|
|
185
|
+
notification.error({
|
|
186
|
+
message: '数据异常',
|
|
187
|
+
description: data
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return Promise.reject(error)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 解析 url 中的参数
|
|
196
|
+
* @param url
|
|
197
|
+
* @returns {Object}
|
|
198
|
+
*/
|
|
199
|
+
function parseUrlParams (url) {
|
|
200
|
+
const params = {}
|
|
201
|
+
if (!url || url === '' || typeof url !== 'string') {
|
|
202
|
+
return params
|
|
203
|
+
}
|
|
204
|
+
const paramsStr = url.split('?')[1]
|
|
205
|
+
if (!paramsStr) {
|
|
206
|
+
return params
|
|
207
|
+
}
|
|
208
|
+
const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
|
|
209
|
+
for (let i = 0; i < paramsArr.length / 2; i++) {
|
|
210
|
+
const value = paramsArr[i * 2 + 1]
|
|
211
|
+
params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
|
|
212
|
+
}
|
|
213
|
+
return params
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export {
|
|
217
|
+
METHOD,
|
|
218
|
+
AUTH_TYPE,
|
|
219
|
+
request,
|
|
220
|
+
setAuthorization,
|
|
221
|
+
removeAuthorization,
|
|
222
|
+
checkAuthorization,
|
|
223
|
+
loadInterceptors,
|
|
224
|
+
parseUrlParams
|
|
225
|
+
}
|