| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const _sfc_main = {
- __name: "transaction",
- setup(__props) {
- const transactions = common_vendor.ref([]);
- const handleBack = () => {
- const pages = getCurrentPages();
- if (pages.length > 1) {
- common_vendor.index.navigateBack();
- } else {
- common_vendor.index.switchTab({
- url: "/pages/mine/mine"
- });
- }
- };
- const groupedTransactions = common_vendor.computed(() => {
- const groups = {};
- transactions.value.forEach((item) => {
- const dateKey = formatDate(item.timestamp);
- if (!groups[dateKey]) {
- groups[dateKey] = [];
- }
- groups[dateKey].push(item);
- });
- return groups;
- });
- const formatDate = (timestamp) => {
- const date = new Date(timestamp);
- const today = /* @__PURE__ */ new Date();
- const yesterday = new Date(today);
- yesterday.setDate(yesterday.getDate() - 1);
- const dateStr = date.toLocaleDateString("zh-CN", {
- year: "numeric",
- month: "2-digit",
- day: "2-digit"
- });
- const todayStr = today.toLocaleDateString("zh-CN", {
- year: "numeric",
- month: "2-digit",
- day: "2-digit"
- });
- const yesterdayStr = yesterday.toLocaleDateString("zh-CN", {
- year: "numeric",
- month: "2-digit",
- day: "2-digit"
- });
- if (dateStr === todayStr) {
- return "今天";
- } else if (dateStr === yesterdayStr) {
- return "昨天";
- } else {
- return dateStr;
- }
- };
- const formatAmount = (amount) => {
- return amount.toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
- };
- const formatTime = (timestamp) => {
- const date = new Date(timestamp);
- const hours = String(date.getHours()).padStart(2, "0");
- const minutes = String(date.getMinutes()).padStart(2, "0");
- return `${hours}:${minutes}`;
- };
- const loadTransactions = () => {
- try {
- const storedTransactions = common_vendor.index.getStorageSync("simulated_transactions") || [];
- transactions.value = storedTransactions.sort((a, b) => b.timestamp - a.timestamp);
- } catch (e) {
- console.error("加载交易记录失败:", e);
- transactions.value = [];
- }
- };
- common_vendor.onMounted(() => {
- loadTransactions();
- });
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: common_vendor.o(handleBack),
- b: common_vendor.f(common_vendor.unref(groupedTransactions), (group, dateKey, i0) => {
- return {
- a: common_vendor.t(dateKey),
- b: common_vendor.f(group, (item, index, i1) => {
- return {
- a: common_vendor.t(item.stockName),
- b: common_vendor.t(item.stockCode),
- c: common_vendor.t(formatTime(item.timestamp)),
- d: common_vendor.t(item.type === "buy" ? "-" : "+"),
- e: common_vendor.t(formatAmount(item.totalAmount)),
- f: common_vendor.n(item.type === "buy" ? "amount-buy" : "amount-sell"),
- g: common_vendor.t(item.type === "buy" ? "买入" : "卖出"),
- h: common_vendor.n(item.type === "buy" ? "status-buy" : "status-sell"),
- i: index
- };
- }),
- c: dateKey
- };
- }),
- c: transactions.value.length === 0
- }, transactions.value.length === 0 ? {} : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a901d1cb"], ["__file", "D:/program/gupiao-wx/src/pages/transaction/transaction.vue"]]);
- wx.createPage(MiniProgramPage);
|