石广澎
2024-01-02 0cd1631ceaa93e6483908fd692d2cb693b85324b
admin-web/src/views/systemManger/server/user/editRole.vue
@@ -1,5 +1,5 @@
<template>
  <win :title="setting.title" @close="close" :width="'800px'">
  <win :title="setting.title" @close="close" :width="'800px'" :loading="loading">
    <el-form  :model="formData"  class="demo-ruleForm" label-width="100px">
      <el-form-item label="角色配置"  prop="roleSetting">
        <el-checkbox v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
@@ -36,6 +36,7 @@
  },
  data() {
    return {
      loading: true,
      data_scope: null,
      checkAll:false,
      checkedList:[],
@@ -69,30 +70,21 @@
      }
    }
  },
  created() {
    this.getInfo()
    this.getAllRole()
  async created() {
    this.title = this.setting.title
    if (this.setting.id != null) {
      await this.getInfo()
    }
    await this.getAllRole()
    this.loading = false
  },
  methods: {
    // 获取所有角色
    getAllRole() {
      const user = this.$store.getters.userInfo
      // debugger
      // if (user == undefined){
    async getAllRole() {
      // const user = this.$store.getters.userInfo
      //   this.data_scope = 1
      // } else {
      //   if (user.lv==null|| user.lv== 1) {
      //     this.data_scope = 1
      //   }
      //   if (user.lv && user.lv== 2) {
      //     this.data_scope = 2
      //   }
      //   if (user.lv && user.lv== 3) {
      //     this.data_scope = 3
      //   }
      // }
      this.data_scope = 1
      role.listRoleByDataScope({dataScope: this.data_scope}).then(response => {
      this.data_scope = this.$store.getters.userInfo ? this.$store.getters.userInfo.lv : ''
      await role.listRoleByDataScope({dataScope: this.setting.data_scope}).then(response => {
            if (response) {
              this.roleOptions = response;
            } else {
@@ -115,11 +107,9 @@
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.roleOptions.length;
    },
    getInfo() {
      this.title = this.setting.title
      if ( this.setting.id != null ) {
    async getInfo() {
        // 查询数据
        user.getUser({ id: this.setting.id }).then(res => {
      await user.getUser({id: this.setting.id}).then(res => {
          const data = res.data
          this.formData = Object.assign(this.formData, data)
          this.checkedList = res.list.map(x=>{
@@ -129,29 +119,27 @@
              this.handleCheckedCitiesChange(res.list)
          }
        })
      }
    },
    close() {
        this.formData = {
          projectName: '',
          projectSubName: '',
          projectCode: '',
          projectContact: '',
          projectTel: '',
          projectEmail: '',
          projectStart: null,
          projectEnd: null,
          projectDesc: '',
          status: 1
        },
        userName: '',
        userCode: '',
        userPhone: '',
        sex: 1,
        status: 1,
        remark: '',
        seq: null
      }
      this.$emit('close')
    },
    save() {
        const params = Object.assign({}, this.formData)
        params.roleList=this.checkedList
        if (params.id) {
            console.log(params+'params')
        if (this.loading) return;
        this.loading = true
            user.updRole(params).then(res => {
          this.loading = false
                if (res) {
                    this.$message.success('保存成功!')
                    this.close()
@@ -159,6 +147,8 @@
                } else {
                    this.$message.error('保存失败')
                }
        }).catch(() => {
          this.loading = false
            })
        }
    }