修复角色权限要保存两次

This commit is contained in:
Mrtangl 2022-08-01 11:59:09 +08:00
parent de7972fa00
commit dd1be368da
1 changed files with 195 additions and 196 deletions

View File

@ -48,7 +48,7 @@
icon="ArrowRight"
:props="{
children: 'children',
label: 'menuName'
label: 'menuName',
}"
empty-text=""
show-checkbox
@ -65,23 +65,17 @@
</template>
<script lang="ts">
import { defineComponent, reactive, onMounted, Ref, ref, toRefs } from 'vue'
import {
apiConfigGetMenu,
apiConfigGetAuth,
apiRoleAdd,
apiRoleEdit,
apiRoleDetail
} from '@/api/auth'
import { ElInput, ElForm } from 'element-plus'
import FooterBtns from '@/components/footer-btns/index.vue'
import { useAdmin } from '@/core/hooks/app'
import { flatten } from '@/utils/util'
import { ElMessage } from 'element-plus'
import { defineComponent, reactive, onMounted, Ref, ref, toRefs } from 'vue'
import { apiConfigGetMenu, apiConfigGetAuth, apiRoleAdd, apiRoleEdit, apiRoleDetail } from '@/api/auth'
import { ElInput, ElForm } from 'element-plus'
import FooterBtns from '@/components/footer-btns/index.vue'
import { useAdmin } from '@/core/hooks/app'
import { flatten } from '@/utils/util'
import { ElMessage } from 'element-plus'
export default defineComponent({
export default defineComponent({
components: {
FooterBtns
FooterBtns,
},
setup() {
const { route, router } = useAdmin()
@ -98,13 +92,13 @@ export default defineComponent({
menus: [], // id
isDisable: 0,
sort: '',
menuIds: '' // ID,
menuIds: '', // ID,
},
menu: {
permissionsTree: [], //
allAuthKeys: [] // id
}
allAuthKeys: [], // id
},
})
)
@ -115,17 +109,17 @@ export default defineComponent({
required: true,
message: '请输入角色名称',
trigger: ['blur'],
pattern: /(^[^\s]*$)/ //
}
pattern: /(^[^\s]*$)/, //
},
],
sort: [
{
required: true,
message: '请输入排序',
trigger: 'blur',
pattern: /(^[0-9]\d*$)/
}
]
pattern: /(^[0-9]\d*$)/,
},
],
}
//
@ -159,6 +153,11 @@ export default defineComponent({
//
const roleAdd = () => {
// id
formData.value.menus.length == 0
? (formData.value.menuIds = '')
: (formData.value.menuIds = formData.value.menus.join(','))
apiRoleAdd({ ...formData.value })
.then((res: any) => {
console.log('res', res)
@ -180,7 +179,7 @@ export default defineComponent({
apiRoleEdit({
...formData.value,
id: id.value
id: id.value,
})
.then((res: any) => {
console.log('res', res)
@ -197,7 +196,7 @@ export default defineComponent({
//
const roleDetail = () => {
apiRoleDetail({
id: id.value
id: id.value,
})
.then((res: any) => {
console.log('res', res)
@ -217,7 +216,7 @@ export default defineComponent({
if (!data.id) {
return
}
const index = formData.value.menus.findIndex(item => item == data.id)
const index = formData.value.menus.findIndex((item) => item == data.id)
if (checked) {
index == -1 && (formData.value.menus as any).push(data.id)
return
@ -262,16 +261,16 @@ export default defineComponent({
onSubmit,
handlePermissionsCheckChange,
close,
allSelect
allSelect,
}
}
})
},
})
</script>
<style lang="scss" scoped>
.role-edit {
.role-edit {
:deep .el-textarea {
width: 340px;
}
}
}
</style>