count-down.d.ts.map 2.8 KB

1
  1. {"version":3,"sources":["../src/count-down/count-down.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAYlE,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,cAAc;IACnD,eAAe,WAAe;IAE9B,UAAU,oCAAS;IAEnB,SAAS;;MAIP;IAEF,IAAI;;;;MAIF;IAEF,GAAG,EAAE,IAAI,GAAG,MAAM,CAAQ;IAE1B,QAAQ;IAIR,SAAS;IAQT,KAAK;IAWL,KAAK;IAML,KAAK;IAUL,IAAI;IAQJ,SAAS;IAUT,SAAS;IAcT,SAAS,IAAI,MAAM;IAInB,SAAS,CAAC,MAAM,EAAE,MAAM;CAezB","file":"count-down.d.ts","sourcesContent":["import { SuperComponent, wxComponent } from '../common/src/index';\nimport config from '../common/config';\nimport props from './props';\nimport { isSameSecond, parseFormat, parseTimeData } from './utils';\n\nconst { prefix } = config;\nconst name = `${prefix}-count-down`;\nconst simpleTick = function (fn: (...args: any[]) => void): any {\n return setTimeout(fn, 30);\n};\n\n@wxComponent()\nexport default class CountDown extends SuperComponent {\n externalClasses = ['t-class'];\n\n properties = props;\n\n observers = {\n time() {\n this.reset();\n },\n };\n\n data = {\n classPrefix: name,\n timeData: parseTimeData(0),\n formattedTime: '0',\n };\n\n tid: null | number = null;\n\n detached() {\n this.destroyed();\n }\n\n destroyed() {\n if (this.tid) {\n clearTimeout(this.tid);\n this.tid = null;\n }\n }\n\n // 开始\n start() {\n if (this.counting) {\n return;\n }\n\n this.counting = true;\n this.endTime = Date.now() + this.remain;\n this.tick();\n }\n\n // 暂停\n pause() {\n this.counting = false;\n this.tid && clearTimeout(this.tid);\n }\n\n // 重置\n reset() {\n this.pause();\n this.remain = this.properties.time;\n this.setRemain(this.remain);\n\n if (this.properties.autoStart) {\n this.start();\n }\n }\n\n tick() {\n if (this.properties.millisecond) {\n this.microTick();\n } else {\n this.macroTick();\n }\n }\n\n microTick() {\n this.tid = simpleTick(() => {\n this.setRemain(this.getRemain());\n\n if (this.remain !== 0) {\n this.microTick();\n }\n });\n }\n\n macroTick() {\n this.tid = simpleTick(() => {\n const remain: number = this.getRemain();\n\n if (!isSameSecond(remain, this.remain) || remain === 0) {\n this.setRemain(remain);\n }\n\n if (this.remain !== 0) {\n this.macroTick();\n }\n });\n }\n\n getRemain(): number {\n return Math.max(this.endTime - Date.now(), 0);\n }\n\n setRemain(remain: number) {\n this.remain = remain;\n const timeData = parseTimeData(remain);\n this.triggerEvent('change', timeData);\n const { timeText } = parseFormat(remain, this.properties.format as any as string);\n this.setData({\n timeData,\n formattedTime: timeText.replace(/:/g, ' : '),\n });\n\n if (remain === 0) {\n this.pause();\n this.triggerEvent('finish');\n }\n }\n}\n"]}