Ver código fonte

用户管理

zhengnaiwen_citu 7 meses atrás
pai
commit
add632b345

+ 4 - 4
src/components/AutoComponents/MForm/index.vue

@@ -39,7 +39,7 @@
           <el-input-number v-bind="item.options" v-on="item.handles" v-model="query[item.prop]"></el-input-number>
         </template>
         <template v-if="item.type === 'select'">
-          <el-select v-bind="item.options" v-on="item.handles" v-model="query[item.prop]" placeholder="请选择">
+          <el-select v-bind="item.options" v-on="item.handles" v-model="query[item.prop]">
             <template v-for="slot in item.slots" :slot="slot">
               <slot :name="`${item.prop}.${slot}`"></slot>
             </template>
@@ -61,15 +61,15 @@
               <el-option
                 v-for="_item in item.options.items"
                 :key="_item.label"
-                :label="_item.label"
-                :value="_item.value"
+                :label="_item[item.options.labelText ?? _item.label]"
+                :value="_item[item.options.labelValue ?? _item.value]"
                 :disable="_item.disable"
               ></el-option>
             </template>
           </el-select>
         </template>
         <template v-if="item.type === 'radioGroup'">
-          <el-radio-group v-model="query[item.prop]" v-bind="item.options">
+          <el-radio-group v-model="query[item.prop]" v-bind="item.options" v-on="item.handles">
             <template v-if="item.button">
               <el-radio-button
                 v-for="_item in item.options.items"

+ 4 - 1
src/views/humanResources/welfare/welfareList.vue

@@ -14,6 +14,9 @@
       :page-current="pageInfo.current"
       @page-change="onPageChange"
     >
+      <template #title="{ row }">
+        {{ row.subsidyPersonnelCategory?.title ?? '找不到该项福利' }}
+      </template>
       <template #actions="{ row }">
         <m-button text type="primary" size="small" @click="onEdit(row)">编辑</m-button>
         <m-button text type="danger" size="small" @click="onDelete(row)">删除</m-button>
