mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-23 20:23:37 +08:00
feat(settings): redesign appearance and menu preferences
This commit is contained in:
parent
c3f96f1638
commit
089b0e44cc
@ -1,7 +1,7 @@
|
||||
import { createPinia, disposePinia, setActivePinia } from 'pinia'
|
||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
import { createApp, nextTick } from 'vue'
|
||||
import { APP_CATCH_KEY } from '../../apps/admin/src/app-config'
|
||||
import { APP_CATCH_KEY, APP_THEME } from '../../apps/admin/src/app-config'
|
||||
import {
|
||||
findMenuRoot,
|
||||
firstMenuLeaf,
|
||||
@ -71,6 +71,7 @@ describe('layout preferences', () => {
|
||||
localeLanguage: 'en-US',
|
||||
sideBarLogo: { icon: 'ray', title: 'Saved title' },
|
||||
menuTagSwitch: false,
|
||||
menuConfig: { iconSize: 16, collapsedIconSize: 16, menuWidth: 244 },
|
||||
primaryColorOverride: {
|
||||
common: { primaryColor: '#3468db', bodyColor: '#000000' },
|
||||
Card: { borderRadius: '99px' },
|
||||
@ -89,10 +90,17 @@ describe('layout preferences', () => {
|
||||
})
|
||||
expect(store.localeLanguage).toBe('en-US')
|
||||
expect(store.menuTagSwitch).toBe(false)
|
||||
expect(store.themeStyle).toBe('naive')
|
||||
expect(store.menuConfig).toMatchObject({
|
||||
iconSize: 20,
|
||||
collapsedIconSize: 22,
|
||||
menuWidth: 244,
|
||||
})
|
||||
expect(store.themeStyle).toBe('modern')
|
||||
expect(store.themeOverrides.common?.primaryColor).toBe('#3468db')
|
||||
expect(store.themeOverrides.common?.bodyColor).toBeUndefined()
|
||||
expect(store.themeOverrides.Card).toBeUndefined()
|
||||
expect(store.themeOverrides.common?.bodyColor).toBe(
|
||||
APP_THEME.appNaiveUIThemeOverrides.light.common?.bodyColor,
|
||||
)
|
||||
expect(store.themeOverrides.Card?.borderRadius).toBe('12px')
|
||||
store.updateSettingState('layoutConfig', { mode: 'top' })
|
||||
expect(store.layoutConfig.fixedHeader).toBe(true)
|
||||
expect(store.layoutConfig.mode).toBe('top')
|
||||
@ -103,6 +111,31 @@ describe('layout preferences', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ iconSize: 16, collapsedIconSize: 16 },
|
||||
{ iconSize: 24, collapsedIconSize: 18 },
|
||||
])('preserves menu icon sizes saved by the current app (%o)', (sizes) => {
|
||||
const initial = mountPersistedSettings()
|
||||
const store = piniaSettingStore()
|
||||
|
||||
store.updateSettingState('menuConfig', sizes)
|
||||
store.$persist()
|
||||
initial.app.unmount()
|
||||
disposePinia(initial.pinia)
|
||||
const restored = mountPersistedSettings()
|
||||
|
||||
try {
|
||||
expect(piniaSettingStore().menuConfig).toMatchObject(sizes)
|
||||
expect(
|
||||
piniaSettingStore().exportPreferences().preferences,
|
||||
).not.toHaveProperty('menuIconSizesUpdated')
|
||||
} finally {
|
||||
restored.app.unmount()
|
||||
disposePinia(restored.pinia)
|
||||
localStorage.removeItem(APP_CATCH_KEY.appPiniaSettingStore)
|
||||
}
|
||||
})
|
||||
|
||||
it('restores the exported preferences through the existing store and persistence', async () => {
|
||||
const { pinia, app } = mountPersistedSettings()
|
||||
const store = piniaSettingStore()
|
||||
@ -162,8 +195,8 @@ describe('layout preferences', () => {
|
||||
const { themeStyle: _style, ...legacy } = preferences
|
||||
|
||||
store.importPreferences(JSON.stringify({ ...file, preferences: legacy }))
|
||||
expect(store.themeStyle).toBe('naive')
|
||||
expect(store.themeOverrides.Card).toBeUndefined()
|
||||
expect(store.themeStyle).toBe('modern')
|
||||
expect(store.themeOverrides.Card?.borderRadius).toBe('12px')
|
||||
expect(store.themeOverrides.common?.primaryColor).toBe('#3468db')
|
||||
|
||||
store.changePrimaryColor()
|
||||
|
||||
@ -10,20 +10,22 @@ export default defineComponent({
|
||||
const { getAppThemeStr } = useSettingGetters()
|
||||
const { updateSettingState } = useSettingActions()
|
||||
const options = computed(() => [
|
||||
{
|
||||
label: t('theme.dark'),
|
||||
key: 'dark',
|
||||
icon: () => <RIcon name="system/dark" size="16" />,
|
||||
},
|
||||
{
|
||||
label: t('theme.light'),
|
||||
key: 'light',
|
||||
icon: () => <RIcon name="system/light" size="16" />,
|
||||
icon: () => <RIcon name="system/light" size="16" aria-hidden="true" />,
|
||||
},
|
||||
{
|
||||
label: t('theme.dark'),
|
||||
key: 'dark',
|
||||
icon: () => <RIcon name="system/dark" size="16" aria-hidden="true" />,
|
||||
},
|
||||
{
|
||||
label: t('theme.auto'),
|
||||
key: 'auto',
|
||||
icon: () => <RIcon name="system/system_os" size="16" />,
|
||||
icon: () => (
|
||||
<RIcon name="system/system_os" size="16" aria-hidden="true" />
|
||||
),
|
||||
},
|
||||
])
|
||||
const modelAppTheme = computed({
|
||||
|
||||
@ -166,3 +166,154 @@
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
}
|
||||
|
||||
.r-appearance-presets {
|
||||
min-inline-size: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
|
||||
legend {
|
||||
margin-block-end: 8px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&__grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.r-appearance-preset {
|
||||
position: relative;
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 6px;
|
||||
min-inline-size: 0;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--r-control-border);
|
||||
border-radius: var(--r-control-radius);
|
||||
background: var(--r-surface);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: var(--r-surface-hover);
|
||||
}
|
||||
|
||||
&:has(input:checked) {
|
||||
border-color: var(--r-primary-text);
|
||||
box-shadow: inset 0 0 0 1px var(--r-primary-text);
|
||||
}
|
||||
|
||||
&:has(input:focus-visible) {
|
||||
outline: 2px solid var(--r-primary-text);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
input {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
inset-block-start: 12px;
|
||||
inset-inline-end: 12px;
|
||||
inline-size: 14px;
|
||||
block-size: 14px;
|
||||
margin: 0;
|
||||
accent-color: var(--r-theme-primary-color);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&__preview {
|
||||
display: grid;
|
||||
align-items: end;
|
||||
min-block-size: 48px;
|
||||
padding: 7px;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: var(--preset-radius);
|
||||
background: var(--preset-background);
|
||||
|
||||
> span {
|
||||
display: grid;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 5px;
|
||||
inline-size: 68%;
|
||||
border: 1px solid var(--r-line);
|
||||
border-radius: var(--preset-radius);
|
||||
background: var(--preset-surface);
|
||||
}
|
||||
|
||||
> span::before,
|
||||
> span::after {
|
||||
content: '';
|
||||
block-size: 3px;
|
||||
border-radius: var(--preset-radius);
|
||||
background: var(--preset-accent);
|
||||
}
|
||||
|
||||
> span::after {
|
||||
inline-size: 55%;
|
||||
opacity: 0.45;
|
||||
}
|
||||
}
|
||||
|
||||
&__name {
|
||||
color: var(--r-text);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
&__note {
|
||||
color: var(--r-text-secondary);
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
.r-appearance-color,
|
||||
.r-appearance-color__controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
}
|
||||
|
||||
.r-appearance-color {
|
||||
justify-content: space-between;
|
||||
padding-block-start: 12px;
|
||||
border-block-start: 1px solid var(--r-line);
|
||||
}
|
||||
|
||||
.r-appearance-color__trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-block-size: 32px;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid var(--r-control-border);
|
||||
border-radius: var(--r-control-radius);
|
||||
background: var(--r-surface);
|
||||
color: var(--r-text);
|
||||
font-size: 12px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: var(--r-surface-hover);
|
||||
}
|
||||
|
||||
> span {
|
||||
inline-size: 14px;
|
||||
block-size: 14px;
|
||||
border: 1px solid var(--r-control-border);
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@container (min-width: 420px) {
|
||||
.r-appearance-presets__grid {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,10 +23,10 @@ import CustomMenu from './segment-views/CustomMenu'
|
||||
import Watermark from './segment-views/Watermark'
|
||||
|
||||
const categories = [
|
||||
{ key: 'layout', icon: 'navigation/dashboard', view: LayoutSettings },
|
||||
{ key: 'appearance', icon: 'system/light', view: Appearance },
|
||||
{ key: 'layout', icon: 'navigation/layout', view: LayoutSettings },
|
||||
{ key: 'appearance', icon: 'navigation/appearance', view: Appearance },
|
||||
{ key: 'menu', icon: 'navigation/menu', view: CustomMenu },
|
||||
{ key: 'watermark', icon: 'action/print', view: Watermark },
|
||||
{ key: 'watermark', icon: 'system/watermark', view: Watermark },
|
||||
{ key: 'general', icon: 'action/setting', view: Common },
|
||||
] as const
|
||||
|
||||
@ -36,8 +36,12 @@ export default defineComponent({
|
||||
setup(props) {
|
||||
const { t } = useI18n('preferences')
|
||||
const { create } = useModal()
|
||||
const { updateSettingState, exportPreferences, importPreferences } =
|
||||
useSettingActions()
|
||||
const {
|
||||
updateSettingState,
|
||||
changePrimaryColor,
|
||||
exportPreferences,
|
||||
importPreferences,
|
||||
} = useSettingActions()
|
||||
const { setupAppMenu } = useMenuActions()
|
||||
const fileInput = useTemplateRef<HTMLInputElement>('preferenceFile')
|
||||
const importing = ref(false)
|
||||
@ -105,6 +109,7 @@ export default defineComponent({
|
||||
forIn(cloneDeep(getDefaultSettingConfig()), (value, key) => {
|
||||
updateSettingState(key as keyof SettingState, value)
|
||||
})
|
||||
changePrimaryColor()
|
||||
void setupAppMenu()
|
||||
},
|
||||
})
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
import { APP_THEME, CONTENT_TRANSITION_OPTIONS } from '@/app-config'
|
||||
import { useI18n } from '@/hooks'
|
||||
import { useSettingActions, useSettingGetters } from '@/store'
|
||||
import { themeStyles } from '@ray-template/ui/theme-presets'
|
||||
import type { ThemeStyle } from '@ray-template/ui/theme-presets'
|
||||
import {
|
||||
DEFAULT_THEME_STYLE,
|
||||
themeStyleOverrides,
|
||||
themeStyles,
|
||||
} from '@ray-template/ui/theme-presets'
|
||||
import {
|
||||
darkTheme,
|
||||
lightTheme,
|
||||
NButton,
|
||||
NColorPicker,
|
||||
NForm,
|
||||
@ -15,6 +20,10 @@ import {
|
||||
import SettingsSection from '../components/SettingsSection'
|
||||
import ThemeSegment from '../components/ThemeSegment'
|
||||
|
||||
type ColorTriggerProps = Parameters<
|
||||
NonNullable<InstanceType<typeof NColorPicker>['$slots']['trigger']>
|
||||
>[0]
|
||||
|
||||
export default defineComponent({
|
||||
name: 'SegmentViewsAppearance',
|
||||
setup() {
|
||||
@ -22,6 +31,7 @@ export default defineComponent({
|
||||
const { changePrimaryColor, updateSettingState, toggleColorWeakness } =
|
||||
useSettingActions()
|
||||
const {
|
||||
getAppTheme,
|
||||
getThemeStyle,
|
||||
getCustomPrimaryColor,
|
||||
getDrawerPlacement,
|
||||
@ -32,12 +42,29 @@ export default defineComponent({
|
||||
getColorWeakness,
|
||||
} = useSettingGetters()
|
||||
const themeVars = useThemeVars()
|
||||
const styleOptions = computed(() =>
|
||||
themeStyles.map((value) => ({
|
||||
value,
|
||||
label: t(`themeStyle.${value}`),
|
||||
})),
|
||||
)
|
||||
const styleName = useId()
|
||||
const colorOpen = ref(false)
|
||||
const previews = computed(() => {
|
||||
const mode = getAppTheme.value ? 'dark' : 'light'
|
||||
const base = mode === 'dark' ? darkTheme : lightTheme
|
||||
|
||||
return themeStyles.map((value) => {
|
||||
const { primaryColor, bodyColor, cardColor, borderRadius } = {
|
||||
...base.common,
|
||||
...themeStyleOverrides[value][mode].common,
|
||||
}
|
||||
|
||||
return {
|
||||
value,
|
||||
style: {
|
||||
'--preset-accent': primaryColor,
|
||||
'--preset-background': bodyColor,
|
||||
'--preset-surface': cardColor,
|
||||
'--preset-radius': borderRadius,
|
||||
},
|
||||
}
|
||||
})
|
||||
})
|
||||
const switches = [
|
||||
['breadcrumbSwitch', getBreadcrumbSwitch],
|
||||
['menuTagSwitch', getMenuTagSwitch],
|
||||
@ -49,38 +76,93 @@ export default defineComponent({
|
||||
<div class="r-settings-stack">
|
||||
<SettingsSection title={t('appearance.theme')}>
|
||||
<ThemeSegment />
|
||||
<NForm
|
||||
labelPlacement="top"
|
||||
showFeedback={false}
|
||||
class="r-settings-fields"
|
||||
>
|
||||
<NFormItem label={t('appearance.themeStyle')}>
|
||||
<NSelect
|
||||
aria-label={t('appearance.themeStyle')}
|
||||
value={getThemeStyle.value}
|
||||
options={styleOptions.value}
|
||||
onUpdateValue={(value: ThemeStyle) =>
|
||||
updateSettingState('themeStyle', value)
|
||||
}
|
||||
/>
|
||||
</NFormItem>
|
||||
<NFormItem label={t('appearance.primaryColor')}>
|
||||
<fieldset class="r-appearance-presets">
|
||||
<legend>{t('appearance.themeStyle')}</legend>
|
||||
<div class="r-appearance-presets__grid">
|
||||
{previews.value.map(({ value, style }) => (
|
||||
<label class="r-appearance-preset" key={value}>
|
||||
<input
|
||||
type="radio"
|
||||
name={styleName}
|
||||
value={value}
|
||||
checked={getThemeStyle.value === value}
|
||||
onChange={() => updateSettingState('themeStyle', value)}
|
||||
/>
|
||||
<span
|
||||
class="r-appearance-preset__preview"
|
||||
style={style}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<span />
|
||||
</span>
|
||||
<span class="r-appearance-preset__name">
|
||||
{t(`themeStyle.${value}`)}
|
||||
</span>
|
||||
{value === DEFAULT_THEME_STYLE && (
|
||||
<span class="r-appearance-preset__note">
|
||||
{t('appearance.defaultStyle')}
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="r-appearance-color">
|
||||
<span>{t('appearance.primaryColor')}</span>
|
||||
<div class="r-appearance-color__controls">
|
||||
<NColorPicker
|
||||
showPreview
|
||||
show={colorOpen.value}
|
||||
onUpdateShow={(show) => (colorOpen.value = show)}
|
||||
swatches={APP_THEME.appThemeColors}
|
||||
value={themeVars.value.primaryColor}
|
||||
onUpdateValue={(value) => {
|
||||
if (value) changePrimaryColor(value)
|
||||
}}
|
||||
/>
|
||||
</NFormItem>
|
||||
{getCustomPrimaryColor.value && (
|
||||
<NButton text type="primary" onClick={() => changePrimaryColor()}>
|
||||
>
|
||||
{{
|
||||
trigger: ({
|
||||
value,
|
||||
onClick,
|
||||
ref: triggerRef,
|
||||
}: ColorTriggerProps) => (
|
||||
<button
|
||||
type="button"
|
||||
ref={triggerRef}
|
||||
class="r-appearance-color__trigger"
|
||||
aria-label={`${t('appearance.primaryColor')}: ${value}`}
|
||||
aria-expanded={colorOpen.value}
|
||||
onClick={onClick}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
style={{ background: value ?? void 0 }}
|
||||
/>
|
||||
{value}
|
||||
</button>
|
||||
),
|
||||
}}
|
||||
</NColorPicker>
|
||||
<NButton
|
||||
size="small"
|
||||
quaternary
|
||||
disabled={!getCustomPrimaryColor.value}
|
||||
onClick={() => changePrimaryColor()}
|
||||
>
|
||||
{t('appearance.resetColor')}
|
||||
</NButton>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</SettingsSection>
|
||||
<SettingsSection title={t('appearance.workspace')}>
|
||||
<NForm
|
||||
labelPlacement="top"
|
||||
showFeedback={false}
|
||||
class="r-settings-fields"
|
||||
>
|
||||
<NFormItem label={t('appearance.transition')}>
|
||||
<NSelect
|
||||
aria-label={t('appearance.transition')}
|
||||
value={getContentTransition.value}
|
||||
options={CONTENT_TRANSITION_OPTIONS.map(({ value }) => ({
|
||||
value,
|
||||
@ -93,6 +175,7 @@ export default defineComponent({
|
||||
</NFormItem>
|
||||
<NFormItem label={t('appearance.placement')}>
|
||||
<NSelect
|
||||
aria-label={t('appearance.placement')}
|
||||
value={getDrawerPlacement.value}
|
||||
options={['right', 'left'].map((value) => ({
|
||||
value,
|
||||
|
||||
@ -20,6 +20,7 @@ export default defineComponent({
|
||||
getLayoutConfig.value.mode === 'split'
|
||||
}
|
||||
label={t('layout.navigation')}
|
||||
iconSize={getMenuConfig.value.iconSize}
|
||||
select={(option) => changeMenuModelValue(option.fullPath, option)}
|
||||
>
|
||||
{{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"title": "Preferences",
|
||||
"subtitle": "Changes apply immediately and are saved in this browser",
|
||||
"reset": "Restore defaults",
|
||||
"resetDescription": "Restore the default layout, menu and general options.",
|
||||
"resetDescription": "Restore the default interface style, accent color, layout, menu and general options.",
|
||||
"cancel": "Cancel",
|
||||
"config": {
|
||||
"export": "Export settings",
|
||||
@ -33,7 +33,9 @@
|
||||
"appearance": {
|
||||
"themeStyle": "Interface style",
|
||||
"resetColor": "Use preset color",
|
||||
"theme": "Theme and motion",
|
||||
"theme": "Theme",
|
||||
"workspace": "Window and motion",
|
||||
"defaultStyle": "Default",
|
||||
"primaryColor": "Accent color",
|
||||
"transition": "Page transition",
|
||||
"placement": "Drawer position",
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
"title": "偏好设置",
|
||||
"subtitle": "更改即时生效并保存在此浏览器",
|
||||
"reset": "恢复默认设置",
|
||||
"resetDescription": "将布局、菜单和通用选项恢复为默认值。",
|
||||
"resetDescription": "将界面风格、主题色、布局、菜单和通用选项恢复为默认值。",
|
||||
"cancel": "取消",
|
||||
"config": {
|
||||
"export": "导出配置",
|
||||
@ -33,7 +33,9 @@
|
||||
"appearance": {
|
||||
"themeStyle": "界面风格",
|
||||
"resetColor": "使用风格默认色",
|
||||
"theme": "主题与动效",
|
||||
"theme": "主题",
|
||||
"workspace": "窗口与动效",
|
||||
"defaultStyle": "默认",
|
||||
"primaryColor": "主题色",
|
||||
"transition": "页面切换动画",
|
||||
"placement": "设置抽屉位置",
|
||||
|
||||
@ -7,7 +7,6 @@ import { getStorage } from '@/utils/cache'
|
||||
import { isValueType } from '@/utils/core'
|
||||
import { NTag } from 'naive-ui'
|
||||
import type { TagProps } from 'naive-ui'
|
||||
import { piniaMenuStore } from '.'
|
||||
import { piniaSettingStore } from '../setting'
|
||||
|
||||
/**
|
||||
@ -150,8 +149,6 @@ export const createMenuIcon = (option: AppMenuOption) => {
|
||||
return () => icon
|
||||
}
|
||||
|
||||
const settings = piniaSettingStore()
|
||||
const menu = piniaMenuStore()
|
||||
const name = resolveIconName(icon)
|
||||
|
||||
if (!name) return
|
||||
@ -159,10 +156,7 @@ export const createMenuIcon = (option: AppMenuOption) => {
|
||||
return () =>
|
||||
h(RIcon, {
|
||||
name,
|
||||
size: menu.collapsed
|
||||
? settings.menuConfig.collapsedIconSize
|
||||
: settings.menuConfig.iconSize,
|
||||
cursor: 'pointer',
|
||||
size: '1em',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { LAYOUT_MODES } from '@ray-template/admin-shell'
|
||||
import { DEFAULT_THEME_STYLE } from '@ray-template/ui/theme-presets'
|
||||
import type { LayoutConfig, SettingState } from './types'
|
||||
|
||||
type OmitKeys =
|
||||
@ -22,7 +23,7 @@ export { LAYOUT_MODES }
|
||||
|
||||
// SettingDrawer 默认配置系统配置项
|
||||
const defaultSettingConfig: Readonly<Config> = {
|
||||
themeStyle: 'naive',
|
||||
themeStyle: DEFAULT_THEME_STYLE,
|
||||
layoutConfig: {
|
||||
mode: 'side',
|
||||
contentWidth: 'fluid',
|
||||
@ -45,11 +46,11 @@ const defaultSettingConfig: Readonly<Config> = {
|
||||
menuConfig: {
|
||||
collapsedWidth: 64,
|
||||
collapsedMode: 'width',
|
||||
collapsedIconSize: 16,
|
||||
collapsedIconSize: 22,
|
||||
collapsedIndent: 24,
|
||||
accordion: false,
|
||||
menuSiderBarLogo: true,
|
||||
iconSize: 16,
|
||||
iconSize: 20,
|
||||
menuWidth: 272,
|
||||
inverted: false,
|
||||
nativeScrollbar: false,
|
||||
|
||||
@ -207,6 +207,32 @@ export const piniaSettingStore = defineStore(
|
||||
key: APP_CATCH_KEY.appPiniaSettingStore,
|
||||
omit: ['lockScreenSwitch'],
|
||||
storage: window.localStorage,
|
||||
serializer: {
|
||||
serialize: (state) =>
|
||||
JSON.stringify({ ...state, menuIconSizesUpdated: true }),
|
||||
deserialize: (json) => {
|
||||
const { menuIconSizesUpdated, ...state } = JSON.parse(
|
||||
json,
|
||||
) as Partial<SettingState> & {
|
||||
menuIconSizesUpdated?: boolean
|
||||
}
|
||||
const { menuConfig } = state
|
||||
|
||||
// 旧缓存写入了整组默认值。仅升级旧的尺寸组合,保留此后保存的自定义值。
|
||||
if (
|
||||
!menuIconSizesUpdated &&
|
||||
menuConfig?.iconSize === 16 &&
|
||||
menuConfig.collapsedIconSize === 16
|
||||
) {
|
||||
const defaults = getDefaultSettingConfig().menuConfig
|
||||
|
||||
menuConfig.iconSize = defaults.iconSize
|
||||
menuConfig.collapsedIconSize = defaults.collapsedIconSize
|
||||
}
|
||||
|
||||
return state
|
||||
},
|
||||
},
|
||||
afterHydrate: ({ store }) => {
|
||||
store.layoutConfig = normalizeLayoutConfig(store.layoutConfig)
|
||||
store.themeStyle = normalizeThemeStyle(store.themeStyle)
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { CONTENT_TRANSITION_OPTIONS } from '@/app-config'
|
||||
import { themeStyles } from '@ray-template/ui/theme-presets'
|
||||
import {
|
||||
DEFAULT_THEME_STYLE,
|
||||
themeStyles,
|
||||
} from '@ray-template/ui/theme-presets'
|
||||
import { pick } from 'lodash-es'
|
||||
import * as v from 'valibot'
|
||||
import { LAYOUT_MODES } from './constant'
|
||||
@ -38,7 +41,7 @@ const preferences = v.strictObject({
|
||||
fixedFooter: flag,
|
||||
}),
|
||||
appTheme: v.picklist(['light', 'dark', 'auto']),
|
||||
themeStyle: v.optional(v.picklist(themeStyles), 'naive'),
|
||||
themeStyle: v.optional(v.picklist(themeStyles), DEFAULT_THEME_STYLE),
|
||||
primaryColor: v.optional(
|
||||
v.pipe(
|
||||
v.string(),
|
||||
|
||||
@ -74,7 +74,7 @@ export interface SettingState {
|
||||
* collapsedMode:
|
||||
* - transform: 边栏将只会移动它的位置而不会改变宽度
|
||||
* - width: Sider 的内容宽度将会被实际改变
|
||||
* collapsedIconSize 配置菜单未折叠时图标的大小
|
||||
* iconSize 配置展开和顶部菜单的图标尺寸;collapsedIconSize 配置折叠侧栏的图标尺寸
|
||||
* collapsedIndent 配置菜单每级的缩进
|
||||
* accordion 手风琴模式
|
||||
*/
|
||||
|
||||
@ -4,14 +4,14 @@
|
||||
|
||||
在「偏好设置 → 外观 → 界面风格」切换。风格与浅色、深色、跟随系统独立;切换即时生效,刷新和偏好导入导出会保留选择。
|
||||
|
||||
| 风格 | 外观 |
|
||||
| ------------- | -------------------------------------- |
|
||||
| Naive UI 默认 | 使用组件库原生 token,初次使用选中此项 |
|
||||
| 现代化 | Ray 蓝、低饱和底色、适度圆角和留白 |
|
||||
| Material | 紫色调、较大的圆角、胶囊按钮和分层表面 |
|
||||
| 朴素 | 中性灰、小圆角和无阴影表面 |
|
||||
| 风格 | 外观 |
|
||||
| ------------- | -------------------------------------------- |
|
||||
| Naive UI 默认 | 使用组件库原生 token |
|
||||
| 现代化 | 默认风格:Ray 蓝、低饱和底色、适度圆角和留白 |
|
||||
| Material | 紫色调、较大的圆角、胶囊按钮和分层表面 |
|
||||
| 朴素 | 中性灰、小圆角和无阴影表面 |
|
||||
|
||||
手动选择的主题色优先于预设,并随风格保留;点击「使用风格默认色」可恢复当前风格的配色。历史设置会补齐默认风格并保留曾手动选择的主色。
|
||||
手动选择的主题色优先于预设,并随风格保留;点击「使用风格默认色」可恢复当前风格的配色。新用户、恢复默认设置,以及缺少风格的历史配置都使用现代化。已有的显式风格选择会在刷新和导入时保留。
|
||||
|
||||
### 样式放在哪里
|
||||
|
||||
|
||||
@ -33,6 +33,10 @@ updateSettingState('layoutConfig', {
|
||||
|
||||
最大宽度范围是 640–2560px,间距为 0–48px。顶栏和页脚可固定或随内容滚动。旧设置补齐默认值,布局恢复默认只重置 `layoutConfig`。
|
||||
|
||||
## 菜单图标
|
||||
|
||||
展开侧栏、移动端抽屉和顶部导航默认使用 20 px 的图标;折叠侧栏默认 22 px,方便只凭图形辨认菜单。线性图标跟随菜单状态和明暗主题变色。可在「偏好设置 → 菜单」调整「图标尺寸」与「折叠图标尺寸」,修改即时生效。
|
||||
|
||||
## 替换布局区域
|
||||
|
||||
`RLayout` 提供 `header`、`sidebar`、`tabs`、`footer` 和 `default` 插槽。模式和显隐开关仍生效,例如顶部导航模式不会渲染侧栏。替换 `default` 内容时,需要自行接入所需的路由缓存和请求取消。
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
| `getLayoutConfig` | `layoutConfig`,布局模式和工作区尺寸,见下表。 |
|
||||
| `getDrawerPlacement` | `drawerPlacement`,设置抽屉方向,默认 `right`。 |
|
||||
| `getPrimaryColorOverride` | Naive UI 生效的 token 覆盖,由当前风格、明暗和用户主色计算。 |
|
||||
| `getThemeStyle` / `getCustomPrimaryColor` | 界面风格与手动主色。默认 `naive`,未指定手动主色时使用风格原色。 |
|
||||
| `getThemeStyle` / `getCustomPrimaryColor` | 界面风格与手动主色。默认 `modern`,未指定手动主色时使用风格原色。 |
|
||||
| `getAppTheme` / `getAppThemeStr` | `_appTheme` 为实际深色布尔值,`appTheme` 为 `light/dark/auto` 模式,初始 `light`。 |
|
||||
| `getLocaleLanguage` | `localeLanguage`,应用语言,默认读取历史值或系统默认配置。 |
|
||||
| `getMenuTagSwitch` / `getBreadcrumbSwitch` | `menuTagSwitch` / `breadcrumbSwitch`,默认显示标签和面包屑。 |
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
`layoutConfig` 的 `mode` 为 `side`(默认)、`top`、`mixed`。`contentWidth` 默认 `fluid`,也可取 `fixed`。`contentMaxWidth` 默认 1200,限制在 640–2560;`contentPadding` 默认 16,限制在 0–48;`fixedHeader`、`fixedFooter` 默认开启。旧缓存水合时补齐字段并规范化范围。
|
||||
|
||||
`menuConfig` 默认菜单宽 272、折叠宽 64、普通和折叠图标均为 16、缩进 24。`collapsedMode` 默认 `width`,`transform` 模式改变位置;`accordion`、`inverted`、`nativeScrollbar` 默认关,`menuSiderBarLogo` 默认开。`sideBarLogo.jumpType` 用 `station` 站内跳转或 `outsideStation` 打开外部地址,未传 `url` 时不跳转。缓存中的旧裸图标名会尝试映射成完整名称;需要持久化的 Logo 建议用图标名字符串,VNode 不适合作为缓存值。
|
||||
`menuConfig` 默认菜单宽 272、折叠宽 64、展开与顶部菜单图标 20 px、折叠侧栏图标 22 px、缩进 24。`collapsedMode` 默认 `width`,`transform` 模式改变位置;`accordion`、`inverted`、`nativeScrollbar` 默认关,`menuSiderBarLogo` 默认开。`sideBarLogo.jumpType` 用 `station` 站内跳转或 `outsideStation` 打开外部地址,未传 `url` 时不跳转。旧浏览器缓存中同时为 16 px 的尺寸组合会升级为新默认值;当前应用保存的尺寸和偏好文件中的尺寸会原样保留。缓存中的旧裸图标名会尝试映射成完整名称;需要持久化的 Logo 建议用图标名字符串,VNode 不适合作为缓存值。
|
||||
|
||||
## Actions
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ export const ShellTopNavigation = defineComponent({
|
||||
active: { type: [String, Number] as PropType<AppMenuKey>, default: null },
|
||||
label: { type: String, required: true },
|
||||
grouped: Boolean,
|
||||
iconSize: { type: Number, default: 20 },
|
||||
select: {
|
||||
type: Function as PropType<(option: AppMenuOption) => void>,
|
||||
required: true,
|
||||
@ -47,6 +48,8 @@ export const ShellTopNavigation = defineComponent({
|
||||
<NMenu
|
||||
mode="horizontal"
|
||||
responsive
|
||||
iconSize={props.iconSize}
|
||||
collapsedIconSize={props.iconSize}
|
||||
keyField="fullPath"
|
||||
value={selected.value}
|
||||
options={options.value as unknown as MenuOption[]}
|
||||
|
||||
@ -96,11 +96,13 @@ const plainComponents = {
|
||||
Tag: { borderRadius: '2px' },
|
||||
} satisfies GlobalThemeOverrides
|
||||
|
||||
export const themeStyles = ['naive', 'modern', 'material', 'plain'] as const
|
||||
export const themeStyles = ['modern', 'naive', 'material', 'plain'] as const
|
||||
export type ThemeStyle = (typeof themeStyles)[number]
|
||||
|
||||
export const DEFAULT_THEME_STYLE: ThemeStyle = 'modern'
|
||||
|
||||
export const normalizeThemeStyle = (value: unknown): ThemeStyle =>
|
||||
themeStyles.find((style) => style === value) ?? 'naive'
|
||||
themeStyles.find((style) => style === value) ?? DEFAULT_THEME_STYLE
|
||||
|
||||
export const themeStyleOverrides: Record<ThemeStyle, ThemePalette> = {
|
||||
naive: { light: {}, dark: {} },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user