@aiot-toolkit/velasim
Version:
vela for sim
515 lines (448 loc) • 19.8 kB
JavaScript
export default function(global, globalThis, window, $app_exports$){
var createPageHandler = function() {
return /******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/script-loader.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/module-loader.js!./node_modules/babel-loader/lib/index.js?cwd=/home/hx/work/project/third-app/vela-drinkwater&cacheDirectory&plugins[]=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/babel-plugin-jsx.js&comments=false&configFile=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/packager/babel.config.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/access-loader.js!./src/pages/drinksuccess/drinksuccess.js?uxType=page":
/*!*****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** ./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/script-loader.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/module-loader.js!./node_modules/babel-loader/lib/index.js?cwd=/home/hx/work/project/third-app/vela-drinkwater&cacheDirectory&plugins[]=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/babel-plugin-jsx.js&comments=false&configFile=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/packager/babel.config.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/access-loader.js!./src/pages/drinksuccess/drinksuccess.js?uxType=page ***!
\*****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
/***/ ((module) => {
module.exports = function __scriptModule__ (module, exports, $app_require$){"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _system = _interopRequireDefault($app_require$("@app-module/system.router"));
var _system2 = _interopRequireDefault($app_require$("@app-module/system.file"));
var _system3 = _interopRequireDefault($app_require$("@app-module/system.vibrator"));
var _system4 = _interopRequireDefault($app_require$("@app-module/system.interconnect"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = {
protected: {
today_water: '',
receive_data: '',
userId: 123,
bottleType: 0,
bottleVolume: 150,
bottleVolumeIndex: 10,
intervalTimerId: null,
intervalCount: 5,
timer: null,
instance: {}
},
onInit() {
this.instance = _system4.default.instance();
},
onReady() {
this.today_water = this.$t('strings.drinking');
var that = this;
console.log('--instance--:', this.instance);
this.instance.onmessage = appData => {
console.log('从设备接收数据..........');
var recData = appData.data;
console.log('从设备接收的数据appData:', appData);
console.log('从设备接收的数据:', recData);
if (recData != undefined && recData != 'undefined' && recData != null && recData != '') {
if (recData.substr(0, 5) == '&EOF&' && recData.substring(recData.length - 5) == '&EOF&') {
if (that.timer != null) {
clearTimeout(that.timer);
}
try {
that.receive_data = recData.substring(0, recData.length - 5).slice(5);
that.parseWaterData();
_system3.default.vibrate({
mode: 'short'
});
that.cacheData(that.receive_data, 'internal://cache/water.txt', true);
} catch (err) {}
} else if (recData.substr(0, 5) == '&EOF&') {
if (that.timer != null) {
clearTimeout(that.timer);
}
that.receive_data = recData.slice(5);
} else if (recData.substring(recData.length - 5) == '&EOF&') {
that.receive_data = that.receive_data + recData.substring(0, recData.length - 5);
_system3.default.vibrate({
mode: 'short'
});
try {
that.parseWaterData();
that.cacheData(that.receive_data, 'internal://cache/water.txt', true);
} catch (err) {}
} else {
that.receive_data = that.receive_data + recData;
}
}
};
_system2.default.readText({
uri: 'internal://cache/water.txt',
encoding: 'UTF-8',
success: function (data) {
var jsonObj = JSON.parse(data.text);
that.userId = jsonObj.userId;
that.bottleType = jsonObj.bottleType;
that.bottleVolume = jsonObj.bottleVolume;
that.bottleVolumeIndex = jsonObj.bottleVolumeIndex;
if (jsonObj.dayList[0].totalVolume >= jsonObj.target * 1.5) {
that.today_water = that.$t('strings.drink_too_more');
that.backToMain();
} else {
console.log('water文件中jsonObj:', jsonObj);
var sendObj = that.getSendData();
that.sendWaterData(sendObj, data);
}
},
fail: function (data, code) {
that.today_water = that.$t('strings.drink_error_back');
that.backToMain();
}
});
},
sendWaterData(sendObj, data) {
var that = this;
var messageStr = '&EOF&' + JSON.stringify(sendObj) + '&EOF&';
console.log('sendMessageToApp messageStr:' + messageStr);
this.instance.send({
data: {
data: messageStr
},
success: () => {
that.today_water = that.$t('strings.sending_drink_water');
that.intervalTimerId = setInterval(function () {
that.intervalCount = that.intervalCount - 1;
console.log('发送喝水数据打印intervalCount:', that.intervalCount);
if (that.intervalCount >= 1) {
that.today_water = that.$t('strings.sending_drink_water');
} else if (that.intervalCount == 0) {
that.today_water = that.$t('strings.send_drink_water_failed');
that.backToMain();
if (that.intervalTimerId != null) {
clearInterval(that.intervalTimerId);
that.intervalTimerId = null;
}
}
}, 1000);
},
fail: result => {
console.log(`handling fail, errMsg = ${result.data}, errCode = ${result.code}`);
that.drinkWaterLocal(data.text);
that.cacheSendDrinkWater(sendObj);
that.today_water = that.$t('strings.drink_local');
}
});
},
parseWaterData() {
var jsonObj = JSON.parse(this.receive_data);
if (jsonObj.dayList.length > 0) {
var today_water_data = jsonObj.dayList[0];
this.today_water = this.$t('strings.send_drink_water_success');
if (this.intervalTimerId != null) {
clearInterval(this.intervalTimerId);
this.intervalTimerId = null;
}
}
},
backToMain() {
var that = this;
this.timer = setTimeout(function () {
_system.default.replace({
uri: "pages/main",
params: {}
});
}, 1000);
},
cacheData(storeData, uri, isFinish) {
var that = this;
_system2.default.writeText({
uri: uri,
text: storeData,
append: false,
encoding: 'UTF-8',
success: function () {
if (isFinish) {
that.backToMain();
}
},
fail: function (data, code) {
if (isFinish) {
that.backToMain();
}
}
});
},
getSendData: function () {
var s1 = this.getNowDate();
var s2 = this.getNowTime();
var jsonObj = [{
"userId": this.userId,
"type": this.bottleType,
"volume": this.bottleVolume,
"date": s1,
"time": s2,
"volumeIndex": this.bottleVolumeIndex
}];
return jsonObj;
},
drinkWaterLocal(localData) {
var jsonObj = JSON.parse(localData);
var nowDate = this.getNowDate();
var nowTime = this.getNowTime();
if (jsonObj.dayList.length > 0) {
var today_water_data = jsonObj.dayList[0];
if (nowDate.indexOf(today_water_data.date) != -1) {
var local_count = today_water_data.totalCount + 1;
var local_volume = today_water_data.totalVolume * 1 + this.bottleVolume * 1;
jsonObj.dayList[0].totalCount = local_count;
jsonObj.dayList[0].totalVolume = local_volume;
var mm = {
"date": nowDate,
"time": nowTime,
"type": this.bottleType,
"volume": this.bottleVolume
};
jsonObj.itemList.unshift(mm);
} else {
jsonObj.dayList.splice(0, jsonObj.dayList.length);
jsonObj.itemList.splice(0, jsonObj.itemList.length);
jsonObj.dayList.unshift({
"date": nowDate,
"totalCount": 1,
"totalVolume": this.bottleVolume
});
jsonObj.itemList.unshift({
"date": nowDate,
"time": nowTime,
"type": this.bottleType,
"volume": this.bottleVolume
});
}
} else {
jsonObj.dayList.splice(0, jsonObj.dayList.length);
jsonObj.itemList.splice(0, jsonObj.itemList.length);
jsonObj.dayList.push({
"date": nowDate,
"totalCount": 1,
"totalVolume": this.bottleVolume
});
jsonObj.itemList.push({
"date": nowDate,
"time": nowTime,
"type": this.bottleType,
"volume": this.bottleVolume
});
}
this.receive_data = JSON.stringify(jsonObj);
this.cacheData(this.receive_data, 'internal://cache/water.txt', false);
},
cacheSendDrinkWater(sendObj) {
var that = this;
_system2.default.readText({
uri: 'internal://cache/local_drink.txt',
encoding: 'UTF-8',
success: function (data) {
var jsonObj = JSON.parse(data.text);
jsonObj.unshift(sendObj);
that.cacheData(JSON.stringify(jsonObj), 'internal://cache/local_drink.txt', true);
},
fail: function (data, code) {
var datas = [];
datas.push(sendObj);
that.cacheData(JSON.stringify(datas), 'internal://cache/local_drink.txt', true);
}
});
},
getNowDate() {
var date = new Date();
var seperator1 = '-';
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = '0' + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
return currentdate;
},
getNowTime() {
var date = new Date();
var seperator2 = ':';
var Hours = date.getHours();
var Minutes = date.getMinutes();
var Seconds = date.getSeconds();
if (Hours >= 0 && Hours <= 9) {
Hours = '0' + Hours;
}
if (Minutes >= 0 && Minutes <= 9) {
Minutes = '0' + Minutes;
}
if (Seconds >= 0 && Seconds <= 9) {
Seconds = '0' + Seconds;
}
var currentdate = Hours + seperator2 + Minutes + seperator2 + Seconds;
return currentdate;
},
onDestroy() {
this.instance.onmessage = null;
}
};
exports.default = _default;
const moduleOwn = exports.default || module.exports;
const accessors = ['public', 'protected', 'private'];
if (moduleOwn.data && accessors.some(function (acc) {
return moduleOwn[acc];
})) {
throw new Error('页面VM对象中的属性data不可与"' + accessors.join(',') + '"同时存在,请使用private替换data名称');
} else if (!moduleOwn.data) {
moduleOwn.data = {};
moduleOwn._descriptor = {};
accessors.forEach(function (acc) {
const accType = typeof moduleOwn[acc];
if (accType === 'object') {
moduleOwn.data = Object.assign(moduleOwn.data, moduleOwn[acc]);
for (const name in moduleOwn[acc]) {
moduleOwn._descriptor[name] = {
access: acc
};
}
} else if (accType === 'function') {
console.warn('页面VM对象中的属性' + acc + '的值不能是函数,请使用对象');
}
});
}}
/***/ }),
/***/ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!./src/pages/drinksuccess/drinksuccess.css?uxType=page":
/*!*************************************************************************************************************************************************!*\
!*** ./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!./src/pages/drinksuccess/drinksuccess.css?uxType=page ***!
\*************************************************************************************************************************************************/
/***/ ((module) => {
module.exports = [
[
[
[
0,
"page1radiuscontainer"
]
],
{
"display": "flex",
"justifyContent": "center",
"alignItems": "center",
"flexDirection": "column",
"width": "454px",
"height": "384px"
}
],
[
[
[
0,
"drink_water"
]
],
{
"width": "256px",
"height": "70px",
"animationName": "drink_anim",
"animationDuration": "100ms",
"animationIterationCount": 3,
"animationFillMode": "none"
}
]
]
/***/ }),
/***/ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/template-loader.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./src/pages/drinksuccess/drinksuccess.hml?uxType=page&":
/*!****************************************************************************************************************************************************************************************************************************!*\
!*** ./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/template-loader.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./src/pages/drinksuccess/drinksuccess.hml?uxType=page& ***!
\****************************************************************************************************************************************************************************************************************************/
/***/ ((module) => {
module.exports = function (vm) {
const _vm_ = vm || this
return aiot.__ce__("div", {
"style": {
"width": "454px",
"height": "454px",
"flexDirection": "column",
"justifyContent": "center",
"alignItems": "center"
}
}, [
aiot.__ce__("div", {
"classList": [
"page1radiuscontainer"
]
}, [
aiot.__ce__("image", {
"src": "/common/water_icon.png",
"style": {
"width": "48px",
"height": "64px"
}
}),
aiot.__ce__("text", {
"style": {
"marginTop": "20px",
"letterSpacing": "1px",
"fontSize": "34px",
"textAlign": "center",
"width": "400px",
"height": "100px",
"color": "#ffffff"
},
"value": function () {return _vm_.today_water}
})
])
])
}
/***/ }),
/***/ "./src/pages/drinksuccess/drinksuccess.hml?uxType=page":
/*!*************************************************************!*\
!*** ./src/pages/drinksuccess/drinksuccess.hml?uxType=page ***!
\*************************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var $app_style$ = __webpack_require__(/*! !../../../node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!./drinksuccess.css?uxType=page */ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!./src/pages/drinksuccess/drinksuccess.css?uxType=page")
var $app_script$ = __webpack_require__(/*! !../../../node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/script-loader.js!../../../node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/module-loader.js!../../../node_modules/babel-loader/lib/index.js?cwd=/home/hx/work/project/third-app/vela-drinkwater&cacheDirectory&plugins[]=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/babel-plugin-jsx.js&comments=false&configFile=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/packager/babel.config.js!../../../node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/access-loader.js!./drinksuccess.js?uxType=page */ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/script-loader.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/module-loader.js!./node_modules/babel-loader/lib/index.js?cwd=/home/hx/work/project/third-app/vela-drinkwater&cacheDirectory&plugins[]=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/babel-plugin-jsx.js&comments=false&configFile=/home/hx/work/project/third-app/vela-drinkwater/node_modules/@aiot-toolkit/packager/babel.config.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/access-loader.js!./src/pages/drinksuccess/drinksuccess.js?uxType=page")
var $app_template$ = __webpack_require__(/*! !../../../node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/template-loader.js!../../../node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./drinksuccess.hml?uxType=page& */ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/template-loader.js!./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/fragment-loader.js?index=0&type=template!./src/pages/drinksuccess/drinksuccess.hml?uxType=page&")
$app_script$({}, $app_exports$, $app_require$);
$app_exports$.default.template = $app_template$;
$app_exports$.default.style = $app_style$;
module.exports = $app_exports$.default;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__("./src/pages/drinksuccess/drinksuccess.hml?uxType=page");
/******/
/******/ })()
;
};
return createPageHandler();
};