Browse Source

修改customer文件位restful模式 提供示例

pixel 5 years ago
parent
commit
ed6e888470

+ 7 - 7
server/api/v1/exa_customer.go

@@ -17,7 +17,7 @@ import (
 // @Produce application/json
 // @Param data body model.ExaCustomer true "创建客户"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/createExaCustomer [post]
+// @Router /customer/customer [post]
 func CreateExaCustomer(c *gin.Context) {
 	var cu model.ExaCustomer
 	_ = c.ShouldBindJSON(&cu)
@@ -40,7 +40,7 @@ func CreateExaCustomer(c *gin.Context) {
 // @Produce application/json
 // @Param data body model.ExaCustomer true "删除客户"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/deleteExaCustomer [post]
+// @Router /customer/customer [delete]
 func DeleteExaCustomer(c *gin.Context) {
 	var cu model.ExaCustomer
 	_ = c.ShouldBindJSON(&cu)
@@ -59,7 +59,7 @@ func DeleteExaCustomer(c *gin.Context) {
 // @Produce application/json
 // @Param data body model.ExaCustomer true "创建客户"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/updateExaCustomer [post]
+// @Router /customer/customer [put]
 func UpdateExaCustomer(c *gin.Context) {
 	var cu model.ExaCustomer
 	_ = c.ShouldBindJSON(&cu)
@@ -78,10 +78,10 @@ func UpdateExaCustomer(c *gin.Context) {
 // @Produce application/json
 // @Param data body model.ExaCustomer true "获取单一客户信息"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/getExaCustomer [post]
+// @Router /customer/customer [get]
 func GetExaCustomer(c *gin.Context) {
 	var cu model.ExaCustomer
-	_ = c.ShouldBindJSON(&cu)
+	_ = c.ShouldBindQuery(&cu)
 	err, customer := service.GetExaCustomer(cu.ID)
 	if err != nil {
 		response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
@@ -97,12 +97,12 @@ func GetExaCustomer(c *gin.Context) {
 // @Produce application/json
 // @Param data body model.PageInfo true "获取权限客户列表"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/getExaCustomerList [post]
+// @Router /customer/customerList [get]
 func GetExaCustomerList(c *gin.Context) {
 	claims, _ := c.Get("claims")
 	waitUse := claims.(*request.CustomClaims)
 	var pageInfo request.PageInfo
-	_ = c.ShouldBindJSON(&pageInfo)
+	_ = c.ShouldBindQuery(&pageInfo)
 	err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
 	if err != nil {
 		response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)

+ 5 - 5
server/model/exa_customer.go

@@ -6,9 +6,9 @@ import (
 
 type ExaCustomer struct {
 	gorm.Model
-	CustomerName       string  `json:"customerName"`
-	CustomerPhoneData  string  `json:"customerPhoneData"`
-	SysUserID          uint    `json:"sysUserId"`
-	SysUserAuthorityID string  `json:"sysUserAuthorityID"`
-	SysUser            SysUser `json:"sysUser"`
+	CustomerName       string  `json:"customerName" form:"customerName"`
+	CustomerPhoneData  string  `json:"customerPhoneData" form:"customerPhoneData"`
+	SysUserID          uint    `json:"sysUserId" form:"sysUserId"`
+	SysUserAuthorityID string  `json:"sysUserAuthorityID" form:"sysUserAuthorityID"`
+	SysUser            SysUser `json:"sysUser" form:"sysUser"`
 }

+ 3 - 3
server/model/request/common.go

@@ -2,11 +2,11 @@ package request
 
 // Paging common input parameter structure
 type PageInfo struct {
-	Page     int `json:"page"`
-	PageSize int `json:"pageSize"`
+	Page     int `json:"page" form:"page"`
+	PageSize int `json:"pageSize" form:"pageSize"`
 }
 
 // Find by id structure
 type GetById struct {
-	Id float64 `json:"id"`
+	Id float64 `json:"id" form:"id"`
 }

+ 1 - 1
server/resource/rbac_model.conf

@@ -11,4 +11,4 @@ g = _, _
 e = some(where (p.eft == allow))
 
 [matchers]
-m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
+m = r.sub == p.sub && ParamsMatch(r.obj,p.obj) && r.act == p.act

+ 5 - 5
server/router/exp_customer.go

@@ -9,10 +9,10 @@ import (
 func InitCustomerRouter(Router *gin.RouterGroup) {
 	ApiRouter := Router.Group("customer").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
 	{
-		ApiRouter.POST("createExaCustomer", v1.CreateExaCustomer)   // 创建客户
-		ApiRouter.POST("updateExaCustomer", v1.UpdateExaCustomer)   // 更新客户
-		ApiRouter.POST("deleteExaCustomer", v1.DeleteExaCustomer)   // 删除客户
-		ApiRouter.POST("getExaCustomer", v1.GetExaCustomer)         // 获取单一客户信息
-		ApiRouter.POST("getExaCustomerList", v1.GetExaCustomerList) // 获取客户列表
+		ApiRouter.POST("customer", v1.CreateExaCustomer)   // 创建客户
+		ApiRouter.PUT("customer", v1.UpdateExaCustomer)   // 更新客户
+		ApiRouter.DELETE("customer", v1.DeleteExaCustomer)   // 删除客户
+		ApiRouter.GET("customer", v1.GetExaCustomer)         // 获取单一客户信息
+		ApiRouter.GET("customerList", v1.GetExaCustomerList) // 获取客户列表
 	}
 }

+ 4 - 1
server/service/sys_casbin.go

@@ -55,7 +55,10 @@ func  AddCasbin(cm model.CasbinModel) bool {
 // @return                     error
 func  UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
 	var cs []model.CasbinModel
-	err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Update("v1", newPath).Update("v2", newMethod).Error
+	err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Updates(map[string]string{
+		"v1": newPath,
+		"v2": newMethod,
+	}).Error
 	return err
 }
 

+ 18 - 18
web/src/api/customer.js

@@ -7,10 +7,10 @@ import service from '@/utils/request'
 // @Produce application/json
 // @Param data body dbModel.ExaCustomer true "删除客户"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/createExaCustomer [post]
+// @Router /customer/customer [post]
 export const createExaCustomer = (data) => {
     return service({
-        url: "/customer/createExaCustomer",
+        url: "/customer/customer",
         method: 'post',
         data
     })
@@ -25,11 +25,11 @@ export const createExaCustomer = (data) => {
 // @Produce application/json
 // @Param data body dbModel.ExaCustomer true "更新客户信息"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/updateExaCustomer [post]
+// @Router /customer/customer [put]
 export const updateExaCustomer = (data) => {
     return service({
-        url: "/customer/updateExaCustomer",
-        method: 'post',
+        url: "/customer/customer",
+        method: 'put',
         data
     })
 }
@@ -42,11 +42,11 @@ export const updateExaCustomer = (data) => {
 // @Produce application/json
 // @Param data body dbModel.ExaCustomer true "创建客户"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/deleteExaCustomer [post]
+// @Router /customer/customer [delete]
 export const deleteExaCustomer = (data) => {
     return service({
-        url: "/customer/deleteExaCustomer",
-        method: 'post',
+        url: "/customer/customer",
+        method: 'delete',
         data
     })
 }
@@ -59,12 +59,12 @@ export const deleteExaCustomer = (data) => {
 // @Produce application/json
 // @Param data body dbModel.ExaCustomer true "获取单一客户信息"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/getExaCustomer [post]
-export const getExaCustomer = (data) => {
+// @Router /customer/customer [get]
+export const getExaCustomer = (params) => {
     return service({
-        url: "/customer/getExaCustomer",
-        method: 'post',
-        data
+        url: "/customer/customer",
+        method: 'get',
+        params
     })
 }
 
@@ -76,11 +76,11 @@ export const getExaCustomer = (data) => {
 // @Produce application/json
 // @Param data body modelInterface.PageInfo true "获取权限客户列表"
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
-// @Router /customer/createExaCustomer [post]
-export const getExaCustomerList = (data) => {
+// @Router /customer/customerList [get]
+export const getExaCustomerList = (params) => {
     return service({
-        url: "/customer/getExaCustomerList",
-        method: 'post',
-        data
+        url: "/customer/customerList",
+        method: 'get',
+        params
     })
 }

+ 8 - 5
web/src/view/example/customer/customer.vue

@@ -9,7 +9,6 @@
     </div>
     <el-table
       :data="tableData"
-      @selection-change="handleSelectionChange"
       border
       ref="multipleTable"
       stripe
@@ -29,10 +28,10 @@
           <el-popover
           placement="top"
           width="160"
-          v-model="visible">
+          v-model="scope.row.visible">
           <p>确定要删除吗?</p>
           <div style="text-align: right; margin: 0">
-            <el-button size="mini" type="text" @click="visible = false">取消</el-button>
+            <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
             <el-button type="primary" size="mini" @click="deleteCustomer(scope.row)">确定</el-button>
           </div>
           <el-button type="text" size="mini" slot="reference">删除</el-button>
@@ -113,7 +112,7 @@ export default {
   },
   methods:{
     async updateCustomer(row){
-      const res = await getExaCustomer(row)
+      const res = await getExaCustomer({ID:row.ID})
       this.type = "update"
       if(res.code == 0){
         this.form = res.data.customer        
@@ -125,8 +124,12 @@ export default {
     },
     async deleteCustomer(row){
       this.visible = false
-      const res = await deleteExaCustomer(row)
+      const res = await deleteExaCustomer({ID:row.ID})
       if (res.code == 0){
+        this.$message({
+          type:"success",
+          message:"删除成功"
+        })
          this.getTableData()
       }
     },

+ 2 - 0
web/src/view/superAdmin/user/user.vue

@@ -163,6 +163,8 @@ export default {
     const res = await getAuthorityList({ page: 1, pageSize: 999 })
     this.authOptions = res.data.list
   }
+
+  
 }
 </script>
 <style scoped lang="scss">