acdr-ui/dist/dev/mp-weixin/pages/message/message-list.js

89 lines
3.0 KiB
JavaScript

"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const common_vendor = require("../../common/vendor.js");
const utils_strings = require("../../utils/strings.js");
const utils_http = require("../../utils/http.js");
const utils_commUtils = require("../../utils/commUtils.js");
const store_message = require("../../store/message.js");
if (!Array) {
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
_component_layout_default_uni();
}
if (!Math) {
EmptyState();
}
const EmptyState = () => "../../components/EmptyState.js";
const _sfc_main = {
__name: "message-list",
setup(__props) {
const messages = common_vendor.ref([]);
const useMessage = store_message.useMessageStore();
const messageList = () => __async(this, null, function* () {
var _a;
try {
const res = yield utils_http.httpGet("/notifications/list");
if (res.code == 200) {
messages.value = res.data;
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "消息请求失败");
}
});
const markAllAsRead = () => __async(this, null, function* () {
var _a;
try {
const messageIdList = useMessage.messages.unreadMessages.map((item) => item.id);
const res = yield utils_http.httpPost("/notifications/readList", messageIdList);
if (res.code == 200) {
} else {
utils_commUtils.toast(res.message);
}
} catch (e) {
utils_commUtils.toast(((_a = e.data) == null ? void 0 : _a.message) || "消息阅读失败");
}
});
common_vendor.onLoad(() => __async(this, null, function* () {
yield messageList();
yield markAllAsRead();
}));
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(messages).length > 0
}, common_vendor.unref(messages).length > 0 ? {
b: common_vendor.f(common_vendor.unref(messages), (message, k0, i0) => {
return {
a: common_vendor.t(message.title),
b: common_vendor.t(message.createTime),
c: common_vendor.t(common_vendor.unref(utils_strings.truncateString)(message.content)),
d: message.id
};
})
} : {});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6ab77851"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=message-list.js.map