From a5e8bef596ae9966be23cab45831c012d9ac1754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=A3=8A?= <17600116464@163.com> Date: Wed, 26 Feb 2025 01:53:00 -0500 Subject: [PATCH] =?UTF-8?q?fix(other):=20=E6=96=B0=E5=A2=9E=E4=BC=81?= =?UTF-8?q?=E4=B8=9A=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E6=8E=A5=E5=90=8E=E7=AB=AFFastAPI=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- .env.test | 3 +- package.json | 1 + pnpm-lock.yaml | 8 ++ src/assets/svg-icon/gitee.svg | 1 + src/assets/svg-icon/wechat.svg | 1 + src/assets/svg-icon/wecom.svg | 1 + src/locales/langs/en-us.ts | 7 +- src/locales/langs/zh-cn.ts | 7 +- src/service/api/auth.ts | 8 ++ src/typings/api.d.ts | 8 ++ src/typings/app.d.ts | 5 + src/typings/components.d.ts | 3 + .../_builtin/login/modules/pwd-login.vue | 69 +++++++------- .../_builtin/login/modules/wecom-login.vue | 93 +++++++++++++++++++ 15 files changed, 180 insertions(+), 37 deletions(-) create mode 100644 src/assets/svg-icon/gitee.svg create mode 100644 src/assets/svg-icon/wechat.svg create mode 100644 src/assets/svg-icon/wecom.svg create mode 100644 src/views/_builtin/login/modules/wecom-login.vue diff --git a/.env b/.env index d2d7f54c..0910581f 100644 --- a/.env +++ b/.env @@ -29,7 +29,7 @@ VITE_HTTP_PROXY=Y VITE_ROUTER_HISTORY_MODE=history # success code of backend service, when the code is received, the request is successful -VITE_SERVICE_SUCCESS_CODE=0000 +VITE_SERVICE_SUCCESS_CODE=200 # logout codes of backend service, when the code is received, the user will be logged out and redirected to login page VITE_SERVICE_LOGOUT_CODES=8888,8889 diff --git a/.env.test b/.env.test index dd18d7bb..f5bcaf12 100644 --- a/.env.test +++ b/.env.test @@ -1,5 +1,6 @@ # backend service base url, test environment -VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default +# VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default +VITE_SERVICE_BASE_URL=http://172.21.10.20:8000/api/v1 # other backend service base url, test environment VITE_OTHER_SERVICE_BASE_URL= `{ diff --git a/package.json b/package.json index 1d763e49..b5bc1f0e 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@sa/materials": "workspace:*", "@sa/utils": "workspace:*", "@vueuse/core": "12.5.0", + "@wecom/jssdk": "^2.2.5", "clipboard": "2.0.11", "dayjs": "1.11.13", "defu": "6.1.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7fa39712..10793df9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ importers: '@vueuse/core': specifier: 12.5.0 version: 12.5.0(typescript@5.7.3) + '@wecom/jssdk': + specifier: ^2.2.5 + version: 2.2.5 clipboard: specifier: 2.0.11 version: 2.0.11 @@ -1466,6 +1469,9 @@ packages: '@vueuse/shared@12.5.0': resolution: {integrity: sha512-vMpcL1lStUU6O+kdj6YdHDixh0odjPAUM15uJ9f7MY781jcYkIwFA4iv2EfoIPO6vBmvutI1HxxAwmf0cx5ISQ==} + '@wecom/jssdk@2.2.5': + resolution: {integrity: sha512-qOBAsfqaiYM8jZHWYs/atHSpJhsLdZVNaxHQdmEQ7ZWul/GZMt4P5VY8Nf7GII7GhG8z/k+r37Dto6qtAaRqow==} + acorn-jsx@5.3.2: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -5618,6 +5624,8 @@ snapshots: transitivePeerDependencies: - typescript + '@wecom/jssdk@2.2.5': {} + acorn-jsx@5.3.2(acorn@8.14.0): dependencies: acorn: 8.14.0 diff --git a/src/assets/svg-icon/gitee.svg b/src/assets/svg-icon/gitee.svg new file mode 100644 index 00000000..c39ce29e --- /dev/null +++ b/src/assets/svg-icon/gitee.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icon/wechat.svg b/src/assets/svg-icon/wechat.svg new file mode 100644 index 00000000..95d8b5d4 --- /dev/null +++ b/src/assets/svg-icon/wechat.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icon/wecom.svg b/src/assets/svg-icon/wecom.svg new file mode 100644 index 00000000..5cc6d2d8 --- /dev/null +++ b/src/assets/svg-icon/wecom.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/locales/langs/en-us.ts b/src/locales/langs/en-us.ts index c3ae71c7..496d7fb9 100644 --- a/src/locales/langs/en-us.ts +++ b/src/locales/langs/en-us.ts @@ -178,7 +178,8 @@ const local: App.I18n.Schema = { back: 'Back', validateSuccess: 'Verification passed', loginSuccess: 'Login successfully', - welcomeBack: 'Welcome back, {userName} !' + welcomeBack: 'Welcome back, {userName} !', + infoWarning: 'The current feature has not been implemented yet.' }, pwdLogin: { title: 'Password Login', @@ -209,6 +210,10 @@ const local: App.I18n.Schema = { }, bindWeChat: { title: 'Bind WeChat' + }, + weComLogin: { + title: 'WeCom Login', + wecomOauth: 'WeCom OAuth Login' } }, home: { diff --git a/src/locales/langs/zh-cn.ts b/src/locales/langs/zh-cn.ts index 32c14ceb..25eb6ee2 100644 --- a/src/locales/langs/zh-cn.ts +++ b/src/locales/langs/zh-cn.ts @@ -178,7 +178,8 @@ const local: App.I18n.Schema = { back: '返回', validateSuccess: '验证成功', loginSuccess: '登录成功', - welcomeBack: '欢迎回来,{userName} !' + welcomeBack: '欢迎回来,{userName} !', + infoWarning: '当前功能尚未实现!' }, pwdLogin: { title: '密码登录', @@ -209,6 +210,10 @@ const local: App.I18n.Schema = { }, bindWeChat: { title: '绑定微信' + }, + weComLogin: { + title: '企业微信登录', + wecomOauth: '企业微信单点登录' } }, home: { diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index 1ffcf2bf..0fa25731 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -1,5 +1,13 @@ import { request } from '../request'; +/** 获取企业微信手机及Webview的URL链接 */ +export function fetchGetWecomUrl(info: boolean) { + if (info) { + return request({ url: '/getWecomUrl', params: { info } }); + } + return request({ url: '/getWecomUrl' }); +} + /** * Login * diff --git a/src/typings/api.d.ts b/src/typings/api.d.ts index 5a8e2552..e7f70480 100644 --- a/src/typings/api.d.ts +++ b/src/typings/api.d.ts @@ -65,6 +65,14 @@ declare namespace Api { roles: string[]; buttons: string[]; } + + interface WecomInfo { + appid: string; + agent_id: string; + redirect_uri: string; + state: string; + session_id?: string; + } } /** diff --git a/src/typings/app.d.ts b/src/typings/app.d.ts index cdfde34c..71b279cf 100644 --- a/src/typings/app.d.ts +++ b/src/typings/app.d.ts @@ -422,6 +422,7 @@ declare namespace App { validateSuccess: string; loginSuccess: string; welcomeBack: string; + infoWarning: string; }; pwdLogin: { title: string; @@ -453,6 +454,10 @@ declare namespace App { bindWeChat: { title: string; }; + weComLogin: { + title: string; + wecomOauth: string; + }; }; home: { branchDesc: string; diff --git a/src/typings/components.d.ts b/src/typings/components.d.ts index 1b0ebf02..e43c8f33 100644 --- a/src/typings/components.d.ts +++ b/src/typings/components.d.ts @@ -26,7 +26,10 @@ declare module 'vue' { IconIcRoundRemove: typeof import('~icons/ic/round-remove')['default'] IconIcRoundSearch: typeof import('~icons/ic/round-search')['default'] IconLocalBanner: typeof import('~icons/local/banner')['default'] + IconLocalGitee: typeof import('~icons/local/gitee')['default'] IconLocalLogo: typeof import('~icons/local/logo')['default'] + IconLocalWechat: typeof import('~icons/local/wechat')['default'] + IconLocalWecom: typeof import('~icons/local/wecom')['default'] IconMdiArrowDownThin: typeof import('~icons/mdi/arrow-down-thin')['default'] IconMdiArrowUpThin: typeof import('~icons/mdi/arrow-up-thin')['default'] IconMdiDrag: typeof import('~icons/mdi/drag')['default'] diff --git a/src/views/_builtin/login/modules/pwd-login.vue b/src/views/_builtin/login/modules/pwd-login.vue index e968560b..b2b16b1e 100644 --- a/src/views/_builtin/login/modules/pwd-login.vue +++ b/src/views/_builtin/login/modules/pwd-login.vue @@ -5,11 +5,14 @@ import { loginModuleRecord } from '@/constants/app'; import { useRouterPush } from '@/hooks/common/router'; import { useFormRules, useNaiveForm } from '@/hooks/common/form'; import { useAuthStore } from '@/store/modules/auth'; +import { useAppStore } from '@/store/modules/app'; +import { fetchGetWecomUrl } from '@/service/api'; defineOptions({ name: 'PwdLogin' }); +const appStore = useAppStore(); const authStore = useAuthStore(); const { toggleLoginModule } = useRouterPush(); const { formRef, validate } = useNaiveForm(); @@ -39,39 +42,26 @@ async function handleSubmit() { await authStore.login(model.userName, model.password); } -type AccountKey = 'super' | 'admin' | 'user'; - -interface Account { - key: AccountKey; - label: string; - userName: string; - password: string; -} - -const accounts = computed(() => [ - { - key: 'super', - label: $t('page.login.pwdLogin.superAdmin'), - userName: 'Super', - password: '123456' - }, - { - key: 'admin', - label: $t('page.login.pwdLogin.admin'), - userName: 'Admin', - password: '123456' - }, - { - key: 'user', - label: $t('page.login.pwdLogin.user'), - userName: 'User', - password: '123456' +async function getWecomInfo(info = false) { + // 调用后端接口获取企业微信相关信息 + const { data: url, error } = await fetchGetWecomUrl(info); + if (!error) { + // 跳转到企业微信授权页面 + window.location.href = url; } -]); - -async function handleAccountLogin(account: Account) { - await authStore.login(account.userName, account.password); } + +// 判断是否是手机和企业微信Webview的方法 +const isMobileAndWecom = computed(() => { + const userAgent = navigator.userAgent; + const isWecom = /wxwork/i.test(userAgent); + return !appStore.isMobile && !isWecom; +}); + +// 未实现功能告警 +const handleFailed = () => { + window.$message?.warning($t('page.login.common.infoWarning')); +};