Просмотр исходного кода

修改编辑方法逻辑,前端细节调整

pixel 5 лет назад
Родитель
Сommit
474e07b863

+ 10 - 6
server/service/sys_api.go

@@ -30,7 +30,7 @@ func CreateApi(a model.SysApi) (err error) {
 // @return                    error
 func DeleteApi(a model.SysApi) (err error) {
 	err = global.GVA_DB.Delete(a).Error
-	ClearCasbin(1, a.Path)
+	ClearCasbin(1, a.Path,a.Method)
 	return err
 }
 
@@ -111,15 +111,19 @@ func GetApiById(id float64) (err error, api model.SysApi) {
 // @return                    error
 func UpdateApi(a model.SysApi) (err error) {
 	var oldA model.SysApi
-	flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound()
-	if !flag {
-		return errors.New("存在相同api路径")
-	}
+
 	err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error
+
+	if oldA.Path != a.Path || oldA.Method != a.Method{
+		flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound()
+		if !flag {
+			return errors.New("存在相同api路径")
+		}
+	}
 	if err != nil {
 		return err
 	} else {
-		err = UpdateCasbinApi(oldA.Path, a.Path)
+		err = UpdateCasbinApi(oldA.Path, a.Path,oldA.Method,a.Method)
 		if err != nil {
 			return err
 		} else {

+ 4 - 4
server/service/sys_casbin.go

@@ -51,9 +51,9 @@ func  AddCasbin(cm model.CasbinModel) bool {
 // @param     oldPath          string
 // @param     newPath          string
 // @return                     error
-func  UpdateCasbinApi(oldPath string, newPath string) 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 = ?", oldPath).Find(&cs).Update("v1", newPath).Error
+	err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Update("v1", newPath).Update("v2", newMethod).Error
 	return err
 }
 
@@ -78,9 +78,9 @@ func  GetPolicyPathByAuthorityId(authorityId string) []string {
 // @param     v               int
 // @param     p               string
 // @return                    bool
-func  ClearCasbin(v int, p string) bool {
+func  ClearCasbin(v int, p ...string) bool {
 	e := Casbin()
-	return e.RemoveFilteredPolicy(v, p)
+	return e.RemoveFilteredPolicy(v, p...)
 
 }
 

+ 28 - 15
web/src/view/superAdmin/api/api.vue

@@ -8,8 +8,8 @@
         <el-form-item label="描述">
           <el-input placeholder="描述" v-model="searchInfo.description"></el-input>
         </el-form-item>
-         <el-form-item label="请求">
-               <el-select placeholder="请选择" clearable v-model="searchInfo.method">
+        <el-form-item label="请求">
+          <el-select clearable placeholder="请选择" v-model="searchInfo.method">
             <el-option
               :key="item.value"
               :label="`${item.label}(${item.value})`"
@@ -26,12 +26,12 @@
         </el-form-item>
       </el-form>
     </div>
-    <el-table @sort-change="sortChange" :data="tableData" border stripe>
-      <el-table-column sortable="custom" label="id" min-width="60" prop="ID"></el-table-column>
-      <el-table-column sortable="custom" label="api路径" min-width="150" prop="path"></el-table-column>
-      <el-table-column sortable="custom" label="api分组" min-width="150" prop="apiGroup"></el-table-column>
-      <el-table-column sortable="custom" label="api简介" min-width="150" prop="description"></el-table-column>
-      <el-table-column sortable="custom" label="请求" min-width="150" prop="method">
+    <el-table :data="tableData" @sort-change="sortChange" border stripe>
+      <el-table-column label="id" min-width="60" prop="ID" sortable="custom"></el-table-column>
+      <el-table-column label="api路径" min-width="150" prop="path" sortable="custom"></el-table-column>
+      <el-table-column label="api分组" min-width="150" prop="apiGroup" sortable="custom"></el-table-column>
+      <el-table-column label="api简介" min-width="150" prop="description" sortable="custom"></el-table-column>
+      <el-table-column label="请求" min-width="150" prop="method" sortable="custom">
         <template slot-scope="scope">
           <div>
             {{scope.row.method}}
@@ -64,7 +64,7 @@
       layout="total, sizes, prev, pager, next, jumper"
     ></el-pagination>
 
-    <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="新增Api">
+    <el-dialog :before-close="closeDialog" :title="dialogTitle" :visible.sync="dialogFormVisible">
       <el-form :inline="true" :model="form" :rules="rules" label-width="80px" ref="apiForm">
         <el-form-item label="路径" prop="path">
           <el-input autocomplete="off" v-model="form.path"></el-input>
@@ -107,7 +107,7 @@ import {
   deleteApi
 } from '@/api/api'
 import infoList from '@/components/mixins/infoList'
-import {toSQLLine} from '@/utils/stringFun'
+import { toSQLLine } from '@/utils/stringFun'
 const methodOptions = [
   {
     value: 'POST',
@@ -138,6 +138,7 @@ export default {
     return {
       listApi: getApiList,
       dialogFormVisible: false,
+      dialogTitle: '新增Api',
       form: {
         path: '',
         apiGroup: '',
@@ -148,7 +149,9 @@ export default {
       type: '',
       rules: {
         path: [{ required: true, message: '请输入api路径', trigger: 'blur' }],
-        apiGroup: [{ required: true, message: '请输入组名称', trigger: 'blur' }],
+        apiGroup: [
+          { required: true, message: '请输入组名称', trigger: 'blur' }
+        ],
         method: [
           { required: true, message: '请选择请求方式', trigger: 'blur' }
         ],
@@ -160,12 +163,12 @@ export default {
   },
   methods: {
     // 排序
-    sortChange({prop,order}){
-      if(prop){
+    sortChange({ prop, order }) {
+      if (prop) {
         this.searchInfo.orderKey = toSQLLine(prop)
-        this.searchInfo.desc = order=="descending"
+        this.searchInfo.desc = order == 'descending'
       }
-     this.getTableData()
+      this.getTableData()
     },
     //条件搜索前端看此方法
     onSubmit() {
@@ -181,6 +184,16 @@ export default {
       this.dialogFormVisible = false
     },
     openDialog(type) {
+      switch (type) {
+        case 'addApi':
+          this.dialogTitlethis = '新增Api'
+          break
+        case 'edit':
+          this.dialogTitlethis = '编辑Api'
+          break
+        default:
+          break
+      }
       this.type = type
       this.dialogFormVisible = true
     },

+ 2 - 1
web/src/view/superAdmin/authority/authority.vue

@@ -22,7 +22,7 @@
       </el-table-column>
     </el-table>
     <!-- 新增角色弹窗 -->
-    <el-dialog :visible.sync="dialogFormVisible" title="新增角色">
+    <el-dialog :visible.sync="dialogFormVisible" :title="dialogTitle">
       <el-form :model="form" :rules="rules" ref="authorityForm">
         <el-form-item label="父级角色ID" prop="parentId">
           <el-input autocomplete="off" disabled v-model="form.parentId"></el-input>
@@ -79,6 +79,7 @@ export default {
       drawer: false,
       activeRow: {},
       activeUserId: 0,
+      dialogTitle:"新增角色",
       dialogFormVisible: false,
       apiDialogFlag: false,
       form: {

+ 4 - 1
web/src/view/superAdmin/menu/menu.vue

@@ -35,7 +35,7 @@
       </el-table-column>
     </el-table>
 
-    <el-dialog :before-close="handleClose" :visible.sync="dialogFormVisible" title="新增菜单">
+    <el-dialog :before-close="handleClose" :visible.sync="dialogFormVisible" :title="dialogTitle">
       <el-form :inline="true" :model="form" :rules="rules" label-width="85px" ref="menuForm">
         <el-form-item label="路由name" prop="path">
           <el-input autocomplete="off" placeholder="唯一英文字符串" v-model="form.path"></el-input>
@@ -89,6 +89,7 @@ export default {
     return {
       listApi: getMenuList,
       dialogFormVisible: false,
+      dialogTitle:"新增菜单",
       form: {
         ID: 0,
         path: '',
@@ -198,12 +199,14 @@ export default {
     },
     // 添加菜单方法,id为 0则为添加根菜单
     addMenu(id) {
+      this.dialogTitle = "新增菜单"
       this.form.parentId = String(id)
       this.isEdit = false
       this.dialogFormVisible = true
     },
     // 修改菜单方法
     async editMenu(id) {
+      this.dialogTitle = "编辑菜单"
       const res = await getBaseMenuById({ id })
       this.form = res.data.menu
       this.dialogFormVisible = true