refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,97 @@
|
||||
{
|
||||
"id": "uts-worker",
|
||||
"displayName": "uts-worker",
|
||||
"version": "1.0.0",
|
||||
"description": "uts-worker",
|
||||
"keywords": [
|
||||
"uts-worker"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.6.8",
|
||||
"uni-app": "^3.1.0",
|
||||
"uni-app-x": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "uts",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "",
|
||||
"data": "",
|
||||
"permissions": ""
|
||||
},
|
||||
"npmurl": "",
|
||||
"darkmode": "-",
|
||||
"i18n": "-",
|
||||
"widescreen": "-"
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "-",
|
||||
"aliyun": "-",
|
||||
"alipay": "-"
|
||||
},
|
||||
"client": {
|
||||
"uni-app": {
|
||||
"vue": {
|
||||
"vue2": "-",
|
||||
"vue3": "-"
|
||||
},
|
||||
"web": {
|
||||
"safari": "-",
|
||||
"chrome": "-"
|
||||
},
|
||||
"app": {
|
||||
"vue": "-",
|
||||
"nvue": "-",
|
||||
"android": "-",
|
||||
"ios": "-",
|
||||
"harmony": "-"
|
||||
},
|
||||
"mp": {
|
||||
"weixin": "-",
|
||||
"alipay": "-",
|
||||
"toutiao": "-",
|
||||
"baidu": "-",
|
||||
"kuaishou": "-",
|
||||
"jd": "-",
|
||||
"harmony": "-",
|
||||
"qq": "-",
|
||||
"lark": "-"
|
||||
},
|
||||
"quickapp": {
|
||||
"huawei": "-",
|
||||
"union": "-"
|
||||
}
|
||||
},
|
||||
"uni-app-x": {
|
||||
"web": {
|
||||
"safari": "-",
|
||||
"chrome": "-"
|
||||
},
|
||||
"app": {
|
||||
"android": "-",
|
||||
"ios": "-",
|
||||
"harmony": "-"
|
||||
},
|
||||
"mp": {
|
||||
"weixin": "-"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# t-worker
|
||||
### 开发文档
|
||||
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
|
||||
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
|
||||
[UTS uni-app兼容模式组件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
|
||||
[UTS 标准模式组件](https://doc.dcloud.net.cn/uni-app-x/plugin/uts-vue-component.html)
|
||||
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
|
||||
@@ -0,0 +1,115 @@
|
||||
import { CreateWorkers, DestroyWorker, OnWorkerError,
|
||||
OnWorkerMessage, SendWorkerMessage,
|
||||
UTSWorkerAddListenerOptions , UTSWorkerAddListenerOptionsSuccess, UTSWorkerSendWorkerMessageOptions, UTSWorkerErrorOptions, UTSWorkerErrorCallbackSuccess } from './interface.uts';
|
||||
|
||||
export * from './interface.uts';
|
||||
|
||||
export const createWorkers : CreateWorkers = function () : void {
|
||||
UTSWorkerImpl.shared.create();
|
||||
}
|
||||
export const sendWorkerMessage : SendWorkerMessage = function (options : UTSWorkerSendWorkerMessageOptions) : void {
|
||||
UTSWorkerImpl.shared.sendMessage(options);
|
||||
}
|
||||
|
||||
export const onWorkerMessage : OnWorkerMessage = function (options : UTSWorkerAddListenerOptions) : void {
|
||||
UTSWorkerImpl.shared.onMessage(options);
|
||||
}
|
||||
|
||||
export const destroyWorker : DestroyWorker = function () : void {
|
||||
UTSWorkerImpl.shared.destroy();
|
||||
}
|
||||
|
||||
export const onWorkerError : OnWorkerError = function (options: UTSWorkerErrorOptions) : void {
|
||||
UTSWorkerImpl.shared.onError(options);
|
||||
}
|
||||
|
||||
export class UTSWorkerImpl{
|
||||
static shared : UTSWorkerImpl = new UTSWorkerImpl()
|
||||
private workerImp : Worker | null = null;
|
||||
private options : UTSWorkerAddListenerOptions | null = null;
|
||||
private errorOptions : UTSWorkerErrorOptions | null = null;
|
||||
|
||||
create(){
|
||||
if (this.workerImp != null) {
|
||||
console.warn('[UTS Plugin] Worker已存在,先销毁旧的Worker');
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
console.log('[UTS Plugin] 创建Worker');
|
||||
const worker = uni.createWorker('workers/helloWorkerTask.uts');
|
||||
this.workerImp = worker;
|
||||
}
|
||||
|
||||
|
||||
sendMessage(options : UTSWorkerSendWorkerMessageOptions){
|
||||
if (this.workerImp == null) {
|
||||
console.error('Worker未创建,无法发送消息');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取消息信息并添加日志
|
||||
const msgData = options.data;
|
||||
const needReply = options.needReply;
|
||||
|
||||
console.log(`[UTS Plugin] 向Worker发送消息: ${msgData} (需要回复: ${needReply})`);
|
||||
|
||||
// 构造要发送给Worker的消息对象
|
||||
const messageToWorker = {
|
||||
data: msgData,
|
||||
needReply: needReply
|
||||
};
|
||||
|
||||
this.workerImp!.postMessage(messageToWorker,null);
|
||||
}
|
||||
|
||||
onMessage(options : UTSWorkerAddListenerOptions){
|
||||
if (this.workerImp == null) {
|
||||
console.error('Worker未创建,无法监听消息');
|
||||
return;
|
||||
}
|
||||
|
||||
this.options = options;
|
||||
this.workerImp!.onMessage((result) => {
|
||||
// 处理Worker返回的消息
|
||||
console.log(`[UTS Plugin] 收到Worker消息:`, result);
|
||||
|
||||
if (this.options != null && this.options.success != null){
|
||||
let success : UTSWorkerAddListenerOptionsSuccess = {
|
||||
result: result as UTSJSONObject
|
||||
}
|
||||
this.options.success(success);
|
||||
}
|
||||
})
|
||||
}
|
||||
onError(options: UTSWorkerErrorOptions){
|
||||
if (this.workerImp == null) {
|
||||
console.error('Worker未创建,无法监听错误');
|
||||
return;
|
||||
}
|
||||
|
||||
this.errorOptions = options;
|
||||
this.workerImp!.onError((error) => {
|
||||
console.error('[UTS Plugin] Worker发生错误:', error);
|
||||
|
||||
if (this.errorOptions != null && this.errorOptions.success != null) {
|
||||
// const errorInfo: UTSWorkerErrorCallbackSuccess = {
|
||||
// message: error.message
|
||||
// };
|
||||
const errorInfo: UTSWorkerErrorCallbackSuccess = {
|
||||
message: "worker error"
|
||||
};
|
||||
this.errorOptions.success(errorInfo);
|
||||
}
|
||||
})
|
||||
}
|
||||
destroy(){
|
||||
|
||||
if (this.workerImp != null) {
|
||||
console.log('[UTS Plugin] 销毁Worker');
|
||||
this.workerImp.terminate();
|
||||
this.workerImp = null;
|
||||
this.options = null;
|
||||
this.errorOptions = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
export type UTSWorkerAddListenerOptions = {
|
||||
success ?: UTSWorkerReceiveEventCallback
|
||||
}
|
||||
|
||||
export type UTSWorkerAddListenerOptionsSuccess = {
|
||||
result : UTSJSONObject
|
||||
}
|
||||
|
||||
export type UTSWorkerSendWorkerMessageOptions = {
|
||||
data : string,
|
||||
needReply : boolean
|
||||
}
|
||||
|
||||
export type UTSWorkerErrorCallbackSuccess = {
|
||||
message : string
|
||||
}
|
||||
|
||||
export type UTSWorkerErrorOptions = {
|
||||
success ?: UTSWorkerErrorCallback
|
||||
}
|
||||
|
||||
export type UTSWorkerErrorCallback = (error: UTSWorkerErrorCallbackSuccess) => void
|
||||
|
||||
export type UTSWorkerReceiveEventCallback = (callback: UTSWorkerAddListenerOptionsSuccess) => void
|
||||
|
||||
|
||||
export type SendWorkerMessage = (options: UTSWorkerSendWorkerMessageOptions) => void
|
||||
|
||||
export type OnWorkerMessage = (options: UTSWorkerAddListenerOptions) => void
|
||||
|
||||
|
||||
export type OnWorkerError = (options: UTSWorkerErrorOptions) => void
|
||||
|
||||
export type CreateWorkers = () => void
|
||||
|
||||
export type DestroyWorker = () => void
|
||||
在新工单中引用
屏蔽一个用户