瀏覽代碼

科室新增删除对clerk,role操作,优化ag-grid中按钮的显示

wuyunfeng 4 年之前
父節點
當前提交
ddd878c6d3

+ 2 - 3
src/api/role.js

@@ -12,14 +12,13 @@ export function getRoleList(part_id) {
   })
 }
 
-
 /**
  * 删除角色
  * @param id
  */
 export function deleteRole(id) {
   return request({
-    url: `admin/systems/roles/${id}`,
+    url: `/mgr/role/${id}`,
     method: 'delete'
   })
 }
@@ -41,7 +40,7 @@ export function getRolePermission(id) {
  */
 export function addRole(params) {
   return request({
-    url: 'admin/systems/roles',
+    url: '/mgr/role',
     method: 'post',
     headers: { 'Content-Type': 'application/json' },
     data: params

+ 7 - 3
src/components/AgGridCellRender/ButtonCellRender.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <el-button :type="buttonType" :size="buttonSize" @click="buttonClick">{{ label }}</el-button>
+    <el-button :type="buttonType" :size="buttonSize" :disabled="disabled" @click="buttonClick">{{ label }}</el-button>
   </div>
 </template>
 
@@ -11,13 +11,14 @@ export default {
     return {
       buttonType: 'primary',
       buttonSize: 'mini',
-      label: 'button'
+      label: 'button',
+      disabled: false
     }
   },
   beforeMount() {
   },
   mounted() {
-    const { buttonType, buttonSize, label } = this.params
+    const { buttonType, buttonSize, label, disabled } = this.params
     if (buttonType) {
       this.buttonType = buttonType
     }
@@ -27,6 +28,9 @@ export default {
     if (label) {
       this.label = label
     }
+    if (disabled !== undefined) {
+      this.disabled = disabled
+    }
   },
   methods: {
     buttonClick() {

文件差異過大導致無法顯示
+ 1 - 0
src/icons/svg/authen.svg


文件差異過大導致無法顯示
+ 1 - 0
src/icons/svg/function.svg


+ 2 - 2
src/router/index.js

@@ -278,7 +278,7 @@ export const adminRoutes = [
         path: 'index',
         component: () => import('@/views/ncs-menu/menuManager'),
         name: 'menuSetting',
-        meta: { title: '菜单管理', icon: 'tree', noCache: true }
+        meta: { title: '菜单管理', icon: 'function', noCache: true }
       }
     ]
   },
@@ -302,7 +302,7 @@ export const adminRoutes = [
         path: 'index',
         component: () => import('@/views/ncs-auth/superadmin/defaultRoleManager'),
         name: 'rolemanager',
-        meta: { title: '角色功能', icon: 'tree', noCache: true }
+        meta: { title: '角色功能', icon: 'authen', noCache: true }
       }
     ]
   },

+ 8 - 4
src/views/ncs-auth/compontents/roleEdit.vue

@@ -169,16 +169,20 @@ export default {
             shop_id: -1
           }
           this.role_id === 0
-            ? API_Auth.addRole(params).then(() => saveSuccess())
-            : API_Auth.editRole(this.role_id, params).then(() => saveSuccess())
-          const saveSuccess = () => {
+            ? API_Auth.addRole(params).then((response) => saveSuccess(response)).catch(err => {
+              this.$message.error(err)
+            })
+            : API_Auth.editRole(this.role_id, params).then((response) => saveSuccess(response)).catch(err => {
+              this.$message.error(err)
+            })
+          const saveSuccess = (response) => {
             this.$message.success('保存成功!')
             // this.$route.params.callback()
             // this.$store.dispatch('delCurrentViews', {
             //   view: this.$route,
             //   $router: this.$router
             // })
-            this.$emit('aftersave')
+            this.$emit('aftersave', response)
           }
         } else {
           this.$message.error('表单填写有误,请检查!')

+ 49 - 5
src/views/ncs-auth/superadmin/defaultRoleManager.vue

@@ -18,6 +18,10 @@
         </el-table>
       </el-aside>
       <el-main>
+        <el-header style="text-align: right; font-size: 12px;height: 30px">
+          <el-button type="primary" size="mini" @click="createRole">新建角色</el-button>
+          <el-button type="danger" size="mini" @click="deleteRole">删除角色</el-button>
+        </el-header>
         <role-edit :role_id="role_id" @aftersave="getRoleList" />
       </el-main>
     </el-container>
@@ -48,15 +52,20 @@ export default {
     this.getRoleList()
   },
   methods: {
-    getRoleList() {
+    getRoleList(response) { // roleEdit 保存成功时回调会传入当前role实体,新增时需要根据当前role选择新添加的角色
       API_Auth.getRoleList(-1).then(res => {
         this.tableData = [...res]
         this.$nextTick(() => {
-          if (this.role_id === 0) { // 初始加载角色列表
-            this.$refs.roleTable.setCurrentRow(this.tableData[0])
-            this.role_id = this.tableData[0].role_id
+          if (!response) {
+            if (this.role_id === 0) { // 初始加载角色列表
+              this.$refs.roleTable.setCurrentRow(this.tableData[0])
+              this.role_id = this.tableData[0].role_id
+            } else {
+              const index = this.tableData.findIndex(p => p.role_id === this.role_id)
+              this.$refs.roleTable.setCurrentRow(this.tableData[index])
+            }
           } else {
-            const index = this.tableData.findIndex(p => p.role_id === this.role_id)
+            const index = this.tableData.findIndex(p => p.role_id === response.role_id)
             this.$refs.roleTable.setCurrentRow(this.tableData[index])
           }
         })
@@ -68,6 +77,41 @@ export default {
        */
     rowClick(row) {
       this.role_id = row.role_id
+    },
+    /** 创建新角色,role_id 设置为0,传入roleEdit组件 **/
+    createRole() {
+      this.role_id = 0
+    },
+    deleteRole() {
+      if (this.role_id === 0) {
+        this.$message.error('没有选中任何角色!')
+      }
+      this.$confirm('删除操作后数据不可复原,您确定要删除此数据?', '警告', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        API_Auth.deleteRole(this.role_id).then(
+          response => {
+            this.role_id = 0
+            this.getRoleList()
+            this.$message({
+              type: 'success',
+              message: '删除成功!'
+            })
+          }
+        ).catch(response => {
+          this.$message({
+            type: 'error',
+            message: response
+          })
+        })
+      }).catch(() => {
+        this.$message({
+          type: 'info',
+          message: '已取消删除'
+        })
+      })
     }
   }
 }

+ 21 - 7
src/views/ncs-orginazition/index.vue

@@ -150,7 +150,8 @@ export default {
       columnApi: null,
       localeText: AG_GRID_LOCALE_CN,
       filterState: null,
-      rowSelection: null
+      rowSelection: null,
+      frameworkComponents: null
     }
   },
   computed: {
@@ -221,11 +222,14 @@ export default {
         sortable: false },
       { headerName: '删除', field: 'shop_id',
         cellRendererFramework: 'ButtonCellRender',
-        cellRendererParams: {
-          onClick: this.deleteSingle,
-          label: '删除',
-          buttonType: 'danger',
-          buttonSize: 'mini'
+        cellRendererParams: param => {
+          return {
+            onClick: this.deleteSingle,
+            label: '删除',
+            buttonType: 'danger',
+            buttonSize: 'mini',
+            disabled: param.data['member_name'] === 'superadmin' ? true:false
+          }
         },
         pinned: 'right',
         lockPinned: true,
@@ -251,6 +255,16 @@ export default {
   mounted() {
     this.gridApi = this.gridOptions.api
     this.gridColumnApi = this.gridOptions.columnApi
+    // 设置默认排序字段,应用列状态之后会触发 gridSortChange 函数,会调用getlist,后面不需要再调用this.getlist
+    this.gridColumnApi.applyColumnState({
+      state: [
+        {
+          colId: 'shop_id',
+          sort: 'asc'
+        }
+      ]
+    })
+
     // var column = this.gridColumnApi.getColumn('id')
     // const _this = this
     // column.addEventListener('sortChanged', function(event) {
@@ -267,7 +281,7 @@ export default {
     //   // event.columnApi.applyColumnState({ defaultState: { sort: null }})
     //   // console.log('Column visibility changed', event)
     // })
-    this.getList()
+    // this.getList()
   },
   methods: {
     handlerDelete(ids) {