Commit ce70185f authored by jiangjiantao's avatar jiangjiantao

防抖动点击

parent 9d5c89da
# Changelog
## [Unreleased][]
## [2.2.1][] - 2020-06-08
### Changed
- Upgrade package
- Add Browserstack testing
- Add more detailed usage example to README (#36)
- Use ES2015+ features
[unreleased]: https://github.com/niksy/throttle-debounce/compare/v2.2.1...HEAD
[2.2.1]: https://github.com/niksy/throttle-debounce/tree/v2.2.1
This diff is collapsed.
# throttle-debounce
[![Build Status][ci-img]][ci]
[![BrowserStack Status][browserstack-img]][browserstack]
[![Mentioned in Awesome Micro npm Packages][awesome-img]][awesome]
Throttle and debounce functions.
This module is the same as [jquery-throttle-debounce][jquery-throttle-debounce]
([with some differences](#differences-with-original-module)), but it’s
transferred to ES Modules and CommonJS format.
## Install
```sh
npm install throttle-debounce --save
```
## Usage
### `throttle`
```js
import { throttle } from 'throttle-debounce';
const throttleFunc = throttle(1000, false, (num) => {
console.log('num:', num);
});
// Can also be used like this, because noTrailing is false by default
const throttleFunc = throttle(1000, () => {
console.log('num:', num);
});
throttleFunc(1); // Will execute the callback
throttleFunc(2); // Won’t execute callback
throttleFunc(3); // Won’t execute callback
// Will execute the callback, because noTrailing is false,
// but if we set noTrailing to true, this callback won’t be executed
throttleFunc(4);
setTimeout(() => {
throttleFunc(10); // Will execute the callback
}, 1200);
// Output
// num: 1
// num: 4
// num: 10
```
### `debounce`
```js
import { debounce } from 'throttle-debounce';
const debounceFunc = debounce(1000, false, (num) => {
console.log('num:', num);
});
// Can also be used like this, because atBegin is false by default
const debounceFunc = debounce(1000, () => {
console.log('num:', num);
});
// Won’t execute the callback, because atBegin is false,
// but if we set atBegin to true, this callback will be executed.
debounceFunc(1);
debounceFunc(2); // Won’t execute callback
debounceFunc(3); // Won’t execute callback
// Will execute the callback,
// but if we set atBegin to true, this callback won’t be executed.
debounceFunc(4);
setTimeout(() => {
debounceFunc(10); // Will execute the callback
}, 1200);
// Output
// num: 4
// num: 10
```
### Cancelling
Debounce and throttle can both be cancelled by calling the `cancel` function.
```js
const throttleFunc = throttle(300, () => {
// Throttled function
});
throttleFunc.cancel();
const debounceFunc = debounce(300, () => {
// Debounced function
});
debounceFunc.cancel();
```
The logic that is being throttled or debounced will no longer be called.
## API
### throttle(delay, noTrailing, callback, debounceMode)
Returns: `Function`
Throttle execution of a function. Especially useful for rate limiting execution
of handlers on events like resize and scroll.
#### delay
Type: `Number`
A zero-or-greater delay in milliseconds. For event callbacks, values around 100
or 250 (or even higher) are most useful.
#### noTrailing
Type: `Boolean`
Optional, defaults to false. If noTrailing is true, callback will only execute
every `delay` milliseconds while the throttled-function is being called. If
noTrailing is false or unspecified, callback will be executed one final time
after the last throttled-function call. (After the throttled-function has not
been called for `delay` milliseconds, the internal counter is reset)
#### callback
Type: `Function`
A function to be executed after delay milliseconds. The `this` context and all
arguments are passed through, as-is, to `callback` when the throttled-function
is executed.
#### debounceMode
Type: `Boolean`
If `debounceMode` is true (at begin), schedule `clear` to execute after `delay`
ms. If `debounceMode` is false (at end), schedule `callback` to execute after
`delay` ms.
### debounce(delay, atBegin, callback)
Returns: `Function`
Debounce execution of a function. Debouncing, unlike throttling, guarantees that
a function is only executed a single time, either at the very beginning of a
series of calls, or at the very end.
#### delay
Type: `Number`
A zero-or-greater delay in milliseconds. For event callbacks, values around 100
or 250 (or even higher) are most useful.
#### atBegin
Type: `Boolean`
Optional, defaults to false. If `atBegin` is false or unspecified, callback will
only be executed `delay` milliseconds after the last debounced-function call. If
`atBegin` is true, callback will be executed only at the first
debounced-function call. (After the throttled-function has not been called for
`delay` milliseconds, the internal counter is reset).
#### callback
Type: `Function`
A function to be executed after delay milliseconds. The `this` context and all
arguments are passed through, as-is, to `callback` when the debounced-function
is executed.
## Differences with original module
- Dependancy on jQuery is removed, so if you rely on GUIDs set by jQuery, plan
accordingly
- There is no standalone version available, so don’t rely on `$.throttle` and
`$.debounce` to be available
## Browser support
Tested in IE9+ and all modern browsers.
## Test
For automated tests, run `npm run test:automated` (append `:watch` for watcher
support).
## License
<!-- prettier-ignore-start -->
**Original module license:** Copyright (c) 2010 "Cowboy" Ben Alman (Dual licensed under the MIT and GPL licenses. http://benalman.com/about/license/)
**This module license:** MIT © [Ivan Nikolić](http://ivannikolic.com)
[ci]: https://travis-ci.org/niksy/throttle-debounce
[ci-img]: https://travis-ci.org/niksy/throttle-debounce.svg?branch=master
[browserstack]: https://www.browserstack.com/
[browserstack-img]: https://www.browserstack.com/automate/badge.svg?badge_key=QWo5dGJqTzNkMWFnVXZqYzNvVDF1Q2p2Mm84Skc5ZTZFUUlnYkdEcFhQTT0tLTc1bVR3U284Uk9LZEFiSGR0NS8rY1E9PQ==--4a20321e30f225033ed6840c2fb71c6d1a8d2d1a
[awesome]: https://github.com/parro-it/awesome-micro-npm-packages
[awesome-img]: https://awesome.re/mentioned-badge.svg
[jquery-throttle-debounce]: https://github.com/cowboy/jquery-throttle-debounce
<!-- prettier-ignore-end -->
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/* eslint-disable no-undefined,no-param-reassign,no-shadow */
/**
* Throttle execution of a function. Especially useful for rate limiting
* execution of handlers on events like resize and scroll.
*
* @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {boolean} [noTrailing] - Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the
* throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time
* after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,
* the internal counter is reset).
* @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the throttled-function is executed.
* @param {boolean} [debounceMode] - If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),
* schedule `callback` to execute after `delay` ms.
*
* @returns {Function} A new, throttled, function.
*/
function throttle (delay, noTrailing, callback, debounceMode) {
/*
* After wrapper has stopped being called, this timeout ensures that
* `callback` is executed at the proper times in `throttle` and `end`
* debounce modes.
*/
var timeoutID;
var cancelled = false; // Keep track of the last time `callback` was executed.
var lastExec = 0; // Function to clear existing timeout
function clearExistingTimeout() {
if (timeoutID) {
clearTimeout(timeoutID);
}
} // Function to cancel next exec
function cancel() {
clearExistingTimeout();
cancelled = true;
} // `noTrailing` defaults to falsy.
if (typeof noTrailing !== 'boolean') {
debounceMode = callback;
callback = noTrailing;
noTrailing = undefined;
}
/*
* The `wrapper` function encapsulates all of the throttling / debouncing
* functionality and when executed will limit the rate at which `callback`
* is executed.
*/
function wrapper() {
for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {
arguments_[_key] = arguments[_key];
}
var self = this;
var elapsed = Date.now() - lastExec;
if (cancelled) {
return;
} // Execute `callback` and update the `lastExec` timestamp.
function exec() {
lastExec = Date.now();
callback.apply(self, arguments_);
}
/*
* If `debounceMode` is true (at begin) this is used to clear the flag
* to allow future `callback` executions.
*/
function clear() {
timeoutID = undefined;
}
if (debounceMode && !timeoutID) {
/*
* Since `wrapper` is being called for the first time and
* `debounceMode` is true (at begin), execute `callback`.
*/
exec();
}
clearExistingTimeout();
if (debounceMode === undefined && elapsed > delay) {
/*
* In throttle mode, if `delay` time has been exceeded, execute
* `callback`.
*/
exec();
} else if (noTrailing !== true) {
/*
* In trailing throttle mode, since `delay` time has not been
* exceeded, schedule `callback` to execute `delay` ms after most
* recent execution.
*
* If `debounceMode` is true (at begin), schedule `clear` to execute
* after `delay` ms.
*
* If `debounceMode` is false (at end), schedule `callback` to
* execute after `delay` ms.
*/
timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);
}
}
wrapper.cancel = cancel; // Return the wrapper function.
return wrapper;
}
/* eslint-disable no-undefined */
/**
* Debounce execution of a function. Debouncing, unlike throttling,
* guarantees that a function is only executed a single time, either at the
* very beginning of a series of calls, or at the very end.
*
* @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {boolean} [atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds
* after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
* (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
* @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the debounced-function is executed.
*
* @returns {Function} A new, debounced function.
*/
function debounce (delay, atBegin, callback) {
return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false);
}
exports.debounce = debounce;
exports.throttle = throttle;
//# sourceMappingURL=index.cjs.js.map
{"version":3,"file":"index.cjs.js","sources":["throttle.js","debounce.js"],"sourcesContent":["/* eslint-disable no-undefined,no-param-reassign,no-shadow */\n\n/**\n * Throttle execution of a function. Especially useful for rate limiting\n * execution of handlers on events like resize and scroll.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {boolean} [noTrailing] - Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the\n * throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time\n * after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,\n * the internal counter is reset).\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the throttled-function is executed.\n * @param {boolean} [debounceMode] - If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),\n * schedule `callback` to execute after `delay` ms.\n *\n * @returns {Function} A new, throttled, function.\n */\nexport default function(delay, noTrailing, callback, debounceMode) {\n\t/*\n\t * After wrapper has stopped being called, this timeout ensures that\n\t * `callback` is executed at the proper times in `throttle` and `end`\n\t * debounce modes.\n\t */\n\tlet timeoutID;\n\tlet cancelled = false;\n\n\t// Keep track of the last time `callback` was executed.\n\tlet lastExec = 0;\n\n\t// Function to clear existing timeout\n\tfunction clearExistingTimeout() {\n\t\tif (timeoutID) {\n\t\t\tclearTimeout(timeoutID);\n\t\t}\n\t}\n\n\t// Function to cancel next exec\n\tfunction cancel() {\n\t\tclearExistingTimeout();\n\t\tcancelled = true;\n\t}\n\n\t// `noTrailing` defaults to falsy.\n\tif (typeof noTrailing !== 'boolean') {\n\t\tdebounceMode = callback;\n\t\tcallback = noTrailing;\n\t\tnoTrailing = undefined;\n\t}\n\n\t/*\n\t * The `wrapper` function encapsulates all of the throttling / debouncing\n\t * functionality and when executed will limit the rate at which `callback`\n\t * is executed.\n\t */\n\tfunction wrapper(...arguments_) {\n\t\tlet self = this;\n\t\tlet elapsed = Date.now() - lastExec;\n\n\t\tif (cancelled) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Execute `callback` and update the `lastExec` timestamp.\n\t\tfunction exec() {\n\t\t\tlastExec = Date.now();\n\t\t\tcallback.apply(self, arguments_);\n\t\t}\n\n\t\t/*\n\t\t * If `debounceMode` is true (at begin) this is used to clear the flag\n\t\t * to allow future `callback` executions.\n\t\t */\n\t\tfunction clear() {\n\t\t\ttimeoutID = undefined;\n\t\t}\n\n\t\tif (debounceMode && !timeoutID) {\n\t\t\t/*\n\t\t\t * Since `wrapper` is being called for the first time and\n\t\t\t * `debounceMode` is true (at begin), execute `callback`.\n\t\t\t */\n\t\t\texec();\n\t\t}\n\n\t\tclearExistingTimeout();\n\n\t\tif (debounceMode === undefined && elapsed > delay) {\n\t\t\t/*\n\t\t\t * In throttle mode, if `delay` time has been exceeded, execute\n\t\t\t * `callback`.\n\t\t\t */\n\t\t\texec();\n\t\t} else if (noTrailing !== true) {\n\t\t\t/*\n\t\t\t * In trailing throttle mode, since `delay` time has not been\n\t\t\t * exceeded, schedule `callback` to execute `delay` ms after most\n\t\t\t * recent execution.\n\t\t\t *\n\t\t\t * If `debounceMode` is true (at begin), schedule `clear` to execute\n\t\t\t * after `delay` ms.\n\t\t\t *\n\t\t\t * If `debounceMode` is false (at end), schedule `callback` to\n\t\t\t * execute after `delay` ms.\n\t\t\t */\n\t\t\ttimeoutID = setTimeout(\n\t\t\t\tdebounceMode ? clear : exec,\n\t\t\t\tdebounceMode === undefined ? delay - elapsed : delay\n\t\t\t);\n\t\t}\n\t}\n\n\twrapper.cancel = cancel;\n\n\t// Return the wrapper function.\n\treturn wrapper;\n}\n","/* eslint-disable no-undefined */\n\nimport throttle from './throttle';\n\n/**\n * Debounce execution of a function. Debouncing, unlike throttling,\n * guarantees that a function is only executed a single time, either at the\n * very beginning of a series of calls, or at the very end.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {boolean} [atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds\n * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.\n * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the debounced-function is executed.\n *\n * @returns {Function} A new, debounced function.\n */\nexport default function(delay, atBegin, callback) {\n\treturn callback === undefined\n\t\t? throttle(delay, atBegin, false)\n\t\t: throttle(delay, callback, atBegin !== false);\n}\n"],"names":["delay","noTrailing","callback","debounceMode","timeoutID","cancelled","lastExec","clearExistingTimeout","clearTimeout","cancel","undefined","wrapper","arguments_","self","elapsed","Date","now","exec","apply","clear","setTimeout","atBegin","throttle"],"mappings":";;;;AAAA;;AAEA;;;;;;;;;;;;;;;;AAgBe,mBAASA,KAAT,EAAgBC,UAAhB,EAA4BC,QAA5B,EAAsCC,YAAtC,EAAoD;AAClE;;;;;AAKA,MAAIC,SAAJ;AACA,MAAIC,SAAS,GAAG,KAAhB,CAPkE;;AAUlE,MAAIC,QAAQ,GAAG,CAAf,CAVkE;;AAalE,WAASC,oBAAT,GAAgC;AAC/B,QAAIH,SAAJ,EAAe;AACdI,MAAAA,YAAY,CAACJ,SAAD,CAAZ;AACA;AACD,GAjBiE;;;AAoBlE,WAASK,MAAT,GAAkB;AACjBF,IAAAA,oBAAoB;AACpBF,IAAAA,SAAS,GAAG,IAAZ;AACA,GAvBiE;;;AA0BlE,MAAI,OAAOJ,UAAP,KAAsB,SAA1B,EAAqC;AACpCE,IAAAA,YAAY,GAAGD,QAAf;AACAA,IAAAA,QAAQ,GAAGD,UAAX;AACAA,IAAAA,UAAU,GAAGS,SAAb;AACA;AAED;;;;;;;AAKA,WAASC,OAAT,GAAgC;AAAA,sCAAZC,UAAY;AAAZA,MAAAA,UAAY;AAAA;;AAC/B,QAAIC,IAAI,GAAG,IAAX;AACA,QAAIC,OAAO,GAAGC,IAAI,CAACC,GAAL,KAAaV,QAA3B;;AAEA,QAAID,SAAJ,EAAe;AACd;AACA,KAN8B;;;AAS/B,aAASY,IAAT,GAAgB;AACfX,MAAAA,QAAQ,GAAGS,IAAI,CAACC,GAAL,EAAX;AACAd,MAAAA,QAAQ,CAACgB,KAAT,CAAeL,IAAf,EAAqBD,UAArB;AACA;AAED;;;;;;AAIA,aAASO,KAAT,GAAiB;AAChBf,MAAAA,SAAS,GAAGM,SAAZ;AACA;;AAED,QAAIP,YAAY,IAAI,CAACC,SAArB,EAAgC;AAC/B;;;;AAIAa,MAAAA,IAAI;AACJ;;AAEDV,IAAAA,oBAAoB;;AAEpB,QAAIJ,YAAY,KAAKO,SAAjB,IAA8BI,OAAO,GAAGd,KAA5C,EAAmD;AAClD;;;;AAIAiB,MAAAA,IAAI;AACJ,KAND,MAMO,IAAIhB,UAAU,KAAK,IAAnB,EAAyB;AAC/B;;;;;;;;;;;AAWAG,MAAAA,SAAS,GAAGgB,UAAU,CACrBjB,YAAY,GAAGgB,KAAH,GAAWF,IADF,EAErBd,YAAY,KAAKO,SAAjB,GAA6BV,KAAK,GAAGc,OAArC,GAA+Cd,KAF1B,CAAtB;AAIA;AACD;;AAEDW,EAAAA,OAAO,CAACF,MAAR,GAAiBA,MAAjB,CA9FkE;;AAiGlE,SAAOE,OAAP;AACA;;ACpHD;AAEA,AAEA;;;;;;;;;;;;;;;AAcA,AAAe,mBAASX,KAAT,EAAgBqB,OAAhB,EAAyBnB,QAAzB,EAAmC;AACjD,SAAOA,QAAQ,KAAKQ,SAAb,GACJY,QAAQ,CAACtB,KAAD,EAAQqB,OAAR,EAAiB,KAAjB,CADJ,GAEJC,QAAQ,CAACtB,KAAD,EAAQE,QAAR,EAAkBmB,OAAO,KAAK,KAA9B,CAFX;AAGA;;;;;"}
\ No newline at end of file
/* eslint-disable no-undefined,no-param-reassign,no-shadow */
/**
* Throttle execution of a function. Especially useful for rate limiting
* execution of handlers on events like resize and scroll.
*
* @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {boolean} [noTrailing] - Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the
* throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time
* after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,
* the internal counter is reset).
* @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the throttled-function is executed.
* @param {boolean} [debounceMode] - If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),
* schedule `callback` to execute after `delay` ms.
*
* @returns {Function} A new, throttled, function.
*/
function throttle (delay, noTrailing, callback, debounceMode) {
/*
* After wrapper has stopped being called, this timeout ensures that
* `callback` is executed at the proper times in `throttle` and `end`
* debounce modes.
*/
var timeoutID;
var cancelled = false; // Keep track of the last time `callback` was executed.
var lastExec = 0; // Function to clear existing timeout
function clearExistingTimeout() {
if (timeoutID) {
clearTimeout(timeoutID);
}
} // Function to cancel next exec
function cancel() {
clearExistingTimeout();
cancelled = true;
} // `noTrailing` defaults to falsy.
if (typeof noTrailing !== 'boolean') {
debounceMode = callback;
callback = noTrailing;
noTrailing = undefined;
}
/*
* The `wrapper` function encapsulates all of the throttling / debouncing
* functionality and when executed will limit the rate at which `callback`
* is executed.
*/
function wrapper() {
for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {
arguments_[_key] = arguments[_key];
}
var self = this;
var elapsed = Date.now() - lastExec;
if (cancelled) {
return;
} // Execute `callback` and update the `lastExec` timestamp.
function exec() {
lastExec = Date.now();
callback.apply(self, arguments_);
}
/*
* If `debounceMode` is true (at begin) this is used to clear the flag
* to allow future `callback` executions.
*/
function clear() {
timeoutID = undefined;
}
if (debounceMode && !timeoutID) {
/*
* Since `wrapper` is being called for the first time and
* `debounceMode` is true (at begin), execute `callback`.
*/
exec();
}
clearExistingTimeout();
if (debounceMode === undefined && elapsed > delay) {
/*
* In throttle mode, if `delay` time has been exceeded, execute
* `callback`.
*/
exec();
} else if (noTrailing !== true) {
/*
* In trailing throttle mode, since `delay` time has not been
* exceeded, schedule `callback` to execute `delay` ms after most
* recent execution.
*
* If `debounceMode` is true (at begin), schedule `clear` to execute
* after `delay` ms.
*
* If `debounceMode` is false (at end), schedule `callback` to
* execute after `delay` ms.
*/
timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);
}
}
wrapper.cancel = cancel; // Return the wrapper function.
return wrapper;
}
/* eslint-disable no-undefined */
/**
* Debounce execution of a function. Debouncing, unlike throttling,
* guarantees that a function is only executed a single time, either at the
* very beginning of a series of calls, or at the very end.
*
* @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {boolean} [atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds
* after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
* (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
* @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the debounced-function is executed.
*
* @returns {Function} A new, debounced function.
*/
function debounce (delay, atBegin, callback) {
return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false);
}
export { debounce, throttle };
//# sourceMappingURL=index.esm.js.map
{"version":3,"file":"index.esm.js","sources":["throttle.js","debounce.js"],"sourcesContent":["/* eslint-disable no-undefined,no-param-reassign,no-shadow */\n\n/**\n * Throttle execution of a function. Especially useful for rate limiting\n * execution of handlers on events like resize and scroll.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {boolean} [noTrailing] - Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the\n * throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time\n * after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,\n * the internal counter is reset).\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the throttled-function is executed.\n * @param {boolean} [debounceMode] - If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),\n * schedule `callback` to execute after `delay` ms.\n *\n * @returns {Function} A new, throttled, function.\n */\nexport default function(delay, noTrailing, callback, debounceMode) {\n\t/*\n\t * After wrapper has stopped being called, this timeout ensures that\n\t * `callback` is executed at the proper times in `throttle` and `end`\n\t * debounce modes.\n\t */\n\tlet timeoutID;\n\tlet cancelled = false;\n\n\t// Keep track of the last time `callback` was executed.\n\tlet lastExec = 0;\n\n\t// Function to clear existing timeout\n\tfunction clearExistingTimeout() {\n\t\tif (timeoutID) {\n\t\t\tclearTimeout(timeoutID);\n\t\t}\n\t}\n\n\t// Function to cancel next exec\n\tfunction cancel() {\n\t\tclearExistingTimeout();\n\t\tcancelled = true;\n\t}\n\n\t// `noTrailing` defaults to falsy.\n\tif (typeof noTrailing !== 'boolean') {\n\t\tdebounceMode = callback;\n\t\tcallback = noTrailing;\n\t\tnoTrailing = undefined;\n\t}\n\n\t/*\n\t * The `wrapper` function encapsulates all of the throttling / debouncing\n\t * functionality and when executed will limit the rate at which `callback`\n\t * is executed.\n\t */\n\tfunction wrapper(...arguments_) {\n\t\tlet self = this;\n\t\tlet elapsed = Date.now() - lastExec;\n\n\t\tif (cancelled) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Execute `callback` and update the `lastExec` timestamp.\n\t\tfunction exec() {\n\t\t\tlastExec = Date.now();\n\t\t\tcallback.apply(self, arguments_);\n\t\t}\n\n\t\t/*\n\t\t * If `debounceMode` is true (at begin) this is used to clear the flag\n\t\t * to allow future `callback` executions.\n\t\t */\n\t\tfunction clear() {\n\t\t\ttimeoutID = undefined;\n\t\t}\n\n\t\tif (debounceMode && !timeoutID) {\n\t\t\t/*\n\t\t\t * Since `wrapper` is being called for the first time and\n\t\t\t * `debounceMode` is true (at begin), execute `callback`.\n\t\t\t */\n\t\t\texec();\n\t\t}\n\n\t\tclearExistingTimeout();\n\n\t\tif (debounceMode === undefined && elapsed > delay) {\n\t\t\t/*\n\t\t\t * In throttle mode, if `delay` time has been exceeded, execute\n\t\t\t * `callback`.\n\t\t\t */\n\t\t\texec();\n\t\t} else if (noTrailing !== true) {\n\t\t\t/*\n\t\t\t * In trailing throttle mode, since `delay` time has not been\n\t\t\t * exceeded, schedule `callback` to execute `delay` ms after most\n\t\t\t * recent execution.\n\t\t\t *\n\t\t\t * If `debounceMode` is true (at begin), schedule `clear` to execute\n\t\t\t * after `delay` ms.\n\t\t\t *\n\t\t\t * If `debounceMode` is false (at end), schedule `callback` to\n\t\t\t * execute after `delay` ms.\n\t\t\t */\n\t\t\ttimeoutID = setTimeout(\n\t\t\t\tdebounceMode ? clear : exec,\n\t\t\t\tdebounceMode === undefined ? delay - elapsed : delay\n\t\t\t);\n\t\t}\n\t}\n\n\twrapper.cancel = cancel;\n\n\t// Return the wrapper function.\n\treturn wrapper;\n}\n","/* eslint-disable no-undefined */\n\nimport throttle from './throttle';\n\n/**\n * Debounce execution of a function. Debouncing, unlike throttling,\n * guarantees that a function is only executed a single time, either at the\n * very beginning of a series of calls, or at the very end.\n *\n * @param {number} delay - A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {boolean} [atBegin] - Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds\n * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.\n * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).\n * @param {Function} callback - A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the debounced-function is executed.\n *\n * @returns {Function} A new, debounced function.\n */\nexport default function(delay, atBegin, callback) {\n\treturn callback === undefined\n\t\t? throttle(delay, atBegin, false)\n\t\t: throttle(delay, callback, atBegin !== false);\n}\n"],"names":["delay","noTrailing","callback","debounceMode","timeoutID","cancelled","lastExec","clearExistingTimeout","clearTimeout","cancel","undefined","wrapper","arguments_","self","elapsed","Date","now","exec","apply","clear","setTimeout","atBegin","throttle"],"mappings":"AAAA;;AAEA;;;;;;;;;;;;;;;;AAgBe,mBAASA,KAAT,EAAgBC,UAAhB,EAA4BC,QAA5B,EAAsCC,YAAtC,EAAoD;AAClE;;;;;AAKA,MAAIC,SAAJ;AACA,MAAIC,SAAS,GAAG,KAAhB,CAPkE;;AAUlE,MAAIC,QAAQ,GAAG,CAAf,CAVkE;;AAalE,WAASC,oBAAT,GAAgC;AAC/B,QAAIH,SAAJ,EAAe;AACdI,MAAAA,YAAY,CAACJ,SAAD,CAAZ;AACA;AACD,GAjBiE;;;AAoBlE,WAASK,MAAT,GAAkB;AACjBF,IAAAA,oBAAoB;AACpBF,IAAAA,SAAS,GAAG,IAAZ;AACA,GAvBiE;;;AA0BlE,MAAI,OAAOJ,UAAP,KAAsB,SAA1B,EAAqC;AACpCE,IAAAA,YAAY,GAAGD,QAAf;AACAA,IAAAA,QAAQ,GAAGD,UAAX;AACAA,IAAAA,UAAU,GAAGS,SAAb;AACA;AAED;;;;;;;AAKA,WAASC,OAAT,GAAgC;AAAA,sCAAZC,UAAY;AAAZA,MAAAA,UAAY;AAAA;;AAC/B,QAAIC,IAAI,GAAG,IAAX;AACA,QAAIC,OAAO,GAAGC,IAAI,CAACC,GAAL,KAAaV,QAA3B;;AAEA,QAAID,SAAJ,EAAe;AACd;AACA,KAN8B;;;AAS/B,aAASY,IAAT,GAAgB;AACfX,MAAAA,QAAQ,GAAGS,IAAI,CAACC,GAAL,EAAX;AACAd,MAAAA,QAAQ,CAACgB,KAAT,CAAeL,IAAf,EAAqBD,UAArB;AACA;AAED;;;;;;AAIA,aAASO,KAAT,GAAiB;AAChBf,MAAAA,SAAS,GAAGM,SAAZ;AACA;;AAED,QAAIP,YAAY,IAAI,CAACC,SAArB,EAAgC;AAC/B;;;;AAIAa,MAAAA,IAAI;AACJ;;AAEDV,IAAAA,oBAAoB;;AAEpB,QAAIJ,YAAY,KAAKO,SAAjB,IAA8BI,OAAO,GAAGd,KAA5C,EAAmD;AAClD;;;;AAIAiB,MAAAA,IAAI;AACJ,KAND,MAMO,IAAIhB,UAAU,KAAK,IAAnB,EAAyB;AAC/B;;;;;;;;;;;AAWAG,MAAAA,SAAS,GAAGgB,UAAU,CACrBjB,YAAY,GAAGgB,KAAH,GAAWF,IADF,EAErBd,YAAY,KAAKO,SAAjB,GAA6BV,KAAK,GAAGc,OAArC,GAA+Cd,KAF1B,CAAtB;AAIA;AACD;;AAEDW,EAAAA,OAAO,CAACF,MAAR,GAAiBA,MAAjB,CA9FkE;;AAiGlE,SAAOE,OAAP;AACA;;ACpHD;AAEA,AAEA;;;;;;;;;;;;;;;AAcA,AAAe,mBAASX,KAAT,EAAgBqB,OAAhB,EAAyBnB,QAAzB,EAAmC;AACjD,SAAOA,QAAQ,KAAKQ,SAAb,GACJY,QAAQ,CAACtB,KAAD,EAAQqB,OAAR,EAAiB,KAAjB,CADJ,GAEJC,QAAQ,CAACtB,KAAD,EAAQE,QAAR,EAAkBmB,OAAO,KAAK,KAA9B,CAFX;AAGA;;;;"}
\ No newline at end of file
{
"_from": "throttle-debounce",
"_id": "throttle-debounce@2.2.1",
"_inBundle": false,
"_integrity": "sha512-i9hAVld1f+woAiyNGqWelpDD5W1tpMroL3NofTz9xzwq6acWBlO2dC8k5EFSZepU6oOINtV5Q3aSPoRg7o4+fA==",
"_location": "/throttle-debounce",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "throttle-debounce",
"name": "throttle-debounce",
"escapedName": "throttle-debounce",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/throttle-debounce/-/throttle-debounce-2.2.1.tgz",
"_shasum": "fbd933ae6793448816f7d5b3cae259d464c98137",
"_spec": "throttle-debounce",
"_where": "/Users/jiangjiantao/Documents/workspace/qingting/back/doublescreen-back",
"author": {
"name": "Ivan Nikolić",
"email": "niksy5@gmail.com",
"url": "http://ivannikolic.com"
},
"bugs": {
"url": "https://github.com/niksy/throttle-debounce/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Ben Alman",
"url": "http://benalman.com"
}
],
"dependencies": {},
"deprecated": false,
"description": "Throttle and debounce functions.",
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/runtime": "^7.2.0",
"babel-loader": "^8.0.4",
"babel-preset-niksy": "^4.1.0",
"changelog-verify": "^1.1.2",
"core-js": "^2.6.5",
"eslint": "^6.7.2",
"eslint-config-niksy": "^8.0.0",
"eslint-config-prettier": "^4.2.0",
"eslint-plugin-extend": "^0.1.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsdoc": "^18.4.3",
"eslint-plugin-mocha": "^6.2.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.9.1",
"eslint-plugin-unicorn": "^14.0.1",
"esm": "^3.0.51",
"get-port": "^4.0.0",
"get-port-cli": "^2.0.0",
"github-release-from-changelog": "^2.1.1",
"husky": "^3.1.0",
"karma": "^4.0.1",
"karma-browserstack-launcher": "^1.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha-reporter": "^2.2.5",
"karma-qunit": "^0.1.9",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"lint-staged": "^9.5.0",
"minimist": "^1.2.0",
"np": "^3.0.4",
"prettier": "^1.17.0",
"qunitjs": "^1.23.1",
"rollup": "^1.0.0",
"rollup-plugin-babel": "^4.2.0",
"version-changelog": "^3.1.1",
"webpack": "^4.12.0"
},
"directories": {
"test": "test"
},
"engines": {
"node": ">=8"
},
"files": [
"index.cjs.{js,js.map}",
"index.esm.{js,js.map}",
"CHANGELOG.md",
"LICENSE.md",
"README.md"
],
"homepage": "https://github.com/niksy/throttle-debounce#readme",
"keywords": [
"debounce",
"throttle"
],
"license": "MIT",
"main": "index.cjs.js",
"module": "index.esm.js",
"name": "throttle-debounce",
"repository": {
"type": "git",
"url": "git+https://github.com/niksy/throttle-debounce.git"
},
"scripts": {
"build": "rollup --config rollup.config.js",
"lint": "eslint '{index,debounce,throttle,test/**/*}.js'",
"postpublish": "GITHUB_TOKEN=$GITHUB_RELEASE_TOKEN echo 'github-release-from-changelog'",
"prepublishOnly": "npm run build",
"release": "np",
"test": "npm run lint && npm run test:automated",
"test:automated": "BABEL_ENV=test SERVICE_PORT=$(get-port) karma start",
"test:automated:watch": "npm run test:automated -- --auto-watch --no-single-run",
"version": "version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md"
},
"sideEffects": false,
"version": "2.2.1"
}
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"mini-antui": {
"version": "0.4.34",
"resolved": "https://registry.npmjs.org/mini-antui/-/mini-antui-0.4.34.tgz",
"integrity": "sha512-ZiJJwUa8kso2OQqBtJsRhliueXa7L8a++sAAZeNCnJ8nQ+eWfONV/8uV3IDdMEJEZKVZZTYsrFZcXRIwRXLomQ=="
},
"throttle-debounce": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/throttle-debounce/-/throttle-debounce-2.2.1.tgz",
"integrity": "sha512-i9hAVld1f+woAiyNGqWelpDD5W1tpMroL3NofTz9xzwq6acWBlO2dC8k5EFSZepU6oOINtV5Q3aSPoRg7o4+fA=="
},
"undefined": {
"version": "0.1.0",
"resolved": "https://registry.npm.taobao.org/undefined/download/undefined-0.1.0.tgz",
"integrity": "sha1-m3BqSzKtMMIMpP5l3cu72sMr3tA="
}
}
}
import { throttle } from 'throttle-debounce';
var api = require("../../utils/api.js"); var api = require("../../utils/api.js");
import { import {
ACTION_USE_COUPON, ACTION_GOODS, ACTION_MEMBER, ACTION_USE_COUPON, ACTION_GOODS, ACTION_MEMBER,
...@@ -116,6 +117,8 @@ Page({ ...@@ -116,6 +117,8 @@ Page({
], ],
}, },
/** /**
* 显示吐司方法 * 显示吐司方法
* @param text 吐司内容 * @param text 吐司内容
...@@ -451,7 +454,7 @@ Page({ ...@@ -451,7 +454,7 @@ Page({
//回到首页 //回到首页
goHome() { goHome: throttle(2000, function(){
console.log("goHome"); console.log("goHome");
let context = this; let context = this;
my.ix.sendBuddyMessage({ my.ix.sendBuddyMessage({
...@@ -470,7 +473,7 @@ Page({ ...@@ -470,7 +473,7 @@ Page({
console.log("通知前屏回到首页 失败 ===》 " + JSON.stringify(res)); console.log("通知前屏回到首页 失败 ===》 " + JSON.stringify(res));
}, },
}); });
}, }),
//重置部分必须重置的内容 //重置部分必须重置的内容
reinitData() { reinitData() {
...@@ -494,23 +497,23 @@ Page({ ...@@ -494,23 +497,23 @@ Page({
/**首页相关 */ /**首页相关 */
/**立即收款 */ /**立即收款 */
onHomeCashierImmediatelyClicked() { onHomeCashierImmediatelyClicked: throttle(2000, function(){
this.setData({ scene: 3, flowType: FLOW_DIRECT_PAYMENT }) this.setData({ scene: 3, flowType: FLOW_DIRECT_PAYMENT })
}, }),
/** /**
* 兑换 * 兑换
*/ */
onHomeExchangeClicked() { onHomeExchangeClicked: throttle(2000, function(){
this.setData({ convertCouponState: 1 }) this.setData({ convertCouponState: 1 })
this.sendConvertCouponToFront(1) this.sendConvertCouponToFront(1)
}, }),
/** /**
* 海报 * 海报
*/ */
onHomePosterClicked() { onHomePosterClicked: throttle(2000, function(){
//发送指令至前屏,获取当前正在显示的广告页面 //发送指令至前屏,获取当前正在显示的广告页面
my.ix.sendBuddyMessage({ my.ix.sendBuddyMessage({
target: getApp().globalData.frontScreenAppId, target: getApp().globalData.frontScreenAppId,
...@@ -525,23 +528,23 @@ Page({ ...@@ -525,23 +528,23 @@ Page({
console.log("sendBuddyMessage fail:" + JSON.stringify(res)); console.log("sendBuddyMessage fail:" + JSON.stringify(res));
}, },
}); });
}, }),
/** /**
* 退款 * 退款
*/ */
onHomeRefundClicked() { onHomeRefundClicked: throttle(2000, function(){
this.setData({ this.setData({
flowType: FLOW_REFUND, flowType: FLOW_REFUND,
scene: 4 scene: 4
}) })
console.log("scene:" + this.data.scene) console.log("scene:" + this.data.scene)
}, }),
/** /**
* 打印上一单 * 打印上一单
*/ */
onHomePrintLastOrderClicked() { onHomePrintLastOrderClicked: throttle(2000, function(){
if (this.data.printEnabled != true) { if (this.data.printEnabled != true) {
return; return;
} }
...@@ -565,12 +568,12 @@ Page({ ...@@ -565,12 +568,12 @@ Page({
context.showToast("发送指令失败"); context.showToast("发送指令失败");
} }
}); });
}, }),
/** /**
* 核验 * 核验
*/ */
onHomeVerifyClicked() { onHomeVerifyClicked: throttle(2000, function(){
this.setData({ this.setData({
flowType: FLOW_VERIFY, flowType: FLOW_VERIFY,
}) })
...@@ -595,12 +598,12 @@ Page({ ...@@ -595,12 +598,12 @@ Page({
console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`); console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
} }
}); });
}, }),
/** /**
* 提货 * 提货
*/ */
onHomePickUpGoodsClicked() { onHomePickUpGoodsClicked: throttle(2000, function(){
let context = this; let context = this;
my.ix.sendBuddyMessage({ my.ix.sendBuddyMessage({
target: getApp().globalData.frontScreenAppId, target: getApp().globalData.frontScreenAppId,
...@@ -616,10 +619,10 @@ Page({ ...@@ -616,10 +619,10 @@ Page({
console.log("提货通知前屏 失败 ===》 " + JSON.stringify(fres)); console.log("提货通知前屏 失败 ===》 " + JSON.stringify(fres));
} }
}) })
}, }),
/**日结 */ /**日结 */
onHomeDayCheckClicked() { onHomeDayCheckClicked: throttle(2000, function(){
//发送打印日结订单到前屏 //发送打印日结订单到前屏
let context = this; let context = this;
my.ix.sendBuddyMessage({ my.ix.sendBuddyMessage({
...@@ -639,17 +642,17 @@ Page({ ...@@ -639,17 +642,17 @@ Page({
console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`); console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
} }
}); });
}, }),
/**关于系统(实际上是关于应用) */ /**关于系统(实际上是关于应用) */
onHomeAboutAppClicked() { onHomeAboutAppClicked: throttle(2000, function(){
this.goPage("aboutsystem"); this.goPage("aboutsystem");
}, }),
/** /**
* 系统设置 * 系统设置
*/ */
onHomeSysSettingClicked() { onHomeSysSettingClicked: throttle(2000, function(){
this.showToast("请在前屏操作"); this.showToast("请在前屏操作");
my.ix.sendBuddyMessage({ my.ix.sendBuddyMessage({
// 填入目标小程序的 AppID // 填入目标小程序的 AppID
...@@ -665,15 +668,15 @@ Page({ ...@@ -665,15 +668,15 @@ Page({
console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`); console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
} }
}); });
}, }),
/** /**
* 应用设置 * 应用设置
*/ */
onHomeAppSettingClicked() { onHomeAppSettingClicked: throttle(2000, function(){
this.goPage("appsetting"); this.goPage("appsetting");
}, }),
/**payresult页面逻辑方法 */ /**payresult页面逻辑方法 */
//重新收款 //重新收款
...@@ -681,7 +684,7 @@ Page({ ...@@ -681,7 +684,7 @@ Page({
//跳转至结算页 //跳转至结算页
this.goPage('waitoperate'); this.goPage('waitoperate');
}, },
onReprint() { onReprint: throttle(2000, function(){
if (this.data.printEnabled != true) { if (this.data.printEnabled != true) {
return; return;
} }
...@@ -700,7 +703,7 @@ Page({ ...@@ -700,7 +703,7 @@ Page({
console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`); console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
} }
}); });
}, }),
onNextPayFromPayResult() { onNextPayFromPayResult() {
//通知前屏跳首页 //通知前屏跳首页
...@@ -721,8 +724,11 @@ Page({ ...@@ -721,8 +724,11 @@ Page({
}); });
}, },
//跳转到收银页面 //跳转到收银页面
sendGoToCollections() { sendGoToCollections: throttle(2000, function(){
//首先清除数据 //首先清除数据
this.setData({ this.setData({
...@@ -763,7 +769,7 @@ Page({ ...@@ -763,7 +769,7 @@ Page({
console.log("发送收银事件到前屏小程序 ===》" + JSON.stringify(res)); console.log("发送收银事件到前屏小程序 ===》" + JSON.stringify(res));
}, },
}); });
}, }),
//发生直接收银事件 //发生直接收银事件
...@@ -878,13 +884,13 @@ Page({ ...@@ -878,13 +884,13 @@ Page({
//清空商品信息 //清空商品信息
clearGood(e) { clearGood: throttle(2000, function(e){
this.setData({ goods: [], discCouponPrice: 0 }) this.setData({ goods: [], discCouponPrice: 0 })
this.calculation([]); this.calculation([]);
}, }),
//删除商品 //删除商品
deleteGood(e) { deleteGood: throttle(2000, function(e){
let barcode = e.target.id; let barcode = e.target.id;
let lastgoods = this.data.goods; let lastgoods = this.data.goods;
let newGoods = [] let newGoods = []
...@@ -896,9 +902,9 @@ Page({ ...@@ -896,9 +902,9 @@ Page({
this.setData({ goods: newGoods }) this.setData({ goods: newGoods })
this.calculation(newGoods); this.calculation(newGoods);
}, }),
//减少商品 //减少商品
decreaseGood(e) { decreaseGood: throttle(2000, function(e){
let barcode = e.target.id; let barcode = e.target.id;
let lastgoods = this.data.goods; let lastgoods = this.data.goods;
...@@ -917,9 +923,9 @@ Page({ ...@@ -917,9 +923,9 @@ Page({
this.setData({ goods: newGoods }) this.setData({ goods: newGoods })
this.calculation(newGoods); this.calculation(newGoods);
}, }),
//增加商品 //增加商品
increaseGood(e) { increaseGood: throttle(2000, function(e){
console.log(e); console.log(e);
let barcode = e.target.id; let barcode = e.target.id;
let lastgoods = this.data.goods; let lastgoods = this.data.goods;
...@@ -935,7 +941,7 @@ Page({ ...@@ -935,7 +941,7 @@ Page({
}) })
this.setData({ goods: newGoods }) this.setData({ goods: newGoods })
this.calculation(newGoods); this.calculation(newGoods);
}, }),
//计算总价格 总数量 总优惠 //计算总价格 总数量 总优惠
...@@ -987,7 +993,7 @@ Page({ ...@@ -987,7 +993,7 @@ Page({
}, },
//跳转到结算等待页 //跳转到结算等待页
goPay(e) { goPay: throttle(2000, function(e){
//购物车不能为空 //购物车不能为空
if (this.data.goods.length == 0) { if (this.data.goods.length == 0) {
this.showToast("等待收银员录入商品", 3000) this.showToast("等待收银员录入商品", 3000)
...@@ -1023,9 +1029,9 @@ Page({ ...@@ -1023,9 +1029,9 @@ Page({
waitOperateCancelText: "取消收款", waitOperateCancelText: "取消收款",
waitOperateMoneyRemind: "应收款:", waitOperateMoneyRemind: "应收款:",
}); });
}, }),
waitOperateBack() { waitOperateBack: throttle(2000, function(){
//直接返回到扫码页面,并且通知前屏返回 //直接返回到扫码页面,并且通知前屏返回
if (this.data.flowType == FLOW_REFUND) { if (this.data.flowType == FLOW_REFUND) {
this.operateResultClose(); this.operateResultClose();
...@@ -1049,10 +1055,10 @@ Page({ ...@@ -1049,10 +1055,10 @@ Page({
} else if (this.data.flowType == FLOW_DIRECT_PAYMENT) { } else if (this.data.flowType == FLOW_DIRECT_PAYMENT) {
this.goHome(); this.goHome();
} }
}, }),
//等待操作页,取消付款/收款等按钮 //等待操作页,取消付款/收款等按钮
waitOperateCancel() { waitOperateCancel: throttle(2000, function(){
//todo 是否需要加上当接口在请求时,则屏蔽取消按钮的操作? //todo 是否需要加上当接口在请求时,则屏蔽取消按钮的操作?
console.log("取消操作等待页"); console.log("取消操作等待页");
...@@ -1075,10 +1081,10 @@ Page({ ...@@ -1075,10 +1081,10 @@ Page({
//直接退出到home //直接退出到home
this.goHome(); this.goHome();
} }
}, }),
//提货关闭 //提货关闭
pickGoodsClose(e) { pickGoodsClose: throttle(2000, function(e){
let context = this; let context = this;
my.ix.sendBuddyMessage({ my.ix.sendBuddyMessage({
target: getApp().globalData.frontScreenAppId, target: getApp().globalData.frontScreenAppId,
...@@ -1094,12 +1100,12 @@ Page({ ...@@ -1094,12 +1100,12 @@ Page({
console.log("关闭提货通知前屏 失败 ===》 " + JSON.stringify(fres)); console.log("关闭提货通知前屏 失败 ===》 " + JSON.stringify(fres));
} }
}) })
}, }),
//兑换券界面关闭 //兑换券界面关闭
convertCouponClose(e) { convertCouponClose: throttle(2000, function(e){
this.setData({ convertCouponState: 0 }) this.setData({ convertCouponState: 0 })
this.sendConvertCouponToFront(0) this.sendConvertCouponToFront(0)
}, }),
//发送优惠券到前屏 //发送优惠券到前屏
...@@ -1140,12 +1146,12 @@ Page({ ...@@ -1140,12 +1146,12 @@ Page({
}, },
//用券返回 //用券返回
couponBack(e) { couponBack: throttle(2000, function(e){
this.setData({ discCouponState: 0 }) this.setData({ discCouponState: 0 })
this.sendDiscCouponToFront(0) this.sendDiscCouponToFront(0)
}, }),
//使用券 //使用券
useCoupon(e) { useCoupon: throttle(2000, function(e){
if (this.data.goods.length == 0) { if (this.data.goods.length == 0) {
this.showToast("请先录入商品") this.showToast("请先录入商品")
...@@ -1157,7 +1163,7 @@ Page({ ...@@ -1157,7 +1163,7 @@ Page({
request.discCouponState = 1; request.discCouponState = 1;
request.discCouponPrice = this.data.discCouponPrice request.discCouponPrice = this.data.discCouponPrice
this.sendDiscCouponToFront(request) this.sendDiscCouponToFront(request)
}, }),
//发送退款金额.以分为单位 //发送退款金额.以分为单位
sendRefund(amount) { sendRefund(amount) {
...@@ -1232,7 +1238,7 @@ Page({ ...@@ -1232,7 +1238,7 @@ Page({
}, },
onPrintLastOrderBackClicked() { onPrintLastOrderBackClicked: throttle(2000, function(e){
//回首页 //回首页
this.setData({ this.setData({
printLastOrderIsPrintSuccess: false, printLastOrderIsPrintSuccess: false,
...@@ -1240,7 +1246,7 @@ Page({ ...@@ -1240,7 +1246,7 @@ Page({
printLastOrderPrintStatusHint: "正在打印上一单" printLastOrderPrintStatusHint: "正在打印上一单"
}); });
this.goPage('home'); this.goPage('home');
}, }),
//结果页面关闭 //结果页面关闭
operateResultClose() { operateResultClose() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment