@ithinkdt/page 4.1.1 → 4.2.0-0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ithinkdt/page",
3
- "version": "4.1.1",
3
+ "version": "4.2.0-0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "iThinkDT Page",
@@ -40,8 +40,8 @@
40
40
  "sideEffects": false,
41
41
  "dependencies": {
42
42
  "@vueuse/core": "^14.3.0",
43
- "nanoid": "^5.1.15",
44
- "@ithinkdt/common": "^4.1.1"
43
+ "nanoid": "^5.1.16",
44
+ "@ithinkdt/common": "~4.2.0-0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "vue": ">=3.5",
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "typescript": "~6.0.3",
52
- "vite": "^8.0.16",
53
- "vue": "^3.5.38",
52
+ "vite": "^8.1.4",
53
+ "vue": "^3.5.39",
54
54
  "vue-router": "^5.1.0"
55
55
  },
56
56
  "scripts": {
@@ -1,4 +1,5 @@
1
1
  import { promiseTimeout, until, useAsyncState } from '@vueuse/core'
2
+ import { nanoid } from 'nanoid'
2
3
  import { computed, hasInjectionContext, inject, nextTick, reactive, ref, shallowReactive, shallowRef, toRaw, watch } from 'vue'
3
4
 
4
5
  import { PAGE_INJECTION, pageInjection } from './plugin'
@@ -24,19 +25,17 @@ export function useDs(fetch, options = {}) {
24
25
  options,
25
26
  )
26
27
 
27
- let lastReject
28
+ let lastId
28
29
  const { state, isLoading: loading, error, execute } = useAsyncState(
29
30
  async (...params) => {
30
- if (lastReject) {
31
- lastReject()
32
- }
33
- const { promise, resolve, reject } = Promise.withResolvers()
34
- lastReject = reject
31
+ const currentId = lastId = nanoid()
32
+ const { promise, resolve } = Promise.withResolvers()
35
33
  let [res] = await Promise.all([
36
34
  Promise.resolve(fetch(...params))
37
35
  .finally (() => {
38
- resolve()
39
- lastReject = undefined
36
+ if (currentId === lastId) {
37
+ resolve()
38
+ }
40
39
  }),
41
40
  promiseTimeout(200),
42
41
  promise,
@@ -114,7 +114,6 @@ export function useDescriptionsHelper(
114
114
  scope = effectScope()
115
115
  items0.length = 0
116
116
  scope.run(() => {
117
- // eslint-disable-next-line unicorn/no-array-callback-reference
118
117
  items0.push(...items({ it, group, model }).filter(Boolean).map(reactive))
119
118
  })
120
119
  }
package/src/form.d.ts CHANGED
@@ -198,6 +198,14 @@ export interface FilterHelper<Model extends {}> extends FormHelper<Model> {
198
198
  }): void
199
199
  custom(this: void, sort: string[]): void
200
200
  custom(this: void, reset: true): void
201
+ custom(this: void, batchs: Array<
202
+ | true
203
+ | string[]
204
+ | {
205
+ key: string
206
+ hidden?: boolean | undefined
207
+ }>
208
+ ): void
201
209
  }
202
210
 
203
211
  export declare function useFilterHelper<Model extends {}>(
package/src/form.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { StorageSerializers, toReactive, tryOnScopeDispose, useEventListener, useStorage } from '@vueuse/core'
2
2
  import { nanoid } from 'nanoid'
3
- import { computed, effectScope, h, hasInjectionContext, inject, reactive, readonly, ref, shallowReactive, shallowRef, toRaw, unref } from 'vue'
3
+ import { computed, effectScope, h, hasInjectionContext, inject, nextTick, reactive, readonly, ref, shallowReactive, shallowRef, toRaw, unref } from 'vue'
4
4
  import { useRoute } from 'vue-router'
5
5
 
6
6
  import { copy, isNone } from '@ithinkdt/common/object'
@@ -342,25 +342,35 @@ export function useFilterHelper(items, { customizable = false, cached, cacheVers
342
342
  })
343
343
 
344
344
  const items1 = shallowReactive([])
345
-
346
- const custom = (params) => {
345
+ const _custom = (params, customs) => {
347
346
  if (typeof params === 'boolean') {
348
- if (params) setCustoms(getDefaultCustom())
347
+ if (params) customs = getDefaultCustom()
349
348
  } else if (Array.isArray(params)) {
350
- customs.value.sort = JSON.stringify(params) === JSON.stringify(returns.items.map(col => col.name))
349
+ customs.sort = JSON.stringify(params) === JSON.stringify(returns.items.map(col => col.name))
351
350
  ? []
352
351
  : params
353
- setCustoms()
354
352
  } else {
355
- customs.value.hidden[params.key] = 'hidden' in params ? params.hidden : customs.value.hidden[params.key]
356
- if (!customs.value.hidden[params.key]) {
357
- delete customs.value.hidden[params.key]
353
+ customs.hidden[params.key] = 'hidden' in params ? params.hidden : customs.hidden[params.key]
354
+ const item = returns.items.find(item => item.name === params.key)
355
+ if (item && customs.hidden[params.key] === item.hidden) {
356
+ delete customs.hidden[params.key]
358
357
  }
359
358
  if (params.hidden) {
360
359
  returns.model[params.key] = undefined
361
360
  }
362
- setCustoms()
363
361
  }
362
+ return customs
363
+ }
364
+ const custom = (params) => {
365
+ if (!Array.isArray(params) || typeof params[0] === 'string') {
366
+ params = [params]
367
+ }
368
+ let customs0 = customs.value
369
+ for (const params0 of params) {
370
+ customs0 = _custom(params0, customs0)
371
+ }
372
+ setCustoms(customs0)
373
+
364
374
  const _items = returns.items
365
375
  .map((item, i, arr) => {
366
376
  const index = customs.value.sort.indexOf(item.name)
@@ -425,7 +435,7 @@ export function useFilterHelper(items, { customizable = false, cached, cacheVers
425
435
  } else {
426
436
  useEventListener(globalThis, 'storage', (event) => {
427
437
  if (event.key !== key) return
428
- Promise.resolve().then(() => read(event.newValue)).then(reinit)
438
+ nextTick().then(() => read(event.newValue)).then(reinit)
429
439
  }, { passive: true })
430
440
  }
431
441
 
package/src/modal.js CHANGED
@@ -12,7 +12,7 @@ export const ModalProvider = defineComponent({
12
12
  },
13
13
  })
14
14
 
15
- const ModalInjectionKey = Symbol('modal')
15
+ const ModalInjectionKey = Symbol('__MODAL__')
16
16
 
17
17
  export function useModal({ content, confirmText, confirmLoading, cancelText, cancelLoading, footer, onConfirm, onCancel, onClose, title, ...options }) {
18
18
  const { i18n: useI18n, getModalRenderer, addModal } = (hasInjectionContext() ? inject(PAGE_INJECTION, pageInjection) : pageInjection) ?? {}
package/src/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineComponent, onErrorCaptured, renderSlot, shallowRef } from 'vue'
2
2
 
3
- export const PAGE_INJECTION = Symbol('page')
3
+ export const PAGE_INJECTION = Symbol('__PAGE__')
4
4
 
5
5
  export class IgnoreRejectionError extends Error {}
6
6
 
package/src/rules.js CHANGED
@@ -64,7 +64,7 @@ export const plateNo = (message, options) =>
64
64
  export const noChinese = (message, options) => pattern(/^[^\u{4E00}-\u{9FA5}]+$/u, message, options)
65
65
  export const chinese = (message, options) => pattern(/^[\u{4E00}-\u{9FA5}]+$/u, message, options)
66
66
 
67
- export const requiredRuleSymbol = Symbol('rule:required')
67
+ export const requiredRuleSymbol = Symbol('__RULE_REQUIRED__')
68
68
  export function required(message, { required = true, trigger = ['input', 'blur', 'change'] } = {}) {
69
69
  return {
70
70
  [requiredRuleSymbol]: true,
package/src/table.d.ts CHANGED
@@ -189,6 +189,17 @@ export interface TableHelper<Model extends {}> {
189
189
  }): void
190
190
  custom(this: void, sort: string[]): void
191
191
  custom(this: void, reset: true): void
192
+ custom(this: void, batchs: Array<
193
+ | true
194
+ | string[]
195
+ | {
196
+ key: string
197
+ hidden?: boolean | undefined
198
+ fixed?: false | 'left' | 'right' | undefined
199
+ width?: number | string | undefined
200
+ }>
201
+ ): void
202
+
192
203
  dataMode: Ref<'all' | 'selection'>
193
204
  reinit(this: void): void
194
205
  }
package/src/table.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { StorageSerializers, tryOnScopeDispose, useEventListener } from '@vueuse/core'
2
2
  import { nanoid } from 'nanoid'
3
- import { computed, effectScope, hasInjectionContext, inject, reactive, ref, shallowReactive, shallowRef, toValue, unref } from 'vue'
3
+ import { computed, effectScope, hasInjectionContext, inject, nextTick, reactive, ref, shallowReactive, shallowRef, toValue, unref } from 'vue'
4
4
  import { useRoute } from 'vue-router'
5
5
 
6
6
  import { isNone } from '@ithinkdt/common/object'
@@ -124,29 +124,43 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
124
124
  const columns0 = shallowRef([])
125
125
  const columns1 = shallowReactive([])
126
126
 
127
- const custom = (params) => {
127
+ const _custom = (params, customs) => {
128
128
  if (typeof params === 'boolean') {
129
- if (params) setCustoms(getDefaultCustom())
129
+ if (params) customs = getDefaultCustom()
130
130
  } else if (Array.isArray(params)) {
131
- customs.value.sort = JSON.stringify(params) === JSON.stringify(columns0.value.map(col => col.key))
131
+ customs.sort = JSON.stringify(params) === JSON.stringify(columns0.value.map(col => col.key))
132
132
  ? []
133
133
  : params
134
- setCustoms()
135
134
  } else {
136
- customs.value.hidden[params.key] = 'hidden' in params ? params.hidden : customs.value.hidden[params.key]
137
- customs.value.fixed[params.key] = 'fixed' in params ? params.fixed : customs.value.fixed[params.key]
138
- customs.value.width[params.key] = 'width' in params ? params.width : customs.value.width[params.key]
139
- if (!customs.value.hidden[params.key]) {
140
- delete customs.value.hidden[params.key]
141
- }
142
- if (!customs.value.fixed[params.key]) {
143
- delete customs.value.fixed[params.key]
144
- }
145
- if (!customs.value.width[params.key]) {
146
- delete customs.value.width[params.key]
135
+ customs.hidden[params.key] = 'hidden' in params ? params.hidden : customs.hidden[params.key]
136
+ customs.fixed[params.key] = 'fixed' in params ? params.fixed : customs.fixed[params.key]
137
+ customs.width[params.key] = 'width' in params ? params.width : customs.width[params.key]
138
+ const col = columns0.value.find(col => col.key === params.key)
139
+ if (col) {
140
+ if (customs.hidden[params.key] === col.hidden) {
141
+ delete customs.hidden[params.key]
142
+ }
143
+ if (customs.fixed[params.key] === col.fixed) {
144
+ delete customs.fixed[params.key]
145
+ }
146
+ if (customs.width[params.key] === col.width) {
147
+ delete customs.width[params.key]
148
+ }
147
149
  }
148
- setCustoms()
149
150
  }
151
+ return customs
152
+ }
153
+
154
+ const custom = (params) => {
155
+ if (!Array.isArray(params) || typeof params[0] === 'string') {
156
+ params = [params]
157
+ }
158
+ let customs0 = customs.value
159
+ for (const params0 of params) {
160
+ customs0 = _custom(params0, customs0)
161
+ }
162
+ setCustoms(customs0)
163
+
150
164
  const columns2 = columns0.value.map((col, i, arr) => {
151
165
  const index = customs.value.sort.indexOf(col.key)
152
166
  return reactive({
@@ -344,7 +358,7 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
344
358
  } else {
345
359
  useEventListener(globalThis, 'storage', (event) => {
346
360
  if (event.key !== key) return
347
- Promise.resolve().then(() => read(event.newValue)).then(reinit)
361
+ nextTick().then(() => read(event.newValue)).then(reinit)
348
362
  }, { passive: true })
349
363
  }
350
364