wnjk
Version:
两只蜗牛通用微服务脚本
247 lines (246 loc) • 10.8 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
define(["require", "exports", "../../interface/ibaseNative", "../../utils/jsBridge", "../../model/response", "../../model/webCommand"], function (require, exports, ibaseNative_1, jsBridge_1, response_1, webCommand_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
ibaseNative_1 = __importDefault(ibaseNative_1);
jsBridge_1 = __importDefault(jsBridge_1);
response_1 = __importDefault(response_1);
webCommand_1 = __importDefault(webCommand_1);
var WebNative = (function (_super) {
__extends(WebNative, _super);
function WebNative(appKey) {
var _this = _super.call(this, appKey) || this;
_this.listen();
return _this;
}
WebNative.prototype.listen = function () {
window.onmessage = function (e) {
console.log('客户端监听到新消息:', e.data, e.origin);
if (e && e.data) {
try {
var command = e.data;
if (typeof e.data == 'string') {
command = JSON.parse(e.data);
}
if (command.methodName && command.isContainerMsg != false) {
if (window.native[command.methodName]) {
window.native[command.methodName](command.content);
}
else {
console.log('接收到没有约定过的命令');
}
}
else {
console.log('接收到无法识别的命令');
}
}
catch (err) {
console.log('命令序列化出错:', err);
}
}
};
};
WebNative.prototype.sendMsg = function (data) {
if (self != top) {
window.parent.postMessage(data, '*');
console.log('发送消息:', data);
}
else {
throw new Error("\u5F53\u524D\u4E3A\u975E\u5BB9\u5668\u73AF\u5883\u8FD0\u884C\uFF0C\u65E0\u6CD5\u5B9E\u73B0\u4EA4\u4E92\uFF01");
console.log('没有找到父级页面');
}
};
WebNative.prototype.createWebCommand = function (methodName, data) {
var command = new webCommand_1.default();
command.methodName = methodName;
command.source = this.appKey;
command.content = data;
return command;
};
WebNative.prototype.getToken = function (callback) {
var command = this.createWebCommand('getToken', "{}");
this.sendMsg(command);
jsBridge_1.default.injectListen('getToken', function (sysInfo) {
if (callback) {
callback(sysInfo);
}
});
};
WebNative.prototype.getDoctorInfo = function (callback) {
var command = this.createWebCommand('getDoctorInfo', "{}");
this.sendMsg(command);
jsBridge_1.default.injectListen('getDoctorInfo', function (userInfo) {
if (callback) {
callback(userInfo);
}
});
};
WebNative.prototype.getSystemInfo = function (callback) {
var command = this.createWebCommand('getSystemInfo', "{}");
this.sendMsg(command);
jsBridge_1.default.injectListen('getSystemInfo', function (sysInfo) {
if (callback) {
callback(sysInfo);
}
});
};
WebNative.prototype.measure = function (measureType, presetParam, callback) {
throw new Error('没有对应实现');
};
WebNative.prototype.onAppStart = function (appInfo) {
var command = this.createWebCommand('onAppStart', appInfo);
this.sendMsg(command);
};
WebNative.prototype.onAPPClose = function (callback) {
jsBridge_1.default.injectListen('onAPPClose', callback);
};
WebNative.prototype.getResidentInfo = function (healthRecordId, callback) {
var res = new response_1.default();
if (!healthRecordId) {
res.code = 1;
res.errorMsg = "\u5C45\u6C11\u6863\u6848id\u4E0D\u80FD\u4E3A\u7A7A";
if (callback) {
callback(res);
}
return;
}
var command = this.createWebCommand('getResidentInfo', { healthRecordId: healthRecordId });
this.sendMsg(command);
jsBridge_1.default.injectListen('getResidentInfo', function (res) {
if (callback) {
callback(res);
}
});
};
WebNative.prototype.exitApp = function () {
var command = this.createWebCommand('exitApp', "");
this.sendMsg(command);
};
WebNative.prototype.scanQRCode = function (callback) {
throw new Error('web端容器没有二维码扫码实现!');
};
WebNative.prototype.pickPhoto = function (callback) {
throw new Error('web端容器没有照片选择实现!');
};
WebNative.prototype.pickResident = function (condition, callback) {
var command = this.createWebCommand('pickResident', __assign({}, condition));
this.sendMsg(command);
jsBridge_1.default.injectListen('pickResident', function (res) {
if (callback) {
callback(res);
}
});
};
WebNative.prototype.pickDoctor = function (condition, callback) {
var command = this.createWebCommand('pickDoctor', __assign({}, condition));
this.sendMsg(command);
jsBridge_1.default.injectListen('pickDoctor', function (res) {
if (callback) {
callback(res);
}
});
};
WebNative.prototype.verificationApp = function (callback) {
var command = this.createWebCommand('verificationApp', "");
this.sendMsg(command);
jsBridge_1.default.injectListen('verificationApp', function (res) {
if (callback) {
callback(res);
}
});
};
WebNative.prototype.checkResidentSignStatus = function (spkgId, healthRecordId, callback) {
var res = new response_1.default();
if (!spkgId) {
res.code = 1;
res.errorMsg = "\u7B7E\u7EA6\u670D\u52A1\u5305id\u4E0D\u80FD\u4E3A\u7A7A";
if (callback) {
callback(res);
}
return;
}
if (!healthRecordId) {
res.code = 1;
res.errorMsg = "\u7B7E\u7EA6\u5C45\u6C11\u6863\u6848id\u4E0D\u80FD\u4E3A\u7A7A";
if (callback) {
callback(res);
}
return;
}
var command = this.createWebCommand('checkResidentSignStatus', { spkgId: spkgId, healthRecordId: healthRecordId });
this.sendMsg(command);
jsBridge_1.default.injectListen('checkResidentSignStatus', function (res) {
if (callback) {
callback(res);
}
});
};
WebNative.prototype.bindInspectionNum = function (measureType, businessId, callback) {
var res = new response_1.default();
if (!businessId) {
res.code = 1;
res.errorMsg = "\u5FAE\u5E94\u7528\u63D0\u4F9B\u7684\u4E1A\u52A1id\u4E0D\u80FD\u4E3A\u7A7A";
if (callback) {
callback(res);
}
return;
}
if (!this.measureArr.includes(measureType)) {
res.code = 1;
res.errorMsg = "\u4E0D\u652F\u6301\u7684\u8BBE\u5907\u7C7B\u578B\u2018" + measureType + "\u2019";
if (callback) {
callback(res);
}
return;
}
var command = this.createWebCommand('bindInspectionNum', { id: businessId, measureType: measureType });
this.sendMsg(command);
jsBridge_1.default.injectListen('bindInspectionNum', function (res) {
if (callback) {
callback(res);
}
});
};
WebNative.prototype.nativeExtendsCall = function (methodName, param, callback) {
var fullParam = { appKey: this.appKey };
if (param) {
fullParam = __assign(__assign({}, fullParam), param);
}
var command = this.createWebCommand(methodName, fullParam);
this.sendMsg(command);
jsBridge_1.default.injectListen(methodName, function (res) {
if (callback) {
callback(res);
}
});
};
return WebNative;
}(ibaseNative_1.default));
exports.default = WebNative;
});