@peng_kai/kit 0.3.0-beta.35 → 0.3.0-beta.37

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.
@@ -85,6 +85,9 @@ onTtaTimeZone(() => {
85
85
  </Button>
86
86
  <template #overlay>
87
87
  <Menu>
88
+ <MenuItem @click="props.filterParams?.update?.(true, false);">
89
+ 刷新本页
90
+ </MenuItem>
88
91
  <MenuItem v-if="tableColumns" @click="openTableSettingModal">
89
92
  设置表格
90
93
  </MenuItem>
@@ -1,5 +1,5 @@
1
1
  import { cloneDeep, eq, mapValues } from 'lodash-es';
2
- import { type DeepReadonly, type MaybeRefOrGetter, reactive, toRef, watch } from 'vue';
2
+ import { type DeepReadonly, type MaybeRefOrGetter, reactive, toRef, watch, isReadonly, toRaw } from 'vue';
3
3
 
4
4
  export type ShcemeConfig<T> = {
5
5
  [P in keyof T]: {
@@ -40,24 +40,26 @@ export function useFilterParams<T extends Record<string, any>>(shcemes: ShcemeCo
40
40
  const pesponsiveParams = Object.keys(modifiableParams).filter(k => !!shcemes[k]?.responsive).map(k => toRef(modifiableParams, k));
41
41
  const readonlyParams = reactive(cloneDeep(modifiableParams));
42
42
 
43
- const update = (force?: boolean) => {
43
+ const update = (force?: boolean, resetPage?: boolean) => {
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
47
  const beforeFuns = Object.entries(shcemes).filter(([k, s]) => modifiedParamKeys.includes(k) && !!s.before).map(([_, s]) => s.before!);
48
- const needResetPage = modifiedParamKeys.some(k => !!shcemes[k]?.resetPage);
49
- const pageParams = needResetPage || !!force ? { page: 1 } : {};
48
+ let needResetPage = modifiedParamKeys.some(k => !!shcemes[k]?.resetPage);
49
+ needResetPage = needResetPage || !!force;
50
+ needResetPage = typeof resetPage === 'boolean' ? resetPage : needResetPage;
51
+ const pageParams = needResetPage ? { page: 1 } : {};
50
52
 
51
53
  beforeFuns.forEach(fun => fun(beforeParams, prevParams));
52
54
  Object.assign(readonlyParams, prevParams, pageParams, beforeParams);
53
55
 
56
+ const modifiableParamsRaw = toRaw(modifiableParams);
57
+ const isReadonlyParams = (k: keyof T) => isReadonly(modifiableParamsRaw[k]);
54
58
  for (const k in readonlyParams) {
55
- // 为了拦截“只读属性赋值”的报错,因为无法判断哪些属性是只读的
56
- try {
59
+ if (!isReadonlyParams(k)) {
57
60
  // @ts-expect-error 类型错误,暂时不理会
58
61
  modifiableParams[k] = readonlyParams[k];
59
62
  }
60
- catch {}
61
63
  }
62
64
 
63
65
  if (force)
@@ -5,6 +5,7 @@ import { computed, toRef } from 'vue';
5
5
  import dayjs from '../../../../libs/dayjs';
6
6
  import { type ItemSchema, useAntdForm } from '../../../../antd';
7
7
  import { PictureCardUpload } from '../../../components/upload';
8
+ import InputNumberRange from '../../../../antd/components/InputNumberRange.vue';
8
9
 
9
10
  export interface IConfigDetail {
10
11
  category_id: number
@@ -43,6 +44,8 @@ export enum FormTypes {
43
44
  SINGLE_DATE_PICKER = 13,
44
45
  /** 日期范围选择器 */
45
46
  RANGE_DATE_PICKER = 14,
47
+ /** 数字范围输入框 */
48
+ NUMBER_RANGE = 15,
46
49
  }
47
50
 
48
51
  const antdPropsResolvers: Record<number, (config: IConfigDetail) => IConfigDetail> = {
@@ -122,6 +125,12 @@ const antdPropsResolvers: Record<number, (config: IConfigDetail) => IConfigDetai
122
125
 
123
126
  return config;
124
127
  },
128
+ [FormTypes.NUMBER_RANGE](config) {
129
+ config.value = config.value === '' ? undefined : config.value.split(',');
130
+ const [min, max] = config.options?.split(',') || [];
131
+ config.options = { min: Number(min), max: Number(max) };
132
+ return config;
133
+ },
125
134
  };
126
135
 
127
136
  const antdValueResolvers: Record<number, (value: any) => any> = {
@@ -154,6 +163,11 @@ const antdValueResolvers: Record<number, (value: any) => any> = {
154
163
 
155
164
  return value;
156
165
  },
166
+ [FormTypes.NUMBER_RANGE](value) {
167
+ if (Array.isArray(value))
168
+ return value.join(',');
169
+ return value;
170
+ },
157
171
  };
158
172
  </script>
159
173
 
@@ -291,6 +305,10 @@ defineExpose({ reset, validate });
291
305
  <RangePicker v-model:value="settingForm.state[item.key]" v-bind="item.options" />
292
306
  </slot>
293
307
 
308
+ <slot v-else-if="item.form_type === FormTypes.NUMBER_RANGE" :name="FormTypes.NUMBER_RANGE">
309
+ <InputNumberRange v-model:value="settingForm.state[item.key]" v-bind="item.options" />
310
+ </slot>
311
+
294
312
  <span v-else class="text-red">没有找到预设 form_type:{{ item.form_type }},可以通过 {{ item.key }} 插槽自定义</span>
295
313
  </template>
296
314
  </FormItem>
@@ -1,6 +1,6 @@
1
1
  import { Modal as AntModal } from 'ant-design-vue';
2
2
  import { tryOnBeforeUnmount, tryOnMounted } from '@vueuse/core';
3
- import { createVNode, defineComponent, isProxy, onDeactivated, onMounted, reactive, toRef, toRefs } from 'vue';
3
+ import { createVNode, defineComponent, isProxy, onBeforeUnmount, onDeactivated, onMounted, reactive, toRef, toRefs } from 'vue';
4
4
  import type { Component } from 'vue';
5
5
  import type { ModalProps } from 'ant-design-vue';
6
6
  import type { ComponentEmit, ComponentProps } from 'vue-component-type-helpers';
@@ -110,6 +110,8 @@ export function useAntdModal<Comp extends Component>(
110
110
  const PresetComponent = defineComponent({
111
111
  setup(props) {
112
112
  onMounted(() => _modalProps.opener?.(open as any));
113
+ onBeforeUnmount(_onClose);
114
+ onDeactivated(_onClose);
113
115
 
114
116
  return () => {
115
117
  return createVNode(AntModal, { ..._modalProps, ...props }, {
@@ -127,8 +129,8 @@ export function useAntdModal<Comp extends Component>(
127
129
  (compProps as any).onClose = onClose;
128
130
  (compProps as any).onConfirm = onConfirm;
129
131
 
130
- tryOnBeforeUnmount(_onClose);
131
- tryOnMounted(() => onDeactivated(_onClose));
132
+ // tryOnBeforeUnmount(_onClose);
133
+ // tryOnMounted(() => onDeactivated(_onClose));
132
134
 
133
135
  return {
134
136
  PresetComponent,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.3.0-beta.35",
4
+ "version": "0.3.0-beta.37",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",