@kevisual/kv-login 0.1.4 → 0.1.14
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/assets/index-CyXnpqtU.js +469 -0
- package/dist/index.html +127 -0
- package/package.json +9 -7
- package/src/main.ts +6 -1
- package/src/modules/login-handle.ts +33 -14
- package/src/modules/query.ts +8 -3
- package/src/pages/kv-login.ts +45 -9
- package/dist/app.d.ts +0 -115
- package/dist/app.js +0 -6518
package/dist/index.html
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>KvMessage Demo</title>
|
|
8
|
+
<style>
|
|
9
|
+
* {
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
body {
|
|
16
|
+
margin: 0;
|
|
17
|
+
padding: 0;
|
|
18
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
19
|
+
min-height: 100vh;
|
|
20
|
+
background-image: url('https://zxj.tos-cn-shanghai.volces.com/img/20260119213348097_1768829628101.png');
|
|
21
|
+
background-size: cover;
|
|
22
|
+
background-position: center;
|
|
23
|
+
background-repeat: no-repeat;
|
|
24
|
+
background-attachment: fixed;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.demo-container {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 20px;
|
|
35
|
+
padding: 40px 20px;
|
|
36
|
+
width: 100%;
|
|
37
|
+
max-width: 500px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.button-group {
|
|
41
|
+
display: flex;
|
|
42
|
+
gap: 12px;
|
|
43
|
+
flex-wrap: wrap;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.demo-button {
|
|
48
|
+
padding: 10px 20px;
|
|
49
|
+
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
50
|
+
border-radius: 8px;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
font-size: 14px;
|
|
53
|
+
transition: all 0.3s ease;
|
|
54
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.demo-button.success {
|
|
58
|
+
background: #52c41a;
|
|
59
|
+
color: white;
|
|
60
|
+
border-color: #52c41a;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.demo-button.success:hover {
|
|
64
|
+
background: #389e0d;
|
|
65
|
+
border-color: #389e0d;
|
|
66
|
+
box-shadow: 0 4px 12px rgba(82, 196, 26, 0.3);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.demo-button.error {
|
|
70
|
+
background: #ff4d4f;
|
|
71
|
+
color: white;
|
|
72
|
+
border-color: #ff4d4f;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.demo-button.error:hover {
|
|
76
|
+
background: #cf1322;
|
|
77
|
+
border-color: #cf1322;
|
|
78
|
+
box-shadow: 0 4px 12px rgba(255, 77, 79, 0.3);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.demo-button.loading {
|
|
82
|
+
background: #1890ff;
|
|
83
|
+
color: white;
|
|
84
|
+
border-color: #1890ff;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.demo-button.loading:hover {
|
|
88
|
+
background: #096dd9;
|
|
89
|
+
border-color: #096dd9;
|
|
90
|
+
box-shadow: 0 4px 12px rgba(24, 144, 255, 0.3);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.login-section {
|
|
94
|
+
text-align: center;
|
|
95
|
+
background: rgba(255, 255, 255, 0.95);
|
|
96
|
+
padding: 40px 30px;
|
|
97
|
+
border-radius: 16px;
|
|
98
|
+
border: 2px solid rgba(255, 255, 255, 0.8);
|
|
99
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1),
|
|
100
|
+
0 0 0 1px rgba(255, 255, 255, 0.5) inset;
|
|
101
|
+
backdrop-filter: blur(10px);
|
|
102
|
+
-webkit-backdrop-filter: blur(10px);
|
|
103
|
+
width: 100%;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.login-section h2 {
|
|
107
|
+
margin-bottom: 30px;
|
|
108
|
+
color: #1a1a1a;
|
|
109
|
+
font-size: 28px;
|
|
110
|
+
font-weight: 600;
|
|
111
|
+
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
|
112
|
+
}
|
|
113
|
+
</style>
|
|
114
|
+
<script type="module" crossorigin src="/root/login/assets/index-CyXnpqtU.js"></script>
|
|
115
|
+
</head>
|
|
116
|
+
|
|
117
|
+
<body>
|
|
118
|
+
<div class="demo-container">
|
|
119
|
+
<div class="login-section">
|
|
120
|
+
<h2>登录</h2>
|
|
121
|
+
<!-- <kv-login method="wechat,password"></kv-login> -->
|
|
122
|
+
<kv-login></kv-login>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</body>
|
|
126
|
+
|
|
127
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevisual/kv-login",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"postbuild": "dts -i src/main.ts -o app.d.ts",
|
|
10
10
|
"build:test": "vite build",
|
|
11
11
|
"prepub": "rm -rf ./dist && pnpm run build:test",
|
|
12
|
-
"pub": "ev deploy ./dist -k
|
|
12
|
+
"pub": "ev deploy ./dist -k login -v 0.1.15 -u -y yes"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"files": [
|
|
@@ -19,14 +19,15 @@
|
|
|
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.30.1",
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@kevisual/
|
|
29
|
-
"@kevisual/
|
|
28
|
+
"@kevisual/cache": "^0.0.5",
|
|
29
|
+
"@kevisual/context": "^0.0.8",
|
|
30
|
+
"@kevisual/query": "^0.0.49",
|
|
30
31
|
"crypto-js": "^4.2.0",
|
|
31
32
|
"lit-html": "^3.3.2",
|
|
32
33
|
"qrcode": "^1.5.4"
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
},
|
|
38
39
|
"types": "./types/index.d.ts",
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@kevisual/api": "^0.0.
|
|
41
|
-
"@types/bun": "^1.3.
|
|
41
|
+
"@kevisual/api": "^0.0.59",
|
|
42
|
+
"@types/bun": "^1.3.9",
|
|
43
|
+
"vite": "^7.3.1"
|
|
42
44
|
}
|
|
43
45
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import './pages/kv-login'
|
|
2
2
|
import './pages/kv-message'
|
|
3
|
+
import { createMessage } from './pages/kv-message';
|
|
3
4
|
|
|
4
5
|
export { loginEmitter } from './pages/kv-login'
|
|
5
6
|
|
|
6
|
-
export { checkPluginLogin, clearCode } from './modules/login-handle';
|
|
7
|
+
export { checkPluginLogin, clearCode, redirectHome } from './modules/login-handle';
|
|
8
|
+
|
|
9
|
+
export { createMessage }
|
|
10
|
+
|
|
11
|
+
export { queryLogin } from './modules/query.ts';
|
|
@@ -10,22 +10,28 @@ type LoginOpts = {
|
|
|
10
10
|
data: any,
|
|
11
11
|
el: HTMLElement
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* 登录成功后重定向到首页
|
|
15
|
-
*/
|
|
16
13
|
export const redirectHome = () => {
|
|
17
14
|
const href = window.location.href;
|
|
18
15
|
const url = new URL(href);
|
|
19
16
|
const redirect = url.searchParams.get('redirect');
|
|
20
17
|
if (redirect) {
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
const href = decodeURIComponent(redirect);
|
|
20
|
+
window.open(href, '_self');
|
|
21
|
+
}, 2000);
|
|
22
|
+
return;
|
|
23
23
|
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 登录成功后重定向到首页
|
|
27
|
+
*/
|
|
28
|
+
export const logginSuccess = () => {
|
|
29
|
+
|
|
24
30
|
// 从url上清除 code 参数, 清除 state 参数
|
|
25
31
|
emit({ type: 'login-success', data: {} });
|
|
26
32
|
setTimeout(() => {
|
|
27
33
|
clearCode();
|
|
28
|
-
},
|
|
34
|
+
}, 2000);
|
|
29
35
|
}
|
|
30
36
|
export const loginHandle = async (opts: LoginOpts) => {
|
|
31
37
|
const { loginMethod, data, el } = opts
|
|
@@ -59,7 +65,7 @@ const loginByWeb = async (data: {}) => {
|
|
|
59
65
|
window.open(res.url, '_blank');
|
|
60
66
|
const status = await login.pollLoginStatus(res);
|
|
61
67
|
if (status) {
|
|
62
|
-
|
|
68
|
+
logginSuccess()
|
|
63
69
|
} else {
|
|
64
70
|
message.error('网页登录失败,请重试')
|
|
65
71
|
}
|
|
@@ -86,9 +92,10 @@ const loginByPassword = async (data: { username: string, password: string }) =>
|
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
if (!needLogin) {
|
|
89
|
-
|
|
95
|
+
logginSuccess()
|
|
90
96
|
return;
|
|
91
97
|
}
|
|
98
|
+
localStorage.removeItem('token')
|
|
92
99
|
const res = await query.login({
|
|
93
100
|
username: data.username,
|
|
94
101
|
password: data.password
|
|
@@ -96,7 +103,7 @@ const loginByPassword = async (data: { username: string, password: string }) =>
|
|
|
96
103
|
if (res.code === 200) {
|
|
97
104
|
console.log('登录成功')
|
|
98
105
|
message.success('登录成功')
|
|
99
|
-
|
|
106
|
+
logginSuccess()
|
|
100
107
|
} else {
|
|
101
108
|
message.error(`登录失败: ${res.message}`)
|
|
102
109
|
}
|
|
@@ -136,7 +143,7 @@ export const checkWechat = async () => {
|
|
|
136
143
|
const res = await query.loginByWechat({ code });
|
|
137
144
|
if (res.code === 200) {
|
|
138
145
|
message.success('登录成功');
|
|
139
|
-
|
|
146
|
+
logginSuccess();
|
|
140
147
|
} else {
|
|
141
148
|
message.error(res.message || '登录失败');
|
|
142
149
|
clearCode();
|
|
@@ -168,7 +175,14 @@ export const checkMpWechat = async () => {
|
|
|
168
175
|
closePage();
|
|
169
176
|
}
|
|
170
177
|
}
|
|
171
|
-
|
|
178
|
+
|
|
179
|
+
type CheckPluginLoginResult = {
|
|
180
|
+
code: number
|
|
181
|
+
data: {
|
|
182
|
+
redirectUrl: string
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export const checkPluginLogin = async (): Promise<CheckPluginLoginResult> => {
|
|
172
186
|
const userCheck = 'user-check';
|
|
173
187
|
const url = new URL(location.href);
|
|
174
188
|
const redirect = url.searchParams.get('redirect');
|
|
@@ -185,11 +199,16 @@ export const checkPluginLogin = async () => {
|
|
|
185
199
|
setTimeout(() => {
|
|
186
200
|
window.open(newRedirectUrl.toString(), '_blank');
|
|
187
201
|
}, 2000);
|
|
188
|
-
return
|
|
202
|
+
return { code: 200, data: { redirectUrl } }
|
|
189
203
|
}
|
|
190
204
|
// 刷新token失败,登陆页自己跳转
|
|
191
205
|
}
|
|
192
|
-
|
|
206
|
+
return {
|
|
207
|
+
code: 400,
|
|
208
|
+
data: {
|
|
209
|
+
redirectUrl: ''
|
|
210
|
+
}
|
|
211
|
+
}
|
|
193
212
|
}
|
|
194
213
|
const isWechat = () => {
|
|
195
214
|
const ua = navigator.userAgent.toLowerCase();
|
|
@@ -265,7 +284,7 @@ export const checkMpQrCodeLogin = (ticket: string) => {
|
|
|
265
284
|
if (res.code === 200) {
|
|
266
285
|
message.success('登录成功');
|
|
267
286
|
clearTimeout(timer);
|
|
268
|
-
|
|
287
|
+
logginSuccess();
|
|
269
288
|
} else {
|
|
270
289
|
// message.error(res.message || '登录失败');
|
|
271
290
|
if (res.code === 401) {
|
package/src/modules/query.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Query } from '@kevisual/query'
|
|
2
|
-
import { QueryLoginBrowser } from '@kevisual/query-login';
|
|
2
|
+
import { QueryLoginBrowser } from '@kevisual/api/query-login';
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export const queryBase = new Query()
|
|
5
|
+
export const queryBase = new Query({})
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const queryLogin = new QueryLoginBrowser({
|
|
8
8
|
query: queryBase,
|
|
9
|
+
isBrowser: true,
|
|
10
|
+
onLoad: () => {
|
|
11
|
+
console.log('加载完成');
|
|
12
|
+
}
|
|
9
13
|
})
|
|
10
14
|
|
|
15
|
+
export const query = queryLogin;
|
package/src/pages/kv-login.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
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
|
|
3
|
+
import { loginHandle, checkWechat, getQrCode, checkMpQrCodeLogin } 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
|
+
const randomId = (num: number = 6) => {
|
|
10
|
+
return 'id-' + Math.random().toString(36).slice(2, num + 2);
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
export const loginEmitter = useContextKey('login-emitter', eventEmitter);
|
|
10
14
|
export const WX_MP_APP_ID = "wxff97d569b1db16b6";
|
|
11
15
|
interface LoginMethod {
|
|
@@ -27,9 +31,9 @@ const icons: any = {
|
|
|
27
31
|
wxOpenSvg
|
|
28
32
|
}
|
|
29
33
|
const DefaultLoginMethods: LoginMethod[] = [
|
|
34
|
+
{ id: 'wechat', name: '微信登录', icon: 'wxmpSvg', appid: "wx9378885c8390e09b" },
|
|
30
35
|
{ id: 'password', name: '密码登录', icon: 'pwd' },
|
|
31
36
|
{ id: 'web', name: '网页登录', icon: 'web' },
|
|
32
|
-
{ id: 'wechat', name: '微信登录', icon: 'wxmpSvg', appid: "wx9378885c8390e09b" },
|
|
33
37
|
{ id: 'wechat-mp', name: '微信公众号', icon: 'wxOpenSvg', appid: WX_MP_APP_ID },
|
|
34
38
|
{ id: 'wechat-mp-ticket', name: '微信公众号', icon: 'wxOpenSvg' },
|
|
35
39
|
{ id: 'phone', name: '手机号登录', icon: 'phone' }
|
|
@@ -40,10 +44,14 @@ type LoginMethods = 'password' | 'web' | 'phone' | 'wechat' | 'wechat-mp' | 'wec
|
|
|
40
44
|
const getLoginMethodByDomain = (): LoginMethod[] => {
|
|
41
45
|
let domain = window.location.host
|
|
42
46
|
let methods: LoginMethods[] = []
|
|
43
|
-
const
|
|
47
|
+
const isCnb = domain.includes('cnb.run');
|
|
48
|
+
const has51 = domain.includes('localhost') || domain.endsWith('51515');
|
|
44
49
|
if (has51) {
|
|
45
50
|
domain = 'localhost'
|
|
46
51
|
}
|
|
52
|
+
if (isCnb) {
|
|
53
|
+
domain = 'cnb.run'
|
|
54
|
+
}
|
|
47
55
|
switch (domain) {
|
|
48
56
|
case 'kevisual.xiongxiao.me':
|
|
49
57
|
methods = ['password', 'wechat-mp']
|
|
@@ -54,6 +62,9 @@ const getLoginMethodByDomain = (): LoginMethod[] => {
|
|
|
54
62
|
case 'localhost':
|
|
55
63
|
methods = ['password', 'web']
|
|
56
64
|
break
|
|
65
|
+
case 'cnb.run':
|
|
66
|
+
methods = ['password', 'web']
|
|
67
|
+
break;
|
|
57
68
|
default:
|
|
58
69
|
methods = ['password', 'web', 'phone', 'wechat', 'wechat-mp', 'wechat-mp-ticket']
|
|
59
70
|
break;
|
|
@@ -63,10 +74,13 @@ const getLoginMethodByDomain = (): LoginMethod[] => {
|
|
|
63
74
|
const getLoginMethod = (methods: LoginMethods[]): LoginMethod[] => {
|
|
64
75
|
return DefaultLoginMethods.filter(method => methods.includes(method.id))
|
|
65
76
|
}
|
|
77
|
+
export const findLoginMethod = (methodId: LoginMethods): LoginMethod | undefined => {
|
|
78
|
+
return DefaultLoginMethods.find(method => method.id === methodId);
|
|
79
|
+
}
|
|
66
80
|
class KvLogin extends HTMLElement {
|
|
67
81
|
private selectedMethod: LoginMethods = 'password'
|
|
68
82
|
|
|
69
|
-
private loginMethods: LoginMethod[] =
|
|
83
|
+
private loginMethods: LoginMethod[] = [];
|
|
70
84
|
setLoginMethods(methods: LoginMethod[]) {
|
|
71
85
|
this.loginMethods = methods
|
|
72
86
|
this.render()
|
|
@@ -77,23 +91,37 @@ class KvLogin extends HTMLElement {
|
|
|
77
91
|
|
|
78
92
|
connectedCallback() {
|
|
79
93
|
this.attachShadow({ mode: 'open' })
|
|
80
|
-
this.render()
|
|
81
94
|
this.bindEvents()
|
|
82
95
|
checkWechat()
|
|
83
96
|
const method = this.getAttribute('method');
|
|
97
|
+
let id = this.id;
|
|
98
|
+
if (!id) {
|
|
99
|
+
id = randomId(6);
|
|
100
|
+
this.id = id;
|
|
101
|
+
}
|
|
102
|
+
let methodSetFlag = false;
|
|
84
103
|
if (method) {
|
|
85
104
|
const methods = method ? method.split(',') as LoginMethods[] : [];
|
|
86
105
|
if (methods.length > 0) {
|
|
87
|
-
|
|
106
|
+
let loginMethods: LoginMethod[] = [];
|
|
107
|
+
for (const m of methods) {
|
|
108
|
+
const finded = findLoginMethod(m);
|
|
109
|
+
if (finded?.id) {
|
|
110
|
+
loginMethods.push(finded);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
88
113
|
if (loginMethods.length > 0) {
|
|
89
|
-
|
|
90
|
-
this.
|
|
91
|
-
|
|
114
|
+
methodSetFlag = true;
|
|
115
|
+
this.loginMethods = loginMethods;
|
|
116
|
+
this.selectedMethod = loginMethods[0].id;
|
|
92
117
|
}
|
|
93
118
|
}
|
|
119
|
+
}
|
|
120
|
+
if (!methodSetFlag) {
|
|
94
121
|
this.loginMethods = getLoginMethodByDomain();
|
|
95
122
|
this.selectedMethod = this.loginMethods[0].id;
|
|
96
123
|
}
|
|
124
|
+
this.render()
|
|
97
125
|
}
|
|
98
126
|
#clearTimer: any = null;
|
|
99
127
|
private selectLoginMethod(methodId: LoginMethods) {
|
|
@@ -253,6 +281,14 @@ class KvLogin extends HTMLElement {
|
|
|
253
281
|
}
|
|
254
282
|
|
|
255
283
|
private renderWechatForm() {
|
|
284
|
+
let weixinLogin = document.querySelector('#weixinLogin');
|
|
285
|
+
if (!weixinLogin) {
|
|
286
|
+
weixinLogin = document.createElement('div');
|
|
287
|
+
weixinLogin.id = 'weixinLogin';
|
|
288
|
+
const id = this.id;
|
|
289
|
+
const host = document.querySelector(`#${id}`)!;
|
|
290
|
+
host.appendChild(weixinLogin);
|
|
291
|
+
}
|
|
256
292
|
return html`
|
|
257
293
|
<div class="wechat-login">
|
|
258
294
|
<slot></slot>
|
package/dist/app.d.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
interface EventData<T = any> {
|
|
2
|
-
type: string;
|
|
3
|
-
data: T;
|
|
4
|
-
}
|
|
5
|
-
type EventHandler<T = any> = (event: EventData<T>) => void;
|
|
6
|
-
declare class EventEmitter {
|
|
7
|
-
private events;
|
|
8
|
-
/**
|
|
9
|
-
* 监听事件
|
|
10
|
-
* @param type 事件类型
|
|
11
|
-
* @param handler 事件处理函数
|
|
12
|
-
*/
|
|
13
|
-
on<T = any>(type: string, handler: EventHandler<T>): void;
|
|
14
|
-
/**
|
|
15
|
-
* 移除事件监听器
|
|
16
|
-
* @param type 事件类型
|
|
17
|
-
* @param handler 事件处理函数 (可选,如果不提供则移除该类型的所有监听器)
|
|
18
|
-
*/
|
|
19
|
-
off<T = any>(type: string, handler?: EventHandler<T>): void;
|
|
20
|
-
/**
|
|
21
|
-
* 触发事件
|
|
22
|
-
* @param event 事件对象,包含 type 和 data
|
|
23
|
-
*/
|
|
24
|
-
emit<T = any>(event: EventData<T>): void;
|
|
25
|
-
/**
|
|
26
|
-
* 触发事件(简化版本,直接传递type和data)
|
|
27
|
-
* @param type 事件类型
|
|
28
|
-
* @param data 事件数据
|
|
29
|
-
*/
|
|
30
|
-
emitSimple<T = any>(type: string, data: T): void;
|
|
31
|
-
/**
|
|
32
|
-
* 清空所有事件监听器
|
|
33
|
-
*/
|
|
34
|
-
clear(): void;
|
|
35
|
-
/**
|
|
36
|
-
* 获取指定类型的监听器数量
|
|
37
|
-
* @param type 事件类型
|
|
38
|
-
* @returns 监听器数量
|
|
39
|
-
*/
|
|
40
|
-
listenerCount(type: string): number;
|
|
41
|
-
/**
|
|
42
|
-
* 获取所有事件类型
|
|
43
|
-
* @returns 事件类型数组
|
|
44
|
-
*/
|
|
45
|
-
eventNames(): string[];
|
|
46
|
-
/**
|
|
47
|
-
* 检查是否有指定类型的监听器
|
|
48
|
-
* @param type 事件类型
|
|
49
|
-
* @returns 是否有监听器
|
|
50
|
-
*/
|
|
51
|
-
hasListeners(type: string): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* 只监听一次事件
|
|
54
|
-
* @param type 事件类型
|
|
55
|
-
* @param handler 事件处理函数
|
|
56
|
-
*/
|
|
57
|
-
once<T = any>(type: string, handler: EventHandler<T>): void;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
declare const loginEmitter: EventEmitter;
|
|
61
|
-
|
|
62
|
-
interface KvMessageOptions {
|
|
63
|
-
type?: 'success' | 'error' | 'loading';
|
|
64
|
-
message: string;
|
|
65
|
-
duration?: number;
|
|
66
|
-
closable?: boolean;
|
|
67
|
-
position?: 'center' | 'right';
|
|
68
|
-
}
|
|
69
|
-
declare class KvMessage extends HTMLElement {
|
|
70
|
-
private options;
|
|
71
|
-
private timer;
|
|
72
|
-
constructor();
|
|
73
|
-
connectedCallback(): void;
|
|
74
|
-
setOptions(options: KvMessageOptions): void;
|
|
75
|
-
private render;
|
|
76
|
-
private setTimer;
|
|
77
|
-
remove(): void;
|
|
78
|
-
disconnectedCallback(): void;
|
|
79
|
-
}
|
|
80
|
-
declare class KvMessageManager {
|
|
81
|
-
private static instance;
|
|
82
|
-
private container;
|
|
83
|
-
private defaultPosition;
|
|
84
|
-
static getInstance(): KvMessageManager;
|
|
85
|
-
setDefaultPosition(position: 'center' | 'right'): void;
|
|
86
|
-
private getContainer;
|
|
87
|
-
show(options: KvMessageOptions): KvMessage;
|
|
88
|
-
success(message: string, options?: {
|
|
89
|
-
duration?: number;
|
|
90
|
-
position?: 'center' | 'right';
|
|
91
|
-
closable?: boolean;
|
|
92
|
-
}): KvMessage;
|
|
93
|
-
error(message: string, options?: {
|
|
94
|
-
duration?: number;
|
|
95
|
-
position?: 'center' | 'right';
|
|
96
|
-
closable?: boolean;
|
|
97
|
-
}): KvMessage;
|
|
98
|
-
loading(message: string, options?: {
|
|
99
|
-
position?: 'center' | 'right';
|
|
100
|
-
closable?: boolean;
|
|
101
|
-
}): KvMessage;
|
|
102
|
-
remove(message: KvMessage): void;
|
|
103
|
-
clear(): void;
|
|
104
|
-
}
|
|
105
|
-
declare const createMessage: () => KvMessageManager;
|
|
106
|
-
declare global {
|
|
107
|
-
interface Window {
|
|
108
|
-
createMessage: typeof createMessage;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
declare const clearCode: () => void;
|
|
113
|
-
declare const checkPluginLogin: () => Promise<void>;
|
|
114
|
-
|
|
115
|
-
export { checkPluginLogin, clearCode, loginEmitter };
|