points.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. __name: "points",
  5. setup(__props) {
  6. const records = common_vendor.ref([]);
  7. const handleBack = () => {
  8. const pages = getCurrentPages();
  9. if (pages.length > 1) {
  10. common_vendor.index.navigateBack();
  11. } else {
  12. common_vendor.index.switchTab({
  13. url: "/pages/mine/mine"
  14. });
  15. }
  16. };
  17. const groupedRecords = common_vendor.computed(() => {
  18. const groups = {};
  19. records.value.forEach((item) => {
  20. const dateKey = formatDate(item.timestamp);
  21. if (!groups[dateKey]) {
  22. groups[dateKey] = [];
  23. }
  24. groups[dateKey].push(item);
  25. });
  26. return groups;
  27. });
  28. const formatDate = (timestamp) => {
  29. const date = new Date(timestamp);
  30. const today = /* @__PURE__ */ new Date();
  31. const yesterday = new Date(today);
  32. yesterday.setDate(yesterday.getDate() - 1);
  33. const dateStr = date.toLocaleDateString("zh-CN", {
  34. year: "numeric",
  35. month: "2-digit",
  36. day: "2-digit"
  37. });
  38. const todayStr = today.toLocaleDateString("zh-CN", {
  39. year: "numeric",
  40. month: "2-digit",
  41. day: "2-digit"
  42. });
  43. const yesterdayStr = yesterday.toLocaleDateString("zh-CN", {
  44. year: "numeric",
  45. month: "2-digit",
  46. day: "2-digit"
  47. });
  48. if (dateStr === todayStr) {
  49. return "今天";
  50. } else if (dateStr === yesterdayStr) {
  51. return "昨天";
  52. } else {
  53. return dateStr;
  54. }
  55. };
  56. const formatTime = (timestamp) => {
  57. const date = new Date(timestamp);
  58. const hours = String(date.getHours()).padStart(2, "0");
  59. const minutes = String(date.getMinutes()).padStart(2, "0");
  60. return `${hours}:${minutes}`;
  61. };
  62. const loadRecords = () => {
  63. try {
  64. const storedRecords = common_vendor.index.getStorageSync("points_records") || [];
  65. records.value = storedRecords.sort((a, b) => b.timestamp - a.timestamp);
  66. } catch (e) {
  67. console.error("加载积分记录失败:", e);
  68. records.value = [];
  69. }
  70. };
  71. const initMockData = () => {
  72. const mockRecords = [
  73. {
  74. title: "每日签到",
  75. points: 10,
  76. type: "add",
  77. timestamp: Date.now() - 1e3 * 60 * 30
  78. },
  79. {
  80. title: "完成交易",
  81. points: 5,
  82. type: "add",
  83. timestamp: Date.now() - 1e3 * 60 * 60 * 2
  84. },
  85. {
  86. title: "查询股票",
  87. points: 2,
  88. type: "use",
  89. timestamp: Date.now() - 1e3 * 60 * 60 * 5
  90. },
  91. {
  92. title: "邀请好友",
  93. points: 20,
  94. type: "add",
  95. timestamp: Date.now() - 1e3 * 60 * 60 * 24
  96. },
  97. {
  98. title: "解锁超短池",
  99. points: 18,
  100. type: "use",
  101. timestamp: Date.now() - 1e3 * 60 * 60 * 24 * 2
  102. }
  103. ];
  104. if (records.value.length === 0) {
  105. records.value = mockRecords;
  106. common_vendor.index.setStorageSync("points_records", mockRecords);
  107. }
  108. };
  109. common_vendor.onMounted(() => {
  110. loadRecords();
  111. initMockData();
  112. });
  113. return (_ctx, _cache) => {
  114. return common_vendor.e({
  115. a: common_vendor.o(handleBack),
  116. b: common_vendor.f(common_vendor.unref(groupedRecords), (group, dateKey, i0) => {
  117. return {
  118. a: common_vendor.t(dateKey),
  119. b: common_vendor.f(group, (item, index, i1) => {
  120. return {
  121. a: common_vendor.t(item.title),
  122. b: common_vendor.t(formatTime(item.timestamp)),
  123. c: common_vendor.t(item.type === "add" ? "+" : "-"),
  124. d: common_vendor.t(item.points),
  125. e: common_vendor.n(item.type === "add" ? "amount-sell" : "amount-buy"),
  126. f: common_vendor.t(item.type === "add" ? "获得" : "消耗"),
  127. g: common_vendor.n(item.type === "add" ? "status-sell" : "status-buy"),
  128. h: index
  129. };
  130. }),
  131. c: dateKey
  132. };
  133. }),
  134. c: records.value.length === 0
  135. }, records.value.length === 0 ? {} : {});
  136. };
  137. }
  138. };
  139. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-9b5c2d6e"], ["__file", "D:/program/gupiao-wx/src/pages/points/points.vue"]]);
  140. wx.createPage(MiniProgramPage);