This commit is contained in:
zhx 2026-05-20 12:01:58 +08:00
parent 045a8af46f
commit 6375b45f3a
2 changed files with 59 additions and 15 deletions

View File

@ -20,14 +20,21 @@ import {
defineOptions({ name: 'OperatePropsSourceSelectDrawer' });
type SourceTypeOption = {
label: string;
value: string;
};
const props = withDefaults(
defineProps<{
defaultType?: string;
open: boolean;
sysOrigin: string;
typeOptions?: SourceTypeOption[];
}>(),
{
defaultType: 'AVATAR_FRAME',
typeOptions: undefined,
},
);
@ -36,11 +43,6 @@ const emit = defineEmits<{
select: [item: SourceItem];
}>();
type SourceTypeOption = {
label: string;
value: string;
};
type SourceItem = {
amount?: number | string;
cover?: string;
@ -62,12 +64,21 @@ const TYPE_OPTIONS: SourceTypeOption[] = [
{ label: '聊天气泡', value: 'CHAT_BUBBLE' },
{ label: '飘窗', value: 'FLOAT_PICTURE' },
{ label: '碎片', value: 'FRAGMENTS' },
{ label: '资料卡', value: 'DATA_CARD' },
];
const typeSelectOptions = TYPE_OPTIONS.map((item) => ({
label: item.label,
value: item.value as any,
}));
const effectiveTypeOptions = computed(() =>
(props.typeOptions && props.typeOptions.length > 0 ? props.typeOptions : TYPE_OPTIONS).map(
(item) => ({
label: item.label,
value: item.value as any,
}),
),
);
const allowedTypeSet = computed(
() => new Set(effectiveTypeOptions.value.map((item) => String(item.value))),
);
const loading = ref(false);
const keyword = ref('');
@ -197,13 +208,21 @@ function formatSourcePrice(amount: number | string | undefined) {
return `${amount} 金币`;
}
function resolveSourceType(type?: string) {
const value = String(type || '').trim();
if (value && allowedTypeSet.value.has(value)) {
return value;
}
return String(effectiveTypeOptions.value[0]?.value || 'AVATAR_FRAME');
}
watch(
() => props.open,
(open) => {
if (!open) {
return;
}
query.propsType = props.defaultType || 'AVATAR_FRAME';
query.propsType = resolveSourceType(props.defaultType);
keyword.value = '';
void loadSource(query.propsType);
},
@ -213,14 +232,26 @@ watch(
watch(
() => props.defaultType,
(value) => {
if (!props.open || !value) {
if (!props.open) {
return;
}
query.propsType = value;
void loadSource(value);
query.propsType = resolveSourceType(value);
void loadSource(query.propsType);
},
);
watch(
() => props.typeOptions,
() => {
if (!props.open) {
return;
}
query.propsType = resolveSourceType(query.propsType || props.defaultType);
void loadSource(query.propsType);
},
{ deep: true },
);
watch(
() => props.sysOrigin,
() => {
@ -327,7 +358,7 @@ function handleSelect(item: SourceItem) {
<Space class="toolbar" wrap>
<Select
v-model:value="query.propsType"
:options="typeSelectOptions"
:options="effectiveTypeOptions"
option-label-prop="label"
placeholder="请选择道具类型"
style="width: 220px"

View File

@ -70,6 +70,18 @@ const REWARD_TYPE_OPTIONS = [
{ label: '金币', value: 'GOLD' },
];
const WHEEL_RESOURCE_TYPE_OPTIONS = [
{ label: '头像框', value: 'AVATAR_FRAME' },
{ label: '座驾', value: 'RIDE' },
{ label: '礼物', value: 'GIFT' },
{ label: '用户徽章', value: 'BADGE' },
{ label: '房间徽章', value: 'ROOM_BADGE' },
{ label: '表情包', value: 'EMOJI' },
{ label: '聊天气泡', value: 'CHAT_BUBBLE' },
{ label: '飘窗', value: 'FLOAT_PICTURE' },
{ label: '资料卡', value: 'DATA_CARD' },
];
let localRowId = 0;
function normalizeRewardTypeValue(value: any) {
@ -646,7 +658,7 @@ function validateCategory(category: Record<string, any>) {
return false;
}
if (categoryProbability(category) !== PROBABILITY_TOTAL) {
message.warning(`${category.label} 启用时概率总和必须等于 10000`);
message.warning(`${category.label} 启用时概率总和必须等于 ${PROBABILITY_TOTAL}`);
return false;
}
}
@ -1166,6 +1178,7 @@ watch(activePageTab, (value) => {
"
:open="resourcePickerOpen"
:sys-origin="selectedSysOrigin"
:type-options="WHEEL_RESOURCE_TYPE_OPTIONS"
@close="closeResourcePicker"
@select="handleResourceSelect"
/>