mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-26 23:23:22 +08:00
merge
This commit is contained in:
10
.github/workflows/deploy.yml
vendored
10
.github/workflows/deploy.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
|||||||
run: pnpm build:play
|
run: pnpm build:play
|
||||||
|
|
||||||
- name: Sync Playground files
|
- name: Sync Playground files
|
||||||
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
|
uses: SamKirkland/FTP-Deploy-Action@v4.3.6
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.PRO_FTP_HOST }}
|
server: ${{ secrets.PRO_FTP_HOST }}
|
||||||
username: ${{ secrets.WEB_PLAYGROUND_FTP_ACCOUNT }}
|
username: ${{ secrets.WEB_PLAYGROUND_FTP_ACCOUNT }}
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
run: pnpm build:docs
|
run: pnpm build:docs
|
||||||
|
|
||||||
- name: Sync Docs files
|
- name: Sync Docs files
|
||||||
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
|
uses: SamKirkland/FTP-Deploy-Action@v4.3.6
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.PRO_FTP_HOST }}
|
server: ${{ secrets.PRO_FTP_HOST }}
|
||||||
username: ${{ secrets.WEBSITE_FTP_ACCOUNT }}
|
username: ${{ secrets.WEBSITE_FTP_ACCOUNT }}
|
||||||
@@ -85,7 +85,7 @@ jobs:
|
|||||||
run: pnpm run build:antd
|
run: pnpm run build:antd
|
||||||
|
|
||||||
- name: Sync files
|
- name: Sync files
|
||||||
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
|
uses: SamKirkland/FTP-Deploy-Action@v4.3.6
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.PRO_FTP_HOST }}
|
server: ${{ secrets.PRO_FTP_HOST }}
|
||||||
username: ${{ secrets.WEB_ANTD_FTP_ACCOUNT }}
|
username: ${{ secrets.WEB_ANTD_FTP_ACCOUNT }}
|
||||||
@@ -116,7 +116,7 @@ jobs:
|
|||||||
run: pnpm run build:ele
|
run: pnpm run build:ele
|
||||||
|
|
||||||
- name: Sync files
|
- name: Sync files
|
||||||
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
|
uses: SamKirkland/FTP-Deploy-Action@v4.3.6
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.PRO_FTP_HOST }}
|
server: ${{ secrets.PRO_FTP_HOST }}
|
||||||
username: ${{ secrets.WEB_ELE_FTP_ACCOUNT }}
|
username: ${{ secrets.WEB_ELE_FTP_ACCOUNT }}
|
||||||
@@ -147,7 +147,7 @@ jobs:
|
|||||||
run: pnpm run build:naive
|
run: pnpm run build:naive
|
||||||
|
|
||||||
- name: Sync files
|
- name: Sync files
|
||||||
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
|
uses: SamKirkland/FTP-Deploy-Action@v4.3.6
|
||||||
with:
|
with:
|
||||||
server: ${{ secrets.PRO_FTP_HOST }}
|
server: ${{ secrets.PRO_FTP_HOST }}
|
||||||
username: ${{ secrets.WEB_NAIVE_FTP_ACCOUNT }}
|
username: ${{ secrets.WEB_NAIVE_FTP_ACCOUNT }}
|
||||||
|
|||||||
2
.npmrc
2
.npmrc
@@ -1,4 +1,4 @@
|
|||||||
registry = "https://registry.npmmirror.com"
|
registry=https://registry.npmmirror.com
|
||||||
public-hoist-pattern[]=lefthook
|
public-hoist-pattern[]=lefthook
|
||||||
public-hoist-pattern[]=eslint
|
public-hoist-pattern[]=eslint
|
||||||
public-hoist-pattern[]=prettier
|
public-hoist-pattern[]=prettier
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<h1>Vue Vben Admin</h1>
|
<h1>Vue Vben Admin</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
[](https://sonarcloud.io/summary/new_code?id=vbenjs_vue-vben-admin)    
|
[](https://sonarcloud.io/summary/new_code?id=vbenjs_vue-vben-admin) [](https://github.com/vbenjs/vue-vben-admin/actions/workflows/codeql.yml) [](https://github.com/vbenjs/vue-vben-admin/actions/workflows/build.yml) [](https://github.com/vbenjs/vue-vben-admin/actions/workflows/ci.yml) [](https://github.com/vbenjs/vue-vben-admin/actions/workflows/deploy.yml)
|
||||||
|
|
||||||
**English** | [中文](./README.zh-CN.md) | [日本語](./README.ja-JP.md)
|
**English** | [中文](./README.zh-CN.md) | [日本語](./README.ja-JP.md)
|
||||||
|
|
||||||
|
|||||||
12
apps/backend-mock/api/timezone/getTimezone.ts
Normal file
12
apps/backend-mock/api/timezone/getTimezone.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { eventHandler } from 'h3';
|
||||||
|
import { verifyAccessToken } from '~/utils/jwt-utils';
|
||||||
|
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
||||||
|
import { getTimezone } from '~/utils/timezone-utils';
|
||||||
|
|
||||||
|
export default eventHandler((event) => {
|
||||||
|
const userinfo = verifyAccessToken(event);
|
||||||
|
if (!userinfo) {
|
||||||
|
return unAuthorizedResponse(event);
|
||||||
|
}
|
||||||
|
return useResponseSuccess(getTimezone());
|
||||||
|
});
|
||||||
11
apps/backend-mock/api/timezone/getTimezoneOptions.ts
Normal file
11
apps/backend-mock/api/timezone/getTimezoneOptions.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { eventHandler } from 'h3';
|
||||||
|
import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
|
||||||
|
import { useResponseSuccess } from '~/utils/response';
|
||||||
|
|
||||||
|
export default eventHandler(() => {
|
||||||
|
const data = TIME_ZONE_OPTIONS.map((o) => ({
|
||||||
|
label: `${o.timezone} (GMT${o.offset >= 0 ? `+${o.offset}` : o.offset})`,
|
||||||
|
value: o.timezone,
|
||||||
|
}));
|
||||||
|
return useResponseSuccess(data);
|
||||||
|
});
|
||||||
22
apps/backend-mock/api/timezone/setTimezone.ts
Normal file
22
apps/backend-mock/api/timezone/setTimezone.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { eventHandler, readBody } from 'h3';
|
||||||
|
import { verifyAccessToken } from '~/utils/jwt-utils';
|
||||||
|
import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
|
||||||
|
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
||||||
|
import { setTimezone } from '~/utils/timezone-utils';
|
||||||
|
|
||||||
|
export default eventHandler(async (event) => {
|
||||||
|
const userinfo = verifyAccessToken(event);
|
||||||
|
if (!userinfo) {
|
||||||
|
return unAuthorizedResponse(event);
|
||||||
|
}
|
||||||
|
const body = await readBody<{ timezone?: unknown }>(event);
|
||||||
|
const timezone =
|
||||||
|
typeof body?.timezone === 'string' ? body.timezone : undefined;
|
||||||
|
const allowed = TIME_ZONE_OPTIONS.some((o) => o.timezone === timezone);
|
||||||
|
if (!timezone || !allowed) {
|
||||||
|
setResponseStatus(event, 400);
|
||||||
|
return useResponseError('Bad Request', 'Invalid timezone');
|
||||||
|
}
|
||||||
|
setTimezone(timezone);
|
||||||
|
return useResponseSuccess({});
|
||||||
|
});
|
||||||
@@ -7,6 +7,11 @@ export interface UserInfo {
|
|||||||
homePath?: string;
|
homePath?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TimezoneOption {
|
||||||
|
offset: number;
|
||||||
|
timezone: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const MOCK_USERS: UserInfo[] = [
|
export const MOCK_USERS: UserInfo[] = [
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 0,
|
||||||
@@ -276,7 +281,7 @@ export const MOCK_MENU_LIST = [
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
id: 20_401,
|
id: 20_401,
|
||||||
pid: 201,
|
pid: 202,
|
||||||
name: 'SystemDeptCreate',
|
name: 'SystemDeptCreate',
|
||||||
status: 1,
|
status: 1,
|
||||||
type: 'button',
|
type: 'button',
|
||||||
@@ -285,7 +290,7 @@ export const MOCK_MENU_LIST = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 20_402,
|
id: 20_402,
|
||||||
pid: 201,
|
pid: 202,
|
||||||
name: 'SystemDeptEdit',
|
name: 'SystemDeptEdit',
|
||||||
status: 1,
|
status: 1,
|
||||||
type: 'button',
|
type: 'button',
|
||||||
@@ -294,7 +299,7 @@ export const MOCK_MENU_LIST = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 20_403,
|
id: 20_403,
|
||||||
pid: 201,
|
pid: 202,
|
||||||
name: 'SystemDeptDelete',
|
name: 'SystemDeptDelete',
|
||||||
status: 1,
|
status: 1,
|
||||||
type: 'button',
|
type: 'button',
|
||||||
@@ -388,3 +393,29 @@ export function getMenuIds(menus: any[]) {
|
|||||||
});
|
});
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时区选项
|
||||||
|
*/
|
||||||
|
export const TIME_ZONE_OPTIONS: TimezoneOption[] = [
|
||||||
|
{
|
||||||
|
offset: -5,
|
||||||
|
timezone: 'America/New_York',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
timezone: 'Europe/London',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 8,
|
||||||
|
timezone: 'Asia/Shanghai',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 9,
|
||||||
|
timezone: 'Asia/Tokyo',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 9,
|
||||||
|
timezone: 'Asia/Seoul',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|||||||
9
apps/backend-mock/utils/timezone-utils.ts
Normal file
9
apps/backend-mock/utils/timezone-utils.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
let mockTimeZone: null | string = null;
|
||||||
|
|
||||||
|
export const setTimezone = (timeZone: string) => {
|
||||||
|
mockTimeZone = timeZone;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getTimezone = () => {
|
||||||
|
return mockTimeZone;
|
||||||
|
};
|
||||||
@@ -8,12 +8,14 @@ import { $t } from '#/locales';
|
|||||||
|
|
||||||
const appName = computed(() => preferences.app.name);
|
const appName = computed(() => preferences.app.name);
|
||||||
const logo = computed(() => preferences.logo.source);
|
const logo = computed(() => preferences.logo.source);
|
||||||
|
const logoDark = computed(() => preferences.logo.sourceDark);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AuthPageLayout
|
<AuthPageLayout
|
||||||
:app-name="appName"
|
:app-name="appName"
|
||||||
:logo="logo"
|
:logo="logo"
|
||||||
|
:logo-dark="logoDark"
|
||||||
:page-description="$t('authentication.pageDesc')"
|
:page-description="$t('authentication.pageDesc')"
|
||||||
:page-title="$t('authentication.pageTitle')"
|
:page-title="$t('authentication.pageTitle')"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ const defaultPreferences: Preferences = {
|
|||||||
enable: true,
|
enable: true,
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
||||||
|
// sourceDark: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-dark.webp', // Optional: Dark theme logo
|
||||||
},
|
},
|
||||||
navigation: {
|
navigation: {
|
||||||
accordion: true,
|
accordion: true,
|
||||||
@@ -457,6 +458,8 @@ interface LogoPreferences {
|
|||||||
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||||
/** Logo URL */
|
/** Logo URL */
|
||||||
source: string;
|
source: string;
|
||||||
|
/** Dark theme logo URL (optional, if not set, use source) */
|
||||||
|
sourceDark?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavigationPreferences {
|
interface NavigationPreferences {
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ const defaultPreferences: Preferences = {
|
|||||||
enable: true,
|
enable: true,
|
||||||
fit: 'contain',
|
fit: 'contain',
|
||||||
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
source: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
||||||
|
// sourceDark: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-dark.webp', // 可选:暗色主题logo
|
||||||
},
|
},
|
||||||
navigation: {
|
navigation: {
|
||||||
accordion: true,
|
accordion: true,
|
||||||
@@ -457,6 +458,8 @@ interface LogoPreferences {
|
|||||||
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||||
/** logo地址 */
|
/** logo地址 */
|
||||||
source: string;
|
source: string;
|
||||||
|
/** 暗色主题logo地址 (可选,若不设置则使用 source) */
|
||||||
|
sourceDark?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavigationPreferences {
|
interface NavigationPreferences {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
.side-content {
|
.side-content {
|
||||||
animation-duration: 0.2s;
|
animation-duration: 0.3s;
|
||||||
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
@keyframes slide-down {
|
@keyframes slide-down {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(-10px);
|
transform: translateY(50px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
@keyframes slide-left {
|
@keyframes slide-left {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateX(-10px);
|
transform: translateX(-50px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
@keyframes slide-right {
|
@keyframes slide-right {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateX(-10px);
|
transform: translateX(50px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
@keyframes slide-up {
|
@keyframes slide-up {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(10px);
|
transform: translateY(-50px);
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
|
|||||||
143
packages/@core/base/shared/src/utils/__tests__/date.test.ts
Normal file
143
packages/@core/base/shared/src/utils/__tests__/date.test.ts
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
import dayjs from 'dayjs';
|
||||||
|
import timezone from 'dayjs/plugin/timezone';
|
||||||
|
import utc from 'dayjs/plugin/utc';
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
|
import {
|
||||||
|
formatDate,
|
||||||
|
formatDateTime,
|
||||||
|
getCurrentTimezone,
|
||||||
|
getSystemTimezone,
|
||||||
|
isDate,
|
||||||
|
isDayjsObject,
|
||||||
|
setCurrentTimezone,
|
||||||
|
} from '../date';
|
||||||
|
|
||||||
|
dayjs.extend(utc);
|
||||||
|
dayjs.extend(timezone);
|
||||||
|
|
||||||
|
describe('dateUtils', () => {
|
||||||
|
const sampleISO = '2024-10-30T12:34:56Z';
|
||||||
|
const sampleTimestamp = Date.parse(sampleISO);
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// 重置时区
|
||||||
|
dayjs.tz.setDefault();
|
||||||
|
setCurrentTimezone(); // 重置为系统默认
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// formatDate
|
||||||
|
// ===============================
|
||||||
|
describe('formatDate', () => {
|
||||||
|
it('should format a valid ISO date string', () => {
|
||||||
|
const formatted = formatDate(sampleISO, 'YYYY/MM/DD');
|
||||||
|
expect(formatted).toMatch(/2024\/10\/30/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should format a timestamp correctly', () => {
|
||||||
|
const formatted = formatDate(sampleTimestamp);
|
||||||
|
expect(formatted).toMatch(/2024-10-30/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should format a Date object', () => {
|
||||||
|
const formatted = formatDate(new Date(sampleISO));
|
||||||
|
expect(formatted).toMatch(/2024-10-30/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should format a dayjs object', () => {
|
||||||
|
const formatted = formatDate(dayjs(sampleISO));
|
||||||
|
expect(formatted).toMatch(/2024-10-30/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return original input if date is invalid', () => {
|
||||||
|
const invalid = 'not-a-date';
|
||||||
|
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
const formatted = formatDate(invalid);
|
||||||
|
expect(formatted).toBe(invalid);
|
||||||
|
expect(spy).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should apply given format', () => {
|
||||||
|
const formatted = formatDate(sampleISO, 'YYYY-MM-DD HH:mm');
|
||||||
|
expect(formatted).toMatch(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// formatDateTime
|
||||||
|
// ===============================
|
||||||
|
describe('formatDateTime', () => {
|
||||||
|
it('should format date into full datetime', () => {
|
||||||
|
const result = formatDateTime(sampleISO);
|
||||||
|
expect(result).toMatch(/2024-10-30 \d{2}:\d{2}:\d{2}/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// isDate
|
||||||
|
// ===============================
|
||||||
|
describe('isDate', () => {
|
||||||
|
it('should return true for Date instances', () => {
|
||||||
|
expect(isDate(new Date())).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for non-Date values', () => {
|
||||||
|
expect(isDate('2024-10-30')).toBe(false);
|
||||||
|
expect(isDate(null)).toBe(false);
|
||||||
|
expect(isDate(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// isDayjsObject
|
||||||
|
// ===============================
|
||||||
|
describe('isDayjsObject', () => {
|
||||||
|
it('should return true for dayjs objects', () => {
|
||||||
|
expect(isDayjsObject(dayjs())).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for other values', () => {
|
||||||
|
expect(isDayjsObject(new Date())).toBe(false);
|
||||||
|
expect(isDayjsObject('string')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// getSystemTimezone
|
||||||
|
// ===============================
|
||||||
|
describe('getSystemTimezone', () => {
|
||||||
|
it('should return a valid IANA timezone string', () => {
|
||||||
|
const tz = getSystemTimezone();
|
||||||
|
expect(typeof tz).toBe('string');
|
||||||
|
expect(tz).toMatch(/^[A-Z]+\/[A-Z_]+/i);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// setCurrentTimezone / getCurrentTimezone
|
||||||
|
// ===============================
|
||||||
|
describe('setCurrentTimezone & getCurrentTimezone', () => {
|
||||||
|
it('should set and retrieve the current timezone', () => {
|
||||||
|
setCurrentTimezone('Asia/Shanghai');
|
||||||
|
expect(getCurrentTimezone()).toBe('Asia/Shanghai');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reset to system timezone when called with no args', () => {
|
||||||
|
const guessed = getSystemTimezone();
|
||||||
|
setCurrentTimezone();
|
||||||
|
expect(getCurrentTimezone()).toBe(guessed);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update dayjs default timezone', () => {
|
||||||
|
setCurrentTimezone('America/New_York');
|
||||||
|
const d = dayjs('2024-01-01T00:00:00Z');
|
||||||
|
// 校验时区转换生效(小时变化)
|
||||||
|
expect(d.tz().format('HH')).not.toBe('00');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,19 +1,26 @@
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import timezone from 'dayjs/plugin/timezone';
|
||||||
|
import utc from 'dayjs/plugin/utc';
|
||||||
|
|
||||||
export function formatDate(time: number | string, format = 'YYYY-MM-DD') {
|
dayjs.extend(utc);
|
||||||
|
dayjs.extend(timezone);
|
||||||
|
|
||||||
|
type FormatDate = Date | dayjs.Dayjs | number | string;
|
||||||
|
|
||||||
|
export function formatDate(time: FormatDate, format = 'YYYY-MM-DD') {
|
||||||
try {
|
try {
|
||||||
const date = dayjs(time);
|
const date = dayjs.isDayjs(time) ? time : dayjs(time);
|
||||||
if (!date.isValid()) {
|
if (!date.isValid()) {
|
||||||
throw new Error('Invalid date');
|
throw new Error('Invalid date');
|
||||||
}
|
}
|
||||||
return date.format(format);
|
return date.tz().format(format);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error formatting date: ${error}`);
|
console.error(`Error formatting date: ${error}`);
|
||||||
return time;
|
return String(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDateTime(time: number | string) {
|
export function formatDateTime(time: FormatDate) {
|
||||||
return formatDate(time, 'YYYY-MM-DD HH:mm:ss');
|
return formatDate(time, 'YYYY-MM-DD HH:mm:ss');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,3 +31,33 @@ export function isDate(value: any): value is Date {
|
|||||||
export function isDayjsObject(value: any): value is dayjs.Dayjs {
|
export function isDayjsObject(value: any): value is dayjs.Dayjs {
|
||||||
return dayjs.isDayjs(value);
|
return dayjs.isDayjs(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前时区
|
||||||
|
* @returns 当前时区
|
||||||
|
*/
|
||||||
|
export const getSystemTimezone = () => {
|
||||||
|
return dayjs.tz.guess();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义设置的时区
|
||||||
|
*/
|
||||||
|
let currentTimezone = getSystemTimezone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置默认时区
|
||||||
|
* @param timezone
|
||||||
|
*/
|
||||||
|
export const setCurrentTimezone = (timezone?: string) => {
|
||||||
|
currentTimezone = timezone || getSystemTimezone();
|
||||||
|
dayjs.tz.setDefault(currentTimezone);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设置的时区
|
||||||
|
* @returns 设置的时区
|
||||||
|
*/
|
||||||
|
export const getCurrentTimezone = () => {
|
||||||
|
return currentTimezone;
|
||||||
|
};
|
||||||
|
|||||||
10
packages/@core/base/typings/src/app.d.ts
vendored
10
packages/@core/base/typings/src/app.d.ts
vendored
@@ -93,6 +93,15 @@ type PageTransitionType = 'fade' | 'fade-down' | 'fade-slide' | 'fade-up';
|
|||||||
*/
|
*/
|
||||||
type AuthPageLayoutType = 'panel-center' | 'panel-left' | 'panel-right';
|
type AuthPageLayoutType = 'panel-center' | 'panel-left' | 'panel-right';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时区选项
|
||||||
|
*/
|
||||||
|
interface TimezoneOption {
|
||||||
|
label: string;
|
||||||
|
offset: number;
|
||||||
|
timezone: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
AccessModeType,
|
AccessModeType,
|
||||||
AuthPageLayoutType,
|
AuthPageLayoutType,
|
||||||
@@ -108,4 +117,5 @@ export type {
|
|||||||
PreferencesButtonPositionType,
|
PreferencesButtonPositionType,
|
||||||
TabsStyleType,
|
TabsStyleType,
|
||||||
ThemeModeType,
|
ThemeModeType,
|
||||||
|
TimezoneOption,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
|||||||
"enableCheckUpdates": true,
|
"enableCheckUpdates": true,
|
||||||
"enablePreferences": true,
|
"enablePreferences": true,
|
||||||
"enableRefreshToken": false,
|
"enableRefreshToken": false,
|
||||||
|
"enableStickyPreferencesNavigationBar": true,
|
||||||
"isMobile": false,
|
"isMobile": false,
|
||||||
"layout": "sidebar-nav",
|
"layout": "sidebar-nav",
|
||||||
"locale": "zh-CN",
|
"locale": "zh-CN",
|
||||||
@@ -29,6 +30,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
|||||||
"name": "Vben Admin",
|
"name": "Vben Admin",
|
||||||
"preferencesButtonPosition": "auto",
|
"preferencesButtonPosition": "auto",
|
||||||
"watermark": false,
|
"watermark": false,
|
||||||
|
"watermarkContent": "",
|
||||||
"zIndex": 200,
|
"zIndex": 200,
|
||||||
},
|
},
|
||||||
"breadcrumb": {
|
"breadcrumb": {
|
||||||
@@ -131,6 +133,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
|
|||||||
"refresh": true,
|
"refresh": true,
|
||||||
"sidebarToggle": true,
|
"sidebarToggle": true,
|
||||||
"themeToggle": true,
|
"themeToggle": true,
|
||||||
|
"timezone": true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ const defaultPreferences: Preferences = {
|
|||||||
refresh: true,
|
refresh: true,
|
||||||
sidebarToggle: true,
|
sidebarToggle: true,
|
||||||
themeToggle: true,
|
themeToggle: true,
|
||||||
|
timezone: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { BuiltinThemeType } from '@vben-core/typings';
|
import type { BuiltinThemeType, TimezoneOption } from '@vben-core/typings';
|
||||||
|
|
||||||
interface BuiltinThemePreset {
|
interface BuiltinThemePreset {
|
||||||
color: string;
|
color: string;
|
||||||
@@ -81,8 +81,39 @@ const BUILT_IN_THEME_PRESETS: BuiltinThemePreset[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时区选项
|
||||||
|
*/
|
||||||
|
const DEFAULT_TIME_ZONE_OPTIONS: TimezoneOption[] = [
|
||||||
|
{
|
||||||
|
offset: -5,
|
||||||
|
timezone: 'America/New_York',
|
||||||
|
label: 'America/New_York(GMT-5)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 0,
|
||||||
|
timezone: 'Europe/London',
|
||||||
|
label: 'Europe/London(GMT0)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 8,
|
||||||
|
timezone: 'Asia/Shanghai',
|
||||||
|
label: 'Asia/Shanghai(GMT+8)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 9,
|
||||||
|
timezone: 'Asia/Tokyo',
|
||||||
|
label: 'Asia/Tokyo(GMT+9)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
offset: 9,
|
||||||
|
timezone: 'Asia/Seoul',
|
||||||
|
label: 'Asia/Seoul(GMT+9)',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export const COLOR_PRESETS = [...BUILT_IN_THEME_PRESETS].slice(0, 7);
|
export const COLOR_PRESETS = [...BUILT_IN_THEME_PRESETS].slice(0, 7);
|
||||||
|
|
||||||
export { BUILT_IN_THEME_PRESETS };
|
export { BUILT_IN_THEME_PRESETS, DEFAULT_TIME_ZONE_OPTIONS };
|
||||||
|
|
||||||
export type { BuiltinThemePreset };
|
export type { BuiltinThemePreset };
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ interface LogoPreferences {
|
|||||||
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
fit: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
||||||
/** logo地址 */
|
/** logo地址 */
|
||||||
source: string;
|
source: string;
|
||||||
|
/** 暗色主题logo地址 (可选,若不设置则使用 source) */
|
||||||
|
sourceDark?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavigationPreferences {
|
interface NavigationPreferences {
|
||||||
@@ -275,6 +277,8 @@ interface WidgetPreferences {
|
|||||||
sidebarToggle: boolean;
|
sidebarToggle: boolean;
|
||||||
/** 是否显示主题切换部件 */
|
/** 是否显示主题切换部件 */
|
||||||
themeToggle: boolean;
|
themeToggle: boolean;
|
||||||
|
/** 是否显示时区部件 */
|
||||||
|
timezone: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Preferences {
|
interface Preferences {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
useLayoutFooterStyle,
|
useLayoutFooterStyle,
|
||||||
useLayoutHeaderStyle,
|
useLayoutHeaderStyle,
|
||||||
} from '@vben-core/composables';
|
} from '@vben-core/composables';
|
||||||
import { Menu } from '@vben-core/icons';
|
import { IconifyIcon } from '@vben-core/icons';
|
||||||
import { VbenIconButton } from '@vben-core/shadcn-ui';
|
import { VbenIconButton } from '@vben-core/shadcn-ui';
|
||||||
import { ELEMENT_ID_MAIN_CONTENT } from '@vben-core/shared/constants';
|
import { ELEMENT_ID_MAIN_CONTENT } from '@vben-core/shared/constants';
|
||||||
|
|
||||||
@@ -559,7 +559,8 @@ const idMainContent = ELEMENT_ID_MAIN_CONTENT;
|
|||||||
class="my-0 mr-1 rounded-md"
|
class="my-0 mr-1 rounded-md"
|
||||||
@click="handleHeaderToggle"
|
@click="handleHeaderToggle"
|
||||||
>
|
>
|
||||||
<Menu class="size-4" />
|
<IconifyIcon v-if="showSidebar" icon="ep:fold" />
|
||||||
|
<IconifyIcon v-else icon="ep:expand" />
|
||||||
</VbenIconButton>
|
</VbenIconButton>
|
||||||
</template>
|
</template>
|
||||||
<slot name="header"></slot>
|
<slot name="header"></slot>
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ function escapeKeyDown(e: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handerOpenAutoFocus(e: Event) {
|
function handleOpenAutoFocus(e: Event) {
|
||||||
if (!openAutoFocus.value) {
|
if (!openAutoFocus.value) {
|
||||||
e?.preventDefault();
|
e?.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -209,6 +209,12 @@ const getForceMount = computed(() => {
|
|||||||
return !unref(destroyOnClose) && unref(firstOpened);
|
return !unref(destroyOnClose) && unref(firstOpened);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleOpened = () => {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
props.modalApi?.onOpened();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function handleClosed() {
|
function handleClosed() {
|
||||||
isClosed.value = true;
|
isClosed.value = true;
|
||||||
props.modalApi?.onClosed();
|
props.modalApi?.onClosed();
|
||||||
@@ -253,8 +259,8 @@ function handleClosed() {
|
|||||||
@escape-key-down="escapeKeyDown"
|
@escape-key-down="escapeKeyDown"
|
||||||
@focus-outside="handleFocusOutside"
|
@focus-outside="handleFocusOutside"
|
||||||
@interact-outside="interactOutside"
|
@interact-outside="interactOutside"
|
||||||
@open-auto-focus="handerOpenAutoFocus"
|
@open-auto-focus="handleOpenAutoFocus"
|
||||||
@opened="() => modalApi?.onOpened()"
|
@opened="handleOpened"
|
||||||
@pointer-down-outside="pointerDownOutside"
|
@pointer-down-outside="pointerDownOutside"
|
||||||
>
|
>
|
||||||
<DialogHeader
|
<DialogHeader
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { VbenAvatar } from '../avatar';
|
import { VbenAvatar } from '../avatar';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -22,6 +24,10 @@ interface Props {
|
|||||||
* @zh_CN Logo 图标
|
* @zh_CN Logo 图标
|
||||||
*/
|
*/
|
||||||
src?: string;
|
src?: string;
|
||||||
|
/**
|
||||||
|
* @zh_CN 暗色主题 Logo 图标 (可选,若不设置则使用 src)
|
||||||
|
*/
|
||||||
|
srcDark?: string;
|
||||||
/**
|
/**
|
||||||
* @zh_CN Logo 文本
|
* @zh_CN Logo 文本
|
||||||
*/
|
*/
|
||||||
@@ -36,14 +42,27 @@ defineOptions({
|
|||||||
name: 'VbenLogo',
|
name: 'VbenLogo',
|
||||||
});
|
});
|
||||||
|
|
||||||
withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
href: 'javascript:void 0',
|
href: 'javascript:void 0',
|
||||||
logoSize: 32,
|
logoSize: 32,
|
||||||
src: '',
|
src: '',
|
||||||
|
srcDark: '',
|
||||||
theme: 'light',
|
theme: 'light',
|
||||||
fit: 'cover',
|
fit: 'cover',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh_CN 根据主题选择合适的 logo 图标
|
||||||
|
*/
|
||||||
|
const logoSrc = computed(() => {
|
||||||
|
// 如果是暗色主题且提供了 srcDark,则使用暗色主题的 logo
|
||||||
|
if (props.theme === 'dark' && props.srcDark) {
|
||||||
|
return props.srcDark;
|
||||||
|
}
|
||||||
|
// 否则使用默认的 src
|
||||||
|
return props.src;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -54,9 +73,9 @@ withDefaults(defineProps<Props>(), {
|
|||||||
class="flex h-full items-center gap-2 overflow-hidden px-3 text-lg leading-normal transition-all duration-500"
|
class="flex h-full items-center gap-2 overflow-hidden px-3 text-lg leading-normal transition-all duration-500"
|
||||||
>
|
>
|
||||||
<VbenAvatar
|
<VbenAvatar
|
||||||
v-if="src"
|
v-if="logoSrc"
|
||||||
:alt="text"
|
:alt="text"
|
||||||
:src="src"
|
:src="logoSrc"
|
||||||
:size="logoSize"
|
:size="logoSize"
|
||||||
:fit="fit"
|
:fit="fit"
|
||||||
class="relative rounded-none bg-transparent"
|
class="relative rounded-none bg-transparent"
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|||||||
v-bind="forwarded"
|
v-bind="forwarded"
|
||||||
:class="
|
:class="
|
||||||
cn(
|
cn(
|
||||||
'focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground border-border peer h-4 w-4 shrink-0 rounded-sm border transition focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50',
|
'focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground border-border hover:border-primary peer h-4 w-4 shrink-0 rounded-sm border transition focus-visible:outline-none focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50',
|
||||||
props.class,
|
props.class,
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { TabsListProps } from 'radix-vue';
|
import type { TabsListProps } from 'radix-vue';
|
||||||
|
|
||||||
import { cn } from '@vben-core/shared/utils';
|
|
||||||
import { TabsList } from 'radix-vue';
|
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
const props = defineProps<{ class?: any } & TabsListProps>();
|
import { cn } from '@vben-core/shared/utils';
|
||||||
|
|
||||||
|
import { TabsList } from 'radix-vue';
|
||||||
|
|
||||||
|
const props = defineProps<TabsListProps & { class?: any }>();
|
||||||
|
|
||||||
const delegatedProps = computed(() => {
|
const delegatedProps = computed(() => {
|
||||||
const { class: _, ...delegated } = props;
|
const { class: _, ...delegated } = props;
|
||||||
@@ -19,7 +21,7 @@ const delegatedProps = computed(() => {
|
|||||||
v-bind="delegatedProps"
|
v-bind="delegatedProps"
|
||||||
:class="
|
:class="
|
||||||
cn(
|
cn(
|
||||||
'bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-lg p-1',
|
'bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-md p-1',
|
||||||
props.class,
|
props.class,
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { ToolbarType } from './types';
|
import type { ToolbarType } from './types';
|
||||||
|
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { preferences, usePreferences } from '@vben/preferences';
|
import { preferences, usePreferences } from '@vben/preferences';
|
||||||
|
|
||||||
import { Copyright } from '../basic/copyright';
|
import { Copyright } from '../basic/copyright';
|
||||||
@@ -11,6 +13,7 @@ import Toolbar from './toolbar.vue';
|
|||||||
interface Props {
|
interface Props {
|
||||||
appName?: string;
|
appName?: string;
|
||||||
logo?: string;
|
logo?: string;
|
||||||
|
logoDark?: string;
|
||||||
pageTitle?: string;
|
pageTitle?: string;
|
||||||
pageDescription?: string;
|
pageDescription?: string;
|
||||||
sloganImage?: string;
|
sloganImage?: string;
|
||||||
@@ -20,10 +23,11 @@ interface Props {
|
|||||||
clickLogo?: () => void;
|
clickLogo?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
appName: '',
|
appName: '',
|
||||||
copyright: true,
|
copyright: true,
|
||||||
logo: '',
|
logo: '',
|
||||||
|
logoDark: '',
|
||||||
pageDescription: '',
|
pageDescription: '',
|
||||||
pageTitle: '',
|
pageTitle: '',
|
||||||
sloganImage: '',
|
sloganImage: '',
|
||||||
@@ -34,6 +38,18 @@ withDefaults(defineProps<Props>(), {
|
|||||||
|
|
||||||
const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
||||||
usePreferences();
|
usePreferences();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @zh_CN 根据主题选择合适的 logo 图标
|
||||||
|
*/
|
||||||
|
const logoSrc = computed(() => {
|
||||||
|
// 如果是暗色主题且提供了 logoDark,则使用暗色主题的 logo
|
||||||
|
if (isDark.value && props.logoDark) {
|
||||||
|
return props.logoDark;
|
||||||
|
}
|
||||||
|
// 否则使用默认的 logo
|
||||||
|
return props.logo;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -50,7 +66,7 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
|||||||
<AuthenticationFormView
|
<AuthenticationFormView
|
||||||
v-if="authPanelLeft"
|
v-if="authPanelLeft"
|
||||||
class="min-h-full w-2/5 flex-1"
|
class="min-h-full w-2/5 flex-1"
|
||||||
transition-name="slide-left"
|
data-side="left"
|
||||||
>
|
>
|
||||||
<template v-if="copyright" #copyright>
|
<template v-if="copyright" #copyright>
|
||||||
<slot name="copyright">
|
<slot name="copyright">
|
||||||
@@ -65,14 +81,21 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
|||||||
<slot name="logo">
|
<slot name="logo">
|
||||||
<!-- 头部 Logo 和应用名称 -->
|
<!-- 头部 Logo 和应用名称 -->
|
||||||
<div
|
<div
|
||||||
v-if="logo || appName"
|
v-if="logoSrc || appName"
|
||||||
class="absolute left-0 top-0 z-10 flex flex-1"
|
class="absolute left-0 top-0 z-10 flex flex-1"
|
||||||
@click="clickLogo"
|
@click="clickLogo"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="text-foreground lg:text-foreground ml-4 mt-4 flex flex-1 items-center sm:left-6 sm:top-6"
|
class="text-foreground lg:text-foreground ml-4 mt-4 flex flex-1 items-center sm:left-6 sm:top-6"
|
||||||
>
|
>
|
||||||
<img v-if="logo" :alt="appName" :src="logo" class="mr-2" width="42" />
|
<img
|
||||||
|
v-if="logoSrc"
|
||||||
|
:key="logoSrc"
|
||||||
|
:alt="appName"
|
||||||
|
:src="logoSrc"
|
||||||
|
class="mr-2"
|
||||||
|
width="42"
|
||||||
|
/>
|
||||||
<p v-if="appName" class="m-0 text-xl font-medium">
|
<p v-if="appName" class="m-0 text-xl font-medium">
|
||||||
{{ appName }}
|
{{ appName }}
|
||||||
</p>
|
</p>
|
||||||
@@ -86,7 +109,14 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
|||||||
class="bg-background-deep absolute inset-0 h-full w-full dark:bg-[#070709]"
|
class="bg-background-deep absolute inset-0 h-full w-full dark:bg-[#070709]"
|
||||||
>
|
>
|
||||||
<div class="login-background absolute left-0 top-0 size-full"></div>
|
<div class="login-background absolute left-0 top-0 size-full"></div>
|
||||||
<div class="flex-col-center -enter-x mr-20 h-full">
|
<div
|
||||||
|
:key="authPanelLeft ? 'left' : authPanelRight ? 'right' : 'center'"
|
||||||
|
class="flex-col-center mr-20 h-full"
|
||||||
|
:class="{
|
||||||
|
'enter-x': authPanelLeft,
|
||||||
|
'-enter-x': authPanelRight,
|
||||||
|
}"
|
||||||
|
>
|
||||||
<template v-if="sloganImage">
|
<template v-if="sloganImage">
|
||||||
<img
|
<img
|
||||||
:alt="appName"
|
:alt="appName"
|
||||||
@@ -110,6 +140,7 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
|||||||
<div class="login-background absolute left-0 top-0 size-full"></div>
|
<div class="login-background absolute left-0 top-0 size-full"></div>
|
||||||
<AuthenticationFormView
|
<AuthenticationFormView
|
||||||
class="md:bg-background shadow-primary/5 shadow-float w-full rounded-3xl pb-20 md:w-2/3 lg:w-1/2 xl:w-[36%]"
|
class="md:bg-background shadow-primary/5 shadow-float w-full rounded-3xl pb-20 md:w-2/3 lg:w-1/2 xl:w-[36%]"
|
||||||
|
data-side="bottom"
|
||||||
>
|
>
|
||||||
<template v-if="copyright" #copyright>
|
<template v-if="copyright" #copyright>
|
||||||
<slot name="copyright">
|
<slot name="copyright">
|
||||||
@@ -125,7 +156,8 @@ const { authPanelCenter, authPanelLeft, authPanelRight, isDark } =
|
|||||||
<!-- 右侧认证面板 -->
|
<!-- 右侧认证面板 -->
|
||||||
<AuthenticationFormView
|
<AuthenticationFormView
|
||||||
v-if="authPanelRight"
|
v-if="authPanelRight"
|
||||||
class="min-h-full w-[34%] flex-1"
|
class="min-h-full w-2/5 flex-1"
|
||||||
|
data-side="right"
|
||||||
>
|
>
|
||||||
<template v-if="copyright" #copyright>
|
<template v-if="copyright" #copyright>
|
||||||
<slot name="copyright">
|
<slot name="copyright">
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'AuthenticationFormView',
|
name: 'AuthenticationFormView',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
dataSide?: 'bottom' | 'left' | 'right' | 'top';
|
||||||
|
}>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -16,7 +20,8 @@ defineOptions({
|
|||||||
<component
|
<component
|
||||||
:is="Component"
|
:is="Component"
|
||||||
:key="route.fullPath"
|
:key="route.fullPath"
|
||||||
class="enter-x mt-6 w-full sm:mx-auto md:max-w-md"
|
class="side-content mt-6 w-full sm:mx-auto md:max-w-md"
|
||||||
|
:data-side="dataSide"
|
||||||
/>
|
/>
|
||||||
</KeepAlive>
|
</KeepAlive>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { computed, useSlots } from 'vue';
|
||||||
|
|
||||||
import { useRefresh } from '@vben/hooks';
|
import { useRefresh } from '@vben/hooks';
|
||||||
import { RotateCw } from '@vben/icons';
|
import { RotateCw } from '@vben/icons';
|
||||||
import { preferences, usePreferences } from '@vben/preferences';
|
import { preferences, usePreferences } from '@vben/preferences';
|
||||||
import { useAccessStore } from '@vben/stores';
|
import { useAccessStore } from '@vben/stores';
|
||||||
|
|
||||||
import { VbenFullScreen, VbenIconButton } from '@vben-core/shadcn-ui';
|
import { VbenFullScreen, VbenIconButton } from '@vben-core/shadcn-ui';
|
||||||
import { computed, useSlots } from 'vue';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GlobalSearch,
|
GlobalSearch,
|
||||||
LanguageToggle,
|
LanguageToggle,
|
||||||
PreferencesButton,
|
PreferencesButton,
|
||||||
ThemeToggle,
|
ThemeToggle,
|
||||||
|
TimezoneButton,
|
||||||
} from '../../widgets';
|
} from '../../widgets';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -64,15 +67,21 @@ const rightSlots = computed(() => {
|
|||||||
name: 'language-toggle',
|
name: 'language-toggle',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (preferences.widget.fullscreen) {
|
if (preferences.widget.timezone) {
|
||||||
list.push({
|
list.push({
|
||||||
index: REFERENCE_VALUE + 40,
|
index: REFERENCE_VALUE + 40,
|
||||||
|
name: 'timezone',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (preferences.widget.fullscreen) {
|
||||||
|
list.push({
|
||||||
|
index: REFERENCE_VALUE + 50,
|
||||||
name: 'fullscreen',
|
name: 'fullscreen',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (preferences.widget.notification) {
|
if (preferences.widget.notification) {
|
||||||
list.push({
|
list.push({
|
||||||
index: REFERENCE_VALUE + 50,
|
index: REFERENCE_VALUE + 60,
|
||||||
name: 'notification',
|
name: 'notification',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -164,6 +173,9 @@ function clearPreferencesAndLogout() {
|
|||||||
<template v-else-if="slot.name === 'fullscreen'">
|
<template v-else-if="slot.name === 'fullscreen'">
|
||||||
<VbenFullScreen class="mr-1" />
|
<VbenFullScreen class="mr-1" />
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="slot.name === 'timezone'">
|
||||||
|
<TimezoneButton class="mr-1 mt-[2px]" />
|
||||||
|
</template>
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ const headerSlots = computed(() => {
|
|||||||
:class="logoClass"
|
:class="logoClass"
|
||||||
:collapsed="logoCollapsed"
|
:collapsed="logoCollapsed"
|
||||||
:src="preferences.logo.source"
|
:src="preferences.logo.source"
|
||||||
|
:src-dark="preferences.logo.sourceDark"
|
||||||
:text="preferences.app.name"
|
:text="preferences.app.name"
|
||||||
:theme="showHeaderNav ? headerTheme : theme"
|
:theme="showHeaderNav ? headerTheme : theme"
|
||||||
@click="clickLogo"
|
@click="clickLogo"
|
||||||
@@ -302,6 +303,9 @@ const headerSlots = computed(() => {
|
|||||||
<template #notification>
|
<template #notification>
|
||||||
<slot name="notification"></slot>
|
<slot name="notification"></slot>
|
||||||
</template>
|
</template>
|
||||||
|
<template #timezone>
|
||||||
|
<slot name="timezone"></slot>
|
||||||
|
</template>
|
||||||
<template v-for="item in headerSlots" #[item]>
|
<template v-for="item in headerSlots" #[item]>
|
||||||
<slot :name="item"></slot>
|
<slot :name="item"></slot>
|
||||||
</template>
|
</template>
|
||||||
@@ -347,6 +351,8 @@ const headerSlots = computed(() => {
|
|||||||
<VbenLogo
|
<VbenLogo
|
||||||
v-if="preferences.logo.enable"
|
v-if="preferences.logo.enable"
|
||||||
:fit="preferences.logo.fit"
|
:fit="preferences.logo.fit"
|
||||||
|
:src="preferences.logo.source"
|
||||||
|
:src-dark="preferences.logo.sourceDark"
|
||||||
:text="preferences.app.name"
|
:text="preferences.app.name"
|
||||||
:theme="theme"
|
:theme="theme"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ export * from './lock-screen';
|
|||||||
export * from './notification';
|
export * from './notification';
|
||||||
export * from './preferences';
|
export * from './preferences';
|
||||||
export * from './theme-toggle';
|
export * from './theme-toggle';
|
||||||
|
export * from './timezone';
|
||||||
export * from './user-dropdown';
|
export * from './user-dropdown';
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Recordable } from '@vben/types';
|
import type { Recordable } from '@vben/types';
|
||||||
|
|
||||||
|
import { computed, reactive } from 'vue';
|
||||||
|
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
import { useVbenForm, z } from '@vben-core/form-ui';
|
import { useVbenForm, z } from '@vben-core/form-ui';
|
||||||
import { useVbenModal } from '@vben-core/popup-ui';
|
import { useVbenModal } from '@vben-core/popup-ui';
|
||||||
import { VbenAvatar, VbenButton } from '@vben-core/shadcn-ui';
|
import { VbenAvatar, VbenButton } from '@vben-core/shadcn-ui';
|
||||||
import { computed, reactive } from 'vue';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
@@ -25,29 +27,30 @@ const emit = defineEmits<{
|
|||||||
submit: [Recordable<any>];
|
submit: [Recordable<any>];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const [Form, { resetForm, validate, getValues }] = useVbenForm(
|
const [Form, { resetForm, validate, getValues, getFieldComponentRef }] =
|
||||||
reactive({
|
useVbenForm(
|
||||||
commonConfig: {
|
reactive({
|
||||||
hideLabel: true,
|
commonConfig: {
|
||||||
hideRequiredMark: true,
|
hideLabel: true,
|
||||||
},
|
hideRequiredMark: true,
|
||||||
schema: computed(() => [
|
|
||||||
{
|
|
||||||
component: 'VbenInputPassword' as const,
|
|
||||||
componentProps: {
|
|
||||||
placeholder: $t('ui.widgets.lockScreen.placeholder'),
|
|
||||||
},
|
|
||||||
fieldName: 'lockScreenPassword',
|
|
||||||
formFieldProps: { validateOnBlur: false },
|
|
||||||
label: $t('authentication.password'),
|
|
||||||
rules: z
|
|
||||||
.string()
|
|
||||||
.min(1, { message: $t('ui.widgets.lockScreen.placeholder') }),
|
|
||||||
},
|
},
|
||||||
]),
|
schema: computed(() => [
|
||||||
showDefaultActions: false,
|
{
|
||||||
}),
|
component: 'VbenInputPassword' as const,
|
||||||
);
|
componentProps: {
|
||||||
|
placeholder: $t('ui.widgets.lockScreen.placeholder'),
|
||||||
|
},
|
||||||
|
fieldName: 'lockScreenPassword',
|
||||||
|
formFieldProps: { validateOnBlur: false },
|
||||||
|
label: $t('authentication.password'),
|
||||||
|
rules: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: $t('ui.widgets.lockScreen.placeholder') }),
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
showDefaultActions: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const [Modal] = useVbenModal({
|
const [Modal] = useVbenModal({
|
||||||
onConfirm() {
|
onConfirm() {
|
||||||
@@ -58,6 +61,13 @@ const [Modal] = useVbenModal({
|
|||||||
resetForm();
|
resetForm();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onOpened() {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
getFieldComponentRef('lockScreenPassword')
|
||||||
|
?.$el?.querySelector('[name="lockScreenPassword"]')
|
||||||
|
?.focus();
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const date = useDateFormat(now, 'YYYY-MM-DD dddd', { locales: locale.value });
|
|||||||
const showUnlockForm = ref(false);
|
const showUnlockForm = ref(false);
|
||||||
const { lockScreenPassword } = storeToRefs(accessStore);
|
const { lockScreenPassword } = storeToRefs(accessStore);
|
||||||
|
|
||||||
const [Form, { form, validate }] = useVbenForm(
|
const [Form, { form, validate, getFieldComponentRef }] = useVbenForm(
|
||||||
reactive({
|
reactive({
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
hideLabel: true,
|
hideLabel: true,
|
||||||
@@ -75,6 +75,13 @@ async function handleSubmit() {
|
|||||||
|
|
||||||
function toggleUnlockForm() {
|
function toggleUnlockForm() {
|
||||||
showUnlockForm.value = !showUnlockForm.value;
|
showUnlockForm.value = !showUnlockForm.value;
|
||||||
|
if (showUnlockForm.value) {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
getFieldComponentRef('password')
|
||||||
|
?.$el?.querySelector('[name="password"]')
|
||||||
|
?.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useScrollLock();
|
useScrollLock();
|
||||||
|
|||||||
1
packages/effects/layouts/src/widgets/timezone/index.ts
Normal file
1
packages/effects/layouts/src/widgets/timezone/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default as TimezoneButton } from './timezone-button.vue';
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, unref } from 'vue';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
import { $t } from '@vben/locales';
|
||||||
|
import { useTimezoneStore } from '@vben/stores';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben-core/popup-ui';
|
||||||
|
import {
|
||||||
|
RadioGroup,
|
||||||
|
RadioGroupItem,
|
||||||
|
VbenIconButton,
|
||||||
|
} from '@vben-core/shadcn-ui';
|
||||||
|
|
||||||
|
const TimezoneIcon = createIconifyIcon('fluent-mdl2:world-clock');
|
||||||
|
|
||||||
|
const timezoneStore = useTimezoneStore();
|
||||||
|
|
||||||
|
const timezoneRef = ref<string | undefined>();
|
||||||
|
|
||||||
|
const timezoneOptionsRef = ref<
|
||||||
|
{
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
}[]
|
||||||
|
>([]);
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
fullscreenButton: false,
|
||||||
|
onConfirm: async () => {
|
||||||
|
try {
|
||||||
|
modalApi.setState({ confirmLoading: true });
|
||||||
|
const timezone = unref(timezoneRef);
|
||||||
|
if (timezone) {
|
||||||
|
await timezoneStore.setTimezone(timezone);
|
||||||
|
}
|
||||||
|
modalApi.close();
|
||||||
|
} finally {
|
||||||
|
modalApi.setState({ confirmLoading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async onOpenChange(isOpen) {
|
||||||
|
if (isOpen) {
|
||||||
|
timezoneRef.value = unref(timezoneStore.timezone);
|
||||||
|
timezoneOptionsRef.value = await timezoneStore.getTimezoneOptions();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
modalApi.open();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<VbenIconButton
|
||||||
|
:tooltip="$t('ui.widgets.timezone.setTimezone')"
|
||||||
|
class="hover:animate-[shrink_0.3s_ease-in-out]"
|
||||||
|
@click="handleClick"
|
||||||
|
>
|
||||||
|
<TimezoneIcon class="text-foreground size-4" />
|
||||||
|
</VbenIconButton>
|
||||||
|
<Modal :title="$t('ui.widgets.timezone.setTimezone')">
|
||||||
|
<div class="timezone-container">
|
||||||
|
<RadioGroup v-model="timezoneRef" class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
class="flex cursor-pointer items-center gap-2"
|
||||||
|
v-for="item in timezoneOptionsRef"
|
||||||
|
:key="`container${item.value}`"
|
||||||
|
>
|
||||||
|
<RadioGroupItem :id="item.value" :value="item.value" />
|
||||||
|
<label :for="item.value" class="cursor-pointer">{{
|
||||||
|
item.label
|
||||||
|
}}</label>
|
||||||
|
</div>
|
||||||
|
</RadioGroup>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.timezone-container {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -103,6 +103,10 @@
|
|||||||
"errorPasswordTip": "Password error, please re-enter",
|
"errorPasswordTip": "Password error, please re-enter",
|
||||||
"backToLogin": "Back to login",
|
"backToLogin": "Back to login",
|
||||||
"entry": "Enter the system"
|
"entry": "Enter the system"
|
||||||
|
},
|
||||||
|
"timezone": {
|
||||||
|
"setTimezone": "Set Timezone",
|
||||||
|
"setSuccess": "Timezone set successfully"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,10 @@
|
|||||||
"errorPasswordTip": "密码错误,请重新输入",
|
"errorPasswordTip": "密码错误,请重新输入",
|
||||||
"backToLogin": "返回登录",
|
"backToLogin": "返回登录",
|
||||||
"entry": "进入系统"
|
"entry": "进入系统"
|
||||||
|
},
|
||||||
|
"timezone": {
|
||||||
|
"setTimezone": "设置时区",
|
||||||
|
"setSuccess": "时区设置成功"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './access';
|
export * from './access';
|
||||||
export * from './tabbar';
|
export * from './tabbar';
|
||||||
|
export * from './timezone';
|
||||||
export * from './user';
|
export * from './user';
|
||||||
|
|||||||
132
packages/stores/src/modules/timezone.ts
Normal file
132
packages/stores/src/modules/timezone.ts
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
import { ref, unref } from 'vue';
|
||||||
|
|
||||||
|
import { DEFAULT_TIME_ZONE_OPTIONS } from '@vben-core/preferences';
|
||||||
|
import {
|
||||||
|
getCurrentTimezone,
|
||||||
|
setCurrentTimezone,
|
||||||
|
} from '@vben-core/shared/utils';
|
||||||
|
|
||||||
|
import { acceptHMRUpdate, defineStore } from 'pinia';
|
||||||
|
|
||||||
|
interface TimezoneHandler {
|
||||||
|
getTimezone?: () => Promise<null | string | undefined>;
|
||||||
|
getTimezoneOptions?: () => Promise<
|
||||||
|
{
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
}[]
|
||||||
|
>;
|
||||||
|
setTimezone?: (timezone: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认时区处理模块
|
||||||
|
* 时区存储基于pinia存储插件
|
||||||
|
*/
|
||||||
|
const getDefaultTimezoneHandler = (): TimezoneHandler => {
|
||||||
|
return {
|
||||||
|
getTimezoneOptions: () => {
|
||||||
|
return Promise.resolve(
|
||||||
|
DEFAULT_TIME_ZONE_OPTIONS.map((item) => {
|
||||||
|
return {
|
||||||
|
label: item.label,
|
||||||
|
value: item.timezone,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义时区处理模块
|
||||||
|
*/
|
||||||
|
let customTimezoneHandler: null | Partial<TimezoneHandler> = null;
|
||||||
|
const setTimezoneHandler = (handler: Partial<TimezoneHandler>) => {
|
||||||
|
customTimezoneHandler = handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取时区处理模块
|
||||||
|
*/
|
||||||
|
const getTimezoneHandler = () => {
|
||||||
|
return {
|
||||||
|
...getDefaultTimezoneHandler(),
|
||||||
|
...customTimezoneHandler,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* timezone支持模块
|
||||||
|
*/
|
||||||
|
const useTimezoneStore = defineStore(
|
||||||
|
'core-timezone',
|
||||||
|
() => {
|
||||||
|
const timezoneRef = ref(getCurrentTimezone());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化时区
|
||||||
|
* Initialize the timezone
|
||||||
|
*/
|
||||||
|
async function initTimezone() {
|
||||||
|
const timezoneHandler = getTimezoneHandler();
|
||||||
|
const timezone = await timezoneHandler.getTimezone?.();
|
||||||
|
if (timezone) {
|
||||||
|
timezoneRef.value = timezone;
|
||||||
|
}
|
||||||
|
// 设置dayjs默认时区
|
||||||
|
setCurrentTimezone(unref(timezoneRef));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置时区
|
||||||
|
* Set the timezone
|
||||||
|
* @param timezone 时区字符串
|
||||||
|
*/
|
||||||
|
async function setTimezone(timezone: string) {
|
||||||
|
const timezoneHandler = getTimezoneHandler();
|
||||||
|
await timezoneHandler.setTimezone?.(timezone);
|
||||||
|
timezoneRef.value = timezone;
|
||||||
|
// 设置dayjs默认时区
|
||||||
|
setCurrentTimezone(timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取时区选项
|
||||||
|
* Get the timezone options
|
||||||
|
*/
|
||||||
|
async function getTimezoneOptions() {
|
||||||
|
const timezoneHandler = getTimezoneHandler();
|
||||||
|
return (await timezoneHandler.getTimezoneOptions?.()) || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
initTimezone().catch((error) => {
|
||||||
|
console.error('Failed to initialize timezone during store setup:', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
function $reset() {
|
||||||
|
timezoneRef.value = getCurrentTimezone();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timezone: timezoneRef,
|
||||||
|
setTimezone,
|
||||||
|
getTimezoneOptions,
|
||||||
|
$reset,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
persist: {
|
||||||
|
// 持久化
|
||||||
|
pick: ['timezone'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export { setTimezoneHandler, useTimezoneStore };
|
||||||
|
|
||||||
|
// 解决热更新问题
|
||||||
|
const hot = import.meta.hot;
|
||||||
|
if (hot) {
|
||||||
|
hot.accept(acceptHMRUpdate(useTimezoneStore, hot));
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './auth';
|
export * from './auth';
|
||||||
export * from './menu';
|
export * from './menu';
|
||||||
|
export * from './timezone';
|
||||||
export * from './user';
|
export * from './user';
|
||||||
|
|||||||
26
playground/src/api/core/timezone.ts
Normal file
26
playground/src/api/core/timezone.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统支持的时区列表
|
||||||
|
*/
|
||||||
|
export async function getTimezoneOptionsApi() {
|
||||||
|
return await requestClient.get<
|
||||||
|
{
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
}[]
|
||||||
|
>('/timezone/getTimezoneOptions');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取用户时区
|
||||||
|
*/
|
||||||
|
export async function getTimezoneApi(): Promise<null | string | undefined> {
|
||||||
|
return requestClient.get<null | string | undefined>('/timezone/getTimezone');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置用户时区
|
||||||
|
* @param timezone 时区
|
||||||
|
*/
|
||||||
|
export async function setTimezoneApi(timezone: string): Promise<void> {
|
||||||
|
return requestClient.post('/timezone/setTimezone', { timezone });
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import { router } from '#/router';
|
|||||||
import { initComponentAdapter } from './adapter/component';
|
import { initComponentAdapter } from './adapter/component';
|
||||||
import { initSetupVbenForm } from './adapter/form';
|
import { initSetupVbenForm } from './adapter/form';
|
||||||
import App from './app.vue';
|
import App from './app.vue';
|
||||||
|
import { initTimezone } from './timezone-init';
|
||||||
|
|
||||||
async function bootstrap(namespace: string) {
|
async function bootstrap(namespace: string) {
|
||||||
// 初始化组件适配器
|
// 初始化组件适配器
|
||||||
@@ -46,6 +47,9 @@ async function bootstrap(namespace: string) {
|
|||||||
// 配置 pinia-tore
|
// 配置 pinia-tore
|
||||||
await initStores(app, { namespace });
|
await initStores(app, { namespace });
|
||||||
|
|
||||||
|
// 初始化时区HANDLER
|
||||||
|
initTimezone();
|
||||||
|
|
||||||
// 安装权限指令
|
// 安装权限指令
|
||||||
registerAccessDirective(app);
|
registerAccessDirective(app);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"title": "系统管理",
|
||||||
"dept": {
|
"dept": {
|
||||||
"list": "部门列表",
|
"list": "部门列表",
|
||||||
"createTime": "创建时间",
|
"createTime": "创建时间",
|
||||||
@@ -62,6 +63,5 @@
|
|||||||
"operation": "操作",
|
"operation": "操作",
|
||||||
"permissions": "权限",
|
"permissions": "权限",
|
||||||
"setPermissions": "授权"
|
"setPermissions": "授权"
|
||||||
},
|
}
|
||||||
"title": "系统管理"
|
|
||||||
}
|
}
|
||||||
|
|||||||
20
playground/src/timezone-init.ts
Normal file
20
playground/src/timezone-init.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { setTimezoneHandler } from '@vben/stores';
|
||||||
|
|
||||||
|
import { getTimezoneApi, getTimezoneOptionsApi, setTimezoneApi } from '#/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化时区处理,通过API保存时区设置
|
||||||
|
*/
|
||||||
|
export function initTimezone() {
|
||||||
|
setTimezoneHandler({
|
||||||
|
getTimezone() {
|
||||||
|
return getTimezoneApi();
|
||||||
|
},
|
||||||
|
setTimezone(timezone: string) {
|
||||||
|
return setTimezoneApi(timezone);
|
||||||
|
},
|
||||||
|
getTimezoneOptions() {
|
||||||
|
return getTimezoneOptionsApi();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -22,8 +22,8 @@ const props = reactive({
|
|||||||
leftWidth: 30,
|
leftWidth: 30,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
rightWidth: 70,
|
rightWidth: 70,
|
||||||
splitHandle: false,
|
splitHandle: true,
|
||||||
splitLine: false,
|
splitLine: true,
|
||||||
});
|
});
|
||||||
const leftMinWidth = ref(props.leftMinWidth || 1);
|
const leftMinWidth = ref(props.leftMinWidth || 1);
|
||||||
const leftMaxWidth = ref(props.leftMaxWidth || 100);
|
const leftMaxWidth = ref(props.leftMaxWidth || 100);
|
||||||
@@ -42,7 +42,11 @@ const leftMaxWidth = ref(props.leftMaxWidth || 100);
|
|||||||
<template #left="{ isCollapsed, expand }">
|
<template #left="{ isCollapsed, expand }">
|
||||||
<div v-if="isCollapsed" @click="expand">
|
<div v-if="isCollapsed" @click="expand">
|
||||||
<Tooltip title="点击展开左侧">
|
<Tooltip title="点击展开左侧">
|
||||||
<Button shape="circle" type="primary">
|
<Button
|
||||||
|
shape="circle"
|
||||||
|
type="primary"
|
||||||
|
class="flex items-center justify-center"
|
||||||
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<IconifyIcon class="text-2xl" icon="bi:arrow-right" />
|
<IconifyIcon class="text-2xl" icon="bi:arrow-right" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ catalog:
|
|||||||
'@types/lodash.get': ^4.4.9
|
'@types/lodash.get': ^4.4.9
|
||||||
'@types/lodash.isequal': ^4.5.8
|
'@types/lodash.isequal': ^4.5.8
|
||||||
'@types/lodash.set': ^4.3.9
|
'@types/lodash.set': ^4.3.9
|
||||||
'@types/node': ^22.16.0
|
'@types/node': ^24.9.2
|
||||||
'@types/nprogress': ^0.2.3
|
'@types/nprogress': ^0.2.3
|
||||||
'@types/postcss-import': ^14.0.3
|
'@types/postcss-import': ^14.0.3
|
||||||
'@types/qrcode': ^1.5.5
|
'@types/qrcode': ^1.5.5
|
||||||
@@ -64,7 +64,7 @@ catalog:
|
|||||||
'@vue/shared': ^3.5.17
|
'@vue/shared': ^3.5.17
|
||||||
'@vue/test-utils': ^2.4.6
|
'@vue/test-utils': ^2.4.6
|
||||||
'@vueuse/core': ^13.4.0
|
'@vueuse/core': ^13.4.0
|
||||||
'@vueuse/integrations': ^13.4.0
|
'@vueuse/integrations': ^14.0.0
|
||||||
'@vueuse/motion': ^3.0.3
|
'@vueuse/motion': ^3.0.3
|
||||||
ant-design-vue: ^4.2.6
|
ant-design-vue: ^4.2.6
|
||||||
archiver: ^7.0.1
|
archiver: ^7.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user