Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
confucius
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
罗超
confucius
Commits
8f091636
Commit
8f091636
authored
Sep 22, 2020
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理数据访问问题
parent
f99b2f0b
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
214 additions
and
103 deletions
+214
-103
package.json
package.json
+48
-47
quasar.conf.js
quasar.conf.js
+1
-2
login.js
src/api/login.js
+8
-7
permission.js
src/boot/permission.js
+6
-6
login.vue
src/pages/user/login.vue
+2
-2
getters.js
src/store/getters.js
+18
-0
index.js
src/store/index.js
+24
-23
permission.js
src/store/modules/permission.js
+81
-0
user.js
src/store/modules/user.js
+14
-10
cache.js
src/utils/cache.js
+2
-1
request.js
src/utils/request.js
+10
-5
No files found.
package.json
View file @
8f091636
...
...
@@ -13,6 +13,7 @@
"
@quasar/extras
"
:
"^1.0.0"
,
"
axios
"
:
"^0.18.1"
,
"
core-js
"
:
"^3.6.5"
,
"
lockr
"
:
"^0.8.5"
,
"
quasar
"
:
"^1.0.0"
,
"
vue-i18n
"
:
"^8.0.0"
},
...
...
quasar.conf.js
View file @
8f091636
...
...
@@ -19,7 +19,6 @@ module.exports = function(ctx) {
// --> boot files are part of "main.js"
// https://quasar.dev/quasar-cli/boot-files
boot
:
[
'i18n'
,
'axios'
,
'permission'
...
...
@@ -48,7 +47,7 @@ module.exports = function(ctx) {
build
:
{
vueRouterMode
:
'hash'
,
// available values: 'hash', 'history'
env
:
ctx
.
dev
?
{
API
:
'http
s://dev.api.com
'
API
:
'http
://192.168.1.214:8300/api
'
}
:
{
API
:
'https://prod.api.com'
},
...
...
src/api/login.js
View file @
8f091636
...
...
@@ -3,16 +3,17 @@
*/
import
request
from
'../utils/request'
export
function
login
({
account
,
pwd
})
{
return
request
({
url
:
'/login'
,
method
:
"post"
,
export
function
login
({
Account
,
Password
})
{
// headers: {
// 'Content-Type': 'application/json;charset=UTF-8'
// }, 申明Headers信息,不包含token ,token通过注入添加
return
request
({
url
:
'/login/login'
,
method
:
"post"
,
data
:
{
account
,
pwd
Account
,
Password
,
AccountType
:
1
}
});
}
...
...
src/boot/permission.js
View file @
8f091636
import
router
from
"../router/index"
;
import
store
from
"../store"
;
import
store
from
"../store
/index
"
;
import
{
LoadingBar
,
Notify
}
from
"quasar"
;
import
{
getAuth
}
from
"../utils/auth"
;
// 验权
LoadingBar
.
setDefaults
({
color
:
"primary"
,
size
:
"
10
px"
,
size
:
"
5
px"
,
position
:
"bottom"
});
let
loadAsyncRouter
=
false
;
const
whiteList
=
[
"/login"
,
"/"
];
// 不重定向白名单
console
.
log
(
router
)
...
...
@@ -16,9 +15,10 @@ router.beforeEach((to, from, next) => {
LoadingBar
.
start
();
/** 请求头包含授权信息 并且 页面必须授权 直接进入 */
if
(
getAuth
())
{
if
(
to
.
path
===
"/login"
)
{
//debugger;
if
(
to
.
path
===
"/login"
||
to
.
path
===
"/"
)
{
next
({
path
:
"/"
path
:
"/
home
"
});
LoadingBar
.
stop
();
}
else
{
...
...
@@ -28,7 +28,7 @@ router.beforeEach((to, from, next) => {
if
(
store
.
getters
.
allAuth
)
{
store
.
dispatch
(
"GenerateRoutes"
,
store
.
getters
.
allAuth
).
then
(()
=>
{
// 根据auths权限生成可访问的路由表
router
.
addRoutes
(
store
.
getters
.
addRouters
);
// 动态添加可访问路由表
//
router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表
if
(
to
.
path
===
"/404"
)
{
next
({
path
:
to
.
redirectedFrom
||
"/"
,
...
...
src/pages/user/login.vue
View file @
8f091636
...
...
@@ -127,8 +127,8 @@ export default {
// })
this
.
$store
.
dispatch
(
'Login'
,
{
a
ccount
:
this
.
account
,
pwd
:
this
.
pwd
A
ccount
:
this
.
account
,
Password
:
this
.
pwd
,
})
.
then
(
res
=>
{
this
.
$router
.
push
({
...
...
src/store/getters.js
0 → 100644
View file @
8f091636
const
getters
=
{
userInfo
:
state
=>
state
.
user
.
userInfo
,
logo
:
state
=>
{
//TODO 根据登录信息返回
return
''
//require('@/assets/img/logo.png')
},
name
:
state
=>
{
// if (state.app.name) {
// return state.app.name
// }
//TODO 根据登录信息返回
return
'悟空CRM系统'
},
// 权限
allAuth
:
state
=>
state
.
user
.
allAuth
,
}
export
default
getters
\ No newline at end of file
src/store/index.js
View file @
8f091636
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
user
from
'./modules/user'
// import example from './module-example'
import
permission
from
'./modules/permission'
import
getters
from
'./getters'
Vue
.
use
(
Vuex
)
// export default function( /* { ssrContext } */ ) {
// const Store = new Vuex.Store({
// modules: {
// // example
// user,
// permission
// },
// getters,
// // enable strict mode (adds overhead!)
// // for dev mode only
/*
* If not building with SSR mode, you can
* directly export the Store instantiation;
*
* The function below can be async too; either use
* async/await or return a Promise which resolves
* with the Store instance.
*/
// })
export
default
function
(
/* { ssrContext } */
)
{
const
Store
=
new
Vuex
.
Store
({
// return Store
// }
const
store
=
new
Vuex
.
Store
({
modules
:
{
// example
user
user
,
permission
},
// enable strict mode (adds overhead!)
// for dev mode only
getters
,
strict
:
process
.
env
.
DEV
})
})
return
Store
}
\ No newline at end of file
export
default
store
\ No newline at end of file
src/store/modules/permission.js
0 → 100644
View file @
8f091636
import
Vue
from
'vue'
/**
*
* @param {*} router
* @param {*} authInfo
*/
function
checkAuth
(
router
,
authInfo
)
{
// 判断当前路由在权限数组中是否存在
if
(
router
.
meta
)
{
const
metaInfo
=
router
.
meta
if
(
!
metaInfo
.
requiresAuth
)
{
return
true
}
else
{
if
(
metaInfo
.
index
==
0
)
{
return
!!
authInfo
[
metaInfo
.
type
]
}
else
if
(
metaInfo
.
index
==
1
)
{
if
(
authInfo
[
metaInfo
.
type
])
{
return
!!
authInfo
[
metaInfo
.
type
][
metaInfo
.
subType
]
}
return
false
}
else
{
var
typeAuth
=
authInfo
[
metaInfo
.
type
]
for
(
let
index
=
0
;
index
<
metaInfo
.
subType
.
length
;
index
++
)
{
const
field
=
metaInfo
.
subType
[
index
]
typeAuth
=
typeAuth
[
field
]
if
(
typeAuth
&&
metaInfo
.
subType
.
length
-
1
==
index
)
{
return
true
}
else
if
(
!
typeAuth
)
{
return
false
}
}
}
}
}
return
true
}
/**
*
* @param {*} routers
* @param {*} authInfo
*/
const
filterAsyncRouter
=
function
(
routers
,
authInfo
)
{
const
res
=
[]
routers
.
forEach
(
router
=>
{
const
tmp
=
{
...
router
}
if
(
checkAuth
(
tmp
,
authInfo
))
{
if
(
tmp
.
children
)
{
tmp
.
children
=
filterAsyncRouter
(
tmp
.
children
,
authInfo
)
}
res
.
push
(
tmp
)
}
})
return
res
}
const
permission
=
{
state
:
{
addRouters
:
[]
},
mutations
:
{
SET_ROUTERS
:
(
state
,
routers
)
=>
{
state
.
addRouters
=
routers
}
},
actions
:
{
GenerateRoutes
({
commit
},
data
)
{
return
new
Promise
(
resolve
=>
{
// TODO 实现权限验证
resolve
()
})
}
}
}
export
default
permission
\ No newline at end of file
src/store/modules/user.js
View file @
8f091636
...
...
@@ -7,7 +7,7 @@ const user = {
state
:
{
userInfo
:
null
,
// 用户信息
//TODO 用户权限
allAuth
:
null
,
allAuth
:
[
'/home'
]
,
},
mutations
:
{
...
...
@@ -23,22 +23,26 @@ const user = {
actions
:
{
// 登录
Login
({
commit
},
userInfo
)
{
const
username
=
userInfo
.
a
ccount
.
trim
();
userInfo
.
Account
=
userInfo
.
A
ccount
.
trim
();
return
new
Promise
((
resolve
,
reject
)
=>
{
login
(
user
name
,
userInfo
.
password
)
login
(
user
Info
)
.
then
(
data
=>
{
Lockr
.
set
(
"Token"
,
data
[
"Token"
]);
Lockr
.
set
(
"loginUserInfo"
,
data
.
user
);
let
r
=
data
.
Data
let
token
=
r
.
Token
delete
r
.
Token
Lockr
.
set
(
"Token"
,
token
);
Lockr
.
set
(
"loginUserInfo"
,
r
);
Lockr
.
set
(
"authList"
,
data
.
auth
);
//
Lockr.set("authList", data.auth);
addAuth
(
data
[
"Token"
]
);
commit
(
"SET_USERINFO"
,
data
.
user
);
commit
(
'SET_ALLAUTH'
,
data
.
auth
)
addAuth
(
token
);
//
commit("SET_USERINFO", data.user);
//
commit('SET_ALLAUTH', data.auth)
// TODO 完成登录 读取权限
resolve
(
data
);
})
.
catch
(
error
=>
{
console
.
log
(
error
)
reject
(
error
);
});
});
...
...
src/utils/cache.js
View file @
8f091636
...
...
@@ -23,7 +23,8 @@ const cache = {
*/
updateAxiosCache
:
function
()
{
axios
.
defaults
.
headers
[
'Token'
]
=
Lockr
.
get
(
'Token'
)
store
.
dispatch
(
'GetUserInfo'
)
//TODO 更新用户信息
//store.dispatch('GetUserInfo')
},
/**
* 移除登录信息
...
...
src/utils/request.js
View file @
8f091636
...
...
@@ -4,7 +4,7 @@ import qs from "qs";
import
{
Dialog
,
Notify
}
from
'quasar'
var
showLoginMessageBox
=
false
;
axios
.
defaults
.
headers
.
post
[
"Content-Type"
]
=
"application/json;charset=UTF-8"
;
//application/x-www-form-urlencoded;charset=UTF-8
axios
.
defaults
.
headers
[
"Content-Type"
]
=
"application/json;charset=UTF-8"
;
//application/x-www-form-urlencoded;charset=UTF-8
const
service
=
axios
.
create
({
baseURL
:
process
.
env
.
API
,
...
...
@@ -14,6 +14,7 @@ const service = axios.create({
// request拦截器
service
.
interceptors
.
request
.
use
(
config
=>
{
console
.
log
(
config
.
headers
)
const
flag
=
config
.
headers
[
"Content-Type"
]
&&
config
.
headers
[
"Content-Type"
].
indexOf
(
"application/json"
)
!==
-
1
;
...
...
@@ -26,6 +27,10 @@ service.interceptors.request.use(
}
else
{
config
.
data
=
qs
.
stringify
(
config
.
data
);
}
}
else
{
config
.
data
=
{
"Msg"
:
config
.
data
}
}
return
config
;
},
...
...
@@ -43,9 +48,9 @@ service.interceptors.response.use(
if
(
response
.
status
===
200
&&
response
.
config
.
responseType
===
"blob"
)
{
// 文件类型特殊处理
return
response
;
}
else
if
(
res
.
code
!==
0
)
{
}
else
if
(
res
.
Code
!=
1
)
{
// TODO 确定后台的CODE码
if
(
res
.
code
=
==
302
)
{
if
(
res
.
Code
==
302
)
{
if
(
!
showLoginMessageBox
)
{
showLoginMessageBox
=
true
;
Dialog
.
create
({
...
...
@@ -63,11 +68,11 @@ service.interceptors.response.use(
});
}
}
else
{
if
(
res
.
msg
)
{
if
(
res
.
Message
)
{
Notify
.
create
({
icon
:
"error"
,
color
:
"negative"
,
message
:
res
.
msg
,
message
:
res
.
Message
,
position
:
"top"
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment