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
+13 -84
View File
@@ -15,12 +15,14 @@
<t-cell-group v-if="rule" title="基本信息" theme="card" v-entrance-transition="70">
<t-cell title="所属门店" :note="storeName" />
<t-cell
title="登记事件"
v-if="rule.triggerSourceType === 'EVENT_RECORD'"
title="触发事件"
:note="event?.name || '未绑定事件'"
:arrow="canReadEvent && !!event?.id"
:hover="canReadEvent && !!event?.id"
@click="toEventDetail"
/>
<t-cell v-else-if="rule.triggerSourceType === 'SALES_ORDER_PAID'" title="触发来源" note="订单首次全额实收" />
<t-cell title="规则名称" :note="rule.name || '未命名规则'" />
<t-cell title="规则状态">
<template #note>
@@ -30,26 +32,9 @@
<t-cell title="规则备注" :note="Text.display(rule.remark)" />
</t-cell-group>
<t-cell-group v-if="rule" title="积分配置" theme="card" v-entrance-transition="140">
<t-cell title="触发类型" :note="getTriggerText(rule.triggerType)" />
<t-cell title="积分值模式" :note="getModeText(rule.pointMode)" />
<t-cell v-if="rule.pointMode === 'FIXED'" title="固定积分" :note="formatPointValue(rule.pointValue)" />
<t-cell v-if="rule.pointMode === 'SOURCE_VALUE'" title="自定义积分范围" :note="sourceValueRangeText" />
<t-cell v-if="rule.triggerType === 'AFTER_COUNT_EVERY_TIME'" title="触发阈值" :note="getThresholdText(rule)" />
<t-cell v-if="rule.triggerType === 'FIRST_TIME'" title="匹配范围" note="每个客户的首次登记" />
<t-cell v-if="rule.conditionJson?.window" title="累计窗口" :note="getWindowText(rule)" />
<t-cell v-if="rule.conditionJson?.sourceEventId" title="来源事件">
<template #note>
<span v-text="sourceEvent?.name || rule.conditionJson.sourceEventId" />
</template>
</t-cell>
</t-cell-group>
<t-cell-group
v-if="tierTextList.length"
title="积分分档"
theme="card"
v-entrance-transition="210"
>
<t-cell v-for="(text, index) in tierTextList" :key="index" :title="`第 ${index + 1} 档`" :note="text" />
<t-cell title="规则模式" :note="rule.ruleMode === 'GROOVY' ? '脚本规则' : '简单规则'" />
<t-cell v-if="rule.ruleMode !== 'GROOVY'" title="固定积分" :note="formatPointValue(rule.pointValue)" />
<t-cell v-else title="执行脚本" :note="rule.groovyScriptId || '未绑定脚本'" />
</t-cell-group>
<t-cell-group v-if="rule" title="其他配置" theme="card" v-entrance-transition="280">
<t-cell title="规则优先级" :note="formatNumber(rule.priority)" />
@@ -82,8 +67,7 @@ import PointAPI from "@/api/PointAPI";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import { useNavBarStore } from "@/store/navBarStore";
import type { EventItem } from "@/types/EventItem";
import type { PointRule, PointRuleStatus, PointRuleMode, PointRuleTriggerType } from "@/types/Point";
import { formatEventNumberValue } from "@/utils/eventValue";
import type { PointRule, PointRuleStatus } from "@/types/Point";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
@@ -118,31 +102,16 @@ const storeName = computed(() => {
const rule = ref<PointRule>();
const event = ref<EventItem>();
const sourceEvent = ref<EventItem>();
const isLoading = ref(false);
const isDeleting = ref(false);
const condition = computed(() => rule.value?.conditionJson);
const isConsumeRule = computed(() => (rule.value?.pointValue ?? 0) < 0);
const rulePointText = computed(() => {
if (rule.value?.pointMode === "TIER") {
return condition.value?.tiers?.length ? `${condition.value.tiers.length} 档积分` : "分档积分";
}
if (rule.value?.pointMode === "SOURCE_VALUE") {
return "按登记时填写的积分变化";
if (rule.value?.ruleMode === "GROOVY") {
return "脚本规则";
}
return formatPointValue(rule.value?.pointValue);
});
const sourceValueRangeText = computed(() => {
const minText = condition.value?.min === undefined ? "不限" : formatPointValue(condition.value.min);
const maxText = condition.value?.max === undefined ? "不限" : formatPointValue(condition.value.max);
return `最小值:${minText};最大值:${maxText}`;
});
const tierTextList = computed(() => (condition.value?.tiers || []).map(tier => {
const minText = formatEventNumberValue(sourceEvent.value, tier.min);
const maxText = tier.max === undefined || tier.max === null ? "以上" : formatEventNumberValue(sourceEvent.value, tier.max);
return `${minText}~${maxText}:${formatPointValue(tier.pointValue)}`;
}));
async function loadStoreScope(): Promise<void> {
if (isGlobalManager.value) {
@@ -166,13 +135,11 @@ async function loadRule(): Promise<void> {
if (!ruleId) {
rule.value = undefined;
event.value = undefined;
sourceEvent.value = undefined;
return;
}
rule.value = undefined;
event.value = undefined;
sourceEvent.value = undefined;
isLoading.value = true;
try {
await loadStoreScope();
@@ -181,20 +148,13 @@ async function loadRule(): Promise<void> {
return;
}
const eventId = rule.value.eventId || "";
const sourceEventId = rule.value.conditionJson?.sourceEventId || "";
const [eventResult, sourceEventResult] = await Promise.all([
eventId ? loadOptionalEvent(eventId, "积分规则登记事件加载失败") : Promise.resolve(undefined),
sourceEventId && sourceEventId !== eventId
? loadOptionalEvent(sourceEventId, "积分规则来源事件加载失败")
: Promise.resolve(undefined)
]);
event.value = eventResult;
sourceEvent.value = sourceEventResult || (sourceEventId === eventId ? eventResult : undefined);
const triggerRefId = rule.value.triggerRefId || "";
event.value = triggerRefId && rule.value.triggerSourceType === "EVENT_RECORD"
? await loadOptionalEvent(triggerRefId, "积分规则触发事件加载失败")
: undefined;
} catch (error) {
rule.value = undefined;
event.value = undefined;
sourceEvent.value = undefined;
console.warn("积分规则详情加载失败", error);
Message.error("积分规则加载失败");
} finally {
@@ -226,24 +186,6 @@ function getStatusTheme(status?: PointRuleStatus): "default" | "success" | "warn
return "default";
}
function getTriggerText(triggerType?: PointRuleTriggerType): string {
return ({
EVERY_TIME: "每次登记",
FIRST_TIME: "首次登记",
AFTER_COUNT_EVERY_TIME: "达到阈值后每次登记",
SOURCE_VALUE: "登记时自定义积分",
CUSTOMER_EVENT_VALUE_TIER: "按来源事件累计分档"
} as Record<string, string>)[triggerType || ""] || "未知触发类型";
}
function getModeText(pointMode?: PointRuleMode): string {
return ({
FIXED: "固定积分",
SOURCE_VALUE: "使用登记时填写的积分",
TIER: "分档积分"
} as Record<string, string>)[pointMode || ""] || "未知积分模式";
}
function formatPointValue(value?: number | null): string {
if (value === undefined || value === null) {
return "未配置";
@@ -254,19 +196,6 @@ function formatPointValue(value?: number | null): string {
return `${0 < value ? "发放" : "消耗"} ${Math.abs(value)} 分`;
}
function getThresholdText(value: PointRule): string {
const threshold = value.conditionJson?.threshold;
return threshold === undefined || threshold === null ? "未配置" : `${threshold} 次`;
}
function getWindowText(value: PointRule): string {
const window = value.conditionJson?.window;
if (!window) {
return "未配置";
}
return `${window.amount} ${window.unit === "YEAR" ? "年" : window.unit}`;
}
function formatNumber(value?: number): string {
return value === undefined || value === null ? "未配置" : String(value);
}