chore: 更新表格选择器示例

This commit is contained in:
xiaoxian521 2024-01-11 19:39:10 +08:00
parent 9d965a7c63
commit 7b228f4784
7 changed files with 50 additions and 38 deletions

View File

@ -67,7 +67,7 @@
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"echarts": "^5.4.3", "echarts": "^5.4.3",
"el-table-infinite-scroll": "^3.0.3", "el-table-infinite-scroll": "^3.0.3",
"element-plus": "^2.5.0", "element-plus": "^2.5.1",
"intro.js": "^7.2.0", "intro.js": "^7.2.0",
"js-cookie": "^3.0.5", "js-cookie": "^3.0.5",
"jsbarcode": "^3.11.6", "jsbarcode": "^3.11.6",

22
pnpm-lock.yaml generated
View File

@ -19,10 +19,10 @@ dependencies:
version: 1.2.19 version: 1.2.19
'@pureadmin/descriptions': '@pureadmin/descriptions':
specifier: ^1.2.0 specifier: ^1.2.0
version: 1.2.0(element-plus@2.5.0)(typescript@5.3.3) version: 1.2.0(element-plus@2.5.1)(typescript@5.3.3)
'@pureadmin/table': '@pureadmin/table':
specifier: ^3.0.1 specifier: ^3.0.1
version: 3.0.1(element-plus@2.5.0)(typescript@5.3.3) version: 3.0.1(element-plus@2.5.1)(typescript@5.3.3)
'@pureadmin/utils': '@pureadmin/utils':
specifier: ^2.3.1 specifier: ^2.3.1
version: 2.3.1(echarts@5.4.3)(vue@3.4.7) version: 2.3.1(echarts@5.4.3)(vue@3.4.7)
@ -63,8 +63,8 @@ dependencies:
specifier: ^3.0.3 specifier: ^3.0.3
version: 3.0.3(typescript@5.3.3) version: 3.0.3(typescript@5.3.3)
element-plus: element-plus:
specifier: ^2.5.0 specifier: ^2.5.1
version: 2.5.0(vue@3.4.7) version: 2.5.1(vue@3.4.7)
intro.js: intro.js:
specifier: ^7.2.0 specifier: ^7.2.0
version: 7.2.0 version: 7.2.0
@ -1726,24 +1726,24 @@ packages:
resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==} resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==}
dev: false dev: false
/@pureadmin/descriptions@1.2.0(element-plus@2.5.0)(typescript@5.3.3): /@pureadmin/descriptions@1.2.0(element-plus@2.5.1)(typescript@5.3.3):
resolution: {integrity: sha512-k2A3SGGKf0eKrSQB3hXzgGlAz7DKSM31WN/QGBn37UCIHfQlIVrvSPEAF2omHlukQT2Artap6veCqBcJ9dGAKQ==} resolution: {integrity: sha512-k2A3SGGKf0eKrSQB3hXzgGlAz7DKSM31WN/QGBn37UCIHfQlIVrvSPEAF2omHlukQT2Artap6veCqBcJ9dGAKQ==}
peerDependencies: peerDependencies:
element-plus: ^2.0.0 element-plus: ^2.0.0
dependencies: dependencies:
'@element-plus/icons-vue': 2.3.1(vue@3.4.7) '@element-plus/icons-vue': 2.3.1(vue@3.4.7)
element-plus: 2.5.0(vue@3.4.7) element-plus: 2.5.1(vue@3.4.7)
vue: 3.4.7(typescript@5.3.3) vue: 3.4.7(typescript@5.3.3)
transitivePeerDependencies: transitivePeerDependencies:
- typescript - typescript
dev: false dev: false
/@pureadmin/table@3.0.1(element-plus@2.5.0)(typescript@5.3.3): /@pureadmin/table@3.0.1(element-plus@2.5.1)(typescript@5.3.3):
resolution: {integrity: sha512-DBIv0YRZogSIEtsBPNjm6tYuImaE8ZJXwAu/gutEyaH9wATN09doKDmAisyBj+XEydfM5R9hlvhQ8SzJkbtarA==} resolution: {integrity: sha512-DBIv0YRZogSIEtsBPNjm6tYuImaE8ZJXwAu/gutEyaH9wATN09doKDmAisyBj+XEydfM5R9hlvhQ8SzJkbtarA==}
peerDependencies: peerDependencies:
element-plus: ^2.0.0 element-plus: ^2.0.0
dependencies: dependencies:
element-plus: 2.5.0(vue@3.4.7) element-plus: 2.5.1(vue@3.4.7)
vue: 3.4.7(typescript@5.3.3) vue: 3.4.7(typescript@5.3.3)
transitivePeerDependencies: transitivePeerDependencies:
- typescript - typescript
@ -3959,7 +3959,7 @@ packages:
resolution: {integrity: sha512-cmMHg4MxrNOV2dFziV3ISRo+rM/3tAH8TE3wWMGKd4ucjvk21Bfb6MJfPuNAicLOkq4fYZm+J+mr0NmDPnvolQ==} resolution: {integrity: sha512-cmMHg4MxrNOV2dFziV3ISRo+rM/3tAH8TE3wWMGKd4ucjvk21Bfb6MJfPuNAicLOkq4fYZm+J+mr0NmDPnvolQ==}
dependencies: dependencies:
core-js: 3.35.0 core-js: 3.35.0
element-plus: 2.5.0(vue@3.4.7) element-plus: 2.5.1(vue@3.4.7)
vue: 3.4.7(typescript@5.3.3) vue: 3.4.7(typescript@5.3.3)
transitivePeerDependencies: transitivePeerDependencies:
- '@vue/composition-api' - '@vue/composition-api'
@ -3992,8 +3992,8 @@ packages:
- '@vue/composition-api' - '@vue/composition-api'
dev: false dev: false
/element-plus@2.5.0(vue@3.4.7): /element-plus@2.5.1(vue@3.4.7):
resolution: {integrity: sha512-NE58a5Exf0/vxgxRRR2Ibs7AjiqB72lMrg7plmSoZwgZy17IQAWgzOe7ZyRtEQM/3q3BAuJDTUUAuhP/mKVPKg==} resolution: {integrity: sha512-ylX9h2U125/nesPlLWgfPkI1rID9EiGROlgf0QkzBUjx+/d4w/YqS+IqZZZC5yvQPhKYu9aMDqEBzOurwn4Cnw==}
peerDependencies: peerDependencies:
vue: ^3.2.0 vue: ^3.2.0
dependencies: dependencies:

