微信小程序编译
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 13s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 17s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 35s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 15s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 33s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 5s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 15s
Plugin Library CI / publish (07.RKTools) (push) Successful in 2s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 2m32s
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 13s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 17s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 35s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 15s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 33s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 5s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 15s
Plugin Library CI / publish (07.RKTools) (push) Successful in 2s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 2m32s
This commit is contained in:
@@ -0,0 +1,460 @@
|
||||
|
||||
import moduleHelper from './module-helper';
|
||||
import { uid, formatResponse, formatJsonStr, stringifyRes } from './utils';
|
||||
const onEventLists = {};
|
||||
let wxOnAddToFavoritesResolveConf;
|
||||
let wxOnCopyUrlResolveConf;
|
||||
let wxOnHandoffResolveConf;
|
||||
let wxOnShareTimelineResolveConf;
|
||||
let wxOnGameLiveStateChangeResolveConf;
|
||||
const ClassLists = {};
|
||||
const ClassOnEventLists = {};
|
||||
function getClassObject(className, id) {
|
||||
if (!ClassLists[className]) {
|
||||
ClassLists[className] = {};
|
||||
}
|
||||
const obj = ClassLists[className][id];
|
||||
if (!obj) {
|
||||
console.error(`${className} 不存在:`, id);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
function WX_OneWayNoFunction(functionName, ...params) {
|
||||
wx[functionName.replace(/^\w/, (a) => a.toLowerCase())](...params);
|
||||
}
|
||||
|
||||
|
||||
const onlyReadResponse = [
|
||||
'getSystemSetting',
|
||||
'getAppAuthorizeSetting',
|
||||
];
|
||||
|
||||
const needParseJson = ['WXMiniReportManagerReport'];
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
function WX_SyncFunction(functionName, ...params) {
|
||||
return wx[functionName.replace(/^\w/, (a) => a.toLowerCase())](...params);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
function WX_ClassOneWayNoFunction(className, functionName, id, ...params) {
|
||||
const obj = getClassObject(className, id);
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
obj[functionName.replace(/^\w/, (a) => a.toLowerCase())](...params);
|
||||
}
|
||||
function classFormatAndSend(id, callbackId, callbackName, callbackType, resType, res) {
|
||||
formatResponse(resType, res);
|
||||
moduleHelper.send(callbackName, classGetMsg(id, callbackId, callbackType, res));
|
||||
}
|
||||
function classGetMsg(id, callbackId, resType, res) {
|
||||
return JSON.stringify({
|
||||
id, callbackId, type: resType, res: JSON.stringify(res) || '',
|
||||
});
|
||||
}
|
||||
export default {
|
||||
WX_OneWayFunction(functionName, successType, failType, completeType, conf, callbackId) {
|
||||
const lowerFunctionName = functionName.replace(/^\w/, (a) => a.toLowerCase());
|
||||
const config = formatJsonStr(conf);
|
||||
// specialJS
|
||||
if (lowerFunctionName === 'login') {
|
||||
if (!config.timeout) {
|
||||
delete config.timeout;
|
||||
}
|
||||
}
|
||||
else if (lowerFunctionName === 'reportScene') {
|
||||
if (GameGlobal.manager && GameGlobal.manager.setGameStage) {
|
||||
GameGlobal.manager.setGameStage(config.sceneId);
|
||||
}
|
||||
}
|
||||
wx[lowerFunctionName]({
|
||||
...config,
|
||||
success(res) {
|
||||
formatResponse(successType, res);
|
||||
|
||||
if (lowerFunctionName === 'getGameExptInfo') {
|
||||
res.list = JSON.stringify(res.list);
|
||||
}
|
||||
moduleHelper.send(`${functionName}Callback`, JSON.stringify({
|
||||
callbackId, type: 'success', res: JSON.stringify(res),
|
||||
}));
|
||||
},
|
||||
fail(res) {
|
||||
formatResponse(failType, res);
|
||||
moduleHelper.send(`${functionName}Callback`, JSON.stringify({
|
||||
callbackId, type: 'fail', res: JSON.stringify(res),
|
||||
}));
|
||||
},
|
||||
complete(res) {
|
||||
formatResponse(completeType, res);
|
||||
moduleHelper.send(`${functionName}Callback`, JSON.stringify({
|
||||
callbackId, type: 'complete', res: JSON.stringify(res),
|
||||
}));
|
||||
},
|
||||
});
|
||||
},
|
||||
WX_OneWayNoFunction_v(functionName) {
|
||||
WX_OneWayNoFunction(functionName);
|
||||
},
|
||||
WX_OneWayNoFunction_vs(functionName, param1) {
|
||||
WX_OneWayNoFunction(functionName, param1);
|
||||
},
|
||||
WX_OneWayNoFunction_vt(functionName, param1) {
|
||||
const formatParam1 = formatJsonStr(param1);
|
||||
WX_OneWayNoFunction(functionName, formatParam1);
|
||||
},
|
||||
WX_OneWayNoFunction_vst(functionName, param1, param2) {
|
||||
const formatParam2 = formatJsonStr(param2);
|
||||
WX_OneWayNoFunction(functionName, param1, formatParam2);
|
||||
},
|
||||
WX_OneWayNoFunction_vsn(functionName, param1, param2) {
|
||||
WX_OneWayNoFunction(functionName, param1, param2);
|
||||
},
|
||||
WX_OneWayNoFunction_vnns(functionName, param1, param2, param3) {
|
||||
WX_OneWayNoFunction(functionName, param1, param2, param3);
|
||||
},
|
||||
WX_OnEventRegister(functionName, resType) {
|
||||
if (!onEventLists[functionName]) {
|
||||
onEventLists[functionName] = [];
|
||||
}
|
||||
const callback = (res) => {
|
||||
formatResponse(resType, res);
|
||||
const resStr = stringifyRes(res);
|
||||
moduleHelper.send(`_${functionName}Callback`, resStr);
|
||||
};
|
||||
onEventLists[functionName].push(callback);
|
||||
wx[functionName.replace(/^\w/, (a) => a.toLowerCase())](callback);
|
||||
},
|
||||
WX_OffEventRegister(functionName) {
|
||||
(onEventLists[functionName] || []).forEach((v) => {
|
||||
wx[functionName.replace(/^On/, 'off')](v);
|
||||
});
|
||||
},
|
||||
WX_OnAddToFavorites() {
|
||||
const callback = (res) => {
|
||||
const resStr = stringifyRes(res);
|
||||
moduleHelper.send('_OnAddToFavoritesCallback', resStr);
|
||||
return wxOnAddToFavoritesResolveConf;
|
||||
};
|
||||
wx.onAddToFavorites(callback);
|
||||
},
|
||||
WX_OnAddToFavorites_Resolve(conf) {
|
||||
try {
|
||||
wxOnAddToFavoritesResolveConf = formatJsonStr(conf);
|
||||
return;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
wxOnAddToFavoritesResolveConf = {};
|
||||
},
|
||||
WX_OffAddToFavorites() {
|
||||
wx.offAddToFavorites();
|
||||
},
|
||||
WX_OnCopyUrl() {
|
||||
const callback = (res) => {
|
||||
const resStr = stringifyRes(res);
|
||||
moduleHelper.send('_OnCopyUrlCallback', resStr);
|
||||
return wxOnCopyUrlResolveConf;
|
||||
};
|
||||
wx.onCopyUrl(callback);
|
||||
},
|
||||
WX_OnCopyUrl_Resolve(conf) {
|
||||
try {
|
||||
wxOnCopyUrlResolveConf = formatJsonStr(conf);
|
||||
return;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
wxOnCopyUrlResolveConf = {};
|
||||
},
|
||||
WX_OffCopyUrl() {
|
||||
wx.offCopyUrl();
|
||||
},
|
||||
WX_OnHandoff() {
|
||||
const callback = (res) => {
|
||||
const resStr = stringifyRes(res);
|
||||
moduleHelper.send('_OnHandoffCallback', resStr);
|
||||
return wxOnHandoffResolveConf;
|
||||
};
|
||||
wx.onHandoff(callback);
|
||||
},
|
||||
WX_OnHandoff_Resolve(conf) {
|
||||
try {
|
||||
wxOnHandoffResolveConf = formatJsonStr(conf);
|
||||
return;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
wxOnHandoffResolveConf = {};
|
||||
},
|
||||
WX_OffHandoff() {
|
||||
wx.offHandoff();
|
||||
},
|
||||
WX_OnShareTimeline() {
|
||||
const callback = (res) => {
|
||||
const resStr = stringifyRes(res);
|
||||
moduleHelper.send('_OnShareTimelineCallback', resStr);
|
||||
return wxOnShareTimelineResolveConf;
|
||||
};
|
||||
wx.onShareTimeline(callback);
|
||||
},
|
||||
WX_OnShareTimeline_Resolve(conf) {
|
||||
try {
|
||||
wxOnShareTimelineResolveConf = formatJsonStr(conf);
|
||||
return;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
wxOnShareTimelineResolveConf = {};
|
||||
},
|
||||
WX_OffShareTimeline() {
|
||||
wx.offShareTimeline();
|
||||
},
|
||||
WX_OnGameLiveStateChange() {
|
||||
const callback = (res) => {
|
||||
formatResponse('OnGameLiveStateChangeCallbackResult', res);
|
||||
const resStr = stringifyRes(res);
|
||||
moduleHelper.send('_OnGameLiveStateChangeCallback', resStr);
|
||||
return wxOnGameLiveStateChangeResolveConf;
|
||||
};
|
||||
wx.onGameLiveStateChange(callback);
|
||||
},
|
||||
WX_OnGameLiveStateChange_Resolve(conf) {
|
||||
try {
|
||||
wxOnGameLiveStateChangeResolveConf = formatJsonStr(conf);
|
||||
return;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
wxOnGameLiveStateChangeResolveConf = {};
|
||||
},
|
||||
WX_OffGameLiveStateChange() {
|
||||
wx.offGameLiveStateChange();
|
||||
},
|
||||
WX_SyncFunction_bs(functionName, param1) {
|
||||
const res = WX_SyncFunction(functionName, param1);
|
||||
return res;
|
||||
},
|
||||
WX_SyncFunction_t(functionName, returnType) {
|
||||
const res = WX_SyncFunction(functionName);
|
||||
if (onlyReadResponse.includes(functionName.replace(/^\w/, (a) => a.toLowerCase()))) {
|
||||
formatResponse(returnType, JSON.parse(JSON.stringify(res)));
|
||||
return JSON.stringify(res);
|
||||
}
|
||||
formatResponse(returnType, res);
|
||||
return JSON.stringify(res);
|
||||
},
|
||||
WX_SyncFunction_tt(functionName, returnType, param1) {
|
||||
const res = WX_SyncFunction(functionName, formatJsonStr(param1));
|
||||
formatResponse(returnType, res);
|
||||
return JSON.stringify(res);
|
||||
},
|
||||
WX_SyncFunction_b(functionName) {
|
||||
const res = WX_SyncFunction(functionName);
|
||||
return res;
|
||||
},
|
||||
WX_SyncFunction_bsnn(functionName, param1, param2, param3) {
|
||||
const res = WX_SyncFunction(functionName, param1, param2, param3);
|
||||
return res;
|
||||
},
|
||||
WX_SyncFunction_bt(functionName, param1) {
|
||||
const res = WX_SyncFunction(functionName, formatJsonStr(param1));
|
||||
return res;
|
||||
},
|
||||
WX_SyncFunction_nt(functionName, param1) {
|
||||
const res = WX_SyncFunction(functionName, formatJsonStr(param1));
|
||||
return res;
|
||||
},
|
||||
WX_SyncFunction_ss(functionName, param1) {
|
||||
const res = WX_SyncFunction(functionName, param1);
|
||||
return res;
|
||||
},
|
||||
WX_SyncFunction_tnn(functionName, returnType, param1, param2) {
|
||||
const res = WX_SyncFunction(functionName, param1, param2);
|
||||
formatResponse(returnType, res);
|
||||
return JSON.stringify(res);
|
||||
},
|
||||
WX_ClassConstructor(functionName, returnType, successType, failType, completeType, conf) {
|
||||
const config = formatJsonStr(conf);
|
||||
const callbackId = uid();
|
||||
const obj = wx[functionName.replace(/^\w/, (a) => a.toLowerCase())]({
|
||||
...config,
|
||||
success(res) {
|
||||
formatResponse(successType, res);
|
||||
moduleHelper.send(`${functionName}Callback`, JSON.stringify({
|
||||
callbackId, type: 'success', res: JSON.stringify(res),
|
||||
}));
|
||||
},
|
||||
fail(res) {
|
||||
formatResponse(failType, res);
|
||||
moduleHelper.send(`${functionName}Callback`, JSON.stringify({
|
||||
callbackId, type: 'fail', res: JSON.stringify(res),
|
||||
}));
|
||||
},
|
||||
complete(res) {
|
||||
formatResponse(completeType, res);
|
||||
moduleHelper.send(`${functionName}Callback`, JSON.stringify({
|
||||
callbackId, type: 'complete', res: JSON.stringify(res),
|
||||
}));
|
||||
},
|
||||
});
|
||||
if (!ClassLists[returnType]) {
|
||||
ClassLists[returnType] = {};
|
||||
}
|
||||
ClassLists[returnType][callbackId] = obj;
|
||||
return callbackId;
|
||||
},
|
||||
WX_ClassFunction(functionName, returnType, option) {
|
||||
const obj = wx[functionName.replace(/^\w/, (a) => a.toLowerCase())](formatJsonStr(option));
|
||||
const id = uid();
|
||||
if (!ClassLists[returnType]) {
|
||||
ClassLists[returnType] = {};
|
||||
}
|
||||
ClassLists[returnType][id] = obj;
|
||||
return id;
|
||||
},
|
||||
WX_ClassSetProperty(className, id, key, value) {
|
||||
const obj = getClassObject(className, id);
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
if (/^\s*(\{.*\}|\[.*\])\s*$/.test(value)) {
|
||||
try {
|
||||
const jsonValue = JSON.parse(value);
|
||||
Object.assign(obj[key], jsonValue);
|
||||
}
|
||||
catch (e) {
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
obj[key] = value;
|
||||
}
|
||||
},
|
||||
WX_ClassOnEventFunction(className, functionName, returnType, id, eventName) {
|
||||
const obj = getClassObject(className, id);
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
if (!ClassOnEventLists[className + functionName]) {
|
||||
ClassOnEventLists[className + functionName] = {};
|
||||
}
|
||||
const callback = (res) => {
|
||||
if (returnType !== 'string') {
|
||||
formatResponse(returnType, res);
|
||||
}
|
||||
if (!eventName) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
eventName = '';
|
||||
}
|
||||
const resStr = JSON.stringify({
|
||||
callbackId: id + eventName,
|
||||
res: JSON.stringify(res),
|
||||
});
|
||||
moduleHelper.send(`_${className}${functionName}Callback`, resStr);
|
||||
};
|
||||
if (!ClassOnEventLists[className + functionName][id + eventName]) {
|
||||
ClassOnEventLists[className + functionName][id + eventName] = [];
|
||||
}
|
||||
ClassOnEventLists[className + functionName][id + eventName].push(callback);
|
||||
// WXVideoDecoder OnEvent 不规范 特殊处理
|
||||
// update: 2025.9.27: 严重怀疑之前 WXPageManager 压根没有跑通过事件监听,跑到下面去了
|
||||
if (className === 'WXVideoDecoder' || className === 'WXPageManager') {
|
||||
obj[functionName.replace(/^\w/, (a) => a.toLowerCase())](eventName, callback);
|
||||
}
|
||||
else {
|
||||
obj[functionName.replace(/^\w/, (a) => a.toLowerCase())](callback);
|
||||
}
|
||||
},
|
||||
WX_ClassOffEventFunction(className, functionName, id, eventName) {
|
||||
const obj = getClassObject(className, id);
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
if (!eventName) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
eventName = '';
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
functionName = functionName.replace(/Off/, 'On');
|
||||
if (!ClassOnEventLists[className + functionName][id + eventName]) {
|
||||
return;
|
||||
}
|
||||
ClassOnEventLists[className + functionName][id + eventName].forEach((v) => {
|
||||
|
||||
|
||||
if (className === 'WXVideoDecoder' || className === 'WXPageManager') {
|
||||
obj[functionName.replace(/^\w/, (a) => a.toLowerCase())](eventName, v);
|
||||
}
|
||||
else {
|
||||
obj[functionName.replace(/^\w/, (a) => a.toLowerCase())](v);
|
||||
}
|
||||
});
|
||||
delete ClassOnEventLists[className + functionName][id + eventName];
|
||||
},
|
||||
WX_ClassOneWayNoFunction_v(className, functionName, id) {
|
||||
WX_ClassOneWayNoFunction(className, functionName, id);
|
||||
},
|
||||
WX_ClassOneWayNoFunction_vs(className, functionName, id, param1) {
|
||||
if (needParseJson.includes(className + functionName)) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
param1 = JSON.parse(param1);
|
||||
}
|
||||
WX_ClassOneWayNoFunction(className, functionName, id, param1);
|
||||
},
|
||||
WX_ClassOneWayNoFunction_t(className, functionName, returnType, id) {
|
||||
const obj = getClassObject(className, id);
|
||||
if (!obj) {
|
||||
return JSON.stringify(formatResponse(returnType));
|
||||
}
|
||||
const res = obj[functionName.replace(/^\w/, (a) => a.toLowerCase())]();
|
||||
return JSON.stringify(formatResponse(returnType, res, id));
|
||||
},
|
||||
WX_ClassOneWayNoFunction_vt(className, functionName, id, param1) {
|
||||
const formatParam1 = formatJsonStr(param1);
|
||||
WX_ClassOneWayNoFunction(className, functionName, id, formatParam1);
|
||||
},
|
||||
WX_ClassOneWayNoFunction_vn(className, functionName, id, param1) {
|
||||
WX_ClassOneWayNoFunction(className, functionName, id, param1);
|
||||
},
|
||||
WX_ClassOneWayFunction(className, functionName, id, successType, failType, completeType, conf, callbackId, usePromise = false) {
|
||||
|
||||
const obj = getClassObject(className, id);
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
const lowerFunctionName = functionName.replace(/^\w/, (a) => a.toLowerCase());
|
||||
const config = formatJsonStr(conf);
|
||||
|
||||
if (usePromise) {
|
||||
obj[lowerFunctionName]({
|
||||
...config,
|
||||
}).then((res) => {
|
||||
classFormatAndSend(id, callbackId, `_${className}${functionName}Callback`, 'success', successType, res);
|
||||
})
|
||||
.catch((res) => {
|
||||
classFormatAndSend(id, callbackId, `_${className}${functionName}Callback`, 'fail', failType, res);
|
||||
})
|
||||
.finally((res) => {
|
||||
classFormatAndSend(id, callbackId, `_${className}${functionName}Callback`, 'complete', completeType, res);
|
||||
});
|
||||
}
|
||||
else {
|
||||
obj[lowerFunctionName]({
|
||||
...config,
|
||||
success(res) {
|
||||
classFormatAndSend(id, callbackId, `_${className}${functionName}Callback`, 'success', successType, res);
|
||||
},
|
||||
fail(res) {
|
||||
classFormatAndSend(id, callbackId, `_${className}${functionName}Callback`, 'fail', failType, res);
|
||||
},
|
||||
complete(res) {
|
||||
classFormatAndSend(id, callbackId, `_${className}${functionName}Callback`, 'complete', completeType, res);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user