|
@@ -1,15 +1,23 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div class="flex flex-col w-full" :class="props.border ? 'slider-border p-2' : ''">
|
|
|
|
|
|
|
+ <div
|
|
|
|
|
+ class="flex flex-col w-full"
|
|
|
|
|
+ :class="props.border ? 'slider-border p-2' : ''"
|
|
|
|
|
+ >
|
|
|
<a-input-group class="mb-2 w-full" size="mini">
|
|
<a-input-group class="mb-2 w-full" size="mini">
|
|
|
- <a-input :placeholder="props?.searchPlaceholder" allow-clear @input="changeKeyword" @clear="resetData" />
|
|
|
|
|
|
|
+ <a-input
|
|
|
|
|
+ :placeholder="props?.searchPlaceholder"
|
|
|
|
|
+ allow-clear
|
|
|
|
|
+ @input="changeKeyword"
|
|
|
|
|
+ @clear="resetData"
|
|
|
|
|
+ />
|
|
|
<a-button
|
|
<a-button
|
|
|
@click="
|
|
@click="
|
|
|
() => {
|
|
() => {
|
|
|
- isExpand ? saTree.expandAll(false) : saTree.expandAll(true)
|
|
|
|
|
- isExpand = !isExpand
|
|
|
|
|
|
|
+ isExpand ? saTree.expandAll(false) : saTree.expandAll(true);
|
|
|
|
|
+ isExpand = !isExpand;
|
|
|
}
|
|
}
|
|
|
"
|
|
"
|
|
|
- >{{ isExpand ? '折叠' : '展开' }}</a-button
|
|
|
|
|
|
|
+ >{{ isExpand ? "折叠" : "展开" }}</a-button
|
|
|
>
|
|
>
|
|
|
<slot name="treeAfterButtons"></slot>
|
|
<slot name="treeAfterButtons"></slot>
|
|
|
</a-input-group>
|
|
</a-input-group>
|
|
@@ -21,8 +29,11 @@
|
|
|
@select="handlerSelect"
|
|
@select="handlerSelect"
|
|
|
:field-names="props.fieldNames"
|
|
:field-names="props.fieldNames"
|
|
|
v-model:selected-keys="modelValue"
|
|
v-model:selected-keys="modelValue"
|
|
|
- v-bind="$attrs">
|
|
|
|
|
- <template #icon v-if="props.icon"><component :is="props.icon" /></template>
|
|
|
|
|
|
|
+ v-bind="$attrs"
|
|
|
|
|
+ >
|
|
|
|
|
+ <template #icon v-if="props.icon"
|
|
|
|
|
+ ><component :is="props.icon"
|
|
|
|
|
+ /></template>
|
|
|
<template v-for="(_, name) in $slots" v-slot:[name]="data">
|
|
<template v-for="(_, name) in $slots" v-slot:[name]="data">
|
|
|
<slot :name="name" v-bind="data"></slot>
|
|
<slot :name="name" v-bind="data"></slot>
|
|
|
</template>
|
|
</template>
|
|
@@ -31,13 +42,13 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, watch, computed, onMounted } from 'vue'
|
|
|
|
|
|
|
+import { ref, watch, computed, onMounted } from "vue";
|
|
|
|
|
|
|
|
-const treeData = ref([])
|
|
|
|
|
-const saTree = ref()
|
|
|
|
|
-const isExpand = ref(false)
|
|
|
|
|
|
|
+const treeData = ref([]);
|
|
|
|
|
+const saTree = ref();
|
|
|
|
|
+const isExpand = ref(false);
|
|
|
|
|
|
|
|
-const emit = defineEmits(['update:modelValue', 'click'])
|
|
|
|
|
|
|
+const emit = defineEmits(["update:modelValue", "click"]);
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
modelValue: { type: Array },
|
|
modelValue: { type: Array },
|
|
@@ -47,63 +58,63 @@ const props = defineProps({
|
|
|
fieldNames: {
|
|
fieldNames: {
|
|
|
type: Object,
|
|
type: Object,
|
|
|
default: () => {
|
|
default: () => {
|
|
|
- return { title: 'label', key: 'value' }
|
|
|
|
|
|
|
+ return { title: "label", key: "value" };
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
icon: { type: String, default: undefined },
|
|
icon: { type: String, default: undefined },
|
|
|
-})
|
|
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
const modelValue = computed({
|
|
const modelValue = computed({
|
|
|
get() {
|
|
get() {
|
|
|
- return props.modelValue
|
|
|
|
|
|
|
+ return props.modelValue;
|
|
|
},
|
|
},
|
|
|
set(newVal) {
|
|
set(newVal) {
|
|
|
- emit('update:modelValue', newVal)
|
|
|
|
|
|
|
+ emit("update:modelValue", newVal);
|
|
|
},
|
|
},
|
|
|
-})
|
|
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
watch(
|
|
watch(
|
|
|
() => props.data,
|
|
() => props.data,
|
|
|
(val) => {
|
|
(val) => {
|
|
|
- treeData.value = val
|
|
|
|
|
|
|
+ treeData.value = val;
|
|
|
},
|
|
},
|
|
|
{ immediate: true, deep: true }
|
|
{ immediate: true, deep: true }
|
|
|
-)
|
|
|
|
|
|
|
+);
|
|
|
|
|
|
|
|
const handlerSelect = (item, data) => {
|
|
const handlerSelect = (item, data) => {
|
|
|
- modelValue.value = [item]
|
|
|
|
|
- emit('click', ...[item, data])
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ modelValue.value = [item];
|
|
|
|
|
+ emit("click", ...[item, data]);
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
-const resetData = () => (treeData.value = props.data)
|
|
|
|
|
|
|
+const resetData = () => (treeData.value = props.data);
|
|
|
|
|
|
|
|
const changeKeyword = (keyword) => {
|
|
const changeKeyword = (keyword) => {
|
|
|
- if (!keyword || keyword === '') {
|
|
|
|
|
- treeData.value = Object.assign(props.data, [])
|
|
|
|
|
- return false
|
|
|
|
|
|
|
+ if (!keyword || keyword === "") {
|
|
|
|
|
+ treeData.value = Object.assign(props.data, []);
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- treeData.value = searchNode(keyword)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ treeData.value = searchNode(keyword);
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
const searchNode = (keyword) => {
|
|
const searchNode = (keyword) => {
|
|
|
const loop = (data) => {
|
|
const loop = (data) => {
|
|
|
- let tree = []
|
|
|
|
|
|
|
+ let tree = [];
|
|
|
data.map((item) => {
|
|
data.map((item) => {
|
|
|
- if (item[props.fieldNames['title']].indexOf(keyword) !== -1) {
|
|
|
|
|
- tree.push(item)
|
|
|
|
|
|
|
+ if (item[props.fieldNames["title"]].indexOf(keyword) !== -1) {
|
|
|
|
|
+ tree.push(item);
|
|
|
} else if (item.children && item.children.length > 0) {
|
|
} else if (item.children && item.children.length > 0) {
|
|
|
- const temp = loop(item.children)
|
|
|
|
|
- tree.push(...temp)
|
|
|
|
|
|
|
+ const temp = loop(item.children);
|
|
|
|
|
+ tree.push(...temp);
|
|
|
}
|
|
}
|
|
|
- return tree
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ return tree;
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- return tree
|
|
|
|
|
- }
|
|
|
|
|
- return loop(treeData.value)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return tree;
|
|
|
|
|
+ };
|
|
|
|
|
+ return loop(treeData.value);
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
-defineExpose({ saTree })
|
|
|
|
|
|
|
+defineExpose({ saTree });
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
<style scoped lang="less">
|