Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
merchant-manage-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
ui
merchant-manage-ui
Commits
add401fa
Commit
add401fa
authored
Jun 01, 2023
by
武广
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 处理获取token 问题
parent
f324f4af
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
13 deletions
+26
-13
BasicLayout.jsx
src/layouts/BasicLayout.jsx
+2
-2
SecurityLayout.jsx
src/layouts/SecurityLayout.jsx
+8
-1
index.jsx
src/pages/GoodsManage/index.jsx
+4
-4
request.js
src/utils/request.js
+2
-6
utils.js
src/utils/utils.js
+10
-0
No files found.
src/layouts/BasicLayout.jsx
View file @
add401fa
...
@@ -14,7 +14,7 @@ import Authorized from '@/utils/Authorized';
...
@@ -14,7 +14,7 @@ import Authorized from '@/utils/Authorized';
import
localStorage
from
'
@/utils/localStorage
'
;
import
localStorage
from
'
@/utils/localStorage
'
;
import
RightContent
from
'
@/components/GlobalHeader/RightContent
'
;
import
RightContent
from
'
@/components/GlobalHeader/RightContent
'
;
import
MessageReminder
from
'
@/components/MessageReminder
'
;
import
MessageReminder
from
'
@/components/MessageReminder
'
;
import
{
getAuthorityFromRouter
,
getUrlSearchParams
}
from
'
@/utils/utils
'
;
import
{
getAuthorityFromRouter
,
getUrlSearchParams
,
getToken
}
from
'
@/utils/utils
'
;
import
{
getSocketUrl
}
from
'
@/services/messageReminder
'
;
import
{
getSocketUrl
}
from
'
@/services/messageReminder
'
;
import
logo
from
'
../assets/logo.png
'
;
import
logo
from
'
../assets/logo.png
'
;
import
style
from
'
./BasicLayout.less
'
;
import
style
from
'
./BasicLayout.less
'
;
...
@@ -60,7 +60,7 @@ const BasicLayout = props => {
...
@@ -60,7 +60,7 @@ const BasicLayout = props => {
useEffect
(()
=>
{
useEffect
(()
=>
{
try
{
try
{
const
token
=
window
.
localStorage
.
getItem
(
'
token
'
);
const
token
=
getToken
(
);
const
socket
=
new
Socket
({
const
socket
=
new
Socket
({
url
:
getSocketUrl
({
token
,
channelId
:
CHANNEL_ID
}),
url
:
getSocketUrl
({
token
,
channelId
:
CHANNEL_ID
}),
});
});
...
...
src/layouts/SecurityLayout.jsx
View file @
add401fa
...
@@ -3,6 +3,7 @@ import { connect } from 'dva';
...
@@ -3,6 +3,7 @@ import { connect } from 'dva';
import
{
Redirect
}
from
'
umi
'
;
import
{
Redirect
}
from
'
umi
'
;
import
PageLoading
from
'
@/components/PageLoading
'
;
import
PageLoading
from
'
@/components/PageLoading
'
;
import
localStorage
from
'
@/utils/localStorage
'
;
import
localStorage
from
'
@/utils/localStorage
'
;
import
{
getUrlSearchParams
,
getToken
}
from
'
@/utils/utils
'
;
class
SecurityLayout
extends
React
.
Component
{
class
SecurityLayout
extends
React
.
Component
{
state
=
{
state
=
{
...
@@ -24,13 +25,19 @@ class SecurityLayout extends React.Component {
...
@@ -24,13 +25,19 @@ class SecurityLayout extends React.Component {
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-underscore-dangle */
render
()
{
render
()
{
// 判断是否从tob进入
const
searchPrams
=
getUrlSearchParams
();
const
isTob
=
searchPrams
.
source
===
'
tob
'
;
const
{
isReady
}
=
this
.
state
;
const
{
isReady
}
=
this
.
state
;
let
isLogin
=
true
;
let
isLogin
=
true
;
// 你可以把它替换成你自己的登录认证规则(比如判断 token 是否存在)
// 你可以把它替换成你自己的登录认证规则(比如判断 token 是否存在)
const
{
children
,
loading
}
=
this
.
props
;
const
{
children
,
loading
}
=
this
.
props
;
if
(
!
localStorage
.
get
(
'
token
'
))
{
if
(
!
getToken
(
))
{
isLogin
=
false
;
isLogin
=
false
;
}
}
console
.
log
(
'
getToken() :>>
'
,
getToken
());
console
.
log
(
'
isLogin :>>
'
,
isLogin
);
// 切换子应用布局
// 切换子应用布局
if
(
window
.
__POWERED_BY_QIANKUN__
)
{
if
(
window
.
__POWERED_BY_QIANKUN__
)
{
...
...
src/pages/GoodsManage/index.jsx
View file @
add401fa
...
@@ -4,8 +4,8 @@ import { Card, Pagination, Table, notification, Drawer, Spin, Button, Modal } fr
...
@@ -4,8 +4,8 @@ import { Card, Pagination, Table, notification, Drawer, Spin, Button, Modal } fr
import
React
,
{
Component
}
from
'
react
'
;
import
React
,
{
Component
}
from
'
react
'
;
import
{
PageHeaderWrapper
}
from
'
@ant-design/pro-layout
'
;
import
{
PageHeaderWrapper
}
from
'
@ant-design/pro-layout
'
;
import
{
connect
}
from
'
dva
'
;
import
{
connect
}
from
'
dva
'
;
import
{
getToken
}
from
'
@/utils/utils
'
;
import
styles
from
'
./style.less
'
;
import
styles
from
'
./style.less
'
;
import
LocalStroage
from
'
@/utils/localStorage
'
;
import
configApi
from
'
../../../config/env.config
'
;
import
configApi
from
'
../../../config/env.config
'
;
import
UpdateStock
from
'
./UpdateStock
'
;
import
UpdateStock
from
'
./UpdateStock
'
;
...
@@ -163,9 +163,9 @@ class goodsManage extends Component {
...
@@ -163,9 +163,9 @@ class goodsManage extends Component {
audit
=
skuId
=>
{
audit
=
skuId
=>
{
this
.
setState
({
this
.
setState
({
previewVisible
:
true
,
previewVisible
:
true
,
src
:
`
${
configApi
.
prologueDomain
}
/goods/
${
skuId
}
?h=0&token=
${
LocalStroage
.
get
(
src
:
`
${
'
token
'
,
configApi
.
prologueDomain
)}
&hideReport=1&time=
${
Date
.
now
()}
`
,
}
/goods/
${
skuId
}
?h=0&token=
${
getToken
(
)}
&hideReport=1&time=
${
Date
.
now
()}
`
,
});
});
};
};
...
...
src/utils/request.js
View file @
add401fa
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-underscore-dangle */
import
{
extend
}
from
'
umi-request
'
;
import
{
extend
}
from
'
umi-request
'
;
import
{
notification
}
from
'
antd
'
;
import
{
notification
}
from
'
antd
'
;
import
{
getUrlSearchParams
}
from
'
./utils
'
;
import
{
getUrlSearchParams
,
getToken
}
from
'
./utils
'
;
import
localStorage
from
'
./localStorage
'
;
import
localStorage
from
'
./localStorage
'
;
import
config
from
'
../../config/env.config
'
;
import
config
from
'
../../config/env.config
'
;
...
@@ -81,11 +81,7 @@ const isTob = searchPrams.source === 'tob';
...
@@ -81,11 +81,7 @@ const isTob = searchPrams.source === 'tob';
// request拦截器, 改变url 或 options.
// request拦截器, 改变url 或 options.
request
.
interceptors
.
request
.
use
(
async
(
url
,
options
)
=>
{
request
.
interceptors
.
request
.
use
(
async
(
url
,
options
)
=>
{
let
token
=
localStorage
.
get
(
'
token
'
);
const
token
=
getToken
();
// tob进入使用tob token
if
(
isTob
&&
localStorage
.
get
(
'
tobToken
'
))
{
token
=
localStorage
.
get
(
'
tobToken
'
);
}
if
(
!
token
&&
!
url
.
includes
(
'
/v2/oauth/login
'
))
{
if
(
!
token
&&
!
url
.
includes
(
'
/v2/oauth/login
'
))
{
window
.
location
.
href
=
`
${
window
.
origin
}
/user/login`
;
window
.
location
.
href
=
`
${
window
.
origin
}
/user/login`
;
}
}
...
...
src/utils/utils.js
View file @
add401fa
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
{
parse
}
from
'
querystring
'
;
import
{
parse
}
from
'
querystring
'
;
import
pathRegexp
from
'
path-to-regexp
'
;
import
pathRegexp
from
'
path-to-regexp
'
;
import
moment
from
'
moment
'
;
import
moment
from
'
moment
'
;
import
localStorage
from
'
./localStorage
'
;
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
/* eslint no-useless-escape:0 import/prefer-default-export:0 */
const
reg
=
/
(((
^https
?
:
(?:\/\/)?)(?:[
-;:&=
\+\$
,
\w]
+@
)?[
A-Za-z0-9.-
]
+
(?:
:
\d
+
)?
|
(?:
www.|
[
-;:&=
\+\$
,
\w]
+@
)[
A-Za-z0-9.-
]
+
)((?:\/[\+
~%
\/
.
\w
-_
]
*
)?\??(?:[
-
\+
=&;%@.
\w
_
]
*
)
#
?(?:[\w]
*
))?)
$/
;
const
reg
=
/
(((
^https
?
:
(?:\/\/)?)(?:[
-;:&=
\+\$
,
\w]
+@
)?[
A-Za-z0-9.-
]
+
(?:
:
\d
+
)?
|
(?:
www.|
[
-;:&=
\+\$
,
\w]
+@
)[
A-Za-z0-9.-
]
+
)((?:\/[\+
~%
\/
.
\w
-_
]
*
)?\??(?:[
-
\+
=&;%@.
\w
_
]
*
)
#
?(?:[\w]
*
))?)
$/
;
...
@@ -192,3 +193,12 @@ export const getUrlSearchParams = () => {
...
@@ -192,3 +193,12 @@ export const getUrlSearchParams = () => {
}
}
return
newObj
;
return
newObj
;
};
};
// 获取token
export
const
getToken
=
()
=>
{
// 从消费地图后管过来
if
(
getUrlParams
(
'
source
'
)
===
'
tob
'
&&
localStorage
.
get
(
'
tobToken
'
))
{
return
localStorage
.
get
(
'
tobToken
'
);
}
return
localStorage
.
get
(
'
token
'
);
};
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