@vue-ui-kit/ant 2.4.4 → 2.4.6

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.
@@ -4,15 +4,14 @@
4
4
  name="PromisePicker"
5
5
  generic="D extends Recordable = Recordable, F extends Recordable = Recordable"
6
6
  >
7
- import { reactive, ref, computed, onMounted, nextTick } from 'vue';
8
- import { PGridInstance, PromisePickerProps } from '#/antProxy';
7
+ import { PGridInstance, PGridProps, PromisePickerProps } from '#/antProxy';
9
8
  import PGrid from '@/components/PGrid.vue';
10
9
  import { $warning } from '@/hooks/useMessage';
11
10
  import { Button as AButton, Modal as AModal } from 'ant-design-vue';
11
+ import { computed, reactive, ref } from 'vue';
12
12
 
13
13
  const gridEl = ref<PGridInstance<D>>();
14
14
 
15
- const rendered = ref(false);
16
15
  const props = withDefaults(defineProps<PromisePickerProps<D, F>>(), {
17
16
  title: '数据选择',
18
17
  width: '70%',
@@ -21,6 +20,24 @@
21
20
  beforePick: () => Promise.resolve(),
22
21
  });
23
22
  const isMultiple = computed(() => props.gridSetting.selectConfig?.multiple);
23
+ /**
24
+ * 合并内置的 `fitContent: true`:
25
+ * - 弹窗容器由内容撑开,外层不写死高度;
26
+ * - 数据少时按内容自然高显示,避免出现大面积空白;
27
+ * - 数据多时由外层 `max-height` 限制总高度,表格内部 `scroll.y` 作为上限滚动。
28
+ * 用户在 `gridSetting` 中若显式传入 `fitContent`/`renderY` 可覆盖。
29
+ */
30
+ const mergedGridSetting = computed<PGridProps<D, F>>(() => ({
31
+ fitContent: true,
32
+ ...props.gridSetting,
33
+ }));
34
+ const pickerBodyStyle = {
35
+ display: 'flex',
36
+ flexDirection: 'column',
37
+ minHeight: 0,
38
+ maxHeight: 'min(80dvh, calc(100dvh - 200px))',
39
+ overflow: 'hidden',
40
+ } as const;
24
41
  let resolvePromise: (
25
42
  value: { row: D; field?: string } | PromiseLike<{ row: D; field?: string }>,
26
43
  ) => void;
@@ -61,27 +78,18 @@
61
78
  });
62
79
  }
63
80
  };
