|
|
@@ -1,5 +1,10 @@
|
|
|
<script lang="ts" setup name="GroupSelector">
|
|
|
import { getGroupView } from '@/api/system/groupApi'
|
|
|
+const props = withDefaults(defineProps<{
|
|
|
+ modelValue: number
|
|
|
+}>(), {
|
|
|
+ modelValue: 0,
|
|
|
+})
|
|
|
const emit = defineEmits(['update:modelValue'])
|
|
|
interface TreeNode {
|
|
|
id: number
|
|
|
@@ -14,33 +19,35 @@ const state = reactive({
|
|
|
dataList: [] as TreeNode[],
|
|
|
})
|
|
|
|
|
|
-const treeRef = ref()
|
|
|
-
|
|
|
const getData = async () => {
|
|
|
state.loading = true
|
|
|
const { data } = await getGroupView()
|
|
|
state.dataList = data
|
|
|
+ // 初始化第一个给tree
|
|
|
+ // emit('update:modelValue', data[0].groupId)
|
|
|
}
|
|
|
|
|
|
-watch(() => state.groupId, (newValue) => {
|
|
|
- emit('update:modelValue', newValue)
|
|
|
-})
|
|
|
-
|
|
|
-watch(() => 'modelValue', (newValue) => {
|
|
|
- // emit('update:modelValue', newValue)
|
|
|
- window.console.log(newValue)
|
|
|
+const groupId = computed({
|
|
|
+ get: () => {
|
|
|
+ return props.modelValue
|
|
|
+ },
|
|
|
+ set: (val) => {
|
|
|
+ emit('update:modelValue', val)
|
|
|
+ },
|
|
|
})
|
|
|
-
|
|
|
onMounted(() => {
|
|
|
getData ()
|
|
|
- treeRef.value.currentNodeKey = state.groupId
|
|
|
})
|
|
|
+const selectProps = {
|
|
|
+ value: 'groupId',
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<el-tree-select
|
|
|
- ref="treeRef"
|
|
|
- v-model="state.groupId"
|
|
|
+ v-model="groupId"
|
|
|
+ check-strictly
|
|
|
+ :props="selectProps"
|
|
|
:data="state.dataList"
|
|
|
style="width: 100%"
|
|
|
filterable
|