update permission and product

This commit is contained in:
Timi
2026-09-04 23:07:59 +08:00
parent 1df5748f54
commit fc9e6a5023
48 changed files with 1670 additions and 2475 deletions
+9 -74
View File
@@ -62,10 +62,8 @@
<t-cell-group title="命中规则" theme="card" v-entrance-transition="350">
<template v-if="hitRule">
<t-cell title="规则名称" :note="hitRule.name || '未命名规则'" />
<t-cell title="触发类型" :note="getTriggerTypeText(hitRule.triggerType)" />
<t-cell title="积分模式" :note="getPointModeText(hitRule.pointMode)" />
<t-cell title="规则模式" :note="hitRule.ruleMode === 'GROOVY' ? '脚本规则' : '简单规则'" />
<t-cell title="规则积分" :note="getRulePointText(hitRule)" />
<t-cell title="匹配条件" :note="getRuleConditionText(hitRule)" />
<t-cell title="规则状态" :note="getRuleStatusText(hitRule.status)" />
<t-cell title="规则优先级" :note="getPointText(hitRule.priority)" />
<t-cell title="命中后停止匹配" :note="hitRule.exclusive ? '是' : '否'" />
@@ -90,7 +88,7 @@ import CustomerProfileCard from "@/components/CustomerProfileCard.vue";
import type { Customer } from "@/types/Customer";
import type { EventItem } from "@/types/EventItem";
import type { EventRecord } from "@/types/EventRecord";
import type { PointLedger, PointRule, PointRuleMode, PointRuleStatus, PointRuleTriggerType } from "@/types/Point";
import type { PointLedger, PointRule, PointRuleStatus } from "@/types/Point";
import { formatEventNumberValue, getEventValueUnitText } from "@/utils/eventValue";
import { permissionCodes } from "@/utils/permission";
@@ -115,7 +113,6 @@ const canReadRule = computed(() => userStore.hasPermissions(permissionCodes.poin
const ledger = ref<PointLedger>();
const customer = ref<Customer>();
const triggerEvent = ref<EventItem>();
const sourceEvent = ref<EventItem>();
const eventRecord = ref<EventRecord>();
const hitRule = ref<PointRule>();
const isLoading = ref(false);
@@ -126,10 +123,7 @@ const hasEarnedPointValue = computed(() => eventRecord.value?.earnedPointValue !
const isDeletedEventRevoke = computed(() => isDeletedEventRevokeLedger(ledger.value));
function isDeletedEventRevokeLedger(value?: PointLedger): boolean {
const idempotencyKey = value?.idempotencyKey || "";
return value?.changeType === "REVOKE"
&& idempotencyKey.startsWith("GAO_EVENT_RECORD:")
&& idempotencyKey.endsWith(":REVOKE");
return value?.changeType === "REVOKE" && value?.triggerSourceType === "EVENT_RECORD" && !value.triggerSourceId;
}
function getQueryText(key: string): string {
@@ -171,7 +165,6 @@ async function loadPageData(): Promise<void> {
ledger.value = parseLedgerSnapshot();
customer.value = undefined;
triggerEvent.value = undefined;
sourceEvent.value = undefined;
eventRecord.value = undefined;
hitRule.value = undefined;
if (!ledger.value) {
@@ -180,11 +173,12 @@ async function loadPageData(): Promise<void> {
isLoading.value = true;
try {
if (ledger.value.eventRecordId && canReadEventRecord.value && !isDeletedEventRevoke.value) {
eventRecord.value = await loadOptional(() => EventRecordAPI.detail(ledger.value!.eventRecordId!), "积分流水关联事件记录加载失败");
if (ledger.value.triggerSourceType === "EVENT_RECORD" && ledger.value.triggerSourceId && canReadEventRecord.value && !isDeletedEventRevoke.value) {
eventRecord.value = await loadOptional(() => EventRecordAPI.detail(ledger.value!.triggerSourceId!), "积分流水关联事件记录加载失败");
}
const eventId = eventRecord.value?.eventId || ledger.value.eventId;
const eventId = eventRecord.value?.eventId
|| (ledger.value.triggerSourceType === "EVENT_RECORD" ? ledger.value.triggerSourceId : "");
const eventResult = eventRecord.value?.event
? Promise.resolve(eventRecord.value.event)
: eventId && canReadEvent.value
@@ -201,11 +195,6 @@ async function loadPageData(): Promise<void> {
if (eventRecord.value?.customer) {
customer.value = eventRecord.value.customer;
}
const sourceEventId = hitRule.value?.conditionJson?.sourceEventId;
if (sourceEventId && sourceEventId !== eventId && canReadEvent.value) {
sourceEvent.value = await loadOptional(() => EventAPI.detail(sourceEventId), "积分规则来源事件加载失败");
}
} finally {
isLoading.value = false;
}
@@ -255,27 +244,9 @@ function getEventNumberValueText(): string {
return formatEventNumberValue(eventRecord.value?.event || triggerEvent.value, eventRecord.value?.numberValue);
}
function getTriggerTypeText(triggerType?: PointRuleTriggerType): string {
return ({
EVERY_TIME: "每次登记",
FIRST_TIME: "首次登记",
AFTER_COUNT_EVERY_TIME: "达到阈值后每次登记",
SOURCE_VALUE: "登记时自定义积分",
CUSTOMER_EVENT_VALUE_TIER: "按来源事件累计分档"
} as Record<string, string>)[triggerType || ""] || "未知触发类型";
}
function getPointModeText(pointMode?: PointRuleMode): string {
return ({
FIXED: "固定积分",
SOURCE_VALUE: "使用登记时填写的积分",
TIER: "分档积分"
} as Record<string, string>)[pointMode || ""] || "未知积分模式";
}
function getRulePointText(rule: PointRule): string {
if (rule.pointMode === "TIER") {
return rule.conditionJson?.tiers?.length ? `${rule.conditionJson.tiers.length} 档` : "分档积分";
if (rule.ruleMode === "GROOVY") {
return "由脚本决定";
}
if (rule.pointValue === undefined || rule.pointValue === null) {
return "-";
@@ -283,42 +254,6 @@ function getRulePointText(rule: PointRule): string {
return `${0 < rule.pointValue ? "发放" : "消耗"} ${Math.abs(rule.pointValue)} 分`;
}
function getRuleConditionText(rule: PointRule): string {
const condition = rule.conditionJson;
if (!condition) {
return "无额外条件";
}
const textList: string[] = [];
if (condition.min !== undefined || condition.max !== undefined) {
textList.push(`数值范围 ${condition.min ?? "不限"}~${condition.max ?? "不限"}`);
}
if (condition.threshold !== undefined) {
textList.push(`累计达到 ${condition.threshold} 次`);
}
if (condition.includeCurrent !== undefined) {
textList.push(condition.includeCurrent ? "包含本次登记" : "不含本次登记");
}
if (condition.window) {
textList.push(`累计窗口 ${condition.window.amount} ${condition.window.unit === "YEAR" ? "年" : condition.window.unit}`);
}
if (condition.sourceEventId) {
textList.push(`来源事件:${sourceEvent.value?.name || sourceEvent.value?.id || condition.sourceEventId}`);
}
if (condition.tiers?.length) {
const tierSourceEvent = sourceEvent.value || (condition.sourceEventId === triggerEvent.value?.id ? triggerEvent.value : undefined);
textList.push(condition.tiers.map(tier => {
const minText = formatEventNumberValue(tierSourceEvent, tier.min);
const maxText = tier.max === undefined || tier.max === null ? "以上" : formatEventNumberValue(tierSourceEvent, tier.max);
const pointText = tier.pointValue === 0
? "不产生积分流水"
: `${0 < tier.pointValue ? "发放" : "消耗"} ${Math.abs(tier.pointValue)} 分`;
return `${minText}~${maxText}:${pointText}`;
}).join(","));
}
return textList.join(";") || "无额外条件";
}
function getRuleStatusText(status?: PointRuleStatus): string {
return ({
DRAFT: "草稿",