Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
ProjectSpecification
Project
Project
Details
Activity
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
guohao
ProjectSpecification
Commits
2b4ce186
Commit
2b4ce186
authored
Jul 07, 2020
by
guohao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(前后端交互): 添加交互规范
parent
9c08960f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
0 deletions
+132
-0
config.js
docs/.vuepress/config.js
+1
-0
前后端交互.md
docs/chapter1/前后端交互.md
+131
-0
No files found.
docs/.vuepress/config.js
View file @
2b4ce186
...
...
@@ -22,6 +22,7 @@ module.exports = {
"chapter1/JS代码规范"
,
"chapter1/CSS代码规范"
,
"chapter1/Git代码提交规范"
,
"chapter1/前后端交互"
],
},
],
...
...
docs/chapter1/前后端交互.md
0 → 100644
View file @
2b4ce186
# 前后端交互
## 响应结果
> 响应结果形如以下结构
```
js
{
code
:
200
,
// 按照http状态直接返回就好(可自定义状态)
data
:
{},
// 返回数据
message
:
""
,
// 返回参考信息(可以不返回该字段)
srvTime
:
"2020-07-06 12:00:00"
// 当前服务器信息
}
```
> 参考信息如下:
-
自定义响应状态
```
js
{
code
:
10001
,
// 无该页面访问权限
message
:
"无该页面访问权限"
,
srvTime
:
"2020-07-06 12:00:00"
,
// 当前服务器信息
}
{
code
:
10002
,
// 无该页面访问权限
message
:
"无该页面访问权限"
,
srvTime
:
"2020-07-06 12:00:00"
// 当前服务器信息
}
```
-
返回数据
```
js
// 正常情况下
{
code
:
200
,
data
:
{
class
:
"五年一班"
,
memberCount
:
30
,
member
:
[
{
name
:
'小明'
,
age
:
11
},
{
name
:
'小红'
,
age
:
13
},
{
name
:
'小白'
,
age
:
12
},
]
},
srvTime
:
"2020-07-06 12:00:00"
}
// 字符串数据不存在的时候,返回空字符串
{
code
:
200
,
data
:
{
class
:
""
,
memberCount
:
30
,
member
:
[
{
name
:
'小明'
,
age
:
11
},
{
name
:
'小红'
,
age
:
13
},
{
name
:
'小白'
,
age
:
12
},
]
},
srvTime
:
"2020-07-06 12:00:00"
}
// int类型数据不存在的时候,字段不返回
{
code
:
200
,
data
:
{
class
:
"五年一班"
,
member
:
[
{
name
:
'小明'
,
age
:
11
},
{
name
:
'小红'
,
age
:
13
},
{
name
:
'小白'
,
age
:
12
},
]
},
srvTime
:
"2020-07-06 12:00:00"
}
// 数组查询为空,返回空数组
{
code
:
200
,
data
:
{
class
:
"五年一班"
,
memberCount
:
30
,
member
:
[]
},
srvTime
:
"2020-07-06 12:00:00"
}
```
-
message返回情况
```
js
// 接口访问无权限
{
code
:
10001
,
message
:
"无权限"
,
srvTime
:
"2020-07-06 12:00:00"
}
// 修改类
{
code
:
200
,
data
:
{
---
},
message
:
"修改成功 | 修改失败"
,
srvTime
:
"2020-07-06 12:00:00"
}
// 上传类
{
code
:
200
|
10003
,
data
:
{
---
},
message
:
"上传成功 | 上传失败"
,
srvTime
:
"2020-07-06 12:00:00"
}
// 请求错误
{
code
:
500
,
data
:
{
---
},
message
:
"error message"
,
// 错误信息返回明确 比如 sql报错,或者其他问题, 便于定位错误
srvTime
:
"2020-07-06 12:00:00"
}
```
\ No newline at end of file
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