@kevisual/kv-login 0.1.2 → 0.1.4
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/dist/app.d.ts +4 -1
- package/dist/app.js +1174 -223
- package/package.json +6 -4
- package/src/main.ts +1 -2
- package/src/modules/login-handle.ts +21 -1
- package/src/pages/kv-login.ts +25 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/kv-login",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"packageManager": "pnpm@10.
|
|
22
|
+
"packageManager": "pnpm@10.26.2",
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@kevisual/context": "^0.0.4",
|
|
29
29
|
"@kevisual/query-login": "^0.0.7",
|
|
30
|
-
"
|
|
30
|
+
"crypto-js": "^4.2.0",
|
|
31
|
+
"lit-html": "^3.3.2",
|
|
31
32
|
"qrcode": "^1.5.4"
|
|
32
33
|
},
|
|
33
34
|
"exports": {
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
},
|
|
37
38
|
"types": "./types/index.d.ts",
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
+
"@kevisual/api": "^0.0.8",
|
|
41
|
+
"@types/bun": "^1.3.5"
|
|
40
42
|
}
|
|
41
43
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { checkPluginLogin, clearCode } from './modules/login-handle';
|
|
2
1
|
import './pages/kv-login'
|
|
3
2
|
import './pages/kv-message'
|
|
4
3
|
|
|
5
4
|
export { loginEmitter } from './pages/kv-login'
|
|
6
5
|
|
|
7
|
-
export { checkPluginLogin, clearCode }
|
|
6
|
+
export { checkPluginLogin, clearCode } from './modules/login-handle';
|
|
@@ -2,9 +2,11 @@ import { query } from './query.ts';
|
|
|
2
2
|
import { createMessage } from '../pages/kv-message.ts';
|
|
3
3
|
import { WX_MP_APP_ID } from '../pages/kv-login.ts';
|
|
4
4
|
import { emit } from './mitt.ts';
|
|
5
|
+
import { Query } from '@kevisual/query';
|
|
6
|
+
import { QueryLoginBrowser } from '@kevisual/api/login'
|
|
5
7
|
export const message = createMessage();
|
|
6
8
|
type LoginOpts = {
|
|
7
|
-
loginMethod: 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket',
|
|
9
|
+
loginMethod: 'password' | 'web' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket',
|
|
8
10
|
data: any,
|
|
9
11
|
el: HTMLElement
|
|
10
12
|
}
|
|
@@ -40,10 +42,28 @@ export const loginHandle = async (opts: LoginOpts) => {
|
|
|
40
42
|
case 'wechat':
|
|
41
43
|
await loginByWeChat(data)
|
|
42
44
|
break
|
|
45
|
+
case 'web':
|
|
46
|
+
await loginByWeb(data)
|
|
47
|
+
break
|
|
43
48
|
default:
|
|
44
49
|
console.warn('未知的登录方式:', loginMethod)
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
const loginByWeb = async (data: {}) => {
|
|
53
|
+
const url = new URL("https://kevisual.cn/api/router");
|
|
54
|
+
const query = new Query({ url: "https://kevisual.cn/api/router" })
|
|
55
|
+
const login = new QueryLoginBrowser({ query })
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
const res = login.loginWithWeb(url.origin, {})
|
|
58
|
+
console.log('打开网页登录:', res)
|
|
59
|
+
window.open(res.url, '_blank');
|
|
60
|
+
const status = await login.pollLoginStatus(res);
|
|
61
|
+
if (status) {
|
|
62
|
+
redirectHome()
|
|
63
|
+
} else {
|
|
64
|
+
message.error('网页登录失败,请重试')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
47
67
|
/**
|
|
48
68
|
* 使用用户名和密码登录
|
|
49
69
|
* @param data
|
package/src/pages/kv-login.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { render, html } from 'lit-html'
|
|
2
2
|
import { unsafeHTML } from 'lit-html/directives/unsafe-html.js'
|
|
3
|
-
import { loginHandle, checkWechat, getQrCode, checkMpQrCodeLogin } from '../modules/login-handle.ts'
|
|
3
|
+
import { loginHandle, checkWechat, getQrCode, checkMpQrCodeLogin, redirectHome } from '../modules/login-handle.ts'
|
|
4
4
|
import { setWxerwma } from '../modules/wx/ws-login.ts';
|
|
5
5
|
import { useCreateLoginQRCode } from '../modules/wx-mp/qr.ts';
|
|
6
6
|
import { eventEmitter } from '../modules/mitt.ts';
|
|
7
7
|
import { useContextKey } from '@kevisual/context'
|
|
8
|
+
|
|
8
9
|
export const loginEmitter = useContextKey('login-emitter', eventEmitter);
|
|
9
10
|
export const WX_MP_APP_ID = "wxff97d569b1db16b6";
|
|
10
11
|
interface LoginMethod {
|
|
@@ -17,29 +18,31 @@ const wxmpSvg = `<svg t="1764510467010" class="icon" viewBox="0 0 1024 1024" ver
|
|
|
17
18
|
const wxOpenSvg = `<svg t="1764511395617" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3882" width="32" height="32"><path d="M256 259.584c-29.184 0-51.2 14.848-51.2 44.032s29.184 44.032 51.2 44.032c29.184 0 44.032-14.848 44.032-44.032s-22.016-44.032-44.032-44.032zM541.184 303.616c0-29.184-14.848-44.032-44.032-44.032-29.184 0-51.2 14.848-51.2 44.032s29.184 44.032 51.2 44.032c29.696 0 44.032-22.016 44.032-44.032zM614.4 508.416c-14.848 0-36.352 14.848-36.352 36.352 0 14.848 14.848 36.352 36.352 36.352 29.184 0 44.032-14.848 44.032-36.352 0-14.336-14.848-36.352-44.032-36.352z" p-id="3883"></path><path d="M1024 625.152c0-138.752-124.416-256-285.184-270.848-29.184-153.6-189.952-263.168-373.248-263.168C160.768 91.648 0 230.4 0 406.016c0 95.232 44.032 175.616 138.752 241.152L109.568 742.4c0 7.168 0 14.848 7.168 22.016h14.848l117.248-58.368h14.848c36.352 7.168 66.048 14.848 109.568 14.848 14.848 0 44.032-7.168 44.032-7.168C460.8 822.784 578.048 896 716.8 896c36.352 0 73.216-7.168 102.4-14.848l87.552 51.2h14.848c7.168-7.168 7.168-7.168 7.168-14.848l-22.016-87.552c80.896-58.368 117.248-131.584 117.248-204.8z m-621.568 51.2h-36.352c-36.352 0-66.048-7.168-95.232-14.848l-22.016-7.168h-7.168L153.6 698.368l22.016-66.048c0-7.168 0-14.848-7.168-14.848C80.384 559.616 36.352 486.4 36.352 398.848 36.352 245.248 182.784 128 358.4 128c160.768 0 300.032 95.232 329.216 226.816-168.448 0-300.032 117.248-300.032 263.168 7.168 22.016 14.848 44.032 14.848 58.368z m467.968 132.096c-7.168 7.168-7.168 7.168-7.168 14.848l14.848 51.2L819.2 844.8h-14.848c-29.184 7.168-66.048 14.848-95.232 14.848-146.432 0-270.848-102.4-270.848-226.816 0-131.584 124.416-233.984 270.848-233.984s270.848 102.4 270.848 226.816c0 65.536-36.352 123.904-109.568 182.784z" p-id="3884"></path><path d="M804.352 508.416c-14.848 0-36.352 14.848-36.352 36.352 0 14.848 14.848 36.352 36.352 36.352 29.184 0 44.032-14.848 44.032-36.352 0-14.336-14.336-36.352-44.032-36.352z" p-id="3885"></path></svg>`
|
|
18
19
|
const phone = `<svg t="1764511425462" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5097" width="32" height="32"><path d="M820.409449 797.228346q0 25.19685-10.07874 46.866142t-27.716535 38.299213-41.322835 26.204724-50.897638 9.574803l-357.795276 0q-27.212598 0-50.897638-9.574803t-41.322835-26.204724-27.716535-38.299213-10.07874-46.866142l0-675.275591q0-25.19685 10.07874-47.370079t27.716535-38.80315 41.322835-26.204724 50.897638-9.574803l357.795276 0q27.212598 0 50.897638 9.574803t41.322835 26.204724 27.716535 38.80315 10.07874 47.370079l0 675.275591zM738.771654 170.330709l-455.559055 0 0 577.511811 455.559055 0 0-577.511811zM510.992126 776.062992q-21.165354 0-36.787402 15.11811t-15.622047 37.291339q0 21.165354 15.622047 36.787402t36.787402 15.622047q22.173228 0 37.291339-15.622047t15.11811-36.787402q0-22.173228-15.11811-37.291339t-37.291339-15.11811zM591.622047 84.661417q0-8.062992-5.03937-12.598425t-11.086614-4.535433l-128 0q-5.03937 0-10.582677 4.535433t-5.543307 12.598425 5.03937 12.598425 11.086614 4.535433l128 0q6.047244 0 11.086614-4.535433t5.03937-12.598425z" p-id="5098"></path></svg>`
|
|
19
20
|
const pwd = `<svg t="1764511500570" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10511" width="32" height="32"><path d="M768.9216 422.72768 372.06016 422.72768C378.88 365.21984 329.37984 131.42016 512.2048 125.72672c173.83424-6.59456 146.78016 213.34016 146.78016 213.34016l85.13536 0.57344c0 0 24.73984-294.4-231.91552-295.8336C232.09984 58.01984 297.82016 377.18016 289.28 422.72768c1.98656 0 4.56704 0 7.29088 0-55.88992 0-101.21216 45.34272-101.21216 101.21216l0 337.38752c0 55.88992 45.34272 101.21216 101.21216 101.21216l472.35072 0c55.88992 0 101.21216-45.34272 101.21216-101.21216L870.13376 523.93984C870.13376 468.0704 824.79104 422.72768 768.9216 422.72768zM566.4768 717.02528l0 76.84096c0 18.57536-15.1552 33.73056-33.73056 33.73056-18.57536 0-33.73056-15.1552-33.73056-33.73056l0-76.84096c-20.09088-11.69408-33.73056-33.21856-33.73056-58.12224 0-37.2736 30.208-67.4816 67.4816-67.4816 37.2736 0 67.4816 30.208 67.4816 67.4816C600.22784 683.80672 586.58816 705.3312 566.4768 717.02528z" fill="#272636" p-id="10512"></path></svg>`
|
|
20
|
-
|
|
21
|
+
const web = `<svg t="1764511538113" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="11994" width="32" height="32"><path d="M512 85.333333C264.533333 85.333333 64 285.866667 64 533.333333s200.533333 448 448 448 448-200.533333 448-448S759.466667 85.333333 512 85.333333z m0 810.666667c-200.533333 0-362.666667-162.133333-362.666667-362.666667S311.466667 170.666667 512 170.666667s362.666667 162.133333 362.666667 362.666667-162.133333 362.666667-362.666667 362.666667z" p-id="11995"></path><path d="M512 298.666667c-119.466667 0-216.533333 97.066667-216.533333 216.533333s97.066667 216.533333 216.533333 216.533333 216.533333-97.066667 216.533333-216.533333-97.066667-216.533333-216.533333-216.533333z m0 362.666666c-80.853333 0-146.133333-65.28-146.133333-146.133333s65.28-146.133333 146.133333-146.133333 146.133333 65.28 146.133333 146.133333-65.28 146.133333-146.133333 146.133333z" p-id="11996"></path></svg>`
|
|
21
22
|
const icons: any = {
|
|
22
23
|
pwd,
|
|
24
|
+
web,
|
|
23
25
|
phone,
|
|
24
26
|
wxmpSvg,
|
|
25
27
|
wxOpenSvg
|
|
26
28
|
}
|
|
27
29
|
const DefaultLoginMethods: LoginMethod[] = [
|
|
28
30
|
{ id: 'password', name: '密码登录', icon: 'pwd' },
|
|
31
|
+
{ id: 'web', name: '网页登录', icon: 'web' },
|
|
29
32
|
{ id: 'wechat', name: '微信登录', icon: 'wxmpSvg', appid: "wx9378885c8390e09b" },
|
|
30
33
|
{ id: 'wechat-mp', name: '微信公众号', icon: 'wxOpenSvg', appid: WX_MP_APP_ID },
|
|
31
34
|
{ id: 'wechat-mp-ticket', name: '微信公众号', icon: 'wxOpenSvg' },
|
|
32
35
|
{ id: 'phone', name: '手机号登录', icon: 'phone' }
|
|
33
36
|
]
|
|
34
|
-
const LoginMethods = ['password', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket'] as const;
|
|
35
|
-
type LoginMethods = 'password' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket';
|
|
37
|
+
const LoginMethods = ['password', 'web', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket'] as const;
|
|
38
|
+
type LoginMethods = 'password' | 'web' | 'phone' | 'wechat' | 'wechat-mp' | 'wechat-mp-ticket';
|
|
36
39
|
|
|
37
40
|
const getLoginMethodByDomain = (): LoginMethod[] => {
|
|
38
41
|
let domain = window.location.host
|
|
39
42
|
let methods: LoginMethods[] = []
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
domain = 'localhost
|
|
43
|
+
const has51 = domain.includes('localhost') && (domain.endsWith('51515') || domain.endsWith('51015'));
|
|
44
|
+
if (has51) {
|
|
45
|
+
domain = 'localhost'
|
|
43
46
|
}
|
|
44
47
|
switch (domain) {
|
|
45
48
|
case 'kevisual.xiongxiao.me':
|
|
@@ -48,11 +51,11 @@ const getLoginMethodByDomain = (): LoginMethod[] => {
|
|
|
48
51
|
case 'kevisual.cn':
|
|
49
52
|
methods = ['password', 'wechat-mp-ticket', 'wechat',]
|
|
50
53
|
break;
|
|
51
|
-
case 'localhost
|
|
52
|
-
methods = ['password']
|
|
54
|
+
case 'localhost':
|
|
55
|
+
methods = ['password', 'web']
|
|
53
56
|
break
|
|
54
57
|
default:
|
|
55
|
-
methods = ['password', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket']
|
|
58
|
+
methods = ['password', 'web', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket']
|
|
56
59
|
break;
|
|
57
60
|
}
|
|
58
61
|
return DefaultLoginMethods.filter(method => methods.includes(method.id))
|
|
@@ -161,7 +164,8 @@ class KvLogin extends HTMLElement {
|
|
|
161
164
|
username: username?.value || '',
|
|
162
165
|
password: password?.value || ''
|
|
163
166
|
}
|
|
164
|
-
|
|
167
|
+
case 'web':
|
|
168
|
+
return {}
|
|
165
169
|
case 'phone':
|
|
166
170
|
const phone = this.shadowRoot.querySelector('#phone') as HTMLInputElement
|
|
167
171
|
const code = this.shadowRoot.querySelector('#code') as HTMLInputElement
|
|
@@ -210,7 +214,14 @@ class KvLogin extends HTMLElement {
|
|
|
210
214
|
</form>
|
|
211
215
|
`
|
|
212
216
|
}
|
|
213
|
-
|
|
217
|
+
private renderWebForm() {
|
|
218
|
+
return html`
|
|
219
|
+
<div class="web-login">
|
|
220
|
+
<button type="button" class="refresh-button" @click=${this.handleLogin.bind(this)}>点击登录</button>
|
|
221
|
+
<slot></slot>
|
|
222
|
+
</div>
|
|
223
|
+
`
|
|
224
|
+
}
|
|
214
225
|
private renderPhoneForm() {
|
|
215
226
|
return html`
|
|
216
227
|
<form id="loginForm" class="login-form">
|
|
@@ -308,6 +319,8 @@ class KvLogin extends HTMLElement {
|
|
|
308
319
|
switch (this.selectedMethod) {
|
|
309
320
|
case 'password':
|
|
310
321
|
return this.renderPasswordForm()
|
|
322
|
+
case 'web':
|
|
323
|
+
return this.renderWebForm()
|
|
311
324
|
case 'phone':
|
|
312
325
|
return this.renderPhoneForm()
|
|
313
326
|
case 'wechat':
|