@kevisual/kv-login 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/kv-login",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "main": "src/main.ts",
6
6
  "scripts": {
package/src/main.ts CHANGED
@@ -1,4 +1,7 @@
1
+ import { checkPluginLogin, clearCode } from './modules/login-handle';
1
2
  import './pages/kv-login'
2
3
  import './pages/kv-message'
3
4
 
4
- export { loginEmitter } from './pages/kv-login'
5
+ export { loginEmitter } from './pages/kv-login'
6
+
7
+ export { checkPluginLogin, clearCode }
@@ -93,11 +93,13 @@ const loginByWeChatMp = async (data: { wechatMpCode: string }) => {
93
93
  console.log('使用微信公众号登录:', data)
94
94
  }
95
95
 
96
- const clearCode = () => {
96
+ export const clearCode = () => {
97
97
  const url = new URL(window.location.href);
98
98
  // 清理 URL 中的 code 参数
99
99
  url.searchParams.delete('code');
100
100
  url.searchParams.delete('state');
101
+ url.searchParams.delete('user-check');
102
+ url.searchParams.delete('redirect');
101
103
  window.history.replaceState({}, document.title, url.toString());
102
104
  }
103
105
  export const checkWechat = async () => {
@@ -146,6 +148,29 @@ export const checkMpWechat = async () => {
146
148
  closePage();
147
149
  }
148
150
  }
151
+ export const checkPluginLogin = async () => {
152
+ const userCheck = 'user-check';
153
+ const url = new URL(location.href);
154
+ const redirect = url.searchParams.get('redirect');
155
+ const redirectUrl = redirect ? decodeURIComponent(redirect) : '';
156
+ const checkKey = url.searchParams.get(userCheck);
157
+ if (redirect && checkKey) {
158
+ // 通过refresh_token 刷新token
159
+ const me = await query.getMe();
160
+ if (me.code === 200) {
161
+ message.success('登录插件中...');
162
+ const token = await query.cacheStore.getAccessToken();
163
+ const newRedirectUrl = new URL(redirectUrl);
164
+ newRedirectUrl.searchParams.set('token', token + '');
165
+ setTimeout(() => {
166
+ window.open(newRedirectUrl.toString(), '_blank');
167
+ }, 2000);
168
+ return;
169
+ }
170
+ // 刷新token失败,登陆页自己跳转
171
+ }
172
+ console.log('checkKey', checkKey, redirectUrl);
173
+ }
149
174
  const isWechat = () => {
150
175
  const ua = navigator.userAgent.toLowerCase();
151
176
  return /micromessenger/i.test(ua);