fix:补充 eslint 格式化
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div v-clickoutside="{obj: editRole, func: esc}" class="right-box right-box-asset">
|
||||
<div class="right-box__header">
|
||||
<div class="header__title">{{editRole.id ? $t('config.user.editRole') : $t('config.user.createUser')}}</div>
|
||||
<div class="header__title">{{editRole.id ? $t('config.roles.editRole') : $t('config.roles.createRole')}}</div>
|
||||
<div class="header__operation">
|
||||
<span v-cancel="{obj: editRole, func: esc}"><i class="nz-icon nz-icon-close"></i></span>
|
||||
</div>
|
||||
@@ -48,154 +48,152 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'userBox',
|
||||
components: {
|
||||
export default {
|
||||
name: 'userBox',
|
||||
components: {
|
||||
},
|
||||
props: {
|
||||
obj: {
|
||||
type: Object
|
||||
},
|
||||
props: {
|
||||
obj: {
|
||||
type: Object
|
||||
detail: Boolean
|
||||
},
|
||||
data () {
|
||||
const vm = this
|
||||
return {
|
||||
editRole: {},
|
||||
url: 'sys/role',
|
||||
rightBox: { model: { show: false } },
|
||||
rules: { // 表单校验规则
|
||||
name: [
|
||||
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
detail: Boolean
|
||||
},
|
||||
data () {
|
||||
const vm = this
|
||||
return {
|
||||
editRole: {},
|
||||
url: 'sys/role',
|
||||
rightBox: {model: {show: false}},
|
||||
rules: { // 表单校验规则
|
||||
name: [
|
||||
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
menus: [],
|
||||
selectedIds:[],
|
||||
selectAllFlag: false,
|
||||
expandAllFlag: true
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
obj: {
|
||||
deep: true,
|
||||
immediate: true,
|
||||
handler (n) {
|
||||
this.editRole = JSON.parse(JSON.stringify(n))
|
||||
if(this.editRole.roles && this.editRole.roles.length>0){
|
||||
this.editRole.roleIds=this.editRole.roles.map(t=>t.id)
|
||||
}
|
||||
menus: [],
|
||||
selectedIds: [],
|
||||
selectAllFlag: false,
|
||||
expandAllFlag: true
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
obj: {
|
||||
deep: true,
|
||||
immediate: true,
|
||||
handler (n) {
|
||||
this.editRole = JSON.parse(JSON.stringify(n))
|
||||
if (this.editRole.roles && this.editRole.roles.length > 0) {
|
||||
this.editRole.roleIds = this.editRole.roles.map(t => t.id)
|
||||
}
|
||||
},
|
||||
},
|
||||
created () {
|
||||
|
||||
},
|
||||
mounted () {
|
||||
this.getMenus().then(()=>{
|
||||
if (this.$refs.menuTree && this.selectedIds && this.selectedIds.length > 0) {
|
||||
this.$refs.menuTree.setCheckedKeys(this.selectedIds, true)
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
methods: {
|
||||
clickOutside () {
|
||||
this.esc(false)
|
||||
},
|
||||
/* 关闭弹框 */
|
||||
esc (refresh) {
|
||||
this.prevent_opt.save = false
|
||||
this.$emit('close', refresh)
|
||||
},
|
||||
getMenus: function () {
|
||||
let self = this;
|
||||
return new Promise(resolve => {
|
||||
self.menus = []
|
||||
if(self.editRole.id){
|
||||
self.$get('/sys/role/menu/'+self.editRole.id).then(response => {
|
||||
if (response.code == 200) {
|
||||
self.menus = response.data.menus;
|
||||
self.selectedIds = response.data.selectedIds
|
||||
} else {
|
||||
self.$message.error('load menu faild')
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
}else{
|
||||
self.$get('/sys/menu').then(response => {
|
||||
if (response.code == 200) {
|
||||
self.menus = response.data.list;
|
||||
|
||||
} else {
|
||||
self.$message.error('load menu faild')
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
labelFormatter: function (data, node) {
|
||||
return data && data.i18n ? this.$t(data.i18n) : data.name
|
||||
},
|
||||
selectChange: function (data, isCheck, childIsCheck) {
|
||||
if (this.$refs.menuTree) {
|
||||
this.editRole.menuIds = this.$refs.menuTree.getCheckedKeys(true)
|
||||
}
|
||||
},
|
||||
selectAllOrNone: function () {
|
||||
if (this.$refs.menuTree) {
|
||||
if (!this.selectAllFlag) {
|
||||
this.$refs.menuTree.setCheckedNodes(this.menus)
|
||||
} else {
|
||||
this.$refs.menuTree.setCheckedNodes([])
|
||||
}
|
||||
this.selectAllFlag = !this.selectAllFlag
|
||||
}
|
||||
},
|
||||
expandAllOrNone: function () {
|
||||
this.expandAllFlag = !this.expandAllFlag
|
||||
const $self = this
|
||||
if (this.$refs.menuTree) {
|
||||
this.menus.forEach(t => {
|
||||
$self.$refs.menuTree.store.nodesMap[t.id].expanded = $self.expandAllFlag
|
||||
})
|
||||
}
|
||||
},
|
||||
save () {
|
||||
if (this.prevent_opt.save) { return } ;
|
||||
this.prevent_opt.save = true
|
||||
|
||||
this.$refs.roleForm.validate((valid) => {
|
||||
if (valid) {
|
||||
if (this.editRole.id) {
|
||||
this.$put(this.url, this.editRole).then(res => {
|
||||
this.prevent_opt.save = false
|
||||
if (res.code === 200) {
|
||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||
this.esc(true)
|
||||
} else {
|
||||
this.$message.error(res.msg)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.$post(this.url, this.editRole).then(res => {
|
||||
this.prevent_opt.save = false
|
||||
if (res.code === 200) {
|
||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||
this.esc(true)
|
||||
} else {
|
||||
this.$message.error(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.prevent_opt.save = false
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
created () {
|
||||
|
||||
},
|
||||
mounted () {
|
||||
this.getMenus().then(() => {
|
||||
if (this.$refs.menuTree && this.selectedIds && this.selectedIds.length > 0) {
|
||||
this.$refs.menuTree.setCheckedKeys(this.selectedIds, true)
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
clickOutside () {
|
||||
this.esc(false)
|
||||
},
|
||||
/* 关闭弹框 */
|
||||
esc (refresh) {
|
||||
this.prevent_opt.save = false
|
||||
this.$emit('close', refresh)
|
||||
},
|
||||
getMenus: function () {
|
||||
const self = this
|
||||
return new Promise(resolve => {
|
||||
self.menus = []
|
||||
if (self.editRole.id) {
|
||||
self.$get('/sys/role/menu/' + self.editRole.id).then(response => {
|
||||
if (response.code == 200) {
|
||||
self.menus = response.data.menus
|
||||
self.selectedIds = response.data.selectedIds
|
||||
} else {
|
||||
self.$message.error('load menu faild')
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
} else {
|
||||
self.$get('/sys/menu').then(response => {
|
||||
if (response.code == 200) {
|
||||
self.menus = response.data.list
|
||||
} else {
|
||||
self.$message.error('load menu faild')
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
labelFormatter: function (data, node) {
|
||||
return data && data.i18n ? this.$t(data.i18n) : data.name
|
||||
},
|
||||
selectChange: function (data, isCheck, childIsCheck) {
|
||||
if (this.$refs.menuTree) {
|
||||
this.editRole.menuIds = this.$refs.menuTree.getCheckedKeys(true)
|
||||
}
|
||||
},
|
||||
selectAllOrNone: function () {
|
||||
if (this.$refs.menuTree) {
|
||||
if (!this.selectAllFlag) {
|
||||
this.$refs.menuTree.setCheckedNodes(this.menus)
|
||||
} else {
|
||||
this.$refs.menuTree.setCheckedNodes([])
|
||||
}
|
||||
this.selectAllFlag = !this.selectAllFlag
|
||||
}
|
||||
},
|
||||
expandAllOrNone: function () {
|
||||
this.expandAllFlag = !this.expandAllFlag
|
||||
const $self = this
|
||||
if (this.$refs.menuTree) {
|
||||
this.menus.forEach(t => {
|
||||
$self.$refs.menuTree.store.nodesMap[t.id].expanded = $self.expandAllFlag
|
||||
})
|
||||
}
|
||||
},
|
||||
save () {
|
||||
if (this.prevent_opt.save) { return } ;
|
||||
this.prevent_opt.save = true
|
||||
|
||||
this.$refs.roleForm.validate((valid) => {
|
||||
if (valid) {
|
||||
if (this.editRole.id) {
|
||||
this.$put(this.url, this.editRole).then(res => {
|
||||
this.prevent_opt.save = false
|
||||
if (res.code === 200) {
|
||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||
this.esc(true)
|
||||
} else {
|
||||
this.$message.error(res.msg)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.$post(this.url, this.editRole).then(res => {
|
||||
this.prevent_opt.save = false
|
||||
if (res.code === 200) {
|
||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||
this.esc(true)
|
||||
} else {
|
||||
this.$message.error(res.msg)
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.prevent_opt.save = false
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
@import '@/assets/css/common/rightBoxCommon.scss';
|
||||
|
||||
Reference in New Issue
Block a user