1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
| <template>
| <div class="scope">
| <div class="h">
| <el-tag size="small" effect="dark" disable-transitions>select-table</el-tag>
| <span>选择表格</span>
| </div>
|
| <div class="c">
| <el-button @click="open">预览</el-button>
| <demo-code :files="['crud/select-table.vue']" />
|
| <!-- 自定义表格组件 -->
| <cl-form ref="Form" />
| </div>
|
| <div class="f">
| <span class="date">2025-02-07</span>
| </div>
| </div>
| </template>
|
| <script setup lang="ts">
| import { useForm } from '@cool-vue/crud';
| import { useCool } from '/@/cool';
|
| const { service, refs, setRefs } = useCool();
| const Form = useForm();
|
| const columns = [
| {
| label: '头像',
| prop: 'avatarUrl',
| component: {
| name: 'cl-avatar'
| }
| },
| {
| label: '昵称',
| prop: 'nickName'
| },
| {
| label: '创建时间',
| prop: 'createTime'
| }
| ];
|
| function open() {
| Form.value?.open({
| width: '800px',
| title: '选择表格',
| items: [
| {
| label: '多选 - default',
| prop: 'a',
| value: [],
| component: {
| name: 'cl-select-table',
| props: {
| pickerType: 'default',
| multiple: true,
| columns,
| service: service.user.info
| }
| },
| span: 12
| },
| {
| label: '单选 - default',
| prop: 'b',
| component: {
| name: 'cl-select-table',
| props: {
| pickerType: 'default',
| multiple: false,
| columns,
| service: service.user.info
| }
| },
| span: 12
| },
| {
| label: '多选 - text',
| prop: 'c',
| value: [],
| component: {
| name: 'cl-select-table',
| props: {
| pickerType: 'text',
| multiple: true,
| columns,
| service: service.user.info
| }
| },
| span: 12
| },
| {
| label: '单选 - text',
| prop: 'd',
| component: {
| name: 'cl-select-table',
| props: {
| pickerType: 'text',
| multiple: false,
| columns,
| service: service.user.info
| }
| },
| span: 12
| },
| {
| label: '回显',
| prop: 'f',
| component: {
| name: 'cl-select-table',
| props: {
| pickerType: 'default',
| multiple: false,
| columns,
| service: service.user.info
| },
| // 【很重要】设置 ref
| ref: setRefs('selectTable')
| }
| },
| {
| label: '多选 - table',
| prop: 'e',
| value: [],
| component: {
| name: 'cl-select-table',
| props: {
| pickerType: 'table',
| multiple: true,
| columns,
| service: service.user.info
| }
| }
| }
| ],
| // useUpsert 中使用 onOpened
| on: {
| open() {
| // 【很重要】设置回显,实际根据接口返回
| refs.selectTable?.set([
| {
| id: 1,
| avatarUrl: 'http://....',
| nickName: '橘子'
| }
| ]);
| }
| }
| });
| }
| </script>
|
|