-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tree-select): [tree-select] add tree-select component (#1683)
* feat(tree-select): add tree-select component * refactor(tree-select): obtain updateSelectedData/hidePanel from baseSelectRef
- Loading branch information
Showing
15 changed files
with
484 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
export default { | ||
mode: ['pc'], | ||
apis: [ | ||
{ | ||
name: 'tree-select', | ||
type: 'component', | ||
props: [ | ||
{ | ||
name: 'clearable', | ||
type: 'boolean', | ||
defaultValue: 'false', | ||
desc: { | ||
'zh-CN': '是否启用一键清除的功能', | ||
'en-US': 'Whether to display the one click clear button, only applicable to radio selection' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'filter' | ||
}, | ||
{ | ||
name: 'filter-method', | ||
type: '(query: string) => void', | ||
defaultValue: '', | ||
desc: { | ||
'zh-CN': '自定义过滤方法', | ||
'en-US': 'Custom filtering method' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'filter' | ||
}, | ||
{ | ||
name: 'filterable', | ||
type: 'boolean', | ||
defaultValue: 'false', | ||
desc: { | ||
'zh-CN': '是否可搜索', | ||
'en-US': 'Is it searchable' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'filter' | ||
}, | ||
{ | ||
name: 'modelValue / v-model', | ||
type: 'string | number | Array<string|number>', | ||
defaultValue: '', | ||
desc: { | ||
'zh-CN': '绑定值', | ||
'en-US': 'Bind value' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'basic-usage' | ||
}, | ||
{ | ||
name: 'multiple', | ||
type: 'boolean', | ||
defaultValue: 'false', | ||
desc: { | ||
'zh-CN': '是否允许选择多个选项', | ||
'en-US': 'Allow multiple options to be selected' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'multiple' | ||
}, | ||
{ | ||
name: 'text-field', | ||
type: 'string', | ||
defaultValue: "'label'", | ||
desc: { | ||
'zh-CN': '显示值字段', | ||
'en-US': 'Show Value Fields' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'map-field' | ||
}, | ||
{ | ||
name: 'tree-op', | ||
typeAnchorName: 'ITreeOption', | ||
type: 'ITreeOption', | ||
defaultValue: '', | ||
desc: { | ||
'zh-CN': '下拉树时,内置树组件的配置,用法同 Tree 组件。', | ||
'en-US': | ||
'When pulling down a tree, the configuration of the built-in tree component is the same as that of the Tree component. To be used in conjunction with the render type attribute' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'basic-usage' | ||
}, | ||
{ | ||
name: 'value-field', | ||
type: 'string', | ||
defaultValue: "'value'", | ||
desc: { | ||
'zh-CN': '绑定值字段', | ||
'en-US': 'Bind Value Field' | ||
}, | ||
mode: ['pc'], | ||
pcDemo: 'map-field' | ||
} | ||
] | ||
} | ||
], | ||
types: [ | ||
{ | ||
name: 'ITreeOption', | ||
type: 'interface', | ||
code: ` | ||
interface ITreeNode { | ||
label: string // 默认树节点的文本字段 | ||
id: number|string // 树节点唯一标识 | ||
children: ITreeNode[] // 子节点 | ||
} | ||
interface ITreeOption { | ||
data: ITreeNode[] // 树数据,用法同 Tree | ||
} | ||
` | ||
} | ||
] | ||
} |
55 changes: 55 additions & 0 deletions
55
examples/sites/demos/pc/app/tree-select/basic-usage-composition-api.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template> | ||
<tiny-tree-select v-model="value" :tree-op="treeOp"></tiny-tree-select> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
import { TreeSelect as TinyTreeSelect } from '@opentiny/vue' | ||
const value = ref('') | ||
const treeOp = ref({ | ||
data: [ | ||
{ | ||
value: 1, | ||
label: '一级 1', | ||
children: [ | ||
{ | ||
value: 4, | ||
label: '二级 1-1', | ||
children: [ | ||
{ | ||
value: 9, | ||
label: '三级 1-1-1' | ||
}, | ||
{ | ||
value: 10, | ||
label: '三级 1-1-2' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
value: 2, | ||
label: '一级 2', | ||
children: [ | ||
{ | ||
value: 5, | ||
label: '二级 2-1' | ||
}, | ||
{ | ||
value: 6, | ||
label: '二级 2-2' | ||
} | ||
] | ||
} | ||
] | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
.tiny-tree-select { | ||
width: 280px; | ||
} | ||
</style> |
20 changes: 20 additions & 0 deletions
20
examples/sites/demos/pc/app/tree-select/basic-usage.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
test('测试基本用法', async ({ page }) => { | ||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
await page.goto('tree-select#basic-usage') | ||
|
||
const wrap = page.locator('#basic-usage') | ||
const select = wrap.locator('.tiny-tree-select').nth(0) | ||
const input = select.locator('.tiny-input__inner') | ||
const dropdown = page.locator('body > .tiny-select-dropdown') | ||
const treeNode = dropdown.locator('.tiny-tree-node') | ||
|
||
await input.click() | ||
await expect(treeNode).toHaveCount(7) | ||
|
||
await treeNode.filter({ hasText: /^二级 2-1$/ }).click() | ||
await expect(input).toHaveValue('二级 2-1') | ||
await input.click() | ||
await expect(treeNode.filter({ hasText: /^二级 2-1$/ })).toHaveClass(/is-current/) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<template> | ||
<tiny-tree-select v-model="value" :tree-op="treeOp"></tiny-tree-select> | ||
</template> | ||
|
||
<script> | ||
import { TreeSelect } from '@opentiny/vue' | ||
export default { | ||
components: { | ||
TinyTreeSelect: TreeSelect | ||
}, | ||
data() { | ||
return { | ||
treeOp: { | ||
data: [ | ||
{ | ||
value: 1, | ||
label: '一级 1', | ||
children: [ | ||
{ | ||
value: 4, | ||
label: '二级 1-1', | ||
children: [ | ||
{ | ||
value: 9, | ||
label: '三级 1-1-1' | ||
}, | ||
{ | ||
value: 10, | ||
label: '三级 1-1-2' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
value: 2, | ||
label: '一级 2', | ||
children: [ | ||
{ | ||
value: 5, | ||
label: '二级 2-1' | ||
}, | ||
{ | ||
value: 6, | ||
label: '二级 2-2' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.tiny-tree-select { | ||
width: 280px; | ||
} | ||
</style> |
7 changes: 7 additions & 0 deletions
7
examples/sites/demos/pc/app/tree-select/webdoc/tree-select.cn.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: TreeSelect 树形选择器 | ||
--- | ||
|
||
# TreeSelect 树形选择器 | ||
|
||
结合了 BaseSelect 和 Tree 组件的选择器,用于从一个下拉树中选择一个或多个选项。 |
7 changes: 7 additions & 0 deletions
7
examples/sites/demos/pc/app/tree-select/webdoc/tree-select.en.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: TreeSelect | ||
--- | ||
|
||
# TreeSelect | ||
|
||
A selector that combines the BaseSelect and Tree components to select one or more options from a drop-down tree. |
18 changes: 18 additions & 0 deletions
18
examples/sites/demos/pc/app/tree-select/webdoc/tree-select.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default { | ||
column: '2', | ||
owner: '', | ||
demos: [ | ||
{ | ||
demoId: 'basic-usage', | ||
name: { | ||
'zh-CN': '基本用法', | ||
'en-US': 'Basic Usage' | ||
}, | ||
desc: { | ||
'zh-CN': '<p>最基础的用法,通过 <code>tree-op</code> 设置下拉树的数据源,<code>v-model</code> 设置绑定值。</p>', | ||
'en-US': '' | ||
}, | ||
codeFiles: ['basic-usage.vue'] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export const filter = | ||
({ vm }) => | ||
(value) => { | ||
vm.$refs.treeRef.filter(value) | ||
} | ||
|
||
export const nodeClick = | ||
({ props, vm }) => | ||
(data) => { | ||
if (!props.multiple) { | ||
vm.$refs.baseSelectRef.updateSelectedData({ | ||
...data, | ||
currentLabel: data[props.textField], | ||
value: data[props.valueField], | ||
state: { | ||
currentLabel: data[props.textField] | ||
} | ||
}) | ||
|
||
vm.$refs.baseSelectRef.hidePanel() | ||
} | ||
} | ||
|
||
export const check = | ||
({ props }) => | ||
(data, { checkedNodes }) => { | ||
if (props.multiple) { | ||
vm.$refs.baseSelectRef.updateSelectedData( | ||
checkedNodes.map((node) => { | ||
return { | ||
...node, | ||
currentLabel: node[props.textField], | ||
value: node[props.valueField] | ||
} | ||
}) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { filter, nodeClick, check } from './index' | ||
|
||
export const api = ['state', 'filter', 'nodeClick', 'check'] | ||
|
||
export const renderless = (props, { reactive }, { vm }) => { | ||
const api = {} | ||
|
||
const state = reactive({ | ||
value: props.modelValue, | ||
treeData: props.treeOp.data | ||
}) | ||
|
||
Object.assign(api, { | ||
state, | ||
filter: filter({ vm }), | ||
nodeClick: nodeClick({ props, vm }), | ||
check: check({ props }) | ||
}) | ||
|
||
return api | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.