plain-design 1.0.0-beta.76 → 1.0.0-beta.78

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": "plain-design",
3
- "version": "1.0.0-beta.76",
3
+ "version": "1.0.0-beta.78",
4
4
  "description": "",
5
5
  "main": "dist/plain-design.min.js",
6
6
  "module": "dist/plain-design.commonjs.min.js",
@@ -1,6 +1,7 @@
1
1
  import {eAddressTypeEnum, iAddressLazyMeta, iAddressSyncMeta} from "./address.utils";
2
2
  import {defer, DFD} from "plain-utils/utils/defer";
3
3
  import {reactive} from "plain-design-composition";
4
+ import i18n from "../i18n";
4
5
 
5
6
  export function createAddressService(
6
7
  config: {
@@ -126,13 +127,14 @@ export function createAddressService(
126
127
  };
127
128
  })();
128
129
 
130
+ let dfd: DFD<iAddressSyncMeta[]> | null = null;
131
+
129
132
  /**
130
133
  * 带缓存地查询所有地址数据
131
134
  * @author 韦胜健
132
135
  * @date 2022.12.16 23:20
133
136
  */
134
137
  const getAddress = (() => {
135
- let dfd: DFD<iAddressSyncMeta[]> | null = null;
136
138
  return () => {
137
139
  if (!dfd) {
138
140
  dfd = defer<iAddressSyncMeta[]>();
@@ -142,6 +144,15 @@ export function createAddressService(
142
144
  };
143
145
  })();
144
146
 
147
+ /**
148
+ * 清理缓存
149
+ * @author 韦胜健
150
+ * @date 2024.6.18 15:34
151
+ */
152
+ const clear = () => {
153
+ dfd = null;
154
+ };
155
+
145
156
  const getAddressByCodesComputed = (() => {
146
157
 
147
158
  const state = reactive({
@@ -171,6 +182,13 @@ export function createAddressService(
171
182
  return getter;
172
183
  })();
173
184
 
185
+ /**
186
+ * 切换多语言的时候清理缓存
187
+ * @author 韦胜健
188
+ * @date 2024.6.18 15:35
189
+ */
190
+ i18n.hooks.onChangeLang.use(() => clear());
191
+
174
192
  return {
175
193
  config,
176
194
  getAddressByLabel,
@@ -178,6 +196,7 @@ export function createAddressService(
178
196
  getAddressByParentCodes,
179
197
  getAddress,
180
198
  getAddressByCodesComputed,
199
+ clear,
181
200
  };
182
201
  }
183
202
 
@@ -35,6 +35,7 @@ export function createAddressCascadeMultiple(
35
35
 
36
36
  effects.push(hooks.onRender.use({
37
37
  processor: ({ list, render }) => {list.push({ render, key: '1', seq: 1 });},
38
+ separate: false,
38
39
  render: () => (
39
40
  <Cascade
40
41
  modelValue={state.modelMetas}
@@ -58,6 +58,7 @@ export function createAddressCascadeSingle(
58
58
 
59
59
  effects.push(hooks.onRender.use({
60
60
  processor: ({ list, render }) => {list.push({ render, key: '1', seq: 1 });},
61
+ separate: false,
61
62
  render: () => (
62
63
  <Cascade
63
64
  modelValue={metaArray.value}
@@ -8,6 +8,7 @@ import {createAddressCascadeHooks} from "./createAddressCascade.hooks";
8
8
  import {useWatchAutoClear} from "../../utils/watchEffectAutoClear";
9
9
  import {createAddressCascadeMultiple} from "./createAddressCascade.multiple";
10
10
  import {createAddressCascadeSingle} from "./createAddressCascade.single";
11
+ import {useEdit} from "../../uses/useEdit";
11
12
 
12
13
  export const AddressCascade = designComponent({
13
14
  name: 'address-cascade',
@@ -17,6 +18,7 @@ export const AddressCascade = designComponent({
17
18
  setup({ props, event }) {
18
19
 
19
20
  useStyle();
21
+ useEdit();
20
22
 
21
23
  const hooks = createAddressCascadeHooks();
22
24
 
@@ -94,6 +94,7 @@ export function createSingleCascadeRender(
94
94
  ref={onRef.input}
95
95
  className={classes.value}
96
96
  suffixIcon="pi-mind-mapping"
97
+ customReadonly={props.disableFilter || props.lazy}
97
98
  {...mergeAttrs(
98
99
  { class: classes.value, },
99
100
  {
@@ -107,7 +108,6 @@ export function createSingleCascadeRender(
107
108
  }
108
109
  }
109
110
  )}
110
- customReadonly={props.disableFilter || props.lazy}
111
111
  />
112
112
  )));
113
113
 
@@ -55,6 +55,7 @@
55
55
  cursor: pointer;
56
56
  transition: background-color linear 300ms;
57
57
  border-radius: plv(box-size-small-border-radius);
58
+ word-break: break-all;
58
59
 
59
60
  @include comp(checkbox) {
60
61
  line-height: 1.4em;
@@ -1,4 +1,4 @@
1
- import {designComponent, getComponentCls, useClasses, useRefs} from "plain-design-composition";
1
+ import {designComponent, Fragment, getComponentCls, useClasses, useRefs} from "plain-design-composition";
2
2
  import {FormItemValidatePropsOption} from "../Form/validate/validate.utils";
3
3
  import {EditProps, useEdit} from "../../uses/useEdit";
4
4
  import {StyleProps, ThemeStatus, useStyle} from "../../uses/useStyle";
@@ -109,7 +109,7 @@ export const FormItem = designComponent({
109
109
  <div className="form-item-content box-message-reference" style={formItemLayout.contentStyles.value}>
110
110
  {slots.prepend.isExist() && <div className="form-item-prepend-content">{slots.prepend()}</div>}
111
111
  <div className="form-item-content-inner">
112
- {slots.default()}
112
+ <Fragment key="slot_default">{slots.default()}</Fragment>
113
113
  {/*校验消息放下边的时候放在 form-item-content-inner 内部使得与输入框左或者右对齐*/}
114
114
  {formItemLayout.validateMessagePosition.value !== 'right' && <FormItemValidateMessage message={formItemValidation.validateMessage.value!}/>}
115
115
  </div>
@@ -1,4 +1,4 @@
1
- import {computed, designComponent, getComponentCls, iHTMLDivElement, mergeAttrs, useClasses, useRefs, useStyles} from "plain-design-composition";
1
+ import {computed, designComponent, Fragment, getComponentCls, iHTMLDivElement, mergeAttrs, useClasses, useRefs, useStyles} from "plain-design-composition";
2
2
  import './index.scss';
3
3
  import {ThemeStatus, useStyle} from "../../uses/useStyle";
4
4
  import {useEdit} from "../../uses/useEdit";
@@ -134,7 +134,7 @@ export const Input = designComponent({
134
134
  {content}
135
135
 
136
136
  {inputSuffixIcon.render()}
137
- {hooks.onRenderSuffix.exec(slots.suffix())}
137
+ {hooks.onRenderSuffix.exec(<Fragment key="slot_suffix">{slots.suffix()}</Fragment>)}
138
138
  </span>
139
139
  );
140
140
  },
@@ -133,13 +133,19 @@ export const PlcExpand = designComponent({
133
133
  * @author 韦胜健
134
134
  * @date 2022/11/17 14:15
135
135
  */
136
+ const weakMap = new WeakMap<PlainObject, (param: any) => any>();
136
137
  onBeforeUnmount(table.hooks.onTableMessyData.use(({ data }) => {
137
138
  const newData = [] as any[];
138
139
  data.forEach(item => {
139
140
  newData.push(item);
140
141
  if (typeof item === "function") {return;}
141
142
  if (utils.isExpand(item.data)) {
142
- newData.push((param: any) => utils.renderExpand(item, param.vIndex, param.vid, param.index));
143
+ let dataFunc = weakMap.get(item.data);
144
+ if (!dataFunc) {
145
+ dataFunc = (param: any) => utils.renderExpand(item, param.vIndex, param.vid, param.index);
146
+ weakMap.set(item.data, dataFunc);
147
+ }
148
+ newData.push(dataFunc);
143
149
  }
144
150
  });
145
151
  return { data: newData };
@@ -75,12 +75,26 @@ export function useVirtualList(
75
75
  hostSize: null as null | number, // 容器高度
76
76
  scrollDirection: ScrollDirection.none as typeof ScrollDirection.TYPE,
77
77
  id2size: {} as Record<string, number | undefined>,
78
- avgSize: props.size
78
+ });
79
+
80
+ const _avgSize = computed((): number => {
81
+ const total = Object.values(state.id2size).reduce((prev, item) => {
82
+ if (item != null) {
83
+ prev.total += item;
84
+ prev.count++;
85
+ }
86
+ return prev;
87
+ }, { total: 0, count: 0 });
88
+ if (!!total.count) {
89
+ return Math.floor(total.total / total.count);
90
+ } else {
91
+ return props.size;
92
+ }
79
93
  });
80
94
 
81
95
  const _pageSize = computed(() => {
82
96
  if (state.hostSize == null) {return null;}
83
- return Math.floor(state.hostSize / (state.avgSize == null ? props.size : state.avgSize));
97
+ return Math.floor(state.hostSize / _avgSize.value);
84
98
  });
85
99
 
86
100
  const idMap = new WeakMap<PlainObject, string>();
@@ -94,7 +108,7 @@ export function useVirtualList(
94
108
  id = nextRowId();
95
109
  idMap.set(item, id);
96
110
  }
97
- const size: number = state.id2size[id] || state.avgSize;
111
+ const size: number = state.id2size[id] || _avgSize.value;
98
112
  let start = prevEnd;
99
113
  let end = start + size;
100
114
  prevEnd = end;
@@ -120,7 +134,7 @@ export function useVirtualList(
120
134
  startPageIndex: 0,
121
135
  };
122
136
  }
123
- const { startIndex, endIndex, pageIndex } = utils.getPageIndex(scrollValue, pageSize);
137
+ const { startIndex, endIndex, pageIndex } = utils.getPageIndex(scrollValue);
124
138
  return {
125
139
  list: nodes.value.slice(startIndex, endIndex),
126
140
  startPageIndex: pageIndex,
@@ -264,10 +278,11 @@ export function useVirtualList(
264
278
  * @author 韦胜健
265
279
  * @date 2020/12/14 22:44
266
280
  */
267
- getPageIndex: (scrollValue: number, pageSize: number | null | undefined) => {
281
+ getPageIndex: (scrollValue: number) => {
268
282
  if (scrollValue < 0) {
269
283
  scrollValue = 0;
270
284
  }
285
+ const pageSize = _pageSize.value;
271
286
  const data = dataModel.value || [];
272
287
  if (pageSize == null) {
273
288
  return {
@@ -322,18 +337,15 @@ export function useVirtualList(
322
337
  };
323
338
  },
324
339
  resetHostSize: () => {
325
- let hostSize = refs.scroll!.refs.host![props.horizontal ? 'offsetWidth' : 'offsetHeight'];
326
- const headEl = refs.scroll!.refs.host!.querySelector('[data-virtual-head]') as undefined | HTMLDivElement;
327
- const footEl = refs.scroll!.refs.host!.querySelector('[data-virtual-foot]') as undefined | HTMLDivElement;
328
- if (!!headEl) {
329
- hostSize -= headEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];
330
- }
331
- if (!!footEl) {
332
- hostSize -= footEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];
333
- }
334
- if (state.hostSize != hostSize) {
335
- state.hostSize = hostSize;
336
- }
340
+ const hostEl = refs.scroll?.refs.host;
341
+ if (!hostEl) {return;}
342
+ let hostSize = hostEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];
343
+ const headEl = hostEl.querySelector('[data-virtual-head]') as undefined | HTMLDivElement;
344
+ const footEl = hostEl.querySelector('[data-virtual-foot]') as undefined | HTMLDivElement;
345
+ if (!!headEl) {hostSize -= headEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];}
346
+ if (!!footEl) {hostSize -= footEl[props.horizontal ? 'offsetWidth' : 'offsetHeight'];}
347
+
348
+ if (state.hostSize != hostSize) {state.hostSize = hostSize;}
337
349
  },
338
350
  };
339
351
 
@@ -348,7 +360,7 @@ export function useVirtualList(
348
360
  const newScrollValue = (e.target as HTMLDivElement)[props.horizontal ? 'scrollLeft' : 'scrollTop'];
349
361
  state.scrollDirection = newScrollValue > freezeState.scrollValue ? ScrollDirection.end : ScrollDirection.start;
350
362
  freezeState.scrollValue = newScrollValue;
351
- const current = utils.getPageIndex((e.target as HTMLDivElement).scrollTop, _pageSize.value);
363
+ const current = utils.getPageIndex((e.target as HTMLDivElement).scrollTop);
352
364
  state.scrollValue = (e.target as HTMLDivElement)[props.horizontal ? 'scrollLeft' : 'scrollTop'];
353
365
  freezeState.current = current;
354
366
  emit.onPageIndexChange(current);
@@ -387,7 +399,6 @@ export function useVirtualList(
387
399
  await delay();
388
400
  // console.log('dynamic scan height')
389
401
  const elNodes = (refs.content?.querySelectorAll('[data-vid],[vid]') || []) as HTMLElement[];
390
- let newAvgSize = state.avgSize;
391
402
 
392
403
  for (let i = 0; i < elNodes.length; i++) {
393
404
  const el = elNodes[i];
@@ -398,13 +409,8 @@ export function useVirtualList(
398
409
  }
399
410
  if (state.id2size[vid] != size) {
400
411
  state.id2size[vid] = size;
401
- newAvgSize = Number(((state.avgSize + size) / 2).toFixed(0));
402
412
  }
403
413
  }
404
-
405
- if (newAvgSize != state.avgSize) {
406
- state.avgSize = newAvgSize;
407
- }
408
414
  });
409
415
 
410
416
  return {