189 lines
6.3 KiB
JavaScript
189 lines
6.3 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const common_assets = require("../../common/assets.js");
|
||
const _sfc_main = {
|
||
data() {
|
||
return {
|
||
activeTab: "all",
|
||
loading: false,
|
||
notificationList: [
|
||
{
|
||
id: 1,
|
||
type: "system",
|
||
title: "系统升级通知",
|
||
content: "我们将于今晚22:00-24:00进行系统维护升级,届时部分功能可能无法使用,请提前做好安排。",
|
||
time: Date.now() - 1e3 * 60 * 5,
|
||
isRead: false
|
||
},
|
||
{
|
||
id: 2,
|
||
type: "activity",
|
||
title: "限时优惠活动",
|
||
content: "新用户首单立减50元,活动时间有限,快来参与吧!",
|
||
time: Date.now() - 1e3 * 60 * 60 * 2,
|
||
isRead: false
|
||
},
|
||
{
|
||
id: 3,
|
||
type: "service",
|
||
title: "预约成功提醒",
|
||
content: "您的机票预约已成功提交,工作人员将在24小时内与您联系确认。",
|
||
time: Date.now() - 1e3 * 60 * 60 * 24,
|
||
isRead: true
|
||
},
|
||
{
|
||
id: 4,
|
||
type: "system",
|
||
title: "账户安全提醒",
|
||
content: "检测到您的账户在新设备登录,如非本人操作请及时修改密码。",
|
||
time: Date.now() - 1e3 * 60 * 60 * 24 * 2,
|
||
isRead: true
|
||
},
|
||
{
|
||
id: 5,
|
||
type: "service",
|
||
title: "服务完成通知",
|
||
content: "您预约的酒店服务已完成,感谢您的使用,期待再次为您服务!",
|
||
time: Date.now() - 1e3 * 60 * 60 * 24 * 3,
|
||
isRead: true
|
||
}
|
||
]
|
||
};
|
||
},
|
||
computed: {
|
||
filteredList() {
|
||
if (this.activeTab === "all") {
|
||
return this.notificationList;
|
||
}
|
||
return this.notificationList.filter((item) => item.type === this.activeTab);
|
||
},
|
||
unreadCount() {
|
||
const counts = {
|
||
all: 0,
|
||
system: 0,
|
||
activity: 0,
|
||
service: 0
|
||
};
|
||
this.notificationList.forEach((item) => {
|
||
if (!item.isRead) {
|
||
counts.all++;
|
||
counts[item.type]++;
|
||
}
|
||
});
|
||
return counts;
|
||
}
|
||
},
|
||
methods: {
|
||
back() {
|
||
common_vendor.index.navigateBack({
|
||
delta: 1
|
||
});
|
||
},
|
||
switchTab(tab) {
|
||
this.activeTab = tab;
|
||
},
|
||
getTypeIcon(type) {
|
||
const icons = {
|
||
system: "/static/ic_notice.png",
|
||
activity: "/static/hot_server.png",
|
||
service: "/static/customer_service.png"
|
||
};
|
||
return icons[type] || "/static/ic_notice.png";
|
||
},
|
||
formatTime(timestamp) {
|
||
const now = Date.now();
|
||
const diff = now - timestamp;
|
||
const minutes = Math.floor(diff / (1e3 * 60));
|
||
const hours = Math.floor(diff / (1e3 * 60 * 60));
|
||
const days = Math.floor(diff / (1e3 * 60 * 60 * 24));
|
||
if (minutes < 1)
|
||
return this.$t("notification.justNow");
|
||
if (minutes < 60)
|
||
return this.$t("notification.minutesAgo").replace("{n}", minutes);
|
||
if (hours < 24)
|
||
return this.$t("notification.hoursAgo").replace("{n}", hours);
|
||
return this.$t("notification.daysAgo").replace("{n}", days);
|
||
},
|
||
readNotification(item) {
|
||
item.isRead = true;
|
||
},
|
||
markAllRead() {
|
||
this.notificationList.forEach((item) => {
|
||
item.isRead = true;
|
||
});
|
||
common_vendor.index.showToast({
|
||
title: this.$t("common.success"),
|
||
icon: "success"
|
||
});
|
||
},
|
||
loadMore() {
|
||
}
|
||
}
|
||
};
|
||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||
return common_vendor.e({
|
||
a: common_assets._imports_0,
|
||
b: common_vendor.o((...args) => $options.back && $options.back(...args)),
|
||
c: common_vendor.t(_ctx.$t("me.notification")),
|
||
d: common_vendor.t(_ctx.$t("notification.markAllRead")),
|
||
e: common_vendor.o((...args) => $options.markAllRead && $options.markAllRead(...args)),
|
||
f: common_vendor.t(_ctx.$t("notification.all")),
|
||
g: $data.activeTab === "all" ? 1 : "",
|
||
h: $options.unreadCount.all > 0
|
||
}, $options.unreadCount.all > 0 ? {
|
||
i: common_vendor.t($options.unreadCount.all)
|
||
} : {}, {
|
||
j: $data.activeTab === "all" ? 1 : "",
|
||
k: common_vendor.o(($event) => $options.switchTab("all")),
|
||
l: common_vendor.t(_ctx.$t("notification.system")),
|
||
m: $data.activeTab === "system" ? 1 : "",
|
||
n: $options.unreadCount.system > 0
|
||
}, $options.unreadCount.system > 0 ? {
|
||
o: common_vendor.t($options.unreadCount.system)
|
||
} : {}, {
|
||
p: $data.activeTab === "system" ? 1 : "",
|
||
q: common_vendor.o(($event) => $options.switchTab("system")),
|
||
r: common_vendor.t(_ctx.$t("notification.activity")),
|
||
s: $data.activeTab === "activity" ? 1 : "",
|
||
t: $options.unreadCount.activity > 0
|
||
}, $options.unreadCount.activity > 0 ? {
|
||
v: common_vendor.t($options.unreadCount.activity)
|
||
} : {}, {
|
||
w: $data.activeTab === "activity" ? 1 : "",
|
||
x: common_vendor.o(($event) => $options.switchTab("activity")),
|
||
y: common_vendor.t(_ctx.$t("notification.service")),
|
||
z: $data.activeTab === "service" ? 1 : "",
|
||
A: $options.unreadCount.service > 0
|
||
}, $options.unreadCount.service > 0 ? {
|
||
B: common_vendor.t($options.unreadCount.service)
|
||
} : {}, {
|
||
C: $data.activeTab === "service" ? 1 : "",
|
||
D: common_vendor.o(($event) => $options.switchTab("service")),
|
||
E: common_vendor.f($options.filteredList, (item, k0, i0) => {
|
||
return common_vendor.e({
|
||
a: common_vendor.t(item.title),
|
||
b: !item.isRead
|
||
}, !item.isRead ? {} : {}, {
|
||
c: common_vendor.t(item.content),
|
||
d: common_vendor.t($options.formatTime(item.time)),
|
||
e: !item.isRead ? 1 : "",
|
||
f: item.id,
|
||
g: common_vendor.o(($event) => $options.readNotification(item), item.id)
|
||
});
|
||
}),
|
||
F: $data.loading
|
||
}, $data.loading ? {
|
||
G: common_vendor.t(_ctx.$t("common.loading"))
|
||
} : {}, {
|
||
H: $options.filteredList.length === 0 && !$data.loading
|
||
}, $options.filteredList.length === 0 && !$data.loading ? {
|
||
I: common_assets._imports_1,
|
||
J: common_vendor.t(_ctx.$t("notification.noNotification"))
|
||
} : {}, {
|
||
K: common_vendor.o((...args) => $options.loadMore && $options.loadMore(...args))
|
||
});
|
||
}
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||
wx.createPage(MiniProgramPage);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/me/notification-page.js.map
|