mtl-js-sdk
Version:
ynf-fw-mtl-api
83 lines (71 loc) • 2.28 kB
JavaScript
/*
* @Author: wangyingliang@yonyou.com
* @Date: 2023-11-28 16:28:47
* @LastEditors: wangyingliang wangyingliang@yonyou.com
* @LastEditTime: 2025-04-11 15:47:38
* @FilePath: /mtl-api-project/src/plugins/vui/platforms/APIIos/methods.js
* @Description: 小友
* Copyright (c) 2023 by Yonyou, All Rights Reserved.
*/
function invokeFail(param, err) {
if (!param) return;
if (err && !err.message) {
err.message = err.msg || err.errMsg;
}
typeof param.fail === "function" && param.fail(err);
}
function initXiaoYou(object = {}) {
let { bodyDomainId, appcode, tenantid, domain, token, userid, domainid = 'yonapppro',
robotVersion = 'v2', isDialog = false, locale = 'zh_cn', msgtype = 'text', devicetype = 'app',
type = 0, showModel = true, testFlag = false, isShowInputBox = true, isShowHelpBox = true,
bosTime = 3000, eosTime = 1000 } = object;
// 主动获取 yht 信息
mtl.getUserYHTInfo({
isEncrypt: false,
success: function success(res) {
let yhtAccessToken = res?.yhtToken
if (!tenantid || !domain || !token || !userid || !yhtAccessToken) {
invokeFail(object, { message: 'initXiaoYou params error' });
return;
}
if (!bodyDomainId && !appcode) {
bodyDomainId = 'diwork';
appcode = 'diwork';
} else if (!bodyDomainId && appcode) {
bodyDomainId = appcode
} else if (!appcode && bodyDomainId) {
appcode = bodyDomainId
}
execApiBridge('initXiaoYou', {
...object, bodyDomainId, domainid, robotVersion, isDialog, locale, msgtype, devicetype, type,
showModel, testFlag, isShowHelpBox, isShowInputBox, bosTime, eosTime, appcode, yhtAccessToken
})
},
fail: function fail() {
invokeFail(object, { message: 'initXiaoYou yhtAccessToken is null' });
}
});
}
function openXiaoYou(object = {}) {
execApiBridge('openXiaoYou', object)
}
function closeXY(object = {}) {
execApiBridge('closeXY', object)
}
// 内部方法
function execApiBridge(method, object) {
const { isNative = false } = object
let requireName = 'xiaoyouLight'
var obj = window.api?.require(requireName);
if (obj && !isNative) {
requireName = 'xiaoyouLight'
} else {
requireName = 'xiaoyou'
}
mtl.execPluginBridge({ ...object, method, requireName })
}
export default {
initXiaoYou,
openXiaoYou,
closeXY
};