UNPKG

live-model-bing

Version:

109 lines (102 loc) 7.91 kB
/* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["live-model-bing"] = factory(); else root["live-model-bing"] = factory(); })(self, function() { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./index.js": /*!******************!*\ !*** ./index.js ***! \******************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _model_Countdown__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./model/Countdown */ \"./model/Countdown.js\");\n\r\n\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({\r\n Countdown: _model_Countdown__WEBPACK_IMPORTED_MODULE_0__[\"default\"]\r\n});\n\n//# sourceURL=webpack://live-model-bing/./index.js?"); /***/ }), /***/ "./model/Countdown.js": /*!****************************!*\ !*** ./model/Countdown.js ***! \****************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"CountdownStatus\": () => (/* binding */ CountdownStatus),\n/* harmony export */ \"toFixed\": () => (/* binding */ toFixed),\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n\r\nconst CountdownStatus = {\r\n running: \"running\",\r\n paused: \"paused\",\r\n stoped: \"stoped\"\r\n}\r\nconsole.log(\"Hello world\")\r\nconst COUNT_IN_MILLIS = 10\r\nconst SECOND_IN_MILLIS = 100 * COUNT_IN_MILLIS\r\nconst MINUTE_IN_MILLIS = 60 * SECOND_IN_MILLIS\r\nconst HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS\r\nconst DAY_IN_MILLIS = 24 * HOUR_IN_MILLIS\r\n\r\n// 只有一位的数字前面补0\r\nfunction toFixed(num) {\r\n return `0${num}`.slice(-2)\r\n}\r\n\r\n\r\nclass Countdown {\r\n constructor(ontick, endTimes, step = 200) {\r\n this.ontick = ontick\r\n this.endTimes = endTimes\r\n this.step = step\r\n this.status = CountdownStatus.paused\r\n // 当前计数\r\n this.remainTime = {\r\n days: 0,\r\n hours: 0,\r\n minutes: 0,\r\n seconds: 0,\r\n count: 0\r\n }\r\n }\r\n\r\n /**\r\n * 开始计时\r\n */\r\n start() {\r\n this.status = CountdownStatus.running\r\n this.ontick && this.ontick()\r\n this.countdown()\r\n }\r\n\r\n /**\r\n * 停止计时\r\n */\r\n pause() {\r\n this.status = CountdownStatus.paused\r\n this.ontick && this.ontick()\r\n }\r\n\r\n /**\r\n * 停止计时\r\n */\r\n stop() {\r\n this.status = CountdownStatus.stoped\r\n this.ontick && this.ontick()\r\n }\r\n\r\n /**\r\n * 计时数数逻辑\r\n */\r\n countdown() {\r\n if(this.status !== CountdownStatus.running) {\r\n return\r\n }\r\n let count = this.endTimes - Date.now()\r\n count = count > 0 ? count : 0\r\n this.remainTime = this.formatRemainTime(count)\r\n if(count > 0) {\r\n setTimeout(this.countdown.bind(this), this.step)\r\n }else{\r\n this.stop()\r\n }\r\n // 重复调用可能导致多次diff\r\n this.ontick && this.ontick()\r\n }\r\n\r\n formatRemainTime(count) {\r\n const days = parseInt(count / DAY_IN_MILLIS)\r\n count = count % DAY_IN_MILLIS\r\n\r\n const hours = parseInt(count / HOUR_IN_MILLIS)\r\n count = count % HOUR_IN_MILLIS\r\n\r\n const minutes = parseInt(count / MINUTE_IN_MILLIS)\r\n count = count % MINUTE_IN_MILLIS\r\n\r\n const seconds = parseInt(count / SECOND_IN_MILLIS)\r\n count = count % SECOND_IN_MILLIS\r\n\r\n count = count / parseInt(COUNT_IN_MILLIS)\r\n count = count % COUNT_IN_MILLIS\r\n\r\n return {\r\n days,\r\n hours,\r\n minutes,\r\n seconds,\r\n count\r\n }\r\n\r\n }\r\n\r\n}\r\n\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Countdown);\n\n//# sourceURL=webpack://live-model-bing/./model/Countdown.js?"); /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.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; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module can't be inlined because the eval devtool is used. /******/ var __webpack_exports__ = __webpack_require__("./index.js"); /******/ __webpack_exports__ = __webpack_exports__["default"]; /******/ /******/ return __webpack_exports__; /******/ })() ; });