@huyooo/ui 0.11.7 → 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,26 +1,26 @@
1
- import { ref as g, computed as B } from "vue";
1
+ import { ref as y, computed as q } from "vue";
2
2
  import { f as h } from "./apiClients-KFp-rs-C.js";
3
3
  /* empty css */
4
- import { Message as v } from "@arco-design/web-vue";
5
- import { u as H } from "./useEnsureAuthenticated-D78tsddF.js";
6
- function F(e) {
4
+ import { Message as g } from "@arco-design/web-vue";
5
+ import { u as J } from "./useEnsureAuthenticated-D78tsddF.js";
6
+ function x(e) {
7
7
  var i;
8
8
  const n = (i = e == null ? void 0 : e.metadata) == null ? void 0 : i.originalPrice;
9
9
  return typeof n == "number" ? n : void 0;
10
10
  }
11
- function J(e) {
12
- const n = F(e);
11
+ function N(e) {
12
+ const n = x(e);
13
13
  return !e || n === void 0 || n <= e.unitAmount ? 0 : Math.round((1 - e.unitAmount / n) * 100);
14
14
  }
15
- function N(e) {
16
- var f, d;
17
- const n = (f = e == null ? void 0 : e.metadata) == null ? void 0 : f.discountLabel;
15
+ function W(e) {
16
+ var l, f;
17
+ const n = (l = e == null ? void 0 : e.metadata) == null ? void 0 : l.discountLabel;
18
18
  if (typeof n == "string" && n.trim())
19
19
  return n;
20
- const i = (d = e == null ? void 0 : e.metadata) == null ? void 0 : d.savingMonths;
20
+ const i = (f = e == null ? void 0 : e.metadata) == null ? void 0 : f.savingMonths;
21
21
  return typeof i == "number" && i > 0 ? `买 ${12 - i} 个月送 ${i} 个月` : "";
22
22
  }
23
- function D(e) {
23
+ function B(e) {
24
24
  return e === void 0 ? 0 : Math.floor(e / 100);
25
25
  }
26
26
  function X(e, n = 1) {
@@ -53,7 +53,7 @@ function Y(e) {
53
53
  return "";
54
54
  }
55
55
  }
56
- function k(e) {
56
+ function w(e) {
57
57
  switch (e) {
58
58
  case "day":
59
59
  return "每天";
@@ -69,18 +69,18 @@ function k(e) {
69
69
  return "";
70
70
  }
71
71
  }
72
- function M(e) {
72
+ function D(e) {
73
73
  if (e.type === "quota" && e.value !== void 0) {
74
- const n = k(e.quotaPeriod), i = n ? ` / ${n}` : "";
74
+ const n = w(e.quotaPeriod), i = n ? ` / ${n}` : "";
75
75
  return `${e.name}: ${e.value === -1 ? "无限" : e.value}${i}`;
76
76
  }
77
77
  if (e.type === "unlimited") {
78
- const n = k(e.quotaPeriod);
78
+ const n = w(e.quotaPeriod);
79
79
  return n ? `${e.name}: 不限 / ${n}` : `${e.name}不限`;
80
80
  }
81
81
  return e.type === "boolean" && e.value === !1 ? `${e.name}(不支持)` : e.name;
82
82
  }
83
- function A(e) {
83
+ function C(e) {
84
84
  return e.type !== "recurring" || !e.interval ? null : {
85
85
  key: `${e.interval}:${e.intervalCount ?? 1}`,
86
86
  interval: e.interval,
@@ -98,25 +98,25 @@ function Z(e, n) {
98
98
  }
99
99
  function ee(e, n) {
100
100
  let i = 0;
101
- for (const f of e)
102
- for (const d of f.prices) {
103
- const o = A(d);
104
- (o == null ? void 0 : o.key) === n && (i = Math.max(i, J(d)));
101
+ for (const l of e)
102
+ for (const f of l.prices) {
103
+ const s = C(f);
104
+ (s == null ? void 0 : s.key) === n && (i = Math.max(i, N(f)));
105
105
  }
106
106
  return i > 0 ? `省 ${i}%` : void 0;
107
107
  }
108
108
  function te(e) {
109
109
  return e.includes(":") ? e : `${e}:1`;
110
110
  }
111
- function x() {
111
+ function M() {
112
112
  return !!localStorage.getItem("jwtToken");
113
113
  }
114
- function fe(e = "month") {
115
- const n = g([]), i = g(null), f = g(null), d = g(!1), o = g(!1), l = g(te(e)), a = B(() => {
114
+ function le(e = "month") {
115
+ const n = y([]), i = y(null), l = y(null), f = y(!1), s = y(!1), d = y(te(e)), a = q(() => {
116
116
  const t = /* @__PURE__ */ new Map();
117
117
  for (const r of n.value)
118
118
  for (const u of r.prices) {
119
- const c = A(u);
119
+ const c = C(u);
120
120
  c && t.set(c.key, c);
121
121
  }
122
122
  return [...t.values()].sort(Z).map((r) => ({
@@ -124,107 +124,107 @@ function fe(e = "month") {
124
124
  label: X(r.interval, r.intervalCount),
125
125
  badge: ee(n.value, r.key)
126
126
  }));
127
- }), $ = B(() => {
127
+ }), b = q(() => {
128
128
  var r;
129
129
  const t = [];
130
130
  for (const u of n.value) {
131
- const c = u.prices.find((b) => {
132
- const w = A(b);
133
- return (w == null ? void 0 : w.key) === l.value;
134
- }), m = u.prices.find((b) => b.type === "free"), s = c ?? (m && u.prices.every((b) => b.type === "free") ? m : void 0);
135
- s && t.push({
131
+ const c = u.prices.find((p) => {
132
+ const I = C(p);
133
+ return (I == null ? void 0 : I.key) === d.value;
134
+ }), m = u.prices.find((p) => p.type === "free"), o = c ?? (m && u.prices.every((p) => p.type === "free") ? m : void 0);
135
+ o && t.push({
136
136
  ...u,
137
- features: (r = s.features) != null && r.length ? s.features : u.features,
138
- selectedPrice: s
137
+ features: (r = o.features) != null && r.length ? o.features : u.features,
138
+ selectedPrice: o
139
139
  });
140
140
  }
141
141
  return t;
142
142
  });
143
- function P(t) {
144
- l.value = t;
143
+ function F(t) {
144
+ d.value = t;
145
145
  }
146
- function p(t) {
147
- const r = i.value, u = f.value;
146
+ function P(t) {
147
+ const r = i.value, u = l.value;
148
148
  return r != null && r.priceId && t.selectedPrice ? r.priceId === t.selectedPrice.id : r ? r.productId === t.id : u != null && u.priceId && t.selectedPrice ? u.priceId === t.selectedPrice.id : u ? u.productId === t.id : !1;
149
149
  }
150
- function L(t) {
150
+ function k(t) {
151
151
  var r;
152
152
  return ((r = i.value) == null ? void 0 : r.productId) === t.id;
153
153
  }
154
- function y(t) {
154
+ function v(t) {
155
155
  var r;
156
156
  return ((r = t.selectedPrice) == null ? void 0 : r.type) === "free";
157
157
  }
158
- function T() {
158
+ function U() {
159
159
  return !!i.value;
160
160
  }
161
- function U(t) {
162
- return !!(!t.selectedPrice || p(t) || y(t) && T());
161
+ function T(t) {
162
+ return !!(!t.selectedPrice || P(t) || v(t) && U());
163
163
  }
164
- function I(t) {
164
+ function $(t) {
165
165
  var r;
166
166
  return ((r = t.metadata) == null ? void 0 : r.recommended) === !0;
167
167
  }
168
168
  function j(t) {
169
169
  var r;
170
- return D((r = t.selectedPrice) == null ? void 0 : r.unitAmount);
170
+ return B((r = t.selectedPrice) == null ? void 0 : r.unitAmount);
171
171
  }
172
172
  function G(t) {
173
- const r = F(t.selectedPrice);
174
- return r === void 0 ? void 0 : D(r);
173
+ const r = x(t.selectedPrice);
174
+ return r === void 0 ? void 0 : B(r);
175
175
  }
176
176
  function O(t) {
177
- return y(t) ? "" : Y(t.selectedPrice);
177
+ return v(t) ? "" : Y(t.selectedPrice);
178
178
  }
179
179
  function R(t) {
180
180
  var r;
181
- if (y(t)) {
181
+ if (v(t)) {
182
182
  const u = (r = t.selectedPrice) == null ? void 0 : r.trialPeriodDays;
183
183
  return u ? `${u} 天免费体验` : "免费体验";
184
184
  }
185
- return N(t.selectedPrice);
185
+ return W(t.selectedPrice);
186
186
  }
187
187
  function E(t) {
188
- return p(t) ? "当前方案" : I(t) ? "最受欢迎" : "";
188
+ return P(t) ? "当前方案" : $(t) ? "最受欢迎" : "";
189
189
  }
190
190
  function K(t) {
191
191
  const r = [];
192
- return p(t) ? r.push({
192
+ return P(t) ? r.push({
193
193
  label: "当前方案",
194
194
  type: "current"
195
- }) : y(t) ? r.push({
195
+ }) : v(t) ? r.push({
196
196
  label: "免费体验",
197
197
  type: "trial"
198
- }) : I(t) && r.push({
198
+ }) : $(t) && r.push({
199
199
  label: "最受欢迎",
200
200
  type: "recommended"
201
201
  }), r;
202
202
  }
203
203
  function Q(t) {
204
204
  const r = i.value;
205
- return p(t) ? "当前方案" : y(t) ? r ? "已订阅付费方案" : x() ? "免费开通" : "免费注册" : r ? L(t) ? "切换周期" : typeof r.unitAmount == "number" && t.selectedPrice.unitAmount > r.unitAmount ? "升级方案" : "切换方案" : "立即订阅";
205
+ return P(t) ? "当前方案" : v(t) ? r ? "已订阅付费方案" : M() ? "免费开通" : "免费注册" : r ? k(t) ? "切换周期" : typeof r.unitAmount == "number" && t.selectedPrice.unitAmount > r.unitAmount ? "升级方案" : "切换方案" : "立即订阅";
206
206
  }
207
207
  function V(t, r) {
208
208
  const u = t.features.find((c) => c.type === "quota" && c.value !== void 0);
209
209
  if (u) {
210
- const c = k(u.quotaPeriod), m = u.value === -1 ? "不限量" : u.value;
210
+ const c = w(u.quotaPeriod), m = u.value === -1 ? "不限量" : u.value;
211
211
  return `${u.name} ${c ? `${m} / ${c}` : m},覆盖核心使用场景。`;
212
212
  }
213
- return y(t) ? "注册后自动开通免费权益,适合先体验核心能力。" : r === 1 ? "为正式团队准备的高配能力组合。" : "包含入门所需的核心能力。";
213
+ return v(t) ? "注册后自动开通免费权益,适合先体验核心能力。" : r === 1 ? "为正式团队准备的高配能力组合。" : "包含入门所需的核心能力。";
214
214
  }
215
- function W(t) {
215
+ function _(t) {
216
216
  return t.filter((r) => r.highlight !== !1).map((r) => ({
217
- title: M(r),
217
+ title: D(r),
218
218
  description: r.description || ""
219
219
  }));
220
220
  }
221
- function _(t) {
222
- const r = t.filter((s) => s.highlight !== !1), u = r.filter((s) => s.type === "quota" || s.type === "unlimited").map((s) => ({
223
- title: M(s),
224
- description: s.description || ""
225
- })), c = r.filter((s) => s.type === "boolean" && s.value !== !1).map((s) => ({
226
- title: s.name,
227
- description: s.description || ""
221
+ function z(t) {
222
+ const r = t.filter((o) => o.highlight !== !1), u = r.filter((o) => o.type === "quota" || o.type === "unlimited").map((o) => ({
223
+ title: D(o),
224
+ description: o.description || ""
225
+ })), c = r.filter((o) => o.type === "boolean" && o.value !== !1).map((o) => ({
226
+ title: o.name,
227
+ description: o.description || ""
228
228
  })), m = [];
229
229
  return c.length && m.push({
230
230
  title: "功能特性",
@@ -234,8 +234,8 @@ function fe(e = "month") {
234
234
  items: u
235
235
  }), m;
236
236
  }
237
- async function q() {
238
- d.value = !0;
237
+ async function A() {
238
+ f.value = !0;
239
239
  try {
240
240
  const {
241
241
  data: t,
@@ -245,17 +245,17 @@ function fe(e = "month") {
245
245
  console.error("加载产品列表失败", r);
246
246
  return;
247
247
  }
248
- n.value = Array.isArray(t) ? t : [], !a.value.some((c) => c.value === l.value) && a.value[0] && (l.value = a.value[0].value);
248
+ n.value = Array.isArray(t) ? t : [], !a.value.some((c) => c.value === d.value) && a.value[0] && (d.value = a.value[0].value);
249
249
  } finally {
250
- d.value = !1;
250
+ f.value = !1;
251
251
  }
252
252
  }
253
- async function S() {
254
- if (!x()) {
253
+ async function L() {
254
+ if (!M()) {
255
255
  i.value = null;
256
256
  return;
257
257
  }
258
- o.value = !0;
258
+ s.value = !0;
259
259
  try {
260
260
  const {
261
261
  data: t,
@@ -265,29 +265,29 @@ function fe(e = "month") {
265
265
  console.error("加载当前订阅失败", r);
266
266
  return;
267
267
  }
268
- i.value = (t == null ? void 0 : t.current) ?? null, f.value = (t == null ? void 0 : t.trial) ?? null;
268
+ i.value = (t == null ? void 0 : t.current) ?? null, l.value = (t == null ? void 0 : t.trial) ?? null;
269
269
  } finally {
270
- o.value = !1;
270
+ s.value = !1;
271
271
  }
272
272
  }
273
- async function z() {
274
- await Promise.all([q(), S()]);
273
+ async function H() {
274
+ await Promise.all([A(), L()]);
275
275
  }
276
276
  return {
277
277
  products: n,
278
- plans: $,
278
+ plans: b,
279
279
  currentSubscription: i,
280
- currentTrial: f,
281
- listLoading: d,
282
- currentLoading: o,
283
- billingInterval: l,
280
+ currentTrial: l,
281
+ listLoading: f,
282
+ currentLoading: s,
283
+ billingInterval: d,
284
284
  billingIntervalTabs: a,
285
- setBillingInterval: P,
286
- isCurrentPlan: p,
287
- isSameProduct: L,
288
- isRecommendedPlan: I,
289
- isFreePlan: y,
290
- isPlanActionDisabled: U,
285
+ setBillingInterval: F,
286
+ isCurrentPlan: P,
287
+ isSameProduct: k,
288
+ isRecommendedPlan: $,
289
+ isFreePlan: v,
290
+ isPlanActionDisabled: T,
291
291
  getDisplayPrice: j,
292
292
  getDisplayOriginalPrice: G,
293
293
  getDisplayCycle: O,
@@ -296,17 +296,17 @@ function fe(e = "month") {
296
296
  getBadgeLabels: K,
297
297
  getButtonLabel: Q,
298
298
  getPlanSummary: V,
299
- getFeatureItems: W,
300
- getFeatureGroups: _,
301
- loadProducts: q,
302
- loadCurrentSubscription: S,
303
- refresh: z
299
+ getFeatureItems: _,
300
+ getFeatureGroups: z,
301
+ loadProducts: A,
302
+ loadCurrentSubscription: L,
303
+ refresh: H
304
304
  };
305
305
  }
306
306
  function re(e) {
307
307
  window.open(e, "_blank", "noopener,noreferrer");
308
308
  }
309
- function C(e) {
309
+ function S(e) {
310
310
  return e && typeof e == "object" && "message" in e && typeof e.message == "string" ? e.message : "";
311
311
  }
312
312
  function ne(e) {
@@ -315,72 +315,58 @@ function ne(e) {
315
315
  function ie(e) {
316
316
  return e && typeof e == "object" && "status" in e && e.status === "trialing";
317
317
  }
318
- const ue = h;
319
- function de(e) {
320
- const n = g(null), {
318
+ function fe(e) {
319
+ const n = y(null), {
321
320
  ensureAuthenticated: i
322
- } = H();
323
- async function f(o) {
324
- if (!o.selectedPrice) {
325
- v.warning("当前方案暂无可购买价格");
321
+ } = J();
322
+ async function l(s) {
323
+ if (!s.selectedPrice) {
324
+ g.warning("当前方案暂无可购买价格");
326
325
  return;
327
326
  }
328
- if (!i(() => f(o))) return;
329
- const l = e.currentSubscription.value;
330
- if ((l == null ? void 0 : l.priceId) === o.selectedPrice.id) {
331
- v.info("当前已经是该方案");
327
+ if (!i(() => l(s))) return;
328
+ const d = e.currentSubscription.value;
329
+ if ((d == null ? void 0 : d.priceId) === s.selectedPrice.id) {
330
+ g.info("当前已经是该方案");
332
331
  return;
333
332
  }
334
- n.value = o.id;
333
+ n.value = s.id;
335
334
  try {
336
- if (o.selectedPrice.type === "free") {
337
- if (l) {
338
- v.info("当前已有付费订阅,无需重复开通免费体验");
339
- return;
340
- }
341
- const P = await ue.trials.start.post({
342
- priceId: o.selectedPrice.id
343
- });
344
- if (P.error) {
345
- v.error(P.error.message || "免费体验开通失败");
346
- return;
347
- }
348
- v.success(C(P.data) || "免费体验已开通"), await e.refreshCurrentSubscription();
335
+ if (s.selectedPrice.type === "free")
349
336
  return;
350
- }
351
- const a = l ? await h.subscriptions.change.post({
352
- subscriptionId: l.id,
353
- newPriceId: o.selectedPrice.id,
337
+ const a = d ? await h.subscriptions.change.post({
338
+ subscriptionId: d.id,
339
+ newPriceId: s.selectedPrice.id,
354
340
  proration: !0
355
341
  }) : await h.subscriptions.create.post({
356
- priceId: o.selectedPrice.id
342
+ priceId: s.selectedPrice.id
357
343
  });
358
344
  if (a.error) {
359
- v.error(a.error.message || "订阅操作失败");
345
+ g.error(a.error.message || "订阅操作失败");
360
346
  return;
361
347
  }
362
- const $ = ne(a.data);
363
- if ($) {
364
- re($);
348
+ const b = ne(a.data);
349
+ if (b) {
350
+ re(b);
365
351
  return;
366
352
  }
367
- ie(a.data) ? v.success(C(a.data) || "试用已开始") : v.success(C(a.data) || "订阅已更新"), await e.refreshCurrentSubscription();
353
+ ie(a.data) ? g.success(S(a.data) || "试用已开始") : g.success(S(a.data) || "订阅已更新"), await e.refreshCurrentSubscription();
368
354
  } catch (a) {
369
- console.error("订阅操作失败", a), v.error("订阅操作失败,请稍后重试");
355
+ console.error("订阅操作失败", a), g.error("订阅操作失败,请稍后重试");
370
356
  } finally {
371
357
  n.value = null;
372
358
  }
373
359
  }
374
- function d(o) {
375
- return n.value === o.id;
360
+ function f(s) {
361
+ return n.value === s.id;
376
362
  }
377
363
  return {
378
364
  checkoutPlanId: n,
379
- checkout: f,
380
- isCheckingOut: d
365
+ checkout: l,
366
+ isCheckingOut: f
381
367
  };
382
368
  }
383
369
  export {
384
- de as a,
385
- fe as u
370
+ fe as a,
371
+ le as u
386
372
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huyooo/ui",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [