@gindow/vue 1.0.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.
- package/README.md +34 -0
- package/dist/index.cjs +2 -0
- package/dist/index.mjs +406 -0
- package/dist/style.css +3 -0
- package/dist/vue-go.d.ts +394 -0
- package/package.json +99 -0
- package/src/env.d.ts +7 -0
- package/src/hooks/useBreak.ts +23 -0
- package/src/hooks/useCaptcha.ts +29 -0
- package/src/hooks/useChat.ts +135 -0
- package/src/hooks/useNanoid.ts +9 -0
- package/src/hooks/useUpload.ts +59 -0
- package/src/index.ts +29 -0
- package/src/locale/en-US.ts +11 -0
- package/src/locale/index.ts +55 -0
- package/src/locale/zh-CN.ts +11 -0
- package/src/style.css +24 -0
- package/src/types/chat.ts +62 -0
- package/src/types/index.ts +74 -0
- package/src/utils/datetime.ts +42 -0
- package/src/utils/download.ts +11 -0
- package/src/utils/formatter.ts +42 -0
- package/src/utils/get.ts +10 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/platform.ts +38 -0
- package/src/utils/request.ts +146 -0
- package/src/utils/validate.ts +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# vue-go
|
|
2
|
+
|
|
3
|
+
Vue3 通用基础包,为 `element-go`(桌面端)和 `vant-go`(移动端)提供公共基础设施。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- **工具函数**:`request`(HTTP 请求封装)、`resource`(RESTful 资源)、`DateTime`、`Formatter`、`Validate`、`Platform`、`download`、`get`
|
|
8
|
+
- **Hooks**:`useBreak`(响应式断点)、`useNanoid`(ID 生成)、`useCaptcha`(验证码倒计时)、`useUpload`(图片上传处理)、`useChat`(AI 流式对话)
|
|
9
|
+
- **类型定义**:`IModel`、`IAsset`、`IPagination`、`IResult`、`IMenu` 等通用接口
|
|
10
|
+
- **国际化**:Vue3 provide/inject 模式的 i18n 系统,内置中英文
|
|
11
|
+
- **基础样式**:TailwindCSS + 通用布局工具类
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install vue-go
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 使用
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// main.js
|
|
23
|
+
import { createApp } from 'vue'
|
|
24
|
+
import VueGo from 'vue-go'
|
|
25
|
+
import 'vue-go/style.css'
|
|
26
|
+
|
|
27
|
+
const app = createApp(App)
|
|
28
|
+
app.use(VueGo, { locale: 'zh-CN' })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// 按需引入
|
|
33
|
+
import { request, useBreak, IModel } from 'vue-go'
|
|
34
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("vue"),l=require("js-cookie");l=s(l,1);let u=require("axios");u=s(u,1);let d=require("dayjs");d=s(d,1);let f=require("nanoid"),p=require("nanoid/non-secure"),m=require("file-type-checker");m=s(m,1);let h=require("heic2any");h=s(h,1);let g=require("compressorjs");g=s(g,1);var _={cancel:`取消`,confirm:`确认`,empty:{noData:`暂无数据`},dialog:{tip:`操作提示`,confirm:`操作确认`}},v={cancel:`Cancel`,confirm:`Confirm`,empty:{noData:`No data`},dialog:{tip:`Tip`,confirm:`Confirm`}},y=()=>{let e=[`en`,`zh-CN`],t=localStorage.getItem(`locale`),n=navigator.language;return t&&e.includes(t)?t:n&&e.includes(n)?n:n&&e.includes(n.split(`-`)[0])?n.split(`-`)[0]:e[0]??`zh-CN`},b=Symbol(`vue-go-locale`),x=(0,c.ref)(y()),S=(0,c.reactive)({en:v,"zh-CN":_}),C=e=>{if(e?.locale&&(x.value=e.locale),e?.messages)for(let[t,n]of Object.entries(e.messages))S[t]=n;return(0,c.provide)(b,{locale:x,messages:S}),{locale:x,messages:S}},w=()=>{let e=(0,c.inject)(b,void 0),t=e?.locale??x,n=e?.messages??S;return{locale:t,t:(e,r)=>{let i=n[t.value],a=e.replace(/\[(\d+)]/g,`.$1`).split(`.`),o=i;for(let t of a)if(o=o?.[t],o===void 0)return e;let s=o??e;return r&&typeof s==`string`&&(s=s.replace(/\{(\w+)\}/g,(e,t)=>r[t]===void 0?`{${t}}`:String(r[t]))),s}}},T=e=>x.value=e,E=()=>x.value,D=class e{static get userAgent(){return window.navigator.userAgent.toLowerCase()}static get isFlutter(){return e.userAgent.match(/flutter/i)!==null}static get isFlutterIOS(){return e.isFlutter&&e.isIOS}static get isWeb(){return window.matchMedia(`(min-width: 992px)`).matches}static get isMobile(){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}static get isIOS(){return e.userAgent.match(/iphone|ipad|ipod|ios/i)!==null}static get isWechat(){return e.userAgent.match(/MicroMessenger/i)!==null}static get isWxwork(){return e.userAgent.match(/MicroMessenger/i)!==null&&e.userAgent.match(/wxwork/i)!==null}static get isMiniprogram(){return e.userAgent.match(/MicroMessenger/i)!==null&&e.userAgent.match(/miniprogram/i)!==null}},O=e=>{let t={...e};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)},k={baseURL:``,publicKey:``,headers:{Accept:`application/json`},instance:null,accessToken:`accessToken`,init(e={}){this.baseURL=e.baseURL??``,this.publicKey=e.publicKey??``;let t=()=>{this.delToken(),location.reload()};this.instance=u.default.create({baseURL:this.baseURL}),this.instance.interceptors.request.use(e=>{let t=localStorage.getItem(`locale`);return t&&(e.headers[`Accept-Language`]=t),e}),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))},setToken(e,t={}){t={...t,domain:`.`+location.hostname},l.default.set(this.accessToken,e,t)},getToken(){return l.default.get(this.accessToken)||``},delToken(){l.default.remove(this.accessToken,{domain:`.`+location.hostname})},get(e,t,n=!1){return this.request({method:`GET`,url:e,params:t},n)},put(e,t,n=!1){return this.request({method:`PUT`,url:e,data:t},n)},patch(e,t,n=!1){return this.request({method:`PATCH`,url:e,data:t},n)},delete(e,t,n=!1){return this.request({method:`DELETE`,url:e,params:t},n)},post(e,t,n=!1){return this.request({method:`POST`,url:e,data:t},n)},blob(e,t,n=!1){return this.request({method:`GET`,url:e,params:t,responseType:`blob`},n)},request(e,t=!1){let n=e.headers??this.headers;return t&&(n.Authorization=`Bearer `+this.getToken()),e.params&&=O(e.params),this.instance({...e,headers:n})},async download(e,t,n,r=!1){let i=await this.blob(e,t,r);if(D.isFlutter)return i;let a=()=>{let e=i.headers[`content-disposition`].split(`filename*=`)[1].split(`;`)[0].trim();return decodeURIComponent(e.replace(/^UTF-8''/i,``))},o=document.createElement(`a`);return o.href=window.URL.createObjectURL(i.data),o.download=n??a(),o.click(),i},async upload(e,t={}){let n={...this.headers,"Content-Type":`multipart/form-data`};return this.instance.post(e,t,{headers:n})},sse(e,t){let n=t?Object.keys(t).map(e=>e+`=`+t[e]).join(`&`):``;return new EventSource(this.baseURL+`/`+e+`?`+n)},setHeader(e,t){this.headers[e]=t},delHeader(e){delete this.headers[e]}},A=class{url;auth;constructor(e,t=!1){this.url=e,this.auth=t}select=e=>k.get(this.url,e,this.auth);create=e=>k.post(this.url,e,this.auth);find=(e,t)=>k.get(this.url+`/`+e,t,this.auth);update=(e,t)=>k.patch(this.url+`/`+e,t,this.auth);delete=(e,t)=>k.delete(this.url+`/`+e,t,this.auth);async get(e){e.size=1;let t=await this.select(e);return t.data=t.data[0]||{},t}},j=(e,t,n)=>{if(e==null)return n;let r=Array.isArray(t)?t:t.replace(/\[(\d+)]/g,`.$1`).split(`.`).filter(Boolean),i=e;for(let e of r)if(i=i?.[e],i===void 0)return n;return i},M=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.style.display=`none`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},N=class{static config={};static set=e=>this.config=e;static id=(e=``)=>e.slice(-12).toUpperCase();static date=(e=``)=>e.substring(0,10)+` `+e.substring(11,19);static idcard=(e=``)=>e?e.substring(0,6)+`****`+e.substring(14):``;static phone=(e=``,t=!1)=>t||!e?e:e.substring(0,3)+`****`+e.substring(e.length-4);static email=(e=``)=>{let[t,n]=e.split(`@`);return!t||!n?e:`${t.length>2?t[0]+`****`+t[t.length-1]:t}@${n}`};static bankcard=(e=``)=>e.substring(0,4)+`****`+e.substring(e.length-4);static url=(e=``)=>e.replace(/:\/\//g,`:##`).replace(/\/+/g,`/`).replace(/:##/g,`://`);static price=(e=0,t)=>{let{locale:n,decimals:r,currency:i}=this.config,a=typeof e==`string`?parseFloat(e):e;return new Intl.NumberFormat(n,{style:`currency`,currency:t??i??`CNY`,minimumFractionDigits:r??2,maximumFractionDigits:r??2}).format(a/100)};static currency=(e=0,t)=>this.price(e,t)},P=class e{static country=``;static set=e=>this.country=e;static get phone_pattern(){return this.country.toUpperCase()===`CN`?/([1][3,4,5,6,7,8,9][0-9]{9})$/:/^(?:\+?[1-9]\d{7,14}|\d{6,11})$/}static email_pattern=/^([a-zA-Z0-9_\.-]+)@([\da-zA-Z\.-]+)\.([a-zA-Z\.]{2,6})$/;static idcard_pattern=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;static cname_pattern=/^(?:[\u4e00-\u9fa5·]{2,16})$/;static password_pattern=/^(?![A-Za-z]+$)(?![0-9]+$)(?![^A-Za-z0-9]+$).{8,20}$/;static phone=t=>e.phone_pattern.test(t);static email=t=>e.email_pattern.test(t);static idcard=t=>e.idcard_pattern.test(t);static cname=t=>e.cname_pattern.test(t)},F=class e{static dayjs=d.default;static s(t,n=`/`){return e.dayjs(t).format(`YYYY/MM/DD HH:mm:ss`.replace(/\//g,n))}static m(t,n=`/`){return e.dayjs(t).format(`YYYY/MM/DD HH:mm`.replace(/\//g,n))}static h(t,n=`/`){return e.dayjs(t).format(`YYYY/MM/DD HH`.replace(/\//g,n))}static d(t,n=`/`){return e.dayjs(t).format(`YYYY/MM/DD`.replace(/\//g,n))}static M(t,n=`/`){return e.dayjs(t).format(`YYYY/MM`.replace(/\//g,n))}static y(t){return e.dayjs(t).format(`YYYY`)}static date(t,n=`/`){return e.dayjs(t).format(`YYYY/MM/DD`.replace(/\//g,n))}static time(t){return e.dayjs(t).format(`HH:mm`)}static format(t,n=`YYYY/MM/DD HH:mm:ss`){return e.dayjs(t).format(n)}},I=768,L=()=>{let e=(0,c.ref)(typeof window<`u`?window.matchMedia(`(min-width: ${I}px)`).matches:!0),t,n=t=>e.value=t.matches;(0,c.onMounted)(()=>{typeof window>`u`||(t=window.matchMedia(`(min-width: ${I}px)`),e.value=t.matches,t.addEventListener(`change`,n))}),(0,c.onBeforeUnmount)(()=>t?.removeEventListener(`change`,n));let r=(0,c.computed)(()=>e.value);return{isMobile:(0,c.computed)(()=>!e.value),isDesktop:r}},R=()=>({nanoid:f.nanoid,numeric:(e=10)=>(0,p.customAlphabet)(`1234567890`,e)()}),z=e=>{let t=(0,c.ref)(0),n=(0,c.ref)(!1),r=(t={})=>new Promise((r,a)=>{n.value||(n.value=!0,e(t).then(()=>{i(),r(!0)}).catch(e=>a(e)).finally(()=>n.value=!1))}),i=()=>{t.value=60;let e=setInterval(()=>{t.value--,t.value||clearTimeout(e)},1e3)};return{waiting:t,send:r}},B=()=>{let e=e=>new Promise(async t=>{let n=await(0,h.default)({blob:e,toType:`image/jpeg`,quality:.9});return t(new File([n],e.name,{type:n.type,lastModified:Date.now()}))}),t=e=>new Promise(t=>{new g.default(e,{quality:.9,success:e=>t(e)})});return{handler:(n,r={compressor:!0})=>new Promise(i=>{let a=new FileReader;a.readAsArrayBuffer(n),a.onload=()=>{let o=m.default.validateFileType(a.result,[`heic`]),s=m.default.validateFileType(a.result,[`jpeg`,`png`,`gif`,`bmp`]);o?i(e(n)):s&&r.compressor?i(t(n)):i(n)}}),getDimension:async e=>new Promise((t,n)=>{let r=new Image;r.src=URL.createObjectURL(e),r.onload=()=>t({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=e=>n(e)}),getFileType:e=>new Promise(t=>{let n=new FileReader;n.readAsArrayBuffer(e),n.onload=()=>{t({mimeType:m.default.detectFile(n.result)?.mimeType})}})}},V=(e,t)=>({sendMessage:async(n,r)=>{let{onMessage:i,onEnd:a,onError:o,onFinish:s}=r;try{let{ok:r,status:c,statusText:l,body:u}=await fetch(`${e}/chat-messages`,{method:`POST`,headers:{Authorization:`Bearer ${t}`,"Content-Type":`application/json`},body:JSON.stringify({...n,response_mode:`streaming`})});if(!r)return o?.({code:String(c),message:l});let d=u?.getReader();if(!d)return o?.({code:`reader_error`,message:`Failed to get response reader`});let f=new TextDecoder,p=``;for(;;){let{done:e,value:t}=await d.read();if(e)break;p+=f.decode(t,{stream:!0});let n=p.split(`
|
|
2
|
+
`);p=n.pop()||``;for(let e of n)if(e.startsWith(`data:`))try{let t=e.slice(5).trim();if(!t)continue;let n=JSON.parse(t);if(n.event===`agent_message`)i?.(n.answer||``);else if(n.event===`message_end`)a?.(n.conversation_id,n.message_id);else if(n.event===`error`){let{code:e,message:t}=n;o?.({code:e,message:t})}s?.()}catch{}}}catch(e){o?.({code:`network_error`,message:String(e)})}}}),H={install(e,t){C(t),e.config.globalProperties.$setLocale=T,e.config.globalProperties.$getLocale=E}};exports.$params=O,exports.DateTime=F,exports.Formatter=N,exports.Platform=D,exports.Validate=P,exports.default=H,exports.download=M,exports.get=j,exports.getLocale=E,exports.request=k,exports.resource=A,exports.setLocale=T,exports.useBreak=L,exports.useCaptcha=z,exports.useChat=V,exports.useLocale=w,exports.useNanoid=R,exports.useUpload=B;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
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 };
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
|
|
2
|
+
@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.static{position:static}.shrink{flex-shrink:1}}.flex-center{justify-content:center;align-items:center;display:flex!important}.flex-center-end{justify-content:end;align-items:center;display:flex!important}.flex-center-between{justify-content:space-between;align-items:center;display:flex!important}.flex-center-items{align-items:center;display:flex!important}.text-light{color:#ccc}.dark .text-light{color:#333}
|
|
3
|
+
/*$vite$:1*/
|