Browse Source

更改为shouldBindJson 不主动修改 400

pixel 5 years ago
parent
commit
e648dfe7f0

+ 9 - 9
QMPlusServer/controller/api/exa_customer.go

@@ -19,7 +19,7 @@ import (
 // @Router /customer/createExaCustomer [post]
 func CreateExaCustomer(c *gin.Context) {
 	var cu dbModel.ExaCustomer
-	_ = c.BindJSON(&cu)
+	_ = c.ShouldBindJSON(&cu)
 	claims, _ := c.Get("claims")
 	waitUse := claims.(*middleware.CustomClaims)
 	cu.SysUserID = waitUse.ID
@@ -42,7 +42,7 @@ func CreateExaCustomer(c *gin.Context) {
 // @Router /customer/deleteExaCustomer [post]
 func DeleteExaCustomer(c *gin.Context) {
 	var cu dbModel.ExaCustomer
-	_ = c.BindJSON(&cu)
+	_ = c.ShouldBindJSON(&cu)
 	err := cu.DeleteExaCustomer()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
@@ -61,7 +61,7 @@ func DeleteExaCustomer(c *gin.Context) {
 // @Router /customer/updataExaCustomer [post]
 func UpdataExaCustomer(c *gin.Context) {
 	var cu dbModel.ExaCustomer
-	_ = c.BindJSON(&cu)
+	_ = c.ShouldBindJSON(&cu)
 	err := cu.UpdataExaCustomer()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
@@ -80,13 +80,13 @@ func UpdataExaCustomer(c *gin.Context) {
 // @Router /customer/getExaCustomer [post]
 func GetExaCustomer(c *gin.Context) {
 	var cu dbModel.ExaCustomer
-	_ = c.BindJSON(&cu)
-	err,customer := cu.GetExaCustomer()
+	_ = c.ShouldBindJSON(&cu)
+	err, customer := cu.GetExaCustomer()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
 	} else {
 		servers.ReportFormat(c, true, "创建成功", gin.H{
-			"customer":customer,
+			"customer": customer,
 		})
 	}
 }
@@ -105,16 +105,16 @@ func GetExaCustomerList(c *gin.Context) {
 	var cu dbModel.ExaCustomer
 	cu.SysUserAuthorityID = waitUse.AuthorityId
 	var pageInfo modelInterface.PageInfo
-	_ = c.BindJSON(&pageInfo)
+	_ = c.ShouldBindJSON(&pageInfo)
 	err, customerList, total := cu.GetInfoList(pageInfo)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
 	} else {
 		servers.ReportFormat(c, true, "创建成功", gin.H{
-			"customer":customerList,
+			"customer": customerList,
 			"total":    total,
 			"page":     pageInfo.Page,
 			"pageSize": pageInfo.PageSize,
 		})
 	}
-}
+}

+ 1 - 1
QMPlusServer/controller/api/exa_fileUploadAndDownload.go

@@ -85,7 +85,7 @@ func DeleteFile(c *gin.Context) {
 // @Router /fileUploadAndDownload/getFileList [post]
 func GetFileList(c *gin.Context) {
 	var pageInfo modelInterface.PageInfo
-	_ = c.BindJSON(&pageInfo)
+	_ = c.ShouldBindJSON(&pageInfo)
 	err, list, total := new(dbModel.ExaFileUploadAndDownload).GetInfoList(pageInfo)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})

+ 4 - 4
QMPlusServer/controller/api/sys_api.go

@@ -27,7 +27,7 @@ type DeleteApiParams struct {
 // @Router /api/createApi [post]
 func CreateApi(c *gin.Context) {
 	var api sysModel.SysApi
-	_ = c.BindJSON(&api)
+	_ = c.ShouldBindJSON(&api)
 	err := api.CreateApi()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
@@ -46,7 +46,7 @@ func CreateApi(c *gin.Context) {
 // @Router /api/deleteApi [post]
 func DeleteApi(c *gin.Context) {
 	var a sysModel.SysApi
-	_ = c.BindJSON(&a)
+	_ = c.ShouldBindJSON(&a)
 	err := a.DeleteApi()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
@@ -102,7 +102,7 @@ func GetApiList(c *gin.Context) {
 // @Router /api/getApiById [post]
 func GetApiById(c *gin.Context) {
 	var idInfo GetById
-	_ = c.BindJSON(&idInfo)
+	_ = c.ShouldBindJSON(&idInfo)
 	err, api := new(sysModel.SysApi).GetApiById(idInfo.Id)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
@@ -124,7 +124,7 @@ func GetApiById(c *gin.Context) {
 // @Router /api/updataApi [post]
 func UpdataApi(c *gin.Context) {
 	var api sysModel.SysApi
-	_ = c.BindJSON(&api)
+	_ = c.ShouldBindJSON(&api)
 	err := api.UpdataApi()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("修改数据失败,%v", err), gin.H{})

+ 2 - 2
QMPlusServer/controller/api/sys_authority.go

@@ -50,7 +50,7 @@ type DeleteAuthorityPatams struct {
 // @Router /authority/deleteAuthority [post]
 func DeleteAuthority(c *gin.Context) {
 	var a sysModel.SysAuthority
-	_ = c.BindJSON(&a)
+	_ = c.ShouldBindJSON(&a)
 	//删除角色之前需要判断是否有用户正在使用此角色
 	err := a.DeleteAuthority()
 	if err != nil {
@@ -70,7 +70,7 @@ func DeleteAuthority(c *gin.Context) {
 // @Router /authority/getAuthorityList [post]
 func GetAuthorityList(c *gin.Context) {
 	var pageInfo modelInterface.PageInfo
-	_ = c.BindJSON(&pageInfo)
+	_ = c.ShouldBindJSON(&pageInfo)
 	err, list, total := new(sysModel.SysAuthority).GetInfoList(pageInfo)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})

+ 7 - 7
QMPlusServer/controller/api/sys_menu.go

@@ -37,7 +37,7 @@ func GetMenu(c *gin.Context) {
 // @Router /menu/getMenuList [post]
 func GetMenuList(c *gin.Context) {
 	var pageInfo modelInterface.PageInfo
-	_ = c.BindJSON(&pageInfo)
+	_ = c.ShouldBindJSON(&pageInfo)
 	err, menuList, total := new(sysModel.SysBaseMenu).GetInfoList(pageInfo)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
@@ -61,7 +61,7 @@ func GetMenuList(c *gin.Context) {
 // @Router /menu/addBaseMenu [post]
 func AddBaseMenu(c *gin.Context) {
 	var addMenu sysModel.SysBaseMenu
-	_ = c.BindJSON(&addMenu)
+	_ = c.ShouldBindJSON(&addMenu)
 	err := addMenu.AddBaseMenu()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("添加失败,%v", err), gin.H{})
@@ -101,7 +101,7 @@ type AddMenuAuthorityInfo struct {
 // @Router /menu/addMenuAuthority [post]
 func AddMenuAuthority(c *gin.Context) {
 	var addMenuAuthorityInfo AddMenuAuthorityInfo
-	_ = c.BindJSON(&addMenuAuthorityInfo)
+	_ = c.ShouldBindJSON(&addMenuAuthorityInfo)
 	err := new(sysModel.SysMenu).AddMenuAuthority(addMenuAuthorityInfo.Menus, addMenuAuthorityInfo.AuthorityId)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("添加失败,%v", err), gin.H{})
@@ -124,7 +124,7 @@ type AuthorityIdInfo struct {
 // @Router /menu/addMenuAuthority [post]
 func GetMenuAuthority(c *gin.Context) {
 	var authorityIdInfo AuthorityIdInfo
-	_ = c.BindJSON(&authorityIdInfo)
+	_ = c.ShouldBindJSON(&authorityIdInfo)
 	err, menus := new(sysModel.SysMenu).GetMenuAuthority(authorityIdInfo.AuthorityId)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("获取失败:%v", err), gin.H{"menus": menus})
@@ -147,7 +147,7 @@ type IdInfo struct {
 // @Router /menu/deleteBaseMenu [post]
 func DeleteBaseMenu(c *gin.Context) {
 	var idInfo IdInfo
-	_ = c.BindJSON(&idInfo)
+	_ = c.ShouldBindJSON(&idInfo)
 	err := new(sysModel.SysBaseMenu).DeleteBaseMenu(idInfo.Id)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
@@ -166,7 +166,7 @@ func DeleteBaseMenu(c *gin.Context) {
 // @Router /menu/updataBaseMen [post]
 func UpdataBaseMenu(c *gin.Context) {
 	var menu sysModel.SysBaseMenu
-	_ = c.BindJSON(&menu)
+	_ = c.ShouldBindJSON(&menu)
 	err := menu.UpdataBaseMenu()
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("修改失败:%v", err), gin.H{})
@@ -189,7 +189,7 @@ type GetById struct {
 // @Router /menu/getBaseMenuById [post]
 func GetBaseMenuById(c *gin.Context) {
 	var idInfo GetById
-	_ = c.BindJSON(&idInfo)
+	_ = c.ShouldBindJSON(&idInfo)
 	err, menu := new(sysModel.SysBaseMenu).GetBaseMenuById(idInfo.Id)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("查询失败:%v", err), gin.H{})

+ 11 - 11
QMPlusServer/controller/api/sys_user.go

@@ -22,10 +22,10 @@ var (
 )
 
 type RegistAndLoginStuct struct {
-	Username string `json:"username"`
-	Password string `json:"password"`
-	Captcha  string `json:"captcha"`
-	CaptchaId  string `json:"captchaId"`
+	Username  string `json:"username"`
+	Password  string `json:"password"`
+	Captcha   string `json:"captcha"`
+	CaptchaId string `json:"captchaId"`
 }
 
 type RegestStuct struct {
@@ -44,7 +44,7 @@ type RegestStuct struct {
 // @Router /base/regist [post]
 func Regist(c *gin.Context) {
 	var R RegestStuct
-	_ = c.BindJSON(&R)
+	_ = c.ShouldBindJSON(&R)
 	user := &sysModel.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId}
 	err, user := user.Regist()
 	if err != nil {
@@ -66,15 +66,15 @@ func Regist(c *gin.Context) {
 // @Router /base/login [post]
 func Login(c *gin.Context) {
 	var L RegistAndLoginStuct
-	_ = c.BindJSON(&L)
-	if captcha.VerifyString(L.CaptchaId,L.Captcha) {
+	_ = c.ShouldBindJSON(&L)
+	if captcha.VerifyString(L.CaptchaId, L.Captcha) {
 		U := &sysModel.SysUser{Username: L.Username, Password: L.Password}
 		if err, user := U.Login(); err != nil {
 			servers.ReportFormat(c, false, fmt.Sprintf("用户名密码错误或%v", err), gin.H{})
 		} else {
 			tokenNext(c, *user)
 		}
-	}else{
+	} else {
 		servers.ReportFormat(c, false, "验证码错误", gin.H{})
 	}
 
@@ -149,7 +149,7 @@ type ChangePasswordStutrc struct {
 // @Router /user/changePassword [post]
 func ChangePassword(c *gin.Context) {
 	var params ChangePasswordStutrc
-	_ = c.BindJSON(&params)
+	_ = c.ShouldBindJSON(&params)
 	U := &sysModel.SysUser{Username: params.Username, Password: params.Password}
 	if err, _ := U.ChangePassword(params.NewPassword); err != nil {
 		servers.ReportFormat(c, false, "修改失败,请检查用户名密码", gin.H{})
@@ -208,7 +208,7 @@ func UploadHeaderImg(c *gin.Context) {
 // @Router /user/getUserList [post]
 func GetUserList(c *gin.Context) {
 	var pageInfo modelInterface.PageInfo
-	_ = c.BindJSON(&pageInfo)
+	_ = c.ShouldBindJSON(&pageInfo)
 	err, list, total := new(sysModel.SysUser).GetInfoList(pageInfo)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
@@ -237,7 +237,7 @@ type SetUserAuth struct {
 // @Router /user/setUserAuthority [post]
 func SetUserAuthority(c *gin.Context) {
 	var sua SetUserAuth
-	_ = c.BindJSON(&sua)
+	_ = c.ShouldBindJSON(&sua)
 	err := new(sysModel.SysUser).SetUserAuthority(sua.UUID, sua.AuthorityId)
 	if err != nil {
 		servers.ReportFormat(c, false, fmt.Sprintf("修改失败,%v", err), gin.H{})

+ 1 - 1
QMPlusVuePage/src/view/login/login.vue

@@ -20,7 +20,7 @@
           <el-input
             v-model="loginForm.captcha"
             name="logVerify"
-            placeholder="请输入验证码"
+            placeholder="请输入验证码(测试环境有问题可不输入 本地搭建环境可用)"
             maxlength="10"
           />
           <img :src="path + picPath" alt="请输入验证码" @click="loginVefify()" class="vPic">