64
- onMounted(() => {});
65
81
  defineExpose({
66
82
  pick: () =>
67
83
  new Promise<{ row: D; field?: string } | D[]>((resolve, reject) => {
68
84
  resolvePromise = resolve;
69
85
  rejectPromise = reject;
70
- rendered.value = false;
71
86
  visible.modal = true;
72
- nextTick(() => {
73
- rendered.value = true;
74
- });
75
87
  }),
76
88
  pickMultiple: () =>
77
89
  new Promise<{ row: D; field?: string } | D[]>((resolve, reject) => {
78
90
  multipleResolver = resolve;
79
91
  rejectPromise = reject;
80
- rendered.value = false;
81
92
  visible.modal = true;
82
- nextTick(() => {
83
- rendered.value = true;
84
- });
85
93
  }),
86
94
  grid: gridEl,
87
95
  hide: () => {
@@ -99,8 +107,8 @@
99
107
  @cancel="handleCancel"
100
108
  :body-style="bodyStyle"
101
109
  >
102
- <div :style="{ minHeight: rendered ? 'unset' : '642px' }">
103
- <p-grid v-bind="gridSetting" ref="gridEl" @pick="selectRow" />
110
+ <div :style="pickerBodyStyle">
111
+ <p-grid v-bind="mergedGridSetting" ref="gridEl" @pick="selectRow" />
104
112
  </div>
105
113
  <template v-if="isMultiple" #footer>
106
114
  <div class="w-full text-right p-2">
@@ -1,8 +1,16 @@
1
1
  import { createVNode } from 'vue';
2
2
  import * as $Icon from '@ant-design/icons-vue';
3
+ import { getUIKitConfig } from '@/utils/config';
4
+
3
5
  const Icon = (props: { icon: string }) => {
4
6
  const { icon } = props;
7
+ const customRender = getUIKitConfig().icon?.render;
8
+ if (customRender) {
9
+ const custom = customRender(icon);
10
+ if (custom) return custom;
11
+ }
5
12
  const antIcon: { [key: string]: any } = $Icon;
6
- return antIcon[icon] ? createVNode(antIcon[icon]) : antIcon[icon];
13
+ if (antIcon[icon]) return createVNode(antIcon[icon]);
14
+ return null;
7
15
  };
8
16
  export default Icon;
@@ -58,8 +58,15 @@ function findResizeAncestor(start: Element | null): Element {
58
58
  }
59
59
 
60
60
  /**
61
- * 宽/高先按「视口内从元素左上角到右/下边缘」计算,再与**直接父元素**布局框取较小值,
62
- * 避免嵌套在侧栏 + flex 列等窄容器里仍按整屏宽度赋值,从而撑出页面级横向滚动条。
61
+ * 宽/高先按「视口内从元素左上角到右/下边缘」计算。
62
+ *
63
+ * 宽度会再与**直接父元素**布局框取较小值,避免嵌套在侧栏 + flex 列等窄容器里仍按整屏宽度赋值,
64
+ * 从而撑出页面级横向滚动条。
65
+ *
66
+ * 高度不做 parent 截断:autoBoxSize 的语义就是「一直撑到视口底」。若对 parent 取 min,
67
+ * 遇到「父容器没有明确高度、靠子元素内容撑开」的常见布局(外层未写死高度,p-grid 根节点
68
+ * 自身决定可视高度),会形成循环依赖(子依赖父、父又靠子撑开),导致高度被截成极小值,
69
+ * 反映到 PGrid 上就是表体下方出现大面积空白。
63
70
  */
64
71
  export function applyViewportRestSize(el: HTMLElement, offset: AutoViewportBoxOffset): void {
65
72
  const rect = el.getBoundingClientRect();
@@ -67,7 +74,7 @@ export function applyViewportRestSize(el: HTMLElement, offset: AutoViewportBoxOf
67
74
  const vh = window.innerHeight;
68
75
 
69
76
  let targetW = Math.max(0, vw - rect.left - offset.right);
70
- let targetH = Math.max(0, vh - rect.top - offset.bottom);
77
+ const targetH = Math.max(0, vh - rect.top - offset.bottom);
71
78
 
72
79
  const parent = el.parentElement;
73
80
  if (parent) {
@@ -75,9 +82,6 @@ export function applyViewportRestSize(el: HTMLElement, offset: AutoViewportBoxOf
75
82
  if (pr.width > 0) {
76
83
  targetW = Math.min(targetW, pr.width);
77
84
  }
78
- if (pr.height > 0) {
79
- targetH = Math.min(targetH, pr.height);
80
- }
81
85
  }
82
86
 
83
87
  el.style.width = `${targetW}px`;
@@ -26,6 +26,12 @@ export interface UIKitConfig {
26
26
  * @param content tooltip 内容,字符串或返回 VNode 的函数
27
27
  */
28
28
  renderTooltip?: (defaultSlot: () => VNode, content: string | (() => VNode)) => VNode;
29
+ /**
30
+ * 自定义图标:按 `icon` 名字渲染;返回值为真时优先于 `@ant-design/icons-vue` 同名组件。
31
+ */
32
+ icon?: {
33
+ render?: (name: string) => unknown;
34
+ };
29
35
  }
30
36
 
31
37
  // 默认配置
@@ -45,6 +51,7 @@ const defaultConfig: UIKitConfig = {
45
51
  ENABLE_FINDER: true,
46
52
  AUTO_ROW_HEIGHT: true,
47
53
  },
54
+ icon: {},
48
55
  };
49
56
 
50
57
  // 当前配置(可被修改)
@@ -66,6 +73,10 @@ export function setUIKitConfig(config: Partial<UIKitConfig>): void {
66
73
  ...config.canvasTable,
67
74
  },
68
75
  renderTooltip: config.renderTooltip ?? currentConfig.renderTooltip,
76
+ icon: {
77
+ ...currentConfig.icon,
78
+ ...config.icon,
79
+ },
69
80
  };
70
81
  }
71
82