-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid-select): add single/multiple select
- Loading branch information
Showing
10 changed files
with
241 additions
and
29 deletions.
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
8 changes: 4 additions & 4 deletions
8
examples/sites/demos/pc/app/grid-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
21 changes: 13 additions & 8 deletions
21
examples/sites/demos/pc/app/grid-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 |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
test('测试基本用法', async ({ page }) => { | ||
test('测试下拉表格单选', async ({ page }) => { | ||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
await page.goto('tree-select#basic-usage') | ||
await page.goto('grid-select#basic-usage') | ||
|
||
const wrap = page.locator('#basic-usage') | ||
const select = wrap.locator('.tiny-tree-select').nth(0) | ||
const select = wrap.locator('.tiny-grid-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') | ||
const suffixSvg = select.locator('.tiny-base-select__caret') | ||
const row = dropdown.getByRole('row') | ||
|
||
await expect(suffixSvg).toHaveCount(1) | ||
await expect(suffixSvg).toBeVisible() | ||
|
||
await input.click() | ||
await expect(treeNode).toHaveCount(7) | ||
await expect(dropdown).toBeVisible() | ||
await expect(row).toHaveCount(6) | ||
|
||
await treeNode.filter({ hasText: /^二级 2-1$/ }).click() | ||
await expect(input).toHaveValue('二级 2-1') | ||
await row.nth(1).getByRole('cell').first().click() | ||
await expect(input).toHaveValue('广州市') | ||
await input.click() | ||
await expect(treeNode.filter({ hasText: /^二级 2-1$/ })).toHaveClass(/is-current/) | ||
await expect(row.filter({ hasText: '广州市' })).toHaveClass(/tiny-grid-body__row row__radio/) | ||
}) |
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
38 changes: 38 additions & 0 deletions
38
examples/sites/demos/pc/app/grid-select/multiple-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,38 @@ | ||
<template> | ||
<tiny-grid-select | ||
v-model="value" | ||
multiple | ||
:grid-op="gridOpMulti" | ||
value-field="id" | ||
text-field="city" | ||
></tiny-grid-select> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, reactive } from 'vue' | ||
import { GridSelect as TinyGridSelect } from '@opentiny/vue' | ||
const value = ref('') | ||
const gridOpMulti = reactive({ | ||
data: [ | ||
{ id: '001', area: '华南区', province: '广东省', city: '广州市' }, | ||
{ id: '002', area: '华南区', province: '广东省', city: '深圳市' }, | ||
{ id: '003', area: '华南区', province: '广东省', city: '珠海市' }, | ||
{ id: '004', area: '华南区', province: '广东省', city: '佛山市' }, | ||
{ id: '005', area: '华南区', province: '广东省', city: '中山市' } | ||
], | ||
columns: [ | ||
{ type: 'selection', title: '' }, | ||
{ field: 'area', title: '区域', width: 90 }, | ||
{ field: 'province', title: '省份', width: 60 }, | ||
{ field: 'city', title: '城市', width: 60 } | ||
] | ||
}) | ||
</script> | ||
|
||
<style scoped> | ||
.tiny-grid-select { | ||
width: 280px; | ||
} | ||
</style> |
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,45 @@ | ||
<template> | ||
<tiny-grid-select | ||
v-model="value" | ||
multiple | ||
:grid-op="gridOpMulti" | ||
value-field="id" | ||
text-field="city" | ||
></tiny-grid-select> | ||
</template> | ||
|
||
<script> | ||
import { TinyGridSelect } from '@opentiny/vue' | ||
export default { | ||
components: { | ||
TinyGridSelect | ||
}, | ||
data() { | ||
return { | ||
value: '', | ||
treeOp: { | ||
data: [ | ||
{ id: '001', area: '华南区', province: '广东省', city: '广州市' }, | ||
{ id: '002', area: '华南区', province: '广东省', city: '深圳市' }, | ||
{ id: '003', area: '华南区', province: '广东省', city: '珠海市' }, | ||
{ id: '004', area: '华南区', province: '广东省', city: '佛山市' }, | ||
{ id: '005', area: '华南区', province: '广东省', city: '中山市' } | ||
], | ||
columns: [ | ||
{ type: 'selection', title: '' }, | ||
{ field: 'area', title: '区域', width: 90 }, | ||
{ field: 'province', title: '省份', width: 60 }, | ||
{ field: 'city', title: '城市', width: 60 } | ||
] | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.tiny-grid-select { | ||
width: 280px; | ||
} | ||
</style> |
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 radioChange = | ||
({ props, vm, emit }) => | ||
({ row }) => { | ||
if (!props.multiple) { | ||
vm.$refs.baseSelectRef.updateSelectedData({ | ||
...row, | ||
currentLabel: row[props.textField], | ||
value: row[props.valueField], | ||
state: { | ||
currentLabel: row[props.textField] | ||
} | ||
}) | ||
|
||
vm.$refs.baseSelectRef.hidePanel() | ||
|
||
emit('update:modelValue', row) | ||
emit('change', row) | ||
} | ||
} | ||
|
||
export const selectChange = | ||
({ props, vm, emit }) => | ||
({ $table, selection, checked, row }) => { | ||
if (props.multiple) { | ||
vm.$refs.baseSelectRef.updateSelectedData( | ||
selection.map((node) => { | ||
return { | ||
...node, | ||
currentLabel: node[props.textField], | ||
value: node[props.valueField] | ||
} | ||
}) | ||
) | ||
|
||
emit('update:modelValue', selection) | ||
emit('change', selection) | ||
} | ||
} |
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