feat: 统一两端界面并扩展受权限约束的AI助手

This commit is contained in:
LoveChengke committed 2026-11-07 16:27:38 +08:00
1 parent 79a31ebe9d
commit 0b35a58f07
141 files changed
+7999 -2213

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
{
"name": "@classhelper/ui",
"version": "1.4.4",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts",
"./theme.css": "./src/theme.css",
"./tokens.css": "./src/tokens.css"
},
"peerDependencies": {
"vue": "^3.5.42",
"element-plus": "^2.14.5"
}
}
+102
View File
@@ -0,0 +1,102 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, useAttrs, watch } from 'vue';
import { ElDatePicker } from 'element-plus';
import { localDay, visibleCalendarRange, type CalendarRange, type DateMark } from './calendar';
defineOptions({ inheritAttrs: false });
const props = withDefaults(
defineProps<{
marks?: readonly DateMark[];
loadMarks?: (range: CalendarRange) => Promise<DateMark[]>;
scopeKey?: string;
}>(),
{ marks: () => [], loadMarks: undefined, scopeKey: '' },
);
const attrs = useAttrs();
const valueFormat = computed(() =>
typeof attrs['value-format'] === 'string'
? attrs['value-format']
: attrs.type === 'datetime' || attrs.type === 'datetimerange'
? 'YYYY-MM-DD HH:mm:ss'
: 'YYYY-MM-DD',
);
const remote = ref<DateMark[]>([]),
visible = ref(false),
loading = ref(false);
let revision = 0;
let range = visibleCalendarRange(undefined);
const counts = computed(
() => new Map([...remote.value, ...props.marks].map((item) => [item.date, item.count])),
);
function dateKey(value: unknown): string {
return value instanceof Date && Number.isFinite(value.getTime()) ? localDay(value) : '';
}
async function refresh(): Promise<void> {
const current = ++revision;
if (!props.loadMarks) return;
loading.value = true;
try {
const marks = await props.loadMarks(range);
if (current === revision) remote.value = marks;
} catch {
// 日历统计失败不阻断日期选择,离线回退由业务缓存负责。
if (current === revision) remote.value = [];
} finally {
if (current === revision) loading.value = false;
}
}
function onVisible(open: boolean): void {
visible.value = open;
if (open) {
range = visibleCalendarRange(attrs.modelValue ?? attrs['model-value']);
void refresh();
}
}
function onPanel(value: unknown): void {
range = visibleCalendarRange(value);
void refresh();
}
watch(
() => props.scopeKey,
() => {
++revision;
remote.value = [];
if (visible.value) void refresh();
},
);
onBeforeUnmount(() => {
++revision;
});
</script>
<template>
<ElDatePicker
v-bind="$attrs"
:value-format="valueFormat"
popper-class="ch-calendar"
@visible-change="onVisible"
@panel-change="onPanel"
>
<template #default="cell">
<div
class="el-date-table-cell ch-calendar-day"
:aria-label="`${cell.renderText ?? dateKey(cell.date)}${!cell.renderText && counts.get(dateKey(cell.date)) ? `,${counts.get(dateKey(cell.date))} 条记录` : ''}`"
:title="
!cell.renderText && counts.get(dateKey(cell.date))
? `${counts.get(dateKey(cell.date))} 条记录`
: undefined
"
>
<span class="el-date-table-cell__text">{{ cell.renderText ?? cell.text }}</span>
<i v-if="!cell.renderText && counts.get(dateKey(cell.date))" class="ch-calendar-dot" />
</div>
</template>
<template
v-for="name in Object.keys($slots).filter((name) => name !== 'default')"
:key="name"
#[name]="slotProps"
>
<slot :name="name" v-bind="slotProps ?? {}" />
</template>
</ElDatePicker>
<span v-if="loading" class="ch-sr-only" role="status">正在加载日期记录</span>
</template>
+128
View File
@@ -0,0 +1,128 @@
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
import { ElButton } from 'element-plus';
export interface GuideStep {
id: string;
title: string;
text: string;
example: string[];
}
const props = defineProps<{ modelValue: boolean; steps: GuideStep[]; brandLogo?: string }>();
const emit = defineEmits<{ 'update:modelValue': [value: boolean]; finish: [] }>();
const index = ref(0),
root = ref<HTMLElement>();
const current = computed(() => props.steps[Math.min(index.value, props.steps.length - 1)]);
let previousFocus: HTMLElement | null = null;
function retainFocus(): void {
if (props.modelValue && root.value && !root.value.contains(document.activeElement)) root.value.focus();
}
function finish(): void {
emit('update:modelValue', false);
emit('finish');
}
function next(): void {
if (index.value >= props.steps.length - 1) finish();
else index.value++;
}
function keydown(event: KeyboardEvent): void {
if (event.key === 'Escape') {
event.preventDefault();
finish();
}
if (event.key === 'ArrowRight') {
event.preventDefault();
next();
}
if (event.key === 'ArrowLeft') {
event.preventDefault();
index.value = Math.max(0, index.value - 1);
}
if (event.key === 'Tab') {
const buttons = [...(root.value?.querySelectorAll<HTMLElement>('button:not(:disabled)') ?? [])];
const target = event.shiftKey ? buttons.at(-1) : buttons[0];
if (
document.activeElement === (event.shiftKey ? buttons[0] : buttons.at(-1)) ||
document.activeElement === root.value
) {
event.preventDefault();
target?.focus();
}
}
event.stopPropagation();
}
watch(
() => props.modelValue,
async (open) => {
if (open) {
index.value = 0;
previousFocus = document.activeElement as HTMLElement;
await nextTick();
if (!props.modelValue || !root.value) return;
document.addEventListener('focusin', retainFocus, true);
window.addEventListener('focus', retainFocus);
root.value?.focus();
} else {
document.removeEventListener('focusin', retainFocus, true);
window.removeEventListener('focus', retainFocus);
previousFocus?.focus();
}
},
{ immediate: true },
);
onBeforeUnmount(() => {
document.removeEventListener('focusin', retainFocus, true);
window.removeEventListener('focus', retainFocus);
if (props.modelValue) previousFocus?.focus();
});
</script>
<template>
<Teleport to="body">
<section
v-if="modelValue && current"
ref="root"
class="ch-guide onboarding-welcome"
tabindex="-1"
role="dialog"
aria-modal="true"
aria-labelledby="ch-guide-title"
@keydown="keydown"
>
<header class="ch-guide-header">
<span class="ch-guide-brand">
<img v-if="brandLogo" :src="brandLogo" alt="" />
ClassHelper
</span>
<ElButton text data-action="skip" @click="finish">跳过</ElButton>
</header>
<main class="ch-guide-main">
<div class="ch-guide-copy" aria-live="polite">
<p class="ch-guide-progress">{{ index + 1 }} / {{ steps.length }}</p>
<h1 id="ch-guide-title">{{ current.title }}</h1>
<p>{{ current.text }}</p>
</div>
<div class="ch-guide-example" aria-label="功能示意">
<span class="ch-guide-example-label">功能示意</span>
<div v-for="(line, n) in current.example" :key="n" class="ch-guide-example-row">
<span class="ch-guide-example-dot" />
{{ line }}
</div>
</div>
</main>
<footer class="ch-guide-footer">
<div class="ch-guide-track">
<span v-for="(step, n) in steps" :key="step.id" :class="{ active: n === index }" />
</div>
<div>
<ElButton data-action="prev" :disabled="index === 0" @click="index--">上一步</ElButton>
<ElButton
type="primary"
:data-action="index === steps.length - 1 ? 'finish' : 'next'"
@click="next"
>
{{ index === steps.length - 1 ? '开始使用' : '下一步' }}
</ElButton>
</div>
</footer>
</section>
</Teleport>
</template>
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
defineProps<{ title: string; description?: string }>();
</script>
<template>
<div class="page-header">
<div>
<h1 class="page-title">{{ title }}</h1>
<p v-if="description" class="page-subtitle">{{ description }}</p>
</div>
<div v-if="$slots.default" class="page-actions"><slot /></div>
</div>
</template>
+40
View File
@@ -0,0 +1,40 @@
export interface DateMark {
date: string;
count: number;
}
export interface CalendarRange {
from: string;
to: string;
}
export const ONBOARDING_VERSION = 2;
export function localDay(date: Date): string {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
}
export function visibleCalendarRange(value: unknown): CalendarRange {
const values = Array.isArray(value) ? value : [value];
const dates = values
.map((item) => {
if (item instanceof Date) return item;
if (typeof item === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(item)) return new Date(`${item}T12:00:00`);
return typeof item === 'string' || typeof item === 'number' ? new Date(item) : new Date();
})
.filter((date) => Number.isFinite(date.getTime()))
.sort((a, b) => a.getTime() - b.getTime());
const first = dates[0] ?? new Date(),
last = dates.at(-1) ?? first;
return {
from: localDay(new Date(first.getFullYear(), first.getMonth(), -6)),
to: localDay(new Date(last.getFullYear(), last.getMonth() + 1, 14)),
};
}
export function countDates<T>(items: readonly T[], getDate: (item: T) => string): DateMark[] {
const counts = new Map<string, number>();
for (const item of items) {
const date = getDate(item);
counts.set(date, (counts.get(date) ?? 0) + 1);
}
return [...counts].map(([date, count]) => ({ date, count }));
}
+16
View File
@@ -0,0 +1,16 @@
import type { App } from 'vue';
import ChDatePicker from './ChDatePicker.vue';
export { default as FullScreenGuide } from './FullScreenGuide.vue';
export { default as PageHeader } from './PageHeader.vue';
export { ChDatePicker };
export * from './calendar';
export function registerSharedUi(app: App): void {
app.component('ChDatePicker', ChDatePicker);
}
declare module 'vue' {
export interface GlobalComponents {
ChDatePicker: typeof ChDatePicker;
}
}
+266
View File
@@ -0,0 +1,266 @@
@import './tokens.css';
:root:root {
--el-color-primary: var(--ch-ui-primary);
--el-color-primary-light-3: color-mix(in srgb, var(--ch-ui-primary) 70%, var(--ch-ui-surface));
--el-color-primary-light-5: color-mix(in srgb, var(--ch-ui-primary) 50%, var(--ch-ui-surface));
--el-color-primary-light-7: color-mix(in srgb, var(--ch-ui-primary) 30%, var(--ch-ui-surface));
--el-color-primary-light-8: color-mix(in srgb, var(--ch-ui-primary) 20%, var(--ch-ui-surface));
--el-color-primary-light-9: color-mix(in srgb, var(--ch-ui-primary) 10%, var(--ch-ui-surface));
--el-color-primary-dark-2: color-mix(in srgb, var(--ch-ui-primary) 80%, #000);
--el-border-radius-base: var(--ch-ui-radius);
--el-bg-color: var(--ch-ui-surface);
--el-bg-color-overlay: var(--ch-ui-surface);
--el-fill-color-blank: var(--ch-ui-surface);
--el-text-color-primary: var(--ch-ui-text);
--el-text-color-regular: var(--ch-ui-text);
--el-border-color: var(--ch-ui-border);
--ch-bg: var(--ch-ui-bg);
--ch-surface: var(--ch-ui-surface);
--ch-surface-alt: var(--ch-ui-surface-alt);
--ch-layer: var(--ch-ui-surface);
--ch-layer-solid: var(--ch-ui-surface);
--ch-layer-alt: var(--ch-ui-surface-alt);
--ch-border: var(--ch-ui-border);
--ch-text: var(--ch-ui-text);
--ch-text-muted: var(--ch-ui-muted);
--ch-text-secondary: var(--ch-ui-muted);
--ch-accent: var(--ch-ui-primary);
--ch-accent-hover: var(--el-color-primary-dark-2);
--ch-accent-soft: var(--el-color-primary-light-9);
--ch-accent-soft-strong: var(--el-color-primary-light-8);
--ch-sidebar: var(--ch-ui-surface);
--ch-radius-card: var(--ch-ui-radius);
--ch-radius-control: var(--ch-ui-radius);
}
body {
background: var(--ch-ui-bg);
color: var(--ch-ui-text);
}
html body :is(.page, .settings-page) {
padding: 24px;
min-width: 0;
box-sizing: border-box;
}
html body :is(.page-header, .toolbar, .filter-bar, .page-actions) {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
html body .page-header {
justify-content: space-between;
margin-bottom: 20px;
}
html body .page-title {
margin: 0;
font-size: calc(22px * var(--ch-font-scale, 1));
font-weight: 600;
color: var(--ch-ui-text);
}
html body .page-subtitle {
margin: 6px 0 0;
color: var(--ch-ui-muted);
line-height: 1.6;
}
html body :is(.toolbar, .filter-bar) {
margin-bottom: 16px;
}
html body :is(.toolbar, .filter-bar) > :is(.el-input, .el-select) {
width: 200px;
max-width: 100%;
}
html body :is(.el-card, .el-dialog, .el-message-box) {
border-radius: var(--ch-ui-radius) !important;
background: var(--ch-ui-surface) !important;
}
html body .el-card {
box-shadow: none !important;
border-color: var(--ch-ui-border) !important;
backdrop-filter: none;
}
html body .el-dialog {
max-width: calc(100vw - 32px);
}
html body :is(.el-dialog__footer, .el-message-box__btns) {
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
gap: 8px;
}
html body .el-form-item {
margin-bottom: 20px;
}
html body .el-table {
--el-table-header-bg-color: var(--ch-ui-surface-alt);
--el-table-border-color: var(--ch-ui-border);
}
.ch-calendar-day {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
width: 100%;
height: 100%;
line-height: 24px;
}
.ch-calendar-dot {
pointer-events: none;
position: absolute;
bottom: 0;
width: 4px;
height: 4px;
border-radius: 50%;
background: currentColor;
}
.ch-calendar {
max-width: calc(100vw - 24px);
max-height: calc(100dvh - 24px);
overflow-y: auto;
}
.ch-calendar .el-date-table {
font-size: calc(13px * var(--ch-font-scale, 1));
}
.ch-calendar .el-date-table td {
height: calc(38px * var(--ch-font-scale, 1));
}
.ch-calendar .el-date-table td .ch-calendar-day {
height: calc(34px * var(--ch-font-scale, 1));
}
.ch-calendar .el-date-table-cell__text {
width: calc(24px * var(--ch-font-scale, 1));
height: calc(24px * var(--ch-font-scale, 1));
line-height: calc(24px * var(--ch-font-scale, 1));
}
html.care-mode .ch-calendar .el-date-picker {
width: min(calc(322px * var(--ch-font-scale, 1)), calc(100vw - 32px));
}
.ch-calendar .el-date-picker .el-picker-panel__content {
width: auto;
}
@media (pointer: coarse) {
.ch-calendar .el-date-table td {
height: max(44px, calc(38px * var(--ch-font-scale, 1)));
}
}
.ch-sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
.ch-guide {
position: fixed;
inset: 0;
z-index: 10000;
display: flex;
flex-direction: column;
background: var(--ch-ui-bg);
color: var(--ch-ui-text);
padding: clamp(20px, 5vw, 64px);
box-sizing: border-box;
outline: none;
overflow: auto;
}
.ch-guide-header,
.ch-guide-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.ch-guide-brand {
display: flex;
align-items: center;
gap: 12px;
font-size: 20px;
font-weight: 650;
}
.ch-guide-brand img {
width: 32px;
height: 32px;
}
.ch-guide-main {
flex: 1;
display: grid;
grid-template-columns: 1fr 1fr;
align-items: center;
gap: clamp(24px, 6vw, 100px);
width: min(1120px, 100%);
margin: 32px auto;
}
.ch-guide-copy h1 {
font-size: clamp(28px, 4vw, 48px);
margin: 12px 0 20px;
letter-spacing: -1px;
}
.ch-guide-copy p {
font-size: calc(17px * var(--ch-font-scale, 1));
line-height: 1.8;
max-width: 36em;
}
.ch-guide-copy .ch-guide-progress {
color: var(--ch-ui-primary);
font-size: 14px;
}
.ch-guide-example {
padding: clamp(24px, 4vw, 48px);
border-radius: 16px;
border: 1px solid var(--ch-ui-border);
background: var(--ch-ui-surface);
box-shadow: var(--ch-ui-shadow);
}
.ch-guide-example-label {
font-weight: 600;
}
.ch-guide-example-row {
display: flex;
align-items: center;
gap: 12px;
padding: 18px 0;
border-bottom: 1px solid var(--ch-ui-border);
}
.ch-guide-example-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--ch-ui-primary);
flex-shrink: 0;
}
.ch-guide-track {
display: flex;
gap: 6px;
}
.ch-guide-track span {
width: 20px;
height: 4px;
border-radius: 2px;
background: var(--ch-ui-border);
}
.ch-guide-track .active {
background: var(--ch-ui-primary);
}
@media (max-width: 720px) {
.ch-calendar .el-date-range-picker {
width: calc(100vw - 32px);
}
.ch-calendar .el-date-range-picker__content {
width: 100%;
float: none;
}
.ch-calendar .el-date-range-picker__content.is-right {
border-left: 0;
border-top: 1px solid var(--ch-ui-border);
}
html body :is(.page, .settings-page) {
padding: 16px;
}
.ch-guide-main {
grid-template-columns: 1fr;
gap: 24px;
}
.ch-guide-footer {
flex-wrap: wrap;
}
}
+21
View File
@@ -0,0 +1,21 @@
:root {
--ch-ui-primary: #5d6bfa;
--ch-ui-bg: #f7f8fa;
--ch-ui-surface: #fff;
--ch-ui-surface-alt: #f3f5f9;
--ch-ui-border: #e6e9ef;
--ch-ui-text: #242936;
--ch-ui-muted: #737c8e;
--ch-ui-radius: 8px;
--ch-ui-gap: 16px;
--ch-ui-shadow: 0 8px 30px rgb(30 40 70 / 8%);
}
html.dark {
--ch-ui-bg: #14161a;
--ch-ui-surface: #1d2027;
--ch-ui-surface-alt: #252934;
--ch-ui-border: #343946;
--ch-ui-text: #e9edf5;
--ch-ui-muted: #a2abbd;
--ch-ui-shadow: 0 8px 30px rgb(0 0 0 / 25%);
}