Skip to content

Commit

Permalink
fix(panel-kit): fix TYNativeApi中 apiRequest 解析崩溃 && showLoading对内对外保持统一
Browse files Browse the repository at this point in the history
  • Loading branch information
曾照 committed Jun 16, 2020
1 parent 4f5b74e commit 30fd8f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
54 changes: 29 additions & 25 deletions lib/TYNativeApi.js
Expand Up @@ -28,7 +28,7 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
} catch (e) {
result = str;
}
} else result = str || {};return result;
} else rst = void 0 === str ? {} : str;return result;
},
formatValue = function formatValue(e, t) {
if ("string" === type(e)) {
Expand All @@ -44,15 +44,15 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
n = void 0,
a = void 0,
o = void 0,
r = void 0;var v = e,
s = v.dps,
c = parseJson(v.schema);v.schema = {}, v.codeIds = {}, v.idCodes = {}, v.state = {};for (var _e in c) {
t = (i = c[_e]).code, n = "" + i.id, a = parseJson(i.property), i.dptype = i.type, (i = _extends({}, i, a)).id = n, v.codeIds[t] = n, v.idCodes[n] = t, o = formatValue(s[n], i), v.state[t] = o, v.schema[t] = i, delete i.property;
}if (v.panelConfig) {
r = _extends({}, v.panelConfig);for (var _e2 in r) {
v.panelConfig[_e2] = "string" == typeof r[_e2] ? parseJson(r[_e2]) : r[_e2];
r = void 0;var s = e,
v = s.dps,
c = parseJson(s.schema);s.schema = {}, s.codeIds = {}, s.idCodes = {}, s.state = {};for (var _e in c) {
t = (i = c[_e]).code, n = "" + i.id, a = parseJson(i.property), i.dptype = i.type, (i = _extends({}, i, a)).id = n, s.codeIds[t] = n, s.idCodes[n] = t, o = formatValue(v[n], i), s.state[t] = o, s.schema[t] = i, delete i.property;
}if (s.panelConfig) {
r = _extends({}, s.panelConfig);for (var _e2 in r) {
s.panelConfig[_e2] = "string" == typeof r[_e2] ? parseJson(r[_e2]) : r[_e2];
}
} else v.panelConfig = {};return v;
} else s.panelConfig = {};return s;
};var AppDeviceEventEmitter = {};var Event = {},
Device = {},
App = {};var Native = {},
Expand All @@ -70,8 +70,8 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
a = _reactNative.NativeModules.TYRCTDeviceModule,
o = _reactNative.NativeModules.TYRCTPanelManager,
r = i || n,
v = a || o;
r && v && (Native = _extends({}, r, v), TYDeviceData.devInfo = {}, Device.formatDps = function (e) {
s = a || o;
r && s && (Native = _extends({}, r, s), TYDeviceData.devInfo = {}, Device.formatDps = function (e) {
return TYDeviceData.devInfo && TYDeviceData.devInfo.idCodes ? Object.keys(e).reduce(function (t, i) {
var n = TYDeviceData.devInfo.idCodes[i];return _extends({}, t, _defineProperty({}, n, e[i]));
}, {}) : {};
Expand All @@ -97,7 +97,7 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
});
}, Device.initDevice = function () {
return Promise.all([new Promise(function (e) {
return v.getDevInfo({}, function (t) {
return s.getDevInfo({}, function (t) {
return e(t);
});
}), App.getNetworkState()]).then(function (e) {
Expand Down Expand Up @@ -125,11 +125,11 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
a = _objectWithoutProperties(e, ["option"]);

var o = void 0,
r = !0;var s = {};for (var _e4 in a) {
r = !0;var v = {};for (var _e4 in a) {
if (Device.checkDpExist(_e4)) {
s[/^\d+$/.test(_e4) ? _e4 : Device.getDpIdByCode(_e4)] = a[_e4], r = !1;
v[/^\d+$/.test(_e4) ? _e4 : Device.getDpIdByCode(_e4)] = a[_e4], r = !1;
}
}if (r) return i(o = { error: "param error" }), void Event.emit("message", o);__DEV__ && console.log("-----数据下发", e, s), v.putDpData({ command: s, option: "undefined" === type(n) ? 3 : n }, function () {
}if (r) return i(o = { error: "param error" }), void Event.emit("message", o);__DEV__ && console.log("-----数据下发", e, v), s.putDpData({ command: v, option: "undefined" === type(n) ? 3 : n }, function () {
return t({ success: !0 });
}, function (e) {
i(e), Event.emit("message", e);
Expand All @@ -146,15 +146,15 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
return void 0 !== e ? 0 === e.length : e;
}, Device.getBleManagerState = function () {
return new Promise(function (e, t) {
(v.getBleManagerState || function () {
(s.getBleManagerState || function () {
t();
})(function (i) {
if (i) return e(i.state);t();
});
});
}, Device.deleteDeviceInfo = function () {
return new Promise(function (e, t) {
(v.deleteDeviceInfo || function () {
(s.deleteDeviceInfo || function () {
t();
})(e, t);
});
Expand Down Expand Up @@ -202,25 +202,29 @@ var INTERNAL_EVENT_TYPE = ["error", "newListener", "removeListener", "dpDataChan
});
}, App.jumpTo = function (e) {
r.jumpTo(e || "");
}, App.showLoading = function (e) {
r.showLoading({ title: e || "" });
}, App.back = function () {
r.back();
}, App.disablePopGesture = function () {
"ios" === _reactNative.Platform.OS && v.disablePopGesture();
"ios" === _reactNative.Platform.OS && s.disablePopGesture();
}, App.enablePopGesture = function () {
"ios" === _reactNative.Platform.OS && v.enablePopGesture();
}, App.showPromptDialog = function (e, t, i, n, a, o, v) {
"ios" === _reactNative.Platform.OS && s.enablePopGesture();
}, App.showPromptDialog = function (e, t, i, n, a, o, s) {
if ("ios" === _reactNative.Platform.OS) try {
_reactNative.AlertIOS.prompt(i, n, [{ text: e, onPress: function onPress(e) {
return o(e);
}, style: "default" }, { text: t, onPress: function onPress() {
return v();
return s();
}, style: "cancel" }], "plain-text", a);
} catch (e) {} else r.showPromptDialog(i, n, a, o, v);
} catch (e) {} else r.showPromptDialog(i, n, a, o, s);
}, apiRequest = function apiRequest(e) {
return new Promise(function (t, i) {
v.apiRNRequest(e, function (e) {
var i = "object" == typeof e ? e : JSON.parse(e);t(i);
}, i);
s.apiRNRequest(e, function (e) {
var i = parseJson(e);t(i);
}, function (e) {
var t = parseJson(e);i(t);
});
});
});
}var TySdk = { mobile: App, device: Device, apiRequest: apiRequest, native: Native, event: Event, DeviceEventEmitter: AppDeviceEventEmitter, Navigator: {}, applyNavigator: function applyNavigator(e) {
Expand Down

0 comments on commit 30fd8f2

Please sign in to comment.