@ysgroup/ui 0.1.47 → 0.1.48
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 +1 -1
- package/src/components/YsCrudTable.vue +15 -4
- package/src/components/YsMultiCell.vue +33 -0
- package/src/index.ts +2 -0
- package/src/multiValue.ts +15 -0
package/package.json
CHANGED
|
@@ -8,6 +8,8 @@ import { ysMatch, ysSearchText } from "@ysgroup/core";
|
|
|
8
8
|
import { enumLabel } from "../tokens-runtime";
|
|
9
9
|
import { columnWidth as lookupColumnWidth } from "../columnWidths";
|
|
10
10
|
import YsBoolMark from "./YsBoolMark.vue";
|
|
11
|
+
import YsMultiCell from "./YsMultiCell.vue";
|
|
12
|
+
import { ysMultiText } from "../multiValue";
|
|
11
13
|
import YsFormDialog from "./YsFormDialog.vue";
|
|
12
14
|
import YsRowActionMenu from "./YsRowActionMenu.vue";
|
|
13
15
|
import YsTableToolbar from "./YsTableToolbar.vue";
|
|
@@ -104,8 +106,15 @@ function switchLabels(field: FieldSpec): { on: string; off: string } {
|
|
|
104
106
|
return { on: "是", off: "否" };
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
function cellValue(row: Record<string, unknown>, f: FieldSpec): unknown {
|
|
110
|
+
return props.rowDisplay ? props.rowDisplay(row, f.key, row[f.key]) : row[f.key];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** 本页有数组值的列:单元格用 YsMultiCell(一行「、」隔开,悬停每项一行),列上不再开表格自带的悬停提示。 */
|
|
114
|
+
const multiColumns = computed(() => new Set(displayColumns.value.filter((c) => paged.value.some((row) => Array.isArray(cellValue(row, c)))).map((c) => c.key)));
|
|
115
|
+
|
|
107
116
|
function display(row: Record<string, unknown>, f: FieldSpec): string {
|
|
108
|
-
const v =
|
|
117
|
+
const v = cellValue(row, f);
|
|
109
118
|
if (f.widget === "switch") {
|
|
110
119
|
const labels = switchLabels(f);
|
|
111
120
|
return v ? labels.on : labels.off;
|
|
@@ -113,7 +122,7 @@ function display(row: Record<string, unknown>, f: FieldSpec): string {
|
|
|
113
122
|
if (f.widget === "enum" && f.enum && ENUM_META[f.enum as keyof typeof ENUM_META]) {
|
|
114
123
|
return enumLabel(f.enum as keyof typeof ENUM_META, String(v ?? ""));
|
|
115
124
|
}
|
|
116
|
-
if (Array.isArray(v)) return v
|
|
125
|
+
if (Array.isArray(v)) return ysMultiText(v);
|
|
117
126
|
return String(v ?? "");
|
|
118
127
|
}
|
|
119
128
|
|
|
@@ -157,12 +166,14 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
157
166
|
:key="c.key"
|
|
158
167
|
:label="c.title"
|
|
159
168
|
:width="columnWidth(c)"
|
|
160
|
-
:show-overflow-tooltip="c.widget !== 'switch'"
|
|
169
|
+
:show-overflow-tooltip="c.widget !== 'switch' && !multiColumns.has(c.key)"
|
|
161
170
|
:align="c.widget === 'switch' ? 'center' : undefined"
|
|
162
171
|
>
|
|
163
172
|
<template #default="{ row }">
|
|
164
173
|
<YsBoolMark v-if="c.widget === 'switch'" :value="row[c.key]" :on-label="switchLabels(c).on" :off-label="switchLabels(c).off" />
|
|
165
|
-
<slot v-else name="cell" :row="row" :column="c" :text="display(row, c)"
|
|
174
|
+
<slot v-else name="cell" :row="row" :column="c" :text="display(row, c)"
|
|
175
|
+
><YsMultiCell v-if="Array.isArray(cellValue(row, c))" :items="cellValue(row, c)" /><template v-else>{{ display(row, c) }}</template></slot
|
|
176
|
+
>
|
|
166
177
|
</template>
|
|
167
178
|
</el-table-column>
|
|
168
179
|
<el-table-column v-if="!readonly" label="操作栏" :width="actionWidth ?? 76" fixed="right" align="center">
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* 多值单元格(规范 8.5「多值单元格」):表格里一行显示,各项用「、」隔开,放不下时省略号;
|
|
4
|
+
* 只在被截断时悬停立即显示提示,提示里每项一行,方便逐条阅读。
|
|
5
|
+
*
|
|
6
|
+
* <YsMultiCell :items="row.fund_names" />
|
|
7
|
+
* <YsMultiCell :items="row.ips" empty="—" />
|
|
8
|
+
*
|
|
9
|
+
* items 可以是数组(空值、空字符串自动去掉),也可以是单个值;YsCrudTable 遇到数组值时自动用它。
|
|
10
|
+
* 列上不要再开 show-overflow-tooltip(会和本组件的提示叠在一起)。
|
|
11
|
+
*/
|
|
12
|
+
import { computed } from "vue";
|
|
13
|
+
import { vTip } from "../vTip";
|
|
14
|
+
import { ysMultiItems, YS_MULTI_SEPARATOR } from "../multiValue";
|
|
15
|
+
|
|
16
|
+
const props = withDefaults(defineProps<{ items: unknown; empty?: string }>(), { empty: "" });
|
|
17
|
+
const lines = computed(() => ysMultiItems(props.items));
|
|
18
|
+
const text = computed(() => lines.value.join(YS_MULTI_SEPARATOR) || props.empty);
|
|
19
|
+
const tip = computed(() => lines.value.join("\n"));
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<span v-tip.overflow="tip" class="ys-multi-cell">{{ text }}</span>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<style scoped>
|
|
27
|
+
.ys-multi-cell {
|
|
28
|
+
display: block;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
text-overflow: ellipsis;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
}
|
|
33
|
+
</style>
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,8 @@ export { default as YsSettingsCenterDialog } from "./components/YsSettingsCenter
|
|
|
26
26
|
export { default as YsPortalGrid } from "./components/YsPortalGrid.vue";
|
|
27
27
|
export { default as YsRoleTag } from "./components/YsRoleTag.vue";
|
|
28
28
|
export { default as YsAmount } from "./components/YsAmount.vue";
|
|
29
|
+
export { default as YsMultiCell } from "./components/YsMultiCell.vue";
|
|
30
|
+
export { ysMultiItems, ysMultiText, YS_MULTI_SEPARATOR } from "./multiValue";
|
|
29
31
|
export { default as YsBoolMark } from "./components/YsBoolMark.vue";
|
|
30
32
|
export { default as YsSegmented } from "./components/YsSegmented.vue";
|
|
31
33
|
export { default as YsCountBadge } from "./components/YsCountBadge.vue";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 多值单元格的文字规则(YsMultiCell、YsCrudTable 共用,业务仓拼搜索文本时也用它)。 */
|
|
2
|
+
|
|
3
|
+
/** 表格里各项之间的分隔符。 */
|
|
4
|
+
export const YS_MULTI_SEPARATOR = "、";
|
|
5
|
+
|
|
6
|
+
/** 把数组(或单个值)整理成要显示的各项:去掉空值和首尾空白,嵌套数组展开。 */
|
|
7
|
+
export function ysMultiItems(value: unknown): string[] {
|
|
8
|
+
const list = Array.isArray(value) ? value.flat(Infinity) : [value];
|
|
9
|
+
return list.map((item) => (item === null || item === undefined ? "" : String(item).trim())).filter(Boolean);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** 单元格里显示的一行文字:各项用「、」隔开。 */
|
|
13
|
+
export function ysMultiText(value: unknown): string {
|
|
14
|
+
return ysMultiItems(value).join(YS_MULTI_SEPARATOR);
|
|
15
|
+
}
|