@peng_kai/kit 0.2.39 → 0.2.41

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.
@@ -44,7 +44,7 @@ export function useFilterParams<T extends Record<string, any>>(shcemes: ShcemeCo
44
44
  const prevParams = Object.freeze({ ...modifiableParams });
45
45
  const beforeParams = {};
46
46
  const modifiedParamKeys = Object.keys(readonlyParams).filter(pk => !eq(modifiableParams[pk], readonlyParams[pk]));
47
- const beforeFuns = Object.entries(shcemes).filter(([k, s]) => modifiedParamKeys.includes(k) && !!s.effect).map(([_, s]) => s.effect!);
47
+ const beforeFuns = Object.entries(shcemes).filter(([k, s]) => modifiedParamKeys.includes(k) && !!s.before).map(([_, s]) => s.before!);
48
48
  const needResetPage = modifiedParamKeys.some(k => !!shcemes[k]?.resetPage);
49
49
  const pageParams = needResetPage || !!force ? { page: 1 } : {};
50
50
 
@@ -5,6 +5,7 @@ import Duration from './src/Duration.vue';
5
5
  import IP from './src/IP.vue';
6
6
 
7
7
  export { createTagGetter } from './src/createTagGetter';
8
+ export { createDateTypeSwitcher } from './src/createDateTypeSwitcher';
8
9
 
9
10
  export const Text = {
10
11
  Hash,
@@ -67,7 +67,7 @@ const amountColor = computed(() => {
67
67
  <!-- 约等于 -->
68
68
  <span v-if="props.approx">≈</span>
69
69
  <!-- 符号 -->
70
- <CurrencyIcon class="symbol-logo" :symbol="symbol" :useCdn="useCdn" />
70
+ <CurrencyIcon v-if="symbol" class="symbol-logo" :symbol="symbol" :useCdn="useCdn" />
71
71
  <!-- 金额 -->
72
72
  <span class="color-$amount-color amount">{{ amountText }}</span>
73
73
  <!-- 单位 -->
@@ -0,0 +1,41 @@
1
+ import { useCycleList } from '@vueuse/core';
2
+ import { computed, defineComponent } from 'vue';
3
+ import Datetime from './Datetime.vue';
4
+
5
+ export function createDateTypeSwitcher() {
6
+ const cycle = useCycleList(['local', 'utc'] as const);
7
+
8
+ const Switcher = defineComponent({
9
+ props: [],
10
+ setup(props) {
11
+ const title = computed(() => {
12
+ const state = cycle.state.value;
13
+ return ({
14
+ local: '本地',
15
+ utc: 'UTC',
16
+ } satisfies Record<typeof state, string>)[state];
17
+ });
18
+
19
+ return () => (
20
+ <div
21
+ class="flex-inline items-center ml-1 cursor-pointer select-none text-$antd-colorPrimary hover:op-60"
22
+ onClick={() => cycle.next()}
23
+ >
24
+ (
25
+ <span class="min-w-2em inline-block text-center">
26
+ {title.value}
27
+ </span>
28
+ )
29
+ <i class="i-mi:switch text-1.2em" />
30
+ </div>
31
+ );
32
+ },
33
+ });
34
+ const Display = defineComponent({
35
+ setup(props, { attrs }) {
36
+ return () => (<Datetime {...attrs} utc={cycle.state.value === 'utc'} />);
37
+ },
38
+ });
39
+
40
+ return { Switcher, Display };
41
+ }
@@ -5,8 +5,9 @@
5
5
 
6
6
  import type { FormInstance, FormItemProps, RuleObject } from 'ant-design-vue/es/form';
7
7
  import type { FormProps } from 'ant-design-vue';
8
- import { type MaybeRefOrGetter, computed, reactive, ref, toRef, watch, watchEffect } from 'vue';
9
- import { mapValues } from 'lodash-es';
8
+ import { type MaybeRefOrGetter, computed, reactive, ref, shallowRef, toRef, watch, watchEffect } from 'vue';
9
+ import { cloneDeep, mapValues } from 'lodash-es';
10
+ import { reactiveComputed } from '@vueuse/core';
10
11
  import { GROUP_SEP, buildGroupField, getGroupIndex } from './useAntdForm.helpers';
11
12
 
12
13
  export { useAntdForm };
@@ -28,12 +29,12 @@ interface Options<S, TS> {
28
29
  function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRefOrGetter<SchemaConfig<S>>, options?: Options<S, TS>) {
29
30
  const schemasR = toRef(schemas);
30
31
 
31
- const state = ref({} as S);
32
+ const state = shallowRef({} as S);
32
33
  const stateTF = computed<TS>(() => options?.transform?.(<any>state.value) ?? <any>state.value);
33
34
  const show = computed(() => mapValues(state.value, (_, k): boolean => schemasR.value[k].show?.(state.value) ?? true));
34
35
  const props = computed<FormProps>(() => ({ model: state.value, ref: (c: any) => (formRef.value = c) }));
35
36
  const itemProps = computed(() => mapValues(state.value, (_, k): FormItemProps => {
36
- const r = schemasR.value[k].rules;
37
+ const r = schemasR.value[k]?.rules;
37
38
  const rules = typeof r === 'function' ? r(state.value)?.filter((i: any) => !!i) : r;
38
39
 
39
40
  return { name: k, rules };
@@ -49,15 +50,16 @@ function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRe
49
50
  get scrollToField() {
50
51
  return formRef.value?.scrollToField;
51
52
  },
52
- get validate() {
53
- return formRef.value?.validate;
54
- },
55
53
  get validateFields() {
56
54
  return formRef.value?.validateFields;
57
55
  },
58
56
  get clearValidate() {
59
57
  return formRef.value?.clearValidate;
60
58
  },
59
+ async validate(...args: Parameters<FormInstance['validate']>) {
60
+ const res = await formRef.value?.validate(...args);
61
+ return cloneDeep(reactive(res ?? {}));
62
+ },
61
63
  addGroup(groupName: string, groupSchemas: Record<string, ItemSchema>) {
62
64
  const i = getGroupIndex(groupName, schemasR.value) + 1;
63
65
 
@@ -83,27 +85,18 @@ function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRe
83
85
  watch(itemProps, () => $form.clearValidate?.(), { flush: 'post', deep: true });
84
86
 
85
87
  watchEffect(() => {
86
- const _state: any = {};
87
-
88
- for (const k in schemasR.value) {
89
- const item = schemasR.value[k];
90
- _state[k] = (k in state.value) ? toRef(state.value, k) : ref(item.value);
88
+ const schemas = schemasR.value;
89
+ const oldState = state.value;
90
+ const newState: any = {};
91
+
92
+ for (const k of Object.keys(schemas)) {
93
+ const value = schemas[k].value;
94
+ const isExist = Object.prototype.hasOwnProperty.call(oldState, k);
95
+ newState[k] = isExist ? oldState[k] : toRef(value);
91
96
  }
92
97
 
93
- state.value = _state;
94
- });
95
-
96
- // 为什么之前用 watchEffect?
97
- // watch(schemasR, () => {
98
- // const _state: any = {};
99
-
100
- // for (const k in schemasR.value) {
101
- // const item = schemasR.value[k];
102
- // _state[k] = (k in state.value) ? toRef(state.value, k) : toRef(item, 'value');
103
- // }
104
-
105
- // state.value = _state;
106
- // }, { immediate: true });
98
+ state.value = newState;
99
+ }, { flush: 'pre' });
107
100
 
108
- return reactive({ state, stateTF, show, props, itemProps, $form });
101
+ return reactive({ state: reactiveComputed(() => state.value as S), stateTF, show, props, itemProps, $form });
109
102
  }
package/package.json CHANGED
@@ -1,95 +1,95 @@
1
- {
2
- "name": "@peng_kai/kit",
3
- "type": "module",
4
- "version": "0.2.39",
5
- "description": "",
6
- "author": "",
7
- "license": "ISC",
8
- "keywords": [],
9
- "main": "index.js",
10
- "scripts": {
11
- "dev:js": "tsx ./admin/scripts/deploy.ts",
12
- "lint": "eslint .",
13
- "lint:fix": "eslint . --fix"
14
- },
15
- "peerDependencies": {
16
- "ant-design-vue": "4.2.3",
17
- "vue": "3.4.31",
18
- "vue-router": "4.4.0"
19
- },
20
- "dependencies": {
21
- "@aws-sdk/client-s3": "^3.609.0",
22
- "@aws-sdk/lib-storage": "^3.609.0",
23
- "@babel/generator": "^7.24.7",
24
- "@babel/parser": "^7.24.7",
25
- "@babel/traverse": "^7.24.7",
26
- "@babel/types": "^7.24.7",
27
- "@ckeditor/ckeditor5-vue": "^5.1.0",
28
- "@fingerprintjs/fingerprintjs": "^4.4.1",
29
- "@tanstack/vue-query": "^5.49.1",
30
- "@vueuse/components": "^10.11.0",
31
- "@vueuse/core": "^10.11.0",
32
- "@vueuse/router": "^10.11.0",
33
- "a-calc": "^1.3.12",
34
- "archiver": "^7.0.1",
35
- "axios": "^1.7.2",
36
- "bignumber.js": "^9.1.2",
37
- "chokidar": "^3.6.0",
38
- "crypto-es": "^2.1.0",
39
- "dayjs": "^1.11.11",
40
- "echarts": "^5.4.3",
41
- "execa": "^9.3.0",
42
- "fast-glob": "^3.3.2",
43
- "localstorage-slim": "^2.7.1",
44
- "lodash-es": "^4.17.21",
45
- "nprogress": "^0.2.0",
46
- "pinia": "^2.1.7",
47
- "tsx": "^4.16.00",
48
- "vue": "^3.4.31",
49
- "vue-i18n": "^9.13.1",
50
- "vue-router": "^4.4.0"
51
- },
52
- "devDependencies": {
53
- "@ckeditor/ckeditor5-adapter-ckfinder": "^41.1.0",
54
- "@ckeditor/ckeditor5-alignment": "^41.1.0",
55
- "@ckeditor/ckeditor5-autoformat": "^41.1.0",
56
- "@ckeditor/ckeditor5-basic-styles": "^41.1.0",
57
- "@ckeditor/ckeditor5-block-quote": "^41.1.0",
58
- "@ckeditor/ckeditor5-build-classic": "^41.1.0",
59
- "@ckeditor/ckeditor5-code-block": "^41.1.0",
60
- "@ckeditor/ckeditor5-document-outline": "^41.1.0",
61
- "@ckeditor/ckeditor5-editor-classic": "^41.1.0",
62
- "@ckeditor/ckeditor5-essentials": "^41.1.0",
63
- "@ckeditor/ckeditor5-font": "^41.1.0",
64
- "@ckeditor/ckeditor5-heading": "^41.1.0",
65
- "@ckeditor/ckeditor5-highlight": "^41.1.0",
66
- "@ckeditor/ckeditor5-horizontal-line": "^41.1.0",
67
- "@ckeditor/ckeditor5-html-embed": "^41.1.0",
68
- "@ckeditor/ckeditor5-html-support": "^41.1.0",
69
- "@ckeditor/ckeditor5-image": "^41.1.0",
70
- "@ckeditor/ckeditor5-import-word": "^41.1.0",
71
- "@ckeditor/ckeditor5-indent": "^41.1.0",
72
- "@ckeditor/ckeditor5-link": "^41.1.0",
73
- "@ckeditor/ckeditor5-list": "^41.1.0",
74
- "@ckeditor/ckeditor5-media-embed": "^41.1.0",
75
- "@ckeditor/ckeditor5-paragraph": "^41.1.0",
76
- "@ckeditor/ckeditor5-remove-format": "^41.1.0",
77
- "@ckeditor/ckeditor5-show-blocks": "^41.1.0",
78
- "@ckeditor/ckeditor5-source-editing": "^41.1.0",
79
- "@ckeditor/ckeditor5-table": "^41.1.0",
80
- "@ckeditor/ckeditor5-theme-lark": "^41.1.0",
81
- "@ckeditor/ckeditor5-typing": "^41.1.0",
82
- "@ckeditor/ckeditor5-upload": "^41.1.0",
83
- "@ckeditor/ckeditor5-word-count": "^41.1.0",
84
- "@peng_kai/lint": "^0.1.0",
85
- "@types/archiver": "^6.0.2",
86
- "@types/crypto-js": "^4.2.2",
87
- "@types/lodash-es": "^4.17.12",
88
- "@types/node": "^18.19.39",
89
- "@types/nprogress": "^0.2.3",
90
- "ant-design-vue": "^4.2.3",
91
- "type-fest": "^4.21.0",
92
- "typescript": "^5.5.3",
93
- "vue-component-type-helpers": "^2.0.24"
94
- }
95
- }
1
+ {
2
+ "name": "@peng_kai/kit",
3
+ "type": "module",
4
+ "version": "0.2.41",
5
+ "description": "",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "keywords": [],
9
+ "main": "index.js",
10
+ "scripts": {
11
+ "dev:js": "tsx ./admin/scripts/deploy.ts",
12
+ "lint": "eslint .",
13
+ "lint:fix": "eslint . --fix"
14
+ },
15
+ "peerDependencies": {
16
+ "ant-design-vue": "4.2.3",
17
+ "vue": "3.4.31",
18
+ "vue-router": "4.4.0"
19
+ },
20
+ "dependencies": {
21
+ "@aws-sdk/client-s3": "^3.609.0",
22
+ "@aws-sdk/lib-storage": "^3.609.0",
23
+ "@babel/generator": "^7.24.7",
24
+ "@babel/parser": "^7.24.7",
25
+ "@babel/traverse": "^7.24.7",
26
+ "@babel/types": "^7.24.7",
27
+ "@ckeditor/ckeditor5-vue": "^5.1.0",
28
+ "@fingerprintjs/fingerprintjs": "^4.4.1",
29
+ "@tanstack/vue-query": "^5.49.1",
30
+ "@vueuse/components": "^10.11.0",
31
+ "@vueuse/core": "^10.11.0",
32
+ "@vueuse/router": "^10.11.0",
33
+ "a-calc": "^1.3.12",
34
+ "archiver": "^7.0.1",
35
+ "axios": "^1.7.2",
36
+ "bignumber.js": "^9.1.2",
37
+ "chokidar": "^3.6.0",
38
+ "crypto-es": "^2.1.0",
39
+ "dayjs": "^1.11.11",
40
+ "echarts": "^5.4.3",
41
+ "execa": "^9.3.0",
42
+ "fast-glob": "^3.3.2",
43
+ "localstorage-slim": "^2.7.1",
44
+ "lodash-es": "^4.17.21",
45
+ "nprogress": "^0.2.0",
46
+ "pinia": "^2.1.7",
47
+ "tsx": "^4.16.00",
48
+ "vue": "^3.4.31",
49
+ "vue-i18n": "^9.13.1",
50
+ "vue-router": "^4.4.0"
51
+ },
52
+ "devDependencies": {
53
+ "@ckeditor/ckeditor5-adapter-ckfinder": "^41.1.0",
54
+ "@ckeditor/ckeditor5-alignment": "^41.1.0",
55
+ "@ckeditor/ckeditor5-autoformat": "^41.1.0",
56
+ "@ckeditor/ckeditor5-basic-styles": "^41.1.0",
57
+ "@ckeditor/ckeditor5-block-quote": "^41.1.0",
58
+ "@ckeditor/ckeditor5-build-classic": "^41.1.0",
59
+ "@ckeditor/ckeditor5-code-block": "^41.1.0",
60
+ "@ckeditor/ckeditor5-document-outline": "^41.1.0",
61
+ "@ckeditor/ckeditor5-editor-classic": "^41.1.0",
62
+ "@ckeditor/ckeditor5-essentials": "^41.1.0",
63
+ "@ckeditor/ckeditor5-font": "^41.1.0",
64
+ "@ckeditor/ckeditor5-heading": "^41.1.0",
65
+ "@ckeditor/ckeditor5-highlight": "^41.1.0",
66
+ "@ckeditor/ckeditor5-horizontal-line": "^41.1.0",
67
+ "@ckeditor/ckeditor5-html-embed": "^41.1.0",
68
+ "@ckeditor/ckeditor5-html-support": "^41.1.0",
69
+ "@ckeditor/ckeditor5-image": "^41.1.0",
70
+ "@ckeditor/ckeditor5-import-word": "^41.1.0",
71
+ "@ckeditor/ckeditor5-indent": "^41.1.0",
72
+ "@ckeditor/ckeditor5-link": "^41.1.0",
73
+ "@ckeditor/ckeditor5-list": "^41.1.0",
74
+ "@ckeditor/ckeditor5-media-embed": "^41.1.0",
75
+ "@ckeditor/ckeditor5-paragraph": "^41.1.0",
76
+ "@ckeditor/ckeditor5-remove-format": "^41.1.0",
77
+ "@ckeditor/ckeditor5-show-blocks": "^41.1.0",
78
+ "@ckeditor/ckeditor5-source-editing": "^41.1.0",
79
+ "@ckeditor/ckeditor5-table": "^41.1.0",
80
+ "@ckeditor/ckeditor5-theme-lark": "^41.1.0",
81
+ "@ckeditor/ckeditor5-typing": "^41.1.0",
82
+ "@ckeditor/ckeditor5-upload": "^41.1.0",
83
+ "@ckeditor/ckeditor5-word-count": "^41.1.0",
84
+ "@peng_kai/lint": "^0.1.0",
85
+ "@types/archiver": "^6.0.2",
86
+ "@types/crypto-js": "^4.2.2",
87
+ "@types/lodash-es": "^4.17.12",
88
+ "@types/node": "^18.19.39",
89
+ "@types/nprogress": "^0.2.3",
90
+ "ant-design-vue": "^4.2.3",
91
+ "type-fest": "^4.21.0",
92
+ "typescript": "^5.5.3",
93
+ "vue-component-type-helpers": "^2.0.24"
94
+ }
95
+ }