角色管理setup改造完成

This commit is contained in:
piexlmax
2021-12-29 23:49:01 +08:00
parent f0957c615e
commit d2eaf0b38c
4 changed files with 508 additions and 461 deletions
@@ -14,94 +14,105 @@
</template>
<script>
import { setDataAuthority } from '@/api/authority'
import warningBar from '@/components/warningBar/warningBar.vue'
export default {
name: 'Datas',
components: { warningBar },
props: {
row: {
default: function() {
return {}
},
type: Object
},
authority: {
default: function() {
return []
},
type: Array
}
},
data() {
return {
authoritys: [],
dataAuthorityId: [],
needConfirm: false
}
},
created() {
this.authoritys = []
this.dataAuthorityId = []
this.roundAuthority(this.authority)
this.row.dataAuthorityId && this.row.dataAuthorityId.forEach(item => {
const obj = this.authoritys && this.authoritys.filter(au => au.authorityId === item.authorityId) && this.authoritys.filter(au => au.authorityId === item.authorityId)[0]
this.dataAuthorityId.push(obj)
})
},
methods: {
// 暴露给外层使用的切换拦截统一方法
enterAndNext() {
this.authDataEnter()
},
all() {
this.dataAuthorityId = [...this.authoritys]
this.$emit('changeRow', 'dataAuthorityId', this.dataAuthorityId)
this.needConfirm = true
},
self() {
this.dataAuthorityId = this.authoritys.filter(item => item.authorityId === this.row.authorityId)
this.$emit('changeRow', 'dataAuthorityId', this.dataAuthorityId)
this.needConfirm = true
},
selfAndChildren() {
const arrBox = []
this.getChildrenId(this.row, arrBox)
this.dataAuthorityId = this.authoritys.filter(item => arrBox.indexOf(item.authorityId) > -1)
this.$emit('changeRow', 'dataAuthorityId', this.dataAuthorityId)
this.needConfirm = true
},
getChildrenId(row, arrBox) {
arrBox.push(row.authorityId)
row.children && row.children.forEach(item => {
this.getChildrenId(item, arrBox)
})
},
// 提交
async authDataEnter() {
const res = await setDataAuthority(this.row)
if (res.code === 0) {
this.$message({ type: 'success', message: '资源设置成功' })
}
},
// 平铺角色
roundAuthority(authoritys) {
authoritys && authoritys.forEach(item => {
const obj = {}
obj.authorityId = item.authorityId
obj.authorityName = item.authorityName
this.authoritys.push(obj)
if (item.children && item.children.length) {
this.roundAuthority(item.children)
}
})
},
// 选择
selectAuthority() {
this.$emit('changeRow', 'dataAuthorityId', this.dataAuthorityId)
this.needConfirm = true
}
}
name: 'Datas'
}
</script>
<script setup>
import { setDataAuthority } from '@/api/authority'
import warningBar from '@/components/warningBar/warningBar.vue'
import { defineProps, ref, defineEmits, defineExpose } from 'vue'
import { ElMessage } from 'element-plus'
const props = defineProps({
row: {
default: function() {
return {}
},
type: Object
},
authority: {
default: function() {
return []
},
type: Array
}
})
const authoritys = ref([])
const needConfirm = ref(false)
// 平铺角色
const roundAuthority = (authoritysData) => {
authoritysData && authoritysData.forEach(item => {
const obj = {}
obj.authorityId = item.authorityId
obj.authorityName = item.authorityName
authoritys.value.push(obj)
if (item.children && item.children.length) {
roundAuthority(item.children)
}
})
}
const dataAuthorityId = ref([])
const init = () => {
roundAuthority(props.authority)
props.row.dataAuthorityId && props.row.dataAuthorityId.forEach(item => {
const obj = authoritys.value && authoritys.value.filter(au => au.authorityId === item.authorityId) && authoritys.value.filter(au => au.authorityId === item.authorityId)[0]
dataAuthorityId.value.push(obj)
})
}
init()
// 暴露给外层使用的切换拦截统一方法
const enterAndNext = () => {
console.log(123)
authDataEnter()
}
const emit = defineEmits(['changeRow'])
const all = () => {
dataAuthorityId.value = [...authoritys.value]
emit('changeRow', 'dataAuthorityId', dataAuthorityId.value)
needConfirm.value = true
}
const self = () => {
dataAuthorityId.value = authoritys.value.filter(item => item.authorityId === props.row.authorityId)
emit('changeRow', 'dataAuthorityId', dataAuthorityId.value)
needConfirm.value = true
}
const selfAndChildren = () => {
const arrBox = []
getChildrenId(props.row, arrBox)
dataAuthorityId.value = authoritys.value.filter(item => arrBox.indexOf(item.authorityId) > -1)
emit('changeRow', 'dataAuthorityId', dataAuthorityId.value)
needConfirm.value = true
}
const getChildrenId = (row, arrBox) => {
arrBox.push(row.authorityId)
row.children && row.children.forEach(item => {
getChildrenId(item, arrBox)
})
}
// 提交
const authDataEnter = async() => {
console.log(123, props.row)
const res = await setDataAuthority(props.row)
if (res.code === 0) {
ElMessage({ type: 'success', message: '资源设置成功' })
}
}
// 选择
const selectAuthority = () => {
emit('changeRow', 'dataAuthorityId', dataAuthorityId.value)
needConfirm.value = true
}
defineExpose({
enterAndNext,
needConfirm
})
</script>