提交 3f624983 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

zentao site admin

上级 6c90045f
......@@ -7,8 +7,8 @@ type ResponseCode struct {
var (
Success = ResponseCode{0, "request_success"}
Failure = ResponseCode{100, "request_failure"}
ParamErr = ResponseCode{200, "parm_error"}
CommErr = ResponseCode{100, "comm_err"}
ParamErr = ResponseCode{200, "param_error"}
NeedInitErr = ResponseCode{1000, "data_not_init"}
BizErrProjectConfig = ResponseCode{2000, "project_config_err"}
......
......@@ -26,7 +26,13 @@ func (c *BaseCtrl) ErrResp(err commConsts.ResponseCode, msg string) (ret domain.
}
func (c *BaseCtrl) ErrMsg(err commConsts.ResponseCode, msg string) (ret string) {
ret = i118Utils.Sprintf(err.Key) + "-" + msg
ret = i118Utils.Sprintf(err.Key)
if ret != "" {
ret += ": "
}
ret += msg
return
}
......@@ -29,13 +29,13 @@ func (c *ConfigCtrl) SaveConfig(ctx iris.Context) {
err = configUtils.SaveConfig(req, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
projects, currProject, currProjectConfig, scriptTree, err := c.ProjectService.GetByUser(projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -20,14 +20,14 @@ func NewFileCtrl() *FileCtrl {
func (c *FileCtrl) Upload(ctx iris.Context) {
f, fh, err := ctx.FormFile("file")
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
defer f.Close()
data, err := c.FileService.UploadFile(ctx, fh)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
ctx.JSON(c.SuccessResp(data))
......@@ -41,7 +41,7 @@ func (c *FileCtrl) ListDir(ctx iris.Context) {
var err error
parentDir, err = fileUtils.GetUserHome()
if err != nil {
c.ErrResp(commConsts.Failure, err.Error())
c.ErrResp(commConsts.CommErr, err.Error())
return
}
}
......@@ -49,7 +49,7 @@ func (c *FileCtrl) ListDir(ctx iris.Context) {
data, err := c.FileService.LoadDirs(parentDir)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
ctx.JSON(c.SuccessResp(data))
......
......@@ -29,7 +29,7 @@ func (c *ProjectCtrl) Create(ctx iris.Context) {
_, err = c.ProjectService.Create(req)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -46,7 +46,7 @@ func (c *ProjectCtrl) Delete(ctx iris.Context) {
}
err := c.ProjectService.DeleteByPath(projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -70,7 +70,7 @@ func (c *ProjectCtrl) GetByUser(ctx iris.Context) {
projects, currProject, currProjectConfig, scriptTree, err := c.ProjectService.GetByUser(projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -20,13 +20,13 @@ func NewSiteCtrl() *SiteCtrl {
func (c *SiteCtrl) List(ctx iris.Context) {
var req serverDomain.ReqPaginate
if err := ctx.ReadQuery(&req); err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
data, err := c.SiteService.Paginate(req)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -36,13 +36,13 @@ func (c *SiteCtrl) List(ctx iris.Context) {
func (c *SiteCtrl) Get(ctx iris.Context) {
id, err := ctx.Params().GetInt("id")
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
po, err := c.SiteService.Get(uint(id))
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
ctx.JSON(c.SuccessResp(po))
......@@ -51,12 +51,12 @@ func (c *SiteCtrl) Get(ctx iris.Context) {
func (c *SiteCtrl) Create(ctx iris.Context) {
req := model.Site{}
if err := ctx.ReadJSON(&req); err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
}
id, err := c.SiteService.Create(req)
if err != nil {
c.ErrResp(commConsts.Failure, err.Error())
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -66,12 +66,12 @@ func (c *SiteCtrl) Create(ctx iris.Context) {
func (c *SiteCtrl) Update(ctx iris.Context) {
req := model.Site{}
if err := ctx.ReadJSON(&req); err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
}
err := c.SiteService.Update(req)
if err != nil {
c.ErrResp(commConsts.Failure, err.Error())
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -81,13 +81,13 @@ func (c *SiteCtrl) Update(ctx iris.Context) {
func (c *SiteCtrl) Delete(ctx iris.Context) {
id, err := ctx.Params().GetInt("id")
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
err = c.SiteService.Delete(uint(id))
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -29,7 +29,7 @@ func (c *SyncCtrl) SyncFromZentao(ctx iris.Context) {
err = c.SyncService.SyncFromZentao(req, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -48,7 +48,7 @@ func (c *SyncCtrl) SyncToZentao(ctx iris.Context) {
err := c.SyncService.SyncToZentao(projectPath, commitProductId)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -38,13 +38,13 @@ func (c *TestBugCtrl) Submit(ctx iris.Context) {
projectPath := ctx.URLParam("currProject")
req := commDomain.ZtfBug{}
if err := ctx.ReadJSON(&req); err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
err := c.TestBugService.Submit(req, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -27,7 +27,7 @@ func (c *TestExecCtrl) List(ctx iris.Context) {
data, err := c.TestExecService.List(projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -46,7 +46,7 @@ func (c *TestExecCtrl) Get(ctx iris.Context) {
exec, err := c.TestExecService.Get(projectPath, seq)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
ctx.JSON(c.SuccessResp(exec))
......@@ -64,7 +64,7 @@ func (c *TestExecCtrl) Delete(ctx iris.Context) {
err := c.TestExecService.Delete(projectPath, seq)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -29,7 +29,7 @@ func (c *TestResultCtrl) Submit(ctx iris.Context) {
err = c.TestResultService.Submit(req, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -27,7 +27,7 @@ func (c *TestScriptCtrl) Get(ctx iris.Context) {
script, err := scriptUtils.GetScriptContent(scriptPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
ctx.JSON(c.SuccessResp(script))
......@@ -46,7 +46,7 @@ func (c *TestScriptCtrl) Extract(ctx iris.Context) {
script, err := scriptUtils.GetScriptContent(scriptPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
ctx.JSON(c.SuccessResp(script))
......
......@@ -42,7 +42,7 @@ func (c *ZentaoCtrl) ListModule(ctx iris.Context) {
data, err := zentaoUtils.ListModuleForCase(productId, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -59,7 +59,7 @@ func (c *ZentaoCtrl) ListSuite(ctx iris.Context) {
data, err := zentaoUtils.ListSuiteByProduct(productId, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -76,7 +76,7 @@ func (c *ZentaoCtrl) ListTask(ctx iris.Context) {
data, err := zentaoUtils.ListTaskByProduct(productId, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -94,7 +94,7 @@ func (c *ZentaoCtrl) GetDataForBugSubmition(ctx iris.Context) {
fields, err := zentaoUtils.GetBugFiledOptions(req, projectPath)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......@@ -106,7 +106,7 @@ func (c *ZentaoCtrl) GetDataForBugSubmition(ctx iris.Context) {
func (c *ZentaoCtrl) ListLang(ctx iris.Context) {
data, err := zentaoUtils.ListLang()
if err != nil {
ctx.JSON(c.ErrResp(commConsts.Failure, err.Error()))
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
return
}
......
......@@ -22,8 +22,8 @@ func (m *SiteModule) Party() module.WebModule {
index.Get("/", m.SiteCtrl.List).Name = "列表"
index.Get("/{id:int}", m.SiteCtrl.Get).Name = "详情"
index.Post("/{id:int}", m.SiteCtrl.Create).Name = "保存"
index.Put("/{id:int}", m.SiteCtrl.Update).Name = "保存"
index.Post("/", m.SiteCtrl.Create).Name = "新建"
index.Put("/{id:int}", m.SiteCtrl.Update).Name = "更新"
index.Delete("/{id:int}", m.SiteCtrl.Delete).Name = "删除"
}
return module.NewModule("/sites", handler)
......
......@@ -15,11 +15,11 @@
"translation": "Success"
},
{
"id": "request_failure",
"translation": "Failure"
"id": "comm_err",
"translation": ""
},
{
"id": "parm_error",
"id": "param_error",
"translation": "Parameter error"
},
{
......
......@@ -15,11 +15,11 @@
"translation": "请求成功"
},
{
"id": "request_failure",
"translation": "请求失败"
"id": "comm_err",
"translation": ""
},
{
"id": "parm_error",
"id": "param_error",
"translation": "参数错误"
},
{
......
......@@ -35,7 +35,6 @@ const serverCodeMessage: {[key: number]: string} = {
* 异常处理程序
*/
const errorHandler = (error: any) => {
const { response, message } = error;
if (message === 'CustomError') {
// 自定义错误
......@@ -46,7 +45,7 @@ const errorHandler = (error: any) => {
const noVerifyBool = settings.ajaxResponseNoVerifyUrl.includes(reqUrl);
if (!noVerifyBool) {
notification.error({
message: `提示`,
message: `请求失败`,
description: customCodeMessage[code] || msg || 'Error',
});
}
......
......@@ -92,24 +92,10 @@ export default defineComponent({
const { resetFields, validate, validateInfos } = useForm(model, rules);
const submitForm = () => {
validate()
.then(() => {
console.log(model);
store.dispatch('Site/save', model).then((json) => {
if (json.code === 0) {
notification.success({
message: t('save_success'),
});
} else {
notification.error({
message: t('save_fail'),
description: json.msg,
});
}
})
})
.catch(err => {
console.log('error', err);
});
.then(() => {
console.log(model);
store.dispatch('Site/save', model.value)
})
};
return {
......
......@@ -19,7 +19,7 @@ export async function get(seq: number): Promise<any> {
export async function save(params: any): Promise<any> {
return request({
url: `/${apiPath}`,
url: `/${apiPath}` + (params.id ? `/${params.id}` : ''),
method: params.id? 'PUT': 'POST',
data: params,
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册