@peng_kai/kit 0.2.40 → 0.2.42

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.
@@ -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,
@@ -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,9 +5,8 @@
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, shallowRef, toRef, watch, watchEffect } from 'vue';
8
+ import { type MaybeRefOrGetter, computed, reactive, ref, toRef, watch, watchEffect } from 'vue';
9
9
  import { mapValues } from 'lodash-es';
10
- import { reactiveComputed } from '@vueuse/core';
11
10
  import { GROUP_SEP, buildGroupField, getGroupIndex } from './useAntdForm.helpers';
12
11
 
13
12
  export { useAntdForm };
@@ -29,7 +28,7 @@ interface Options<S, TS> {
29
28
  function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRefOrGetter<SchemaConfig<S>>, options?: Options<S, TS>) {
30
29
  const schemasR = toRef(schemas);
31
30
 
32
- const state = shallowRef({} as S);
31
+ const state = ref({} as S);
33
32
  const stateTF = computed<TS>(() => options?.transform?.(<any>state.value) ?? <any>state.value);
34
33
  const show = computed(() => mapValues(state.value, (_, k): boolean => schemasR.value[k].show?.(state.value) ?? true));
35
34
  const props = computed<FormProps>(() => ({ model: state.value, ref: (c: any) => (formRef.value = c) }));
@@ -97,5 +96,17 @@ function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRe
97
96
  state.value = newState;
98
97
  }, { flush: 'pre' });
99
98
 
100
- return reactive({ state: reactiveComputed(() => state.value as S), stateTF, show, props, itemProps, $form });
99
+ // 为什么之前用 watchEffect?
100
+ // watch(schemasR, () => {
101
+ // const _state: any = {};
102
+
103
+ // for (const k in schemasR.value) {
104
+ // const item = schemasR.value[k];
105
+ // _state[k] = (k in state.value) ? toRef(state.value, k) : toRef(item, 'value');
106
+ // }
107
+
108
+ // state.value = _state;
109
+ // }, { immediate: true });
110
+
111
+ return reactive({ state, stateTF, show, props, itemProps, $form });
101
112
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.40",
4
+ "version": "0.2.42",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",