@ysgroup/ui 0.1.61 → 0.1.62
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 +3 -3
- package/src/components/YsAppToolbar.vue +18 -9
- package/src/components/YsCalendar.vue +45 -12
- package/src/components/YsCalendarDayCard.vue +4 -4
- package/src/components/YsCardList.vue +247 -0
- package/src/components/YsCrudTable.vue +25 -1
- package/src/components/YsFilePreview.vue +3 -2
- package/src/components/YsPageHeader.vue +9 -3
- package/src/components/YsPageLayout.vue +237 -27
- package/src/components/YsRowActionMenu.vue +13 -0
- package/src/components/YsSettingsCenterDialog.vue +2 -1
- package/src/components/YsSideMenu.vue +13 -0
- package/src/components/YsTablePagination.vue +12 -1
- package/src/components/YsTableToolbar.vue +46 -1
- package/src/index.ts +12 -0
- package/src/viewport.ts +52 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ysgroup/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.62",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@ysgroup/contracts": ">=0.1.50",
|
|
14
14
|
"@ysgroup/core": ">=0.1.34",
|
|
15
|
-
"@ysgroup/theme": ">=0.3.
|
|
15
|
+
"@ysgroup/theme": ">=0.3.4",
|
|
16
16
|
"element-plus": ">=2.9",
|
|
17
17
|
"vue": ">=3.5"
|
|
18
18
|
},
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@ysgroup/contracts": "^0.1.53",
|
|
29
29
|
"@ysgroup/core": "^0.1.34",
|
|
30
|
-
"@ysgroup/theme": "^0.3.
|
|
30
|
+
"@ysgroup/theme": "^0.3.4",
|
|
31
31
|
"docx-preview": "^0.4.1"
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { onBeforeUnmount, ref } from "vue";
|
|
2
|
+
import { computed, onBeforeUnmount, ref } from "vue";
|
|
3
3
|
import { ElMessage } from "element-plus";
|
|
4
4
|
import { Moon, Setting, Sunny } from "@element-plus/icons-vue";
|
|
5
5
|
import {
|
|
@@ -9,11 +9,16 @@ import {
|
|
|
9
9
|
THEME_CHANGE_EVENT,
|
|
10
10
|
type ThemeMode,
|
|
11
11
|
} from "@ysgroup/theme";
|
|
12
|
+
import { useYsMobile, useYsTouch } from "../viewport";
|
|
12
13
|
|
|
13
14
|
defineProps<{ username?: string }>();
|
|
14
15
|
const emit = defineEmits<{ settings: []; logout: [] }>();
|
|
15
16
|
const mode = ref<ThemeMode>(resolvedMode());
|
|
16
17
|
const dropdown = ref<{ handleClose: () => void } | null>(null);
|
|
18
|
+
const mobile = useYsMobile();
|
|
19
|
+
const touch = useYsTouch();
|
|
20
|
+
/** 触屏没有悬停:设置菜单改成点一下打开;换肤按钮在触屏上直接切换,不弹菜单。 */
|
|
21
|
+
const menuTrigger = computed(() => (touch.value ? "click" : "hover"));
|
|
17
22
|
if (currentMode() === "auto") applyTheme(mode.value, "sync");
|
|
18
23
|
|
|
19
24
|
// 登录后按账号偏好切换、或别处切换时,图标跟着变。
|
|
@@ -51,13 +56,15 @@ function settingsCommand(command: string) {
|
|
|
51
56
|
|
|
52
57
|
<template>
|
|
53
58
|
<div class="ys-app-toolbar">
|
|
54
|
-
|
|
59
|
+
<!-- 手机上不显示用户名(设置中心里有),把顶栏留给系统名称。 -->
|
|
60
|
+
<span v-if="username && !mobile" class="ys-app-toolbar__user" :title="username">{{
|
|
55
61
|
username
|
|
56
62
|
}}</span>
|
|
57
|
-
<span v-if="username" class="ys-app-toolbar__divider" aria-hidden="true" />
|
|
63
|
+
<span v-if="username && !mobile" class="ys-app-toolbar__divider" aria-hidden="true" />
|
|
58
64
|
<el-dropdown
|
|
59
65
|
ref="dropdown"
|
|
60
66
|
trigger="hover"
|
|
67
|
+
:disabled="touch"
|
|
61
68
|
popper-class="ys-app-theme-menu"
|
|
62
69
|
@command="selectTheme"
|
|
63
70
|
>
|
|
@@ -88,7 +95,7 @@ function settingsCommand(command: string) {
|
|
|
88
95
|
</template>
|
|
89
96
|
</el-dropdown>
|
|
90
97
|
<span class="ys-app-toolbar__divider" aria-hidden="true" />
|
|
91
|
-
<el-dropdown trigger="
|
|
98
|
+
<el-dropdown :trigger="menuTrigger" @command="settingsCommand">
|
|
92
99
|
<button type="button" class="ys-app-toolbar__button" aria-label="设置">
|
|
93
100
|
<el-icon :size="18"><Setting /></el-icon>
|
|
94
101
|
</button>
|
|
@@ -156,16 +163,18 @@ function settingsCommand(command: string) {
|
|
|
156
163
|
outline-offset: -2px;
|
|
157
164
|
color: var(--ys-color-primary);
|
|
158
165
|
}
|
|
159
|
-
|
|
166
|
+
/* 手机:按钮放大到 40px,分隔线收窄。 */
|
|
167
|
+
@media (max-width: 767px) {
|
|
160
168
|
.ys-app-toolbar {
|
|
161
169
|
padding-left: 4px;
|
|
170
|
+
gap: 0;
|
|
162
171
|
}
|
|
163
|
-
.ys-app-
|
|
164
|
-
|
|
165
|
-
|
|
172
|
+
.ys-app-toolbar__button {
|
|
173
|
+
width: 40px;
|
|
174
|
+
height: 40px;
|
|
166
175
|
}
|
|
167
176
|
.ys-app-toolbar__divider {
|
|
168
|
-
margin: 0
|
|
177
|
+
margin: 0 2px;
|
|
169
178
|
}
|
|
170
179
|
}
|
|
171
180
|
</style>
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* 如「2026 年:Auth 下发 · 已与交易所核对」,悬停看各数据源的核对结果。
|
|
22
22
|
*/
|
|
23
23
|
import { computed, nextTick, ref, watch } from "vue";
|
|
24
|
+
import { useYsMobile } from "../viewport";
|
|
24
25
|
import {
|
|
25
26
|
YS_DAY_KIND_LABELS,
|
|
26
27
|
YS_TRADING_TAG_LABELS,
|
|
@@ -159,6 +160,12 @@ const eventMap = computed(() => {
|
|
|
159
160
|
return map;
|
|
160
161
|
});
|
|
161
162
|
const small = computed(() => props.size === "small");
|
|
163
|
+
/**
|
|
164
|
+
* 格子紧凑:迷你模式,或者手机(≤767px,每格只有 50px 左右宽,放不下状态标签和事件条)。
|
|
165
|
+
* 紧凑时格子里只有日期、底色、休 / 班角标和事件圆点;手机上月份统计、数据来源、图例照常显示,详情看旁边的 YsCalendarDayCard。
|
|
166
|
+
*/
|
|
167
|
+
const mobile = useYsMobile();
|
|
168
|
+
const compact = computed(() => small.value || mobile.value);
|
|
162
169
|
const view = computed(() => props.mark ?? (props.trading ? "trading" : "none"));
|
|
163
170
|
const tradingView = computed(() => view.value === "trading");
|
|
164
171
|
const labelText = computed<YsCalendarLabels>(() => ({
|
|
@@ -467,6 +474,8 @@ function goToday() {
|
|
|
467
474
|
class="ys-calendar"
|
|
468
475
|
:class="{
|
|
469
476
|
'is-small': small,
|
|
477
|
+
'is-compact': compact,
|
|
478
|
+
'is-mobile': mobile,
|
|
470
479
|
'is-trading-view': tradingView,
|
|
471
480
|
'is-focusing': Boolean(focusStatus),
|
|
472
481
|
}"
|
|
@@ -556,7 +565,7 @@ function goToday() {
|
|
|
556
565
|
:class="{ 'is-weekend': index >= 5 }"
|
|
557
566
|
role="columnheader"
|
|
558
567
|
>
|
|
559
|
-
{{
|
|
568
|
+
{{ compact ? label : `周${label}` }}
|
|
560
569
|
</div>
|
|
561
570
|
</div>
|
|
562
571
|
<div
|
|
@@ -605,14 +614,14 @@ function goToday() {
|
|
|
605
614
|
Number(cell.date.slice(8))
|
|
606
615
|
}}</span>
|
|
607
616
|
<span
|
|
608
|
-
v-if="
|
|
617
|
+
v-if="compact && badge(cell.date)"
|
|
609
618
|
class="ys-calendar__badge"
|
|
610
619
|
:class="badge(cell.date) === '休' ? 'is-off' : 'is-work'"
|
|
611
620
|
>{{ badge(cell.date) }}</span
|
|
612
621
|
>
|
|
613
622
|
<span
|
|
614
623
|
v-else-if="
|
|
615
|
-
!
|
|
624
|
+
!compact &&
|
|
616
625
|
(ordinalOf(cell.date) ||
|
|
617
626
|
hasNight(cell.date) ||
|
|
618
627
|
(showLabel && statusLabel(cell.date)))
|
|
@@ -639,7 +648,7 @@ function goToday() {
|
|
|
639
648
|
>
|
|
640
649
|
</span>
|
|
641
650
|
</div>
|
|
642
|
-
<template v-if="!
|
|
651
|
+
<template v-if="!compact">
|
|
643
652
|
<div v-if="subline(cell.date)" class="ys-calendar__name">
|
|
644
653
|
{{ subline(cell.date) }}
|
|
645
654
|
</div>
|
|
@@ -1198,33 +1207,33 @@ function goToday() {
|
|
|
1198
1207
|
content: "";
|
|
1199
1208
|
}
|
|
1200
1209
|
|
|
1201
|
-
/*
|
|
1202
|
-
.ys-calendar.is-
|
|
1210
|
+
/* 紧凑格子(迷你模式和手机):只有日期、底色、休、班角标和事件圆点,悬停或看详情卡了解完整信息 */
|
|
1211
|
+
.ys-calendar.is-compact .ys-calendar__weekday {
|
|
1203
1212
|
padding: 4px 0;
|
|
1204
1213
|
text-align: center;
|
|
1205
1214
|
}
|
|
1206
|
-
.ys-calendar.is-
|
|
1215
|
+
.ys-calendar.is-compact .ys-calendar__cell {
|
|
1207
1216
|
align-items: center;
|
|
1208
1217
|
justify-content: center;
|
|
1209
1218
|
min-height: 36px;
|
|
1210
1219
|
padding: 2px;
|
|
1211
1220
|
}
|
|
1212
|
-
.ys-calendar.is-
|
|
1221
|
+
.ys-calendar.is-compact .ys-calendar__cell + .ys-calendar__cell {
|
|
1213
1222
|
border-left: 0;
|
|
1214
1223
|
}
|
|
1215
|
-
.ys-calendar.is-
|
|
1224
|
+
.ys-calendar.is-compact .ys-calendar__row + .ys-calendar__row {
|
|
1216
1225
|
border-top: 0;
|
|
1217
1226
|
}
|
|
1218
1227
|
/* 角标跟着日期数字:top 只包住数字,角标挂在数字右上角(不超出最右一列) */
|
|
1219
|
-
.ys-calendar.is-
|
|
1228
|
+
.ys-calendar.is-compact .ys-calendar__top {
|
|
1220
1229
|
position: relative;
|
|
1221
1230
|
display: inline-flex;
|
|
1222
1231
|
}
|
|
1223
|
-
.ys-calendar.is-
|
|
1232
|
+
.ys-calendar.is-compact .ys-calendar__date {
|
|
1224
1233
|
font-size: 12px;
|
|
1225
1234
|
font-weight: 500;
|
|
1226
1235
|
}
|
|
1227
|
-
.ys-calendar.is-
|
|
1236
|
+
.ys-calendar.is-compact .ys-calendar__badge {
|
|
1228
1237
|
position: absolute;
|
|
1229
1238
|
top: -5px;
|
|
1230
1239
|
right: -6px;
|
|
@@ -1238,4 +1247,28 @@ function goToday() {
|
|
|
1238
1247
|
border-radius: 50%;
|
|
1239
1248
|
background: var(--ys-color-primary);
|
|
1240
1249
|
}
|
|
1250
|
+
/* 手机:格子高 44px 好点,月份切换和页面自己的开关(#extra)各占一行 */
|
|
1251
|
+
.ys-calendar.is-mobile .ys-calendar__cell {
|
|
1252
|
+
min-height: 44px;
|
|
1253
|
+
}
|
|
1254
|
+
.ys-calendar.is-mobile .ys-calendar__date {
|
|
1255
|
+
font-size: 14px;
|
|
1256
|
+
}
|
|
1257
|
+
.ys-calendar.is-mobile .ys-calendar__head {
|
|
1258
|
+
gap: 8px;
|
|
1259
|
+
}
|
|
1260
|
+
.ys-calendar.is-mobile .ys-calendar__nav {
|
|
1261
|
+
flex: 1 1 100%;
|
|
1262
|
+
}
|
|
1263
|
+
.ys-calendar.is-mobile .ys-calendar__nav :deep(.el-date-editor.ys-calendar__month) {
|
|
1264
|
+
flex: 1;
|
|
1265
|
+
width: auto;
|
|
1266
|
+
}
|
|
1267
|
+
.ys-calendar.is-mobile .ys-calendar__arrow {
|
|
1268
|
+
width: 40px;
|
|
1269
|
+
height: 36px;
|
|
1270
|
+
}
|
|
1271
|
+
.ys-calendar.is-mobile .ys-calendar__extra {
|
|
1272
|
+
flex: 1 1 100%;
|
|
1273
|
+
}
|
|
1241
1274
|
</style>
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* 选中日详情卡:放在 YsCalendar 旁边,介绍选中那天的情况。
|
|
4
4
|
*
|
|
5
|
-
* -
|
|
5
|
+
* - 头部:日期方块(颜色跟月历一致:工作日、法定补班浅绿,放假浅橙,休息灰)、完整日期、离今天几天、农历、
|
|
6
6
|
* 传统节日和节气。
|
|
7
7
|
* - 状态:工作日 / 法定补班 / 休息 / 放假、交易日 / 休市,以及节前最后、节后首日、月初、月末这些关键交易日(全称)。
|
|
8
8
|
* - 本月位置:几月第 N 个工作日、第 N 个交易日(带进度条),放假时写「国庆节假期第 3 天,共 8 天」。
|
|
9
9
|
* - 当天的事项(events),以及默认插槽放页面自己的内容(如上一个、下一个交易日和 T+N 推算)。
|
|
10
|
-
* -
|
|
10
|
+
* - 农历、干支生肖、传统节日和节气默认显示,页面不用加开关;确实不需要的系统传 :lunar="false"。农历用 ysLunar 现算,只用于显示。
|
|
11
11
|
* - 交易所额外休市(国务院安排上班、交易所休市)写「交易所休市」和原因;交易日写当晚有没有期货夜盘、夜盘归属哪个交易日
|
|
12
12
|
* (night 关掉不写)。
|
|
13
13
|
* - years 传了就在底部写这一天所在年份的数据来源与核对状态。
|
|
@@ -53,7 +53,7 @@ const props = withDefaults(
|
|
|
53
53
|
labels?: Partial<YsCalendarLabels>;
|
|
54
54
|
/** 显示交易日相关内容(交易日 / 休市、第几个交易日、关键交易日);不涉及交易的系统可以关掉。 */
|
|
55
55
|
trading?: boolean;
|
|
56
|
-
/**
|
|
56
|
+
/** 显示农历、干支生肖、传统节日和节气;默认显示,不需要时传 false。 */
|
|
57
57
|
lunar?: boolean;
|
|
58
58
|
/** 交易日写当晚有没有期货夜盘(trading 关掉时也不写)。 */
|
|
59
59
|
night?: boolean;
|
|
@@ -66,7 +66,7 @@ const props = withDefaults(
|
|
|
66
66
|
today: "",
|
|
67
67
|
labels: () => ({}),
|
|
68
68
|
trading: true,
|
|
69
|
-
lunar:
|
|
69
|
+
lunar: true,
|
|
70
70
|
night: true,
|
|
71
71
|
years: () => [],
|
|
72
72
|
},
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<!-- YsCardList —— 手机上的列表:每条记录一张卡片,代替横向拖不完的表格。
|
|
2
|
+
和表格用同一份数据(当前页的行)、同一套三态和同一个齿轮菜单,页面写法:
|
|
3
|
+
<YsCardList v-if="mobile" :rows="paged" :fields="cardFields" :title="(row) => row.name" :actions="rowActions"
|
|
4
|
+
:loading="loading" :empty-text="emptyText" :index="rowIndex" @action="handleAction" />
|
|
5
|
+
<el-table v-else …>
|
|
6
|
+
- 卡片头:序号(传 index 才有)、标题(一定要有,通常是名称列)、#tags 插槽放状态标签(已归档、已删除)、右上角齿轮菜单。
|
|
7
|
+
- 卡片体:fields 两列排开,标签在上、值在下;wide 的字段独占一行(备注、地址这类长文字);
|
|
8
|
+
值为 null、undefined、空串、空数组时显示「—」,0 照常显示 0;align: "right" 的数值用等宽数字(卡片里不右对齐,标签和值上下排)。
|
|
9
|
+
- #field 插槽可以改某个字段的显示(如 YsBoolMark、链接),参数 { row, field, text }。
|
|
10
|
+
- loading 时转圈(保留旧卡片),没有行时显示 emptyText;读取失败由页面上方的 YsLoadError 负责,和表格一样。
|
|
11
|
+
- 长标题、长值自动换行,不截断(手机上没有悬停,截断了就看不到全文)。
|
|
12
|
+
- 监听了 row-click 时整张卡片可点(如点消息标为已读);点卡片里的按钮、链接、齿轮不触发。 -->
|
|
13
|
+
<script setup lang="ts" generic="T extends object">
|
|
14
|
+
import { computed } from "vue";
|
|
15
|
+
import YsRowActionMenu, { type YsRowAction } from "./YsRowActionMenu.vue";
|
|
16
|
+
import { ysMultiText } from "../multiValue";
|
|
17
|
+
|
|
18
|
+
export interface YsCardField<R = Record<string, unknown>> {
|
|
19
|
+
key: string;
|
|
20
|
+
label: string;
|
|
21
|
+
/** 取值;不传时读 row[key]。数组按「、」连起来。 */
|
|
22
|
+
value?: (row: R) => unknown;
|
|
23
|
+
/** 数值列:表格里右对齐,卡片里用等宽数字。 */
|
|
24
|
+
align?: "left" | "right";
|
|
25
|
+
/** 独占一行(长文字)。 */
|
|
26
|
+
wide?: boolean;
|
|
27
|
+
/** 返回 true 时这张卡片不显示该字段(如学生没有班级时不占位)。 */
|
|
28
|
+
hidden?: (row: R) => boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(
|
|
32
|
+
defineProps<{
|
|
33
|
+
rows: readonly T[];
|
|
34
|
+
fields: readonly YsCardField<T>[];
|
|
35
|
+
/** 卡片标题,通常是名称列。 */
|
|
36
|
+
title: (row: T) => unknown;
|
|
37
|
+
rowKey?: string;
|
|
38
|
+
/** 返回这一行的序号(和表格序号列一致,翻页后接着数);不传不显示序号。 */
|
|
39
|
+
index?: (position: number) => number;
|
|
40
|
+
/** 这一行的操作;返回空数组时不显示齿轮。 */
|
|
41
|
+
actions?: (row: T) => YsRowAction[];
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
emptyText?: string;
|
|
44
|
+
/**
|
|
45
|
+
* 点整张卡片(@row-click)。写成属性而不是 emits:组件要知道调用方有没有监听,没监听的卡片不画成可点的样子
|
|
46
|
+
* (声明在 emits 里的监听器不会出现在 attrs 里,判断不出来)。
|
|
47
|
+
*/
|
|
48
|
+
onRowClick?: (row: T) => void;
|
|
49
|
+
}>(),
|
|
50
|
+
{ rowKey: "_id", index: undefined, actions: undefined, loading: false, emptyText: "暂无数据", onRowClick: undefined },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const emit = defineEmits<{ action: [key: string, row: T] }>();
|
|
54
|
+
/** 只有监听了 row-click 才把卡片画成可点的样子。 */
|
|
55
|
+
const clickable = computed(() => typeof props.onRowClick === "function");
|
|
56
|
+
|
|
57
|
+
function onCardClick(event: MouseEvent, row: T) {
|
|
58
|
+
if ((event.target as HTMLElement | null)?.closest("button, a, input, textarea, [role='menuitem'], .el-popper")) return;
|
|
59
|
+
props.onRowClick?.(row);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
defineSlots<{
|
|
63
|
+
tags?: (props: { row: T }) => unknown;
|
|
64
|
+
field?: (props: { row: T; field: YsCardField<T>; text: string }) => unknown;
|
|
65
|
+
footer?: (props: { row: T }) => unknown;
|
|
66
|
+
/** 齿轮菜单里额外的项,和 YsRowActionMenu 的 #extra 一样。 */
|
|
67
|
+
"menu-extra"?: (props: { row: T; close: () => void }) => unknown;
|
|
68
|
+
}>();
|
|
69
|
+
|
|
70
|
+
function isBlank(value: unknown): boolean {
|
|
71
|
+
return value === null || value === undefined || value === "" || (Array.isArray(value) && value.length === 0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 显示文字:空值「—」,0 显示 0,数组用「、」连起来,数字带千分位由调用方在 value 里决定。 */
|
|
75
|
+
function textOf(row: T, field: YsCardField<T>): string {
|
|
76
|
+
const raw = field.value ? field.value(row) : (row as Record<string, unknown>)[field.key];
|
|
77
|
+
if (isBlank(raw)) return "—";
|
|
78
|
+
if (Array.isArray(raw)) return ysMultiText(raw);
|
|
79
|
+
return String(raw);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const cards = computed(() =>
|
|
83
|
+
props.rows.map((row, position) => ({
|
|
84
|
+
row,
|
|
85
|
+
key: String((row as Record<string, unknown>)[props.rowKey] ?? position),
|
|
86
|
+
index: props.index?.(position),
|
|
87
|
+
title: String(props.title(row) ?? "") || "—",
|
|
88
|
+
actions: props.actions?.(row) ?? [],
|
|
89
|
+
fields: props.fields.filter((field) => !field.hidden?.(row)).map((field) => ({ field, text: textOf(row, field) })),
|
|
90
|
+
})),
|
|
91
|
+
);
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<template>
|
|
95
|
+
<div v-loading="loading" class="ys-card-list" :class="{ 'is-empty': !cards.length }" role="list">
|
|
96
|
+
<p v-if="!cards.length" class="ys-card-list__empty">{{ loading ? "" : emptyText }}</p>
|
|
97
|
+
<article
|
|
98
|
+
v-for="card in cards"
|
|
99
|
+
:key="card.key"
|
|
100
|
+
class="ys-card-list__card"
|
|
101
|
+
:class="{ 'is-clickable': clickable }"
|
|
102
|
+
role="listitem"
|
|
103
|
+
@click="clickable && onCardClick($event, card.row)"
|
|
104
|
+
>
|
|
105
|
+
<header class="ys-card-list__head">
|
|
106
|
+
<span v-if="card.index !== undefined" class="ys-card-list__index">{{ card.index }}</span>
|
|
107
|
+
<div class="ys-card-list__title-wrap">
|
|
108
|
+
<h3 class="ys-card-list__title">{{ card.title }}</h3>
|
|
109
|
+
<span v-if="$slots.tags" class="ys-card-list__tags"><slot name="tags" :row="card.row" /></span>
|
|
110
|
+
</div>
|
|
111
|
+
<YsRowActionMenu
|
|
112
|
+
v-if="card.actions.length || $slots['menu-extra']"
|
|
113
|
+
class="ys-card-list__menu"
|
|
114
|
+
:actions="card.actions"
|
|
115
|
+
:aria-label="`${card.title} 的操作`"
|
|
116
|
+
@action="emit('action', $event, card.row)"
|
|
117
|
+
>
|
|
118
|
+
<template v-if="$slots['menu-extra']" #extra="{ close }"><slot name="menu-extra" :row="card.row" :close="close" /></template>
|
|
119
|
+
</YsRowActionMenu>
|
|
120
|
+
</header>
|
|
121
|
+
<dl v-if="card.fields.length" class="ys-card-list__fields">
|
|
122
|
+
<div v-for="item in card.fields" :key="item.field.key" class="ys-card-list__field" :class="{ 'is-wide': item.field.wide, 'is-right': item.field.align === 'right' }">
|
|
123
|
+
<dt>{{ item.field.label }}</dt>
|
|
124
|
+
<dd>
|
|
125
|
+
<slot name="field" :row="card.row" :field="item.field" :text="item.text">{{ item.text }}</slot>
|
|
126
|
+
</dd>
|
|
127
|
+
</div>
|
|
128
|
+
</dl>
|
|
129
|
+
<footer v-if="$slots.footer" class="ys-card-list__footer"><slot name="footer" :row="card.row" /></footer>
|
|
130
|
+
</article>
|
|
131
|
+
</div>
|
|
132
|
+
</template>
|
|
133
|
+
|
|
134
|
+
<style scoped>
|
|
135
|
+
.ys-card-list {
|
|
136
|
+
display: grid;
|
|
137
|
+
gap: 10px;
|
|
138
|
+
min-height: 64px;
|
|
139
|
+
}
|
|
140
|
+
.ys-card-list__empty {
|
|
141
|
+
margin: 0;
|
|
142
|
+
padding: 28px 12px;
|
|
143
|
+
border: 1px dashed var(--ys-color-border);
|
|
144
|
+
border-radius: var(--ys-radius-l);
|
|
145
|
+
color: var(--ys-color-text-3);
|
|
146
|
+
font-size: 13px;
|
|
147
|
+
line-height: 1.6;
|
|
148
|
+
text-align: center;
|
|
149
|
+
}
|
|
150
|
+
.ys-card-list.is-empty .ys-card-list__empty:empty {
|
|
151
|
+
border: 0;
|
|
152
|
+
}
|
|
153
|
+
.ys-card-list__card {
|
|
154
|
+
min-width: 0;
|
|
155
|
+
padding: 12px 12px 12px 14px;
|
|
156
|
+
border: 1px solid var(--ys-color-border);
|
|
157
|
+
border-radius: var(--ys-radius-l);
|
|
158
|
+
background: var(--ys-color-bg-elevated);
|
|
159
|
+
}
|
|
160
|
+
.ys-card-list__card.is-clickable {
|
|
161
|
+
cursor: pointer;
|
|
162
|
+
}
|
|
163
|
+
.ys-card-list__card.is-clickable:active {
|
|
164
|
+
background: var(--ys-color-bg-hover);
|
|
165
|
+
}
|
|
166
|
+
.ys-card-list__head {
|
|
167
|
+
display: flex;
|
|
168
|
+
align-items: flex-start;
|
|
169
|
+
gap: 8px;
|
|
170
|
+
}
|
|
171
|
+
.ys-card-list__index {
|
|
172
|
+
flex: none;
|
|
173
|
+
min-width: 22px;
|
|
174
|
+
height: 22px;
|
|
175
|
+
margin-top: 1px;
|
|
176
|
+
padding: 0 5px;
|
|
177
|
+
box-sizing: border-box;
|
|
178
|
+
border-radius: 11px;
|
|
179
|
+
background: var(--ys-color-bg-hover);
|
|
180
|
+
color: var(--ys-color-text-3);
|
|
181
|
+
font-size: 12px;
|
|
182
|
+
font-variant-numeric: tabular-nums;
|
|
183
|
+
line-height: 22px;
|
|
184
|
+
text-align: center;
|
|
185
|
+
}
|
|
186
|
+
.ys-card-list__title-wrap {
|
|
187
|
+
display: flex;
|
|
188
|
+
flex: 1;
|
|
189
|
+
flex-wrap: wrap;
|
|
190
|
+
align-items: center;
|
|
191
|
+
gap: 4px 6px;
|
|
192
|
+
min-width: 0;
|
|
193
|
+
}
|
|
194
|
+
.ys-card-list__title {
|
|
195
|
+
min-width: 0;
|
|
196
|
+
margin: 0;
|
|
197
|
+
color: var(--ys-color-text-1);
|
|
198
|
+
font-size: 15px;
|
|
199
|
+
font-weight: 600;
|
|
200
|
+
line-height: 24px;
|
|
201
|
+
overflow-wrap: anywhere;
|
|
202
|
+
}
|
|
203
|
+
.ys-card-list__tags {
|
|
204
|
+
display: inline-flex;
|
|
205
|
+
flex-wrap: wrap;
|
|
206
|
+
gap: 4px;
|
|
207
|
+
}
|
|
208
|
+
.ys-card-list__menu {
|
|
209
|
+
flex: none;
|
|
210
|
+
/* 齿轮按钮(触屏 40px)和标题第一行(24px)垂直居中对齐,右边贴近卡片边。 */
|
|
211
|
+
margin: -8px -8px -8px 0;
|
|
212
|
+
}
|
|
213
|
+
.ys-card-list__fields {
|
|
214
|
+
display: grid;
|
|
215
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
216
|
+
gap: 10px 12px;
|
|
217
|
+
margin: 10px 0 0;
|
|
218
|
+
}
|
|
219
|
+
.ys-card-list__field {
|
|
220
|
+
min-width: 0;
|
|
221
|
+
}
|
|
222
|
+
.ys-card-list__field.is-wide {
|
|
223
|
+
grid-column: 1 / -1;
|
|
224
|
+
}
|
|
225
|
+
.ys-card-list__field dt {
|
|
226
|
+
margin: 0 0 2px;
|
|
227
|
+
color: var(--ys-color-text-3);
|
|
228
|
+
font-size: 12px;
|
|
229
|
+
line-height: 18px;
|
|
230
|
+
}
|
|
231
|
+
.ys-card-list__field dd {
|
|
232
|
+
margin: 0;
|
|
233
|
+
color: var(--ys-color-text-1);
|
|
234
|
+
font-size: 14px;
|
|
235
|
+
line-height: 20px;
|
|
236
|
+
overflow-wrap: anywhere;
|
|
237
|
+
white-space: pre-line;
|
|
238
|
+
}
|
|
239
|
+
.ys-card-list__field.is-right dd {
|
|
240
|
+
font-variant-numeric: tabular-nums;
|
|
241
|
+
}
|
|
242
|
+
.ys-card-list__footer {
|
|
243
|
+
margin-top: 10px;
|
|
244
|
+
padding-top: 10px;
|
|
245
|
+
border-top: 1px dashed var(--ys-color-border);
|
|
246
|
+
}
|
|
247
|
+
</style>
|
|
@@ -13,6 +13,8 @@ import { ysMultiText } from "../multiValue";
|
|
|
13
13
|
import YsFormDialog from "./YsFormDialog.vue";
|
|
14
14
|
import YsRowActionMenu from "./YsRowActionMenu.vue";
|
|
15
15
|
import YsTableToolbar from "./YsTableToolbar.vue";
|
|
16
|
+
import YsCardList, { type YsCardField } from "./YsCardList.vue";
|
|
17
|
+
import { useYsMobile } from "../viewport";
|
|
16
18
|
|
|
17
19
|
interface FieldSpec {
|
|
18
20
|
key: string;
|
|
@@ -50,6 +52,8 @@ const dialogOpen = ref(false);
|
|
|
50
52
|
const editing = ref<Record<string, unknown> | null>(null);
|
|
51
53
|
const currentPage = ref(1);
|
|
52
54
|
const pageSize = ref(20);
|
|
55
|
+
/** 手机上换成卡片:第一列当标题,其余列两列排开,开关列显示「启用 / 停用」文字。 */
|
|
56
|
+
const mobile = useYsMobile();
|
|
53
57
|
|
|
54
58
|
function columnWidth(field: FieldSpec): number {
|
|
55
59
|
return lookupColumnWidth(props.table, field.key);
|
|
@@ -126,6 +130,15 @@ function display(row: Record<string, unknown>, f: FieldSpec): string {
|
|
|
126
130
|
return String(v ?? "");
|
|
127
131
|
}
|
|
128
132
|
|
|
133
|
+
const cardTitle = (row: Record<string, unknown>) => (displayColumns.value[0] ? display(row, displayColumns.value[0]) : "");
|
|
134
|
+
const cardFields = computed<YsCardField[]>(() =>
|
|
135
|
+
displayColumns.value.slice(1).map((c) => ({ key: c.key, label: c.title, value: (row: Record<string, unknown>) => display(row, c) })),
|
|
136
|
+
);
|
|
137
|
+
const crudActions = [
|
|
138
|
+
{ key: "edit", label: "编辑", tone: "primary" as const },
|
|
139
|
+
{ key: "delete", label: "删除", tone: "danger" as const, divided: true },
|
|
140
|
+
];
|
|
141
|
+
|
|
129
142
|
function onCreate() {
|
|
130
143
|
if (props.externalEditor) {
|
|
131
144
|
emit("create");
|
|
@@ -160,7 +173,18 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
160
173
|
>
|
|
161
174
|
</YsTableToolbar>
|
|
162
175
|
|
|
163
|
-
<
|
|
176
|
+
<YsCardList
|
|
177
|
+
v-if="mobile"
|
|
178
|
+
:rows="paged"
|
|
179
|
+
:fields="cardFields"
|
|
180
|
+
:title="cardTitle"
|
|
181
|
+
:loading="loading"
|
|
182
|
+
:actions="readonly ? undefined : () => crudActions"
|
|
183
|
+
@action="(key, row) => (key === 'edit' ? onEdit(row) : onRemove(row))"
|
|
184
|
+
>
|
|
185
|
+
<template v-if="$slots['row-actions']" #menu-extra="{ row, close }"><slot name="row-actions" :row="row" :close="close" /></template>
|
|
186
|
+
</YsCardList>
|
|
187
|
+
<el-table v-else :fit="false" :data="paged" v-loading="loading" stripe border size="small" table-layout="fixed" row-key="_id">
|
|
164
188
|
<el-table-column
|
|
165
189
|
v-for="c in displayColumns"
|
|
166
190
|
:key="c.key"
|
|
@@ -14,6 +14,7 @@ import YsViewerIcon from "./YsViewerIcon.vue";
|
|
|
14
14
|
import YsViewerState from "./YsViewerState.vue";
|
|
15
15
|
import YsFileNotes from "./YsFileNotes.vue";
|
|
16
16
|
import { isActiveContent } from "../fileRules";
|
|
17
|
+
import { YS_MOBILE_QUERY } from "../viewport";
|
|
17
18
|
import "../preview/viewer.css";
|
|
18
19
|
import {
|
|
19
20
|
OFFICE_MIME,
|
|
@@ -187,7 +188,7 @@ function onNarrowChange() {
|
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
onMounted(() => {
|
|
190
|
-
media = window.matchMedia?.(
|
|
191
|
+
media = window.matchMedia?.(YS_MOBILE_QUERY) ?? null;
|
|
191
192
|
onNarrowChange();
|
|
192
193
|
media?.addEventListener?.("change", onNarrowChange);
|
|
193
194
|
});
|
|
@@ -495,7 +496,7 @@ function openInTab() {
|
|
|
495
496
|
white-space: pre-wrap;
|
|
496
497
|
word-break: break-word;
|
|
497
498
|
}
|
|
498
|
-
@media (max-width:
|
|
499
|
+
@media (max-width: 767px) {
|
|
499
500
|
.ys-file-preview__head {
|
|
500
501
|
gap: 8px;
|
|
501
502
|
padding-left: 12px;
|
|
@@ -69,11 +69,17 @@ defineProps<{
|
|
|
69
69
|
.ys-page-header.is-compact h1 {
|
|
70
70
|
font-size: 20px;
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
/* 手机:标题 20px,标题和按钮上下排,按钮占满一行。 */
|
|
73
|
+
@media (max-width: 767px) {
|
|
73
74
|
.ys-page-header {
|
|
74
|
-
align-items:
|
|
75
|
+
align-items: stretch;
|
|
75
76
|
flex-direction: column;
|
|
76
|
-
gap:
|
|
77
|
+
gap: 10px;
|
|
78
|
+
margin-bottom: 12px;
|
|
79
|
+
}
|
|
80
|
+
.ys-page-header h1,
|
|
81
|
+
.ys-page-header.is-compact h1 {
|
|
82
|
+
font-size: 20px;
|
|
77
83
|
}
|
|
78
84
|
.ys-page-header__actions {
|
|
79
85
|
width: 100%;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
<!-- YsPageLayout —— 统一布局骨架:顶栏(logo/app名/工具条) + 侧栏 + 内容。
|
|
1
|
+
<!-- YsPageLayout —— 统一布局骨架:顶栏(logo/app名/工具条) + 侧栏 + 内容。
|
|
2
|
+
三档宽度(断点见 ../viewport.ts):
|
|
3
|
+
- 桌面(≥1024px):侧栏默认展开,左上角按钮收起或展开。
|
|
4
|
+
- 窄屏(768~1023px):侧栏默认收起,把宽度让给内容;按钮照样能展开。
|
|
5
|
+
- 手机(≤767px):侧栏变成从左边滑出的抽屉,左上角是菜单按钮;业务切换(switcher)放到抽屉顶部;
|
|
6
|
+
点抽屉里会跳走的菜单项、点遮罩、按 Esc 都会关上抽屉;顶栏和内容区避开刘海和底部横条(safe-area)。
|
|
7
|
+
不传 v-model:sidebar-collapsed 时,以上都由本组件管理;传了就以调用方为准(手机上的抽屉始终由本组件管理)。 -->
|
|
2
8
|
<script setup lang="ts">
|
|
3
|
-
import { computed, ref } from "vue";
|
|
9
|
+
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
|
10
|
+
import { useYsMobile, useYsNarrow } from "../viewport";
|
|
4
11
|
|
|
5
12
|
const props = withDefaults(
|
|
6
13
|
defineProps<{
|
|
@@ -24,40 +31,97 @@ const emit = defineEmits<{
|
|
|
24
31
|
navigate: [key: string];
|
|
25
32
|
"update:sidebarCollapsed": [value: boolean];
|
|
26
33
|
}>();
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
|
|
35
|
+
const mobile = useYsMobile();
|
|
36
|
+
const narrow = useYsNarrow();
|
|
37
|
+
/** 桌面、窄屏下侧栏是否收起:不受控时窄屏默认收起,宽度跨过 1024px 时重置。 */
|
|
38
|
+
const internalCollapsed = ref(narrow.value);
|
|
39
|
+
watch(narrow, (value) => {
|
|
40
|
+
internalCollapsed.value = value;
|
|
41
|
+
});
|
|
42
|
+
const collapsed = computed(() => props.sidebarCollapsed ?? internalCollapsed.value);
|
|
31
43
|
const hasSidebar = computed(() => !!slots.sidebar || !!props.menus?.length);
|
|
32
44
|
|
|
45
|
+
/** 手机抽屉:只在手机上有效,每次进入手机宽度都是关着的。 */
|
|
46
|
+
const drawerOpen = ref(false);
|
|
47
|
+
const drawer = ref<HTMLElement>();
|
|
48
|
+
const menuButton = ref<HTMLButtonElement>();
|
|
49
|
+
watch(mobile, () => {
|
|
50
|
+
drawerOpen.value = false;
|
|
51
|
+
});
|
|
52
|
+
|
|
33
53
|
function toggleSidebar() {
|
|
54
|
+
if (mobile.value) {
|
|
55
|
+
drawerOpen.value = !drawerOpen.value;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
34
58
|
internalCollapsed.value = !collapsed.value;
|
|
35
59
|
emit("update:sidebarCollapsed", internalCollapsed.value);
|
|
36
60
|
}
|
|
61
|
+
|
|
62
|
+
function closeDrawer(restoreFocus = true) {
|
|
63
|
+
if (!drawerOpen.value) return;
|
|
64
|
+
drawerOpen.value = false;
|
|
65
|
+
if (restoreFocus) void nextTick(() => menuButton.value?.focus());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 打开后把焦点放进抽屉(当前菜单项优先),读屏和键盘都从菜单开始。 */
|
|
69
|
+
watch(drawerOpen, async (open) => {
|
|
70
|
+
if (!open) return;
|
|
71
|
+
await nextTick();
|
|
72
|
+
const menu = drawer.value?.querySelector<HTMLElement>(".ys-layout__drawer-menu");
|
|
73
|
+
const target = menu?.querySelector<HTMLElement>("[aria-current='page']") ?? menu?.querySelector<HTMLElement>("button, a[href]");
|
|
74
|
+
target?.focus({ preventScroll: true });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 点了抽屉里会跳走的按钮或链接就关抽屉;只展开收起的按钮(带 aria-expanded)和标了 data-ys-keep-drawer 的不关。
|
|
79
|
+
* 路由跳转是异步的,等这一轮点击处理完再关,避免菜单先消失、跳转后又闪一下。
|
|
80
|
+
*/
|
|
81
|
+
function onDrawerClick(event: MouseEvent) {
|
|
82
|
+
const target = (event.target as HTMLElement | null)?.closest<HTMLElement>("button, a[href], [role='menuitem']");
|
|
83
|
+
if (!target || !drawer.value?.contains(target)) return;
|
|
84
|
+
if (target.hasAttribute("aria-expanded") || target.closest("[data-ys-keep-drawer]")) return;
|
|
85
|
+
if ((target as HTMLButtonElement).disabled) return;
|
|
86
|
+
setTimeout(() => closeDrawer(false), 0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function onKeydown(event: KeyboardEvent) {
|
|
90
|
+
if (event.key === "Escape" && drawerOpen.value) {
|
|
91
|
+
event.stopPropagation();
|
|
92
|
+
closeDrawer();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
window.addEventListener("keydown", onKeydown);
|
|
96
|
+
onBeforeUnmount(() => window.removeEventListener("keydown", onKeydown));
|
|
97
|
+
|
|
98
|
+
const toggleLabel = computed(() => {
|
|
99
|
+
if (mobile.value) return drawerOpen.value ? "关闭导航菜单" : "打开导航菜单";
|
|
100
|
+
return collapsed.value ? "展开导航栏" : "收起导航栏";
|
|
101
|
+
});
|
|
37
102
|
</script>
|
|
38
103
|
|
|
39
104
|
<template>
|
|
40
|
-
<div class="ys-layout" :class="{ 'is-collapsed': collapsed }">
|
|
105
|
+
<div class="ys-layout" :class="{ 'is-collapsed': collapsed && !mobile, 'is-mobile': mobile }">
|
|
41
106
|
<header class="ys-layout__top">
|
|
42
107
|
<!-- 品牌在前、收起按钮在品牌列最右,收起侧栏后顶栏布局不变。
|
|
43
|
-
顶栏右边有业务系统标签时,品牌列右侧补一条与侧栏同色的竖线把两块分开;没有标签时不画。
|
|
108
|
+
顶栏右边有业务系统标签时,品牌列右侧补一条与侧栏同色的竖线把两块分开;没有标签时不画。
|
|
109
|
+
手机上菜单按钮在最左,业务切换移到抽屉里。 -->
|
|
44
110
|
<div class="ys-layout__brand" :class="{ 'has-sidebar': hasSidebar }">
|
|
45
111
|
<img v-if="logoUrl" :src="logoUrl" class="ys-layout__logo" alt="logo" />
|
|
46
112
|
<span class="ys-layout__title">{{ appTitle }}</span>
|
|
47
|
-
<el-tooltip
|
|
48
|
-
v-if="hasSidebar"
|
|
49
|
-
:content="collapsed ? '展开导航栏' : '收起导航栏'"
|
|
50
|
-
placement="bottom"
|
|
51
|
-
>
|
|
113
|
+
<el-tooltip v-if="hasSidebar" :content="toggleLabel" placement="bottom" :disabled="mobile">
|
|
52
114
|
<span class="ys-layout__toggle-wrap">
|
|
53
115
|
<button
|
|
116
|
+
ref="menuButton"
|
|
54
117
|
type="button"
|
|
55
118
|
class="ys-layout__toggle"
|
|
56
|
-
:aria-label="
|
|
57
|
-
:aria-expanded="!collapsed"
|
|
119
|
+
:aria-label="toggleLabel"
|
|
120
|
+
:aria-expanded="mobile ? drawerOpen : !collapsed"
|
|
121
|
+
:aria-controls="mobile ? 'ys-layout-drawer' : undefined"
|
|
58
122
|
@click="toggleSidebar"
|
|
59
123
|
>
|
|
60
|
-
<!--
|
|
124
|
+
<!-- 手机上是「三条横线」菜单图标;桌面图标画的就是页面布局:展开时「上左右」,收起后「上下」。 -->
|
|
61
125
|
<svg
|
|
62
126
|
class="ys-layout__toggle-icon"
|
|
63
127
|
viewBox="0 0 24 24"
|
|
@@ -68,27 +132,23 @@ function toggleSidebar() {
|
|
|
68
132
|
stroke-linejoin="round"
|
|
69
133
|
aria-hidden="true"
|
|
70
134
|
>
|
|
71
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
135
|
+
<path v-if="mobile" d="M4 7h16M4 12h16M4 17h16" />
|
|
136
|
+
<template v-else>
|
|
137
|
+
<rect x="3.5" y="4.5" width="17" height="15" rx="2.5" />
|
|
138
|
+
<path :d="collapsed ? 'M3.5 9.5h17' : 'M3.5 9.5h17M9.5 9.5v10'" />
|
|
139
|
+
</template>
|
|
75
140
|
</svg>
|
|
76
141
|
</button>
|
|
77
142
|
</span>
|
|
78
143
|
</el-tooltip>
|
|
79
144
|
</div>
|
|
80
|
-
<div class="ys-layout__switcher"><slot name="switcher" /></div>
|
|
145
|
+
<div v-if="!mobile" class="ys-layout__switcher"><slot name="switcher" /></div>
|
|
81
146
|
<div v-if="$slots.toolbar" class="ys-layout__toolbar">
|
|
82
147
|
<slot name="toolbar" />
|
|
83
148
|
</div>
|
|
84
149
|
</header>
|
|
85
150
|
<div class="ys-layout__body">
|
|
86
|
-
<aside
|
|
87
|
-
v-if="hasSidebar"
|
|
88
|
-
v-show="!collapsed"
|
|
89
|
-
class="ys-layout__side"
|
|
90
|
-
aria-label="侧栏导航"
|
|
91
|
-
>
|
|
151
|
+
<aside v-if="hasSidebar && !mobile" v-show="!collapsed" class="ys-layout__side" aria-label="侧栏导航">
|
|
92
152
|
<slot name="sidebar">
|
|
93
153
|
<button
|
|
94
154
|
v-for="menu in menus"
|
|
@@ -107,6 +167,40 @@ function toggleSidebar() {
|
|
|
107
167
|
<slot />
|
|
108
168
|
</main>
|
|
109
169
|
</div>
|
|
170
|
+
<template v-if="hasSidebar && mobile">
|
|
171
|
+
<Transition name="ys-layout-fade">
|
|
172
|
+
<div v-if="drawerOpen" class="ys-layout__mask" aria-hidden="true" @click="closeDrawer()" />
|
|
173
|
+
</Transition>
|
|
174
|
+
<Transition name="ys-layout-slide">
|
|
175
|
+
<aside v-show="drawerOpen" id="ys-layout-drawer" ref="drawer" class="ys-layout__drawer" aria-label="导航菜单" @click="onDrawerClick">
|
|
176
|
+
<div class="ys-layout__drawer-head">
|
|
177
|
+
<img v-if="logoUrl" :src="logoUrl" class="ys-layout__logo" alt="" />
|
|
178
|
+
<span class="ys-layout__title">{{ appTitle }}</span>
|
|
179
|
+
<button type="button" class="ys-layout__toggle ys-layout__drawer-close" aria-label="关闭导航菜单" @click.stop="closeDrawer()">
|
|
180
|
+
<svg class="ys-layout__toggle-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true">
|
|
181
|
+
<path d="M6 6l12 12M18 6L6 18" />
|
|
182
|
+
</svg>
|
|
183
|
+
</button>
|
|
184
|
+
</div>
|
|
185
|
+
<div v-if="$slots.switcher" class="ys-layout__drawer-switcher"><slot name="switcher" /></div>
|
|
186
|
+
<div class="ys-layout__drawer-menu">
|
|
187
|
+
<slot name="sidebar">
|
|
188
|
+
<button
|
|
189
|
+
v-for="menu in menus"
|
|
190
|
+
:key="menu.key"
|
|
191
|
+
type="button"
|
|
192
|
+
class="ys-layout__menu"
|
|
193
|
+
:class="{ 'is-active': menu.key === active }"
|
|
194
|
+
:aria-current="menu.key === active ? 'page' : undefined"
|
|
195
|
+
@click="emit('navigate', menu.key)"
|
|
196
|
+
>
|
|
197
|
+
{{ menu.title }}
|
|
198
|
+
</button>
|
|
199
|
+
</slot>
|
|
200
|
+
</div>
|
|
201
|
+
</aside>
|
|
202
|
+
</Transition>
|
|
203
|
+
</template>
|
|
110
204
|
</div>
|
|
111
205
|
</template>
|
|
112
206
|
|
|
@@ -266,6 +360,122 @@ function toggleSidebar() {
|
|
|
266
360
|
overflow: auto;
|
|
267
361
|
background: var(--ys-color-bg);
|
|
268
362
|
}
|
|
363
|
+
|
|
364
|
+
/* ---------- 手机 ---------- */
|
|
365
|
+
.ys-layout.is-mobile {
|
|
366
|
+
--ys-layout-header-height: calc(52px + env(safe-area-inset-top, 0px));
|
|
367
|
+
}
|
|
368
|
+
.ys-layout.is-mobile .ys-layout__top {
|
|
369
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
370
|
+
padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px)) 0 max(4px, env(safe-area-inset-left, 0px));
|
|
371
|
+
}
|
|
372
|
+
.ys-layout.is-mobile .ys-layout__brand {
|
|
373
|
+
padding: 0;
|
|
374
|
+
gap: 6px;
|
|
375
|
+
}
|
|
376
|
+
/* 菜单按钮挪到最左,44px 见方,手指好点。 */
|
|
377
|
+
.ys-layout.is-mobile .ys-layout__toggle-wrap {
|
|
378
|
+
order: -1;
|
|
379
|
+
flex: 0 0 44px;
|
|
380
|
+
margin-left: 0;
|
|
381
|
+
}
|
|
382
|
+
.ys-layout.is-mobile .ys-layout__toggle {
|
|
383
|
+
flex: 0 0 44px;
|
|
384
|
+
width: 44px;
|
|
385
|
+
height: 44px;
|
|
386
|
+
}
|
|
387
|
+
.ys-layout.is-mobile .ys-layout__toggle-icon {
|
|
388
|
+
width: 22px;
|
|
389
|
+
height: 22px;
|
|
390
|
+
}
|
|
391
|
+
.ys-layout.is-mobile .ys-layout__logo {
|
|
392
|
+
width: 24px;
|
|
393
|
+
height: 24px;
|
|
394
|
+
}
|
|
395
|
+
.ys-layout.is-mobile .ys-layout__content {
|
|
396
|
+
padding: 12px max(12px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
|
|
397
|
+
/* 内容区滚到头不把整页带着回弹,也不触发浏览器的下拉刷新。 */
|
|
398
|
+
overscroll-behavior-y: contain;
|
|
399
|
+
}
|
|
400
|
+
.ys-layout__mask {
|
|
401
|
+
position: fixed;
|
|
402
|
+
inset: 0;
|
|
403
|
+
z-index: 1990;
|
|
404
|
+
background: var(--ys-color-backdrop);
|
|
405
|
+
}
|
|
406
|
+
.ys-layout__drawer {
|
|
407
|
+
position: fixed;
|
|
408
|
+
top: 0;
|
|
409
|
+
bottom: 0;
|
|
410
|
+
left: 0;
|
|
411
|
+
z-index: 1991;
|
|
412
|
+
display: flex;
|
|
413
|
+
flex-direction: column;
|
|
414
|
+
box-sizing: border-box;
|
|
415
|
+
width: min(84vw, 300px);
|
|
416
|
+
padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
|
|
417
|
+
background: var(--ys-color-bg-elevated);
|
|
418
|
+
box-shadow: var(--ys-shadow-dialog);
|
|
419
|
+
}
|
|
420
|
+
.ys-layout__drawer-head {
|
|
421
|
+
display: flex;
|
|
422
|
+
flex: none;
|
|
423
|
+
align-items: center;
|
|
424
|
+
gap: 8px;
|
|
425
|
+
height: 52px;
|
|
426
|
+
padding: 0 4px 0 16px;
|
|
427
|
+
border-bottom: 1px solid var(--ys-color-border);
|
|
428
|
+
}
|
|
429
|
+
.ys-layout__drawer-close {
|
|
430
|
+
flex: 0 0 44px;
|
|
431
|
+
width: 44px;
|
|
432
|
+
height: 44px;
|
|
433
|
+
margin-left: auto;
|
|
434
|
+
}
|
|
435
|
+
.ys-layout__drawer-switcher {
|
|
436
|
+
flex: none;
|
|
437
|
+
padding: 8px 12px;
|
|
438
|
+
border-bottom: 1px solid var(--ys-color-border);
|
|
439
|
+
overflow-x: auto;
|
|
440
|
+
}
|
|
441
|
+
.ys-layout__drawer-switcher:empty {
|
|
442
|
+
display: none;
|
|
443
|
+
}
|
|
444
|
+
.ys-layout__drawer-menu {
|
|
445
|
+
flex: 1;
|
|
446
|
+
min-height: 0;
|
|
447
|
+
padding: 8px;
|
|
448
|
+
overflow-y: auto;
|
|
449
|
+
overscroll-behavior: contain;
|
|
450
|
+
}
|
|
451
|
+
.ys-layout__drawer-menu .ys-layout__menu {
|
|
452
|
+
min-height: 44px;
|
|
453
|
+
font-size: 15px;
|
|
454
|
+
}
|
|
455
|
+
.ys-layout-fade-enter-active,
|
|
456
|
+
.ys-layout-fade-leave-active {
|
|
457
|
+
transition: opacity 0.2s ease;
|
|
458
|
+
}
|
|
459
|
+
.ys-layout-fade-enter-from,
|
|
460
|
+
.ys-layout-fade-leave-to {
|
|
461
|
+
opacity: 0;
|
|
462
|
+
}
|
|
463
|
+
.ys-layout-slide-enter-active,
|
|
464
|
+
.ys-layout-slide-leave-active {
|
|
465
|
+
transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
|
|
466
|
+
}
|
|
467
|
+
.ys-layout-slide-enter-from,
|
|
468
|
+
.ys-layout-slide-leave-to {
|
|
469
|
+
transform: translateX(-100%);
|
|
470
|
+
}
|
|
471
|
+
@media (prefers-reduced-motion: reduce) {
|
|
472
|
+
.ys-layout-fade-enter-active,
|
|
473
|
+
.ys-layout-fade-leave-active,
|
|
474
|
+
.ys-layout-slide-enter-active,
|
|
475
|
+
.ys-layout-slide-leave-active {
|
|
476
|
+
transition: none;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
269
479
|
</style>
|
|
270
480
|
|
|
271
481
|
<style>
|
|
@@ -281,6 +281,19 @@ function select(action: YsRowAction) {
|
|
|
281
281
|
margin: 3px 4px;
|
|
282
282
|
background: var(--ys-color-border);
|
|
283
283
|
}
|
|
284
|
+
/* 触屏:齿轮 40px 见方,菜单项 44px 高、14px 字,手指点得准。 */
|
|
285
|
+
@media (pointer: coarse) {
|
|
286
|
+
.ys-row-action__trigger {
|
|
287
|
+
width: 40px;
|
|
288
|
+
height: 40px;
|
|
289
|
+
}
|
|
290
|
+
.ys-row-action__item,
|
|
291
|
+
.ys-row-action__menu :deep(.ys-row-action-menu__item) {
|
|
292
|
+
min-height: 44px;
|
|
293
|
+
padding: 10px 12px;
|
|
294
|
+
font-size: 14px;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
284
297
|
:global(.ys-action-popover.el-popover.el-popper) {
|
|
285
298
|
padding: 7px;
|
|
286
299
|
border-color: color-mix(in srgb, var(--ys-color-primary) 18%, var(--ys-color-border));
|
|
@@ -287,7 +287,8 @@ defineExpose({
|
|
|
287
287
|
.ys-settings-dialog {
|
|
288
288
|
max-width: calc(100vw - 24px);
|
|
289
289
|
}
|
|
290
|
-
|
|
290
|
+
/* 手机:左侧页签改成顶部横排,内容占满宽度。 */
|
|
291
|
+
@media (max-width: 767px) {
|
|
291
292
|
.ys-settings-dialog .el-tabs--left {
|
|
292
293
|
display: flex;
|
|
293
294
|
flex-direction: column;
|
|
@@ -211,4 +211,17 @@ const emit = defineEmits<{ navigate: [key: string]; toggle: [key: string] }>();
|
|
|
211
211
|
.ys-side-menu__child.is-current .ys-side-menu__marker {
|
|
212
212
|
background: var(--ys-color-primary);
|
|
213
213
|
}
|
|
214
|
+
/* 手机(抽屉里):每行至少 44px、字号 15px,手指点得准;展开箭头也放大到 44px。 */
|
|
215
|
+
@media (max-width: 767px) {
|
|
216
|
+
.ys-side-menu__main,
|
|
217
|
+
.ys-side-menu__child {
|
|
218
|
+
min-height: 44px;
|
|
219
|
+
font-size: 15px;
|
|
220
|
+
}
|
|
221
|
+
.ys-side-menu__toggle {
|
|
222
|
+
width: 44px;
|
|
223
|
+
height: 44px;
|
|
224
|
+
margin-right: 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
214
227
|
</style>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useYsMobile } from "../viewport";
|
|
3
|
+
|
|
2
4
|
defineProps<{
|
|
3
5
|
total: number;
|
|
4
6
|
currentPage: number;
|
|
@@ -11,6 +13,8 @@ const emit = defineEmits<{
|
|
|
11
13
|
}>();
|
|
12
14
|
|
|
13
15
|
const PAGE_SIZES = [20, 50, 100];
|
|
16
|
+
/** 手机:不放每页条数,页码最多 5 个、按钮 32px,一行放得下「共 N 条 ‹ 1 2 3 4 5 ›」。 */
|
|
17
|
+
const mobile = useYsMobile();
|
|
14
18
|
|
|
15
19
|
function updatePageSize(value: number): void {
|
|
16
20
|
emit("update:pageSize", value);
|
|
@@ -25,8 +29,10 @@ function updatePageSize(value: number): void {
|
|
|
25
29
|
:page-size="pageSize"
|
|
26
30
|
:page-sizes="PAGE_SIZES"
|
|
27
31
|
:total="total"
|
|
28
|
-
layout="total, sizes, prev, pager, next"
|
|
32
|
+
:layout="mobile ? 'total, prev, pager, next' : 'total, sizes, prev, pager, next'"
|
|
33
|
+
:pager-count="mobile ? 5 : 7"
|
|
29
34
|
class="ys-table-pagination"
|
|
35
|
+
:class="{ 'is-mobile': mobile }"
|
|
30
36
|
@update:current-page="emit('update:currentPage', $event)"
|
|
31
37
|
@update:page-size="updatePageSize"
|
|
32
38
|
/>
|
|
@@ -37,4 +43,9 @@ function updatePageSize(value: number): void {
|
|
|
37
43
|
margin-top: 12px;
|
|
38
44
|
justify-content: flex-end;
|
|
39
45
|
}
|
|
46
|
+
.ys-table-pagination.is-mobile {
|
|
47
|
+
justify-content: center;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
row-gap: 8px;
|
|
50
|
+
}
|
|
40
51
|
</style>
|
|
@@ -21,7 +21,7 @@ const emit = defineEmits<{
|
|
|
21
21
|
<!-- 检索区从左到右固定为:搜索框 → 下拉框 → 复选框;主操作放 #actions 在最右。 -->
|
|
22
22
|
<slot />
|
|
23
23
|
<div class="ys-table-toolbar__spacer" />
|
|
24
|
-
<slot name="actions"
|
|
24
|
+
<div v-if="$slots.actions" class="ys-table-toolbar__actions"><slot name="actions" /></div>
|
|
25
25
|
</div>
|
|
26
26
|
</template>
|
|
27
27
|
|
|
@@ -43,4 +43,49 @@ const emit = defineEmits<{
|
|
|
43
43
|
.ys-table-toolbar__spacer {
|
|
44
44
|
flex: 1;
|
|
45
45
|
}
|
|
46
|
+
.ys-table-toolbar__actions {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
}
|
|
52
|
+
.ys-table-toolbar__actions :deep(.el-button + .el-button) {
|
|
53
|
+
margin-left: 0;
|
|
54
|
+
}
|
|
55
|
+
/*
|
|
56
|
+
* 手机:第一行是搜索框(占满剩余宽度)和主操作,下拉框两个一行、各占一半,勾选框排在最后自动换行。
|
|
57
|
+
* 业务页给下拉框写的固定宽度(如 width: 180px)在这里统一放开,不用每页再写一遍窄屏样式。
|
|
58
|
+
*/
|
|
59
|
+
@media (max-width: 767px) {
|
|
60
|
+
.ys-table-toolbar {
|
|
61
|
+
gap: 8px;
|
|
62
|
+
}
|
|
63
|
+
.ys-table-toolbar__search {
|
|
64
|
+
order: -2;
|
|
65
|
+
flex: 1 1 0;
|
|
66
|
+
width: auto;
|
|
67
|
+
min-width: 0;
|
|
68
|
+
}
|
|
69
|
+
.ys-table-toolbar__actions {
|
|
70
|
+
order: -1;
|
|
71
|
+
flex-wrap: nowrap;
|
|
72
|
+
}
|
|
73
|
+
.ys-table-toolbar__spacer {
|
|
74
|
+
display: none;
|
|
75
|
+
}
|
|
76
|
+
.ys-table-toolbar > :deep(.el-select),
|
|
77
|
+
.ys-table-toolbar > :deep(.ys-select),
|
|
78
|
+
.ys-table-toolbar > :deep(.el-tree-select),
|
|
79
|
+
.ys-table-toolbar > :deep(.el-date-editor),
|
|
80
|
+
.ys-table-toolbar > :deep(.el-input),
|
|
81
|
+
.ys-table-toolbar > :deep(.ys-segmented) {
|
|
82
|
+
flex: 1 1 calc(50% - 4px);
|
|
83
|
+
width: auto !important;
|
|
84
|
+
min-width: 0;
|
|
85
|
+
max-width: 100%;
|
|
86
|
+
}
|
|
87
|
+
.ys-table-toolbar :deep(.el-checkbox) {
|
|
88
|
+
height: 32px;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
46
91
|
</style>
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,18 @@ export type {
|
|
|
11
11
|
} from "./components/YsCalendar.vue";
|
|
12
12
|
export { default as YsCalendarDayCard } from "./components/YsCalendarDayCard.vue";
|
|
13
13
|
export { default as YsTablePagination } from "./components/YsTablePagination.vue";
|
|
14
|
+
export { default as YsCardList } from "./components/YsCardList.vue";
|
|
15
|
+
export type { YsCardField } from "./components/YsCardList.vue";
|
|
16
|
+
// 移动端断点:手机 ≤767px、窄屏 ≤1023px、触屏(不能悬停);CSS 和脚本用同一个断点。
|
|
17
|
+
export {
|
|
18
|
+
YS_MOBILE_QUERY,
|
|
19
|
+
YS_NARROW_QUERY,
|
|
20
|
+
YS_TOUCH_QUERY,
|
|
21
|
+
useYsMobile,
|
|
22
|
+
useYsNarrow,
|
|
23
|
+
useYsTouch,
|
|
24
|
+
ysIsMobile,
|
|
25
|
+
} from "./viewport";
|
|
14
26
|
export { default as YsRowActionMenu } from "./components/YsRowActionMenu.vue";
|
|
15
27
|
export type { YsRowAction } from "./components/YsRowActionMenu.vue";
|
|
16
28
|
export { default as YsFormDialog } from "./components/YsFormDialog.vue";
|
package/src/viewport.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 移动端断点:全平台只有一个,宽度不超过 767px 就是手机(竖屏手机、横屏小手机)。
|
|
3
|
+
* 768px 及以上(平板、桌面)仍是桌面布局;768~1023px 只把侧栏默认收起。
|
|
4
|
+
*
|
|
5
|
+
* - CSS 里写 `@media (max-width: 767px)`,脚本里用 useYsMobile(),两边是同一个断点,不另写 640、600、720 这类数字。
|
|
6
|
+
* - 「触屏」和「窄屏」是两回事:悬停才出现的内容看 YS_TOUCH_QUERY(没有悬停能力的设备),排版看 YS_MOBILE_QUERY。
|
|
7
|
+
* - 整个页面共用一个 matchMedia 监听,组件里随便调用,不会每次都新建监听。
|
|
8
|
+
*/
|
|
9
|
+
import { readonly, ref, type Ref } from "vue";
|
|
10
|
+
|
|
11
|
+
/** 手机:宽度不超过 767px。 */
|
|
12
|
+
export const YS_MOBILE_QUERY = "(max-width: 767px)";
|
|
13
|
+
/** 窄屏(手机和竖屏平板):宽度不超过 1023px,侧栏默认收起。 */
|
|
14
|
+
export const YS_NARROW_QUERY = "(max-width: 1023px)";
|
|
15
|
+
/** 触屏:主要指针不能悬停(手机、平板),悬停菜单改成点击打开。 */
|
|
16
|
+
export const YS_TOUCH_QUERY = "(hover: none)";
|
|
17
|
+
|
|
18
|
+
type Watched = { state: Ref<boolean>; list: MediaQueryList | null };
|
|
19
|
+
const cache = new Map<string, Watched>();
|
|
20
|
+
|
|
21
|
+
function watchQuery(query: string): Watched {
|
|
22
|
+
const found = cache.get(query);
|
|
23
|
+
if (found) return found;
|
|
24
|
+
const list = typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query) : null;
|
|
25
|
+
const state = ref(list?.matches ?? false);
|
|
26
|
+
list?.addEventListener?.("change", (event) => {
|
|
27
|
+
state.value = event.matches;
|
|
28
|
+
});
|
|
29
|
+
const watched = { state, list };
|
|
30
|
+
cache.set(query, watched);
|
|
31
|
+
return watched;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 当前是不是手机(宽度不超过 767px),随窗口宽度变化。 */
|
|
35
|
+
export function useYsMobile(): Readonly<Ref<boolean>> {
|
|
36
|
+
return readonly(watchQuery(YS_MOBILE_QUERY).state);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 当前是不是窄屏(宽度不超过 1023px),侧栏据此默认收起。 */
|
|
40
|
+
export function useYsNarrow(): Readonly<Ref<boolean>> {
|
|
41
|
+
return readonly(watchQuery(YS_NARROW_QUERY).state);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 当前主要指针能不能悬停;不能悬停(触屏)时悬停才出现的菜单要改成点击。 */
|
|
45
|
+
export function useYsTouch(): Readonly<Ref<boolean>> {
|
|
46
|
+
return readonly(watchQuery(YS_TOUCH_QUERY).state);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 不在组件里时直接读一次(如路由守卫)。 */
|
|
50
|
+
export function ysIsMobile(): boolean {
|
|
51
|
+
return watchQuery(YS_MOBILE_QUERY).state.value;
|
|
52
|
+
}
|