Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: add getUserAgentType function

shuai3def6cabd800
diff --git a/ui/src/common/pattern.ts b/ui/src/common/pattern.ts
index 406e5e3e..8d4a239f 100644
--- a/ui/src/common/pattern.ts
+++ b/ui/src/common/pattern.ts
@@ -1,6 +1,9 @@
const pattern = {
email:
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
+ wx: /micromessenger/,
+ wxwork: /wxwork/,
+ dingtalk: /dingtalk/,
};
export default pattern;
diff --git a/ui/src/plugins/PluginUcLogin/WeCom.tsx b/ui/src/plugins/PluginUcLogin/WeCom.tsx
index 7e0af23c..f08c0134 100644
--- a/ui/src/plugins/PluginUcLogin/WeCom.tsx
+++ b/ui/src/plugins/PluginUcLogin/WeCom.tsx
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import QrCode from 'qrcode';
import { userCenterStore } from '@/stores';
-import { guard } from '@/utils';
+import { guard, getUserAgentType } from '@/utils';
import { getLoginConf, checkLoginResult } from './wecom.service';
@@ -47,7 +47,11 @@ const Index: FC = () => {
return;
}
getLoginConf().then((res) => {
- handleQrCode(res?.redirect_url);
+ if (getUserAgentType() === 'wxwork') {
+ window.location.replace(res?.redirect_url);
+ } else {
+ handleQrCode(res?.redirect_url);
+ }
handleLoginResult(res?.key);
});
}, [agentName]);
@@ -56,7 +60,7 @@ const Index: FC = () => {
clearTimeout(checkTimer);
};
}, []);
- if (/WeCom/i.test(agentName)) {
+ if (/WeCom/i.test(agentName) && getUserAgentType() !== 'wxwork') {
return (
<Card className="text-center">
<Card.Body>
diff --git a/ui/src/plugins/PluginUcLogin/index.tsx b/ui/src/plugins/PluginUcLogin/index.tsx
index e7d78add..6e34a008 100644
--- a/ui/src/plugins/PluginUcLogin/index.tsx
+++ b/ui/src/plugins/PluginUcLogin/index.tsx
@@ -1,4 +1,4 @@
-import React, { memo, FC } from 'react';
+import { memo, FC } from 'react';
import { Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts
index c9cb3267..1773b21b 100644
--- a/ui/src/utils/common.ts
+++ b/ui/src/utils/common.ts
@@ -1,5 +1,7 @@
import i18next from 'i18next';
+import pattern from '@/common/pattern';
+
const Diff = require('diff');
function thousandthDivision(num) {
@@ -254,6 +256,23 @@ function base64ToSvg(base64: string) {
return str;
}
+// Determine whether the user is in WeChat or Enterprise WeChat or DingTalk, and return the corresponding type
+
+function getUserAgentType() {
+ const ua = navigator.userAgent.toLowerCase();
+ if (pattern.wxwork.test(ua)) {
+ return 'wxwork';
+ }
+ // if (pattern.wx.test(ua)) {
+ // return 'weixin';
+ // }
+
+ // if (pattern.dingtalk.test(ua)) {
+ // return 'dingtalk';
+ // }
+ return null;
+}
+
export {
thousandthDivision,
formatCount,
@@ -270,4 +289,5 @@ export {
handleFormError,
diffText,
base64ToSvg,
+ getUserAgentType,
};