-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
前端开发公共事项 #14
Comments
关于网络请求:
//app/promisify.ts
promisify.request({
url: string;
data?: string | object | ArrayBuffer;
header?: any;
method: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT';
dataType?: string; //如果设为json,会尝试对返回的数据做一次 JSON.parse
}) 返回:一个Promise:
当网络请求得到返回值但返回值为4XX或5XX时,其reject为一个异常对象:
其中如果返回的errid为500-599时,会自动调用uni.showToast方法把异常信息提示给用户,调用者无需再次处理 当网络请求失败(没有得到返回值时),其reject为系统自带的异常对象。 用法示例: async updateAllActivity(){
let res = await promisify.request({
url: getApp().globalData.baseUrl + `/getAllActivity?openId=${getApp().globalData.openId}`,
method: "GET",
dataType: "json",
});
this.activities_toShow = res.data.activityList
} 请注意, |
关于UserInfo类的定义: //app/typesDeclare/UserInfo.ts
interface UserInfo {
openId: string;
name: string;
education: Array<{
type: string,
start: number,
department: string,
}>
flag: string
} |
关于活动信息类的定义: //app/types/ActivitySchema.d.ts
interface ActivitySchema{
id: string,
name: string,
place: string,
start: string, //yyyy-mm-dd hh:MM:ss
end: string, //yyyy-mm-dd hh:MM:ss
minUser?: number
maxUser?: number,
curUser: number,
creator: string,
signupBeginAt: string,
signupStopAt: string, //yyyy-mm-dd hh:MM:ss
participants: [string]
type: string,
status: ActivityStatus
}
declare enum ActivityStatus {
Except = 0, //异常情况(如活动被管理员禁止等)
BeforeSignup = 1, //报名尚未开始
Signup = 2, //报名中
SignupPaused = 3, //报名被暂停(发起人主动)
SignupStopped = 4, //报名已截止(到达设定的时间)
Signin = 5, //签到中
SigninPaused = 6, //签到被暂停
Finish = 7, //活动已结束(到达设定的活动结束时间)
} |
这种返回码是不规范的。在 RESTful API规范 或者一般的 HTTP规范 中,返回码均有特定的含义,这是普遍认可的标准。 常见的返回码:
|
补充: |
SureModal使用方法: <SureModal ref="SureModal"></SureModal> 2.在需要使用的地方: await ((this.$refs.SureModal as any).show("您确定要发起这个活动吗?")); (注:this.$refs.SureModal拿到的引用是Vue类型,必须转为any后才能调用show方法,传入的字符串参数是提示信息文字) async attendCurActivity(){
await ((this.$refs.SureModal as any).show("您报名后无需审核,可以直接加入本活动。\r\n确认要报名参加本活动吗?"));
let res = apiService.post(`/joinActivity?activityId=${this.activityId}`, {})
if(res && res.result === 'success'){
uni.showToast({
title: "报名成功"
});
}else{
uni.showToast({
title: (res && res.errmsg) || '参加失败',
icon: "none"
})
}
this.updateActivityData()
} |
@mayeths @BluesCrossing
考虑到前端代码开发经常会有一些公共的声明、规则乃至轮子,此issue专用于记录此事。
在为前端开发制定公共规范方面大家的权利是平等的:
The text was updated successfully, but these errors were encountered: