From 7a926b7086a2993c5465c5e6738414f790c3ba4e Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Tue, 5 Sep 2023 11:30:52 +0800 Subject: [PATCH] user timezone --- client/package.json | 1 + client/pnpm-lock.yaml | 9 +++ client/public/locales/en/common.json | 1 + client/public/locales/zh/common.json | 1 + client/src/components/ChatBox/index.tsx | 7 +- client/src/components/Language/index.tsx | 3 + client/src/components/Select/index.tsx | 4 +- client/src/constants/chat.ts | 4 - client/src/pages/account/components/Info.tsx | 37 +++++++-- client/src/pages/api/chat/chatTest.ts | 4 + .../pages/api/openapi/v1/chat/completions.ts | 20 ++++- client/src/pages/api/user/account/update.ts | 3 +- client/src/service/models/app.ts | 43 +--------- client/src/service/models/user.ts | 4 + client/src/service/utils/auth.ts | 7 +- client/src/types/mongoSchema.d.ts | 1 + client/src/types/user.d.ts | 2 + client/src/utils/user.ts | 80 +++++++++++++++++++ 18 files changed, 166 insertions(+), 65 deletions(-) diff --git a/client/package.json b/client/package.json index 6f0dea05f..2eafc6251 100644 --- a/client/package.json +++ b/client/package.json @@ -62,6 +62,7 @@ "remark-math": "^5.1.1", "request-ip": "^3.3.0", "sass": "^1.58.3", + "timezones-list": "^3.0.2", "tunnel": "^0.0.6", "winston": "^3.10.0", "winston-mongodb": "^5.1.1", diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index d1da0dc24..52bfc37b7 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -164,6 +164,9 @@ dependencies: sass: specifier: ^1.58.3 version: registry.npmmirror.com/sass@1.58.3 + timezones-list: + specifier: ^3.0.2 + version: registry.npmmirror.com/timezones-list@3.0.2 tunnel: specifier: ^0.0.6 version: registry.npmmirror.com/tunnel@0.0.6 @@ -11732,6 +11735,12 @@ packages: version: 0.2.0 dev: true + registry.npmmirror.com/timezones-list@3.0.2: + resolution: {integrity: sha512-I698hm6Jp/xxkwyTSOr39pZkYKETL8LDJeSIhjxXBfPUAHM5oZNuQ4o9UK3PSkDBOkjATecSOBb3pR1IkIBUsg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/timezones-list/-/timezones-list-3.0.2.tgz} + name: timezones-list + version: 3.0.2 + dev: false + registry.npmmirror.com/tiny-invariant@1.3.1: resolution: {integrity: sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/tiny-invariant/-/tiny-invariant-1.3.1.tgz} name: tiny-invariant diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 3889b959c..2c7d2d17a 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -184,6 +184,7 @@ "Sign Out": "Sign Out", "Source": "Source", "Time": "Time", + "Timezone": "Timezone", "Total Amount": "Total Amount", "Update Password": "Update Password", "Update password failed": "Update password failed", diff --git a/client/public/locales/zh/common.json b/client/public/locales/zh/common.json index e1ba315da..b1116d841 100644 --- a/client/public/locales/zh/common.json +++ b/client/public/locales/zh/common.json @@ -184,6 +184,7 @@ "Sign Out": "登出", "Source": "来源", "Time": "时间", + "Timezone": "时区", "Total Amount": "总金额", "Update Password": "修改密码", "Update password failed": "修改密码异常", diff --git a/client/src/components/ChatBox/index.tsx b/client/src/components/ChatBox/index.tsx index ac87df3cf..d7ecff366 100644 --- a/client/src/components/ChatBox/index.tsx +++ b/client/src/components/ChatBox/index.tsx @@ -37,7 +37,7 @@ import { fileDownload } from '@/utils/file'; import { htmlTemplate } from '@/constants/common'; import { useRouter } from 'next/router'; import { useGlobalStore } from '@/store/global'; -import { TaskResponseKeyEnum, getDefaultChatVariables } from '@/constants/chat'; +import { TaskResponseKeyEnum } from '@/constants/chat'; import { useTranslation } from 'react-i18next'; import { customAlphabet } from 'nanoid'; import { userUpdateChatFeedback, adminUpdateChatFeedback } from '@/api/chat'; @@ -350,10 +350,7 @@ const ChatBox = ( messages, controller: abortSignal, generatingMessage, - variables: { - ...getDefaultChatVariables(), - ...variables - } + variables }); // set finish status diff --git a/client/src/components/Language/index.tsx b/client/src/components/Language/index.tsx index 89217d7b1..d15d5b8a7 100644 --- a/client/src/components/Language/index.tsx +++ b/client/src/components/Language/index.tsx @@ -3,6 +3,7 @@ import { Menu, MenuButton, MenuItem, MenuList, MenuButtonProps } from '@chakra-u import { getLangStore, LangEnum, setLangStore } from '@/utils/i18n'; import MyIcon from '@/components/Icon'; import { useTranslation } from 'react-i18next'; +import { useRouter } from 'next/router'; const langMap = { [LangEnum.en]: { @@ -16,6 +17,7 @@ const langMap = { }; const Language = (props: MenuButtonProps) => { + const router = useRouter(); const { i18n } = useTranslation(); const [language, setLanguage] = useState<`${LangEnum}`>(getLangStore()); @@ -43,6 +45,7 @@ const Language = (props: MenuButtonProps) => { setLangStore(lang); setLanguage(lang); i18n?.changeLanguage?.(lang); + router.reload(); }} > {lang.label} diff --git a/client/src/components/Select/index.tsx b/client/src/components/Select/index.tsx index 7b1e303da..0008d780b 100644 --- a/client/src/components/Select/index.tsx +++ b/client/src/components/Select/index.tsx @@ -21,7 +21,7 @@ interface Props extends ButtonProps { } const MySelect = ( - { placeholder, value, width = 'auto', list, onchange, ...props }: Props, + { placeholder, value, width = '100%', list, onchange, ...props }: Props, selectRef: any ) => { const ref = useRef(null); @@ -94,6 +94,8 @@ const MySelect = ( } zIndex={99} transform={'translateY(35px) !important'} + maxH={'40vh'} + overflowY={'auto'} > {list.map((item) => ( ({ - cTime: dayjs().format('YYYY/MM/DD HH:mm:ss') -}); diff --git a/client/src/pages/account/components/Info.tsx b/client/src/pages/account/components/Info.tsx index a6b911737..7ec75d942 100644 --- a/client/src/pages/account/components/Info.tsx +++ b/client/src/pages/account/components/Info.tsx @@ -1,5 +1,5 @@ -import React, { useCallback } from 'react'; -import { Box, Flex, Button, useDisclosure, useTheme, Divider } from '@chakra-ui/react'; +import React, { useCallback, useRef } from 'react'; +import { Box, Flex, Button, useDisclosure, useTheme, Divider, Select } from '@chakra-ui/react'; import { useForm } from 'react-hook-form'; import { UserUpdateParams } from '@/types/user'; import { useToast } from '@/hooks/useToast'; @@ -11,6 +11,7 @@ import { useSelectFile } from '@/hooks/useSelectFile'; import { compressImg } from '@/utils/file'; import { feConfigs } from '@/store/static'; import { useTranslation } from 'next-i18next'; +import { timezoneList } from '@/utils/user'; import Loading from '@/components/Loading'; import Avatar from '@/components/Avatar'; import MyIcon from '@/components/Icon'; @@ -33,6 +34,7 @@ const UserInfo = () => { const theme = useTheme(); const { t } = useTranslation(); const { userInfo, updateUserInfo, initUserInfo } = useUserStore(); + const timezones = useRef(timezoneList()); const { reset } = useForm({ defaultValues: userInfo as UserType }); @@ -59,6 +61,7 @@ const UserInfo = () => { async (data: UserType) => { await updateUserInfo({ avatar: data.avatar, + timezone: data.timezone, openaiAccount: data.openaiAccount }); reset(data); @@ -102,7 +105,13 @@ const UserInfo = () => { }); return ( - + { mt={[6, 0]} > - {t('user.Account')}:  + {t('user.Account')}:  {userInfo?.username} - {t('user.Password')}:  + {t('user.Timezone')}:  + + + + {t('user.Password')}:  *****