From e4a80fc8388293339b6e3fc76f522a3346060348 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Fri, 10 Jan 2025 22:33:51 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=BB=84=E4=BB=B6(=E6=A0=91):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BC=A0=E9=80=92=20v-model=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/config.js | 2 +- docs/components/view/tree.md | 224 ++++++++------------------------- src/App.vue | 46 ++++--- src/ui/tree/ShadcnTree.vue | 12 +- src/ui/tree/ShadcnTreeNode.vue | 22 +++- 5 files changed, 105 insertions(+), 201 deletions(-) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index c0d5bf0c..48cadf3a 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -184,7 +184,7 @@ export default { {text: 'Trend', link: 'view/trend', icon: '/components/view/trend.svg', version: '2024.2.0'}, {text: 'Exception', link: 'view/exception', icon: '/components/view/exception.svg', version: '2024.2.0'}, {text: 'Tag', link: 'view/tag', icon: '/components/view/tag.svg', version: '2024.2.0'}, - {text: 'Tree', link: 'view/tree', icon: '/components/view/tree.svg', version: '2024.3.0'}, + {text: '树 (Tree)', link: 'view/tree', icon: '/components/view/tree.svg', version: '2024.3.0'}, {text: 'Hover Card', link: 'view/hover-card', icon: '/components/view/hover-card.svg', version: '2024.4.0'}, {text: 'Logger', link: 'view/logger', icon: '/components/view/logger.svg', version: '2024.5.1'}, {text: 'Scrollbar', link: 'view/scrollbar', icon: '/components/view/scrollbar.svg', version: '2024.5.1'}, diff --git a/docs/components/view/tree.md b/docs/components/view/tree.md index 8677fd61..22ca9ff1 100644 --- a/docs/components/view/tree.md +++ b/docs/components/view/tree.md @@ -1,17 +1,19 @@ --- -title: Shadcn Tree +title: 树 (Tree) --- # 介绍 -This document is mainly used to describe some features and usage of the ShadcnTree component. +
+ +本文档主要用于描述 `ShadcnTree` 组件的一些特性和用法。 ## 用法 ::: raw - Value: {{ basicValue }} + 值: {{ basicValue }} - - ``` ::: -## Multiple +## 多选 (multiple) ::: raw - - Value: {{ multipleValue }} + + 值: {{ multipleValue }} @@ -83,44 +49,16 @@ console.log('Click Node:', node) - - ``` ::: -## Checkable +## 选择框 (checkable) ::: raw - - Value: {{ checkableValue }} + + 值: {{ checkableValue }} @@ -132,44 +70,16 @@ const data = [ - - ``` ::: -## Cascade +## 级联选择 (cascade) ::: raw - - Value: {{ cascadeValue }} + + 值: {{ cascadeValue }} @@ -181,44 +91,16 @@ const data = [ - - ``` ::: -## Lazy Data +## 懒加载 (lazy) ::: raw - - Value: {{ lazyValue }} + + 值: {{ lazyValue }} @@ -283,7 +165,7 @@ const loadNodeData = (item: any, callback: (children: any[]) => void) => { ::: raw - Value: {{ disabledValue }} + 值: {{ disabledValue }} @@ -328,12 +210,12 @@ const data = reactive([ ::: -## Show Line +## 显示线 (show-line) ::: raw - - Value: {{ showLineValue }} + + 值: {{ basicValue }} @@ -349,12 +231,12 @@ const data = reactive([ ::: -## Label Slot +## 自定义 Label 插槽 ::: raw - - Value: {{ customValue }} + + 值: {{ customValue }} + @@ -472,52 +354,52 @@ const data = [ ::: -## Props +## 树 (Tree) 属性 - -
+## 树节点 (Tree Node) 属性 - -## Slots +## 树 (Tree) 插槽 - -## Events +## 树 (Tree) 事件 - @@ -643,4 +525,4 @@ export default { } } } - + \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 7a4ee925..dd370de8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,28 +1,36 @@ - \ No newline at end of file diff --git a/src/ui/tree/ShadcnTree.vue b/src/ui/tree/ShadcnTree.vue index 2b2267d5..db41dffe 100644 --- a/src/ui/tree/ShadcnTree.vue +++ b/src/ui/tree/ShadcnTree.vue @@ -4,7 +4,7 @@ :key="item.value" :node="item" :level="0" - :selected-values="modelValue" + :selected-values="selectedValues" :checkable="checkable" :cascade="cascade" :show-line="showLine" @@ -27,7 +27,7 @@ + \ No newline at end of file diff --git a/src/ui/tree/ShadcnTreeNode.vue b/src/ui/tree/ShadcnTreeNode.vue index c19e1dce..8c0a5b34 100644 --- a/src/ui/tree/ShadcnTreeNode.vue +++ b/src/ui/tree/ShadcnTreeNode.vue @@ -143,8 +143,26 @@ const nodeChecked = computed({ } }) +// 判断当前节点是否是目标值的父节点 +const isParentOfSelected = (node: TreeNode, selectedValue: any): boolean => { + if (!node.children) { + return false + } + return node.children.some(child => { + if (child.value === selectedValue) { + return true + } + return isParentOfSelected(child, selectedValue) + }) +} + watch(() => props.selectedValues, (newValues) => { - if (newValues.includes(props.node.value) && hasChildren.value) { + // 如果当前节点被选中,或者是选中节点的父节点,则展开 + const shouldExpand = newValues.some(value => { + return isParentOfSelected(props.node, value) + }) + + if (shouldExpand || props.selectedValues.includes(props.node.value)) { isExpanded.value = true } }, { immediate: true }) @@ -185,4 +203,4 @@ const onNodeClick = () => { } const onChildNodeClick = (node: TreeNode) => emit('on-node-click', node) - + \ No newline at end of file From 50891238d5b3b343c91c62a387669cdd165a6c5d Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Fri, 10 Jan 2025 22:42:59 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=BB=84=E4=BB=B6(=E6=A0=91):=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=8A=82=E7=82=B9=E8=AE=BE=E7=BD=AE=20selected=20?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/components/view/tree.md | 1 + src/App.vue | 5 ++-- src/ui/tree/ShadcnTree.vue | 54 ++++++++++++++++++++++++++++++------ src/ui/tree/types.ts | 1 + 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/docs/components/view/tree.md b/docs/components/view/tree.md index 22ca9ff1..4f741784 100644 --- a/docs/components/view/tree.md +++ b/docs/components/view/tree.md @@ -379,6 +379,7 @@ const data = [ ['children', '子节点数据', 'array', '\[\]'], ['isLeaf', '是否为懒加载节点', 'boolean', 'false'], ['disabled', '是否禁用', 'boolean', 'false'], + ['selected', '是否选中', 'boolean', 'false'], ]"> diff --git a/src/App.vue b/src/App.vue index dd370de8..a00d9c83 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,7 +9,8 @@ \ No newline at end of file diff --git a/src/ui/button/ShadcnButton.vue b/src/ui/button/ShadcnButton.vue index 2a269b1b..c7b33201 100644 --- a/src/ui/button/ShadcnButton.vue +++ b/src/ui/button/ShadcnButton.vue @@ -166,11 +166,9 @@ const circleClass = computed(() => { const buttonProps = computed(() => ({ ...(props.to ? { link: props.to } : { type: props.submit ? 'submit' : props.reset ? 'reset' : 'button' }), class: [ - // Style 'inline-flex items-center justify-center whitespace-nowrap transition-colors', - // Size + 'w-fit', !props.circle && ButtonSize[finalSize.value], - // Type style with conditional hover props.ghost ? [ 'bg-transparent', @@ -180,12 +178,9 @@ const buttonProps = computed(() => ({ !props.disabled && !props.loading && getHoverClass.value ] : getTypeStyles.value, - // Rounded corners { 'rounded-full': props.round || props.circle }, { 'rounded-md': !props.round && !props.circle }, - // Rounded circleClass.value, - // State { 'opacity-50 cursor-not-allowed': props.loading || props.disabled } ], disabled: props.loading || props.disabled, From 23752db0bfe94e8b44ae2e900280404ec3279cc2 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Fri, 10 Jan 2025 23:36:57 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=BB=84=E4=BB=B6(=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=99=A8):=20=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/config.js | 6 +- docs/components/form/checkbox.md | 4 +- docs/components/form/radio.md | 4 +- docs/components/form/select.md | 149 ++++++------- docs/components/form/toggle.md | 8 +- docs/components/form/upload.md | 2 +- docs/components/layout/avatar.md | 4 +- docs/components/layout/card.md | 231 +++----------------- docs/components/layout/ellipsis.md | 2 +- docs/components/view/table.md | 4 +- docs/components/view/tag.md | 4 +- src/App.vue | 18 +- src/ui/select/ShadcnSelect.vue | 22 +- src/ui/select/types.ts | 1 + src/ui/skeleton/item/ShadcnSkeletonItem.vue | 2 +- 15 files changed, 136 insertions(+), 325 deletions(-) diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 48cadf3a..ad223997 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -149,7 +149,7 @@ export default { })(), (() => { const items = [ - {text: 'Card', link: 'layout/card', icon: '/components/layout/card.svg', version: '2024.1.1'}, + {text: '卡片 (Card)', link: 'layout/card', icon: '/components/layout/card.svg', version: '2024.1.1'}, {text: 'Row / Col', link: 'layout/row-col', icon: '/components/layout/row-col.svg', version: '2024.1.2'}, {text: 'Divider', link: 'layout/divider', icon: '/components/layout/divider.svg', version: '2024.1.2'}, {text: 'Ellipsis', link: 'layout/ellipsis', icon: '/components/layout/ellipsis.svg', version: '2024.1.2'}, @@ -163,7 +163,7 @@ export default { ] return { - text: `Layout [ ${items.length} ]`, + text: `布局组件 [ ${items.length} ]`, base: '/components/', collapsed: false, items: items.map(item => createSidebarItem(item)) @@ -212,7 +212,7 @@ export default { {text: 'Switch', link: 'form/switch', icon: '/components/form/switch.svg', version: '2024.1.2'}, {text: 'Radio', link: 'form/radio', icon: '/components/form/radio.svg', version: '2024.1.2'}, {text: 'Checkbox', link: 'form/checkbox', icon: '/components/form/checkbox.svg', version: '2024.1.2'}, - {text: 'Select', link: 'form/select', icon: '/components/form/select.svg', version: '2024.1.2'}, + {text: '选择器 (Select)', link: 'form/select', icon: '/components/form/select.svg', version: '2024.1.2'}, {text: 'Rate', link: 'form/rate', icon: '/components/form/rate.svg', version: '2024.1.2'}, {text: 'Form', link: 'form/form', icon: '/components/form/form.svg', version: '2024.2.0'}, {text: 'Slider', link: 'form/slider', icon: '/components/form/slider.svg', version: '2024.2.0'}, diff --git a/docs/components/form/checkbox.md b/docs/components/form/checkbox.md index b41b43b1..a4f969b5 100644 --- a/docs/components/form/checkbox.md +++ b/docs/components/form/checkbox.md @@ -109,9 +109,9 @@ const checked = ref('Primary') ::: -## Group +## 组 (group) - + Checkbox Group Value: {{ checkedGroup }} Vue diff --git a/docs/components/form/radio.md b/docs/components/form/radio.md index 43b92a9d..87e49a05 100644 --- a/docs/components/form/radio.md +++ b/docs/components/form/radio.md @@ -108,9 +108,9 @@ const checked = ref('Primary') ::: -## Group +## 组 (group) - + Checkbox Group Value: {{ checkedGroup }} ON diff --git a/docs/components/form/select.md b/docs/components/form/select.md index 151ab2ef..3564c480 100644 --- a/docs/components/form/select.md +++ b/docs/components/form/select.md @@ -1,15 +1,16 @@ --- -title: Shadcn Select +title: 选择器 (Select) --- # 介绍 -This document is mainly used to describe some features and usage of the ShadcnSelect and ShadcnSelectOption component. +
+ +本文档主要用于描述 `ShadcnSelect` 组件的一些特性和用法。 ## 用法 -

Select Value: {{ defaultSelect }}

@@ -37,7 +38,6 @@ const defaultSelectOptions = [ ## 禁用 (disabled) -

Select Value: {{ defaultSelect }}

@@ -62,52 +62,10 @@ const defaultSelectOptions = [ ::: -## Slot - - -

Select Value: {{ slotSelect }}

- - - -
- -::: details 查看代码 - -```vue - - - -``` - -::: - ## 尺寸 (size)
-

Select Value: {{ defaultSelect }}

@@ -142,7 +100,6 @@ const defaultSelectOptions = [
-

Select Value: {{ defaultSelect }}

@@ -175,13 +132,12 @@ const defaultSelectOptions = [ ::: -## Border +## 边框 (border) ::: raw - +
-

Select Value: {{ defaultSelect }}

@@ -212,11 +168,11 @@ const defaultSelectOptions = [ ::: -## Group +## 组 (group) ::: raw - +