vue-element-ui-x 1.0.51 → 1.1.1
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 +140 -140
- package/components.json +12 -12
- package/lib/components/Attachments/index.js +17 -17
- package/lib/components/EditorSender/index.js +1508 -0
- package/lib/components/FilesCard/index.js +16 -16
- package/lib/components/Prompts/index.js +21 -21
- package/lib/index.common.js +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1274 -287
- package/lib/index.umd.js +1 -1
- package/lib/locale/index.js +97 -97
- package/lib/locale/lang/ar.js +18 -18
- package/lib/locale/lang/ar.umd.js +17 -17
- package/lib/locale/lang/de.js +18 -18
- package/lib/locale/lang/de.umd.js +17 -17
- package/lib/locale/lang/en.js +18 -18
- package/lib/locale/lang/en.umd.js +17 -17
- package/lib/locale/lang/es.js +18 -18
- package/lib/locale/lang/es.umd.js +17 -17
- package/lib/locale/lang/fr.js +18 -18
- package/lib/locale/lang/fr.umd.js +17 -17
- package/lib/locale/lang/it.js +18 -18
- package/lib/locale/lang/it.umd.js +17 -17
- package/lib/locale/lang/ja.js +18 -18
- package/lib/locale/lang/ja.umd.js +17 -17
- package/lib/locale/lang/ko.js +18 -18
- package/lib/locale/lang/ko.umd.js +17 -17
- package/lib/locale/lang/pt-br.js +18 -18
- package/lib/locale/lang/pt-br.umd.js +17 -17
- package/lib/locale/lang/ru-RU.js +18 -18
- package/lib/locale/lang/ru-RU.umd.js +17 -17
- package/lib/locale/lang/zh-CN.js +18 -18
- package/lib/locale/lang/zh-CN.umd.js +17 -17
- package/lib/locale/lang/zh-TW.js +18 -18
- package/lib/locale/lang/zh-TW.umd.js +17 -17
- package/lib/locale/mixin.js +9 -9
- package/lib/mixins/index.js +250 -250
- package/package.json +77 -76
package/lib/mixins/index.js
CHANGED
|
@@ -56,9 +56,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
;// ./src/mixins/recordMixin.js
|
|
59
|
-
/**
|
|
60
|
-
* @description 提供语音识别的混入,允许语音输入并处理开始、结束、结果及错误等各种事件。
|
|
61
|
-
* @mixin recordMixin
|
|
59
|
+
/**
|
|
60
|
+
* @description 提供语音识别的混入,允许语音输入并处理开始、结束、结果及错误等各种事件。
|
|
61
|
+
* @mixin recordMixin
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
64
|
/* harmony default export */ const recordMixin = ({
|
|
@@ -80,13 +80,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
80
80
|
};
|
|
81
81
|
},
|
|
82
82
|
methods: {
|
|
83
|
-
/**
|
|
84
|
-
* 初始化语音识别配置
|
|
85
|
-
* @param {Object} options - 配置选项
|
|
86
|
-
* @param {Function} [options.onError] - 错误回调
|
|
87
|
-
* @param {Function} [options.onStart] - 开始回调
|
|
88
|
-
* @param {Function} [options.onEnd] - 结束回调
|
|
89
|
-
* @param {Function} [options.onResult] - 结果回调
|
|
83
|
+
/**
|
|
84
|
+
* 初始化语音识别配置
|
|
85
|
+
* @param {Object} options - 配置选项
|
|
86
|
+
* @param {Function} [options.onError] - 错误回调
|
|
87
|
+
* @param {Function} [options.onStart] - 开始回调
|
|
88
|
+
* @param {Function} [options.onEnd] - 结束回调
|
|
89
|
+
* @param {Function} [options.onResult] - 结果回调
|
|
90
90
|
*/
|
|
91
91
|
initRecord(options = {}) {
|
|
92
92
|
this.recordOptions = {
|
|
@@ -94,8 +94,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
94
94
|
...options
|
|
95
95
|
};
|
|
96
96
|
},
|
|
97
|
-
/**
|
|
98
|
-
* 开始语音识别
|
|
97
|
+
/**
|
|
98
|
+
* 开始语音识别
|
|
99
99
|
*/
|
|
100
100
|
startRecord() {
|
|
101
101
|
if ('webkitSpeechRecognition' in window) {
|
|
@@ -143,16 +143,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
|
-
/**
|
|
147
|
-
* 停止语音识别
|
|
146
|
+
/**
|
|
147
|
+
* 停止语音识别
|
|
148
148
|
*/
|
|
149
149
|
stopRecord() {
|
|
150
150
|
if (this.recordRecognition) {
|
|
151
151
|
this.recordRecognition.stop();
|
|
152
152
|
}
|
|
153
153
|
},
|
|
154
|
-
/**
|
|
155
|
-
* 清理语音识别资源
|
|
154
|
+
/**
|
|
155
|
+
* 清理语音识别资源
|
|
156
156
|
*/
|
|
157
157
|
cleanupRecord() {
|
|
158
158
|
this.stopRecord();
|
|
@@ -164,8 +164,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
;// ./src/mixins/sendMixin.js
|
|
167
|
-
/**
|
|
168
|
-
* XRequest 类 - 用于处理 SSE 和 Fetch 请求
|
|
167
|
+
/**
|
|
168
|
+
* XRequest 类 - 用于处理 SSE 和 Fetch 请求
|
|
169
169
|
*/
|
|
170
170
|
class XRequest {
|
|
171
171
|
constructor(options = {}) {
|
|
@@ -263,10 +263,10 @@ class XRequest {
|
|
|
263
263
|
this._controller && this._controller.abort();
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
|
-
/**
|
|
267
|
-
* 处理缓冲区数据,提取完整的行
|
|
268
|
-
* @param {string} buffer - 缓冲区数据
|
|
269
|
-
* @returns {string} 剩余的不完整数据
|
|
266
|
+
/**
|
|
267
|
+
* 处理缓冲区数据,提取完整的行
|
|
268
|
+
* @param {string} buffer - 缓冲区数据
|
|
269
|
+
* @returns {string} 剩余的不完整数据
|
|
270
270
|
*/
|
|
271
271
|
processBuffer(buffer) {
|
|
272
272
|
const lines = buffer.split('\n');
|
|
@@ -281,9 +281,9 @@ class XRequest {
|
|
|
281
281
|
return remainingData || '';
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
/**
|
|
285
|
-
* 处理单行数据
|
|
286
|
-
* @param {string} line - 单行数据
|
|
284
|
+
/**
|
|
285
|
+
* 处理单行数据
|
|
286
|
+
* @param {string} line - 单行数据
|
|
287
287
|
*/
|
|
288
288
|
processLine(line) {
|
|
289
289
|
// 跳过空行
|
|
@@ -334,9 +334,9 @@ class XRequest {
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
/**
|
|
338
|
-
* 处理缓冲区中剩余的数据(在流结束时调用)
|
|
339
|
-
* @param {string} buffer - 剩余的缓冲区数据
|
|
337
|
+
/**
|
|
338
|
+
* 处理缓冲区中剩余的数据(在流结束时调用)
|
|
339
|
+
* @param {string} buffer - 剩余的缓冲区数据
|
|
340
340
|
*/
|
|
341
341
|
processBufferData(buffer) {
|
|
342
342
|
const lines = buffer.split('\n');
|
|
@@ -438,9 +438,9 @@ class XRequest {
|
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
-
/**
|
|
442
|
-
* sendMixin -
|
|
443
|
-
* 用于处理发送操作管理请求状态的 mixin,支持可选的中止功能,同时支持 Promise 和 SSE(服务端事件)
|
|
441
|
+
/**
|
|
442
|
+
* sendMixin -
|
|
443
|
+
* 用于处理发送操作管理请求状态的 mixin,支持可选的中止功能,同时支持 Promise 和 SSE(服务端事件)
|
|
444
444
|
*/
|
|
445
445
|
const sendMixin = {
|
|
446
446
|
data() {
|
|
@@ -451,13 +451,13 @@ const sendMixin = {
|
|
|
451
451
|
};
|
|
452
452
|
},
|
|
453
453
|
methods: {
|
|
454
|
-
/**
|
|
455
|
-
* 初始化发送配置
|
|
456
|
-
* @param {Object} options - 配置选项
|
|
457
|
-
* @param {Function} options.onAbort - 中止回调
|
|
458
|
-
* @param {Function} options.sendHandler - 发送处理器
|
|
459
|
-
* @param {Function} options.abortHandler - 中止处理器
|
|
460
|
-
* @param {Function} options.finishHandler - 完成处理器
|
|
454
|
+
/**
|
|
455
|
+
* 初始化发送配置
|
|
456
|
+
* @param {Object} options - 配置选项
|
|
457
|
+
* @param {Function} options.onAbort - 中止回调
|
|
458
|
+
* @param {Function} options.sendHandler - 发送处理器
|
|
459
|
+
* @param {Function} options.abortHandler - 中止处理器
|
|
460
|
+
* @param {Function} options.finishHandler - 完成处理器
|
|
461
461
|
*/
|
|
462
462
|
initSend(options = {}) {
|
|
463
463
|
this._sendOptions = {
|
|
@@ -467,9 +467,9 @@ const sendMixin = {
|
|
|
467
467
|
finishHandler: options.finishHandler
|
|
468
468
|
};
|
|
469
469
|
},
|
|
470
|
-
/**
|
|
471
|
-
* 发送操作
|
|
472
|
-
* @param {...any} args - 传递给 sendHandler 的参数
|
|
470
|
+
/**
|
|
471
|
+
* 发送操作
|
|
472
|
+
* @param {...any} args - 传递给 sendHandler 的参数
|
|
473
473
|
*/
|
|
474
474
|
handleSend(...args) {
|
|
475
475
|
if (this.loading) {
|
|
@@ -480,8 +480,8 @@ const sendMixin = {
|
|
|
480
480
|
}
|
|
481
481
|
this.loading = true;
|
|
482
482
|
},
|
|
483
|
-
/**
|
|
484
|
-
* 中止操作
|
|
483
|
+
/**
|
|
484
|
+
* 中止操作
|
|
485
485
|
*/
|
|
486
486
|
handleAbort() {
|
|
487
487
|
this.loading = false;
|
|
@@ -492,8 +492,8 @@ const sendMixin = {
|
|
|
492
492
|
this._sendOptions.onAbort();
|
|
493
493
|
}
|
|
494
494
|
},
|
|
495
|
-
/**
|
|
496
|
-
* 完成操作
|
|
495
|
+
/**
|
|
496
|
+
* 完成操作
|
|
497
497
|
*/
|
|
498
498
|
handleFinish() {
|
|
499
499
|
this.loading = false;
|
|
@@ -501,10 +501,10 @@ const sendMixin = {
|
|
|
501
501
|
this._sendOptions.finishHandler();
|
|
502
502
|
}
|
|
503
503
|
},
|
|
504
|
-
/**
|
|
505
|
-
* 创建 XRequest 实例的便捷方法
|
|
506
|
-
* @param {Object} options - XRequest 配置选项
|
|
507
|
-
* @returns {XRequest} XRequest 实例
|
|
504
|
+
/**
|
|
505
|
+
* 创建 XRequest 实例的便捷方法
|
|
506
|
+
* @param {Object} options - XRequest 配置选项
|
|
507
|
+
* @returns {XRequest} XRequest 实例
|
|
508
508
|
*/
|
|
509
509
|
createXRequest(options = {}) {
|
|
510
510
|
return new XRequest({
|
|
@@ -532,10 +532,10 @@ const sendMixin = {
|
|
|
532
532
|
}
|
|
533
533
|
};
|
|
534
534
|
|
|
535
|
-
/**
|
|
536
|
-
* 工具函数版本 - 用于非组件场景
|
|
537
|
-
* @param {Object} options - 配置选项
|
|
538
|
-
* @returns {Object} 包含发送相关方法的对象
|
|
535
|
+
/**
|
|
536
|
+
* 工具函数版本 - 用于非组件场景
|
|
537
|
+
* @param {Object} options - 配置选项
|
|
538
|
+
* @returns {Object} 包含发送相关方法的对象
|
|
539
539
|
*/
|
|
540
540
|
function createSendUtils(options = {}) {
|
|
541
541
|
const state = {
|
|
@@ -574,99 +574,99 @@ function createSendUtils(options = {}) {
|
|
|
574
574
|
}
|
|
575
575
|
/* harmony default export */ const mixins_sendMixin = ((/* unused pure expression or super */ null && (sendMixin)));
|
|
576
576
|
;// ./src/mixins/streamMixin.js
|
|
577
|
-
/**
|
|
578
|
-
* @fileoverview 流式数据处理 Mixin
|
|
579
|
-
* 支持 SSE 数据解析和中断功能
|
|
577
|
+
/**
|
|
578
|
+
* @fileoverview 流式数据处理 Mixin
|
|
579
|
+
* 支持 SSE 数据解析和中断功能
|
|
580
580
|
*/
|
|
581
581
|
|
|
582
|
-
/**
|
|
583
|
-
* 默认流分隔符
|
|
584
|
-
* @type {string}
|
|
585
|
-
* @constant
|
|
582
|
+
/**
|
|
583
|
+
* 默认流分隔符
|
|
584
|
+
* @type {string}
|
|
585
|
+
* @constant
|
|
586
586
|
*/
|
|
587
587
|
const DEFAULT_STREAM_SEPARATOR = '\n\n';
|
|
588
588
|
|
|
589
|
-
/**
|
|
590
|
-
* 默认部分分隔符
|
|
591
|
-
* @type {string}
|
|
592
|
-
* @constant
|
|
589
|
+
/**
|
|
590
|
+
* 默认部分分隔符
|
|
591
|
+
* @type {string}
|
|
592
|
+
* @constant
|
|
593
593
|
*/
|
|
594
594
|
const DEFAULT_PART_SEPARATOR = '\n';
|
|
595
595
|
|
|
596
|
-
/**
|
|
597
|
-
* 默认键值分隔符
|
|
598
|
-
* @type {string}
|
|
599
|
-
* @constant
|
|
596
|
+
/**
|
|
597
|
+
* 默认键值分隔符
|
|
598
|
+
* @type {string}
|
|
599
|
+
* @constant
|
|
600
600
|
*/
|
|
601
601
|
const DEFAULT_KV_SEPARATOR = ':';
|
|
602
602
|
|
|
603
|
-
/**
|
|
604
|
-
* SSE 字段类型定义
|
|
605
|
-
* @typedef {'data'|'event'|'id'|'retry'} SSEFields
|
|
603
|
+
/**
|
|
604
|
+
* SSE 字段类型定义
|
|
605
|
+
* @typedef {'data'|'event'|'id'|'retry'} SSEFields
|
|
606
606
|
*/
|
|
607
607
|
|
|
608
|
-
/**
|
|
609
|
-
* SSE 输出对象类型
|
|
610
|
-
* @typedef {Object} SSEOutput
|
|
611
|
-
* @property {string} [data] - 数据字段
|
|
612
|
-
* @property {string} [event] - 事件字段
|
|
613
|
-
* @property {string} [id] - ID字段
|
|
614
|
-
* @property {string} [retry] - 重试字段
|
|
608
|
+
/**
|
|
609
|
+
* SSE 输出对象类型
|
|
610
|
+
* @typedef {Object} SSEOutput
|
|
611
|
+
* @property {string} [data] - 数据字段
|
|
612
|
+
* @property {string} [event] - 事件字段
|
|
613
|
+
* @property {string} [id] - ID字段
|
|
614
|
+
* @property {string} [retry] - 重试字段
|
|
615
615
|
*/
|
|
616
616
|
|
|
617
|
-
/**
|
|
618
|
-
* 流配置选项
|
|
619
|
-
* @typedef {Object} XStreamOptions
|
|
620
|
-
* @property {ReadableStream<Uint8Array>} readableStream - 可读流
|
|
621
|
-
* @property {TransformStream<string, *>} [transformStream] - 可选的转换流
|
|
617
|
+
/**
|
|
618
|
+
* 流配置选项
|
|
619
|
+
* @typedef {Object} XStreamOptions
|
|
620
|
+
* @property {ReadableStream<Uint8Array>} readableStream - 可读流
|
|
621
|
+
* @property {TransformStream<string, *>} [transformStream] - 可选的转换流
|
|
622
622
|
*/
|
|
623
623
|
|
|
624
|
-
/**
|
|
625
|
-
* 流状态对象
|
|
626
|
-
* @typedef {Object} StreamState
|
|
627
|
-
* @property {Array<*>} data - 流数据数组
|
|
628
|
-
* @property {Error|null} error - 错误信息
|
|
629
|
-
* @property {boolean} loading - 加载状态
|
|
624
|
+
/**
|
|
625
|
+
* 流状态对象
|
|
626
|
+
* @typedef {Object} StreamState
|
|
627
|
+
* @property {Array<*>} data - 流数据数组
|
|
628
|
+
* @property {Error|null} error - 错误信息
|
|
629
|
+
* @property {boolean} loading - 加载状态
|
|
630
630
|
*/
|
|
631
631
|
|
|
632
|
-
/**
|
|
633
|
-
* 流回调函数配置
|
|
634
|
-
* @typedef {Object} StreamCallbacks
|
|
635
|
-
* @property {function(*): void} [onData] - 数据回调函数
|
|
636
|
-
* @property {function(Array<*>): void} [onComplete] - 完成回调函数
|
|
637
|
-
* @property {function(Error): void} [onError] - 错误回调函数
|
|
638
|
-
* @property {function(): void} [onCancel] - 取消回调函数
|
|
639
|
-
* @property {function(): void} [onFinish] - 结束回调函数
|
|
632
|
+
/**
|
|
633
|
+
* 流回调函数配置
|
|
634
|
+
* @typedef {Object} StreamCallbacks
|
|
635
|
+
* @property {function(*): void} [onData] - 数据回调函数
|
|
636
|
+
* @property {function(Array<*>): void} [onComplete] - 完成回调函数
|
|
637
|
+
* @property {function(Error): void} [onError] - 错误回调函数
|
|
638
|
+
* @property {function(): void} [onCancel] - 取消回调函数
|
|
639
|
+
* @property {function(): void} [onFinish] - 结束回调函数
|
|
640
640
|
*/
|
|
641
641
|
|
|
642
|
-
/**
|
|
643
|
-
* 流工具函数返回对象
|
|
644
|
-
* @typedef {Object} StreamUtils
|
|
645
|
-
* @property {StreamState} state - 流状态
|
|
646
|
-
* @property {function(XStreamOptions): Promise<void>} startStream - 启动流处理
|
|
647
|
-
* @property {function(): void} cancel - 取消流处理
|
|
648
|
-
* @property {function(): void} reset - 重置流状态
|
|
642
|
+
/**
|
|
643
|
+
* 流工具函数返回对象
|
|
644
|
+
* @typedef {Object} StreamUtils
|
|
645
|
+
* @property {StreamState} state - 流状态
|
|
646
|
+
* @property {function(XStreamOptions): Promise<void>} startStream - 启动流处理
|
|
647
|
+
* @property {function(): void} cancel - 取消流处理
|
|
648
|
+
* @property {function(): void} reset - 重置流状态
|
|
649
649
|
*/
|
|
650
650
|
|
|
651
|
-
/**
|
|
652
|
-
* 验证字符串是否有效(非空且非空白)
|
|
653
|
-
* @param {string} str - 待验证的字符串
|
|
654
|
-
* @returns {boolean} 是否为有效字符串
|
|
651
|
+
/**
|
|
652
|
+
* 验证字符串是否有效(非空且非空白)
|
|
653
|
+
* @param {string} str - 待验证的字符串
|
|
654
|
+
* @returns {boolean} 是否为有效字符串
|
|
655
655
|
*/
|
|
656
656
|
const isValidString = str => (str === null || str === undefined ? '' : str).trim() !== '';
|
|
657
657
|
|
|
658
|
-
/**
|
|
659
|
-
* 创建流分割转换器
|
|
660
|
-
* 按照默认分隔符分割流数据
|
|
661
|
-
* @returns {TransformStream<string, string>} 流分割转换器
|
|
658
|
+
/**
|
|
659
|
+
* 创建流分割转换器
|
|
660
|
+
* 按照默认分隔符分割流数据
|
|
661
|
+
* @returns {TransformStream<string, string>} 流分割转换器
|
|
662
662
|
*/
|
|
663
663
|
function splitStream() {
|
|
664
664
|
let buffer = '';
|
|
665
665
|
return new TransformStream({
|
|
666
|
-
/**
|
|
667
|
-
* 转换函数
|
|
668
|
-
* @param {string} chunk - 数据块
|
|
669
|
-
* @param {TransformStreamDefaultController<string>} controller - 控制器
|
|
666
|
+
/**
|
|
667
|
+
* 转换函数
|
|
668
|
+
* @param {string} chunk - 数据块
|
|
669
|
+
* @param {TransformStreamDefaultController<string>} controller - 控制器
|
|
670
670
|
*/
|
|
671
671
|
transform(chunk, controller) {
|
|
672
672
|
buffer += chunk;
|
|
@@ -676,9 +676,9 @@ function splitStream() {
|
|
|
676
676
|
});
|
|
677
677
|
buffer = parts[parts.length - 1];
|
|
678
678
|
},
|
|
679
|
-
/**
|
|
680
|
-
* 刷新函数
|
|
681
|
-
* @param {TransformStreamDefaultController<string>} controller - 控制器
|
|
679
|
+
/**
|
|
680
|
+
* 刷新函数
|
|
681
|
+
* @param {TransformStreamDefaultController<string>} controller - 控制器
|
|
682
682
|
*/
|
|
683
683
|
flush(controller) {
|
|
684
684
|
if (isValidString(buffer)) controller.enqueue(buffer);
|
|
@@ -686,17 +686,17 @@ function splitStream() {
|
|
|
686
686
|
});
|
|
687
687
|
}
|
|
688
688
|
|
|
689
|
-
/**
|
|
690
|
-
* 创建 SSE 数据解析转换器
|
|
691
|
-
* 将文本数据解析为 SSE 格式对象
|
|
692
|
-
* @returns {TransformStream<string, SSEOutput>} SSE 解析转换器
|
|
689
|
+
/**
|
|
690
|
+
* 创建 SSE 数据解析转换器
|
|
691
|
+
* 将文本数据解析为 SSE 格式对象
|
|
692
|
+
* @returns {TransformStream<string, SSEOutput>} SSE 解析转换器
|
|
693
693
|
*/
|
|
694
694
|
function splitPart() {
|
|
695
695
|
return new TransformStream({
|
|
696
|
-
/**
|
|
697
|
-
* 转换函数
|
|
698
|
-
* @param {string} partChunk - 数据块
|
|
699
|
-
* @param {TransformStreamDefaultController<SSEOutput>} controller - 控制器
|
|
696
|
+
/**
|
|
697
|
+
* 转换函数
|
|
698
|
+
* @param {string} partChunk - 数据块
|
|
699
|
+
* @param {TransformStreamDefaultController<SSEOutput>} controller - 控制器
|
|
700
700
|
*/
|
|
701
701
|
transform(partChunk, controller) {
|
|
702
702
|
const lines = partChunk.split(DEFAULT_PART_SEPARATOR);
|
|
@@ -716,14 +716,14 @@ function splitPart() {
|
|
|
716
716
|
});
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
/**
|
|
720
|
-
* 核心流处理函数(支持中断)
|
|
721
|
-
* @param {XStreamOptions} options - 配置选项
|
|
722
|
-
* @param {ReadableStream<Uint8Array>} options.readableStream - 可读流
|
|
723
|
-
* @param {TransformStream<string, *>} [options.transformStream] - 可选的转换流
|
|
724
|
-
* @param {AbortSignal} [signal] - 中断信号
|
|
725
|
-
* @returns {ReadableStream<*>} 处理后的流,支持异步迭代
|
|
726
|
-
* @throws {TypeError} 当 readableStream 不是 ReadableStream 实例时抛出
|
|
719
|
+
/**
|
|
720
|
+
* 核心流处理函数(支持中断)
|
|
721
|
+
* @param {XStreamOptions} options - 配置选项
|
|
722
|
+
* @param {ReadableStream<Uint8Array>} options.readableStream - 可读流
|
|
723
|
+
* @param {TransformStream<string, *>} [options.transformStream] - 可选的转换流
|
|
724
|
+
* @param {AbortSignal} [signal] - 中断信号
|
|
725
|
+
* @returns {ReadableStream<*>} 处理后的流,支持异步迭代
|
|
726
|
+
* @throws {TypeError} 当 readableStream 不是 ReadableStream 实例时抛出
|
|
727
727
|
*/
|
|
728
728
|
function XStream(options, signal) {
|
|
729
729
|
const {
|
|
@@ -760,21 +760,21 @@ function XStream(options, signal) {
|
|
|
760
760
|
return processedStream;
|
|
761
761
|
}
|
|
762
762
|
|
|
763
|
-
/**
|
|
764
|
-
* streamMixin
|
|
765
|
-
* 用于处理流式数据的 mixin,支持 SSE 数据解析和中断功能
|
|
766
|
-
* @namespace streamMixin
|
|
767
|
-
* @type {Object}
|
|
763
|
+
/**
|
|
764
|
+
* streamMixin
|
|
765
|
+
* 用于处理流式数据的 mixin,支持 SSE 数据解析和中断功能
|
|
766
|
+
* @namespace streamMixin
|
|
767
|
+
* @type {Object}
|
|
768
768
|
*/
|
|
769
769
|
const streamMixin = {
|
|
770
|
-
/**
|
|
771
|
-
* 组件数据
|
|
772
|
-
* @returns {Object} 响应式数据对象
|
|
773
|
-
* @property {Array<*>} streamData - 流数据数组
|
|
774
|
-
* @property {Error|null} streamError - 流错误信息
|
|
775
|
-
* @property {boolean} streamLoading - 流处理状态
|
|
776
|
-
* @property {AbortController|null} _abortController - 私有:中断控制器
|
|
777
|
-
* @property {ReadableStream|null} _currentStream - 私有:当前流引用
|
|
770
|
+
/**
|
|
771
|
+
* 组件数据
|
|
772
|
+
* @returns {Object} 响应式数据对象
|
|
773
|
+
* @property {Array<*>} streamData - 流数据数组
|
|
774
|
+
* @property {Error|null} streamError - 流错误信息
|
|
775
|
+
* @property {boolean} streamLoading - 流处理状态
|
|
776
|
+
* @property {AbortController|null} _abortController - 私有:中断控制器
|
|
777
|
+
* @property {ReadableStream|null} _currentStream - 私有:当前流引用
|
|
778
778
|
*/
|
|
779
779
|
data() {
|
|
780
780
|
return {
|
|
@@ -786,28 +786,28 @@ const streamMixin = {
|
|
|
786
786
|
};
|
|
787
787
|
},
|
|
788
788
|
methods: {
|
|
789
|
-
/**
|
|
790
|
-
* 启动流式请求
|
|
791
|
-
* @async
|
|
792
|
-
* @param {XStreamOptions} options - 流配置选项
|
|
793
|
-
* @param {ReadableStream<Uint8Array>} options.readableStream - 可读流
|
|
794
|
-
* @param {TransformStream<string, *>} [options.transformStream] - 可选的转换流
|
|
795
|
-
* @returns {Promise<void>} 流处理完成的 Promise
|
|
796
|
-
* @fires streamMixin#stream-data - 收到新数据时触发
|
|
797
|
-
* @fires streamMixin#stream-complete - 流完成时触发
|
|
798
|
-
* @fires streamMixin#stream-error - 流错误时触发
|
|
799
|
-
* @fires streamMixin#stream-finish - 流处理结束时触发
|
|
800
|
-
* @example
|
|
801
|
-
* // 基础使用
|
|
802
|
-
* const response = await fetch('/api/stream')
|
|
803
|
-
* await this.startStream({ readableStream: response.body })
|
|
804
|
-
*
|
|
805
|
-
* // 使用自定义转换流
|
|
806
|
-
* const customTransform = new TransformStream({ ... })
|
|
807
|
-
* await this.startStream({
|
|
808
|
-
* readableStream: response.body,
|
|
809
|
-
* transformStream: customTransform
|
|
810
|
-
* })
|
|
789
|
+
/**
|
|
790
|
+
* 启动流式请求
|
|
791
|
+
* @async
|
|
792
|
+
* @param {XStreamOptions} options - 流配置选项
|
|
793
|
+
* @param {ReadableStream<Uint8Array>} options.readableStream - 可读流
|
|
794
|
+
* @param {TransformStream<string, *>} [options.transformStream] - 可选的转换流
|
|
795
|
+
* @returns {Promise<void>} 流处理完成的 Promise
|
|
796
|
+
* @fires streamMixin#stream-data - 收到新数据时触发
|
|
797
|
+
* @fires streamMixin#stream-complete - 流完成时触发
|
|
798
|
+
* @fires streamMixin#stream-error - 流错误时触发
|
|
799
|
+
* @fires streamMixin#stream-finish - 流处理结束时触发
|
|
800
|
+
* @example
|
|
801
|
+
* // 基础使用
|
|
802
|
+
* const response = await fetch('/api/stream')
|
|
803
|
+
* await this.startStream({ readableStream: response.body })
|
|
804
|
+
*
|
|
805
|
+
* // 使用自定义转换流
|
|
806
|
+
* const customTransform = new TransformStream({ ... })
|
|
807
|
+
* await this.startStream({
|
|
808
|
+
* readableStream: response.body,
|
|
809
|
+
* transformStream: customTransform
|
|
810
|
+
* })
|
|
811
811
|
*/
|
|
812
812
|
async startStream(options) {
|
|
813
813
|
this.streamLoading = true;
|
|
@@ -819,27 +819,27 @@ const streamMixin = {
|
|
|
819
819
|
for await (const item of this._currentStream) {
|
|
820
820
|
this.streamData.push(item);
|
|
821
821
|
// 触发数据更新事件
|
|
822
|
-
/**
|
|
823
|
-
* 流数据事件
|
|
824
|
-
* @event streamMixin#stream-data
|
|
825
|
-
* @type {*} 流数据项
|
|
822
|
+
/**
|
|
823
|
+
* 流数据事件
|
|
824
|
+
* @event streamMixin#stream-data
|
|
825
|
+
* @type {*} 流数据项
|
|
826
826
|
*/
|
|
827
827
|
this.$emit('stream-data', item);
|
|
828
828
|
}
|
|
829
829
|
// 流完成事件
|
|
830
|
-
/**
|
|
831
|
-
* 流完成事件
|
|
832
|
-
* @event streamMixin#stream-complete
|
|
833
|
-
* @type {Array<*>} 所有流数据
|
|
830
|
+
/**
|
|
831
|
+
* 流完成事件
|
|
832
|
+
* @event streamMixin#stream-complete
|
|
833
|
+
* @type {Array<*>} 所有流数据
|
|
834
834
|
*/
|
|
835
835
|
this.$emit('stream-complete', this.streamData);
|
|
836
836
|
} catch (err) {
|
|
837
837
|
if (err instanceof Error) {
|
|
838
838
|
this.streamError = err;
|
|
839
|
-
/**
|
|
840
|
-
* 流错误事件
|
|
841
|
-
* @event streamMixin#stream-error
|
|
842
|
-
* @type {Error} 错误对象
|
|
839
|
+
/**
|
|
840
|
+
* 流错误事件
|
|
841
|
+
* @event streamMixin#stream-error
|
|
842
|
+
* @type {Error} 错误对象
|
|
843
843
|
*/
|
|
844
844
|
this.$emit('stream-error', err);
|
|
845
845
|
}
|
|
@@ -847,36 +847,36 @@ const streamMixin = {
|
|
|
847
847
|
this.streamLoading = false;
|
|
848
848
|
this._currentStream = null; // 释放流引用
|
|
849
849
|
this._abortController = null; // 释放控制器
|
|
850
|
-
/**
|
|
851
|
-
* 流处理结束事件
|
|
852
|
-
* @event streamMixin#stream-finish
|
|
850
|
+
/**
|
|
851
|
+
* 流处理结束事件
|
|
852
|
+
* @event streamMixin#stream-finish
|
|
853
853
|
*/
|
|
854
854
|
this.$emit('stream-finish');
|
|
855
855
|
}
|
|
856
856
|
},
|
|
857
|
-
/**
|
|
858
|
-
* 中断流式请求(强制关闭流)
|
|
859
|
-
* @returns {void}
|
|
860
|
-
* @fires streamMixin#stream-cancel - 流被中断时触发
|
|
861
|
-
* @example
|
|
862
|
-
* this.cancelStream()
|
|
857
|
+
/**
|
|
858
|
+
* 中断流式请求(强制关闭流)
|
|
859
|
+
* @returns {void}
|
|
860
|
+
* @fires streamMixin#stream-cancel - 流被中断时触发
|
|
861
|
+
* @example
|
|
862
|
+
* this.cancelStream()
|
|
863
863
|
*/
|
|
864
864
|
cancelStream() {
|
|
865
865
|
if (this._abortController) {
|
|
866
866
|
this._abortController.abort();
|
|
867
|
-
/**
|
|
868
|
-
* 流取消事件
|
|
869
|
-
* @event streamMixin#stream-cancel
|
|
867
|
+
/**
|
|
868
|
+
* 流取消事件
|
|
869
|
+
* @event streamMixin#stream-cancel
|
|
870
870
|
*/
|
|
871
871
|
this.$emit('stream-cancel');
|
|
872
872
|
}
|
|
873
873
|
},
|
|
874
|
-
/**
|
|
875
|
-
* 重置流状态
|
|
876
|
-
* 清空所有数据和状态,但不触发事件
|
|
877
|
-
* @returns {void}
|
|
878
|
-
* @example
|
|
879
|
-
* this.resetStream()
|
|
874
|
+
/**
|
|
875
|
+
* 重置流状态
|
|
876
|
+
* 清空所有数据和状态,但不触发事件
|
|
877
|
+
* @returns {void}
|
|
878
|
+
* @example
|
|
879
|
+
* this.resetStream()
|
|
880
880
|
*/
|
|
881
881
|
resetStream() {
|
|
882
882
|
this.streamData = [];
|
|
@@ -885,14 +885,14 @@ const streamMixin = {
|
|
|
885
885
|
this._abortController = null;
|
|
886
886
|
this._currentStream = null;
|
|
887
887
|
},
|
|
888
|
-
/**
|
|
889
|
-
* 创建流处理器的便捷方法
|
|
890
|
-
* @param {ReadableStream<Uint8Array>} readableStream - 可读流
|
|
891
|
-
* @param {TransformStream<string, *>} [transformStream] - 可选的转换流
|
|
892
|
-
* @returns {XStreamOptions} 流处理器配置对象
|
|
893
|
-
* @example
|
|
894
|
-
* const processor = this.createStreamProcessor(response.body)
|
|
895
|
-
* await this.startStream(processor)
|
|
888
|
+
/**
|
|
889
|
+
* 创建流处理器的便捷方法
|
|
890
|
+
* @param {ReadableStream<Uint8Array>} readableStream - 可读流
|
|
891
|
+
* @param {TransformStream<string, *>} [transformStream] - 可选的转换流
|
|
892
|
+
* @returns {XStreamOptions} 流处理器配置对象
|
|
893
|
+
* @example
|
|
894
|
+
* const processor = this.createStreamProcessor(response.body)
|
|
895
|
+
* await this.startStream(processor)
|
|
896
896
|
*/
|
|
897
897
|
createStreamProcessor(readableStream, transformStream) {
|
|
898
898
|
return {
|
|
@@ -901,10 +901,10 @@ const streamMixin = {
|
|
|
901
901
|
};
|
|
902
902
|
}
|
|
903
903
|
},
|
|
904
|
-
/**
|
|
905
|
-
* 组件销毁前的生命周期钩子
|
|
906
|
-
* 自动清理流资源
|
|
907
|
-
* @returns {void}
|
|
904
|
+
/**
|
|
905
|
+
* 组件销毁前的生命周期钩子
|
|
906
|
+
* 自动清理流资源
|
|
907
|
+
* @returns {void}
|
|
908
908
|
*/
|
|
909
909
|
beforeDestroy() {
|
|
910
910
|
// 组件销毁时清理资源
|
|
@@ -912,30 +912,30 @@ const streamMixin = {
|
|
|
912
912
|
}
|
|
913
913
|
};
|
|
914
914
|
|
|
915
|
-
/**
|
|
916
|
-
* 工具函数版本 - 用于非组件场景
|
|
917
|
-
* @param {StreamCallbacks} [callbacks={}] - 回调函数配置
|
|
918
|
-
* @param {function(*): void} [callbacks.onData] - 数据回调函数
|
|
919
|
-
* @param {function(Array<*>): void} [callbacks.onComplete] - 完成回调函数
|
|
920
|
-
* @param {function(Error): void} [callbacks.onError] - 错误回调函数
|
|
921
|
-
* @param {function(): void} [callbacks.onCancel] - 取消回调函数
|
|
922
|
-
* @param {function(): void} [callbacks.onFinish] - 结束回调函数
|
|
923
|
-
* @returns {StreamUtils} 包含流处理相关方法的对象
|
|
924
|
-
* @example
|
|
925
|
-
* // 基础使用
|
|
926
|
-
* const streamUtils = createStreamUtils({
|
|
927
|
-
* onData: (item) => console.log('数据:', item),
|
|
928
|
-
* onComplete: (allData) => console.log('完成:', allData),
|
|
929
|
-
* onError: (error) => console.error('错误:', error)
|
|
930
|
-
* })
|
|
931
|
-
*
|
|
932
|
-
* const response = await fetch('/api/stream')
|
|
933
|
-
* await streamUtils.startStream({ readableStream: response.body })
|
|
915
|
+
/**
|
|
916
|
+
* 工具函数版本 - 用于非组件场景
|
|
917
|
+
* @param {StreamCallbacks} [callbacks={}] - 回调函数配置
|
|
918
|
+
* @param {function(*): void} [callbacks.onData] - 数据回调函数
|
|
919
|
+
* @param {function(Array<*>): void} [callbacks.onComplete] - 完成回调函数
|
|
920
|
+
* @param {function(Error): void} [callbacks.onError] - 错误回调函数
|
|
921
|
+
* @param {function(): void} [callbacks.onCancel] - 取消回调函数
|
|
922
|
+
* @param {function(): void} [callbacks.onFinish] - 结束回调函数
|
|
923
|
+
* @returns {StreamUtils} 包含流处理相关方法的对象
|
|
924
|
+
* @example
|
|
925
|
+
* // 基础使用
|
|
926
|
+
* const streamUtils = createStreamUtils({
|
|
927
|
+
* onData: (item) => console.log('数据:', item),
|
|
928
|
+
* onComplete: (allData) => console.log('完成:', allData),
|
|
929
|
+
* onError: (error) => console.error('错误:', error)
|
|
930
|
+
* })
|
|
931
|
+
*
|
|
932
|
+
* const response = await fetch('/api/stream')
|
|
933
|
+
* await streamUtils.startStream({ readableStream: response.body })
|
|
934
934
|
*/
|
|
935
935
|
function createStreamUtils(callbacks = {}) {
|
|
936
|
-
/**
|
|
937
|
-
* 流状态对象
|
|
938
|
-
* @type {StreamState}
|
|
936
|
+
/**
|
|
937
|
+
* 流状态对象
|
|
938
|
+
* @type {StreamState}
|
|
939
939
|
*/
|
|
940
940
|
const state = {
|
|
941
941
|
data: [],
|
|
@@ -945,11 +945,11 @@ function createStreamUtils(callbacks = {}) {
|
|
|
945
945
|
let abortController = null;
|
|
946
946
|
let currentStream = null;
|
|
947
947
|
|
|
948
|
-
/**
|
|
949
|
-
* 启动流处理
|
|
950
|
-
* @async
|
|
951
|
-
* @param {XStreamOptions} options - 流配置选项
|
|
952
|
-
* @returns {Promise<void>} 流处理完成的 Promise
|
|
948
|
+
/**
|
|
949
|
+
* 启动流处理
|
|
950
|
+
* @async
|
|
951
|
+
* @param {XStreamOptions} options - 流配置选项
|
|
952
|
+
* @returns {Promise<void>} 流处理完成的 Promise
|
|
953
953
|
*/
|
|
954
954
|
const startStream = async options => {
|
|
955
955
|
state.loading = true;
|
|
@@ -984,9 +984,9 @@ function createStreamUtils(callbacks = {}) {
|
|
|
984
984
|
}
|
|
985
985
|
};
|
|
986
986
|
|
|
987
|
-
/**
|
|
988
|
-
* 取消流处理
|
|
989
|
-
* @returns {void}
|
|
987
|
+
/**
|
|
988
|
+
* 取消流处理
|
|
989
|
+
* @returns {void}
|
|
990
990
|
*/
|
|
991
991
|
const cancel = () => {
|
|
992
992
|
if (abortController) {
|
|
@@ -997,9 +997,9 @@ function createStreamUtils(callbacks = {}) {
|
|
|
997
997
|
}
|
|
998
998
|
};
|
|
999
999
|
|
|
1000
|
-
/**
|
|
1001
|
-
* 重置流状态
|
|
1002
|
-
* @returns {void}
|
|
1000
|
+
/**
|
|
1001
|
+
* 重置流状态
|
|
1002
|
+
* @returns {void}
|
|
1003
1003
|
*/
|
|
1004
1004
|
const reset = () => {
|
|
1005
1005
|
state.data = [];
|
|
@@ -1019,14 +1019,14 @@ function createStreamUtils(callbacks = {}) {
|
|
|
1019
1019
|
// 导出常量和工具函数
|
|
1020
1020
|
|
|
1021
1021
|
|
|
1022
|
-
/**
|
|
1023
|
-
* 默认导出 streamMixin
|
|
1024
|
-
* @type {Object}
|
|
1022
|
+
/**
|
|
1023
|
+
* 默认导出 streamMixin
|
|
1024
|
+
* @type {Object}
|
|
1025
1025
|
*/
|
|
1026
1026
|
/* harmony default export */ const mixins_streamMixin = ((/* unused pure expression or super */ null && (streamMixin)));
|
|
1027
1027
|
;// ./src/mixins/index.js
|
|
1028
|
-
/**
|
|
1029
|
-
* Mixins 入口文件
|
|
1028
|
+
/**
|
|
1029
|
+
* Mixins 入口文件
|
|
1030
1030
|
*/
|
|
1031
1031
|
|
|
1032
1032
|
|