Common.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // 处理多次点击
  2. function noMultipleClicks(methods) {
  3. //复制this对象指向当时的this,防止找不到原来的对象
  4. let that = this;
  5. if (that.noClick) {
  6. that.noClick = false;
  7. //点击方法
  8. methods();
  9. setTimeout(function() {
  10. that.noClick = true;
  11. }, 2000)
  12. } else {
  13. uni.$showMsg('正在加载中', 500)
  14. }
  15. }
  16. //获取胶囊位置信息
  17. function getCapsuleSite() {
  18. let res = uni.getMenuButtonBoundingClientRect()
  19. this.capsuleBottom = res.bottom + 5
  20. this.capsuleMiddle = res.left
  21. this.capsuleWidth = res.width
  22. }
  23. //处理更新时间
  24. function getTimeStamp() {
  25. this.timeStamp = (new Date()).format("hh:mm")
  26. }
  27. //获取近几天时间数组
  28. function getRecentDateArray(day) {
  29. let recentDate = new Array();
  30. for (let i = day; i > 0; i--) {
  31. let dayTime = new Date();
  32. dayTime.setDate(dayTime.getDate() - i + 1);
  33. recentDate.push(dayTime.format("MM-dd"));
  34. }
  35. return recentDate
  36. }
  37. //导出并在Main.js中全局注册
  38. export default {
  39. noMultipleClicks, //禁止多次点击
  40. getCapsuleSite, //获取胶囊位置信息
  41. getTimeStamp, //处理更新时间
  42. getRecentDateArray //获取近几天时间数组
  43. }