@liujitcn/kratos-admin-core 0.0.51 → 0.0.52

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.
@@ -1,8 +1,15 @@
1
1
  import { ColumnProps } from "../../components/ProTable/interface";
2
2
  import { BreakPoint } from "../../components/Grid/interface";
3
+ /** 搜索列配置,补充 ProForm 风格的插槽名称和字段后置位置。 */
4
+ type SearchColumn = ColumnProps & {
5
+ /** 自定义搜索项插槽名称,未配置时使用字段 prop。 */
6
+ slotName?: string;
7
+ /** 将当前搜索项插入到指定字段后面。 */
8
+ after?: string;
9
+ };
3
10
  /** ProTable 搜索表单组件属性。 */
4
11
  interface ProTableProps {
5
- columns?: ColumnProps[];
12
+ columns?: SearchColumn[];
6
13
  searchParam?: {
7
14
  [key: string]: any;
8
15
  };
@@ -11,12 +18,32 @@ interface ProTableProps {
11
18
  reset: (params: any) => void;
12
19
  showOperation?: boolean;
13
20
  }
14
- declare const __VLS_export: import("vue").DefineComponent<ProTableProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ProTableProps> & Readonly<{}>, {
15
- columns: ColumnProps[];
21
+ declare var __VLS_43: string | undefined, __VLS_44: {
22
+ field: SearchColumn;
23
+ model: {
24
+ [key: string]: any;
25
+ };
26
+ column: SearchColumn;
27
+ searchParam: {
28
+ [key: string]: any;
29
+ };
30
+ prop: string | undefined;
31
+ };
32
+ type __VLS_Slots = {} & {
33
+ [K in NonNullable<typeof __VLS_43>]?: (props: typeof __VLS_44) => any;
34
+ };
35
+ declare const __VLS_base: import("vue").DefineComponent<ProTableProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<ProTableProps> & Readonly<{}>, {
36
+ columns: SearchColumn[];
16
37
  searchParam: {
17
38
  [key: string]: any;
18
39
  };
19
40
  showOperation: boolean;
20
41
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
42
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
21
43
  declare const _default: typeof __VLS_export;
22
44
  export default _default;
45
+ type __VLS_WithSlots<T, S> = T & {
46
+ new (): {
47
+ $slots: S;
48
+ };
49
+ };
@@ -1,8 +1,8 @@
1
1
  <template>
2
- <div v-if="columns.length" class="card table-search" :class="{ 'table-search--no-operation': !showOperation }">
2
+ <div v-if="searchColumns.length" class="card table-search" :class="{ 'table-search--no-operation': !showOperation }">
3
3
  <el-form ref="formRef" :model="searchParam">
4
4
  <Grid ref="gridRef" :collapsed="collapsed" :gap="[20, 0]" :cols="searchCol">
5
- <GridItem v-for="(item, index) in columns" :key="item.prop" v-bind="getResponsive(item)" :index="index">
5
+ <GridItem v-for="(item, index) in searchColumns" :key="item.prop" v-bind="getResponsive(item)" :index="index">
6
6
  <el-form-item>
7
7
  <template #label>
8
8
  <el-space :size="4">
@@ -13,7 +13,17 @@
13
13
  </el-space>
14
14
  <span>&nbsp;:</span>
15
15
  </template>
16
- <SearchFormItem :column="item" :search-param="searchParam" />
16
+ <template v-if="resolveSearchSlotName(item)">
17
+ <slot
18
+ :name="resolveSearchSlotName(item)"
19
+ :field="item"
20
+ :model="searchParam"
21
+ :column="item"
22
+ :search-param="searchParam"
23
+ :prop="item.search?.key ?? item.prop"
24
+ />
25
+ </template>
26
+ <SearchFormItem v-else :column="item" :search-param="searchParam" />
17
27
  </el-form-item>
18
28
  </GridItem>
19
29
  <GridItem v-if="showOperation" suffix>
@@ -33,7 +43,7 @@
33
43
  </div>
34
44
  </template>
35
45
  <script setup lang="ts" name="SearchForm">
36
- import { computed, ref } from "vue";
46
+ import { computed, ref, useSlots } from "vue";
37
47
  import { ColumnProps } from "../../components/ProTable/interface";
38
48
  import { BreakPoint } from "../../components/Grid/interface";
39
49
  import { Delete, Search, ArrowDown, ArrowUp } from "@element-plus/icons-vue";
@@ -44,9 +54,17 @@ import { useLocaleStore } from "../../locales";
44
54
 
45
55
  const { t } = useLocaleStore();
46
56
 
57
+ /** 搜索列配置,补充 ProForm 风格的插槽名称和字段后置位置。 */
58
+ type SearchColumn = ColumnProps & {
59
+ /** 自定义搜索项插槽名称,未配置时使用字段 prop。 */
60
+ slotName?: string;
61
+ /** 将当前搜索项插入到指定字段后面。 */
62
+ after?: string;
63
+ };
64
+
47
65
  /** ProTable 搜索表单组件属性。 */
48
66
  interface ProTableProps {
49
- columns?: ColumnProps[]; // 搜索配置列
67
+ columns?: SearchColumn[]; // 搜索配置列
50
68
  searchParam?: { [key: string]: any }; // 搜索参数
51
69
  searchCol: number | Record<BreakPoint, number>;
52
70
  search: (params: any) => void; // 搜索方法
@@ -61,6 +79,43 @@ const props = withDefaults(defineProps<ProTableProps>(), {
61
79
  showOperation: true
62
80
  });
63
81
 
82
+ const slots = useSlots();
83
+
84
+ /** 按 after 配置排列搜索项,未配置或找不到目标字段时保持原有顺序。 */
85
+ const searchColumns = computed<SearchColumn[]>(() => {
86
+ const sourceColumns = [...(props.columns ?? [])];
87
+ const positionedColumns = sourceColumns.filter(column => {
88
+ const after = column.after;
89
+ return Boolean(after && sourceColumns.some(item => item.prop === after));
90
+ });
91
+ const positionedSet = new Set(positionedColumns);
92
+ const columnsByAnchor = new Map<string, SearchColumn[]>();
93
+ for (const column of positionedColumns) {
94
+ const anchor = column.after!;
95
+ const columns = columnsByAnchor.get(anchor) ?? [];
96
+ columns.push(column);
97
+ columnsByAnchor.set(anchor, columns);
98
+ }
99
+
100
+ const result: SearchColumn[] = [];
101
+ for (const column of sourceColumns) {
102
+ if (positionedSet.has(column)) continue;
103
+ result.push(column);
104
+ const columns = column.prop ? columnsByAnchor.get(column.prop) : undefined;
105
+ if (!columns) continue;
106
+ result.push(...columns);
107
+ columnsByAnchor.delete(column.prop!);
108
+ }
109
+ for (const columns of columnsByAnchor.values()) result.push(...columns);
110
+ return result;
111
+ });
112
+
113
+ /** 按 ProForm 的 slotName 优先、字段 prop 回退规则解析搜索项插槽。 */
114
+ function resolveSearchSlotName(item: SearchColumn): string | undefined {
115
+ const slotName = item.slotName ?? item.prop;
116
+ return slotName && slots[slotName] ? slotName : undefined;
117
+ }
118
+
64
119
  // 获取响应式设置
65
120
  const getResponsive = (item: ColumnProps) => {
66
121
  return {
@@ -84,10 +139,10 @@ const breakPoint = computed<BreakPoint>(() => gridRef.value?.breakPoint);
84
139
  // 判断是否显示 展开/合并 按钮
85
140
  const showCollapse = computed(() => {
86
141
  let show = false;
87
- props.columns.reduce((prev, current) => {
142
+ searchColumns.value.reduce((prev, current) => {
88
143
  prev +=
89
- (current.search![breakPoint.value]?.span ?? current.search?.span ?? 1) +
90
- (current.search![breakPoint.value]?.offset ?? current.search?.offset ?? 0);
144
+ (current.search?.[breakPoint.value]?.span ?? current.search?.span ?? 1) +
145
+ (current.search?.[breakPoint.value]?.offset ?? current.search?.offset ?? 0);
91
146
  if (typeof props.searchCol !== "number") {
92
147
  if (prev >= props.searchCol[breakPoint.value]) show = true;
93
148
  } else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liujitcn/kratos-admin-core",
3
3
  "private": false,
4
- "version": "0.0.51",
4
+ "version": "0.0.52",
5
5
  "type": "module",
6
6
  "description": "kratos-admin frontend runtime and base modules",
7
7
  "author": {