- 更新所有文件的导入和导出语法,使用 ES6 模块格式 - 修改 package.json,添加 "type": "module" 配置 - 调整部分代码结构以适应 ES6 模块
20 lines
501 B
JavaScript
20 lines
501 B
JavaScript
class FetchResult {
|
|
constructor(code, msg, data = null) {
|
|
if (typeof code !== 'number') {
|
|
throw new Error('Code must be a number')
|
|
}
|
|
if (typeof msg !== 'string') {
|
|
throw new Error('Msg must be a string')
|
|
}
|
|
this.code = code
|
|
this.msg = msg
|
|
this.data = data !== undefined && data !== null ? data : null
|
|
}
|
|
|
|
static formatResult(res, code, msg, data = null) {
|
|
return res.status(code).json(new FetchResult(code, msg, data))
|
|
}
|
|
}
|
|
|
|
export default FetchResult
|