transaction.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. __name: "transaction",
  5. setup(__props) {
  6. const transactions = 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 groupedTransactions = common_vendor.computed(() => {
  18. const groups = {};
  19. transactions.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 formatAmount = (amount) => {
  57. return amount.toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
  58. };
  59. const formatTime = (timestamp) => {
  60. const date = new Date(timestamp);
  61. const hours = String(date.getHours()).padStart(2, "0");
  62. const minutes = String(date.getMinutes()).padStart(2, "0");
  63. return `${hours}:${minutes}`;
  64. };
  65. const loadTransactions = () => {
  66. try {
  67. const storedTransactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
  68. transactions.value = storedTransactions.sort((a, b) => b.timestamp - a.timestamp);
  69. } catch (e) {
  70. console.error("加载交易记录失败:", e);
  71. transactions.value = [];
  72. }
  73. };
  74. common_vendor.onMounted(() => {
  75. loadTransactions();
  76. });
  77. return (_ctx, _cache) => {
  78. return common_vendor.e({
  79. a: common_vendor.o(handleBack),
  80. b: common_vendor.f(common_vendor.unref(groupedTransactions), (group, dateKey, i0) => {
  81. return {
  82. a: common_vendor.t(dateKey),
  83. b: common_vendor.f(group, (item, index, i1) => {
  84. return {
  85. a: common_vendor.t(item.stockName),
  86. b: common_vendor.t(item.stockCode),
  87. c: common_vendor.t(formatTime(item.timestamp)),
  88. d: common_vendor.t(item.type === "buy" ? "-" : "+"),
  89. e: common_vendor.t(formatAmount(item.totalAmount)),
  90. f: common_vendor.n(item.type === "buy" ? "amount-buy" : "amount-sell"),
  91. g: common_vendor.t(item.type === "buy" ? "买入" : "卖出"),
  92. h: common_vendor.n(item.type === "buy" ? "status-buy" : "status-sell"),
  93. i: index
  94. };
  95. }),
  96. c: dateKey
  97. };
  98. }),
  99. c: transactions.value.length === 0
  100. }, transactions.value.length === 0 ? {} : {});
  101. };
  102. }
  103. };
  104. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a901d1cb"], ["__file", "D:/program/gupiao-wx/src/pages/transaction/transaction.vue"]]);
  105. wx.createPage(MiniProgramPage);