| | |
| | | <template> |
| | | <win :title="setting.title" @close="close" :width="'800px'"> |
| | | <el-form :model="formData" class="demo-ruleForm" label-width="100px"> |
| | | <el-form-item label="角色配置" prop="roleSetting"> |
| | | <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> |
| | | <div style="margin: 15px 0;"></div> |
| | | <el-checkbox-group v-model="checkedList" @change="handleCheckedCitiesChange" > |
| | | <el-checkbox v-for="(r,i) in roleOptions" :label="r.role_id" :key="r.role_id">{{r.role_name}}</el-checkbox> |
| | | <el-checkbox-group v-model="checkedList" @change="handleCheckedCitiesChange"> |
| | | <el-checkbox v-for="(r,i) in roleOptions" :label="r.role_id" :key="r.role_id">{{ r.role_name }}</el-checkbox> |
| | | </el-checkbox-group> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" align="center" class="dialog-footer"> |
| | | <my-button name="取消" site="form" @click="close" /> |
| | | <my-button name="保存" site="form" @click="save" /> |
| | | <my-button name="取消" site="form" @click="close"/> |
| | | <my-button name="保存" site="form" @click="save"/> |
| | | </div> |
| | | </win> |
| | | </template> |
| | |
| | | import * as user from "@/api/user"; |
| | | |
| | | export default { |
| | | components: { win, myButton }, |
| | | components: {win, myButton}, |
| | | props: { |
| | | // setting 中须至少包含控制dialog显示或隐藏的属性,其余属性可拓展 |
| | | // 将添加/修改的大量数据及逻辑从列表页面中分离出来,避免列表页面代码过多,审查困难 |
| | |
| | | }, |
| | | data() { |
| | | return { |
| | | loading: true, |
| | | data_scope: null, |
| | | checkAll:false, |
| | | checkedList:[], |
| | | roleList:[ |
| | | {'id':1,label:'王涵1'}, |
| | | {'id':2,label:'王涵2'} |
| | | checkAll: false, |
| | | checkedList: [], |
| | | roleList: [ |
| | | {'id': 1, label: '王涵1'}, |
| | | {'id': 2, label: '王涵2'} |
| | | ], |
| | | // 查询参数 |
| | | queryParams: { |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | roleName: undefined, |
| | | roleKey: undefined, |
| | | status: 0, |
| | | orgId: 1 |
| | | }, |
| | | // 查询参数 |
| | | queryParams: { |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | roleName: undefined, |
| | | roleKey: undefined, |
| | | status: 0, |
| | | orgId: 1 |
| | | }, |
| | | roleOptions: [],// 选择项 |
| | | roleCheckStrictly: true, |
| | | defaultProps: { |
| | |
| | | } |
| | | } |
| | | }, |
| | | 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){ |
| | | // 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 => { |
| | | if (response) { |
| | | this.roleOptions = response; |
| | | } else { |
| | | this.roleOptions = []; |
| | | } |
| | | this.loading = false; |
| | | } |
| | | ); |
| | | async getAllRole() { |
| | | // const user = this.$store.getters.userInfo |
| | | // this.data_scope = 1 |
| | | 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 { |
| | | this.roleOptions = []; |
| | | } |
| | | this.loading = false; |
| | | } |
| | | ); |
| | | }, |
| | | handleCheckAllChange(val){ |
| | | if(val){ |
| | | this.checkedList = this.roleOptions.map(x=>{ |
| | | handleCheckAllChange(val) { |
| | | if (val) { |
| | | this.checkedList = this.roleOptions.map(x => { |
| | | return x.role_id |
| | | }) |
| | | }else{ |
| | | } else { |
| | | this.checkedList = [] |
| | | } |
| | | }, |
| | |
| | | let checkedCount = value.length; |
| | | this.checkAll = checkedCount === this.roleOptions.length; |
| | | }, |
| | | getInfo() { |
| | | this.title = this.setting.title |
| | | if ( this.setting.id != null ) { |
| | | // 查询数据 |
| | | 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=>{ |
| | | return x.role_id |
| | | }) |
| | | if (res.list.length===this.roleOptions.length){ |
| | | this.handleCheckedCitiesChange(res.list) |
| | | } |
| | | async getInfo() { |
| | | // 查询数据 |
| | | 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 => { |
| | | return x.role_id |
| | | }) |
| | | } |
| | | if (res.list.length === this.roleOptions.length) { |
| | | this.handleCheckedCitiesChange(res.list) |
| | | } |
| | | }) |
| | | }, |
| | | close() { |
| | | this.formData = { |
| | | projectName: '', |
| | | projectSubName: '', |
| | | projectCode: '', |
| | | projectContact: '', |
| | | projectTel: '', |
| | | projectEmail: '', |
| | | projectStart: null, |
| | | projectEnd: null, |
| | | projectDesc: '', |
| | | status: 1 |
| | | }, |
| | | this.formData = { |
| | | 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') |
| | | user.updRole(params).then(res => { |
| | | if (res) { |
| | | this.$message.success('保存成功!') |
| | | this.close() |
| | | this.$emit('search') |
| | | } else { |
| | | this.$message.error('保存失败') |
| | | } |
| | | }) |
| | | } |
| | | const params = Object.assign({}, this.formData) |
| | | params.roleList = this.checkedList |
| | | if (params.id) { |
| | | if (this.loading) return; |
| | | this.loading = true |
| | | user.updRole(params).then(res => { |
| | | this.loading = false |
| | | if (res) { |
| | | this.$message.success('保存成功!') |
| | | this.close() |
| | | this.$emit('search') |
| | | } else { |
| | | this.$message.error('保存失败') |
| | | } |
| | | }).catch(() => { |
| | | this.loading = false |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | } |