UNPKG

@aiot-toolkit/velasim

Version:

vela for sim

679 lines (604 loc) 22.2 kB
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/main/main.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/main/main.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.app")); var _system5 = _interopRequireDefault($app_require$("@app-module/system.brightness")); var _system6 = _interopRequireDefault($app_require$("@app-module/system.interconnect")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _default = { protected: { today_water: '', receive_data: '', show_hint: false, today_title: '', water_progress: 0, allowDrink: false, time_src: '/common/time.png', alarm_src: '/common/alarm.png', instance: {} }, downloadApp() { _system.default.replace({ uri: "pages/downloadpage", params: {} }); }, drinkWater() { console.log('---allowDrink---:', this.allowDrink); if (!this.allowDrink) { return; } this.allowDrink = false; _system.default.replace({ uri: "pages/drinksuccess", params: {} }); }, timePage() { if (!this.allowDrink) { return; } this.allowDrink = false; _system.default.replace({ uri: "pages/detail", params: {} }); }, alarmPage() { if (!this.allowDrink) { return; } this.allowDrink = false; _system.default.replace({ uri: "pages/alarm", params: {} }); }, touchMove: function (e) { if (e.direction == 'right') { _system4.default.terminate(); } }, onInit() { this.today_title = this.$t('strings.drink_water_ml'); this.instance = _system6.default.instance(); }, onReady() { console.log('---drinkwater main onReady---'); var that = this; _system2.default.readText({ uri: 'internal://cache/water.txt', encoding: 'UTF-8', success: function (data) { console.log('checkInitData readText success----'); that.show_hint = false; that.receive_data = data.text; that.parseWaterDataInit(); setTimeout(function () { that.allowDrink = true; console.log('---setTimeout-allowDrink---:', that.allowDrink); }, 700); }, fail: function (data, code) { console.log('checkInitData readText failed'); that.show_hint = true; } }); console.log('--main-instance--:', this.instance); this.instance.onmessage = data => { console.log('喝水接收的数据...', JSON.stringify(data)); var recData = data.data; if (recData != undefined && recData != 'undefined' && recData != null && recData != '') { if (recData == '&EOF&Sync&EOF&') { _system2.default.readText({ uri: 'internal://cache/local_drink.txt', encoding: 'UTF-8', success: function (data) { console.log('sync local drink start'); that.syncDataToPhone(data.text); }, fail: function (data, code) {} }); } else if (recData == '&EOF&Alarm&EOF&') { that.today_water = that.$t('strings.arrive_drink_time'); _system3.default.vibrate({ mode: 'short' }); _system5.default.setKeepScreenOn({ keepScreenOn: true, success: function () {}, fail: function (data, code) {} }); setTimeout(function () { _system5.default.setKeepScreenOn({ keepScreenOn: false, success: function () { console.log("handling set keep screen off success."); }, fail: function (data, code) { console.log("handling set keep screen off fail, code:" + code + ", data: " + data); } }); }, 20 * 1000); } else if (recData.substr(0, 5) == '&EOF&' && recData.substring(recData.length - 5) == '&EOF&') { that.receive_data = recData.substring(0, recData.length - 5).slice(5); that.parseWaterData(); that.show_hint = false; that.allowDrink = true; that.cacheData(that.receive_data, 'internal://cache/water.txt'); _system3.default.vibrate({ mode: 'short' }); } else if (recData.substr(0, 5) == '&EOF&') { 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); try { that.parseWaterData(); that.show_hint = false; that.allowDrink = true; that.cacheData(that.receive_data, 'internal://cache/water.txt'); _system3.default.vibrate({ mode: 'short' }); } catch (err) { return; } } else { that.receive_data = that.receive_data + recData; } } }; }, cacheData(storeData, uri) { _system2.default.writeText({ uri: uri, text: storeData, append: false, encoding: 'UTF-8', success: function () {}, fail: function (data, code) {} }); }, parseWaterData() { var jsonObj = JSON.parse(this.receive_data); if (jsonObj.dayList.length > 0) { var today_water_data = jsonObj.dayList[0]; this.today_water = today_water_data.totalVolume + ' / ' + jsonObj.target + ''; this.water_progress = today_water_data.totalVolume * 100 / jsonObj.target; var date = today_water_data.date.slice(5); date = this.changeStr(date, 2, this.$t('strings.month')); this.today_title = date + this.$t('strings.ri_ml'); } else { this.today_water = this.$t('strings.no_drink_water_data_today'); } }, parseWaterDataInit() { var jsonObj = JSON.parse(this.receive_data); if (jsonObj.dayList.length > 0) { var today_water_data = jsonObj.dayList[0]; var nowDate = this.getNowDate(); if (nowDate.indexOf(today_water_data.date) != -1) { this.today_water = today_water_data.totalVolume + ' / ' + jsonObj.target + ''; this.water_progress = today_water_data.totalVolume * 100 / jsonObj.target; var date = today_water_data.date.slice(5); date = this.changeStr(date, 2, this.$t('strings.month')); this.today_title = date + this.$t('strings.ri_ml'); } else { var date = this.changeStr(nowDate.slice(5), 2, this.$t('strings.month')); this.today_title = date + this.$t('strings.ri_ml'); this.today_water = '0 / ' + jsonObj.target + ''; this.water_progress = 0; } } else { this.today_water = this.$t('strings.no_drink_water_data_today'); } }, changeStr(str, index, changeStr) { return str.substr(0, index) + changeStr + str.substr(index + changeStr.length); }, syncDataToPhone(sendStr) { var that = this; if (sendStr == null || sendStr.length <= 2) { return; } this.today_water = this.$t('strings.start_sync'); var tmp = '&EOF&' + sendStr; var num = 950; var len = Math.ceil(tmp.length / num); for (var i = 0; i < len; i++) { var end = (i + 1) * num; if (end > tmp.length) { end = tmp.length; } var mmm = tmp.substring(i * num, end); if (i == len - 1) { mmm = mmm + '&EOF&'; } this.instance.send({ data: { data: mmm }, success: () => { if (i == len) { that.today_water = that.$t('strings.sync_success'); that.cacheData('[]', 'internal://cache/local_drink.txt'); } }, fail: data => { console.log(`handling fail, errMsg = ${data.data}, errCode = ${data.code}`); } }); } }, 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; }, 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/main/main.css?uxType=page": /*!*********************************************************************************************************************************!*\ !*** ./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!./src/pages/main/main.css?uxType=page ***! \*********************************************************************************************************************************/ /***/ ((module) => { module.exports = [ [ [ [ 0, "container" ] ], { "display": "flex", "justifyContent": "center", "alignItems": "center", "left": "0px", "top": "0px", "width": "454px", "height": "454px" } ], [ [ [ 0, "page1radiuscontainer" ] ], { "display": "flex", "justifyContent": "center", "alignItems": "center", "flexDirection": "column", "width": "454px", "height": "380px" } ], [ [ [ 0, "progress" ] ], { "strokeWidth": "20px", "backgroundColor": "#262626", "color": "#007Dff", "radius": "227px", "startAngle": "240deg", "totalAngle": "240deg", "centerX": "227px", "centerY": "227px", "width": "454px", "height": "454px", "borderRadius": "10px" } ], [ [ [ 0, "drink_water" ] ], { "width": "182px", "height": "62px" } ] ] /***/ }), /***/ "./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/main/main.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/main/main.hml?uxType=page& ***! \************************************************************************************************************************************************************************************************************/ /***/ ((module) => { module.exports = function (vm) { const _vm_ = vm || this return aiot.__ce__("div", { "classList": [ "wrap" ], "style": { "flexDirection": "column" } }, [ aiot.__ce__("stack", { "classList": [ "container" ] }, [ aiot.__ci__({ shown: function () {return !_vm_.show_hint} }, function () { return aiot.__ce__("progress", { "type": "arc", "percent": function () {return _vm_.water_progress}, "classList": [ "progress" ], "style": { "position": "absolute" } })}), aiot.__ci__({ shown: function () {return !_vm_.show_hint} }, function () { return aiot.__ce__("div", { "events": { "swipe": function (evt) {_vm_.touchMove(evt)} }, "style": { "width": "454px", "height": "454px", "flexDirection": "column", "justifyContent": "center", "alignItems": "center", "position": "absolute" } }, [ aiot.__ce__("div", { "classList": [ "page1radiuscontainer" ] }, [ aiot.__ce__("image", { "src": "/common/water_icon.png", "style": { "width": "48px", "height": "64px" } }), aiot.__ce__("text", { "style": { "marginTop": "15px", "fontSize": "30px", "textAlign": "center", "width": "400px", "height": "40px" }, "events": { "click": function (evt) {_vm_.changeTextSub(evt)} }, "value": function () {return _vm_.today_title} }), aiot.__ce__("text", { "style": { "marginTop": "5px", "letterSpacing": "1px", "fontSize": "38px", "textAlign": "center", "width": "400px", "height": "50px", "color": "#45a5ff" }, "value": function () {return _vm_.today_water} }), aiot.__ce__("text", { "style": { "marginTop": "5px", "marginBottom": "30px", "fontSize": "30px", "textAlign": "center", "width": "400px", "height": "40px", "color": "#a8a8a8" }, "value": function () {return _vm_.$t('strings.water_ml')} }), aiot.__ce__("div", { "style": { "width": "400px", "height": "60px", "justifyContent": "center", "alignItems": "center" } }, [ aiot.__ce__("image", { "src": function () {return _vm_.time_src}, "events": { "click": function (evt) {_vm_.timePage(evt)} }, "style": { "width": "60px", "height": "60px" } }), aiot.__ce__("image", { "src": function () {return _vm_.alarm_src}, "events": { "click": function (evt) {_vm_.alarmPage(evt)} }, "style": { "width": "60px", "height": "60px", "marginLeft": "110px" } }) ]) ]), aiot.__ce__("div", { "style": { "width": "454px", "height": "62px", "flexDirection": "column", "justifyContent": "center", "alignItems": "center" } }, [ aiot.__ce__("image", { "src": function () {return _vm_.$t('files.drink_water_new')}, "classList": [ "drink_water" ], "events": { "click": function (evt) {_vm_.drinkWater(evt)} } }) ]) ])}), aiot.__ci__({ shown: function () {return _vm_.show_hint} }, function () { return aiot.__ce__("div", { "events": { "swipe": function (evt) {_vm_.touchMove(evt)} }, "style": { "width": "454px", "height": "454px", "justifyContent": "center", "alignItems": "center", "flexDirection": "column", "position": "absolute" } }, [ aiot.__ce__("image", { "src": function () {return _vm_.$t('files.connect_hint')}, "style": { "width": "454px", "height": "344px" } }), aiot.__ce__("image", { "src": function () {return _vm_.$t('files.connect_hint_download')}, "style": { "width": "110px", "height": "110px" }, "events": { "click": function (evt) {_vm_.downloadApp(evt)} } }) ])}) ]) ]) } /***/ }), /***/ "./src/pages/main/main.hml?uxType=page": /*!*********************************************!*\ !*** ./src/pages/main/main.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!./main.css?uxType=page */ "./node_modules/@aiot-toolkit/dsl-xvm/lib/loaders/style-loader.js?index=0&type=style!./src/pages/main/main.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!./main.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/main/main.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!./main.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/main/main.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/main/main.hml?uxType=page"); /******/ /******/ })() ; }; return createPageHandler(); };