Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
V
vite-threejs-vue
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
黄麒宇
vite-threejs-vue
Commits
35cfb5c8
Commit
35cfb5c8
authored
Apr 26, 2022
by
huangqy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交下axios封装与验证方式还有ts各类的配置
parent
915faa8a
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
34 行增加
和
14 行删除
+34
-14
package.json
package.json
+0
-1
request.ts
src/utils/request.ts
+24
-8
validate.ts
src/utils/validate.ts
+4
-4
tsconfig.json
tsconfig.json
+5
-1
vite.config.ts
vite.config.ts
+1
-0
没有找到文件。
package.json
View file @
35cfb5c8
...
...
@@ -13,7 +13,6 @@
"
axios
"
:
"^0.26.1"
,
"
lodash
"
:
"^4.17.21"
,
"
vue
"
:
"^3.2.25"
,
"
vue-ls
"
:
"^4.2.0"
,
"
vue-router
"
:
"^4.0.14"
,
"
vuex
"
:
"^4.0.2"
},
...
...
src/utils/request.ts
View file @
35cfb5c8
import
Vue
from
'vue'
import
Axios
,
{
Method
,
ResponseType
,
AxiosResponse
}
from
'axios'
import
{
message
}
from
'ant-design-vue'
;
...
...
@@ -30,9 +29,8 @@ axios.defaults.headers.post['Content-Type'] = 'application/json'
// 请求拦截器
axios
.
interceptors
.
request
.
use
(
(
config
)
=>
{
const
token
=
Vue
.
ls
.
get
(
ACCESS_TOKEN
)
if
(
token
)
{
config
.
headers
[
'X-Access-Token'
]
=
token
// 让每个请求携带自定义 token 请根据实际情况自行修改
if
(
sessionStorage
.
getItem
(
"accessToken"
))
{
config
.
headers
!
.
Authorization
=
`
${
sessionStorage
.
getItem
(
"accessToken"
)}
`
;
}
return
config
;
},
...
...
@@ -67,12 +65,30 @@ export default function request(arr: axiosData) {
responseType
:
arr
.
responseType
||
'json'
})
.
then
((
response
:
AxiosResponse
<
any
>
)
=>
{
if
(
response
.
data
.
code
==
99200
)
{
message
.
error
(
response
.
data
)
/**
* response格式
*
* {
data:{},
status:200,
statusText:'OK',//从服务器返回的http状态文本
headers: {},//响应头信息
config: {} //`config`是在请求的时候的一些配置信息
}
*/
const
responseStatus
=
`
${
response
.
status
}
`
// 状态码为2开头的
if
(
responseStatus
.
charAt
(
0
)
===
'2'
)
{
if
(
response
.
data
.
code
!==
'99200'
)
{
message
.
error
(
response
.
data
.
message
)
reject
(
response
.
data
)
return
}
resolve
(
response
.
data
)
}
else
{
message
.
error
(
response
.
data
.
message
)
reject
(
response
.
data
)
return
}
resolve
(
response
.
data
)
})
.
catch
((
err
)
=>
{
message
.
error
(
err
.
message
)
...
...
src/utils/validate.ts
View file @
35cfb5c8
/**
* 邮箱
* @param {*} s
* @param {*} s
tr
*/
export
function
isEmail
(
str
:
string
)
{
return
/^
([
a-zA-Z0-9._-
])
+@
([
a-zA-Z0-9_-
])
+
((
.
[
a-zA-Z0-9_-
]{2,3}){1,2})
$/
.
test
(
str
)
...
...
@@ -8,7 +8,7 @@
/**
* 手机号码
* @param {*} s
* @param {*} s
tr
*/
export
function
isMobile
(
str
:
string
)
{
return
/^1
[
0-9
]{10}
$/
.
test
(
str
)
...
...
@@ -16,7 +16,7 @@ export function isMobile (str: string) {
/**
* 电话号码
* @param {*} s
* @param {*} s
tr
*/
export
function
isPhone
(
str
:
string
)
{
return
/^
([
0-9
]{3,4}
-
)?[
0-9
]{7,8}
$/
.
test
(
str
)
...
...
@@ -24,7 +24,7 @@ export function isPhone (str: string) {
/**
* URL地址
* @param {*} s
* @param {*} s
tr
*/
export
function
isURL
(
str
:
string
)
{
return
/^http
[
s
]?
:
\/\/
.*/
.
test
(
str
)
...
...
tsconfig.json
View file @
35cfb5c8
...
...
@@ -10,7 +10,11 @@
"resolveJsonModule"
:
true
,
"isolatedModules"
:
true
,
"esModuleInterop"
:
true
,
"lib"
:
[
"esnext"
,
"dom"
]
"lib"
:
[
"esnext"
,
"dom"
],
"baseUrl"
:
"./"
,
"paths"
:
{
"@/*"
:
[
"src/*"
]
}
},
"include"
:
[
"src/**/*.ts"
,
"src/**/*.d.ts"
,
"src/**/*.tsx"
,
"src/**/*.vue"
],
"references"
:
[{
"path"
:
"./tsconfig.node.json"
}]
...
...
vite.config.ts
View file @
35cfb5c8
...
...
@@ -11,6 +11,7 @@ export default defineConfig({
resolve
:
{
alias
:
{
// 如果报错__dirname找不到,需要安装node,执行yarn add @types/node --save-dev
'~'
:
resolve
(
__dirname
,
'./'
),
'@'
:
resolve
(
__dirname
,
'src'
)
}
},
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论