mtl-js-sdk
Version:
1,170 lines (1,068 loc) • 36.7 kB
JavaScript
;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// eslint-disable-next-line no-undef
define(['axios'], function (axios) {
var _upesn;
var FAIL_CODE = 1;
var __NCC = "NCC";
var upesn = (_upesn = {
test: function test() {
console.log("test");
},
uploadImageBackBase64: function uploadImageBackBase64(object) {
var _obj = object || {};
var data = {
// 'url': 'https://www.pgyer.com/app/publish',
url: "https://mdoctor.yonyoucloud.com/mtldebugger/mtl/file/convertBase64",
filePath: _obj.filePath,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("uploadFile", data);
},
showToast: function showToast(object) {
var _obj = object || {};
var data = Object.assign({
closeNcc: true,
content: _obj['content'],
duration: _obj['duration']
}, handleResponse(_obj));
execEsnBridge("showToast", data);
},
customScanQRCode: function customScanQRCode(object) {
var _obj = object || {};
var _obj$type = _obj.type,
type = _obj$type === void 0 ? 1 : _obj$type,
url = _obj.url,
callback = _obj.callback,
_obj$scanLeftRatio = _obj.scanLeftRatio,
scanLeftRatio = _obj$scanLeftRatio === void 0 ? 0.25 : _obj$scanLeftRatio,
_obj$scanTopRatio = _obj.scanTopRatio,
scanTopRatio = _obj$scanTopRatio === void 0 ? 0.1 : _obj$scanTopRatio,
_obj$scanWidthRatio = _obj.scanWidthRatio,
scanWidthRatio = _obj$scanWidthRatio === void 0 ? 0.5 : _obj$scanWidthRatio,
_obj$scanHeightRatio = _obj.scanHeightRatio,
scanHeightRatio = _obj$scanHeightRatio === void 0 ? 0.2 : _obj$scanHeightRatio,
_obj$isHiddenLight = _obj.isHiddenLight,
isHiddenLight = _obj$isHiddenLight === void 0 ? 0 : _obj$isHiddenLight,
customNavi = _obj.customNavi,
leftItems = _obj.leftItems,
rightItems = _obj.rightItems,
centerItems = _obj.centerItems,
scanViewCloseCallback = _obj.scanViewCloseCallback;
if (!url || !callback || scanWidthRatio === 0) {
var err = {
code: FAIL_CODE,
message: scanWidthRatio === 0 ? 'scanWidthRatio is zero' : "".concat(!url ? "url" : "callback", " is null")
};
_obj.fail && object.fail(err);
_obj.complete && object.complete(err);
return;
}
var data = Object.assign({
type: type,
url: url,
callback: callback,
scanLeftRatio: scanLeftRatio,
scanTopRatio: scanTopRatio,
scanWidthRatio: scanWidthRatio,
scanHeightRatio: scanHeightRatio,
isHiddenLight: isHiddenLight,
customNavi: customNavi,
leftItems: leftItems,
rightItems: rightItems,
centerItems: centerItems,
scanViewCloseCallback: scanViewCloseCallback
}, handleResponse(_obj));
execEsnBridge("customScanQRCode", data);
},
mdfCustomScanQRCode: function mdfCustomScanQRCode(object) {
var _obj = object || {};
var type = _obj.type,
hide = _obj.hide,
callback = _obj.callback,
scanLeftRatio = _obj.scanLeftRatio,
scanTopRatio = _obj.scanTopRatio,
scanWidthRatio = _obj.scanWidthRatio,
scanHeightRatio = _obj.scanHeightRatio;
var data = Object.assign({
type: type,
hide: hide,
callback: callback,
scanLeftRatio: scanLeftRatio,
scanTopRatio: scanTopRatio,
scanWidthRatio: scanWidthRatio,
scanHeightRatio: scanHeightRatio,
closeNcc: true
}, handleResponse(_obj));
execEsnBridge("mdfCustomScanQRCode", data);
},
mdfChangeCustomScanMode: function mdfChangeCustomScanMode(object) {
var _obj = object || {};
var type = _obj.type;
var data = Object.assign({
type: type,
closeNcc: true
}, handleResponse(_obj));
execEsnBridge("mdfChangeCustomScanMode", data);
},
mdfChangeFlashLightStatus: function mdfChangeFlashLightStatus(object) {
var _obj = object || {};
var type = _obj.type,
callback = _obj.callback;
var data = Object.assign({
type: type,
callback: callback,
closeNcc: true
}, handleResponse(_obj));
execEsnBridge("mdfChangeFlashLightStatus", data);
},
getUserYHTInfo: function getUserYHTInfo(object) {
var _obj = object || {};
var data = handleResponse(_obj);
execEsnBridge("getUserYHTInfo", data);
},
registerCallback: function registerCallback(callbackName, inCallback) {
var obj = {};
obj[callbackName] = function (data, callback) {
console.log(data);
if (!!data && data !== "{}") {
inCallback(JSON.parse(data).qrString, callback);
} else {
inCallback("", callback);
}
}; // eslint-disable-next-line no-undef
YYEsnBridge.registerHandler(obj);
},
registerCommonCallback: function registerCommonCallback(callbackName, inCallback) {
var obj = {};
obj[callbackName] = function (data, callback) {
inCallback(data, callback);
}; // eslint-disable-next-line no-undef
YYEsnBridge.registerHandler(obj);
},
registerResumeCallback: function registerResumeCallback(callbackName, inCallback) {
var obj = {};
obj[callbackName] = function (data) {
inCallback(data);
}; // eslint-disable-next-line no-undef
YYEsnBridge.registerHandler(obj);
},
executeDBOperate: function executeDBOperate(obj) {
var _obj = obj || {};
var data = {
executeType: _obj.executeType,
executeSql: _obj.executeSql,
success: function success(res) {
_obj.success && _obj.success(res);
},
fail: function fail(err) {
_obj.fail && _obj.fail(err);
},
complete: function complete(res) {
_obj.complete && _obj.complete(res);
}
};
execEsnBridge("executeDBOperate", data);
},
loadImageFromLocal: function loadImageFromLocal(object) {
var _obj = object || {};
var data = {
url: _obj.url,
closeNcc: true,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("loadImageFromLocal", data);
},
chooseImage: function chooseImage(object) {
//{OriginalSize: 830617, OriginalUrl: "", thumbSize: 0, thumbUrl: ""}
//目前先写出 一个地址
var _obj = object || {};
var data = {
sourceType: _obj.sourceType,
count: _obj.count,
watermark: _obj.watermark,
returnThumbnail: _obj.returnThumbnail,
success: function success(res) {
// let _localIds = [];
// for (let index in res.pictures) {
// let _picture = res.pictures[index];
// let _value = _picture.filePath;
// _localIds.push(_value);
// }
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("chooseImages", data);
},
chooseImageToServer: function chooseImageToServer(object) {
var _obj = object || {};
var _obj$count = _obj.count,
count = _obj$count === void 0 ? 9 : _obj$count,
_obj$sourceType = _obj.sourceType,
sourceType = _obj$sourceType === void 0 ? ['album', 'camera'] : _obj$sourceType,
watermark = _obj.watermark;
if (!!watermark && !!!watermark.text) {
var err = {
code: FAIL_CODE,
message: "text is null"
};
_obj.fail && object.fail(err);
_obj.complete && object.complete(err);
return;
}
var data = Object.assign({
count: count,
sourceType: sourceType,
watermark: watermark
}, handleResponse(_obj));
execEsnBridge("chooseImageToServer", data);
},
compressLocalImage: function compressLocalImage(object) {
var _obj = object || {};
var data = {
type: _obj.type,
level: _obj.level,
imgData: _obj.imgData,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("compressLocalImage", data);
},
viewUserInfo: function viewUserInfo(object) {
var _obj = object || {};
var data = {
memberId: _obj.memberId,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("viewUserInfo", data);
},
chooseDepartment: function chooseDepartment(object) {
var _obj = object || {};
var multiple = _obj.multiple,
selectedList = _obj.selectedList,
maxCount = _obj.maxCount,
selectedCount = _obj.selectedCount,
deptType = _obj.deptType;
var data = {
multiple: multiple,
selectedList: selectedList ? selectedList : [],
maxCount: maxCount,
selectedCount: selectedCount ? selectedCount : 0,
deptType: deptType,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("chooseDepartment", data);
},
chooseContacts: function chooseContacts(object) {
var _obj = object || {};
var multiple = _obj.multiple,
selectedList = _obj.selectedList,
maxCount = _obj.maxCount,
navTitle = _obj.navTitle,
navColor = _obj.navColor,
qzId = _obj.qzId,
canDelete = _obj.canDelete,
canSelectDept = _obj.canSelectDept,
needYhtUserId = _obj.needYhtUserId;
var data = {
multiple: multiple,
selectedList: selectedList ? selectedList : [],
maxCount: maxCount,
navTitle: navTitle,
navColor: navColor,
qzId: qzId,
canDelete: canDelete,
canSelectDept: canSelectDept,
needYhtUserId: needYhtUserId,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("chooseContacts", data);
},
chooseAllContacts: function chooseAllContacts(object) {
var _obj = object || {};
var data = {
multiple: _obj.multiple,
navTitle: _obj.navTitle,
selectedList: _obj.selectedList,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("chooseAllContacts", data);
},
chooseInsideGroup: function chooseInsideGroup(object) {
var _obj = object || {};
var data = {
multiple: _obj.multiple,
selectedList: _obj.selectedList,
groupType: _obj.groupType,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
}; // eslint-disable-next-line no-undef
YYEsnBridge["do"]("chooseInsideGroup", data);
},
createFeedComponent: function createFeedComponent(object) {
var _obj = object || {};
var data = {
groupId: _obj.groupId,
groupName: _obj.groupName,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("createFeedComponent", data);
},
openChatByUserId: function openChatByUserId(object) {
var _obj = object || {};
var userType = _obj.userType,
userId = _obj.userId;
if (!userId) {
var err = {
code: FAIL_CODE,
message: "userId is null"
};
_obj.fail && object.fail(err);
_obj.complete && object.complete(err);
return;
}
var data = Object.assign({
userId: userId,
userType: userType
}, handleResponse(_obj));
execEsnBridge("openChatByUserId", data);
},
sendImageMessages: function sendImageMessages(object) {
var _obj = object || {};
var data = {
userType: _obj.userType,
chatId: _obj.chatId,
chatType: _obj.chatType,
filePaths: _obj.filePaths,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("sendImageMessages", data);
},
createNewSchedule: function createNewSchedule(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("createNewSchedule", data);
},
viewScheduleList: function viewScheduleList(object) {
var _obj = object || {};
var data = {
time: _obj.time,
memberId: _obj.memberId,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("viewScheduleList", data);
},
viewScheduleDetail: function viewScheduleDetail(object) {
var _obj = object || {};
var data = {
scheduleId: _obj.scheduleId,
subId: _obj.subId,
memberId: _obj.memberId,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("viewScheduleDetail", data);
},
sendMiniMail: function sendMiniMail(object) {
var _obj = object || {};
var data = {
users: _obj.users,
spaceId: _obj.spaceId,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("sendMiniMail", data);
},
openLibraryFiles: function openLibraryFiles(object) {
var _obj = object || {};
var firstCatalog = _obj.firstCatalog,
secondCatalog = _obj.secondCatalog,
thirdCatalog = _obj.thirdCatalog;
var data = {
firstCatalog: firstCatalog,
secondCatalog: secondCatalog,
thirdCatalog: thirdCatalog,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("openLibraryFiles", data);
},
previewDoc: function previewDoc(object) {
var _obj = object || {};
var fileId = _obj.fileId,
_obj$fromType = _obj.fromType,
fromType = _obj$fromType === void 0 ? fromType ? fromType : fileId ? 0 : 5 : _obj$fromType,
downloadUrl = _obj.downloadUrl,
fileName = _obj.fileName,
needDownload = _obj.needDownload,
upload_url = _obj.upload_url;
if (!fileId) {
var message; // 下载地址 文件名称存在
if (!!downloadUrl && !!fileName) {
var index = fileName.lastIndexOf(".");
var ext = fileName.substr(index + 1);
var fileType = ['doc', 'docx', 'wps', 'dps', 'wpt', 'pot', 'potx', 'ppt', 'pptx', 'dpt', 'pps', 'ppsx', 'xls', 'xlsx', 'txt', 'pdf', 'rar', 'zip', 'avi', 'rmvb', 'rm', 'asf', 'divx', 'mpg', 'mpeg', 'mpe', 'wmv', 'mp4', 'mkv', 'vob', 'flv', 'jpg', 'jpeg', 'bmp', 'psd', 'gif', 'png', 'tiff', 'mp3', 'wav'];
if (!fileType.includes(ext)) {
message = 'fileName format error ';
} else if (fromType === 9 && !upload_url) {
message = 'upload_url is error ';
} else {
var _data = Object.assign({
fromType: fromType,
downloadUrl: downloadUrl,
fileName: fileName,
needDownload: needDownload,
upload_url: upload_url
}, handleResponse(_obj));
execEsnBridge("previewDoc", _data);
return;
}
} else {
message = 'parameter is null';
}
var err = {
code: FAIL_CODE,
message: message
};
_obj.fail && object.fail(err);
_obj.complete && object.complete(err);
return;
} // 文件ID
var data = Object.assign({
fileId: fileId,
fromType: fromType
}, handleResponse(_obj));
execEsnBridge("previewDoc", data);
},
closeCurrentWebview: function closeCurrentWebview(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("closeCurrentWebview", data);
},
settingNavBar: function settingNavBar(object) {
var _obj = object || {};
var hide = _obj.hide,
backgroundColor = _obj.backgroundColor,
tintColor = _obj.tintColor,
fullScreen = _obj.fullScreen,
hideShadowImage = _obj.hideShadowImage,
statusBarStyle = _obj.statusBarStyle,
leftItems = _obj.leftItems,
centerItems = _obj.centerItems,
rightItems = _obj.rightItems;
var data = {
hide: hide,
backgroundColor: backgroundColor,
tintColor: tintColor,
fullScreen: fullScreen,
hideShadowImage: hideShadowImage,
statusBarStyle: statusBarStyle
}; // 数据为null 不添加
if (leftItems) {
data.leftItems = leftItems;
}
if (centerItems) {
data.centerItems = centerItems;
}
if (rightItems) {
data.rightItems = rightItems;
}
var allData = _objectSpread({}, data, {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
});
execEsnBridge("settingNavBar", allData);
},
chooseLocalFileToServer: function chooseLocalFileToServer(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("chooseLocalFileToServer", data);
},
chooseLocalFiles: function chooseLocalFiles() {
var object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _object$maxNumber = object.maxNumber,
maxNumber = _object$maxNumber === void 0 ? 5 : _object$maxNumber;
var data = _objectSpread({
maxNumber: maxNumber
}, handleResponse(object));
execEsnBridge("chooseLocalFiles", data);
},
chooseLibraryFiles: function chooseLibraryFiles(object) {
var _obj = object || {};
var type = _obj.type;
var data = {
type: type,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("chooseLibraryFiles", data);
},
startContinuousLocation: function startContinuousLocation(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("continuousLocationStart", data);
},
getContinuousLocation: function getContinuousLocation(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("continuousLocationGet", data);
},
stopContinuousLocation: function stopContinuousLocation(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("continuousLocationStop", data);
},
shareWithType: function shareWithType(object) {
var _obj = object || {};
var data = {
title: _obj.title,
type: _obj.type,
desc: _obj.desc,
imageUrl: _obj.imageUrl,
pageUrl: _obj.pageUrl,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("shareWithType", data);
},
showAlert: function showAlert(object) {
var _obj = object || {};
var data = {
type: _obj.type,
title: _obj.title,
content: _obj.content,
confirmButtonText: _obj.confirmButtonText,
cancelButtonText: _obj.cancelButtonText,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("showAlert", data);
},
getAppData: function getAppData(object) {
var _obj = object || {};
var data = {
appId: _obj.appId,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("getAppData", data);
},
faceDetect: function faceDetect(object) {
var _obj = object || {};
var spaceId = _obj.spaceId,
faceGroupId = _obj.faceGroupId,
needSmile = _obj.needSmile;
var data = {
spaceId: spaceId,
faceGroupId: faceGroupId,
needSmile: needSmile,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("faceDetect", data);
},
setGesturePassword: function setGesturePassword(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("setGesturePassword", data);
},
verifyGesturePassword: function verifyGesturePassword(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("verifyGesturePassword", data);
},
verifyLoginPassword: function verifyLoginPassword(object) {
var _obj = object || {};
var title = _obj.title;
var data = {
title: title,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("verifyLoginPassword", data);
},
showShareMenu: function showShareMenu(object) {
var _obj = object || {};
var type = _obj.type,
title = _obj.title,
desc = _obj.desc,
imageUrl = _obj.imageUrl,
pageUrl = _obj.pageUrl;
if (!desc || !pageUrl) {
var err = {
code: FAIL_CODE,
message: "".concat(desc ? 'pageUrl' : 'desc', " is null")
};
_obj.fail && object.fail(err);
_obj.complete && object.complete(err);
return;
}
var closeNcc = true;
var data = Object.assign({
title: title,
type: type,
desc: desc,
imageUrl: imageUrl,
pageUrl: pageUrl,
closeNcc: closeNcc
}, handleResponse(_obj));
execEsnBridge("showShareMenu", data);
},
voiceToText: function voiceToText(object) {
execEsnBridge("voiceToText", handleResponse(object));
},
chooseFile: function chooseFile() {
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
execEsnBridge("chooseFile", obj);
},
changeFlashLightStatus: function changeFlashLightStatus(object) {
var _obj = object || {};
var type = _obj.type,
callback = _obj.callback;
var data = Object.assign({
callback: callback,
type: type
}, handleResponse(_obj));
execEsnBridge("changeFlashLightStatus", data);
},
isShowTabbar: function isShowTabbar(object) {
var _obj = object || {};
var data = {
isShow: _obj.isShow,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("isShowTabbar", data);
},
openNewWebview: function openNewWebview(object) {
var _obj = object || {};
var data = {
url: _obj.url,
orientation: _obj.orientation,
navShow: _obj.navShow,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("openNewWebview", data);
}
}, _defineProperty(_upesn, "closeCurrentWebview", function closeCurrentWebview(object) {
var _obj = object || {};
var data = {
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("closeCurrentWebview", data);
}), _defineProperty(_upesn, "login", function login(object) {
var path = object.url ? object.url : 'https://mdf-mobile-daily.yyuap.com';
mtl.upesn.getUserYHTInfo({
success: function success(result) {
var yhtToken = result.yhtToken,
yht_access_token = result.yht_access_token,
yht_userid = result.yht_userid,
tenant_id = result.tenant_id;
var token = yhtToken || yht_access_token;
if (token && yht_userid && tenant_id) {
axios.get(path + "/runtime-mobile/mobile/app/index/yht/token/context", {
params: {
yhtAccessTokenCipher: token,
userId: yht_userid,
tenantId: tenant_id
},
withCredentials: true
}).then(function (response) {
object.success && object.success(response.data);
object.complete && object.complete({
code: 200,
data: response.data
});
})["catch"](function (error) {
object.fail && object.fail(error);
object.complete && object.complete(error);
});
}
},
fail: function fail(err) {
object.fail && object.fail(err);
object.complete && object.complete(err);
}
});
}), _defineProperty(_upesn, "openAppWithParams", function openAppWithParams(object) {
var _obj = object || {};
var data = {
app_id: _obj.app_id,
qz_id: _obj.qz_id,
pluginId: _obj.pluginId,
closeNcc: true,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("openAppWithParams", data);
}), _defineProperty(_upesn, "getToken", function getToken(object) {
var _obj = object || {};
var data = {
closeNcc: true,
success: function success(res) {
_obj.success && object.success(res);
},
fail: function fail(err) {
_obj.fail && object.fail(err);
},
complete: function complete(res) {
_obj.complete && object.complete(res);
}
};
execEsnBridge("getToken", data);
}), _upesn);
function execEsnBridge(method, source) {
var platform = mtl.platform;
var __start = platform === 'QYAndroid' || platform === 'QYIos' ? '' : source.closeNcc ? "" : __NCC;
var data = _objectSpread({}, source, {
fail: function fail(error) {
console.log('error:', error);
source.fail(getErrormsg(method, error, __start));
}
});
console.log("exec YYEsnBridge.do method :", __start + method);
console.log("data: ", data); // eslint-disable-next-line no-undef
YYEsnBridge["do"](__start + method, data);
}
/**
* 400 参数不合法
401 用户无权限访问
405 APP无权限进行此项操作,如打开照相机,APP未取得授权
406 文件大小超出限制
500 http请求错误
501 http服务器错误
1001 无网络
1002 解析错误
1003 用户取消
-1 未知错误
-2 界面超时
-1000 未找到对应方法
* @param {*} error
*/
function getErrormsg(method, error, __start) {
var esnError = {
code: -1,
message: errmsg
};
if (_typeof(error) === "object") {
var code = error && error.errCode;
var 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);
}
var errmsg = "\u8C03\u7528\u53CB\u7A7A\u95F4 ".concat(__start + method, " \u65B9\u6CD5,\u8FD4\u56DE\u9519\u8BEF\u4FE1\u606F\uFF1A ").concat(esnError.message);
esnError.message = errmsg;
console.error(errmsg);
return esnError;
}
/**
* 统一处理API的回调
* @param {*} object
* @param {*} callback
*/
function handleResponse(object, callback) {
return {
success: function success(res) {
var data = callback && callback(res) || res;
object.success && object.success(data);
object.complete && object.complete({
code: 200,
data: data
});
},
fail: function fail(res) {
console.log("handleResponse:fail", res);
object.fail && object.fail(res);
object.complete && object.complete(res);
}
};
}
var exports = {
upesn: upesn
};
return exports;
});