Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
肖康
/
H5_2.0
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5346cdd4
authored
May 19, 2023
by
肖康
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
全局拦截生成csrf uid
parent
bca5d83e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
main.js
router/index.js
util/util.js
main.js
View file @
5346cdd4
import
App
from
'./App'
import
{
request
,
setCookie
,
getCookie
}
from
'@/util/util.js'
import
{
request
}
from
'@/util/util.js'
import
filters
from
'@/filters'
import
router
from
'@/router/index.js'
import
{
RouterMount
}
from
'uni-simple-router'
import
directive
from
'@/directive'
import
w_md5
from
'@/util/md5.js'
// #ifndef VUE3
import
Vue
from
'vue'
...
...
@@ -20,17 +19,6 @@ Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));
Vue
.
use
(
directive
);
//生成临时Yo4teW_gid和Yo4teW_csrf
let
time
=
parseInt
(
new
Date
().
getTime
()
/
1000
);
let
gid_
=
w_md5
.
hex_md5_32
(
w_md5
.
hex_md5_32
(
String
(
time
)
+
Math
.
random
())
+
"usersign"
)
let
csrf_
=
w_md5
.
hex_md5_32
(
w_md5
.
hex_md5_32
(
String
(
time
)
+
Math
.
random
())
+
"csrf"
)
if
(
!
getCookie
(
"Yo4teW_gid"
))
{
setCookie
(
'Yo4teW_gid'
,
gid_
,
15
);
}
if
(
!
getCookie
(
"Yo4teW_csrf"
))
{
setCookie
(
'Yo4teW_csrf'
,
csrf_
,
15
);
}
try
{
...
...
router/index.js
View file @
5346cdd4
// router/index.js
import
Vue
from
'vue'
import
Router
from
'uni-simple-router'
import
{
Ichunt_Api
,
Api_Url
}
from
'@/util/api.js'
;
import
{
request
,
getCookie
,
setCookie
}
from
'@/util/util.js'
Vue
.
use
(
Router
)
//初始化
const
router
=
new
Router
({
...
...
@@ -139,6 +140,17 @@ const router = new Router({
//全局路由前置守卫
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
//写入 Yo4teW_gid Yo4teW_csrf
if
(
!
getCookie
(
"Yo4teW_gid"
))
{
request
(
Api_Url
+
"/public/apiInit"
,
'get'
,
{}).
then
(
res
=>
{
if
(
res
.
err_code
===
0
)
{
setCookie
(
'Yo4teW_gid'
,
res
.
data
.
Yo4teW_gid
,
15
);
setCookie
(
'Yo4teW_csrf'
,
res
.
data
.
Yo4teW_csrf
,
15
);
next
()
}
});
return
}
next
()
})
// 全局路由后置守卫
...
...
util/util.js
View file @
5346cdd4
...
...
@@ -3,6 +3,7 @@ import API_BASE from '../util/api.js'
* 请求封装
*/
const
request
=
(
url
=
''
,
type
=
'GET'
,
param
=
{},
Loading
,
headertype
)
=>
{
//是否启动加载
if
(
Loading
)
{
uni
.
showLoading
({
...
...
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