UNPKG

mtl-js-sdk

Version:

ynf-fw-mtl-api

148 lines (133 loc) 4.59 kB
import {executeDBOperate} from '../data/index' import {settingNavBar, closeCurrentWebview} from '../ui/index' import {registerCommonCallback, registerCallback} from '../bridge/index' import {mdfCustomScanQRCode, changeCustomScanMode, changeFlashLightStatus, customScanQRCode} from '../scan/index' import {rfidConnect, rfidDisconnect} from '../rfid/index' import {zebraPrinterList, zebraPrintImage} from '../other/index' import {upesnApiList} from '../apiList' import {markAndNavigationDestination, continuousLocationGet, continuousLocationStart, getAppData} from '../device/index' import {getUserYHTInfo} from '../user/index' import {compressLocalImage} from '../media/index' import {wpsPreview, previewDoc, previewFile} from '../file/index' const FAIL_CODE = 1; const SUCCESS_CODE = 200; const unsupportFailRes = { code: FAIL_CODE, message: "current platform does not support" }; function unsupportMethod(param = {}) { param.fail && param.fail(unsupportFailRes); param.complete && param.complete(unsupportFailRes); } function upesnCustomScanQRCode(param = {}) { customScanQRCode({...param, resultType: 'string'}) } function login (object){ let path = object.url ? object.url : 'htt' + 'ps://mdf-mobile-daily.yonyou' + 'cloud.com'; mtl.upesn.getUserYHTInfo({ success: (result) => { const { yhtToken, yht_access_token, yht_userid, tenant_id } = result; const token = yhtToken || yht_access_token; if (token && yht_userid && tenant_id) { var axios = require("axios"); axios = axios?.default || axios axios.get( path + "/mobile/app/index/yht/token/context", { params: { yhtAccessTokenCipher: token, userId: yht_userid, tenantId: tenant_id, }, withCredentials: true, } ) .then((response) => { object.success && object.success(response.data); object.complete && object.complete({ code: 200, data: response.data, }); }) .catch((error) => { object.fail && object.fail(error); object.complete && object.complete(error); }); } }, fail: (err) => { object.fail && object.fail(err); object.complete && object.complete(err); }, }); } let _upesn = { executeDBOperate, settingNavBar, registerCommonCallback, registerCallback, mdfCustomScanQRCode, mdfChangeFlashLightStatus:changeFlashLightStatus, mdfChangeCustomScanMode:changeCustomScanMode, changeCustomScanMode, changeFlashLightStatus, rfidConnect, rfidDisconnect, customScanQRCode: upesnCustomScanQRCode, markAndNavigationDestination, getUserYHTInfo, zebraPrinterList, zebraPrintImage, getContinuousLocation: continuousLocationGet, startContinuousLocation: continuousLocationStart, registerResumeCallback: registerCommonCallback, openChatByUserId: openChatWindow, compressLocalImage, login, blueToothScan: blueToothScan, closeCurrentWebview, wpsPreview, previewDoc, previewFile, getAppData }; upesnApiList.forEach(name => { if (!_upesn[name]) { _upesn[name] = function(param) { if (api[name]) { api[name](param); } else { unsupportMethod(param); } }; } }); export let upesn = _upesn; export function faceVerify(param = {}) { api.faceDetect && api.faceDetect(param); } export function faceRegister(param = {}) { api.faceCollect && api.faceCollect(param); } export function openChatByUserId(param = {}) { api.openChatByUserId && api.openChatByUserId(param); } export function openChatWindow(param = {}) { api.openChatByUserId && api.openChatByUserId(param); } export function openShare(param = {}) { api.showShareMenu && api.showShareMenu(param); } export function blueToothScan(param = {}) { let registerFunc = param.registerFunc; if (typeof registerFunc == 'function') { let handlerName = 'blueToothScanFunc'; registerCommonCallback(handlerName, registerFunc); param.registerFunc = handlerName; } api.blueToothScan && api.blueToothScan(param); } export function openScheduleDetail(param = {}) { let memberId = param.memberId || param.member_id; api.openScheduleDetail && api.openScheduleDetail({...param, member_id:memberId}); }