mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
feat: 添加积分兑换通知功能;优化通知处理逻辑;更新设置以支持新通知类型
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
import { QAInfo } from "@/api/api-models";
|
||||
import { QAInfo, ResponsePointGoodModel, ResponsePointOrder2OwnerModel } from "@/api/api-models";
|
||||
import { useSettings } from "../store/useSettings";
|
||||
import { isPermissionGranted, onAction, sendNotification } from "@tauri-apps/plugin-notification";
|
||||
import { isPermissionGranted, onAction, Options, sendNotification } from "@tauri-apps/plugin-notification";
|
||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
||||
import { CN_HOST } from "@/data/constants";
|
||||
import { NButton, NFlex } from "naive-ui";
|
||||
import QuestionItem from "@/components/QuestionItem.vue";
|
||||
|
||||
export function onReceivedNotification(type: string, data: any) {
|
||||
export async function trySendNotification(option: Options) {
|
||||
let permissionGranted = await isPermissionGranted();
|
||||
if (permissionGranted) {
|
||||
sendNotification(option);
|
||||
}
|
||||
}
|
||||
|
||||
export function onReceivedNotification(type: string, json: string) {
|
||||
console.log(`接收到通知: ${type}`, json);
|
||||
const data = JSON.parse(json);
|
||||
switch (type) {
|
||||
case 'question-box':
|
||||
|
||||
onReceivedQuestion(data);
|
||||
break;
|
||||
|
||||
case 'goods-buy':
|
||||
onGoodsBuy(data);
|
||||
break;
|
||||
default:
|
||||
console.warn(`Unhandled notification type: ${type}`);
|
||||
}
|
||||
@@ -20,20 +32,57 @@ export async function onReceivedQuestion(question: QAInfo) {
|
||||
const setting = useSettings();
|
||||
if (setting.settings.notificationSettings.enableTypes.includes("question-box")) {
|
||||
window.$notification.info({
|
||||
title: "收到提问",
|
||||
description: '收到来自 [' + question.sender.name || '匿名用户' + '] 的提问',
|
||||
duration: 5,
|
||||
title: "提问箱",
|
||||
description: '收到来自 [' + (question.sender.name || '匿名用户') + '] 的提问',
|
||||
duration: 0,
|
||||
action: () => h(NFlex, {}, () => [
|
||||
h(NButton, {
|
||||
text: true, type: 'info', onClick: () => {
|
||||
window.$modal.create({
|
||||
title: '快速查看',
|
||||
preset: 'card',
|
||||
style: { maxWidth: '80vw' },
|
||||
content: () => h(QuestionItem, { item: question }),
|
||||
});
|
||||
}
|
||||
}, () => '快速查看'),
|
||||
h(NButton, {
|
||||
text: true, type: 'primary', onClick: () => {
|
||||
openUrl(`${CN_HOST}manage/question-box`);
|
||||
}
|
||||
}, () => '查看详情'),
|
||||
])
|
||||
});
|
||||
trySendNotification({
|
||||
title: "提问箱",
|
||||
body: '收到来自 [' + (question.sender.name || '匿名用户') + '] 的提问',
|
||||
extra: { type: 'question-box' },
|
||||
});
|
||||
let permissionGranted = await isPermissionGranted();
|
||||
if (permissionGranted) {
|
||||
sendNotification({
|
||||
title: "收到提问",
|
||||
body: '来自 [' + question.sender.name || '匿名用户' + '] 的提问',
|
||||
silent: false,
|
||||
extra: { type: 'question-box' },
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function onGoodsBuy(info: {
|
||||
data: ResponsePointOrder2OwnerModel,
|
||||
goods: ResponsePointGoodModel
|
||||
}) {
|
||||
const setting = useSettings();
|
||||
const order = info.data;
|
||||
const goods = info.goods;
|
||||
if (setting.settings.notificationSettings.enableTypes.includes("goods-buy")) {
|
||||
window.$notification.info({
|
||||
title: "礼物兑换",
|
||||
description: `${order.customer.name} 兑换了你的 [${goods.name}],数量: ${order.count},总价: ${order.point} 元`,
|
||||
duration: 0,
|
||||
action: () => h(NButton, {
|
||||
text: true, type: 'primary', onClick: () => {
|
||||
openUrl(`${CN_HOST}manage/goods-buy`);
|
||||
}
|
||||
}, () => '查看详情'),
|
||||
});
|
||||
trySendNotification({
|
||||
title: "礼物兑换",
|
||||
body: `${order.customer.name} 兑换了你的 [${goods.name}],数量: ${order.count},总价: ${order.point} 元`,
|
||||
extra: { type: 'goods-buy' },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user