feat: 微信自动关闭功能
This commit is contained in:
parent
2b7c7a8642
commit
96f75907d4
@ -31,8 +31,8 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "types/index.d.ts",
|
"types": "types/index.d.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kevisual/code-center-module": "^0.0.7-alpha.2",
|
"@kevisual/code-center-module": "^0.0.11-alpha.1",
|
||||||
"@kevisual/router": "^0.0.7",
|
"@kevisual/router": "^0.0.8-alpha.1",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"formidable": "^3.5.2",
|
"formidable": "^3.5.2",
|
||||||
"ioredis": "^5.5.0",
|
"ioredis": "^5.5.0",
|
||||||
@ -45,7 +45,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kevisual/types": "^0.0.6",
|
"@kevisual/types": "^0.0.6",
|
||||||
"@kevisual/use-config": "^1.0.8",
|
"@kevisual/use-config": "^1.0.9",
|
||||||
"@rollup/plugin-alias": "^5.1.1",
|
"@rollup/plugin-alias": "^5.1.1",
|
||||||
"@rollup/plugin-commonjs": "^28.0.2",
|
"@rollup/plugin-commonjs": "^28.0.2",
|
||||||
"@rollup/plugin-json": "^6.1.0",
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
@ -55,20 +55,20 @@
|
|||||||
"@types/crypto-js": "^4.2.2",
|
"@types/crypto-js": "^4.2.2",
|
||||||
"@types/formidable": "^3.4.5",
|
"@types/formidable": "^3.4.5",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^22.13.5",
|
"@types/node": "^22.13.8",
|
||||||
"@types/xml2js": "^0.4.14",
|
"@types/xml2js": "^0.4.14",
|
||||||
"concurrently": "^9.1.2",
|
"concurrently": "^9.1.2",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"nodemon": "^3.1.9",
|
"nodemon": "^3.1.9",
|
||||||
"pm2": "^5.4.3",
|
"pm2": "^5.4.3",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"rollup": "^4.34.8",
|
"rollup": "^4.34.9",
|
||||||
"rollup-plugin-copy": "^3.5.0",
|
"rollup-plugin-copy": "^3.5.0",
|
||||||
"rollup-plugin-dts": "^6.1.1",
|
"rollup-plugin-dts": "^6.1.1",
|
||||||
"rollup-plugin-esbuild": "^6.2.1",
|
"rollup-plugin-esbuild": "^6.2.1",
|
||||||
"tape": "^5.9.0",
|
"tape": "^5.9.0",
|
||||||
"tsx": "^4.19.3",
|
"tsx": "^4.19.3",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.8.2"
|
||||||
},
|
},
|
||||||
"pnpm": {}
|
"pnpm": {}
|
||||||
}
|
}
|
@ -5,7 +5,7 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1, user-scalable=no">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1, user-scalable=no">
|
||||||
<title>登录中转</title>
|
<title>登录</title>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@ -40,6 +40,7 @@
|
|||||||
<div class="loading">Loading Code...</div>
|
<div class="loading">Loading Code...</div>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { loginSuccessUrl } from './config.js';
|
import { loginSuccessUrl } from './config.js';
|
||||||
|
import { closePage } from './is-wechat.js';
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const state = url.searchParams.get('state');
|
const state = url.searchParams.get('state');
|
||||||
const code = url.searchParams.get('code');
|
const code = url.searchParams.get('code');
|
||||||
@ -51,18 +52,13 @@
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
alert('登录失败,请稍后再试');
|
alert('登录失败,请稍后再试');
|
||||||
document.body.append('登录失败,请稍后再试');
|
document.body.append('登录失败,请稍后再试');
|
||||||
setTimeout(() => {
|
closePage();
|
||||||
window.close();
|
|
||||||
}, 2000);
|
|
||||||
});
|
});
|
||||||
// document.body.append(JSON.stringify(res, null, 2));
|
// document.body.append(JSON.stringify(res, null, 2));
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
localStorage.setItem('token', res.data.token);
|
localStorage.setItem('token', res.data.token);
|
||||||
window.close()
|
|
||||||
setTimeout(() => {
|
|
||||||
window.open(loginSuccessUrl, '_blank');
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
closePage();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -6,4 +6,4 @@ export const config = {
|
|||||||
|
|
||||||
export const loginUrl = `https://kevisual.xiongxiao.me/root/mini-web/login.html`;
|
export const loginUrl = `https://kevisual.xiongxiao.me/root/mini-web/login.html`;
|
||||||
|
|
||||||
export const loginSuccessUrl = `/ai/chat/`;
|
export const loginSuccessUrl = `/apps/wallnote/`;
|
||||||
|
22
mini-web/envision/is-wechat.js
Normal file
22
mini-web/envision/is-wechat.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
export const isWechat = () => {
|
||||||
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
|
return /micromessenger/i.test(ua);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const closePage = (time = 2000) => {
|
||||||
|
if (!isWechat()) {
|
||||||
|
setTimeout(() => {
|
||||||
|
window.close();
|
||||||
|
}, time);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (window.WeixinJSBridge) {
|
||||||
|
setTimeout(() => {
|
||||||
|
window.WeixinJSBridge.call('closeWindow');
|
||||||
|
}, time);
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
window.close();
|
||||||
|
}, time);
|
||||||
|
}
|
||||||
|
};
|
@ -32,6 +32,7 @@
|
|||||||
<div class="loading">Loading...</div>
|
<div class="loading">Loading...</div>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { config } from './config.js'
|
import { config } from './config.js'
|
||||||
|
import { closePage } from './is-wechat.js'
|
||||||
const demo = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect`
|
const demo = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect`
|
||||||
const appid = config.appid
|
const appid = config.appid
|
||||||
const redirect_uri = encodeURIComponent(config.redirect_uri)
|
const redirect_uri = encodeURIComponent(config.redirect_uri)
|
||||||
@ -40,9 +41,7 @@
|
|||||||
const state = url.searchParams.get('state')
|
const state = url.searchParams.get('state')
|
||||||
if (!state) {
|
if (!state) {
|
||||||
alert('Invalid state. Please try again later.');
|
alert('Invalid state. Please try again later.');
|
||||||
setTimeout(() => {
|
closePage();
|
||||||
window.close();
|
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
const link = demo.replace('APPID', appid).replace('REDIRECT_URI', redirect_uri).replace('SCOPE', scope).replace('STATE', state);
|
const link = demo.replace('APPID', appid).replace('REDIRECT_URI', redirect_uri).replace('SCOPE', scope).replace('STATE', state);
|
||||||
window.location.href = link
|
window.location.href = link
|
||||||
@ -50,9 +49,7 @@
|
|||||||
// Add a timeout for loading
|
// Add a timeout for loading
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
alert('Loading timeout. Please try again later.');
|
alert('Loading timeout. Please try again later.');
|
||||||
setTimeout(() => {
|
closePage()
|
||||||
window.close();
|
|
||||||
}, 2000);
|
|
||||||
}, 60000); // 60 seconds timeout
|
}, 60000); // 60 seconds timeout
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "mini-web",
|
"name": "mini-web",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"basename": "/root/mini-web",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pub": "envision deploy ./envision -k mini-web -v 0.0.3 -y y",
|
"pub": "envision deploy ./envision -k mini-web -v 0.0.4 -y y",
|
||||||
"ev": "npm run build && npm run deploy"
|
"ev": "npm run build && npm run deploy"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
@ -12,6 +12,5 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"qrcode": "^1.5.4"
|
"qrcode": "^1.5.4"
|
||||||
},
|
}
|
||||||
"packageManager": "pnpm@9.14.4+sha512.c8180b3fbe4e4bca02c94234717896b5529740a6cbadf19fa78254270403ea2f27d4e1d46a08a0f56c89b63dc8ebfd3ee53326da720273794e6200fcf0d184ab"
|
}
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user