mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-06 18:36:55 +08:00
- 在 .editorconfig 中调整文件格式设置,统一代码风格。 - 在 default.d.ts 中为 naive-ui 添加 TabPaneSlots 接口声明,增强类型支持。 - 在多个组件中优化了模板和样式,提升用户交互体验。 - 在 ClientAutoAction.vue 中新增签到设置标签页,丰富功能选项。 - 在 Utils.ts 中增强 GUID 处理逻辑,增加输入验证和错误处理。 - 更新多个组件的逻辑,简化代码结构,提升可读性和维护性。
95 lines
2.9 KiB
TypeScript
95 lines
2.9 KiB
TypeScript
import { ResponsePointGoodModel } from "@/api/api-models";
|
||
import { QueryGetAPI } from "@/api/query";
|
||
import { POINT_API_URL } from "@/data/constants";
|
||
import { MessageApiInjection } from "naive-ui/es/message/src/MessageProvider";
|
||
import { defineStore } from "pinia";
|
||
import { useAuthStore } from "./useAuthStore";
|
||
import { GuidUtils } from "@/Utils";
|
||
|
||
export const usePointStore = defineStore('point', () => {
|
||
const useAuth = useAuthStore()
|
||
|
||
async function GetSpecificPoint(id: number) {
|
||
try {
|
||
const data = await useAuth.QueryBiliAuthGetAPI<number>(POINT_API_URL + 'user/get-point', { id: id })
|
||
if (data.code == 200) {
|
||
return data.data
|
||
} else {
|
||
console.error('[point] 无法获取在指定直播间拥有的积分: ' + data.message)
|
||
}
|
||
} catch (err) {
|
||
console.error('[point] 无法获取在指定直播间拥有的积分: ' + err)
|
||
}
|
||
return null
|
||
}
|
||
async function GetGoods(id: number | undefined = undefined, message?: MessageApiInjection) {
|
||
if (!id) {
|
||
return []
|
||
}
|
||
try {
|
||
const resp = await QueryGetAPI<ResponsePointGoodModel[]>(POINT_API_URL + 'get-goods', {
|
||
id: id,
|
||
})
|
||
if (resp.code == 200) {
|
||
return resp.data
|
||
} else {
|
||
message?.error('无法获取数据: ' + resp.message)
|
||
console.error('无法获取数据: ' + resp.message)
|
||
}
|
||
} catch (err) {
|
||
message?.error('无法获取数据: ' + err)
|
||
console.error('无法获取数据: ' + err)
|
||
}
|
||
return []
|
||
}
|
||
/**
|
||
* 给用户添加或扣除积分
|
||
* @param userId 用户ID
|
||
* @param count 积分数量(正数为增加,负数为减少)
|
||
* @param reason 积分变动原因
|
||
* @param remark 备注信息
|
||
* @returns 成功时返回修改后的积分值,失败时返回null
|
||
*/
|
||
async function addPoints(userId: string, count: number, reason: string, remark?: string) {
|
||
if (count === 0) {
|
||
console.warn('[point] 积分变动数量不能为0');
|
||
return null;
|
||
}
|
||
|
||
try {
|
||
// 根据用户ID构建参数
|
||
const params: Record<string, any> = GuidUtils.isGuidFromUserId(userId) ? {
|
||
uId: GuidUtils.guidToLong(userId),
|
||
count: count,
|
||
reason: reason || '',
|
||
} : {
|
||
oid: userId,
|
||
count: count,
|
||
reason: reason || '',
|
||
};
|
||
|
||
if (remark) {
|
||
params.remark = remark;
|
||
}
|
||
|
||
const data = await QueryGetAPI<number>(POINT_API_URL + 'give-point', params);
|
||
|
||
if (data.code === 200) {
|
||
console.log(`[point] 用户 ${userId} 积分${count > 0 ? '增加' : '减少'} ${Math.abs(count)} 成功,当前积分:${data.data}`);
|
||
return data.data; // 返回修改后的积分值
|
||
} else {
|
||
console.error('[point] 积分操作失败:', data.message);
|
||
return null;
|
||
}
|
||
} catch (err) {
|
||
console.error('[point] 积分操作出错:', err);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
return {
|
||
GetSpecificPoint,
|
||
GetGoods,
|
||
addPoints
|
||
}
|
||
}) |