Merge branch 'fork/ming4762/timezone-20251020'

This commit is contained in:
Jin Mao
2025-10-30 00:42:05 +08:00
24 changed files with 444 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
export * from './auth';
export * from './menu';
export * from './timezone';
export * from './user';

View 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 });
}

View File

@@ -15,6 +15,7 @@ import { router } from '#/router';
import { initComponentAdapter } from './adapter/component';
import { initSetupVbenForm } from './adapter/form';
import App from './app.vue';
import { initTimezone } from './timezone-init';
async function bootstrap(namespace: string) {
// 初始化组件适配器
@@ -46,6 +47,9 @@ async function bootstrap(namespace: string) {
// 配置 pinia-tore
await initStores(app, { namespace });
// 初始化时区HANDLER
initTimezone();
// 安装权限指令
registerAccessDirective(app);

View 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();
},
});
}