Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3eed51fd
authored
Oct 29, 2025
by
zhongming4762
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: increase support for multiple time zones
* 优化实现方法
1 parent
4d713db5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
18 deletions
apps/backend-mock/api/timezone/getTimezoneOptions.ts
apps/backend-mock/api/timezone/setTimezone.ts
apps/backend-mock/utils/mock-data.ts
packages/effects/layouts/src/widgets/timezone/timezone-button.vue
packages/stores/src/modules/timezone.ts
playground/src/api/core/timezone.ts
apps/backend-mock/api/timezone/getTimezoneOptions.ts
View file @
3eed51f
...
@@ -3,5 +3,9 @@ import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
...
@@ -3,5 +3,9 @@ import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
import
{
useResponseSuccess
}
from
'~/utils/response'
;
import
{
useResponseSuccess
}
from
'~/utils/response'
;
export
default
eventHandler
(()
=>
{
export
default
eventHandler
(()
=>
{
return
useResponseSuccess
(
TIME_ZONE_OPTIONS
);
const
data
=
TIME_ZONE_OPTIONS
.
map
((
o
)
=>
({
label
:
`
${
o
.
timezone
}
(GMT
${
o
.
offset
>=
0
?
`+
${
o
.
offset
}
`
:
o
.
offset
}
)`
,
value
:
o
.
timezone
,
}));
return
useResponseSuccess
(
data
);
});
});
apps/backend-mock/api/timezone/setTimezone.ts
View file @
3eed51f
import
{
eventHandler
,
readBody
}
from
'h3'
;
import
{
eventHandler
,
readBody
}
from
'h3'
;
import
{
verifyAccessToken
}
from
'~/utils/jwt-utils'
;
import
{
verifyAccessToken
}
from
'~/utils/jwt-utils'
;
import
{
TIME_ZONE_OPTIONS
}
from
'~/utils/mock-data'
;
import
{
unAuthorizedResponse
,
useResponseSuccess
}
from
'~/utils/response'
;
import
{
unAuthorizedResponse
,
useResponseSuccess
}
from
'~/utils/response'
;
import
{
setTimezone
}
from
'~/utils/timezone-utils'
;
import
{
setTimezone
}
from
'~/utils/timezone-utils'
;
...
@@ -8,7 +9,14 @@ export default eventHandler(async (event) => {
...
@@ -8,7 +9,14 @@ export default eventHandler(async (event) => {
if
(
!
userinfo
)
{
if
(
!
userinfo
)
{
return
unAuthorizedResponse
(
event
);
return
unAuthorizedResponse
(
event
);
}
}
const
{
timezone
}
=
await
readBody
(
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
);
setTimezone
(
timezone
);
return
useResponseSuccess
({});
return
useResponseSuccess
({});
});
});
apps/backend-mock/utils/mock-data.ts
View file @
3eed51f
...
@@ -9,7 +9,7 @@ export interface UserInfo {
...
@@ -9,7 +9,7 @@ export interface UserInfo {
export
interface
TimezoneOption
{
export
interface
TimezoneOption
{
offset
:
number
;
offset
:
number
;
time
Z
one
:
string
;
time
z
one
:
string
;
}
}
export
const
MOCK_USERS
:
UserInfo
[]
=
[
export
const
MOCK_USERS
:
UserInfo
[]
=
[
...
...
packages/effects/layouts/src/widgets/timezone/timezone-button.vue
View file @
3eed51f
...
@@ -30,8 +30,9 @@ const [Modal, modalApi] = useVbenModal({
...
@@ -30,8 +30,9 @@ const [Modal, modalApi] = useVbenModal({
onConfirm
:
async
()
=>
{
onConfirm
:
async
()
=>
{
try
{
try
{
modalApi
.
setState
({
confirmLoading
:
true
});
modalApi
.
setState
({
confirmLoading
:
true
});
if
(
timezoneRef
.
value
)
{
const
timezone
=
unref
(
timezoneRef
);
await
timezoneStore
.
setTimezone
(
unref
(
timezoneRef
));
if
(
timezone
)
{
await
timezoneStore
.
setTimezone
(
timezone
);
}
}
modalApi
.
close
();
modalApi
.
close
();
}
finally
{
}
finally
{
...
...
packages/stores/src/modules/timezone.ts
View file @
3eed51f
...
@@ -13,7 +13,7 @@ interface TimezoneHandler {
...
@@ -13,7 +13,7 @@ interface TimezoneHandler {
value
:
string
;
value
:
string
;
}[]
}[]
>
;
>
;
onTimezoneChang
e
?:
(
timezone
:
string
)
=>
Promise
<
void
>
;
setTimezon
e
?:
(
timezone
:
string
)
=>
Promise
<
void
>
;
}
}
/**
/**
...
@@ -63,13 +63,12 @@ const useTimezoneStore = defineStore(
...
@@ -63,13 +63,12 @@ const useTimezoneStore = defineStore(
getTimezone
()
||
new
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
,
getTimezone
()
||
new
Intl
.
DateTimeFormat
().
resolvedOptions
().
timeZone
,
);
);
const
timezoneHandler
=
getTimezoneHandler
();
/**
/**
* 初始化时区
* 初始化时区
* Initialize the timezone
* Initialize the timezone
*/
*/
async
function
initTimezone
()
{
async
function
initTimezone
()
{
const
timezoneHandler
=
getTimezoneHandler
();
const
timezone
=
await
timezoneHandler
.
getTimezone
?.();
const
timezone
=
await
timezoneHandler
.
getTimezone
?.();
if
(
timezone
)
{
if
(
timezone
)
{
timezoneRef
.
value
=
timezone
;
timezoneRef
.
value
=
timezone
;
...
@@ -84,7 +83,8 @@ const useTimezoneStore = defineStore(
...
@@ -84,7 +83,8 @@ const useTimezoneStore = defineStore(
* @param timezone 时区字符串
* @param timezone 时区字符串
*/
*/
async
function
setTimezone
(
timezone
:
string
)
{
async
function
setTimezone
(
timezone
:
string
)
{
await
timezoneHandler
.
onTimezoneChange
?.(
timezone
);
const
timezoneHandler
=
getTimezoneHandler
();
await
timezoneHandler
.
setTimezone
?.(
timezone
);
timezoneRef
.
value
=
timezone
;
timezoneRef
.
value
=
timezone
;
// 设置dayjs默认时区
// 设置dayjs默认时区
setDefaultTimezone
(
timezone
);
setDefaultTimezone
(
timezone
);
...
@@ -95,7 +95,8 @@ const useTimezoneStore = defineStore(
...
@@ -95,7 +95,8 @@ const useTimezoneStore = defineStore(
* Get the timezone options
* Get the timezone options
*/
*/
async
function
getTimezoneOptions
()
{
async
function
getTimezoneOptions
()
{
return
await
timezoneHandler
.
getTimezoneOptions
();
const
timezoneHandler
=
getTimezoneHandler
();
return
(
await
timezoneHandler
.
getTimezoneOptions
?.())
||
[];
}
}
initTimezone
().
catch
((
error
)
=>
{
initTimezone
().
catch
((
error
)
=>
{
...
...
playground/src/api/core/timezone.ts
View file @
3eed51f
...
@@ -6,14 +6,9 @@ import { requestClient } from '#/api/request';
...
@@ -6,14 +6,9 @@ import { requestClient } from '#/api/request';
* 获取系统支持的时区列表
* 获取系统支持的时区列表
*/
*/
export
async
function
getTimezoneOptionsApi
()
{
export
async
function
getTimezoneOptionsApi
()
{
const
dataList
=
return
await
requestClient
.
get
<
TimezoneOption
[]
>
(
(
await
requestClient
.
get
<
TimezoneOption
[]
>
(
'/timezone/getTimezoneOptions'
,
'/timezone/getTimezoneOptions'
,
))
||
[];
);
return
dataList
.
map
((
item
)
=>
({
label
:
item
.
timezone
,
value
:
item
.
timezone
,
}));
}
}
/**
/**
* 获取用户时区
* 获取用户时区
...
@@ -25,6 +20,6 @@ export async function getTimezoneApi(): Promise<null | string | undefined> {
...
@@ -25,6 +20,6 @@ export async function getTimezoneApi(): Promise<null | string | undefined> {
* 设置用户时区
* 设置用户时区
* @param timezone 时区
* @param timezone 时区
*/
*/
export
async
function
setTimezoneApi
(
timezone
:
string
)
{
export
async
function
setTimezoneApi
(
timezone
:
string
)
:
Promise
<
void
>
{
return
requestClient
.
post
(
'/timezone/setTimezone'
,
{
timezone
});
return
requestClient
.
post
(
'/timezone/setTimezone'
,
{
timezone
});
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment