Skip to content

Commit

Permalink
feat:desktop support theme (labring#3800)
Browse files Browse the repository at this point in the history
* feat:desktop support theme

Signed-off-by: jingyang <[email protected]>

* fix

---------

Signed-off-by: jingyang <[email protected]>
  • Loading branch information
zjy365 committed Aug 30, 2023
1 parent 7336729 commit a6f44ed
Show file tree
Hide file tree
Showing 25 changed files with 1,040 additions and 813 deletions.
2 changes: 1 addition & 1 deletion frontend/READMD.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo '121.41.82.246 apiserver.cluster.local' | sudo tee -a /etc/hosts

- It is best to use `sealos/frontend` as the workspace directory to develop applications.
- Before dev, you should install `pnpm` first. [pnpm](https://pnpm.io/zh/)
- The `sealos/frontend/packages/*` are local dependencies, you need run `pnpm -r --filter=./packages/* run build` in the `sealos/frontend` directory tobuild them.
- The `sealos/frontend/packages/*` are local dependencies, you need run `pnpm -r --filter ./packages/* run build` in the `sealos/frontend` directory tobuild them.
- The `sealos/frontend/providers/*` are sub applications..
- The `sealos/frontend/desktop` is desktop app.

Expand Down
3 changes: 2 additions & 1 deletion frontend/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"sass": "^1.63.6",
"sealos-desktop-sdk": "workspace:*",
"uuid": "^9.0.0",
"zustand": "^4.3.9"
"zustand": "^4.3.9",
"react-hook-form": "^7.45.2"
},
"devDependencies": {
"@types/js-cookie": "^3.0.3",
Expand Down
31 changes: 16 additions & 15 deletions frontend/desktop/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,38 @@
"Username": "Username",
"Log Out": "Log Out",
"Log In": "Log In",
"Password Login":"with Password",
"Verification Code Login":"with Phone",
"Password Login": "with Password",
"Verification Code Login": "with Phone",
"Loading": "Loading",
"From": "From",
"Balance": "Balance",
"password tips": "Password must be 8 characters or more",
"username tips":"Username must be 3-16 characters, including letters, numbers",
"username tips": "Username must be 3-16 characters, including letters, numbers",
"Password": "Password",
"Verify password": "Verify password",
"verify code tips":"6-digit Verification Code",
"phone number tips":"Phone Number",
"verify code tips": "6-digit Verification Code",
"phone number tips": "Phone Number",
"Invalid phone number": "Invalid phone number",
"Invalid username or password": "Invalid username or password",
"Invalid verification code":"Invalid verification code",
"Get code failed":"Get code failed",
"Read and agree":"Please read and agree to the agreement below",
"agree policy":"I have read and agree to the",
"Service Agreement":"Service Agreement",
"and":"and",
"Privacy Policy":"Privacy Policy",
"Get Code":"verification",
"Invalid verification code": "Invalid verification code",
"Get code failed": "Get code failed",
"Read and agree": "Please read and agree to the agreement below",
"agree policy": "I have read and agree to the",
"Service Agreement": "Service Agreement",
"and": "and",
"Privacy Policy": "Privacy Policy",
"Get Code": "verification",
"Total Amount": "Total Amount",
"Payment Result": "Payment Result",
"Payment Successful": "Payment Successful",
"In Payment": "In Payment ...",
"Bonus": "Bonus",
"Select Amount": "Select Amount",
"View Discount Rules":"View recharge discount rules.",
"View Discount Rules": "View recharge discount rules.",
"Payment Status": "Payment Status",
"Scan with WeChat": "Scan with WeChat",
"Charge": "Charge",
"Order Number": "Order Number",
"Confirm": "Confirm"
"Confirm": "Confirm",
"Login to your account": "Login to your account"
}
37 changes: 19 additions & 18 deletions frontend/desktop/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@
"Unread": "未读",
"Read All": "全部已读",
"Username": "用户名",
"Password Login":"密码登录",
"Verification Code Login":"手机号登录",
"Password":"密码",
"Password Login": "密码登录",
"Verification Code Login": "手机号登录",
"Password": "密码",
"Log In": "登录",
"Loading": "加载中",
"Log Out": "退出账号",
"From": "来自",
"Balance": "余额",
"verify code tips":"6位验证码",
"phone number tips":"手机号码",
"verify code tips": "6位验证码",
"phone number tips": "手机号码",
"password tips": "密码为8位以上字符",
"username tips":"用户名为3-16位的英文或数字的字符",
"username tips": "用户名为3-16位的英文或数字的字符",
"Verify password": "确认密码",
"Invalid username or password": "用户名或密码错误",
"Invalid phone number":"无效的手机号码",
"Invalid verification code":"无效的验证码",
"Get code failed":"获取验证码失败",
"Read and agree":"请阅读并同意下方协议",
"agree policy":"我已阅读并同意",
"and":"",
"Service Agreement":"服务协议",
"Privacy Policy":"隐私政策",
"Get Code":"获取验证码",
"Bonus":"",
"Invalid phone number": "无效的手机号码",
"Invalid verification code": "无效的验证码",
"Get code failed": "获取验证码失败",
"Read and agree": "请阅读并同意下方协议",
"agree policy": "我已阅读并同意",
"and": "",
"Service Agreement": "服务协议",
"Privacy Policy": "隐私政策",
"Get Code": "获取验证码",
"Bonus": "",
"Payment Result": "支付结果",
"Payment Successful": "支付成功",
"In Payment": "支付中 ...",
"Recharge Amount": "充值金额",
"Select Amount": "选择金额",
"View Discount Rules":"查看优惠规则",
"View Discount Rules": "查看优惠规则",
"Payment Status": "支付状态",
"Scan with WeChat": "微信扫码支付",
"Charge": "充值",
"Order Number": "订单号",
"Confirm": "确认"
"Confirm": "确认",
"Login to your account": "登录您的帐户"
}
8 changes: 7 additions & 1 deletion frontend/desktop/src/components/desktop_content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ export default function DesktopContent(props: any) {
}, [openDesktopApp]);

return (
<Box id="desktop" className={styles.desktop}>
<Box
id="desktop"
className={styles.desktop}
backgroundImage={'url(/images/background.svg)'}
backgroundRepeat={'no-repeat'}
backgroundSize={'cover'}
>
<Flex w="100%" h="100%" alignItems={'center'} flexDirection={'column'}>
<Box mt="12vh" minW={'508px'}>
<TimeComponent />
Expand Down
24 changes: 0 additions & 24 deletions frontend/desktop/src/components/layout/index.tsx

This file was deleted.

73 changes: 73 additions & 0 deletions frontend/desktop/src/components/signin/auth/useAuthList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import useSessionStore from '@/stores/session';
import { Button, Flex, Image } from '@chakra-ui/react';
import { MouseEventHandler } from 'react';

type useAuthListProps = {
needGithub: boolean;
needWechat: boolean;
wechat_client_id: string;
github_client_id: string;
callback_url: string;
};

const useAuthList = ({
needGithub,
needWechat,
wechat_client_id,
github_client_id,
callback_url
}: useAuthListProps) => {
const { generateState, setProvider } = useSessionStore();

const oauthLogin = async ({ url, provider }: { url: string; provider?: 'github' | 'wechat' }) => {
setProvider(provider);
window.location.href = url;
};

const authList: { src: string; cb: MouseEventHandler; need: boolean }[] = [
{
src: '/images/github.svg',
cb: (e) => {
e.preventDefault();
const state = generateState();
oauthLogin({
provider: 'github',
url: `https://github.com/login/oauth/authorize?client_id=${github_client_id}&redirect_uri=${callback_url}&scope=user:email%20read:user&state=${state}`
});
},
need: needGithub
},
{
src: '/images/wechat.svg',
cb: (e) => {
e.preventDefault();
const state = generateState();
oauthLogin({
provider: 'wechat',
url: `https://open.weixin.qq.com/connect/qrconnect?appid=${wechat_client_id}&redirect_uri=${callback_url}&response_type=code&state=${state}&scope=snsapi_login&#wechat_redirect`
});
},
need: needWechat
}
];

const AuthList = () => {
return (
<Flex gap={'14px'}>
{authList
.filter((item) => item.need)
.map((item, index) => (
<Button key={index} onClick={item.cb} borderRadius={'full'} variant={'unstyled'}>
<Image src={item.src} borderRadius={'full'} alt={item.src}></Image>
</Button>
))}
</Flex>
);
};

return {
AuthList
};
};

export default useAuthList;
62 changes: 62 additions & 0 deletions frontend/desktop/src/components/signin/auth/useCustomError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Flex, Img, Button, Text } from '@chakra-ui/react';
import React, { useState, useEffect } from 'react';
import warnIcon from 'public/icons/warning.svg';
import closeIcon from 'public/icons/close_white.svg';
import { useTranslation } from 'next-i18next';

const useCustomError = () => {
const { t } = useTranslation();
const [error, setError] = useState('');

const showError = (errorMessage: string, duration = 5000) => {
setError(errorMessage);
setTimeout(() => {
setError('');
}, duration);
};

const closeError = () => {
setError('');
};

const ErrorComponent = () => {
useEffect(() => {
if (error) {
const timeout = setTimeout(() => {
closeError();
}, 5000); // 默认 5000 毫秒(5秒)后自动关闭错误消息
return () => clearTimeout(timeout);
}
}, [error]);

return error ? (
<Flex
position={'absolute'}
top="0"
bg={'rgba(249, 78, 97, 1)'}
transform={'translateY(-50%)'}
width="266px"
minH="42px"
mb="14px"
borderRadius="4px"
p="10px"
>
<Img src={warnIcon.src} mr={'8px'} />
<Text color={'#fff'}>{t(error)}</Text>
<Button
variant={'unstyled'}
ml={'auto'}
display={'flex'}
justifyContent={'flex-end'}
onClick={closeError}
>
<Img src={closeIcon.src} />
</Button>
</Flex>
) : null;
};

return { showError, ErrorComponent };
};

export default useCustomError;
34 changes: 34 additions & 0 deletions frontend/desktop/src/components/signin/auth/useLanguage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import LangSelect from '@/components/LangSelect';
import { Box, Flex, UseDisclosureReturn } from '@chakra-ui/react';
import { I18n } from 'next-i18next';

type LanguageType = { disclosure: UseDisclosureReturn; i18n: I18n | null };

const Language = ({ disclosure, i18n }: LanguageType) => {
return (
<Flex
alignItems={'center'}
position={'absolute'}
top={'42px'}
right={'42px'}
cursor={'pointer'}
gap={'16px'}
>
<Flex
w="36px"
h="36px"
borderRadius={'50%'}
background={'rgba(244, 246, 248, 0.7)'}
justifyContent={'center'}
alignItems={'center'}
position={'relative'}
boxShadow={'0px 1.2px 2.3px rgba(0, 0, 0, 0.2)'}
>
<Box onClick={() => disclosure.onOpen()}>{i18n?.language === 'en' ? 'en' : '中'}</Box>
<LangSelect disclosure={disclosure} i18n={i18n} />
</Flex>
</Flex>
);
};

export default Language;
Loading

0 comments on commit a6f44ed

Please sign in to comment.