Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
h5
/
vite-integral
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b9b17c54
authored
Aug 16, 2022
by
胡悦
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
解决低版本兼容性问题,修改了axios拦截器
1 parent
dfe48e18
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
21 deletions
src/main.ts
src/utils/axios.ts
src/utils/config.ts
src/utils/http.ts
src/utils/request.ts
src/views/home/index.vue
src/views/home/userInfo.vue
src/views/login/register.vue
vite.config.ts
src/main.ts
View file @
b9b17c5
import
{
createApp
}
from
'vue'
import
{
createApp
}
from
'vue'
import
store
from
'./store'
import
store
from
'./store'
import
axios
from
'axios'
// import apis from './api/index'
// import apis from './api/index'
import
router
,
{
setupRouter
}
from
'./router'
import
router
,
{
setupRouter
}
from
'./router'
import
App
from
'./App.vue'
import
App
from
'./App.vue'
import
SvgIcon
from
'comps/SvgIcon/index.vue'
import
SvgIcon
from
'comps/SvgIcon/index.vue'
import
'lib-flexible/flexible'
import
'lib-flexible/flexible'
import
'utils/rem'
import
'utils/rem'
import
fetchConfig
from
'./utils/config'
import
VConsole
from
'vconsole'
import
VConsole
from
'vconsole'
import
'assets/styles/common.scss'
import
'assets/styles/common.scss'
const
app
=
createApp
(
App
)
const
app
=
createApp
(
App
)
...
@@ -13,6 +15,10 @@ const vConsole = new VConsole()
...
@@ -13,6 +15,10 @@ const vConsole = new VConsole()
import
{
components
}
from
'./libs/vant'
import
{
components
}
from
'./libs/vant'
components
.
forEach
(
component
=>
app
.
use
(
component
));
components
.
forEach
(
component
=>
app
.
use
(
component
));
app
.
component
(
'svg-icon'
,
SvgIcon
)
app
.
component
(
'svg-icon'
,
SvgIcon
)
fetchConfig
().
then
(
res
=>
{
axios
.
defaults
.
baseURL
=
res
.
request
.
baseURL
})
// app.config.globalProperties.$axios = apis
// app.config.globalProperties.$axios = apis
// setupStore(app)
// setupStore(app)
app
.
use
(
store
)
app
.
use
(
store
)
...
...
src/utils/axios.ts
View file @
b9b17c5
...
@@ -6,15 +6,6 @@ import qs from 'qs'
...
@@ -6,15 +6,6 @@ import qs from 'qs'
import
{
createSign
}
from
'./util'
import
{
createSign
}
from
'./util'
import
$mockConfig
from
'./config'
import
$mockConfig
from
'./config'
import
{
useUserStore
}
from
'../store/user'
import
{
useUserStore
}
from
'../store/user'
// function getSession(key: string) {
// let json: any = window.sessionStorage.getItem(key)
// return JSON.parse(json)
// }
// setTimeout(() => {
// console.log(useUserStore())
// }, 1000)
export
const
PATH_URL
:
string
=
'/api'
||
import
.
meta
.
env
.
VITE_API_URL
const
{
response
=
{},
request
=
{},
headers
=
{},
alert
,
sign
,
signWay
=
'sha1'
,
secret
}
=
$mockConfig
const
{
response
=
{},
request
=
{},
headers
=
{},
alert
,
sign
,
signWay
=
'sha1'
,
secret
}
=
$mockConfig
// 配置新建一个axios 实例
// 配置新建一个axios 实例
const
service
:
AxiosInstance
=
axios
.
create
({
const
service
:
AxiosInstance
=
axios
.
create
({
...
...
src/utils/config.ts
View file @
b9b17c5
const
fetchConfig
=
function
(
isEnv
=
true
)
{
const
fetchConfig
=
function
(
isEnv
=
true
)
{
return
window
.
fetch
(
'http://oss-config.dev.glsx.com.cn/mock/618cb9331072f92988f05a23/wx/integral-config'
,
{}).
then
(
res
=>
res
.
json
())
return
window
.
fetch
(
'http://oss-config.dev.glsx.com.cn/mock/618cb9331072f92988f05a23/wx/integral-config'
,
{}).
then
(
res
=>
res
.
json
())
}
}
const
$mockConfig
=
await
fetchConfig
()
export
default
$mockConfig
\ No newline at end of file
\ No newline at end of file
// const $mockConfig = await fetchConfig()
export
default
fetchConfig
\ No newline at end of file
\ No newline at end of file
src/utils/http.ts
0 → 100644
View file @
b9b17c5
import
axios
,
{
AxiosInstance
,
AxiosRequestConfig
,
AxiosResponse
,
AxiosError
}
from
'axios'
import
{
Toast
}
from
'vant'
;
import
router
from
'../router'
import
qs
from
'qs'
import
{
createSign
}
from
'./util'
const
sign
=
{
v
:
'1.0.0'
,
format
:
'json'
,
source
:
'vite-integral'
,
appKey
:
'48e5e13229b82c1b4e6e8c96151f0637'
}
const
secret
=
'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b'
const
response
=
{
data_key
:
'data'
,
message_key
:
'message'
,
code_key
:
'code'
,
code_success_value
:
'0'
,
errId_logout_value
:
'21'
,
logout_function
:
'reLogin'
,
code_message_map
:
{}
}
// const { response = {}, request = {}, headers = {}, alert, sign, signWay = 'sha1', secret } = options
// 配置新建一个axios 实例
const
service
:
AxiosInstance
=
axios
.
create
({
timeout
:
50000
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
}
})
// 添加请求拦截器
service
.
interceptors
.
request
.
use
((
config
:
AxiosRequestConfig
)
=>
{
console
.
log
(
config
)
let
{
data
=
{}
}
=
config
data
=
createSign
(
Object
.
assign
({},
sign
,
data
),
secret
)
// console.log(config)
if
(
config
.
method
)
{
const
method
=
config
.
method
.
toLowerCase
()
if
(
method
==
'get'
)
{
config
.
params
=
data
}
else
if
(
method
==
'post'
)
{
config
.
data
=
qs
.
stringify
(
data
)
}
}
return
config
},
(
error
:
AxiosError
)
=>
{
return
Promise
.
reject
(
error
)
})
// 添加响应拦截器
service
.
interceptors
.
response
.
use
((
r
)
=>
{
console
.
log
(
r
)
const
{
data
:
res
,
config
:
{
returnAll
}
}
=
r
const
{
code_key
,
code_success_value
=
'0'
,
data_key
=
'data'
,
errId_logout_value
,
logout_function
=
'logout'
}
=
response
const
errId
=
'errId'
if
(
returnAll
)
{
return
res
}
let
codekey
=
Array
.
isArray
(
code_key
)
?
code_key
.
find
(
key
=>
res
.
hasOwnProperty
(
key
))
:
code_key
let
code
=
res
[
codekey
]
let
errValue
=
res
[
errId
]
console
.
log
(
code
,
errValue
)
// 特殊的code处理,可以增加
switch
(
code
+
''
)
{
case
code_success_value
+
''
:
break
case
errId_logout_value
+
''
:
localStorage
.
removeItem
(
'sessionId'
)
router
.
push
(
'/login'
)
console
.
log
(
'退出登录'
)
break
default
:
if
(
errValue
&&
errValue
==
errId_logout_value
)
{
localStorage
.
removeItem
(
'sessionId'
)
router
.
push
(
'/login'
)
}
Toast
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
break
}
return
res
[
data_key
]
},
error
=>
{
Toast
(
error
.
message
)
return
Promise
.
reject
(
error
)
})
export
default
service
\ No newline at end of file
\ No newline at end of file
src/utils/request.ts
View file @
b9b17c5
import
axios
from
'./axios
'
import
http
from
'./http
'
import
{
useUserStore
}
from
'../store/user'
import
{
useUserStore
}
from
'../store/user'
const
PATH
=
'rop-scrm-renewal/router'
const
PATH
=
'rop-scrm-renewal/router'
...
@@ -8,7 +8,7 @@ const req: any = (url: string, data: any = {}, returnAll = false, method = 'POST
...
@@ -8,7 +8,7 @@ const req: any = (url: string, data: any = {}, returnAll = false, method = 'POST
console
.
log
(
'调用接口前'
,
sessionId
)
console
.
log
(
'调用接口前'
,
sessionId
)
if
(
sessionId
)
data
.
loginSessionId
=
sessionId
if
(
sessionId
)
data
.
loginSessionId
=
sessionId
data
.
method
=
url
data
.
method
=
url
return
axios
({
return
http
({
url
:
PATH
,
url
:
PATH
,
method
,
method
,
returnAll
,
returnAll
,
...
...
src/views/home/index.vue
View file @
b9b17c5
...
@@ -407,9 +407,6 @@ onBeforeMount(() => {
...
@@ -407,9 +407,6 @@ onBeforeMount(() => {
padding
:
3px
5px
2px
14px
;
padding
:
3px
5px
2px
14px
;
background
:
linear-gradient
(
180deg
,
#ffffff
0%
,
#e2e2e2
100%
);
background
:
linear-gradient
(
180deg
,
#ffffff
0%
,
#e2e2e2
100%
);
border-radius
:
12px
0px
0px
12px
;
border-radius
:
12px
0px
0px
12px
;
border-image
:
linear-gradient
(
180deg
,
rgba
(
247
,
247
,
247
,
1
),
rgba
(
209
,
209
,
209
,
1
))
1
1
;
font-weight
:
400
;
font-weight
:
400
;
color
:
#868686
;
color
:
#868686
;
line-height
:
17px
;
line-height
:
17px
;
...
...
src/views/home/userInfo.vue
View file @
b9b17c5
...
@@ -69,7 +69,7 @@ const update = async(values: object) => {
...
@@ -69,7 +69,7 @@ const update = async(values: object) => {
Dialog
.
alert
({
Dialog
.
alert
({
title
:
'提示'
,
title
:
'提示'
,
message
:
`您的账户已认证通过
message
:
`您的账户已认证通过
不支持修改姓名或车牌号
`
,
请点击“确定”刷新页面重新修改
`
,
}).
then
(()
=>
{
}).
then
(()
=>
{
// on close
// on close
getUserInfo
()
getUserInfo
()
...
...
src/views/login/register.vue
View file @
b9b17c5
...
@@ -121,7 +121,7 @@ const onRegister = async (values: object) => {
...
@@ -121,7 +121,7 @@ const onRegister = async (values: object) => {
Toast
(
'注册成功'
)
Toast
(
'注册成功'
)
router
.
push
(
'/registerSuccess'
)
router
.
push
(
'/registerSuccess'
)
}
else
{
}
else
{
Toast
(
'注册失败'
)
Toast
(
message
)
}
}
}
else
{
}
else
{
Toast
(
message
)
Toast
(
message
)
...
...
vite.config.ts
View file @
b9b17c5
...
@@ -53,7 +53,7 @@ export default defineConfig({
...
@@ -53,7 +53,7 @@ export default defineConfig({
}
}
}
}
},
},
build
:
{
//
build: {
target
:[
'edge90'
,
'chrome90'
,
'firefox90'
,
'safari15'
]
//
target:['edge90','chrome90','firefox90','safari15']
}
//
}
})
})
Write
Preview
Markdown
is supported
Attach a file
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 post a comment