@huyooo/ui 0.4.13 → 0.4.16
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/{AuthkitAppSetting-iL2SVGkm.js → AuthkitAppSetting-MYrqMZAf.js} +391 -390
- package/dist/{AuthkitAuthorize-CLG8uEWI.js → AuthkitAuthorize-CCSa1q9E.js} +1 -1
- package/dist/{UserPanel-CsWfMpZO.js → UserPanel-CvWoQ9nn.js} +203 -179
- package/dist/authkit.js +3 -3
- package/dist/common.js +1 -1
- package/dist/components/Feedback/FeedbackBubbleEnd.vue.d.ts +1 -1
- package/dist/components/Feedback/FeedbackBubbleStart.vue.d.ts +1 -1
- package/dist/composables/Authkit/useAuthkitAuth.d.ts +9 -0
- package/dist/composables/Authkit/useAuthkitUsersProfile.d.ts +3 -0
- package/dist/composables.js +1 -1
- package/dist/index.js +4 -4
- package/dist/style.css +1 -1
- package/dist/useAuthkitProps-BM6B7mZP.js +384 -0
- package/dist/user.js +1 -1
- package/dist/utils/authGuard.d.ts +12 -0
- package/package.json +1 -1
- package/dist/useAuthkitProps-DB04dGw9.js +0 -326
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { ref as n, readonly as z, computed as k } from "vue";
|
|
2
|
+
import { api as s } from "@huyooo/api";
|
|
3
|
+
function Q(e, t) {
|
|
4
|
+
return s({
|
|
5
|
+
url: `${e}/restfulApi/apps/findOne`,
|
|
6
|
+
method: "post",
|
|
7
|
+
data: t
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function V() {
|
|
11
|
+
return s({
|
|
12
|
+
url: "/restfulApi/apps/authPageInfo",
|
|
13
|
+
method: "post"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const l = n({
|
|
17
|
+
id: "",
|
|
18
|
+
appKey: "",
|
|
19
|
+
name: "",
|
|
20
|
+
description: "",
|
|
21
|
+
homePageUrl: "",
|
|
22
|
+
applicationLogo: "",
|
|
23
|
+
applicationLogoUrl: "",
|
|
24
|
+
oauth: {
|
|
25
|
+
google: {
|
|
26
|
+
// redirectURI: '',
|
|
27
|
+
// clientID: '',
|
|
28
|
+
// clientSecret: '',
|
|
29
|
+
enabled: !1
|
|
30
|
+
},
|
|
31
|
+
microsoft: {
|
|
32
|
+
// redirectURI: '',
|
|
33
|
+
// clientID: '',
|
|
34
|
+
// clientSecret: '',
|
|
35
|
+
enabled: !1
|
|
36
|
+
},
|
|
37
|
+
github: {
|
|
38
|
+
// redirectURI: '',
|
|
39
|
+
// clientID: '',
|
|
40
|
+
// clientSecret: '',
|
|
41
|
+
enabled: !1
|
|
42
|
+
},
|
|
43
|
+
wechat: {
|
|
44
|
+
// redirectURI: '',
|
|
45
|
+
// clientID: '',
|
|
46
|
+
// clientSecret: '',
|
|
47
|
+
enabled: !1
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
authorizationCallback: "",
|
|
51
|
+
aboutUs: {
|
|
52
|
+
// 个人信息收集清单
|
|
53
|
+
personalInformationCollectionList: {
|
|
54
|
+
type: "doc",
|
|
55
|
+
content: []
|
|
56
|
+
},
|
|
57
|
+
// 第三方信息共享清单
|
|
58
|
+
thirdPartyInformationSharingList: {
|
|
59
|
+
type: "doc",
|
|
60
|
+
content: []
|
|
61
|
+
},
|
|
62
|
+
// 用户服务协议
|
|
63
|
+
userServiceAgreement: {
|
|
64
|
+
type: "doc",
|
|
65
|
+
content: []
|
|
66
|
+
},
|
|
67
|
+
// 隐私协议
|
|
68
|
+
privacyPolicy: {
|
|
69
|
+
type: "doc",
|
|
70
|
+
content: []
|
|
71
|
+
},
|
|
72
|
+
// 证照信息
|
|
73
|
+
licenseInformation: {
|
|
74
|
+
type: "doc",
|
|
75
|
+
content: []
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
brand: {
|
|
79
|
+
theme: "dark",
|
|
80
|
+
logo: "",
|
|
81
|
+
favicon: "",
|
|
82
|
+
backgroundType: "image",
|
|
83
|
+
backgroundColor: "",
|
|
84
|
+
backgroundImageUrl: "",
|
|
85
|
+
backgroundImage: "/66a0d5b35203890887f0e1a4/6714e2458fe86895bf3da8ae/1ef8ed72-1731-6e00-93d1-fa24165f1a3e.webp"
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
function W() {
|
|
89
|
+
function e(t) {
|
|
90
|
+
V().then(({
|
|
91
|
+
data: a
|
|
92
|
+
}) => {
|
|
93
|
+
l.value.id = a.id, l.value.appKey = a.appKey, l.value.name = a.name, l.value.description = a.description, l.value.homePageUrl = a.homePageUrl, l.value.applicationLogo = a.applicationLogo, l.value.applicationLogoUrl = a.applicationLogoUrl, l.value.oauth = a.oauth, l.value.authorizationCallback = a.authorizationCallback, l.value.aboutUs = a.aboutUs, l.value.brand = a.brand, t && t();
|
|
94
|
+
}).catch((a) => {
|
|
95
|
+
console.error("获取应用认证页面信息失败:", a);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
appsData: l,
|
|
100
|
+
appsAuthPageInfoApi: e
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function E(e) {
|
|
104
|
+
return s({
|
|
105
|
+
url: "/restfulApi/auth/signIn",
|
|
106
|
+
method: "post",
|
|
107
|
+
data: e
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function x(e) {
|
|
111
|
+
return s({
|
|
112
|
+
url: "/restfulApi/auth/resetPassword",
|
|
113
|
+
method: "post",
|
|
114
|
+
data: e
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function F(e) {
|
|
118
|
+
return s({
|
|
119
|
+
url: "/restfulApi/auth/signUp",
|
|
120
|
+
method: "post",
|
|
121
|
+
data: e
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function X(e) {
|
|
125
|
+
return s({
|
|
126
|
+
url: "/restfulApi/oauth2/authorize",
|
|
127
|
+
method: "post",
|
|
128
|
+
data: e
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const h = n("signIn"), U = [], w = [], y = [], f = n(null);
|
|
132
|
+
function C() {
|
|
133
|
+
try {
|
|
134
|
+
const e = localStorage.getItem("jwtToken");
|
|
135
|
+
if (e)
|
|
136
|
+
return f.value = e, !0;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.warn("Failed to access localStorage:", e);
|
|
139
|
+
}
|
|
140
|
+
return !1;
|
|
141
|
+
}
|
|
142
|
+
function R() {
|
|
143
|
+
if (f.value)
|
|
144
|
+
return f.value;
|
|
145
|
+
try {
|
|
146
|
+
const e = localStorage.getItem("jwtToken");
|
|
147
|
+
return e && (f.value = e), e;
|
|
148
|
+
} catch (e) {
|
|
149
|
+
return console.warn("Failed to access localStorage:", e), null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function I(e) {
|
|
153
|
+
f.value = e;
|
|
154
|
+
try {
|
|
155
|
+
localStorage.setItem("jwtToken", e);
|
|
156
|
+
} catch (t) {
|
|
157
|
+
console.warn("Failed to save token to localStorage:", t);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function q() {
|
|
161
|
+
f.value = null;
|
|
162
|
+
try {
|
|
163
|
+
localStorage.removeItem("jwtToken");
|
|
164
|
+
} catch (e) {
|
|
165
|
+
console.warn("Failed to clear localStorage:", e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function $(e) {
|
|
169
|
+
U.push(e);
|
|
170
|
+
}
|
|
171
|
+
function K(e) {
|
|
172
|
+
w.push(e);
|
|
173
|
+
}
|
|
174
|
+
function O(e) {
|
|
175
|
+
y.push(e);
|
|
176
|
+
}
|
|
177
|
+
function Z() {
|
|
178
|
+
const e = n(!1), t = n(!1), a = n(!1);
|
|
179
|
+
function d(u) {
|
|
180
|
+
e.value = !0, E({
|
|
181
|
+
email: u.email,
|
|
182
|
+
password: u.password
|
|
183
|
+
}).then(({
|
|
184
|
+
data: r
|
|
185
|
+
}) => {
|
|
186
|
+
e.value = !1, I(r.jwtToken), U.forEach((j) => j(r));
|
|
187
|
+
}).catch((r) => {
|
|
188
|
+
e.value = !1, console.error("登录失败:", r);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function o(u) {
|
|
192
|
+
t.value = !0, F({
|
|
193
|
+
email: u.email,
|
|
194
|
+
userToken: u.userToken,
|
|
195
|
+
emailVerifyId: u.emailVerifyId,
|
|
196
|
+
password: u.password,
|
|
197
|
+
source: "searchEngine",
|
|
198
|
+
isRecommend: !1
|
|
199
|
+
}).then(() => {
|
|
200
|
+
t.value = !1, h.value = "signIn", w.forEach((r) => r());
|
|
201
|
+
}).catch((r) => {
|
|
202
|
+
t.value = !1, console.error("注册失败:", r);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function P(u) {
|
|
206
|
+
a.value = !0, x({
|
|
207
|
+
email: u.email,
|
|
208
|
+
userToken: u.userToken,
|
|
209
|
+
emailVerifyId: u.emailVerifyId,
|
|
210
|
+
password: u.password
|
|
211
|
+
}).then(() => {
|
|
212
|
+
a.value = !1, h.value = "signIn", y.forEach((r) => r());
|
|
213
|
+
}).catch((r) => {
|
|
214
|
+
a.value = !1, console.error("重置密码失败:", r);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function S() {
|
|
218
|
+
h.value = "signUp";
|
|
219
|
+
}
|
|
220
|
+
function T() {
|
|
221
|
+
h.value = "resetPassword";
|
|
222
|
+
}
|
|
223
|
+
function L() {
|
|
224
|
+
h.value = "signIn";
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
signInSubmit: d,
|
|
228
|
+
signUpSubmit: o,
|
|
229
|
+
resetPasswordSubmit: P,
|
|
230
|
+
currentView: h,
|
|
231
|
+
authSignInLoading: e,
|
|
232
|
+
authSignUpLoading: t,
|
|
233
|
+
resetPasswordLoading: a,
|
|
234
|
+
switchSignUp: S,
|
|
235
|
+
switchResetPassword: T,
|
|
236
|
+
switchSignIn: L,
|
|
237
|
+
addSignInCallback: $,
|
|
238
|
+
addSignUpCallback: K,
|
|
239
|
+
addResetPasswordCallback: O,
|
|
240
|
+
// 简化的token管理
|
|
241
|
+
jwtToken: z(f),
|
|
242
|
+
getToken: R,
|
|
243
|
+
setToken: I,
|
|
244
|
+
initializeAuth: C,
|
|
245
|
+
clearAuth: q
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const B = n(!1);
|
|
249
|
+
function Y() {
|
|
250
|
+
return {
|
|
251
|
+
show: B
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function D(e) {
|
|
255
|
+
return s({
|
|
256
|
+
url: "/restfulApi/users/profile",
|
|
257
|
+
method: "post",
|
|
258
|
+
data: e
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function _(e) {
|
|
262
|
+
return s({
|
|
263
|
+
url: "/restfulApi/users/update/baseInfo",
|
|
264
|
+
method: "post",
|
|
265
|
+
data: e
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function ee(e) {
|
|
269
|
+
return s({
|
|
270
|
+
url: "/restfulApi/users/update/email",
|
|
271
|
+
method: "post",
|
|
272
|
+
data: e
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function te(e) {
|
|
276
|
+
return s({
|
|
277
|
+
url: "/restfulApi/users/update/password",
|
|
278
|
+
method: "post",
|
|
279
|
+
data: e
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function oe() {
|
|
283
|
+
return s({
|
|
284
|
+
url: "/restfulApi/users//unbind/email",
|
|
285
|
+
method: "post"
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const i = n(null), b = n(!1), M = k(() => !!i.value);
|
|
289
|
+
async function N() {
|
|
290
|
+
var d;
|
|
291
|
+
const {
|
|
292
|
+
getToken: e,
|
|
293
|
+
clearAuth: t
|
|
294
|
+
} = Z();
|
|
295
|
+
if (!e()) {
|
|
296
|
+
console.warn("No authentication token found"), i.value = null;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
b.value = !0;
|
|
300
|
+
try {
|
|
301
|
+
const {
|
|
302
|
+
data: o
|
|
303
|
+
} = await D();
|
|
304
|
+
o ? i.value = o : (console.warn("获取用户资料返回空数据"), i.value = null);
|
|
305
|
+
} catch (o) {
|
|
306
|
+
console.error("获取用户资料失败:", o), ((d = o == null ? void 0 : o.response) == null ? void 0 : d.status) === 401 && (console.warn("认证已过期,清除认证状态"), t()), i.value = null;
|
|
307
|
+
} finally {
|
|
308
|
+
b.value = !1;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function G() {
|
|
312
|
+
i.value = null;
|
|
313
|
+
}
|
|
314
|
+
function ae() {
|
|
315
|
+
return {
|
|
316
|
+
userProfile: i,
|
|
317
|
+
loading: b,
|
|
318
|
+
isLoggedIn: M,
|
|
319
|
+
// 新增:基于userProfile的登录状态
|
|
320
|
+
fetchUserProfile: N,
|
|
321
|
+
clearUserProfile: G
|
|
322
|
+
// 新增:清除用户信息的方法
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const c = n(""), g = n("/api"), v = n(""), p = n(""), m = n("ap-beijing");
|
|
326
|
+
function A() {
|
|
327
|
+
const e = [], t = [];
|
|
328
|
+
return c.value || (e.push("appId"), t.push("appId is required for Authkit")), p.value || (e.push("bucketId"), t.push("bucketId is required for Authkit")), v.value || (e.push("bucket"), t.push("bucket is required for Authkit")), c.value && !/^[a-zA-Z0-9]{24}$/.test(c.value) && t.push("appId format is invalid (should be 24 character alphanumeric)"), p.value && !/^[a-zA-Z0-9]{24}$/.test(p.value) && t.push("bucketId format is invalid (should be 24 character alphanumeric)"), {
|
|
329
|
+
isValid: e.length === 0 && t.length === 0,
|
|
330
|
+
missingFields: e,
|
|
331
|
+
errors: t
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function ne() {
|
|
335
|
+
const e = k(() => A()), t = k(() => ({
|
|
336
|
+
appId: c.value,
|
|
337
|
+
prefixUrl: g.value,
|
|
338
|
+
bucket: v.value,
|
|
339
|
+
bucketId: p.value,
|
|
340
|
+
region: m.value
|
|
341
|
+
}));
|
|
342
|
+
function a(o) {
|
|
343
|
+
o.appId !== void 0 && (c.value = o.appId), o.prefixUrl !== void 0 && (g.value = o.prefixUrl), o.bucket !== void 0 && (v.value = o.bucket), o.bucketId !== void 0 && (p.value = o.bucketId), o.region !== void 0 && (m.value = o.region);
|
|
344
|
+
}
|
|
345
|
+
function d() {
|
|
346
|
+
const o = A();
|
|
347
|
+
if (!o.isValid)
|
|
348
|
+
throw new Error(`Authkit configuration incomplete: ${o.errors.join(", ")}`);
|
|
349
|
+
return {
|
|
350
|
+
appId: c.value,
|
|
351
|
+
prefixUrl: g.value,
|
|
352
|
+
bucket: v.value,
|
|
353
|
+
bucketId: p.value,
|
|
354
|
+
region: m.value
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
// 原有的 ref 访问方式(向后兼容)
|
|
359
|
+
appId: c,
|
|
360
|
+
prefixUrl: g,
|
|
361
|
+
bucket: v,
|
|
362
|
+
bucketId: p,
|
|
363
|
+
region: m,
|
|
364
|
+
// 新增的类型安全功能
|
|
365
|
+
config: t,
|
|
366
|
+
validation: e,
|
|
367
|
+
setConfig: a,
|
|
368
|
+
getRequiredConfig: d
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
export {
|
|
372
|
+
W as U,
|
|
373
|
+
ae as a,
|
|
374
|
+
Y as b,
|
|
375
|
+
ne as c,
|
|
376
|
+
Q as d,
|
|
377
|
+
D as e,
|
|
378
|
+
_ as f,
|
|
379
|
+
te as g,
|
|
380
|
+
ee as h,
|
|
381
|
+
oe as i,
|
|
382
|
+
X as o,
|
|
383
|
+
Z as u
|
|
384
|
+
};
|
package/dist/user.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 认证守卫 - 检查用户登录状态
|
|
3
|
+
* @param action 需要执行的操作
|
|
4
|
+
* @param redirectToLogin 是否在未登录时显示登录弹窗
|
|
5
|
+
* @returns 是否允许执行操作
|
|
6
|
+
*/
|
|
7
|
+
export declare function useAuthGuard(): {
|
|
8
|
+
isLoggedIn: import('vue').ComputedRef<boolean>;
|
|
9
|
+
requireAuth: (showLoginIfNeeded?: boolean) => boolean;
|
|
10
|
+
withAuth: <T extends (...args: any[]) => any>(fn: T, showLoginIfNeeded?: boolean) => T;
|
|
11
|
+
withAuthAsync: <T extends (...args: any[]) => Promise<any>>(fn: T, showLoginIfNeeded?: boolean) => T;
|
|
12
|
+
};
|