Files
MiniProgram/NamingAssistant/pages/favorites/index.js
2025-11-05 00:22:09 +08:00

39 lines
979 B
JavaScript

const namingStore = require("../../store/namingStore");
function formatDisplayTime(isoString) {
if (!isoString) {
return "";
}
try {
const date = new Date(isoString);
const yyyy = date.getFullYear();
const mm = `${date.getMonth() + 1}`.padStart(2, "0");
const dd = `${date.getDate()}`.padStart(2, "0");
const hh = `${date.getHours()}`.padStart(2, "0");
const mi = `${date.getMinutes()}`.padStart(2, "0");
return `${yyyy}-${mm}-${dd} ${hh}:${mi}`;
} catch (error) {
return isoString;
}
}
Page({
data: {
favorites: []
},
onShow() {
namingStore.loadFavorites();
const { favorites } = namingStore.getState();
const enriched = favorites.map((item) => ({
...item,
displayTime: formatDisplayTime(item.createdAt)
}));
this.setData({ favorites: enriched });
},
handleDelete(event) {
const { id } = event.currentTarget.dataset;
namingStore.removeFavorite(id);
this.onShow();
}
});