@huyooo/ui 0.11.6 → 0.11.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.
@@ -1,345 +0,0 @@
1
- import { ref as v, computed as C } from "vue";
2
- import { f as p } from "./apiClients-KFp-rs-C.js";
3
- /* empty css */
4
- import { Message as m } from "@arco-design/web-vue";
5
- function q(e) {
6
- var o;
7
- const r = (o = e == null ? void 0 : e.metadata) == null ? void 0 : o.originalPrice;
8
- return typeof r == "number" ? r : void 0;
9
- }
10
- function K(e) {
11
- const r = q(e);
12
- return !e || r === void 0 || r <= e.unitAmount ? 0 : Math.round((1 - e.unitAmount / r) * 100);
13
- }
14
- function Q(e) {
15
- var f, u;
16
- const r = (f = e == null ? void 0 : e.metadata) == null ? void 0 : f.discountLabel;
17
- if (typeof r == "string" && r.trim())
18
- return r;
19
- const o = (u = e == null ? void 0 : e.metadata) == null ? void 0 : u.savingMonths;
20
- return typeof o == "number" && o > 0 ? `买 ${12 - o} 个月送 ${o} 个月` : "";
21
- }
22
- function k(e) {
23
- return e === void 0 ? 0 : Math.floor(e / 100);
24
- }
25
- function V(e, r = 1) {
26
- const o = r > 1 ? `每 ${r} ` : "按";
27
- switch (e) {
28
- case "month":
29
- return `${o}月订阅`;
30
- case "year":
31
- return `${o}年订阅`;
32
- case "day":
33
- return `${o}天订阅`;
34
- case "week":
35
- return `${o}周订阅`;
36
- default:
37
- return "";
38
- }
39
- }
40
- function _(e) {
41
- const r = e != null && e.intervalCount && e.intervalCount > 1 ? `${e.intervalCount} ` : "";
42
- switch (e == null ? void 0 : e.interval) {
43
- case "month":
44
- return `/ ${r}月`;
45
- case "year":
46
- return `/ ${r}年`;
47
- case "day":
48
- return `/ ${r}天`;
49
- case "week":
50
- return `/ ${r}周`;
51
- default:
52
- return "";
53
- }
54
- }
55
- function P(e) {
56
- switch (e) {
57
- case "day":
58
- return "每天";
59
- case "week":
60
- return "每周";
61
- case "month":
62
- return "每月";
63
- case "year":
64
- return "每年";
65
- case "lifetime":
66
- return "不重置";
67
- default:
68
- return "";
69
- }
70
- }
71
- function L(e) {
72
- if (e.type === "quota" && e.value !== void 0) {
73
- const r = P(e.quotaPeriod), o = r ? ` / ${r}` : "";
74
- return `${e.name}: ${e.value === -1 ? "无限" : e.value}${o}`;
75
- }
76
- if (e.type === "unlimited") {
77
- const r = P(e.quotaPeriod);
78
- return r ? `${e.name}: 不限 / ${r}` : `${e.name}不限`;
79
- }
80
- return e.type === "boolean" && e.value === !1 ? `${e.name}(不支持)` : e.name;
81
- }
82
- function h(e) {
83
- return e.type !== "recurring" || !e.interval ? null : {
84
- key: `${e.interval}:${e.intervalCount ?? 1}`,
85
- interval: e.interval,
86
- intervalCount: e.intervalCount ?? 1
87
- };
88
- }
89
- function z(e, r) {
90
- const o = {
91
- day: 1,
92
- week: 2,
93
- month: 3,
94
- year: 4
95
- };
96
- return o[e.interval] - o[r.interval] || e.intervalCount - r.intervalCount;
97
- }
98
- function E(e, r) {
99
- let o = 0;
100
- for (const f of e)
101
- for (const u of f.prices) {
102
- const a = h(u);
103
- (a == null ? void 0 : a.key) === r && (o = Math.max(o, K(u)));
104
- }
105
- return o > 0 ? `省 ${o}%` : void 0;
106
- }
107
- function H(e) {
108
- return e.includes(":") ? e : `${e}:1`;
109
- }
110
- function J() {
111
- return !!localStorage.getItem("jwtToken");
112
- }
113
- function ne(e = "month") {
114
- const r = v([]), o = v(null), f = v(!1), u = v(!1), a = v(H(e)), c = C(() => {
115
- const n = /* @__PURE__ */ new Map();
116
- for (const t of r.value)
117
- for (const l of t.prices) {
118
- const i = h(l);
119
- i && n.set(i.key, i);
120
- }
121
- return [...n.values()].sort(z).map((t) => ({
122
- value: t.key,
123
- label: V(t.interval, t.intervalCount),
124
- badge: E(r.value, t.key)
125
- }));
126
- }), g = C(() => {
127
- var t;
128
- const n = [];
129
- for (const l of r.value) {
130
- const i = l.prices.find((d) => {
131
- const s = h(d);
132
- return (s == null ? void 0 : s.key) === a.value;
133
- });
134
- i && n.push({
135
- ...l,
136
- features: (t = i.features) != null && t.length ? i.features : l.features,
137
- selectedPrice: i
138
- });
139
- }
140
- return n;
141
- });
142
- function M(n) {
143
- a.value = n;
144
- }
145
- function y(n) {
146
- const t = o.value;
147
- return t ? t.priceId && n.selectedPrice ? t.priceId === n.selectedPrice.id : t.productId === n.id : !1;
148
- }
149
- function $(n) {
150
- var t;
151
- return ((t = o.value) == null ? void 0 : t.productId) === n.id;
152
- }
153
- function b(n) {
154
- var t;
155
- return ((t = n.metadata) == null ? void 0 : t.recommended) === !0;
156
- }
157
- function B(n) {
158
- var t;
159
- return k((t = n.selectedPrice) == null ? void 0 : t.unitAmount);
160
- }
161
- function S(n) {
162
- const t = q(n.selectedPrice);
163
- return t === void 0 ? void 0 : k(t);
164
- }
165
- function x(n) {
166
- return _(n.selectedPrice);
167
- }
168
- function D(n) {
169
- return Q(n.selectedPrice);
170
- }
171
- function U(n) {
172
- return y(n) ? "当前方案" : b(n) ? "最受欢迎" : "";
173
- }
174
- function F(n) {
175
- const t = [];
176
- return y(n) ? t.push({
177
- label: "当前方案",
178
- type: "current"
179
- }) : b(n) && t.push({
180
- label: "最受欢迎",
181
- type: "recommended"
182
- }), t;
183
- }
184
- function j(n) {
185
- const t = o.value;
186
- return y(n) ? "当前方案" : t ? $(n) ? "切换周期" : typeof t.unitAmount == "number" && n.selectedPrice.unitAmount > t.unitAmount ? "升级方案" : "切换方案" : "立即订阅";
187
- }
188
- function G(n, t) {
189
- const l = n.features.find((i) => i.type === "quota" && i.value !== void 0);
190
- if (l) {
191
- const i = P(l.quotaPeriod), d = l.value === -1 ? "不限量" : l.value;
192
- return `${l.name} ${i ? `${d} / ${i}` : d},覆盖核心使用场景。`;
193
- }
194
- return t === 1 ? "为正式团队准备的高配能力组合。" : "包含入门所需的核心能力。";
195
- }
196
- function T(n) {
197
- return n.filter((t) => t.highlight !== !1).map((t) => ({
198
- title: L(t),
199
- description: t.description || ""
200
- }));
201
- }
202
- function O(n) {
203
- const t = n.filter((s) => s.highlight !== !1), l = t.filter((s) => s.type === "quota" || s.type === "unlimited").map((s) => ({
204
- title: L(s),
205
- description: s.description || ""
206
- })), i = t.filter((s) => s.type === "boolean" && s.value !== !1).map((s) => ({
207
- title: s.name,
208
- description: s.description || ""
209
- })), d = [];
210
- return i.length && d.push({
211
- title: "功能特性",
212
- items: i
213
- }), l.length && d.push({
214
- title: "用量配额",
215
- items: l
216
- }), d;
217
- }
218
- async function I() {
219
- f.value = !0;
220
- try {
221
- const {
222
- data: n,
223
- error: t
224
- } = await p.products.listActive.post();
225
- if (t) {
226
- console.error("加载产品列表失败", t);
227
- return;
228
- }
229
- r.value = Array.isArray(n) ? n : [], !c.value.some((i) => i.value === a.value) && c.value[0] && (a.value = c.value[0].value);
230
- } finally {
231
- f.value = !1;
232
- }
233
- }
234
- async function w() {
235
- if (!J()) {
236
- o.value = null;
237
- return;
238
- }
239
- u.value = !0;
240
- try {
241
- const {
242
- data: n,
243
- error: t
244
- } = await p.subscriptions.summary.post();
245
- if (t) {
246
- console.error("加载当前订阅失败", t);
247
- return;
248
- }
249
- o.value = (n == null ? void 0 : n.current) ?? null;
250
- } finally {
251
- u.value = !1;
252
- }
253
- }
254
- async function R() {
255
- await Promise.all([I(), w()]);
256
- }
257
- return {
258
- products: r,
259
- plans: g,
260
- currentSubscription: o,
261
- listLoading: f,
262
- currentLoading: u,
263
- billingInterval: a,
264
- billingIntervalTabs: c,
265
- setBillingInterval: M,
266
- isCurrentPlan: y,
267
- isSameProduct: $,
268
- isRecommendedPlan: b,
269
- getDisplayPrice: B,
270
- getDisplayOriginalPrice: S,
271
- getDisplayCycle: x,
272
- getPromotionLabel: D,
273
- getBadgeLabel: U,
274
- getBadgeLabels: F,
275
- getButtonLabel: j,
276
- getPlanSummary: G,
277
- getFeatureItems: T,
278
- getFeatureGroups: O,
279
- loadProducts: I,
280
- loadCurrentSubscription: w,
281
- refresh: R
282
- };
283
- }
284
- function N(e) {
285
- window.open(e, "_blank", "noopener,noreferrer");
286
- }
287
- function A(e) {
288
- return e && typeof e == "object" && "message" in e && typeof e.message == "string" ? e.message : "";
289
- }
290
- function W(e) {
291
- return e && typeof e == "object" && "alipayUrl" in e && typeof e.alipayUrl == "string" ? e.alipayUrl : "";
292
- }
293
- function X(e) {
294
- return e && typeof e == "object" && "status" in e && e.status === "trialing";
295
- }
296
- function re(e) {
297
- const r = v(null);
298
- async function o(u) {
299
- if (!u.selectedPrice) {
300
- m.warning("当前方案暂无可购买价格");
301
- return;
302
- }
303
- const a = e.currentSubscription.value;
304
- if ((a == null ? void 0 : a.priceId) === u.selectedPrice.id) {
305
- m.info("当前已经是该方案");
306
- return;
307
- }
308
- r.value = u.id;
309
- try {
310
- const c = a ? await p.subscriptions.change.post({
311
- subscriptionId: a.id,
312
- newPriceId: u.selectedPrice.id,
313
- proration: !0
314
- }) : await p.subscriptions.create.post({
315
- priceId: u.selectedPrice.id
316
- });
317
- if (c.error) {
318
- m.error(c.error.message || "订阅操作失败");
319
- return;
320
- }
321
- const g = W(c.data);
322
- if (g) {
323
- N(g);
324
- return;
325
- }
326
- X(c.data) ? m.success(A(c.data) || "试用已开始") : m.success(A(c.data) || "订阅已更新"), await e.refreshCurrentSubscription();
327
- } catch (c) {
328
- console.error("订阅操作失败", c), m.error("订阅操作失败,请稍后重试");
329
- } finally {
330
- r.value = null;
331
- }
332
- }
333
- function f(u) {
334
- return r.value === u.id;
335
- }
336
- return {
337
- checkoutPlanId: r,
338
- checkout: o,
339
- isCheckingOut: f
340
- };
341
- }
342
- export {
343
- re as a,
344
- ne as u
345
- };