取名小程序开发
This commit is contained in:
38
NamingAssistant/pages/favorites/index.js
Normal file
38
NamingAssistant/pages/favorites/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
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();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user