mtl-js-sdk
Version:
ynf-fw-mtl-api
129 lines (123 loc) • 2.97 kB
JavaScript
import methods from '../APIIos/methods'
const __NCC = 'NCC';
const { upesnVersion = 0 } = window.mtl
function openXYChatView(obj) {
let _obj = obj || {};
let data = {}
if (upesnVersion > 0) {
data = _obj
} else {
YYEsnBridge.registerHandler({
mtlDataCallBack: obj.callback
});
// xiaoyou_params: { //小友机器人必要参数,必传
// tenantid: "qa56zqg7", //租户id 申请机器人后获得
// appcode: "nccloud", //应用id
// yhtuserid: "b9d3d30d-e110-41a1-99b9-f9ed8b4d771e" //友互通id
// },
data = {
callback: 'mtlDataCallBack',
autoClose: _obj.autoClose,
xiaoyou_params: JSON.stringify(_obj.xiaoyou_params),
success: function (res) {
_obj.success && _obj.success(res);
},
fail: function (res) {
_obj.fail && _obj.fail(res);
},
complete: function (res) {
_obj.complete && _obj.complete(res);
}
};
}
execEsnBridge('openXYChatView', data);
}
function closeXYChatView(obj) {
let _obj = obj || {};
let data = {
success: function (res) {
_obj.success && _obj.success(res);
},
fail: function (res) {
_obj.fail && _obj.fail(res);
},
complete: function (res) {
_obj.complete && _obj.complete(res);
}
};
execEsnBridge('closeXYChatView', data);
}
function getXYVersion(obj) {
let _obj = obj || {};
let data = {
success: function (res) {
_obj.success && _obj.success(res);
},
fail: function (res) {
_obj.fail && _obj.fail(res);
},
complete: function (res) {
_obj.complete && _obj.complete(res);
}
};
execEsnBridge('getXYVersion', data)
}
function execEsnBridge(method, source) {
if (upesnVersion > 0) {
mtl.execPluginBridge({ ...source, method, requireName: null })
return
}
let data = {
...source,
fail: function (error) {
source.fail(getErrormsg(method, error));
}
};
YYEsnBridge.do(__NCC + method, data);
}
/**
* 400 参数不合法
401 用户无权限访问
405 APP无权限进行此项操作,如打开照相机,APP未取得授权
406 文件大小超出限制
500 http请求错误
501 http服务器错误
1001 无网络
1002 解析错误
1003 用户取消
-1 未知错误
-2 界面超时
-1000 未找到对应方法
* @param {*} error
*/
function getErrormsg(method, error) {
let esnError = {
code: -1,
message: errmsg
};
if (typeof error === "object") {
let code = error.errCode;
let msg = "";
if (code == 1003) {
msg = "用户取消";
} else if (code == -1000) {
msg = "未找到对应方法";
} else if (code == 405) {
msg = "APP无权限进行此项操作,如打开照相机,APP未取得授权";
} else if (code == 401) {
msg = "用户无权限访问";
}
esnError.code = code;
esnError.message = msg || JSON.stringify(error);
}
let errmsg = `调用友空间 ${__NCC + method} 方法,返回错误信息: ${esnError.message
}`;
esnError.message = errmsg;
return esnError;
}
export default {
...methods,
openXYChatView,
closeXYChatView,
getXYVersion
};