@yidun/antd-super-table 0.1.5 → 0.1.7

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.
package/example/index.vue CHANGED
@@ -11,8 +11,8 @@ import { createTableColumns } from './tableColumns'
11
11
  import { createFormItems } from './formItems'
12
12
 
13
13
  const tableRef = ref<InstanceType<typeof SuperTable>>()
14
- // 查询条件配置
15
- const formItems: any = createFormItems()
14
+ // 查询条件配置 - 改为响应式
15
+ const formItems = ref<any[]>(createFormItems())
16
16
 
17
17
  // 表头配置
18
18
  const tableColumns: any = createTableColumns({
@@ -20,7 +20,7 @@ const tableColumns: any = createTableColumns({
20
20
  })
21
21
 
22
22
  const setting = useLocalStorage('super-table-example-config', {
23
- enableScene: false,
23
+ enableScene: true,
24
24
  enableTableConfig: false,
25
25
  sortable: false,
26
26
  showRefreshButton: false,
@@ -34,6 +34,21 @@ const setting = useLocalStorage('super-table-example-config', {
34
34
  formItemColSpan: 6,
35
35
  })
36
36
 
37
+ // 默认场景配置
38
+ const defaultScene = {
39
+ name: '默认场景',
40
+ items: [
41
+ {
42
+ name: 'input',
43
+ value: '',
44
+ },
45
+ {
46
+ name: 'select',
47
+ value: undefined,
48
+ },
49
+ ],
50
+ }
51
+
37
52
  // 表单项变更事件处理
38
53
  function onFormItemChange(name: string, value: any, formItem: any, formOperations: any, tableOperations: any) {
39
54
  console.log('form-item-change 事件触发:', {
@@ -139,6 +154,79 @@ const handleUpdateSelectOptions = () => {
139
154
  setFormValue('select', 100)
140
155
  }
141
156
 
157
+ // 清空缓存
158
+ const handleClearCache = () => {
159
+ Modal.confirm({
160
+ title: '提示',
161
+ content: '确定要清空所有 localStorage 缓存吗?此操作不可恢复。',
162
+ onOk: () => {
163
+ try {
164
+ localStorage.clear()
165
+ Modal.success({
166
+ title: '成功',
167
+ content: '缓存已清空,页面将自动刷新',
168
+ onOk: () => {
169
+ window.location.reload()
170
+ },
171
+ })
172
+ } catch (error) {
173
+ Modal.error({
174
+ title: '错误',
175
+ content: '清空缓存失败:' + (error as Error).message,
176
+ })
177
+ }
178
+ },
179
+ })
180
+ }
181
+
182
+ // 新增查询项计数器
183
+ let newItemCounter = 0
184
+
185
+ // 新增查询项
186
+ const handleAddFormItem = () => {
187
+ newItemCounter++
188
+ const newItem = {
189
+ key: `dynamicInput${newItemCounter}`,
190
+ type: 'input',
191
+ label: `动态输入框${newItemCounter}`,
192
+ name: `dynamicInput${newItemCounter}`,
193
+ value: '',
194
+ }
195
+ formItems.value = [...formItems.value, newItem]
196
+ console.log('✅ 新增查询项:', newItem.name, '当前总数:', formItems.value.length)
197
+ }
198
+
199
+ // 删除最后一个非 fixed 的查询项
200
+ const handleRemoveFormItem = () => {
201
+ // 从后往前找第一个非 fixed 的项
202
+ const indexToRemove = formItems.value.findLastIndex((item: any) => !item.fixed)
203
+
204
+ if (indexToRemove === -1) {
205
+ Modal.warning({
206
+ title: '提示',
207
+ content: '没有可删除的查询项(fixed 的项不可删除)',
208
+ })
209
+ return
210
+ }
211
+
212
+ const removedItem = formItems.value[indexToRemove]
213
+ formItems.value = formItems.value.filter((_: any, index: number) => index !== indexToRemove)
214
+ console.log('❌ 删除查询项:', removedItem.name, '当前总数:', formItems.value.length)
215
+ }
216
+
217
+ // 重置所有查询项
218
+ const handleResetFormItems = () => {
219
+ Modal.confirm({
220
+ title: '提示',
221
+ content: '确定要重置所有查询项吗?这将清除所有动态添加的查询项。',
222
+ onOk: () => {
223
+ formItems.value = createFormItems()
224
+ newItemCounter = 0
225
+ console.log('🔄 重置查询项完成,当前总数:', formItems.value.length)
226
+ },
227
+ })
228
+ }
229
+
142
230
  onMounted(() => {
143
231
  handleUpdateSelectOptions()
144
232
 
@@ -247,6 +335,31 @@ onMounted(() => {
247
335
  <a-radio :value="12">12</a-radio>
248
336
  </a-radio-group>
249
337
  </a-form-item>
338
+ <a-form-item>
339
+ <a-space>
340
+ <a-button @click="handleAddFormItem">
341
+ ➕ 新增查询项
342
+ </a-button>
343
+ <a-button @click="handleRemoveFormItem">
344
+ ➖ 删除查询项
345
+ </a-button>
346
+ <a-button @click="handleResetFormItems">
347
+ 🔄 重置查询项
348
+ </a-button>
349
+ </a-space>
350
+ </a-form-item>
351
+ <a-form-item>
352
+ <a-button
353
+ type="primary"
354
+ danger
355
+ @click="handleClearCache"
356
+ >
357
+ 清空缓存
358
+ </a-button>
359
+ </a-form-item>
360
+ <a-form-item label="查询项总数">
361
+ <a-tag color="blue">{{ formItems.length }} 项</a-tag>
362
+ </a-form-item>
250
363
  </a-form>
251
364
  <super-table
252
365
  ref="tableRef"
@@ -260,6 +373,7 @@ onMounted(() => {
260
373
  :show-refresh-button="setting.showRefreshButton"
261
374
  :show-expand-button="setting.showExpandButton"
262
375
  :form-item-col-span="setting.formItemColSpan"
376
+ :default-scene="defaultScene"
263
377
  :table-props="{
264
378
  scroll: {
265
379
  y: 600,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yidun/antd-super-table",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -26,13 +26,13 @@
26
26
  "@ant-design/icons-vue": "^7.0.1",
27
27
  "@vueuse/core": "^13.1.0",
28
28
  "ant-design-vue": "^4.2.6",
29
+ "async-validator": "^4.2.5",
29
30
  "dayjs": "^1.11.13",
30
31
  "lodash-es": "^4.17.21",
31
32
  "sortablejs": "^1.15.6",
32
33
  "uuid": "^11.1.0",
33
34
  "vue": "^3.5.13",
34
- "vuedraggable": "^4.0.1",
35
- "async-validator": "^4.2.5"
35
+ "vuedraggable": "^4.0.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@tsconfig/node22": "^22.0.1",
@@ -57,6 +57,7 @@
57
57
  "vite": "^6.2.4",
58
58
  "vite-plugin-css-injected-by-js": "^3.5.2",
59
59
  "vite-plugin-vue-devtools": "^7.7.2",
60
+ "vite-plugin-vue-mcp": "^0.3.2",
60
61
  "vue-tsc": "^2.2.8"
61
62
  }
62
63
  }