View File

@ -43,6 +43,16 @@ const tableData = [
date, date,
name: "Mike", name: "Mike",
address: "No. 189, Grove St, Los Angeles" address: "No. 189, Grove St, Los Angeles"
},
{
date,
name: "Mike1",
address: "No. 189, Grove St, Los Angeles"
},
{
date,
name: "Mike2",
address: "No. 189, Grove St, Los Angeles"
} }
]; ];
@ -70,24 +80,19 @@ const tableDataSortable = clone(tableData, true).map((item, index) => {
const tableDataDrag = clone(tableData, true).map((item, index) => { const tableDataDrag = clone(tableData, true).map((item, index) => {
delete item.address; delete item.address;
delete item.date; delete item.date;
return Object.assign( return Object.assign(item, {
{ id: index + 1,
id: index + 1, date: `${dayjs(new Date()).format("YYYY-MM")}-${index + 1}`
date: `${dayjs(new Date()).format("YYYY-MM")}-${index + 1}` });
},
item
);
}); });
const tableDataEdit = clone(tableData, true).map((item, index) => { const tableDataEdit = clone(tableData, true).map((item, index) => {
delete item.date; delete item.date;
return Object.assign( return Object.assign(item, {
{ id: index + 1,
id: index + 1, date: `${dayjs(new Date()).format("YYYY-MM")}-${index + 1}`,
date: `${dayjs(new Date()).format("YYYY-MM")}-${index + 1}` address: "China"
}, });
item
);
}); });
export { export {

View File

@ -1,3 +1,4 @@
import { message } from "@/utils/message";
import { tableDataEdit } from "../../data"; import { tableDataEdit } from "../../data";
import { ref, reactive, type Ref } from "vue"; import { ref, reactive, type Ref } from "vue";
import type { PaginationProps } from "@pureadmin/table"; import type { PaginationProps } from "@pureadmin/table";
@ -7,6 +8,7 @@ export function useColumns(selectRef: Ref, tableRef: Ref) {
const columns: TableColumnList = [ const columns: TableColumnList = [
{ {
type: "selection", type: "selection",
reserveSelection: true,
align: "left" align: "left"
}, },
{ {
@ -16,7 +18,8 @@ export function useColumns(selectRef: Ref, tableRef: Ref) {
}, },
{ {
label: "日期", label: "日期",
prop: "date" prop: "date",
minWidth: 120
}, },
{ {
label: "姓名", label: "姓名",
@ -30,7 +33,7 @@ export function useColumns(selectRef: Ref, tableRef: Ref) {
/** 分页配置 */ /** 分页配置 */
const pagination = reactive<PaginationProps>({ const pagination = reactive<PaginationProps>({
pageSize: 10, pageSize: 5,
currentPage: 1, currentPage: 1,
layout: "prev, pager, next", layout: "prev, pager, next",
total: tableDataEdit.length, total: tableDataEdit.length,
@ -41,15 +44,14 @@ export function useColumns(selectRef: Ref, tableRef: Ref) {
const handleSelectionChange = val => { const handleSelectionChange = val => {
const arr = []; const arr = [];
val.forEach(v => { val.forEach(v => {
arr.push(v.name); arr.push({ label: v.name, id: v.id });
}); });
selectValue.value = arr; selectValue.value = arr;
}; };
const removeTag = val => { const removeTag = ({ id }) => {
// TODO optimize el-select add formatter
const { toggleRowSelection } = tableRef.value.getTableRef(); const { toggleRowSelection } = tableRef.value.getTableRef();
toggleRowSelection(tableDataEdit.filter(v => v.name === val)[0], false); toggleRowSelection(tableDataEdit.filter(v => v.id == id)?.[0], false);
}; };
const onClear = () => { const onClear = () => {
@ -59,6 +61,9 @@ export function useColumns(selectRef: Ref, tableRef: Ref) {
const onSure = () => { const onSure = () => {
selectRef.value.blur(); selectRef.value.blur();
message(`当前选中的数据为:${JSON.stringify(selectValue.value)}`, {
type: "success"
});
}; };
return { return {

View File

@ -25,16 +25,16 @@ const {
clearable clearable
multiple multiple
collapse-tags collapse-tags
collapse-tags-tooltip value-key="id"
@remove-tag="removeTag" @remove-tag="removeTag"
@clear="onClear" @clear="onClear"
> >
<template #empty> <template #empty>
<div class="w-[600px] m-4"> <div class="m-4">
<pure-table <pure-table
ref="tableRef" ref="tableRef"
height="355"
row-key="id" row-key="id"
alignWhole="center"
:header-cell-style="{ :header-cell-style="{
background: '#f5f7fa', background: '#f5f7fa',
color: '#303133' color: '#303133'

View File

@ -13,7 +13,8 @@ export function useColumns(selectRef: Ref) {
}, },
{ {
label: "日期", label: "日期",
prop: "date" prop: "date",
minWidth: 120
}, },
{ {
label: "姓名", label: "姓名",

View File

@ -19,13 +19,14 @@ const {
v-model="selectValue" v-model="selectValue"
class="!w-[200px]" class="!w-[200px]"
placeholder="请选择" placeholder="请选择"
value-key="id"
clearable clearable
> >
<template #empty> <template #empty>
<div class="w-[600px] m-4"> <div class="m-4">
<pure-table <pure-table
height="355"
row-key="id" row-key="id"
alignWhole="center"
:header-cell-style="{ :header-cell-style="{
background: '#f5f7fa', background: '#f5f7fa',
color: '#303133' color: '#303133'