formId.js 779 B

123456789101112131415161718192021222324252627282930313233
  1. import { datetime, time } from './utils.js';
  2. import { getStorageSync, setStorageSync } from './cache.js';
  3. const popAll = function() {
  4. const formIdList = getStorageSync('_FORM_ID_LIST');
  5. setStorageSync('_FORM_ID_LIST', []);
  6. return formIdList || [];
  7. };
  8. const push = function(formId) {
  9. if (!formId || formId === 'the formId is a mock one') {
  10. return false;
  11. }
  12. let formIdList = getStorageSync('_FORM_ID_LIST');
  13. if (!formIdList || !formIdList.length) {
  14. formIdList = [];
  15. }
  16. const item = {
  17. value: formId,
  18. type: 0,
  19. remains: 1,
  20. expires_at: datetime(null, (time() + 7 * 86400) - 60),
  21. };
  22. formIdList.push(item);
  23. setStorageSync('_FORM_ID_LIST', formIdList);
  24. };
  25. export {
  26. popAll,
  27. push,
  28. }