@gindow/vue 1.0.0 → 1.0.2

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/index.mjs DELETED
@@ -1,406 +0,0 @@
1
- import { computed as e, inject as t, onBeforeUnmount as n, onMounted as r, provide as i, reactive as a, ref as o } from "vue";
2
- import s from "js-cookie";
3
- import c from "axios";
4
- import l from "dayjs";
5
- import { nanoid as u } from "nanoid";
6
- import { customAlphabet as d } from "nanoid/non-secure";
7
- import f from "file-type-checker";
8
- import p from "heic2any";
9
- import m from "compressorjs";
10
- //#region src/locale/zh-CN.ts
11
- var h = {
12
- cancel: "取消",
13
- confirm: "确认",
14
- empty: { noData: "暂无数据" },
15
- dialog: {
16
- tip: "操作提示",
17
- confirm: "操作确认"
18
- }
19
- }, g = {
20
- cancel: "Cancel",
21
- confirm: "Confirm",
22
- empty: { noData: "No data" },
23
- dialog: {
24
- tip: "Tip",
25
- confirm: "Confirm"
26
- }
27
- }, _ = () => {
28
- let e = ["en", "zh-CN"], t = localStorage.getItem("locale"), n = navigator.language;
29
- return t && e.includes(t) ? t : n && e.includes(n) ? n : n && e.includes(n.split("-")[0]) ? n.split("-")[0] : e[0] ?? "zh-CN";
30
- }, v = Symbol("vue-go-locale"), y = o(_()), b = a({
31
- en: g,
32
- "zh-CN": h
33
- }), x = (e) => {
34
- if (e?.locale && (y.value = e.locale), e?.messages) for (let [t, n] of Object.entries(e.messages)) b[t] = n;
35
- return i(v, {
36
- locale: y,
37
- messages: b
38
- }), {
39
- locale: y,
40
- messages: b
41
- };
42
- }, S = () => {
43
- let e = t(v, void 0), n = e?.locale ?? y, r = e?.messages ?? b;
44
- return {
45
- locale: n,
46
- t: (e, t) => {
47
- let i = r[n.value], a = e.replace(/\[(\d+)]/g, ".$1").split("."), o = i;
48
- for (let t of a) if (o = o?.[t], o === void 0) return e;
49
- let s = o ?? e;
50
- return t && typeof s == "string" && (s = s.replace(/\{(\w+)\}/g, (e, n) => t[n] === void 0 ? `{${n}}` : String(t[n]))), s;
51
- }
52
- };
53
- }, C = (e) => y.value = e, w = () => y.value, T = class e {
54
- static get userAgent() {
55
- return window.navigator.userAgent.toLowerCase();
56
- }
57
- static get isFlutter() {
58
- return e.userAgent.match(/flutter/i) !== null;
59
- }
60
- static get isFlutterIOS() {
61
- return e.isFlutter && e.isIOS;
62
- }
63
- static get isWeb() {
64
- return window.matchMedia("(min-width: 992px)").matches;
65
- }
66
- static get isMobile() {
67
- return e.userAgent.match(/(phone|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) !== null;
68
- }
69
- static get isIOS() {
70
- return e.userAgent.match(/iphone|ipad|ipod|ios/i) !== null;
71
- }
72
- static get isWechat() {
73
- return e.userAgent.match(/MicroMessenger/i) !== null;
74
- }
75
- static get isWxwork() {
76
- return e.userAgent.match(/MicroMessenger/i) !== null && e.userAgent.match(/wxwork/i) !== null;
77
- }
78
- static get isMiniprogram() {
79
- return e.userAgent.match(/MicroMessenger/i) !== null && e.userAgent.match(/miniprogram/i) !== null;
80
- }
81
- }, E = (e) => {
82
- let t = { ...e };
83
- return typeof t?.search == "string" ? t : (t?.search && (t.search = Object.keys(t.search).filter((e) => t.search[e] !== null && t.search[e] !== "").map((e) => e + ":" + t.search[e]).join(";")), t?.searchFields && (t.searchFields = Object.keys(t.searchFields).filter((e) => t.searchFields[e]).map((e) => e + ":" + t.searchFields[e]).join(";")), t);
84
- }, D = {
85
- baseURL: "",
86
- publicKey: "",
87
- headers: { Accept: "application/json" },
88
- instance: null,
89
- accessToken: "accessToken",
90
- init(e = {}) {
91
- this.baseURL = e.baseURL ?? "", this.publicKey = e.publicKey ?? "";
92
- let t = () => {
93
- this.delToken(), location.reload();
94
- };
95
- this.instance = c.create({ baseURL: this.baseURL }), this.instance.interceptors.request.use((e) => {
96
- let t = localStorage.getItem("locale");
97
- return t && (e.headers["Accept-Language"] = t), e;
98
- }), this.instance.interceptors.response.use((e) => e.config.responseType === "blob" ? e : e.data.code === 401 ? t() : e.data.code === 200 ? e.data : Promise.reject(e.data), ({ response: e }) => Promise.reject(e.data));
99
- },
100
- setToken(e, t = {}) {
101
- t = {
102
- ...t,
103
- domain: "." + location.hostname
104
- }, s.set(this.accessToken, e, t);
105
- },
106
- getToken() {
107
- return s.get(this.accessToken) || "";
108
- },
109
- delToken() {
110
- s.remove(this.accessToken, { domain: "." + location.hostname });
111
- },
112
- get(e, t, n = !1) {
113
- return this.request({
114
- method: "GET",
115
- url: e,
116
- params: t
117
- }, n);
118
- },
119
- put(e, t, n = !1) {
120
- return this.request({
121
- method: "PUT",
122
- url: e,
123
- data: t
124
- }, n);
125
- },
126
- patch(e, t, n = !1) {
127
- return this.request({
128
- method: "PATCH",
129
- url: e,
130
- data: t
131
- }, n);
132
- },
133
- delete(e, t, n = !1) {
134
- return this.request({
135
- method: "DELETE",
136
- url: e,
137
- params: t
138
- }, n);
139
- },
140
- post(e, t, n = !1) {
141
- return this.request({
142
- method: "POST",
143
- url: e,
144
- data: t
145
- }, n);
146
- },
147
- blob(e, t, n = !1) {
148
- return this.request({
149
- method: "GET",
150
- url: e,
151
- params: t,
152
- responseType: "blob"
153
- }, n);
154
- },
155
- request(e, t = !1) {
156
- let n = e.headers ?? this.headers;
157
- return t && (n.Authorization = "Bearer " + this.getToken()), e.params &&= E(e.params), this.instance({
158
- ...e,
159
- headers: n
160
- });
161
- },
162
- async download(e, t, n, r = !1) {
163
- let i = await this.blob(e, t, r);
164
- if (T.isFlutter) return i;
165
- let a = () => {
166
- let e = i.headers["content-disposition"].split("filename*=")[1].split(";")[0].trim();
167
- return decodeURIComponent(e.replace(/^UTF-8''/i, ""));
168
- }, o = document.createElement("a");
169
- return o.href = window.URL.createObjectURL(i.data), o.download = n ?? a(), o.click(), i;
170
- },
171
- async upload(e, t = {}) {
172
- let n = {
173
- ...this.headers,
174
- "Content-Type": "multipart/form-data"
175
- };
176
- return this.instance.post(e, t, { headers: n });
177
- },
178
- sse(e, t) {
179
- let n = t ? Object.keys(t).map((e) => e + "=" + t[e]).join("&") : "";
180
- return new EventSource(this.baseURL + "/" + e + "?" + n);
181
- },
182
- setHeader(e, t) {
183
- this.headers[e] = t;
184
- },
185
- delHeader(e) {
186
- delete this.headers[e];
187
- }
188
- }, O = class {
189
- url;
190
- auth;
191
- constructor(e, t = !1) {
192
- this.url = e, this.auth = t;
193
- }
194
- select = (e) => D.get(this.url, e, this.auth);
195
- create = (e) => D.post(this.url, e, this.auth);
196
- find = (e, t) => D.get(this.url + "/" + e, t, this.auth);
197
- update = (e, t) => D.patch(this.url + "/" + e, t, this.auth);
198
- delete = (e, t) => D.delete(this.url + "/" + e, t, this.auth);
199
- async get(e) {
200
- e.size = 1;
201
- let t = await this.select(e);
202
- return t.data = t.data[0] || {}, t;
203
- }
204
- }, k = (e, t, n) => {
205
- if (e == null) return n;
206
- let r = Array.isArray(t) ? t : t.replace(/\[(\d+)]/g, ".$1").split(".").filter(Boolean), i = e;
207
- for (let e of r) if (i = i?.[e], i === void 0) return n;
208
- return i;
209
- }, A = (e, t) => {
210
- let n = URL.createObjectURL(e), r = document.createElement("a");
211
- r.href = n, r.download = t, r.style.display = "none", document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(n);
212
- }, j = class {
213
- static config = {};
214
- static set = (e) => this.config = e;
215
- static id = (e = "") => e.slice(-12).toUpperCase();
216
- static date = (e = "") => e.substring(0, 10) + " " + e.substring(11, 19);
217
- static idcard = (e = "") => e ? e.substring(0, 6) + "****" + e.substring(14) : "";
218
- static phone = (e = "", t = !1) => t || !e ? e : e.substring(0, 3) + "****" + e.substring(e.length - 4);
219
- static email = (e = "") => {
220
- let [t, n] = e.split("@");
221
- return !t || !n ? e : `${t.length > 2 ? t[0] + "****" + t[t.length - 1] : t}@${n}`;
222
- };
223
- static bankcard = (e = "") => e.substring(0, 4) + "****" + e.substring(e.length - 4);
224
- static url = (e = "") => e.replace(/:\/\//g, ":##").replace(/\/+/g, "/").replace(/:##/g, "://");
225
- static price = (e = 0, t) => {
226
- let { locale: n, decimals: r, currency: i } = this.config, a = typeof e == "string" ? parseFloat(e) : e;
227
- return new Intl.NumberFormat(n, {
228
- style: "currency",
229
- currency: t ?? i ?? "CNY",
230
- minimumFractionDigits: r ?? 2,
231
- maximumFractionDigits: r ?? 2
232
- }).format(a / 100);
233
- };
234
- static currency = (e = 0, t) => this.price(e, t);
235
- }, M = class e {
236
- static country = "";
237
- static set = (e) => this.country = e;
238
- static get phone_pattern() {
239
- return this.country.toUpperCase() === "CN" ? /([1][3,4,5,6,7,8,9][0-9]{9})$/ : /^(?:\+?[1-9]\d{7,14}|\d{6,11})$/;
240
- }
241
- static email_pattern = /^([a-zA-Z0-9_\.-]+)@([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})$/;
242
- static idcard_pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
243
- static cname_pattern = /^(?:[\u4e00-\u9fa5·]{2,16})$/;
244
- static password_pattern = /^(?![A-Za-z]+$)(?![0-9]+$)(?![^A-Za-z0-9]+$).{8,20}$/;
245
- static phone = (t) => e.phone_pattern.test(t);
246
- static email = (t) => e.email_pattern.test(t);
247
- static idcard = (t) => e.idcard_pattern.test(t);
248
- static cname = (t) => e.cname_pattern.test(t);
249
- }, N = class e {
250
- static dayjs = l;
251
- static s(t, n = "/") {
252
- return e.dayjs(t).format("YYYY/MM/DD HH:mm:ss".replace(/\//g, n));
253
- }
254
- static m(t, n = "/") {
255
- return e.dayjs(t).format("YYYY/MM/DD HH:mm".replace(/\//g, n));
256
- }
257
- static h(t, n = "/") {
258
- return e.dayjs(t).format("YYYY/MM/DD HH".replace(/\//g, n));
259
- }
260
- static d(t, n = "/") {
261
- return e.dayjs(t).format("YYYY/MM/DD".replace(/\//g, n));
262
- }
263
- static M(t, n = "/") {
264
- return e.dayjs(t).format("YYYY/MM".replace(/\//g, n));
265
- }
266
- static y(t) {
267
- return e.dayjs(t).format("YYYY");
268
- }
269
- static date(t, n = "/") {
270
- return e.dayjs(t).format("YYYY/MM/DD".replace(/\//g, n));
271
- }
272
- static time(t) {
273
- return e.dayjs(t).format("HH:mm");
274
- }
275
- static format(t, n = "YYYY/MM/DD HH:mm:ss") {
276
- return e.dayjs(t).format(n);
277
- }
278
- }, P = 768, F = () => {
279
- let t = o(typeof window < "u" ? window.matchMedia(`(min-width: ${P}px)`).matches : !0), i, a = (e) => t.value = e.matches;
280
- r(() => {
281
- typeof window > "u" || (i = window.matchMedia(`(min-width: ${P}px)`), t.value = i.matches, i.addEventListener("change", a));
282
- }), n(() => i?.removeEventListener("change", a));
283
- let s = e(() => t.value);
284
- return {
285
- isMobile: e(() => !t.value),
286
- isDesktop: s
287
- };
288
- }, I = () => ({
289
- nanoid: u,
290
- numeric: (e = 10) => d("1234567890", e)()
291
- }), L = (e) => {
292
- let t = o(0), n = o(!1), r = (t = {}) => new Promise((r, a) => {
293
- n.value || (n.value = !0, e(t).then(() => {
294
- i(), r(!0);
295
- }).catch((e) => a(e)).finally(() => n.value = !1));
296
- }), i = () => {
297
- t.value = 60;
298
- let e = setInterval(() => {
299
- t.value--, t.value || clearTimeout(e);
300
- }, 1e3);
301
- };
302
- return {
303
- waiting: t,
304
- send: r
305
- };
306
- }, R = () => {
307
- let e = (e) => new Promise(async (t) => {
308
- let n = await p({
309
- blob: e,
310
- toType: "image/jpeg",
311
- quality: .9
312
- });
313
- return t(new File([n], e.name, {
314
- type: n.type,
315
- lastModified: Date.now()
316
- }));
317
- }), t = (e) => new Promise((t) => {
318
- new m(e, {
319
- quality: .9,
320
- success: (e) => t(e)
321
- });
322
- });
323
- return {
324
- handler: (n, r = { compressor: !0 }) => new Promise((i) => {
325
- let a = new FileReader();
326
- a.readAsArrayBuffer(n), a.onload = () => {
327
- let o = f.validateFileType(a.result, ["heic"]), s = f.validateFileType(a.result, [
328
- "jpeg",
329
- "png",
330
- "gif",
331
- "bmp"
332
- ]);
333
- o ? i(e(n)) : s && r.compressor ? i(t(n)) : i(n);
334
- };
335
- }),
336
- getDimension: async (e) => new Promise((t, n) => {
337
- let r = new Image();
338
- r.src = URL.createObjectURL(e), r.onload = () => t({
339
- width: r.naturalWidth,
340
- height: r.naturalHeight
341
- }), r.onerror = (e) => n(e);
342
- }),
343
- getFileType: (e) => new Promise((t) => {
344
- let n = new FileReader();
345
- n.readAsArrayBuffer(e), n.onload = () => {
346
- t({ mimeType: f.detectFile(n.result)?.mimeType });
347
- };
348
- })
349
- };
350
- }, z = (e, t) => ({ sendMessage: async (n, r) => {
351
- let { onMessage: i, onEnd: a, onError: o, onFinish: s } = r;
352
- try {
353
- let { ok: r, status: c, statusText: l, body: u } = await fetch(`${e}/chat-messages`, {
354
- method: "POST",
355
- headers: {
356
- Authorization: `Bearer ${t}`,
357
- "Content-Type": "application/json"
358
- },
359
- body: JSON.stringify({
360
- ...n,
361
- response_mode: "streaming"
362
- })
363
- });
364
- if (!r) return o?.({
365
- code: String(c),
366
- message: l
367
- });
368
- let d = u?.getReader();
369
- if (!d) return o?.({
370
- code: "reader_error",
371
- message: "Failed to get response reader"
372
- });
373
- let f = new TextDecoder(), p = "";
374
- for (;;) {
375
- let { done: e, value: t } = await d.read();
376
- if (e) break;
377
- p += f.decode(t, { stream: !0 });
378
- let n = p.split("\n");
379
- p = n.pop() || "";
380
- for (let e of n) if (e.startsWith("data:")) try {
381
- let t = e.slice(5).trim();
382
- if (!t) continue;
383
- let n = JSON.parse(t);
384
- if (n.event === "agent_message") i?.(n.answer || "");
385
- else if (n.event === "message_end") a?.(n.conversation_id, n.message_id);
386
- else if (n.event === "error") {
387
- let { code: e, message: t } = n;
388
- o?.({
389
- code: e,
390
- message: t
391
- });
392
- }
393
- s?.();
394
- } catch {}
395
- }
396
- } catch (e) {
397
- o?.({
398
- code: "network_error",
399
- message: String(e)
400
- });
401
- }
402
- } }), B = { install(e, t) {
403
- x(t), e.config.globalProperties.$setLocale = C, e.config.globalProperties.$getLocale = w;
404
- } };
405
- //#endregion
406
- export { E as $params, N as DateTime, j as Formatter, T as Platform, M as Validate, B as default, A as download, k as get, w as getLocale, D as request, O as resource, C as setLocale, F as useBreak, L as useCaptcha, z as useChat, S as useLocale, I as useNanoid, R as useUpload };