@mybricks/to-code-taro 1.0.3 → 1.0.5
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/cjs/core/comlib/_AesEncode.js +115 -0
- package/dist/cjs/core/comlib/_BackTo.js +80 -0
- package/dist/cjs/core/comlib/_CallPhone.js +58 -0
- package/dist/cjs/core/comlib/_ChooseFile.js +103 -0
- package/dist/cjs/core/comlib/_ChooseMedia.js +70 -0
- package/dist/cjs/core/comlib/_Connector.js +92 -0
- package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +79 -0
- package/dist/cjs/core/comlib/_Format.js +123 -0
- package/dist/cjs/core/comlib/_GetLocation.js +60 -0
- package/dist/cjs/core/comlib/_GetStorage.js +68 -0
- package/dist/cjs/core/comlib/_GetSystemInfo.js +62 -0
- package/dist/cjs/core/comlib/_OpenCamera.js +73 -0
- package/dist/cjs/core/comlib/_OpenPetalMap.js +49 -0
- package/dist/cjs/core/comlib/_OpenUrl.js +62 -0
- package/dist/cjs/core/comlib/_RemoveStorage.js +68 -0
- package/dist/cjs/core/comlib/_Router.js +100 -0
- package/dist/cjs/core/comlib/_ScanQrcode.js +9 -10
- package/dist/cjs/core/comlib/_SetStorage.js +10 -19
- package/dist/cjs/core/comlib/_Share.js +58 -0
- package/dist/cjs/core/comlib/_ShowToast.js +23 -50
- package/dist/cjs/core/comlib/_TextToSpeech.js +120 -0
- package/dist/cjs/core/comlib/_TimerDebounce.js +72 -0
- package/dist/cjs/core/comlib/_TimerDelay.js +63 -0
- package/dist/cjs/core/comlib/_TimerThrottle.js +75 -0
- package/dist/cjs/core/comlib/_Vibrate.js +60 -0
- package/dist/cjs/core/comlib/index.js +68 -2
- package/dist/cjs/core/utils/ComContext.js +3 -3
- package/dist/cjs/core/utils/PopupRenderer.js +63 -0
- package/dist/cjs/core/utils/hooks.js +16 -14
- package/dist/cjs/core/utils/index.js +15 -3
- package/dist/cjs/core/utils/{page.js → pageRouter.js} +28 -14
- package/dist/cjs/core/utils/popupRouter.js +98 -0
- package/dist/cjs/core/utils/useContext.js +9 -1
- package/dist/cjs/core/utils/with.js +37 -13
- package/dist/cjs/generate/generateTaroProjectJson.js +30 -0
- package/dist/cjs/handleSlot.d.ts +2 -0
- package/dist/cjs/handleSlot.js +19 -5
- package/dist/cjs/processors/processComEvents.js +47 -5
- package/dist/cjs/processors/processScene.js +9 -5
- package/dist/cjs/processors/processSceneLogic.js +9 -5
- package/dist/cjs/shims-taro.d.ts +20 -0
- package/dist/cjs/taro-template.json +493 -351
- package/dist/cjs/toCodeTaro.d.ts +1 -1
- package/dist/cjs/toCodeTaro.js +13 -1
- package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
- package/dist/cjs/utils/builder/buildResult.js +26 -0
- package/dist/cjs/utils/config/handlePageConfig.d.ts +2 -1
- package/dist/cjs/utils/config/handlePageConfig.js +3 -2
- package/dist/cjs/utils/context/createEventQueries.js +1 -1
- package/dist/cjs/utils/logic/handleProcess.js +26 -5
- package/dist/cjs/utils/templates/scene.d.ts +3 -1
- package/dist/cjs/utils/templates/scene.js +16 -4
- package/dist/esm/core/comlib/_AesEncode.js +85 -0
- package/dist/esm/core/comlib/_BackTo.js +66 -0
- package/dist/esm/core/comlib/_CallPhone.js +30 -0
- package/dist/esm/core/comlib/_ChooseFile.js +81 -0
- package/dist/esm/core/comlib/_ChooseMedia.js +38 -0
- package/dist/esm/core/comlib/_Connector.js +60 -0
- package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +56 -0
- package/dist/esm/core/comlib/_Format.js +102 -0
- package/dist/esm/core/comlib/_GetLocation.js +26 -0
- package/dist/esm/core/comlib/_GetStorage.js +44 -0
- package/dist/esm/core/comlib/_GetSystemInfo.js +32 -0
- package/dist/esm/core/comlib/_OpenCamera.js +44 -0
- package/dist/esm/core/comlib/_OpenPetalMap.js +28 -0
- package/dist/esm/core/comlib/_OpenUrl.js +36 -0
- package/dist/esm/core/comlib/_RemoveStorage.js +42 -0
- package/dist/esm/core/comlib/_Router.js +113 -0
- package/dist/esm/core/comlib/_ScanQrcode.js +10 -11
- package/dist/esm/core/comlib/_SetStorage.js +13 -25
- package/dist/esm/core/comlib/_Share.js +28 -0
- package/dist/esm/core/comlib/_ShowToast.js +32 -55
- package/dist/esm/core/comlib/_TextToSpeech.js +117 -0
- package/dist/esm/core/comlib/_TimerDebounce.js +66 -0
- package/dist/esm/core/comlib/_TimerDelay.js +47 -0
- package/dist/esm/core/comlib/_TimerThrottle.js +69 -0
- package/dist/esm/core/comlib/_Vibrate.js +34 -0
- package/dist/esm/core/comlib/index.js +35 -1
- package/dist/esm/core/utils/ComContext.js +1 -1
- package/dist/esm/core/utils/PopupRenderer.js +27 -0
- package/dist/esm/core/utils/hooks.js +24 -16
- package/dist/esm/core/utils/index.js +3 -1
- package/dist/esm/core/utils/pageRouter.js +69 -0
- package/dist/esm/core/utils/popupRouter.js +116 -0
- package/dist/esm/core/utils/useContext.js +14 -2
- package/dist/esm/core/utils/with.js +62 -19
- package/dist/esm/generate/generateTaroProjectJson.js +35 -1
- package/dist/esm/handleSlot.d.ts +2 -0
- package/dist/esm/handleSlot.js +20 -4
- package/dist/esm/processors/processComEvents.js +62 -5
- package/dist/esm/processors/processScene.js +11 -3
- package/dist/esm/processors/processSceneLogic.js +15 -5
- package/dist/esm/shims-taro.d.ts +20 -0
- package/dist/esm/taro-template.json +493 -351
- package/dist/esm/toCodeTaro.d.ts +1 -1
- package/dist/esm/toCodeTaro.js +16 -1
- package/dist/esm/utils/builder/buildResult.d.ts +1 -0
- package/dist/esm/utils/builder/buildResult.js +21 -0
- package/dist/esm/utils/config/handlePageConfig.d.ts +2 -1
- package/dist/esm/utils/config/handlePageConfig.js +5 -1
- package/dist/esm/utils/context/createEventQueries.js +2 -1
- package/dist/esm/utils/logic/handleProcess.js +31 -4
- package/dist/esm/utils/templates/scene.d.ts +3 -1
- package/dist/esm/utils/templates/scene.js +13 -5
- package/package.json +4 -2
- package/dist/esm/core/utils/page.js +0 -50
|
@@ -6,63 +6,40 @@ export default (function (context) {
|
|
|
6
6
|
var inputs = context.inputs;
|
|
7
7
|
var outputs = context.outputs;
|
|
8
8
|
(_inputs$showToast = inputs.showToast) === null || _inputs$showToast === void 0 || _inputs$showToast.call(inputs, function (val) {
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
if (val && _typeof(val) === 'object' && val.image) {
|
|
24
|
-
toastConfig.image = val.image;
|
|
25
|
-
} else if (data.image) {
|
|
26
|
-
toastConfig.image = data.image;
|
|
27
|
-
}
|
|
28
|
-
Taro.showToast(toastConfig);
|
|
29
|
-
if (data.asynchronous) {
|
|
30
|
-
var _ref3, _val$duration2, _data$duration2;
|
|
31
|
-
setTimeout(function () {
|
|
32
|
-
outputs.afterShowToast(val);
|
|
33
|
-
}, Number(val && _typeof(val) === 'object' ? (_ref3 = (_val$duration2 = val === null || val === void 0 ? void 0 : val.duration) !== null && _val$duration2 !== void 0 ? _val$duration2 : data.duration) !== null && _ref3 !== void 0 ? _ref3 : 1000 : (_data$duration2 = data.duration) !== null && _data$duration2 !== void 0 ? _data$duration2 : 1000));
|
|
34
|
-
} else {
|
|
35
|
-
outputs.afterShowToast(val);
|
|
36
|
-
}
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error('显示 Toast 失败:', error);
|
|
9
|
+
try {
|
|
10
|
+
// 构建 Toast 配置
|
|
11
|
+
var toastConfig = {
|
|
12
|
+
title: typeof val === 'string' ? val : (val === null || val === void 0 ? void 0 : val.title) || data.title || '',
|
|
13
|
+
duration: Number(_typeof(val) === 'object' && val !== null && val !== void 0 && val.duration ? val.duration : data.duration || 1000),
|
|
14
|
+
mask: _typeof(val) === 'object' && (val === null || val === void 0 ? void 0 : val.mask) !== undefined ? val.mask : data.mask || false
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// 图标配置
|
|
18
|
+
if (_typeof(val) === 'object' && val !== null && val !== void 0 && val.icon) {
|
|
19
|
+
toastConfig.icon = val.icon;
|
|
20
|
+
} else if (data.icon) {
|
|
21
|
+
toastConfig.icon = data.icon;
|
|
39
22
|
}
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
duration: Number(data.duration || 1000),
|
|
47
|
-
mask: (_data$mask2 = data.mask) !== null && _data$mask2 !== void 0 ? _data$mask2 : false
|
|
48
|
-
};
|
|
49
|
-
if (data.icon) {
|
|
50
|
-
_toastConfig.icon = data.icon;
|
|
51
|
-
}
|
|
52
|
-
if (data.image) {
|
|
53
|
-
_toastConfig.image = data.image;
|
|
54
|
-
}
|
|
55
|
-
Taro.showToast(_toastConfig);
|
|
56
|
-
if (data.asynchronous) {
|
|
57
|
-
setTimeout(function () {
|
|
58
|
-
outputs.afterShowToast(val);
|
|
59
|
-
}, Number(data.duration || 1000));
|
|
60
|
-
} else {
|
|
61
|
-
outputs.afterShowToast(val);
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error('显示 Toast 失败:', error);
|
|
23
|
+
|
|
24
|
+
// 图片配置
|
|
25
|
+
if (_typeof(val) === 'object' && val !== null && val !== void 0 && val.image) {
|
|
26
|
+
toastConfig.image = val.image;
|
|
27
|
+
} else if (data.image) {
|
|
28
|
+
toastConfig.image = data.image;
|
|
65
29
|
}
|
|
30
|
+
Taro.showToast(toastConfig);
|
|
31
|
+
|
|
32
|
+
// 处理输出回调
|
|
33
|
+
var triggerOutput = function triggerOutput() {
|
|
34
|
+
return outputs.afterShowToast(val);
|
|
35
|
+
};
|
|
36
|
+
if (data.asynchronous) {
|
|
37
|
+
setTimeout(triggerOutput, toastConfig.duration);
|
|
38
|
+
} else {
|
|
39
|
+
triggerOutput();
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('显示 Toast 失败:', error);
|
|
66
43
|
}
|
|
67
44
|
});
|
|
68
45
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// 检查浏览器是否支持Web Speech API
|
|
2
|
+
var speechSupported = typeof window !== 'undefined' && 'speechSynthesis' in window;
|
|
3
|
+
var currentUtterance = null;
|
|
4
|
+
export default (function (context) {
|
|
5
|
+
var _inputs$speak, _inputs$stop, _inputs$pause, _inputs$resume;
|
|
6
|
+
var data = context.data;
|
|
7
|
+
var inputs = context.inputs;
|
|
8
|
+
var outputs = context.outputs;
|
|
9
|
+
if (!speechSupported) {
|
|
10
|
+
console.warn('当前环境不支持语音合成功能');
|
|
11
|
+
}
|
|
12
|
+
(_inputs$speak = inputs.speak) === null || _inputs$speak === void 0 || _inputs$speak.call(inputs, function (val) {
|
|
13
|
+
try {
|
|
14
|
+
var text = (val === null || val === void 0 ? void 0 : val.text) || data.text;
|
|
15
|
+
var lang = (val === null || val === void 0 ? void 0 : val.lang) || data.lang || 'zh-CN';
|
|
16
|
+
var rate = (val === null || val === void 0 ? void 0 : val.rate) || data.rate || 1;
|
|
17
|
+
var pitch = (val === null || val === void 0 ? void 0 : val.pitch) || data.pitch || 1;
|
|
18
|
+
var volume = (val === null || val === void 0 ? void 0 : val.volume) || data.volume || 1;
|
|
19
|
+
if (!text) {
|
|
20
|
+
outputs.onFail('待合成的文本不能为空');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!speechSupported) {
|
|
24
|
+
outputs.onFail('当前环境不支持语音合成功能');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 如果有正在播放的语音,先停止
|
|
29
|
+
if (currentUtterance && window.speechSynthesis.speaking) {
|
|
30
|
+
window.speechSynthesis.cancel();
|
|
31
|
+
}
|
|
32
|
+
currentUtterance = new SpeechSynthesisUtterance(text);
|
|
33
|
+
currentUtterance.lang = lang;
|
|
34
|
+
currentUtterance.rate = Math.max(0.1, Math.min(10, rate));
|
|
35
|
+
currentUtterance.pitch = Math.max(0, Math.min(2, pitch));
|
|
36
|
+
currentUtterance.volume = Math.max(0, Math.min(1, volume));
|
|
37
|
+
currentUtterance.onstart = function () {
|
|
38
|
+
outputs.onStart({
|
|
39
|
+
text: text,
|
|
40
|
+
lang: lang,
|
|
41
|
+
rate: rate,
|
|
42
|
+
pitch: pitch,
|
|
43
|
+
volume: volume
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
currentUtterance.onend = function () {
|
|
47
|
+
outputs.onEnd({
|
|
48
|
+
text: text,
|
|
49
|
+
lang: lang,
|
|
50
|
+
rate: rate,
|
|
51
|
+
pitch: pitch,
|
|
52
|
+
volume: volume
|
|
53
|
+
});
|
|
54
|
+
currentUtterance = null;
|
|
55
|
+
};
|
|
56
|
+
currentUtterance.onerror = function (event) {
|
|
57
|
+
outputs.onError({
|
|
58
|
+
error: event.error,
|
|
59
|
+
text: text,
|
|
60
|
+
message: '语音合成失败'
|
|
61
|
+
});
|
|
62
|
+
currentUtterance = null;
|
|
63
|
+
};
|
|
64
|
+
window.speechSynthesis.speak(currentUtterance);
|
|
65
|
+
outputs.onSuccess({
|
|
66
|
+
text: text,
|
|
67
|
+
lang: lang,
|
|
68
|
+
rate: rate,
|
|
69
|
+
pitch: pitch,
|
|
70
|
+
volume: volume
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error('语音合成失败:', error);
|
|
74
|
+
outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '语音合成失败');
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
(_inputs$stop = inputs.stop) === null || _inputs$stop === void 0 || _inputs$stop.call(inputs, function () {
|
|
78
|
+
try {
|
|
79
|
+
if (speechSupported && currentUtterance) {
|
|
80
|
+
window.speechSynthesis.cancel();
|
|
81
|
+
currentUtterance = null;
|
|
82
|
+
outputs.onSuccess('已停止语音播放');
|
|
83
|
+
} else {
|
|
84
|
+
outputs.onFail('没有正在播放的语音');
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('停止语音失败:', error);
|
|
88
|
+
outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '停止语音失败');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
(_inputs$pause = inputs.pause) === null || _inputs$pause === void 0 || _inputs$pause.call(inputs, function () {
|
|
92
|
+
try {
|
|
93
|
+
if (speechSupported && window.speechSynthesis.pause) {
|
|
94
|
+
window.speechSynthesis.pause();
|
|
95
|
+
outputs.onSuccess('已暂停语音播放');
|
|
96
|
+
} else {
|
|
97
|
+
outputs.onFail('当前环境不支持暂停功能');
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error('暂停语音失败:', error);
|
|
101
|
+
outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '暂停语音失败');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
(_inputs$resume = inputs.resume) === null || _inputs$resume === void 0 || _inputs$resume.call(inputs, function () {
|
|
105
|
+
try {
|
|
106
|
+
if (speechSupported && window.speechSynthesis.resume) {
|
|
107
|
+
window.speechSynthesis.resume();
|
|
108
|
+
outputs.onSuccess('已恢复语音播放');
|
|
109
|
+
} else {
|
|
110
|
+
outputs.onFail('当前环境不支持恢复功能');
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('恢复语音失败:', error);
|
|
114
|
+
outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '恢复语音失败');
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// 防抖函数实现
|
|
2
|
+
function debounce(func, delay) {
|
|
3
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4
|
+
var timeoutId = null;
|
|
5
|
+
var lastExecTime = 0;
|
|
6
|
+
var _options$leading = options.leading,
|
|
7
|
+
leading = _options$leading === void 0 ? false : _options$leading,
|
|
8
|
+
_options$trailing = options.trailing,
|
|
9
|
+
trailing = _options$trailing === void 0 ? true : _options$trailing;
|
|
10
|
+
return function () {
|
|
11
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
args[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
var currentTime = Date.now();
|
|
15
|
+
if (!timeoutId && leading) {
|
|
16
|
+
func.apply(null, args);
|
|
17
|
+
lastExecTime = currentTime;
|
|
18
|
+
}
|
|
19
|
+
if (timeoutId) {
|
|
20
|
+
clearTimeout(timeoutId);
|
|
21
|
+
}
|
|
22
|
+
timeoutId = setTimeout(function () {
|
|
23
|
+
if (trailing && (!leading || currentTime - lastExecTime >= delay)) {
|
|
24
|
+
func.apply(null, args);
|
|
25
|
+
}
|
|
26
|
+
timeoutId = null;
|
|
27
|
+
}, delay);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export default (function (context) {
|
|
31
|
+
var _inputs$debounce;
|
|
32
|
+
var data = context.data;
|
|
33
|
+
var inputs = context.inputs;
|
|
34
|
+
var outputs = context.outputs;
|
|
35
|
+
var debouncedFn = null;
|
|
36
|
+
(_inputs$debounce = inputs.debounce) === null || _inputs$debounce === void 0 || _inputs$debounce.call(inputs, function (val) {
|
|
37
|
+
try {
|
|
38
|
+
var delay = (val === null || val === void 0 ? void 0 : val.delay) || data.delay || 300;
|
|
39
|
+
var leading = (val === null || val === void 0 ? void 0 : val.leading) !== undefined ? val.leading : data.leading || false;
|
|
40
|
+
var trailing = (val === null || val === void 0 ? void 0 : val.trailing) !== undefined ? val.trailing : data.trailing || true;
|
|
41
|
+
if (!debouncedFn) {
|
|
42
|
+
debouncedFn = debounce(function () {
|
|
43
|
+
outputs.onExecute({
|
|
44
|
+
delay: delay,
|
|
45
|
+
leading: leading,
|
|
46
|
+
trailing: trailing,
|
|
47
|
+
timestamp: Date.now()
|
|
48
|
+
});
|
|
49
|
+
}, delay, {
|
|
50
|
+
leading: leading,
|
|
51
|
+
trailing: trailing
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 执行防抖函数
|
|
56
|
+
debouncedFn();
|
|
57
|
+
outputs.onComplete({
|
|
58
|
+
delay: delay,
|
|
59
|
+
leading: leading,
|
|
60
|
+
trailing: trailing
|
|
61
|
+
});
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error('防抖执行失败:', error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export default (function (context) {
|
|
2
|
+
var _inputs$delay, _inputs$cancel;
|
|
3
|
+
var data = context.data;
|
|
4
|
+
var inputs = context.inputs;
|
|
5
|
+
var outputs = context.outputs;
|
|
6
|
+
var timeoutId = null;
|
|
7
|
+
(_inputs$delay = inputs.delay) === null || _inputs$delay === void 0 || _inputs$delay.call(inputs, function (val) {
|
|
8
|
+
try {
|
|
9
|
+
var delay = (val === null || val === void 0 ? void 0 : val.delay) || data.delay || 1000;
|
|
10
|
+
|
|
11
|
+
// 清除之前的定时器
|
|
12
|
+
if (timeoutId) {
|
|
13
|
+
clearTimeout(timeoutId);
|
|
14
|
+
}
|
|
15
|
+
outputs.onStart({
|
|
16
|
+
delay: delay,
|
|
17
|
+
timestamp: Date.now()
|
|
18
|
+
});
|
|
19
|
+
timeoutId = setTimeout(function () {
|
|
20
|
+
outputs.onExecute({
|
|
21
|
+
delay: delay,
|
|
22
|
+
timestamp: Date.now()
|
|
23
|
+
});
|
|
24
|
+
timeoutId = null;
|
|
25
|
+
}, delay);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error('延迟执行失败:', error);
|
|
28
|
+
if (timeoutId) {
|
|
29
|
+
clearTimeout(timeoutId);
|
|
30
|
+
timeoutId = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
(_inputs$cancel = inputs.cancel) === null || _inputs$cancel === void 0 || _inputs$cancel.call(inputs, function () {
|
|
35
|
+
try {
|
|
36
|
+
if (timeoutId) {
|
|
37
|
+
clearTimeout(timeoutId);
|
|
38
|
+
timeoutId = null;
|
|
39
|
+
outputs.onCancel('延迟任务已取消');
|
|
40
|
+
} else {
|
|
41
|
+
outputs.onCancel('没有正在执行的延迟任务');
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('取消延迟失败:', error);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// 节流函数实现
|
|
2
|
+
function throttle(func, delay) {
|
|
3
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4
|
+
var timeoutId = null;
|
|
5
|
+
var lastExecTime = 0;
|
|
6
|
+
var _options$leading = options.leading,
|
|
7
|
+
leading = _options$leading === void 0 ? true : _options$leading,
|
|
8
|
+
_options$trailing = options.trailing,
|
|
9
|
+
trailing = _options$trailing === void 0 ? true : _options$trailing;
|
|
10
|
+
return function () {
|
|
11
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
args[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
var currentTime = Date.now();
|
|
15
|
+
if (currentTime - lastExecTime > delay) {
|
|
16
|
+
if (leading) {
|
|
17
|
+
func.apply(null, args);
|
|
18
|
+
lastExecTime = currentTime;
|
|
19
|
+
}
|
|
20
|
+
if (timeoutId) {
|
|
21
|
+
clearTimeout(timeoutId);
|
|
22
|
+
timeoutId = null;
|
|
23
|
+
}
|
|
24
|
+
} else if (trailing && !timeoutId) {
|
|
25
|
+
timeoutId = setTimeout(function () {
|
|
26
|
+
func.apply(null, args);
|
|
27
|
+
lastExecTime = Date.now();
|
|
28
|
+
timeoutId = null;
|
|
29
|
+
}, delay - (currentTime - lastExecTime));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export default (function (context) {
|
|
34
|
+
var _inputs$throttle;
|
|
35
|
+
var data = context.data;
|
|
36
|
+
var inputs = context.inputs;
|
|
37
|
+
var outputs = context.outputs;
|
|
38
|
+
var throttledFn = null;
|
|
39
|
+
(_inputs$throttle = inputs.throttle) === null || _inputs$throttle === void 0 || _inputs$throttle.call(inputs, function (val) {
|
|
40
|
+
try {
|
|
41
|
+
var interval = (val === null || val === void 0 ? void 0 : val.interval) || data.interval || 1000;
|
|
42
|
+
var leading = (val === null || val === void 0 ? void 0 : val.leading) !== undefined ? val.leading : data.leading || true;
|
|
43
|
+
var trailing = (val === null || val === void 0 ? void 0 : val.trailing) !== undefined ? val.trailing : data.trailing || true;
|
|
44
|
+
if (!throttledFn) {
|
|
45
|
+
throttledFn = throttle(function () {
|
|
46
|
+
outputs.onExecute({
|
|
47
|
+
interval: interval,
|
|
48
|
+
leading: leading,
|
|
49
|
+
trailing: trailing,
|
|
50
|
+
timestamp: Date.now()
|
|
51
|
+
});
|
|
52
|
+
}, interval, {
|
|
53
|
+
leading: leading,
|
|
54
|
+
trailing: trailing
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 执行节流函数
|
|
59
|
+
throttledFn();
|
|
60
|
+
outputs.onComplete({
|
|
61
|
+
interval: interval,
|
|
62
|
+
leading: leading,
|
|
63
|
+
trailing: trailing
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('节流执行失败:', error);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro';
|
|
2
|
+
export default (function (context) {
|
|
3
|
+
var _inputs$vibrate;
|
|
4
|
+
var data = context.data;
|
|
5
|
+
var inputs = context.inputs;
|
|
6
|
+
var outputs = context.outputs;
|
|
7
|
+
(_inputs$vibrate = inputs.vibrate) === null || _inputs$vibrate === void 0 || _inputs$vibrate.call(inputs, function (val) {
|
|
8
|
+
try {
|
|
9
|
+
var type = (val === null || val === void 0 ? void 0 : val.type) || data.type || 'short';
|
|
10
|
+
if (type === 'long') {
|
|
11
|
+
Taro.vibrateLong({
|
|
12
|
+
success: function success() {
|
|
13
|
+
return outputs.onSuccess('长振动成功');
|
|
14
|
+
},
|
|
15
|
+
fail: function fail(err) {
|
|
16
|
+
return outputs.onFail(err.errMsg || '长振动失败');
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
Taro.vibrateShort({
|
|
21
|
+
success: function success() {
|
|
22
|
+
return outputs.onSuccess('短振动成功');
|
|
23
|
+
},
|
|
24
|
+
fail: function fail(err) {
|
|
25
|
+
return outputs.onFail(err.errMsg || '短振动失败');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('设备振动失败:', error);
|
|
31
|
+
outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '设备振动失败');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
// 显示提示消息
|
|
1
2
|
export { default as mybricks_taro_showToast } from "./_ShowToast";
|
|
3
|
+
// 扫码
|
|
2
4
|
export { default as mybricks_taro_scanQrcode } from "./_ScanQrcode";
|
|
3
|
-
|
|
5
|
+
// 本地存储
|
|
6
|
+
export { default as mybricks_taro_setStorage } from "./_SetStorage";
|
|
7
|
+
export { default as mybricks_taro_getStorage } from "./_GetStorage";
|
|
8
|
+
export { default as mybricks_taro_removeStorage } from "./_RemoveStorage";
|
|
9
|
+
// 地理位置
|
|
10
|
+
export { default as mybricks_taro_getLocation } from "./_GetLocation";
|
|
11
|
+
// 设备功能
|
|
12
|
+
export { default as mybricks_taro_vibrate } from "./_Vibrate";
|
|
13
|
+
export { default as mybricks_taro_callPhone } from "./_CallPhone";
|
|
14
|
+
export { default as mybricks_taro_openCamera } from "./_OpenCamera";
|
|
15
|
+
// 系统功能
|
|
16
|
+
export { default as mybricks_taro_openUrl } from "./_OpenUrl";
|
|
17
|
+
export { default as mybricks_taro_share } from "./_Share";
|
|
18
|
+
export { default as mybricks_taro_getSystemInfo } from "./_GetSystemInfo";
|
|
19
|
+
// 数据处理
|
|
20
|
+
export { default as mybricks_taro_aesEncode } from "./_AesEncode";
|
|
21
|
+
export { default as mybricks_taro_format } from "./_Format";
|
|
22
|
+
// 文件和媒体
|
|
23
|
+
export { default as mybricks_taro_chooseFile } from "./_ChooseFile";
|
|
24
|
+
export { default as mybricks_taro_chooseMedia } from "./_ChooseMedia";
|
|
25
|
+
// 网络请求
|
|
26
|
+
export { default as mybricks_taro_connector } from "./_Connector";
|
|
27
|
+
export { default as mybricks_taro_connectorGlobalHeaders } from "./_ConnectorGlobalHeaders";
|
|
28
|
+
// 导航和路由
|
|
29
|
+
export { default as mybricks_taro_backTo } from "./_BackTo";
|
|
30
|
+
export { default as mybricks_taro_router } from "./_Router";
|
|
31
|
+
export { default as mybricks_taro_openPetalMap } from "./_OpenPetalMap";
|
|
32
|
+
// 语音和多媒体
|
|
33
|
+
export { default as mybricks_taro_textToSpeech } from "./_TextToSpeech";
|
|
34
|
+
// 定时器
|
|
35
|
+
export { default as mybricks_taro_timerDebounce } from "./_TimerDebounce";
|
|
36
|
+
export { default as mybricks_taro_timerDelay } from "./_TimerDelay";
|
|
37
|
+
export { default as mybricks_taro_timerThrottle } from "./_TimerThrottle";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from '@tarojs/components';
|
|
3
|
+
import { useAppContext } from "./ComContext";
|
|
4
|
+
export var PopupRenderer = function PopupRenderer(_ref) {
|
|
5
|
+
var popupMap = _ref.popupMap;
|
|
6
|
+
var _useAppContext = useAppContext(),
|
|
7
|
+
popupState = _useAppContext.popupState;
|
|
8
|
+
var ActivePopup = popupState.visible && popupMap[popupState.name] ? popupMap[popupState.name] : null;
|
|
9
|
+
if (!ActivePopup) return null;
|
|
10
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
11
|
+
className: "global-popup-container",
|
|
12
|
+
style: {
|
|
13
|
+
position: 'fixed',
|
|
14
|
+
top: 0,
|
|
15
|
+
left: 0,
|
|
16
|
+
right: 0,
|
|
17
|
+
bottom: 0,
|
|
18
|
+
zIndex: 999999,
|
|
19
|
+
pointerEvents: 'auto'
|
|
20
|
+
}
|
|
21
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
22
|
+
style: {
|
|
23
|
+
width: '100%',
|
|
24
|
+
height: '100%'
|
|
25
|
+
}
|
|
26
|
+
}, /*#__PURE__*/React.createElement(ActivePopup, null)));
|
|
27
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
4
|
import { useState, useRef, useMemo } from 'react';
|
|
4
|
-
import {
|
|
5
|
+
import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)
|
|
@@ -18,12 +19,8 @@ export function deepProxy(target, onSet) {
|
|
|
18
19
|
};
|
|
19
20
|
var value = obj[prop];
|
|
20
21
|
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
var mybricksMethods = ['get', 'set', 'changed', 'reset', 'registerChange', 'call', 'apply', 'bind', 'push', 'pop'];
|
|
24
|
-
if (value === undefined && typeof prop === 'string' && !mybricksMethods.includes(prop)) {
|
|
25
|
-
value = obj[prop] = {};
|
|
26
|
-
}
|
|
22
|
+
// 只代理已存在的对象属性,不自动创建空对象
|
|
23
|
+
// 避免访问不存在的属性(如 disabled)时污染原始数据
|
|
27
24
|
if (_typeof(value) === 'object' && value !== null && !value.__isProxy) {
|
|
28
25
|
obj[prop] = deepProxy(value, onSet);
|
|
29
26
|
}
|
|
@@ -47,8 +44,13 @@ export function useModel(rawData) {
|
|
|
47
44
|
});
|
|
48
45
|
}, []);
|
|
49
46
|
}
|
|
50
|
-
export function useBindInputs(scope, id) {
|
|
51
|
-
var handlersRef = useRef({});
|
|
47
|
+
export function useBindInputs(scope, id, initialHandlers) {
|
|
48
|
+
var handlersRef = useRef(_objectSpread({}, initialHandlers));
|
|
49
|
+
|
|
50
|
+
// 同步最新的 initialHandlers
|
|
51
|
+
if (initialHandlers) {
|
|
52
|
+
Object.assign(handlersRef.current, initialHandlers);
|
|
53
|
+
}
|
|
52
54
|
return useMemo(function () {
|
|
53
55
|
var proxy = new Proxy({}, {
|
|
54
56
|
get: function get(_target, pin) {
|
|
@@ -60,14 +62,20 @@ export function useBindInputs(scope, id) {
|
|
|
60
62
|
// 逻辑流触发输入
|
|
61
63
|
var handler = handlersRef.current[pin];
|
|
62
64
|
if (typeof handler === 'function') {
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} else {
|
|
69
|
-
handler(arg);
|
|
65
|
+
if (pin === '_setData') {
|
|
66
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
67
|
+
args[_key - 1] = arguments[_key];
|
|
68
|
+
}
|
|
69
|
+
return handler.apply(void 0, [arg].concat(args));
|
|
70
70
|
}
|
|
71
|
+
// 构造 createReactiveInputHandler 需要的参数
|
|
72
|
+
return createReactiveInputHandler({
|
|
73
|
+
input: handler,
|
|
74
|
+
value: arg,
|
|
75
|
+
rels: {},
|
|
76
|
+
// 这里可以扩展 output 关联
|
|
77
|
+
title: id
|
|
78
|
+
});
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./hooks";
|
|
2
2
|
export { WithCom, WithWrapper } from "./with";
|
|
3
|
-
export {
|
|
3
|
+
export { PopupRenderer } from "./PopupRenderer";
|
|
4
|
+
export { pageRouter, router } from "./pageRouter";
|
|
5
|
+
export { popupRouter, subscribePopupRouter, closeActivePopupRouter } from "./popupRouter";
|
|
4
6
|
export { useAppContext } from "./ComContext";
|
|
5
7
|
export { createVariable, createFx, merge } from "../mybricks";
|
|
6
8
|
export { SUBJECT_SUBSCRIBE, SUBJECT_VALUE } from "../mybricks/constant";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
// @ts-ignore 运行时由宿主项目提供 @tarojs/taro
|
|
5
|
+
import Taro from '@tarojs/taro';
|
|
6
|
+
import { Page } from "../mybricks";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Taro 路由驱动 (纯粹版)
|
|
10
|
+
* 只负责处理真正的 Taro 页面跳转
|
|
11
|
+
*/
|
|
12
|
+
var TaroRouter = /*#__PURE__*/function () {
|
|
13
|
+
function TaroRouter() {
|
|
14
|
+
_classCallCheck(this, TaroRouter);
|
|
15
|
+
_defineProperty(this, "paramsBackup", {});
|
|
16
|
+
}
|
|
17
|
+
_createClass(TaroRouter, [{
|
|
18
|
+
key: "getParams",
|
|
19
|
+
value: function getParams(name) {
|
|
20
|
+
var _instance$router;
|
|
21
|
+
var instance = Taro.getCurrentInstance();
|
|
22
|
+
var params = ((_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params) || {};
|
|
23
|
+
|
|
24
|
+
// 备份参数,解决某些生命周期下 Taro 获取不到 params 的问题
|
|
25
|
+
if (!params.data && this.paramsBackup[name]) {
|
|
26
|
+
params = {
|
|
27
|
+
data: this.paramsBackup[name]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
value: params
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "push",
|
|
36
|
+
value: function push(name, _ref) {
|
|
37
|
+
var value = _ref.value;
|
|
38
|
+
var url = "/pages/".concat(name, "/index");
|
|
39
|
+
var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
|
|
40
|
+
if (dataStr) {
|
|
41
|
+
this.paramsBackup[name] = dataStr;
|
|
42
|
+
}
|
|
43
|
+
Taro.navigateTo({
|
|
44
|
+
url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "replace",
|
|
49
|
+
value: function replace(name, _ref2) {
|
|
50
|
+
var value = _ref2.value;
|
|
51
|
+
var url = "/pages/".concat(name, "/index");
|
|
52
|
+
var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
|
|
53
|
+
if (dataStr) {
|
|
54
|
+
this.paramsBackup[name] = dataStr;
|
|
55
|
+
}
|
|
56
|
+
Taro.redirectTo({
|
|
57
|
+
url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "pop",
|
|
62
|
+
value: function pop() {
|
|
63
|
+
Taro.navigateBack();
|
|
64
|
+
}
|
|
65
|
+
}]);
|
|
66
|
+
return TaroRouter;
|
|
67
|
+
}();
|
|
68
|
+
export var router = new TaroRouter();
|
|
69
|
+
export var pageRouter = new Page(router);
|