微信小程序编译
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,171 @@
|
||||
import moduleHelper from './module-helper';
|
||||
import { formatJsonStr, uid } from './utils';
|
||||
|
||||
let MiniGameChat;
|
||||
|
||||
let instance;
|
||||
|
||||
let onList;
|
||||
function createMiniGameChat(options, callback) {
|
||||
try {
|
||||
if (typeof requirePlugin !== 'undefined') {
|
||||
if (!MiniGameChat) {
|
||||
// @ts-ignore
|
||||
MiniGameChat = requirePlugin('MiniGameChat', {
|
||||
enableRequireHostModule: true,
|
||||
customEnv: {
|
||||
wx,
|
||||
},
|
||||
}).default;
|
||||
}
|
||||
if (instance) {
|
||||
return '';
|
||||
}
|
||||
instance = new MiniGameChat(options);
|
||||
if (typeof instance === 'undefined' || typeof instance.on === 'undefined') {
|
||||
|
||||
console.error('MiniGameChat create error');
|
||||
return '';
|
||||
}
|
||||
// 等待插件初始化完成
|
||||
instance.on('ready', () => {
|
||||
if (!GameGlobal.miniGameChat) {
|
||||
GameGlobal.miniGameChat = instance;
|
||||
if (!onList) {
|
||||
onList = {};
|
||||
}
|
||||
|
||||
Object.keys(onList).forEach((eventType) => {
|
||||
if (!onList) {
|
||||
onList = {};
|
||||
}
|
||||
Object.values(onList[eventType]).forEach((callback) => {
|
||||
instance.on(eventType, callback);
|
||||
});
|
||||
});
|
||||
instance.emit('ready');
|
||||
callback(instance);
|
||||
}
|
||||
});
|
||||
instance.on('error', (err) => {
|
||||
console.log('插件初始化失败', err);
|
||||
});
|
||||
return uid();
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
console.error(e);
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
export default {
|
||||
WXChatCreate(optionsStr) {
|
||||
const options = formatJsonStr(optionsStr);
|
||||
return createMiniGameChat({
|
||||
x: options.x,
|
||||
y: options.y,
|
||||
autoShow: false,
|
||||
logoUrl: options.logoUrl || '',
|
||||
movable: options.movable,
|
||||
enableSnap: options.enableSnap,
|
||||
scale: options.scale,
|
||||
}, (instance) => {
|
||||
instance.on('error', (err) => {
|
||||
console.error('error', err);
|
||||
});
|
||||
});
|
||||
},
|
||||
WXChatHide() {
|
||||
if (!GameGlobal.miniGameChat) {
|
||||
return;
|
||||
}
|
||||
GameGlobal.miniGameChat.hide();
|
||||
},
|
||||
WXChatShow(optionsStr) {
|
||||
if (!GameGlobal.miniGameChat) {
|
||||
return;
|
||||
}
|
||||
const options = formatJsonStr(optionsStr);
|
||||
GameGlobal.miniGameChat.show({
|
||||
x: options.x,
|
||||
y: options.y,
|
||||
});
|
||||
},
|
||||
WXChatClose() {
|
||||
if (!GameGlobal.miniGameChat) {
|
||||
return;
|
||||
}
|
||||
GameGlobal.miniGameChat.close();
|
||||
},
|
||||
WXChatOpen(key) {
|
||||
if (!GameGlobal.miniGameChat) {
|
||||
return;
|
||||
}
|
||||
GameGlobal.miniGameChat.open(key || '');
|
||||
},
|
||||
WXChatSetTabs(keysStr) {
|
||||
if (!GameGlobal.miniGameChat) {
|
||||
return;
|
||||
}
|
||||
if (!keysStr) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
keysStr = '[]';
|
||||
}
|
||||
const keys = JSON.parse(keysStr);
|
||||
GameGlobal.miniGameChat.setTabs(keys);
|
||||
},
|
||||
WXChatOff(eventType) {
|
||||
const { miniGameChat } = GameGlobal;
|
||||
if (!miniGameChat) {
|
||||
return;
|
||||
}
|
||||
if (!miniGameChat || typeof onList === 'undefined' || typeof onList[eventType] === 'undefined') {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key in Object.keys(onList[eventType])) {
|
||||
const callback = onList[eventType][key];
|
||||
if (callback) {
|
||||
miniGameChat.off(eventType, callback);
|
||||
}
|
||||
}
|
||||
onList[eventType] = {};
|
||||
},
|
||||
WXChatOn(eventType) {
|
||||
const callbackId = uid();
|
||||
const callback = (res) => {
|
||||
let result = '';
|
||||
if (res) {
|
||||
result = JSON.stringify(res);
|
||||
}
|
||||
const resStr = JSON.stringify({
|
||||
eventType,
|
||||
result,
|
||||
});
|
||||
moduleHelper.send('OnWXChatCallback', resStr);
|
||||
};
|
||||
if (!onList) {
|
||||
onList = {};
|
||||
}
|
||||
if (typeof onList[eventType] === 'undefined') {
|
||||
onList[eventType] = {};
|
||||
}
|
||||
if (onList[eventType]) {
|
||||
onList[eventType][callbackId] = callback;
|
||||
const { miniGameChat } = GameGlobal;
|
||||
if (miniGameChat) {
|
||||
miniGameChat.on(eventType, callback);
|
||||
}
|
||||
return callbackId;
|
||||
}
|
||||
return '';
|
||||
},
|
||||
WXChatSetSignature(signature) {
|
||||
const { miniGameChat } = GameGlobal;
|
||||
if (miniGameChat) {
|
||||
miniGameChat.setChatSignature({ signature });
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user