yaozc2021
2024-12-25 7df667ff109e5cdccb61305140f81d60856f4ff4
eladmin-web-master/src/views/system/user/index.vue
@@ -86,7 +86,7 @@
        </div>
        <!--表单组件-->
        <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="570px">
          <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="66px">
          <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="70px">
            <el-form-item label="用户名" prop="username">
              <el-input v-model="form.username" @keydown.native="keydown($event)" />
            </el-form-item>
@@ -186,7 +186,7 @@
                <el-option v-for="item in companyList" :key="item.id" :label="item.label" :value="item.id" />
              </el-select>
            </el-form-item>
            <el-form-item style="margin-bottom: 0;" label="角色" prop="roles">
            <el-form-item label="角色" prop="roles">
              <el-select
                v-model="roleDatas"
                style="width: 437px"
@@ -202,6 +202,11 @@
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="操作公司" prop="companys">
              <el-select v-model="companyDatas" clearable multiple collapse-tags style="width: 437px" @remove-tag="deleteCompanyTag" @change="changeCompany">
                <el-option v-for="item in companyList" :key="item.id" :label="item.label" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-form>
@@ -287,7 +292,8 @@
import crudSysCompany from '@/api/system/sysCompany'
let userRoles = []
let userJobs = []
const defaultForm = { id: null, username: null, company: { id: null }, internshipTime: null, nickName: null, gender: '男', email: null, enabled: 'false', roles: [], jobs: [], dept: { id: null }, phone: null, birthday: null, address: null, dingding: null, sysRostering: { id: null }, levelId: null }
let userCompanys = []
const defaultForm = { id: null, username: null, company: { id: null }, internshipTime: null, nickName: null, gender: '男', email: null, enabled: 'false', roles: [], jobs: [], dept: { id: null }, phone: null, birthday: null, address: null, dingding: null, sysRostering: { id: null }, levelId: null, companys: [] }
export default {
  name: 'User',
  components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker },
@@ -311,7 +317,7 @@
    return {
      height: document.documentElement.clientHeight - 180 + 'px;',
      deptName: '', depts: [], deptDatas: [], jobs: [], level: 3, roles: [],
      jobDatas: [], roleDatas: [], // 多选时使用
      jobDatas: [], roleDatas: [], companyDatas: [], // 多选时使用
      defaultProps: { children: 'children', label: 'name', isLeaf: 'leaf' },
      permission: {
        add: ['admin', 'user:add'],
@@ -427,10 +433,24 @@
        this.form.levelId = null
      }
    },
    changeCompany(value) {
      userCompanys = []
      value.forEach(function(data, index) {
        const com = { id: data }
        userCompanys.push(com)
      })
    },
    deleteTag(value) {
      userRoles.forEach(function(data, index) {
        if (data.id === value) {
          userRoles.splice(index, value)
        }
      })
    },
    deleteCompanyTag(value) {
      userCompanys.forEach(function(data, index) {
        if (data.id === value) {
          userCompanys.splice(index, value)
        }
      })
    },
@@ -452,15 +472,18 @@
    [CRUD.HOOK.beforeToAdd]() {
      this.jobDatas = []
      this.roleDatas = []
      this.companyDatas = []
      this.isEditing = false
    },
    // 初始化编辑时候的角色与岗位
    // 初始化编辑时候的角色与岗位与操作公司
    [CRUD.HOOK.beforeToEdit](crud, form) {
      this.getJobs(this.form.dept.id)
      this.jobDatas = []
      this.roleDatas = []
      this.companyDatas = []
      userRoles = []
      userJobs = []
      userCompanys = []
      const _this = this
      this.isEditing = true
      form.roles.forEach(function(role, index) {
@@ -477,6 +500,11 @@
          // 获取级别
          _this.getLevel()
        }
      })
      form.companys.forEach(function(company, index) {
        _this.companyDatas.push(company.id)
        const com = { id: company.id }
        userCompanys.push(com)
      })
    },
    // 提交前做的操作
@@ -502,6 +530,7 @@
      }
      crud.form.roles = userRoles
      crud.form.jobs = userJobs
      crud.form.companys = userCompanys
      return true
    },
    // 获取左侧部门数据