@yourgoods/ui-smart 0.3.0 → 0.4.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.
@@ -1,269 +0,0 @@
1
- import { defineComponent as Pe, ref as r, reactive as N, computed as u, watch as X, onMounted as ye, createElementBlock as _, openBlock as g, Fragment as Ce, createVNode as n, unref as o, withCtx as P, createCommentVNode as Y, createElementVNode as l, toDisplayString as V, createBlock as S, resolveDynamicComponent as B, createTextVNode as R } from "vue";
2
- import { C as b, p as E, g as ge } from "./index-rDbP74yn.js";
3
- import { PDialog as Ve, PInput as $, IconEyeMd as z, IconEyeClosedMd as M, PButton as O, PTopBar as be, IconCrossMd as Ie, PTeleportContainer as Te } from "@profeat/ui-kit";
4
- function xe(I) {
5
- return { showPasswordRateLimitToast: (y) => {
6
- if (!y) return;
7
- const { attemptsLeft: a, retryAfterSec: C } = y;
8
- if (a === 2) {
9
- I("on-toast", {
10
- color: "error",
11
- text: "Осталось 2 попытки. Ввод пароля будет заблокирован на 5 минут."
12
- });
13
- return;
14
- }
15
- if (a === 1) {
16
- I("on-toast", {
17
- color: "error",
18
- text: "Осталась 1 попытка. После исчерпания лимита ввод пароля будет заблокирован на 1 час."
19
- });
20
- return;
21
- }
22
- if (a === 0) {
23
- const v = C && C > 0 ? C : 3600;
24
- I("on-toast", {
25
- color: "error",
26
- text: `Достигнут лимит попыток ввода пароля. Попробуйте снова через ${Math.ceil(v / 60)} минут.`
27
- });
28
- return;
29
- }
30
- } };
31
- }
32
- const ke = { class: "text-center w-full" }, De = { class: "dialogTitle" }, Ee = {
33
- key: 0,
34
- class: "dialogDefaultContainer"
35
- }, he = { class: "dialogDefaultContainerInsideContent" }, Le = { class: "dialogDefaultContainerTextHint" }, Ne = { class: "input-wrapper" }, _e = {
36
- key: 1,
37
- class: "dialogDefaultContainer"
38
- }, Se = { class: "dialogDefaultContainerInsideContent" }, Be = { class: "input-wrapper" }, Re = { class: "input-wrapper" }, $e = { style: { width: "100%", display: "flex" } }, Z = 8, Ue = /* @__PURE__ */ Pe({
39
- __name: "ProfilePasswordDialog",
40
- props: {
41
- modelValue: { type: Boolean },
42
- title: { default: "Смена пароля" },
43
- hintText: { default: "Введите ваш текущий пароль" },
44
- oldPassword: { default: "" }
45
- },
46
- emits: ["update:modelValue", "submit", "edit", "close", "on-update-jwt", "on-password-error", "on-password-success", "on-toast"],
47
- setup(I, { emit: U }) {
48
- const y = I, a = U, C = r(!0), v = r(y.modelValue), p = N({ oldPassword: y.oldPassword ?? "" }), d = r(""), f = r(""), F = N({ oldPassword: !1 }), w = N({ newPassword: !1, newPasswordConfirm: !1 }), i = r(b.OLD), m = r(null), H = r(!1), { showPasswordRateLimitToast: ee } = xe(a), x = r(!1), se = u(() => x.value ? "text" : "password"), te = () => x.value = !x.value, k = r(!1), D = r(!1), oe = u(() => k.value ? "text" : "password"), ae = u(() => D.value ? "text" : "password"), re = () => {
49
- k.value = !k.value;
50
- }, le = () => {
51
- D.value = !D.value;
52
- }, T = r(!1), ne = u(() => T.value ? "Неверный текущий пароль" : F.oldPassword && !p.oldPassword.trim() ? "Введите пароль" : ""), de = u(() => !p.oldPassword.trim()), ie = u(() => H.value || !d.value.trim() || !f.value.trim() ? !0 : q.value);
53
- X(
54
- () => y.modelValue,
55
- (t) => v.value = t
56
- ), X(v, (t) => a("update:modelValue", t));
57
- const ue = async (t = "email") => {
58
- var s;
59
- const e = await ge("/users/profile/session/get-edit-session", { params: { field: t } });
60
- return ((s = e.data) == null ? void 0 : s.data) ?? e.data;
61
- }, h = async (t = "email") => {
62
- var s;
63
- const e = await E("/users/profile/session/create-if-not-exists", { field: t, oldValue: p.oldPassword });
64
- return ((s = e.data) == null ? void 0 : s.data) ?? e.data;
65
- }, we = async () => {
66
- var c, J, K, Q;
67
- if (!m.value) throw new Error("Нет sessionId");
68
- const t = await E("/users/profile/password/match", { sessionId: m.value, password: p.oldPassword }), e = ((c = t.data) == null ? void 0 : c.data) ?? t.data, s = ((K = (J = t.data) == null ? void 0 : J.data) == null ? void 0 : K.passwordRateLimit) ?? ((Q = t.data) == null ? void 0 : Q.passwordRateLimit);
69
- return ee(s), { success: (e == null ? void 0 : e.success) ?? !1, message: (e == null ? void 0 : e.message) ?? "" };
70
- }, ce = async () => {
71
- await E("/users/profile/password/init", { never_: "never" });
72
- }, ve = async () => {
73
- await E("/users/profile/password/update", {
74
- sessionId: m.value,
75
- newPassword: d.value.trim(),
76
- confirmPassword: f.value.trim()
77
- });
78
- }, j = async (t = "password") => {
79
- try {
80
- const e = await ue(t);
81
- if (m.value = e.sessionId, i.value = e.step, !e.sessionId) {
82
- const s = await h(t);
83
- m.value = s.sessionId, i.value = s.step;
84
- }
85
- } catch {
86
- const s = await h(t);
87
- m.value = s.sessionId, i.value = s.step;
88
- }
89
- }, L = () => {
90
- a("close"), v.value = !1;
91
- }, A = (t) => {
92
- F[t] = !0, T.value = !1;
93
- }, pe = async () => {
94
- var t, e;
95
- T.value = !1;
96
- try {
97
- if (await j("password"), i.value !== b.OLD) return;
98
- const { success: s } = await we();
99
- if (!s) {
100
- T.value = !0;
101
- return;
102
- }
103
- const c = await h("password");
104
- m.value = c.sessionId, i.value = c.step;
105
- } catch (s) {
106
- const c = ((e = (t = s == null ? void 0 : s.response) == null ? void 0 : t.data) == null ? void 0 : e.message) ?? "";
107
- if (typeof c == "string" && c.toLowerCase().includes("never")) {
108
- T.value = !0;
109
- return;
110
- }
111
- }
112
- }, fe = async () => {
113
- if (!q.value)
114
- try {
115
- await ve(), i.value = b.COMPLETED, a("on-update-jwt", "password", "edit", d.value), a("on-toast", { color: "success", text: "Пароль изменён" }), a("close");
116
- } catch {
117
- }
118
- }, me = async () => {
119
- d.value = "", f.value = "", w.newPassword = !1, w.newPasswordConfirm = !1, i.value = b.OLD, p.oldPassword = "", a("close");
120
- }, G = u(() => w.newPassword ? d.value.trim() ? d.value.trim().length < Z ? `Пароль слишком короткий. Введите хотя бы ${Z} символов` : "" : "Введите пароль" : ""), W = u(() => w.newPasswordConfirm ? f.value.trim() ? f.value !== d.value ? "Пароли не совпадают" : "" : "Повторите пароль" : ""), q = u(() => !!G.value || !!W.value);
121
- return ye(async () => {
122
- C.value = !0;
123
- try {
124
- await ce(), await j("password");
125
- } finally {
126
- C.value = !1;
127
- }
128
- }), (t, e) => (g(), _(Ce, null, [
129
- n(o(Ve), {
130
- modelValue: v.value,
131
- "onUpdate:modelValue": [
132
- e[9] || (e[9] = (s) => v.value = s),
133
- L
134
- ],
135
- width: "small",
136
- "auto-height": !0,
137
- "close-on-click-outside": !0,
138
- "onClick:outside": L
139
- }, {
140
- header: P(() => [
141
- l("div", ke, [
142
- n(o(be), {
143
- "slot-left": !1,
144
- size: "small",
145
- borded: !0,
146
- "no-padding": !1
147
- }, {
148
- title: P(() => [
149
- l("span", De, V(t.title), 1)
150
- ]),
151
- "right-button": P(() => [
152
- n(o(Ie), {
153
- class: "cross",
154
- onClick: L
155
- })
156
- ]),
157
- _: 1
158
- })
159
- ])
160
- ]),
161
- default: P(() => [
162
- i.value === o(b).OLD ? (g(), _("div", Ee, [
163
- l("div", he, [
164
- l("div", Le, V(t.hintText), 1),
165
- l("div", Ne, [
166
- n(o($), {
167
- modelValue: p.oldPassword,
168
- "onUpdate:modelValue": e[0] || (e[0] = (s) => p.oldPassword = s),
169
- size: "large",
170
- "text-size": "medium",
171
- label: "Текущий пароль",
172
- type: se.value,
173
- error: ne.value,
174
- onBlur: e[1] || (e[1] = (s) => A("oldPassword")),
175
- onInput: e[2] || (e[2] = (s) => A("oldPassword"))
176
- }, null, 8, ["modelValue", "type", "error"]),
177
- (g(), S(B(x.value ? o(z) : o(M)), {
178
- class: "icon-locked",
179
- onClick: te
180
- }))
181
- ]),
182
- n(o(O), {
183
- style: { width: "100%" },
184
- disabled: de.value,
185
- onClick: pe
186
- }, {
187
- default: P(() => e[10] || (e[10] = [
188
- R(V("Продолжить"))
189
- ])),
190
- _: 1,
191
- __: [10]
192
- }, 8, ["disabled"])
193
- ])
194
- ])) : Y("", !0),
195
- i.value === o(b).NEW ? (g(), _("div", _e, [
196
- l("div", Se, [
197
- e[14] || (e[14] = l("div", { class: "dialogDefaultContainerTextHint" }, V("Установите новый пароль для защиты аккаунта. Пароль должен содержать не менее 8 символов."), -1)),
198
- l("div", Be, [
199
- n(o($), {
200
- modelValue: d.value,
201
- "onUpdate:modelValue": e[3] || (e[3] = (s) => d.value = s),
202
- size: "large",
203
- "text-size": "medium",
204
- label: "Новый пароль",
205
- type: oe.value,
206
- error: G.value,
207
- onBlur: e[4] || (e[4] = (s) => w.newPassword = !0),
208
- onInput: e[5] || (e[5] = (s) => w.newPassword = !0)
209
- }, null, 8, ["modelValue", "type", "error"]),
210
- (g(), S(B(k.value ? o(z) : o(M)), {
211
- class: "icon-locked",
212
- onClick: re
213
- }))
214
- ]),
215
- l("div", Re, [
216
- n(o($), {
217
- modelValue: f.value,
218
- "onUpdate:modelValue": e[6] || (e[6] = (s) => f.value = s),
219
- size: "large",
220
- "text-size": "medium",
221
- label: "Повторите новый пароль",
222
- type: ae.value,
223
- error: W.value,
224
- onBlur: e[7] || (e[7] = (s) => w.newPasswordConfirm = !0),
225
- onInput: e[8] || (e[8] = (s) => w.newPasswordConfirm = !0)
226
- }, null, 8, ["modelValue", "type", "error"]),
227
- (g(), S(B(D.value ? o(z) : o(M)), {
228
- class: "icon-locked",
229
- onClick: le
230
- }))
231
- ]),
232
- l("div", $e, [
233
- n(o(O), {
234
- style: { width: "100%" },
235
- color: "secondary",
236
- disabled: H.value,
237
- onClick: me
238
- }, {
239
- default: P(() => e[11] || (e[11] = [
240
- R(V("Отмена"))
241
- ])),
242
- _: 1,
243
- __: [11]
244
- }, 8, ["disabled"]),
245
- e[13] || (e[13] = l("div", { style: { width: "5%" } }, null, -1)),
246
- n(o(O), {
247
- style: { width: "100%" },
248
- disabled: ie.value,
249
- onClick: fe
250
- }, {
251
- default: P(() => e[12] || (e[12] = [
252
- R(V("Сохранить"))
253
- ])),
254
- _: 1,
255
- __: [12]
256
- }, 8, ["disabled"])
257
- ])
258
- ])
259
- ])) : Y("", !0)
260
- ]),
261
- _: 1
262
- }, 8, ["modelValue"]),
263
- n(o(Te))
264
- ], 64));
265
- }
266
- });
267
- export {
268
- Ue as default
269
- };