@kevisual/kv-login 0.0.9 → 0.1.0

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/.cnb.yml ADDED
@@ -0,0 +1,12 @@
1
+ $:
2
+ vscode:
3
+ - docker:
4
+ image: docker.cnb.cool/kevisual/dev-env:latest
5
+ services:
6
+ - vscode
7
+ - docker
8
+ imports: https://cnb.cool/kevisual/env/-/blob/main/env.yml
9
+ # 开发环境启动后会执行的任务
10
+ # stages:
11
+ # - name: pnpm install
12
+ # script: pnpm install
package/index.html CHANGED
@@ -74,7 +74,7 @@
74
74
  <div class="demo-container">
75
75
  <div class="login-section">
76
76
  <h2>登录组件</h2>
77
- <kv-login>
77
+ <kv-login method="password">
78
78
  <div id="weixinLogin"></div>
79
79
  </kv-login>
80
80
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kevisual/kv-login",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
5
  "main": "src/main.ts",
6
6
  "scripts": {
@@ -14,13 +14,14 @@
14
14
  "keywords": [],
15
15
  "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
16
16
  "license": "MIT",
17
- "packageManager": "pnpm@10.24.0",
17
+ "packageManager": "pnpm@10.26.0",
18
18
  "publishConfig": {
19
19
  "access": "public"
20
20
  },
21
21
  "type": "module",
22
22
  "dependencies": {
23
23
  "@kevisual/context": "^0.0.4",
24
+ "@kevisual/query": "^0.0.32",
24
25
  "@kevisual/query-login": "^0.0.7",
25
26
  "lit-html": "^3.3.1",
26
27
  "qrcode": "^1.5.4"
@@ -31,6 +32,8 @@
31
32
  },
32
33
  "types": "./types/index.d.ts",
33
34
  "devDependencies": {
34
- "@types/bun": "^1.3.3"
35
+ "@types/bun": "^1.3.4",
36
+ "@types/qrcode": "^1.5.6",
37
+ "vite": "^7.3.0"
35
38
  }
36
39
  }
package/readme.md CHANGED
@@ -4,9 +4,26 @@
4
4
 
5
5
  黑白
6
6
 
