feat: increase support for multiple time zones
This commit is contained in:
7
apps/backend-mock/api/profile/timezone.ts
Normal file
7
apps/backend-mock/api/profile/timezone.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { eventHandler } from 'h3';
|
||||
import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
|
||||
import { useResponseSuccess } from '~/utils/response';
|
||||
|
||||
export default eventHandler(() => {
|
||||
return useResponseSuccess(TIME_ZONE_OPTIONS);
|
||||
});
|
||||
14
apps/backend-mock/api/user/setTimezone.ts
Normal file
14
apps/backend-mock/api/user/setTimezone.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { eventHandler, readBody } from 'h3';
|
||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
||||
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 { timezone } = await readBody(event);
|
||||
setTimezone(timezone);
|
||||
return useResponseSuccess();
|
||||
});
|
||||
12
apps/backend-mock/api/user/timezone.ts
Normal file
12
apps/backend-mock/api/user/timezone.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());
|
||||
});
|
||||
@@ -7,6 +7,11 @@ export interface UserInfo {
|
||||
homePath?: string;
|
||||
}
|
||||
|
||||
export interface TimeZoneOption {
|
||||
offset: number;
|
||||
timeZone: string;
|
||||
}
|
||||
|
||||
export const MOCK_USERS: UserInfo[] = [
|
||||
{
|
||||
id: 0,
|
||||
@@ -388,3 +393,29 @@ export function getMenuIds(menus: any[]) {
|
||||
});
|
||||
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',
|
||||
},
|
||||
];
|
||||
|
||||
10
apps/backend-mock/utils/timezone-utils.ts
Normal file
10
apps/backend-mock/utils/timezone-utils.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
let mockTimeZone: null | string = null;
|
||||
|
||||
export const setTimezone = (timeZone: string) => {
|
||||
mockTimeZone = timeZone;
|
||||
};
|
||||
|
||||
export const getTimezone = () => {
|
||||
console.log('mockTimeZone', mockTimeZone);
|
||||
return mockTimeZone;
|
||||
};
|
||||
Reference in New Issue
Block a user