docs(base-select): add multiple tree demo

This commit is contained in:
Kagol 2024-05-20 21:10:31 +08:00
parent f122a06b11
commit 9333997a2c
No known key found for this signature in database
GPG Key ID: 48BBA0ECCB3EB997
2 changed files with 56 additions and 2 deletions

View File

@ -1,4 +1,5 @@
<template>
<p>场景1下拉树单选</p>
<tiny-base-select v-model="value">
<template #panel="{ props: { state }, methods: { updateModelValue } }">
<tiny-tree
@ -18,13 +19,39 @@
></tiny-tree>
</template>
</tiny-base-select>
<p>场景2下拉树多选</p>
<tiny-base-select v-model="value2" :multiple="true">
<template #panel="{ props: { state }, methods: { updateModelValue } }">
<tiny-tree
:data="treeData"
:expand-on-click-node="false"
:icon-trigger-click-node="false"
:default-expand-all="true"
:show-checkbox="true"
@check="
(data, { checkedKeys, checkedNodes }) => {
updateModelValue(checkedNodes.map((node) => node.id))
nextTick(() => {
state.selected = state.selected.map((item) => {
return {
...item,
currentLabel: checkedNodes.find((node) => node.id === item.value).label
}
})
})
}
"
></tiny-tree>
</template>
</tiny-base-select>
</template>
<script setup>
import { ref, nextTick } from 'vue'
import { BaseSelect as TinyBaseSelect, Tree as TinyTree } from '@opentiny/vue'
const value = ref('')
const value = ref()
const value2 = ref([])
const treeData = ref([
{

View File

@ -1,4 +1,5 @@
<template>
<p>场景1下拉树单选</p>
<tiny-base-select v-model="value">
<template #panel="{ props: { state }, methods: { updateModelValue } }">
<tiny-tree
@ -10,7 +11,7 @@
(data) => {
state.visible = false
updateModelValue(data.id)
$nextTick(() => {
nextTick(() => {
state.selectedLabel = data.label
})
}
@ -18,6 +19,31 @@
></tiny-tree>
</template>
</tiny-base-select>
<p>场景2下拉树多选</p>
<tiny-base-select v-model="value2" :multiple="true">
<template #panel="{ props: { state }, methods: { updateModelValue } }">
<tiny-tree
:data="treeData"
:expand-on-click-node="false"
:icon-trigger-click-node="false"
:default-expand-all="true"
:show-checkbox="true"
@check="
(data, { checkedKeys, checkedNodes }) => {
updateModelValue(checkedNodes.map((node) => node.id))
nextTick(() => {
state.selected = state.selected.map((item) => {
return {
...item,
currentLabel: checkedNodes.find((node) => node.id === item.value).label
}
})
})
}
"
></tiny-tree>
</template>
</tiny-base-select>
</template>
<script>
@ -31,6 +57,7 @@ export default {
data() {
return {
value: '',
value2: [],
treeData: [
{
id: 1,