@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.
@@ -0,0 +1,394 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { AxiosResponse } from 'axios';
3
+ import { ComputedRef } from 'vue';
4
+ import { default as default_2 } from 'dayjs';
5
+ import { nanoid } from 'nanoid';
6
+ import { Plugin as Plugin_2 } from 'vue';
7
+ import { Ref } from 'vue';
8
+
9
+ export declare const $params: (params: IModel) => {
10
+ [property: string]: any;
11
+ id?: string | any;
12
+ created_at?: string;
13
+ updated_at?: string;
14
+ deleted_at?: string;
15
+ };
16
+
17
+ export declare class DateTime {
18
+ static dayjs: typeof default_2;
19
+ static s(date?: default_2.ConfigType, symbol?: string): string;
20
+ static m(date?: default_2.ConfigType, symbol?: string): string;
21
+ static h(date?: default_2.ConfigType, symbol?: string): string;
22
+ static d(date?: default_2.ConfigType, symbol?: string): string;
23
+ static M(date?: default_2.ConfigType, symbol?: string): string;
24
+ static y(date?: default_2.ConfigType): string;
25
+ static date(date?: default_2.ConfigType, symbol?: string): string;
26
+ static time(date?: default_2.ConfigType): string;
27
+ static format(date?: default_2.ConfigType, format?: string): string;
28
+ }
29
+
30
+ export declare const download: (blob: Blob, filename: string) => void;
31
+
32
+ export declare class Formatter {
33
+ static config: {
34
+ locale?: string;
35
+ currency?: string;
36
+ decimals?: number;
37
+ };
38
+ static set: (config: {
39
+ locale?: string;
40
+ currency?: string;
41
+ decimals?: number;
42
+ }) => {
43
+ locale?: string;
44
+ currency?: string;
45
+ decimals?: number;
46
+ };
47
+ static id: (str?: string) => string;
48
+ static date: (datestr?: string) => string;
49
+ static idcard: (idcard?: string) => string;
50
+ static phone: (phone?: string, naked?: boolean) => string;
51
+ static email: (email?: string) => string;
52
+ static bankcard: (bankcard?: string) => string;
53
+ static url: (url?: string) => string;
54
+ static price: (value?: string | number, currency?: string) => string;
55
+ static currency: (value?: string | number, currency?: string) => string;
56
+ }
57
+
58
+ export declare const get: (object: any, path: string | string[], defaultValue?: any) => any;
59
+
60
+ export declare const getLocale: () => string;
61
+
62
+ export declare interface IAIResponse {
63
+ message: IChatMessageItem;
64
+ sessionId: string;
65
+ suggestions?: string[];
66
+ }
67
+
68
+ export declare interface IAsset extends IModel {
69
+ id: string;
70
+ type: string;
71
+ title: string;
72
+ url: string;
73
+ shrink: string;
74
+ }
75
+
76
+ export declare interface IChatConfig {
77
+ placeholder?: string;
78
+ maxFileSize?: number;
79
+ allowedFileTypes?: string[];
80
+ enableStreaming?: boolean;
81
+ showTimestamp?: boolean;
82
+ showSuggestions?: boolean;
83
+ }
84
+
85
+ export declare interface IChatFile {
86
+ id: string;
87
+ name: string;
88
+ type: string;
89
+ size: number;
90
+ url?: string;
91
+ thumbnail?: string;
92
+ }
93
+
94
+ export declare interface IChatMessage {
95
+ question: string;
96
+ answer: string;
97
+ conversation_id: string;
98
+ message_id: string;
99
+ created_at: number;
100
+ }
101
+
102
+ export declare interface IChatMessageItem {
103
+ id: string;
104
+ role: MessageRole;
105
+ content: string;
106
+ contentType?: MessageContentType;
107
+ timestamp: number;
108
+ isLoading?: boolean;
109
+ isError?: boolean;
110
+ files?: IChatFile[];
111
+ metadata?: Record<string, any>;
112
+ }
113
+
114
+ export declare interface IChatSession {
115
+ id: string;
116
+ title: string;
117
+ messages: IChatMessageItem[];
118
+ createdAt: number;
119
+ updatedAt: number;
120
+ isPinned?: boolean;
121
+ isArchived?: boolean;
122
+ }
123
+
124
+ export declare interface ICodeBlock {
125
+ language: string;
126
+ code: string;
127
+ filename?: string;
128
+ }
129
+
130
+ export declare interface IErrorEvent {
131
+ event: 'error';
132
+ task_id: string;
133
+ id: string;
134
+ code: string;
135
+ message: string;
136
+ }
137
+
138
+ export declare interface IField extends IModel {
139
+ name: string;
140
+ type: string;
141
+ readonly?: boolean;
142
+ multiple?: boolean;
143
+ required?: boolean;
144
+ options?: {
145
+ label: string;
146
+ value: string;
147
+ }[] | any[];
148
+ }
149
+
150
+ export declare type IFilter = Omit<IField, 'name'> & {
151
+ label?: string;
152
+ rules?: any[];
153
+ };
154
+
155
+ export declare interface IMenu {
156
+ key?: string;
157
+ title: string;
158
+ path: string;
159
+ name?: string;
160
+ icon?: string;
161
+ depend?: string;
162
+ hidden?: boolean;
163
+ divider?: boolean;
164
+ disabled?: boolean;
165
+ children?: IMenu[];
166
+ isGroup?: boolean;
167
+ }
168
+
169
+ export declare interface IMessageEvent {
170
+ event: 'message' | 'agent_message' | 'agent_thought' | 'message_file' | 'message_end' | 'tts_message' | 'tts_message_end' | 'message_replace' | 'error' | 'ping';
171
+ task_id: string;
172
+ id: string;
173
+ conversation_id: string;
174
+ message_id: string;
175
+ created_at: number;
176
+ answer?: string;
177
+ metadata?: Record<string, any>;
178
+ }
179
+
180
+ export declare interface IModel {
181
+ id?: string | any;
182
+ created_at?: string;
183
+ updated_at?: string;
184
+ deleted_at?: string;
185
+ [property: string]: any;
186
+ }
187
+
188
+ export declare interface IPagination {
189
+ current_page: number;
190
+ per_page: number;
191
+ count: number;
192
+ total: number;
193
+ total_pages: number;
194
+ }
195
+
196
+ export declare interface IParams extends IModel {
197
+ filter?: Object;
198
+ search?: string;
199
+ include?: string;
200
+ page?: number;
201
+ size?: number;
202
+ }
203
+
204
+ export declare interface IResult {
205
+ code: number;
206
+ message: string;
207
+ data?: IModel | IModel[] | null;
208
+ meta?: {
209
+ pagination?: IPagination;
210
+ };
211
+ }
212
+
213
+ export declare interface ISendChatParams {
214
+ content: string;
215
+ contentType?: MessageContentType;
216
+ files?: IChatFile[];
217
+ sessionId?: string;
218
+ }
219
+
220
+ export declare interface ISendMessageParams {
221
+ query: string;
222
+ inputs?: Record<string, any>;
223
+ response_mode?: 'streaming' | 'blocking';
224
+ conversation_id?: string;
225
+ user: string;
226
+ files?: Array<{
227
+ type: string;
228
+ transfer_method: 'remote_url' | 'local_file';
229
+ url?: string;
230
+ upload_file_id?: string;
231
+ }>;
232
+ auto_generate_name?: boolean;
233
+ }
234
+
235
+ export declare interface IUploadUserFile {
236
+ id?: string;
237
+ percentage?: number;
238
+ asset?: IAsset;
239
+ title?: string;
240
+ width?: number;
241
+ height?: number;
242
+ type?: string;
243
+ mimeType?: string;
244
+ }
245
+
246
+ export declare interface IUsageEvent {
247
+ event: 'message_end';
248
+ task_id: string;
249
+ id: string;
250
+ conversation_id: string;
251
+ message_id: string;
252
+ created_at: number;
253
+ usage: {
254
+ prompt_tokens: number;
255
+ prompt_unit_price: number;
256
+ prompt_price_unit: number;
257
+ prompt_price: number;
258
+ completion_tokens: number;
259
+ completion_unit_price: number;
260
+ completion_price_unit: number;
261
+ completion_price: number;
262
+ total_tokens: number;
263
+ total_price: number;
264
+ currency: string;
265
+ latency: number;
266
+ };
267
+ metadata?: Record<string, any>;
268
+ }
269
+
270
+ export declare type MessageContentType = 'text' | 'image' | 'code' | 'file';
271
+
272
+ export declare type MessageRole = 'user' | 'assistant' | 'system';
273
+
274
+ export declare class Platform {
275
+ static get userAgent(): string;
276
+ static get isFlutter(): boolean;
277
+ static get isFlutterIOS(): boolean;
278
+ static get isWeb(): boolean;
279
+ static get isMobile(): boolean;
280
+ static get isIOS(): boolean;
281
+ static get isWechat(): boolean;
282
+ static get isWxwork(): boolean;
283
+ static get isMiniprogram(): boolean;
284
+ }
285
+
286
+ export declare const request: {
287
+ baseURL: string;
288
+ publicKey: string;
289
+ headers: Record<string, string>;
290
+ instance: AxiosInstance | null;
291
+ accessToken: string;
292
+ init(config?: {
293
+ baseURL?: string;
294
+ publicKey?: string;
295
+ }): void;
296
+ setToken(token: string, options?: {
297
+ expires?: number;
298
+ domain?: string;
299
+ }): void;
300
+ getToken(): string;
301
+ delToken(): void;
302
+ get(url: string, params?: {}, auth?: boolean): any;
303
+ put(url: string, data?: {}, auth?: boolean): any;
304
+ patch(url: string, data?: {}, auth?: boolean): any;
305
+ delete(url: string, params?: {}, auth?: boolean): any;
306
+ post(url: string, data?: {}, auth?: boolean): any;
307
+ blob(url: string, params?: {}, auth?: boolean): any;
308
+ request(para: any, auth?: boolean): any;
309
+ download(url: string, params?: {}, filename?: string, auth?: boolean): Promise<any>;
310
+ upload(url: string, data?: {}): Promise<AxiosResponse<any, any, {}>>;
311
+ sse(url: string, para?: {
312
+ [key: string]: string | number | undefined | null | void;
313
+ } | null): EventSource;
314
+ setHeader(key: string, value: string): void;
315
+ delHeader(key: string): void;
316
+ };
317
+
318
+ export declare class resource {
319
+ url: string;
320
+ auth: boolean;
321
+ constructor(url: string, auth?: boolean);
322
+ select: (para?: {}) => any;
323
+ create: (para?: {}) => any;
324
+ find: (id: string, para?: {}) => any;
325
+ update: (id: string, para?: {}) => any;
326
+ delete: (id: string, para?: {}) => any;
327
+ get(para: any): Promise<any>;
328
+ }
329
+
330
+ export declare const setLocale: (lang: string) => string;
331
+
332
+ export declare const useBreak: () => {
333
+ isMobile: ComputedRef<boolean>;
334
+ isDesktop: ComputedRef<boolean>;
335
+ };
336
+
337
+ export declare const useCaptcha: (api: (data: any) => Promise<void>) => {
338
+ waiting: Ref<number, number>;
339
+ send: (para?: {}) => Promise<unknown>;
340
+ };
341
+
342
+ export declare const useChat: (baseURL: string, apiKey: string) => {
343
+ sendMessage: (params: ISendMessageParams, callbacks: {
344
+ onMessage?: (text: string) => void;
345
+ onEnd?: (conversationId: string, messageId: string) => void;
346
+ onError?: (error: {
347
+ code: string;
348
+ message: string;
349
+ }) => void;
350
+ onFinish?: () => void;
351
+ }) => Promise<void>;
352
+ };
353
+
354
+ export declare const useLocale: () => {
355
+ locale: Ref<string, string>;
356
+ t: (path: string, params?: Record<string, string | number>) => string;
357
+ };
358
+
359
+ export declare const useNanoid: () => {
360
+ nanoid: typeof nanoid;
361
+ numeric: (length?: number) => string;
362
+ };
363
+
364
+ export declare const useUpload: () => {
365
+ handler: (file: File, para?: {
366
+ compressor: boolean;
367
+ }) => Promise<File>;
368
+ getDimension: (blob: Blob) => Promise<{
369
+ width: number;
370
+ height: number;
371
+ }>;
372
+ getFileType: (file: File) => Promise<{
373
+ mimeType: string;
374
+ }>;
375
+ };
376
+
377
+ export declare class Validate {
378
+ static country: string;
379
+ static set: (country: string) => string;
380
+ static get phone_pattern(): RegExp;
381
+ static email_pattern: RegExp;
382
+ static idcard_pattern: RegExp;
383
+ static cname_pattern: RegExp;
384
+ static password_pattern: RegExp;
385
+ static phone: (str: string) => boolean;
386
+ static email: (str: string) => boolean;
387
+ static idcard: (str: string) => boolean;
388
+ static cname: (str: string) => boolean;
389
+ }
390
+
391
+ declare const VueGo: Plugin_2;
392
+ export default VueGo;
393
+
394
+ export { }
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@gindow/vue",
3
+ "version": "1.0.0",
4
+ "description": "Vue3 通用基础包,包含工具函数、Hooks、类型定义、国际化、基础样式",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./dist/vue.cjs",
8
+ "types": "./dist/vue.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/vue.d.ts",
12
+ "import": "./dist/vue.mjs",
13
+ "require": "./dist/vue.cjs"
14
+ },
15
+ "./style.css": "./dist/style.css",
16
+ "./src/*": "./src/*",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src",
22
+ "README.md"
23
+ ],
24
+ "sideEffects": [
25
+ "**/*.css"
26
+ ],
27
+ "scripts": {
28
+ "build": "vue-tsc --noEmit && vite build"
29
+ },
30
+ "peerDependencies": {
31
+ "@icon-park/vue-next": "^1.4.0",
32
+ "@iconify/vue": "^5.0.0",
33
+ "@vueuse/core": "^12.0.0",
34
+ "axios": "^1.6.0",
35
+ "compressorjs": "^1.2.0",
36
+ "dayjs": "^1.11.0",
37
+ "file-type-checker": "^1.0.0",
38
+ "heic2any": "^0.0.4",
39
+ "js-cookie": "^3.0.0",
40
+ "nanoid": "^5.0.0",
41
+ "vue": "^3.5.0"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@icon-park/vue-next": {
45
+ "optional": true
46
+ },
47
+ "@iconify/vue": {
48
+ "optional": true
49
+ },
50
+ "@vueuse/core": {
51
+ "optional": true
52
+ },
53
+ "axios": {
54
+ "optional": true
55
+ },
56
+ "compressorjs": {
57
+ "optional": true
58
+ },
59
+ "dayjs": {
60
+ "optional": true
61
+ },
62
+ "file-type-checker": {
63
+ "optional": true
64
+ },
65
+ "heic2any": {
66
+ "optional": true
67
+ },
68
+ "js-cookie": {
69
+ "optional": true
70
+ },
71
+ "nanoid": {
72
+ "optional": true
73
+ }
74
+ },
75
+ "devDependencies": {
76
+ "@icon-park/vue-next": "^1.4.2",
77
+ "@iconify/vue": "^5.0.1",
78
+ "@tailwindcss/vite": "^4.3.0",
79
+ "@types/js-cookie": "^3.0.6",
80
+ "@types/lodash": "^4.17.24",
81
+ "@types/node": "^22.19.18",
82
+ "@vitejs/plugin-vue": "^6.0.6",
83
+ "@vue/tsconfig": "^0.5.1",
84
+ "@vueuse/core": "^14.3.0",
85
+ "axios": "^1.16.1",
86
+ "compressorjs": "^1.3.0",
87
+ "dayjs": "^1.11.20",
88
+ "file-type-checker": "^1.1.6",
89
+ "heic2any": "^0.0.4",
90
+ "js-cookie": "^3.0.7",
91
+ "nanoid": "^5.1.11",
92
+ "tailwindcss": "^4.3.0",
93
+ "typescript": "^5.9.3",
94
+ "vite": "^8.0.11",
95
+ "vite-plugin-dts": "^4.5.4",
96
+ "vue": "^3.5.34",
97
+ "vue-tsc": "^2.2.12"
98
+ }
99
+ }
package/src/env.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.vue' {
4
+ import type { DefineComponent } from 'vue'
5
+ const component: DefineComponent<{}, {}, any>
6
+ export default component
7
+ }
@@ -0,0 +1,23 @@
1
+ import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
2
+
3
+ const MD = 768
4
+
5
+ export const useBreak = () => {
6
+ const matches = ref(typeof window !== 'undefined' ? window.matchMedia(`(min-width: ${MD}px)`).matches : true)
7
+ let mql: MediaQueryList | undefined
8
+ const onChange = (e: MediaQueryListEvent) => matches.value = e.matches
9
+
10
+ onMounted(() => {
11
+ if (typeof window === 'undefined') return
12
+ mql = window.matchMedia(`(min-width: ${MD}px)`)
13
+ matches.value = mql.matches
14
+ mql.addEventListener('change', onChange)
15
+ })
16
+
17
+ onBeforeUnmount(() => mql?.removeEventListener('change', onChange))
18
+
19
+ const isDesktop = computed(() => matches.value)
20
+ const isMobile = computed(() => !matches.value)
21
+
22
+ return { isMobile, isDesktop }
23
+ }
@@ -0,0 +1,29 @@
1
+ import { ref } from 'vue'
2
+
3
+ export const useCaptcha = (api: (data: any) => Promise<void>) => {
4
+
5
+ const waiting = ref(0)
6
+ const loading = ref(false)
7
+
8
+ const send = (para = {}) => {
9
+ return new Promise((resolve, reject) => {
10
+ if (loading.value) return
11
+ loading.value = true
12
+ api(para).then(() => {
13
+ timer()
14
+ resolve(true)
15
+ }).catch(err => reject(err))
16
+ .finally(() => loading.value = false)
17
+ })
18
+ }
19
+
20
+ const timer = () => {
21
+ waiting.value = 60
22
+ const time = setInterval(() => {
23
+ waiting.value--
24
+ if (!waiting.value) clearTimeout(time)
25
+ }, 1000)
26
+ }
27
+
28
+ return { waiting, send }
29
+ }
@@ -0,0 +1,135 @@
1
+ export interface IChatMessage {
2
+ question: string
3
+ answer: string
4
+ conversation_id: string
5
+ message_id: string
6
+ created_at: number
7
+ }
8
+
9
+ export interface IMessageEvent {
10
+ event: 'message' | 'agent_message' | 'agent_thought' | 'message_file' | 'message_end' | 'tts_message' | 'tts_message_end' | 'message_replace' | 'error' | 'ping'
11
+ task_id: string
12
+ id: string
13
+ conversation_id: string
14
+ message_id: string
15
+ created_at: number
16
+ answer?: string
17
+ metadata?: Record<string, any>
18
+ }
19
+
20
+ export interface IUsageEvent {
21
+ event: 'message_end'
22
+ task_id: string
23
+ id: string
24
+ conversation_id: string
25
+ message_id: string
26
+ created_at: number
27
+ usage: {
28
+ prompt_tokens: number
29
+ prompt_unit_price: number
30
+ prompt_price_unit: number
31
+ prompt_price: number
32
+ completion_tokens: number
33
+ completion_unit_price: number
34
+ completion_price_unit: number
35
+ completion_price: number
36
+ total_tokens: number
37
+ total_price: number
38
+ currency: string
39
+ latency: number
40
+ }
41
+ metadata?: Record<string, any>
42
+ }
43
+
44
+ export interface IErrorEvent {
45
+ event: 'error'
46
+ task_id: string
47
+ id: string
48
+ code: string
49
+ message: string
50
+ }
51
+
52
+ export interface ISendMessageParams {
53
+ query: string
54
+ inputs?: Record<string, any>
55
+ response_mode?: 'streaming' | 'blocking'
56
+ conversation_id?: string
57
+ user: string
58
+ files?: Array<{
59
+ type: string
60
+ transfer_method: 'remote_url' | 'local_file'
61
+ url?: string
62
+ upload_file_id?: string
63
+ }>
64
+ auto_generate_name?: boolean
65
+ }
66
+
67
+ export const useChat = (baseURL: string, apiKey: string) => {
68
+
69
+ const sendMessage = async (
70
+ params: ISendMessageParams,
71
+ callbacks: {
72
+ onMessage?: (text: string) => void
73
+ onEnd?: (conversationId: string, messageId: string) => void
74
+ onError?: (error: { code: string; message: string }) => void
75
+ onFinish?: () => void
76
+ },
77
+ ) => {
78
+ const { onMessage, onEnd, onError, onFinish } = callbacks
79
+
80
+ try {
81
+ const { ok, status, statusText, body } = await fetch(`${baseURL}/chat-messages`, {
82
+ method: 'POST',
83
+ headers: {
84
+ 'Authorization': `Bearer ${apiKey}`,
85
+ 'Content-Type': 'application/json',
86
+ },
87
+ body: JSON.stringify({
88
+ ...params,
89
+ response_mode: 'streaming',
90
+ }),
91
+ })
92
+
93
+ if (!ok) return onError?.({ code: String(status), message: statusText })
94
+
95
+ const reader = body?.getReader()
96
+ if (!reader) return onError?.({ code: 'reader_error', message: 'Failed to get response reader' })
97
+
98
+ const decoder = new TextDecoder()
99
+ let buffer = ''
100
+
101
+ while (true) {
102
+ const { done, value } = await reader.read()
103
+ if (done) break
104
+
105
+ buffer += decoder.decode(value, { stream: true })
106
+ const lines = buffer.split('\n')
107
+ buffer = lines.pop() || ''
108
+
109
+ for (const line of lines) {
110
+ if (line.startsWith('data:')) {
111
+ try {
112
+ const jsonStr = line.slice(5).trim()
113
+ if (!jsonStr) continue
114
+
115
+ const data = JSON.parse(jsonStr) as IMessageEvent | IUsageEvent | IErrorEvent
116
+
117
+ if (data.event === 'agent_message') onMessage?.((data as IMessageEvent).answer || '')
118
+ else if (data.event === 'message_end') onEnd?.(data.conversation_id, data.message_id)
119
+ else if (data.event === 'error') {
120
+ const { code, message } = data as IErrorEvent
121
+ onError?.({ code, message })
122
+ }
123
+
124
+ onFinish?.()
125
+ } catch (e) {}
126
+ }
127
+ }
128
+ }
129
+ } catch (error) {
130
+ onError?.({ code: 'network_error', message: String(error) })
131
+ }
132
+ }
133
+
134
+ return { sendMessage }
135
+ }
@@ -0,0 +1,9 @@
1
+ import { nanoid } from 'nanoid'
2
+ import { customAlphabet } from 'nanoid/non-secure'
3
+
4
+ export const useNanoid = () => {
5
+
6
+ const numeric = (length = 10) => customAlphabet('1234567890', length)()
7
+
8
+ return { nanoid, numeric }
9
+ }