@@ -48,7 +51,7 @@ export default {
         },
         {
           label: '福利类别',
-          prop: 'subsidyPersonnelCategoryId'
+          prop: 'title'
         },
         {
           label: '金额(元 / 月)',

+ 1 - 1
src/views/humanResources/welfare/welfareListEdit.vue

@@ -107,7 +107,7 @@ export default {
       try {
         const { data } = await getWelfareCategoryPage({
           page: {
-            size: 9999,
+            size: 50,
             current: 1
           },
           entity: {

+ 63 - 2
src/views/humanResources/welfare/welfareType.vue

@@ -1,12 +1,73 @@
 <template>
   <div>
-
+    <m-search :items="searchItems" v-model="searchValues" class="mb-3" @search="onSearch">
+      <template #button>
+        <m-button type="primary" icon="el-icon-plus" @click="onAdd">新增</m-button>
+      </template>
+    </m-search>
+    <m-table
+      :headers="headers"
+      :items="items"
+      :page-size="pageInfo.size"
+      :total="total"
+      :page-current="pageInfo.current"
+      v-loading="loading"
+      @page-change="onPageChange"
+    ></m-table>
   </div>
 </template>
 
 <script>
 export default {
-  name: 'welfare-type'
+  name: 'welfare-type',
+  data () {
+    return {
+      searchItems: [
+        {
+          label: '类型/描述',
+          type: 'input',
+          prop: 'welfareType',
+          option: {
+            placeholder: '请输入福利类型 / 描述'
+          }
+        }
+      ],
+      searchValues: {
+        welfareType: ''
+      },
+      headers: [
+        {
+          label: '福利类型',
+          prop: 'welfareType'
+        },
+        {
+          label: '描述',
+          prop: 'description'
+        },
+        {
+          label: '操作',
+          prop: 'action',
+          width: 200
+        }
+      ],
+      items: [],
+      pageInfo: {
+        current: 1,
+        size: 10
+      },
+      total: 0,
+      loading: false
+    }
+  },
+  created () {
+    this.onInit()
+  },
+  methods: {
+    onInit () {},
+    onAdd () {},
+    onSearch () {},
+    onPageChange () {}
+  }
 }
 </script>
 

+ 18 - 233
src/views/system/user/index.vue

@@ -42,6 +42,9 @@
       </template>
       <template #actions="scope">
         <template v-if="scope.row.companyInfo?.homeUserId !== scope.row.id">
+          <m-button type="primary" class="pa-0" text @click="onEdit(scope.row)">编辑</m-button>
+          <m-button type="primary" class="pa-0" text @click="onSetRole(scope.row)">角色分配</m-button>
+          <m-button type="warning" class="pa-0" text @click="onReset(scope.row)">重置密码</m-button>
           <m-button
             :type="scope.row.state ? 'success' : 'danger'"
             class="pa-0"
@@ -50,47 +53,36 @@
           >
             {{ scope.row.state ? '启用' : '禁用' }}
           </m-button>
-          <m-button type="primary" class="pa-0" text @click="onEdit(scope.row)">编辑</m-button>
-          <m-button type="primary" class="pa-0" text @click="onSetRole(scope.row)">角色分配</m-button>
-          <m-button type="warning" class="pa-0" text @click="onReset(scope.row)">重置密码</m-button>
           <m-button type="danger" class="pa-0" text @click="onDelete(scope.row)">删除</m-button>
         </template>
       </template>
     </MTable>
-    <MDialog ref="dialog" :title="itemData.id ? '编辑用户' : '新增用户'" @sure="handleSave">
-      <MForm ref="userForm" :items="userFormItems" v-model="userFormValue"></MForm>
-    </MDialog>
-    <MDialog ref="role" title="角色分配" @sure="handleSaveRole">
-      <MForm ref="roleForm" :items="roleFormItems" v-model="roleFormValue">
-        <template #username>
-          <el-tag>{{ itemData.username }}</el-tag>
-        </template>
-        <template #name>
-          <el-tag>{{ itemData.name }}</el-tag>
-        </template>
-      </MForm>
-    </MDialog>
-    <MDialog ref="password" title="重置密码" @sure="handleSavePassword">
-      <MForm ref="passwordForm" :items="passwordFormItems" v-model="passwordFormValue"></MForm>
-    </MDialog>
+    <UserEdit ref="dialog" @refresh="init"></UserEdit>
+    <UserRole ref="userRefs" @refresh="init"></UserRole>
+    <UserReset ref="userReset" @refresh="init"></UserReset>
   </div>
 </template>
 
 <script>
+import UserEdit from './userEdit.vue'
+import UserRole from './userRole.vue'
+import UserReset from './userReset'
 import util from '@/utils/base64ToFile'
 import {
   getUserList,
-  saveUser,
   deleteUser,
-  resetPassword,
   downloadUserTemplate,
   userExcelExport,
   blockUser
 } from '@/api/user'
-import { getRoleList } from '@/api/menu'
 import { dateFormat } from '@/utils/date'
 export default {
   name: 'user-list',
+  components: {
+    UserEdit,
+    UserRole,
+    UserReset
+  },
   data () {
     return {
       searchItems: [
@@ -106,15 +98,6 @@ export default {
       searchValues: {
         searchKey: null
       },
-      roleFormValue: {
-        roleId: null
-      },
-      userFormValue: {
-        type: 1
-      },
-      passwordFormValue: {
-        newPwd: null
-      },
       headers: [
         { label: '用户昵称', prop: 'name', width: 200 },
         { label: '账号', prop: 'username', width: 200 },
@@ -132,124 +115,12 @@ export default {
         size: 10
       },
       loading: false,
-      itemData: {},
       showReset: false,
       show: false,
-      roleList: [],
       uploadLoading: false
     }
   },
-  computed: {
-    passwordFormItems () {
-      return [
-        {
-          label: '新密码',
-          prop: 'newPwd',
-          type: 'input',
-          options: {
-            showPassword: true,
-            placeholder: '请输入新密码'
-          },
-          rules: [
-            { required: true, message: '请输入密码', trigger: 'change' }
-          ]
-        }
-      ]
-    },
-    roleFormItems () {
-      return [
-        {
-          label: '用户名称',
-          prop: 'username'
-        },
-        {
-          label: '用户昵称',
-          prop: 'name'
-        },
-        {
-          label: '角色',
-          prop: 'roleId',
-          type: 'select',
-          options: {
-            multiple: true,
-            items: this.roleList.map(e => {
-              return {
-                label: e.roleName,
-                value: e.id
-              }
-            })
-          },
-          rules: [
-            { required: true, message: '请选择角色', trigger: 'change' }
-          ]
-        }
-      ]
-    },
-    userFormItems () {
-      const hidden = this.userFormValue.type === 2
-      return [
-        {
-          label: '账户类型',
-          prop: 'type',
-          type: 'radioGroup',
-          options: {
-            items: [
-              { text: '统一认证号用户', label: 1 },
-              { text: '系统普通用户', label: 2 }
-            ]
-          },
-          rules: [
-            { required: true, message: '请选择账户类型', trigger: 'blur' }
-          ]
-        },
-        {
-          label: !hidden ? '统一认证号' : '用户账号',
-          prop: 'username',
-          type: 'input',
-          options: {
-            placeholder: '请输入' + (!hidden ? '统一认证号' : '用户账号')
-          },
-          rules: [
-            { required: true, message: `请输入${!hidden ? '统一认证号' : '用户账号'}`, trigger: 'blur' }
-          ]
-        },
-        {
-          label: '用户昵称',
-          prop: 'name',
-          type: 'input',
-          options: {
-            placeholder: '请输入用户昵称'
-          },
-          rules: [
-            { required: true, message: '请输入用户昵称', trigger: 'blur' }
-          ]
-        },
-        {
-          label: '用户密码',
-          prop: 'password',
-          type: 'input',
-          options: {
-            showPassword: true,
-            placeholder: '请输入用户密码'
-          },
-          hidden: !hidden || this.itemData.id,
-          rules: [
-            { required: true, message: '请输入用户密码', trigger: 'blur' }
-          ]
-        },
-        {
-          label: '用户邮箱',
-          prop: 'email',
-          type: 'input',
-          options: {
-            placeholder: '请输入用户邮箱'
-          }
-        }
-      ]
-    }
-  },
   async created () {
-    await this.initDice()
     await this.init()
   },
   methods: {
@@ -273,28 +144,6 @@ export default {
       this.pageInfo.current = 1
       this.init()
     },
-    async initDice () {
-      try {
-        const { data } = await getRoleList({ size: 999 })
-        this.roleList = data.records
-      } catch (error) {
-        this.$message.error(error)
-      }
-    },
-    async onSave (query) {
-      try {
-        await saveUser({
-          id: this.itemData?.id,
-          tenantCode: this.itemData.tenantCode,
-          ...query
-        })
-        this.$message.success('保存成功')
-        this.init()
-        return true
-      } catch (error) {
-        this.$message.error(error)
-      }
-    },
     async onStatus (item) {
       const state = item.state ? 1 : 0
       try {
@@ -309,34 +158,16 @@ export default {
       }
     },
     onEdit (item) {
-      this.itemData = item
-      this.userFormValue = {
-        type: item.password ? 2 : 1,
-        username: item.username,
-        name: item.name,
-        email: item.email
-      }
-      this.$refs.dialog.open()
+      this.$refs.dialog.open(item)
     },
     onAdd () {
-      this.itemData = {}
-      this.userFormValue = {
-        type: 1
-      }
       this.$refs.dialog.open()
     },
     onSetRole (item) {
-      this.itemData = item
-      console.log(item.roleId.length)
-      this.roleFormValue = {
-        roleId: item.roleId ? item.roleId.split(',').map(e => +e) : []
-      }
-      this.$refs.role.open()
+      this.$refs.userRefs.open(item)
     },
     onReset (item) {
-      this.itemData = item
-      this.passwordFormValue.newPwd = null
-      this.$refs.password.open()
+      this.$refs.userReset.open(item)
     },
     onDelete (item) {
       this.$confirm('是否确定删除该选项', '提示', {
@@ -355,53 +186,7 @@ export default {
         })
         .catch(_ => {})
     },
-    async handleSave () {
-      this.$refs.userForm.validate(async valid => {
-        if (!valid) {
-          return
-        }
-        const { type, ...obj } = this.userFormValue
-        const check = await this.onSave({
-          ...obj,
-          state: 0,
-          roleId: ''
-        })
-        check && this.$refs.dialog.close()
-      })
-    },
-    async handleSaveRole () {
-      this.$refs.roleForm.validate(async valid => {
-        if (!valid) {
-          return
-        }
-        const check = await this.onSave({
-          roleId: this.roleFormValue.roleId.toString()
-        })
-        check && this.$refs.role.close()
-      })
-    },
-    async handleSavePassword () {
-      this.$refs.passwordForm.validate(async valid => {
-        if (!valid) {
-          return
-        }
-        const companyCode = this.itemData.companyInfo?.companyCode
-        const userId = this.itemData.id
-        const param = {
-          type: 1,
-          userId,
-          companyCode,
-          ...this.passwordFormValue
-        }
-        try {
-          await resetPassword(param)
-          this.$refs.password.close()
-          this.$message.success('修改成功')
-        } catch (error) {
-          this.$message.error(error)
-        }
-      })
-    },
+
     handlePageChange (page) {
       this.pageInfo.current = page
       this.init()

+ 194 - 0
src/views/system/user/userEdit.vue

@@ -0,0 +1,194 @@
+<template>
+  <MDialog ref="dialog" :title="userFormValue.id ? '编辑用户' : '新增用户'" @sure="handleSave">
+    <MForm ref="userForm" :items="userFormItems" v-model="userFormValue"></MForm>
+  </MDialog>
+</template>
+
+<script>
+import {
+  saveUser
+} from '@/api/user'
+import {
+  getRosterList
+} from '@/api/system'
+export default {
+  name: 'user-edit',
+  data () {
+    return {
+      userFormValue: {
+        type: 1
+      },
+      loading: false,
+      items: []
+    }
+  },
+  computed: {
+    userFormItems () {
+      const hidden = this.userFormValue.type === 2
+      return [
+        {
+          label: '账户类型',
+          prop: 'type',
+          type: 'radioGroup',
+          handles: {
+            change: this.handleType
+          },
+          options: {
+            items: [
+              { text: '统一认证号用户', label: 1 },
+              { text: '系统普通用户', label: 2 }
+            ]
+          },
+          rules: [
+            { required: true, message: '请选择账户类型', trigger: 'blur' }
+          ]
+        },
+        {
+          label: !hidden ? '统一认证号' : '用户账号',
+          prop: 'username',
+          type: 'input',
+          options: {
+            placeholder: '请输入' + (!hidden ? '统一认证号' : '用户账号')
+          },
+          rules: [
+            { required: true, message: `请输入${!hidden ? '统一认证号' : '用户账号'}`, trigger: 'blur' }
+          ]
+        },
+        {
+          label: '用户昵称',
+          prop: 'name',
+          type: 'input',
+          options: {
+            placeholder: '请输入用户昵称'
+          },
+          rules: [
+            { required: true, message: '请输入用户昵称', trigger: 'blur' }
+          ]
+        },
+        {
+          label: '用户密码',
+          prop: 'password',
+          type: 'input',
+          options: {
+            showPassword: true,
+            placeholder: '请输入用户密码'
+          },
+          hidden: !hidden || this.userFormValue.id,
+          rules: [
+            { required: true, message: '请输入用户密码', trigger: 'blur' }
+          ]
+        },
+        {
+          label: '用户邮箱',
+          prop: 'email',
+          type: 'input',
+          options: {
+            placeholder: '请输入用户邮箱'
+          }
+        },
+        {
+          label: '绑定员工',
+          prop: 'employeeCode',
+          type: 'select',
+          hidden: !hidden,
+          options: {
+            placeholder: '请选择绑定员工',
+            filterable: true,
+            remote: true,
+            labelText: 'employeeName',
+            labelValue: 'personnelCode',
+            remoteMethod: this.remoteMethod,
+            valueKey: 'personnelCode',
+            defaultFirstOption: true,
+            loading: this.loading,
+            items: this.items
+          },
+          rules: [
+            { required: true, message: '请选择绑定员工', trigger: 'change' }
+          ]
+        }
+      ]
+    }
+  },
+  methods: {
+    async open (item) {
+      if (!item) {
+        this.items = []
+        this.userFormValue = {
+          id: undefined,
+          tenantCode: undefined,
+          type: 1,
+          username: null,
+          name: null,
+          email: null,
+          employeeCode: null
+        }
+        this.$refs.dialog.open()
+        return
+      }
+      try {
+        const { data } = await getRosterList({ entity: { personnelCode: item.employeeCode } })
+        this.items = data.records
+        this.userFormValue = {
+          id: item.id,
+          tenantCode: item.tenantCode,
+          type: item.password ? 2 : 1,
+          username: item.username,
+          name: item.name,
+          email: item.email,
+          employeeCode: item.employeeCode
+        }
+        this.$refs.dialog.open()
+      } catch (error) {
+        this.$message.error(error)
+      }
+    },
+    async remoteMethod (str) {
+      this.loading = true
+      try {
+        const { data } = await getRosterList({
+          entity: {
+            employeeName: str
+          },
+          page: {
+            current: 1,
+            size: 50
+          }
+        })
+        this.items = data.records
+      } catch (error) {
+        this.items = []
+        this.$message.error(error)
+      } finally {
+        this.loading = false
+      }
+    },
+    handleType (v) {
+      this.$refs.userForm.clearValidate()
+    },
+    handleSave () {
+      this.$refs.userForm.validate(async valid => {
+        if (!valid) {
+          return
+        }
+        const { type, ...obj } = this.userFormValue
+        try {
+          await saveUser({
+            ...obj,
+            state: 0
+          })
+          this.$message.success('保存成功')
+          this.$refs.dialog.close()
+          this.$emit('refresh')
+        } catch (error) {
+          this.$message.error(error)
+        }
+      })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>

+ 73 - 0
src/views/system/user/userReset.vue

@@ -0,0 +1,73 @@
+<template>
+  <MDialog ref="password" title="重置密码" @sure="handleSavePassword">
+    <MForm ref="passwordForm" :items="passwordFormItems" v-model="passwordFormValue"></MForm>
+  </MDialog>
+</template>
+
+<script>
+import {
+  resetPassword
+} from '@/api/user'
+export default {
+  name: 'user-reset',
+  data () {
+    return {
+      item: {},
+      passwordFormValue: {
+        newPwd: null
+      }
+    }
+  },
+  computed: {
+    passwordFormItems () {
+      return [
+        {
+          label: '新密码',
+          prop: 'newPwd',
+          type: 'input',
+          options: {
+            showPassword: true,
+            placeholder: '请输入新密码'
+          },
+          rules: [
+            { required: true, message: '请输入密码', trigger: 'blur' }
+          ]
+        }
+      ]
+    }
+  },
+  methods: {
+    open (item) {
+      this.item = item
+      this.passwordFormValue.newPwd = null
+      this.$refs.password.open()
+    },
+    async handleSavePassword () {
+      this.$refs.passwordForm.validate(async valid => {
+        if (!valid) {
+          return
+        }
+        const companyCode = this.item.companyInfo?.companyCode
+        const userId = this.item.id
+        const param = {
+          type: 1,
+          userId,
+          companyCode,
+          ...this.passwordFormValue
+        }
+        try {
+          await resetPassword(param)
+          this.$refs.password.close()
+          this.$message.success('修改成功')
+        } catch (error) {
+          this.$message.error(error)
+        }
+      })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>

+ 122 - 0
src/views/system/user/userRole.vue

@@ -0,0 +1,122 @@
+<template>
+  <MDialog ref="dialog" title="角色分配" @sure="handleSaveRole">
+    <MForm ref="form" :items="roleFormItems" v-model="roleFormValue">
+      <template #username>
+        <el-tag>{{ roleFormValue.username }}</el-tag>
+      </template>
+      <template #name>
+        <el-tag>{{ roleFormValue.name }}</el-tag>
+      </template>
+    </MForm>
+  </MDialog>
+</template>
+
+<script>
+import {
+  saveUser
+} from '@/api/user'
+
+import { getRoleList } from '@/api/menu'
+export default {
+  name: 'user-role',
+  data () {
+    return {
+      roleFormValue: {
+        roleId: null
+      },
+      itemData: {},
+      loading: false
+    }
+  },
+  computed: {
+    roleFormItems () {
+      return [
+        {
+          label: '用户账号',
+          prop: 'username'
+        },
+        {
+          label: '用户昵称',
+          prop: 'name'
+        },
+        {
+          label: '角色',
+          prop: 'roleId',
+          type: 'select',
+          options: {
+            multiple: true,
+            placeholder: '请选择角色',
+            filterable: true,
+            remote: true,
+            labelText: 'roleName',
+            labelValue: 'id',
+            remoteMethod: this.remoteMethod,
+            valueKey: 'id',
+            defaultFirstOption: true,
+            loading: this.loading,
+            items: this.items
+          },
+          rules: [
+            { required: true, message: '请选择角色', trigger: 'change' }
+          ]
+        }
+      ]
+    }
+  },
+  methods: {
+    async open (item) {
+      this.itemData = item
+      this.roleFormValue = {
+        username: item.username,
+        name: item.name,
+        roleId: item.roleId ? item.roleId.split(',').map(e => +e) : []
+      }
+      if (this.roleFormValue.roleId.length > 0) {
+        try {
+          const { data } = await getRoleList({ ids: this.roleFormValue.roleId })
+          this.items = data.records
+        } catch (error) {
+          this.items = []
+          this.$message.error(error)
+        }
+      }
+      this.$refs.dialog.open()
+    },
+    async remoteMethod (str) {
+      this.loading = true
+      try {
+        const { data } = await getRoleList({ size: 50, roleName: str })
+        this.items = data.records
+      } catch (error) {
+        this.items = []
+        this.$message.error(error)
+      } finally {
+        this.loading = false
+      }
+    },
+    async handleSaveRole () {
+      this.$refs.form.validate(async valid => {
+        if (!valid) {
+          return
+        }
+        try {
+          await saveUser({
+            id: this.itemData?.id,
+            tenantCode: this.itemData.tenantCode,
+            roleId: this.roleFormValue.roleId.toString()
+          })
+          this.$message.success('保存成功')
+          this.$refs.dialog.close()
+          this.$emit('refresh')
+        } catch (error) {
+          this.$message.error(error)
+        }
+      })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>