7
-
8
7
  ```html
9
8
  <kv-login>
10
9
  <div id="weixinLogin"></div>
11
10
  </kv-login>
12
- ```
11
+ ```
12
+
13
+ ## 网页
14
+
15
+ ```html
16
+ <script type="importmap">
17
+ {
18
+ "imports": {
19
+ "@kevisual/kv-login": "https://esm.kevisual.cn/@kevisual/kv-login"
20
+ }
21
+ }
22
+ </script>
23
+ <script type="module">
24
+ import '@kevisual/kv-login';
25
+ </script>
26
+ <kv-login method="password">
27
+ <div id="weixinLogin"></div>
28
+ </kv-login>
29
+ ```
package/src/main.ts CHANGED
@@ -1,7 +1,4 @@
1
- import { checkPluginLogin, clearCode } from './modules/login-handle';
2
1
  import './pages/kv-login'
3
2
  import './pages/kv-message'
4
3
 
5
- export { loginEmitter } from './pages/kv-login'
6
-
7
- export { checkPluginLogin, clearCode }
4
+ export { loginEmitter } from './pages/kv-login'
@@ -93,13 +93,11 @@ const loginByWeChatMp = async (data: { wechatMpCode: string }) => {
93
93
  console.log('使用微信公众号登录:', data)
94
94
  }
95
95
 
96
- export const clearCode = () => {
96
+ 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');
103
101
  window.history.replaceState({}, document.title, url.toString());
104
102
  }
105
103
  export const checkWechat = async () => {
@@ -148,29 +146,6 @@ export const checkMpWechat = async () => {
148
146
  closePage();
149
147
  }
150
148
  }
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
- }
174
149
  const isWechat = () => {
175
150
  const ua = navigator.userAgent.toLowerCase();
176
151
  return /micromessenger/i.test(ua);
@@ -85,6 +85,7 @@ class KvLogin extends HTMLElement {
85
85
  if (loginMethods.length > 0) {
86
86
  this.loginMethods = getLoginMethod(loginMethods)
87
87
  this.selectedMethod = loginMethods[0]
88
+ this.setLoginMethods(this.loginMethods);
88
89
  return;
89
90
  }
90
91
  }
@@ -133,8 +134,6 @@ class KvLogin extends HTMLElement {
133
134
 
134
135
  private handleLogin() {
135
136
  const formData = this.getFormData()
136
- // console.log('登录方式:', this.selectedMethod)
137
- // console.log('登录数据:', formData)
138
137
  loginHandle({
139
138
  loginMethod: this.selectedMethod,
140
139
  data: formData,
package/web.html ADDED
@@ -0,0 +1,93 @@
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
+ <script type="importmap">
9
+ {
10
+ "imports": {
11
+ "@kevisual/kv-login": "https://esm.kevisual.cn/@kevisual/kv-login"
12
+ }
13
+ }
14
+ </script>
15
+ <script type="module">
16
+ import '@kevisual/kv-login';
17
+ </script>
18
+ <style>
19
+ body {
20
+ margin: 0;
21
+ padding: 20px;
22
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
23
+ }
24
+
25
+ .demo-container {
26
+ display: flex;
27
+ flex-direction: column;
28
+ align-items: center;
29
+ gap: 20px;
30
+ padding: 40px 20px;
31
+ }
32
+
33
+ .button-group {
34
+ display: flex;
35
+ gap: 12px;
36
+ flex-wrap: wrap;
37
+ justify-content: center;
38
+ }
39
+
40
+ .demo-button {
41
+ padding: 10px 20px;
42
+ border: none;
43
+ border-radius: 6px;
44
+ cursor: pointer;
45
+ font-size: 14px;
46
+ transition: all 0.2s;
47
+ }
48
+
49
+ .demo-button.success {
50
+ background: #52c41a;
51
+ color: white;
52
+ }
53
+
54
+ .demo-button.success:hover {
55
+ background: #389e0d;
56
+ }
57
+
58
+ .demo-button.error {
59
+ background: #ff4d4f;
60
+ color: white;
61
+ }
62
+
63
+ .demo-button.error:hover {
64
+ background: #cf1322;
65
+ }
66
+
67
+ .demo-button.loading {
68
+ background: #1890ff;
69
+ color: white;
70
+ }
71
+
72
+ .demo-button.loading:hover {
73
+ background: #096dd9;
74
+ }
75
+
76
+ .login-section {
77
+ text-align: center;
78
+ }
79
+ </style>
80
+ </head>
81
+
82
+ <body>
83
+ <div class="demo-container">
84
+ <div class="login-section">
85
+ <h2>登录组件</h2>
86
+ <kv-login method="password">
87
+ <div id="weixinLogin"></div>
88
+ </kv-login>
89
+ </div>
90
+ </div>
91
+ </body>
92
+
93
+ </html>
package/dist/app.d.ts DELETED
@@ -1,115 +0,0 @@
1
- interface KvMessageOptions {
2
- type?: 'success' | 'error' | 'loading';
3
- message: string;
4
- duration?: number;
5
- closable?: boolean;
6
- position?: 'center' | 'right';
7
- }
8
- declare class KvMessage extends HTMLElement {
9
- private options;
10
- private timer;
11
- constructor();
12
- connectedCallback(): void;
13
- setOptions(options: KvMessageOptions): void;
14
- private render;
15
- private setTimer;
16
- remove(): void;
17
- disconnectedCallback(): void;
18
- }
19
- declare class KvMessageManager {
20
- private static instance;
21
- private container;
22
- private defaultPosition;
23
- static getInstance(): KvMessageManager;
24
- setDefaultPosition(position: 'center' | 'right'): void;
25
- private getContainer;
26
- show(options: KvMessageOptions): KvMessage;
27
- success(message: string, options?: {
28
- duration?: number;
29
- position?: 'center' | 'right';
30
- closable?: boolean;
31
- }): KvMessage;
32
- error(message: string, options?: {
33
- duration?: number;
34
- position?: 'center' | 'right';
35
- closable?: boolean;
36
- }): KvMessage;
37
- loading(message: string, options?: {
38
- position?: 'center' | 'right';
39
- closable?: boolean;
40
- }): KvMessage;
41
- remove(message: KvMessage): void;
42
- clear(): void;
43
- }
44
- declare const createMessage: () => KvMessageManager;
45
- declare global {
46
- interface Window {
47
- createMessage: typeof createMessage;
48
- }
49
- }
50
-
51
- declare const clearCode: () => void;
52
- declare const checkPluginLogin: () => Promise<void>;
53
-
54
- interface EventData<T = any> {
55
- type: string;
56
- data: T;
57
- }
58
- type EventHandler<T = any> = (event: EventData<T>) => void;
59
- declare class EventEmitter {
60
- private events;
61
- /**
62
- * 监听事件
63
- * @param type 事件类型
64
- * @param handler 事件处理函数
65
- */
66
- on<T = any>(type: string, handler: EventHandler<T>): void;
67
- /**
68
- * 移除事件监听器
69
- * @param type 事件类型
70
- * @param handler 事件处理函数 (可选,如果不提供则移除该类型的所有监听器)
71
- */
72
- off<T = any>(type: string, handler?: EventHandler<T>): void;
73
- /**
74
- * 触发事件
75
- * @param event 事件对象,包含 type 和 data
76
- */
77
- emit<T = any>(event: EventData<T>): void;
78
- /**
79
- * 触发事件(简化版本,直接传递type和data)
80
- * @param type 事件类型
81
- * @param data 事件数据
82
- */
83
- emitSimple<T = any>(type: string, data: T): void;
84
- /**
85
- * 清空所有事件监听器
86
- */
87
- clear(): void;
88
- /**
89
- * 获取指定类型的监听器数量
90
- * @param type 事件类型
91
- * @returns 监听器数量
92
- */
93
- listenerCount(type: string): number;
94
- /**
95
- * 获取所有事件类型
96
- * @returns 事件类型数组
97
- */
98
- eventNames(): string[];
99
- /**
100
- * 检查是否有指定类型的监听器
101
- * @param type 事件类型
102
- * @returns 是否有监听器
103
- */
104
- hasListeners(type: string): boolean;
105
- /**
106
- * 只监听一次事件
107
- * @param type 事件类型
108
- * @param handler 事件处理函数
109
- */
110
- once<T = any>(type: string, handler: EventHandler<T>): void;
111
- }
112
-
113
- declare const loginEmitter: EventEmitter;
114
-
115
- export { checkPluginLogin, clearCode, loginEmitter };