@yidun/antd-super-table 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,315 @@
1
+ <script setup lang="ts">
2
+ // 表格组件示例
3
+ import { onMounted, ref } from 'vue'
4
+ import { Modal } from 'ant-design-vue'
5
+ import Mock from 'mockjs'
6
+ import { useLocalStorage } from '@vueuse/core'
7
+ // import SuperTable from '../src/index'
8
+ import SuperTable from '../'
9
+
10
+ import { createTableColumns } from './tableColumns'
11
+ import { createFormItems } from './formItems'
12
+
13
+ const tableRef = ref<InstanceType<typeof SuperTable>>()
14
+ // 查询条件配置
15
+ const formItems: any = createFormItems()
16
+
17
+ // 表头配置
18
+ const tableColumns: any = createTableColumns({
19
+ onDelete,
20
+ })
21
+
22
+ const setting = useLocalStorage('super-table-example-config', {
23
+ enableScene: false,
24
+ enableTableConfig: false,
25
+ sortable: false,
26
+ showRefreshButton: false,
27
+ showSceneAddonBefore: false,
28
+ showSceneAddonAfter: false,
29
+ showExtra: false,
30
+ showTableHead: false,
31
+ showToolBar: false,
32
+ showTableFoot: false,
33
+ formItemColSpan: 6,
34
+ })
35
+
36
+ // 表单项变更事件处理
37
+ function onFormItemChange(name: string, value: any, formItem: any, formOperations: any, tableOperations: any) {
38
+ console.log('form-item-change 事件触发:', {
39
+ name,
40
+ value,
41
+ formItem,
42
+ formOperations: {
43
+ // 验证表单操作方法是否可用
44
+ hasGetFormItem: typeof formOperations.getFormItem === 'function',
45
+ hasSetFormItem: typeof formOperations.setFormItem === 'function',
46
+ hasGetFormValues: typeof formOperations.getFormValues === 'function',
47
+ hasSetFormValues: typeof formOperations.setFormValues === 'function',
48
+ hasGetFormValue: typeof formOperations.getFormValue === 'function',
49
+ hasSetFormValue: typeof formOperations.setFormValue === 'function',
50
+ },
51
+ tableOperations: {
52
+ // 验证表格操作方法是否可用
53
+ hasGetTableData: typeof tableOperations.getTableData === 'function',
54
+ hasSetTableData: typeof tableOperations.setTableData === 'function',
55
+ hasSetTableDataItem: typeof tableOperations.setTableDataItem === 'function',
56
+ },
57
+ })
58
+
59
+ // 演示使用表单操作方法
60
+ if (formOperations.getFormValue) {
61
+ const currentValue = formOperations.getFormValue(name)
62
+ console.log(`当前 ${name} 的值:`, currentValue)
63
+ }
64
+
65
+ // 演示使用表格操作方法
66
+ if (tableOperations.getTableData) {
67
+ const tableData = tableOperations.getTableData()
68
+ console.log('当前表格数据条数:', tableData.length)
69
+ }
70
+ }
71
+
72
+ // 自定义生成中文段落
73
+ const randomParagraph = () => Mock.mock('@cword(10, 15)、@cword(10, 20)、@cword(3, 40)。')
74
+
75
+ // 数据查询方法
76
+ async function onRequest(options: Record<string, any>) {
77
+ console.log('onRequest', options)
78
+ await new Promise(resolve => {
79
+ setTimeout(resolve, 300)
80
+ })
81
+ const { pageSize } = options
82
+
83
+ const imageList = [
84
+ 'https://aliyuncdn.antdv.com/vue.png',
85
+ 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
86
+ 'https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg',
87
+ 'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
88
+ 'https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg',
89
+ 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
90
+ '',
91
+ ]
92
+ return Promise.resolve({
93
+ total: pageSize * 4 + 12,
94
+ data: Array.from({
95
+ length: pageSize,
96
+ }).map((_, index) => ({
97
+ id: index,
98
+ text: randomParagraph(),
99
+ textList: [randomParagraph(), randomParagraph(), randomParagraph()],
100
+ imageSrc: imageList[index % imageList.length],
101
+ imageList: Array.from({
102
+ length: Mock.Random.natural(0, 6),
103
+ }).map((_, index) => imageList[index % imageList.length]),
104
+ })),
105
+ })
106
+ }
107
+
108
+ // 删除
109
+ function onDelete() {
110
+ Modal.confirm({
111
+ title: '提示',
112
+ content: '确定删除?',
113
+ onOk: () => {
114
+ console.log('删除')
115
+ },
116
+ })
117
+ }
118
+
119
+ // 运行时设置查询项,以修改select options为例
120
+ const handleUpdateSelectOptions = () => {
121
+ if (!tableRef.value) return
122
+
123
+ const { setFormItem, setFormValue } = tableRef.value
124
+
125
+ // 修改可选项
126
+ setFormItem('select', 'props.options', [
127
+ {
128
+ label: '色情',
129
+ value: 100,
130
+ },
131
+ {
132
+ label: '涉政',
133
+ value: 500,
134
+ },
135
+ ])
136
+
137
+ // 修改查询详对应的值
138
+ setFormValue('select', 100)
139
+ }
140
+
141
+ onMounted(() => {
142
+ handleUpdateSelectOptions()
143
+
144
+ // 监听组件初始化完成
145
+ const checkInitialized = () => {
146
+ if (tableRef.value?.isInitialized) {
147
+ console.log('SuperTable 组件已初始化完成')
148
+ } else {
149
+ // 如果还没初始化完成,继续检查
150
+ setTimeout(checkInitialized, 100)
151
+ }
152
+ }
153
+ checkInitialized()
154
+ })
155
+ </script>
156
+
157
+ <template>
158
+ <div>
159
+ <a-form
160
+ layout="inline"
161
+ :class="$style.form"
162
+ >
163
+ <a-form-item label="场景">
164
+ <a-switch
165
+ v-model:checked="setting.enableScene"
166
+ checked-children="开启"
167
+ un-checked-children="关闭"
168
+ />
169
+ </a-form-item>
170
+ <a-form-item label="排序">
171
+ <a-switch
172
+ v-model:checked="setting.sortable"
173
+ checked-children="开启"
174
+ un-checked-children="关闭"
175
+ />
176
+ </a-form-item>
177
+ <a-form-item label="刷新按钮">
178
+ <a-switch
179
+ v-model:checked="setting.showRefreshButton"
180
+ :disabled="!setting.enableScene"
181
+ checked-children="展示"
182
+ un-checked-children="隐藏"
183
+ />
184
+ </a-form-item>
185
+ <a-form-item label="配置按钮">
186
+ <a-switch
187
+ v-model:checked="setting.enableTableConfig"
188
+ checked-children="开启"
189
+ un-checked-children="关闭"
190
+ />
191
+ </a-form-item>
192
+ <a-form-item label="sceneAddonBefore">
193
+ <a-switch
194
+ v-model:checked="setting.showSceneAddonBefore"
195
+ checked-children="展示"
196
+ un-checked-children="隐藏"
197
+ />
198
+ </a-form-item>
199
+ <a-form-item label="sceneAddonAfter">
200
+ <a-switch
201
+ v-model:checked="setting.showSceneAddonAfter"
202
+ checked-children="展示"
203
+ un-checked-children="隐藏"
204
+ />
205
+ </a-form-item>
206
+ <a-form-item label="extra">
207
+ <a-switch
208
+ v-model:checked="setting.showExtra"
209
+ checked-children="展示"
210
+ un-checked-children="隐藏"
211
+ />
212
+ </a-form-item>
213
+ <a-form-item label="tableHead">
214
+ <a-switch
215
+ v-model:checked="setting.showTableHead"
216
+ checked-children="展示"
217
+ un-checked-children="隐藏"
218
+ />
219
+ </a-form-item>
220
+ <a-form-item label="toolBar">
221
+ <a-switch
222
+ v-model:checked="setting.showToolBar"
223
+ checked-children="展示"
224
+ un-checked-children="隐藏"
225
+ />
226
+ </a-form-item>
227
+ <a-form-item label="tableFoot">
228
+ <a-switch
229
+ v-model:checked="setting.showTableFoot"
230
+ checked-children="展示"
231
+ un-checked-children="隐藏"
232
+ />
233
+ </a-form-item>
234
+ <a-form-item label="formItemColSpan">
235
+ <a-radio-group v-model:value="setting.formItemColSpan">
236
+ <a-radio :value="4">4</a-radio>
237
+ <a-radio :value="6">6</a-radio>
238
+ <a-radio :value="8">8</a-radio>
239
+ <a-radio :value="12">12</a-radio>
240
+ </a-radio-group>
241
+ </a-form-item>
242
+ </a-form>
243
+ <super-table
244
+ ref="tableRef"
245
+ scene-type="super-table-example"
246
+ :form-items="formItems"
247
+ :columns="tableColumns"
248
+ :request="onRequest"
249
+ :sortable="setting.sortable"
250
+ :enable-table-config="setting.enableTableConfig"
251
+ :enable-scene="setting.enableScene"
252
+ :show-refresh-button="setting.showRefreshButton"
253
+ :form-item-col-span="setting.formItemColSpan"
254
+ :table-props="{
255
+ scroll: {
256
+ y: 600,
257
+ },
258
+ }"
259
+ @form-item-change="onFormItemChange"
260
+ >
261
+ <template
262
+ v-if="setting.showSceneAddonBefore"
263
+ #sceneAddonBefore
264
+ >
265
+ <div :class="$style.block">sceneAddonBefore</div>
266
+ </template>
267
+ <template
268
+ v-if="setting.showSceneAddonAfter"
269
+ #sceneAddonAfter
270
+ >
271
+ <div :class="$style.block">sceneAddonAfter</div>
272
+ </template>
273
+ <template
274
+ v-if="setting.showExtra"
275
+ #extra
276
+ >
277
+ <div :class="$style.block">extra</div>
278
+ </template>
279
+ <template
280
+ v-if="setting.showTableHead"
281
+ #tableHead
282
+ >
283
+ <div :class="$style.block">tableHead</div>
284
+ </template>
285
+ <template
286
+ v-if="setting.showToolBar"
287
+ #toolBarExtra
288
+ >
289
+ <div :class="$style.block">toolBarExtra</div>
290
+ </template>
291
+ <template
292
+ v-if="setting.showTableFoot"
293
+ #tableFoot
294
+ >
295
+ <div :class="$style.block">tableFoot</div>
296
+ </template>
297
+ </super-table>
298
+ </div>
299
+ </template>
300
+
301
+ <style module lang="scss">
302
+ .block {
303
+ height: 32px;
304
+ background-color: #fafafa;
305
+ border: 1px dashed #ededed;
306
+ padding: 0 16px;
307
+ line-height: 32px;
308
+ }
309
+
310
+ .form {
311
+ padding: 16px;
312
+ background-color: #fafafa;
313
+ border-bottom: 1px solid #ededed;
314
+ }
315
+ </style>
@@ -0,0 +1,5 @@
1
+ import { createApp } from 'vue'
2
+ import Example from './index.vue'
3
+ import Antd from 'ant-design-vue'
4
+
5
+ createApp(Example).use(Antd).mount('#app')
@@ -0,0 +1,183 @@
1
+ import { Input, message } from 'ant-design-vue'
2
+ import Mock from 'mockjs'
3
+
4
+ /**
5
+ * @description 初始化表单配置,操作类方法可通过参数传递进来
6
+ * @param { object } options 一些提供给表格内置组件使用的扩展
7
+ *
8
+ * */
9
+ export const createTableColumns = (options: {
10
+ onDelete: (record: Record<string, any>) => void
11
+ }) => {
12
+ return [
13
+ {
14
+ key: 'id',
15
+ title: 'ID',
16
+ type: 'text',
17
+ content: 'id',
18
+ width: 80,
19
+ fixed: 'left',
20
+ },
21
+ {
22
+ key: 'index',
23
+ title: '序号',
24
+ type: 'text',
25
+ content: (record: any, index: number) => index + 1,
26
+ width: 80,
27
+ fixed: 'left',
28
+ },
29
+ {
30
+ key: 'text',
31
+ title: '文本',
32
+ type: 'text',
33
+ content: 'text',
34
+ width: 150,
35
+ titleTooltip: '标题提示信息',
36
+ },
37
+ {
38
+ key: 'textList',
39
+ title: '文本列表',
40
+ content: 'textList',
41
+ width: 150,
42
+ },
43
+ {
44
+ key: 'image',
45
+ type: 'image',
46
+ title: '图片',
47
+ content: 'imageSrc',
48
+ },
49
+ {
50
+ key: 'imageList',
51
+ type: 'image',
52
+ title: '图片列表',
53
+ content: 'imageList',
54
+ width: 200,
55
+ visible: false,
56
+ },
57
+ {
58
+ key: 'tag',
59
+ type: 'tag',
60
+ title: '标签',
61
+ width: 120,
62
+ content() {
63
+ return {
64
+ label: '标签',
65
+ color: 'blue',
66
+ }
67
+ },
68
+ },
69
+ {
70
+ key: 'tagList',
71
+ type: 'tag',
72
+ title: '标签列表',
73
+ width: 200,
74
+ content() {
75
+ return [
76
+ {
77
+ label: '色情',
78
+ color: 'red',
79
+ },
80
+ {
81
+ label: '违禁',
82
+ color: 'blue',
83
+ },
84
+ {
85
+ label: '暴恐',
86
+ color: '#f00',
87
+ },
88
+ {
89
+ label: '涉政',
90
+ color: 'pink',
91
+ },
92
+ ]
93
+ },
94
+ },
95
+ {
96
+ key: 'button',
97
+ type: 'button',
98
+ title: '按钮',
99
+ content() {
100
+ return {
101
+ label: Mock.mock('@cword(2, 4)'),
102
+ onClick() {
103
+ message.info('click')
104
+ },
105
+ }
106
+ },
107
+ },
108
+ {
109
+ key: 'link',
110
+ type: 'link',
111
+ title: '链接',
112
+ content() {
113
+ return {
114
+ label: Mock.mock('@cword(2,8)'),
115
+ to: location.href,
116
+ }
117
+ },
118
+ },
119
+ {
120
+ key: 'custom',
121
+ title: '自定义组件',
122
+ type: 'component',
123
+ component: Input,
124
+ width: 200,
125
+ props: {
126
+ placeholder: '请输入',
127
+ style: {
128
+ width: '120px',
129
+ },
130
+ onChange() {
131
+ console.log('change')
132
+ },
133
+ },
134
+ },
135
+ {
136
+ key: 'status',
137
+ title: '状态',
138
+ type: 'text',
139
+ content: () => Mock.mock('@pick(["启用", "禁用", "待审核"])'),
140
+ width: 100,
141
+ fixed: 'right',
142
+ },
143
+ {
144
+ key: 'createTime',
145
+ title: '创建时间',
146
+ type: 'text',
147
+ content: () => Mock.mock('@datetime'),
148
+ width: 180,
149
+ fixed: 'right',
150
+ },
151
+ {
152
+ key: 'actions',
153
+ type: 'button',
154
+ title: '操作',
155
+ fixed: 'right',
156
+ width: 200,
157
+ configurable: false,
158
+ content() {
159
+ return [
160
+ {
161
+ label: '编辑',
162
+ },
163
+ {
164
+ label: '删除',
165
+ onClick: options.onDelete,
166
+ },
167
+ {
168
+ label: '详情',
169
+ onClick() {
170
+ window.open(location.href)
171
+ },
172
+ },
173
+ {
174
+ label: '上线',
175
+ },
176
+ {
177
+ label: '下线',
178
+ },
179
+ ]
180
+ },
181
+ },
182
+ ]
183
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@yidun/antd-super-table",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "files": [
8
8
  "dist",
9
+ "example",
9
10
  "example.png",
10
11
  "README.md"
11
12
  ],
@@ -14,7 +15,8 @@
14
15
  "build": "vite build --mode lib && tsc --emitDeclarationOnly && cp src/typings.ts dist/",
15
16
  "preview": "vite preview",
16
17
  "tsc": "tsc --noEmit --project tsconfig.json",
17
- "lint": "eslint src --fix",
18
+ "lint": "eslint src --ext .js,.ts,.vue",
19
+ "lint:fix": "eslint src --fix",
18
20
  "format": "prettier --write src/"
19
21
  },
20
22
  "optionalDependencies": {