formId.js 804 B

12345678910111213141516171819202122232425262728293031323334
  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. console.log(formId);
  10. if (!formId || formId === 'the formId is a mock one') {
  11. return false;
  12. }
  13. let formIdList = getStorageSync('_FORM_ID_LIST');
  14. if (!formIdList || !formIdList.length) {
  15. formIdList = [];
  16. }
  17. const item = {
  18. value: formId,
  19. type: 0,
  20. remains: 1,
  21. expires_at: datetime(null, (time() + 7 * 86400) - 60),
  22. };
  23. formIdList.push(item);
  24. setStorageSync('_FORM_ID_LIST', formIdList);
  25. };
  26. export {
  27. popAll,
  28. push,
  29. }