修复资源组

This commit is contained in:
zhx 2026-05-23 13:04:33 +08:00
parent 91cc67e192
commit 94d7c7529b
2 changed files with 56 additions and 4 deletions

View File

@ -20,6 +20,15 @@ const props = withDefaults(
);
const type = computed(() => props.item.detailType || props.item.type || '');
const imageUrl = computed(() =>
String(
props.item.cover ||
props.item.coverUrl ||
props.item.sourceUrl ||
props.item.resourceUrl ||
'',
).trim(),
);
const sizeStyle = computed(() => ({
height: `${props.size}px`,
width: `${props.size}px`,
@ -61,10 +70,10 @@ const tokenClassName = computed(() => {
<template>
<div class="reward-icon" :style="sizeStyle">
<Image
v-if="item.cover && !isCurrencyRewardType(type) && !isGameCouponType(type) && !isPropsCouponType(type) && type !== 'SPECIAL_ID'"
v-if="imageUrl && !isCurrencyRewardType(type) && !isGameCouponType(type) && !isPropsCouponType(type) && type !== 'SPECIAL_ID'"
class="reward-icon__image"
:preview="{ src: item.cover }"
:src="item.cover"
:preview="{ src: imageUrl }"
:src="imageUrl"
/>
<div v-else :class="tokenClassName">
{{ tokenLabel }}

View File

@ -393,7 +393,7 @@ function buildRewardItem(resource: DisplayResource): RewardGroupItem {
const item: RewardGroupItem = {
amount: resource.amount,
content: resource.id,
cover: resource.cover || '',
cover: resource.cover || resource.sourceUrl || '',
detailType: resource.type,
name: resource.name,
quantity: getDefaultQuantity(resource),
@ -408,6 +408,45 @@ function buildRewardItem(resource: DisplayResource): RewardGroupItem {
return item;
}
function applyResourcePreview(item: RewardGroupItem, resource: DisplayResource) {
if (!String(item.cover || '').trim()) {
item.cover = resource.cover || resource.sourceUrl || '';
}
if (!String(item.sourceUrl || '').trim()) {
item.sourceUrl = resource.sourceUrl || '';
}
if (!String(item.name || '').trim()) {
item.name = resource.name;
}
if (!String(item.remark || '').trim()) {
item.remark = resource.remark || resource.name || '';
}
if (!String(item.typeLabel || '').trim()) {
item.typeLabel = resource.typeLabel;
}
if (
(item.amount === undefined ||
item.amount === null ||
String(item.amount).trim() === '') &&
resource.amount !== undefined
) {
item.amount = resource.amount;
}
}
function hydrateSelectedItemsFromResources(resources: DisplayResource[]) {
if (resources.length === 0 || form.rewardConfigList.length === 0) {
return;
}
const resourceMap = new Map(resources.map((item) => [item.key, item]));
form.rewardConfigList.forEach((item) => {
const resource = resourceMap.get(getRewardKey(item));
if (resource) {
applyResourcePreview(item, resource);
}
});
}
function selectType(option: TypeOption) {
if (selectedType.value === option.value) {
return;
@ -451,6 +490,7 @@ async function loadOptions(type: string) {
}),
);
store.list = uniqueResources(results.flat());
hydrateSelectedItemsFromResources(store.list);
store.loaded = true;
return;
}
@ -460,6 +500,7 @@ async function loadOptions(type: string) {
store.list = (rows || []).map((item) =>
normalizeDisplayResource(item, 'gift', 'GIFT', '礼物'),
);
hydrateSelectedItemsFromResources(store.list);
store.loaded = true;
return;
}
@ -489,6 +530,7 @@ async function loadOptions(type: string) {
'VIP',
);
});
hydrateSelectedItemsFromResources(store.list);
store.loaded = true;
return;
}
@ -498,6 +540,7 @@ async function loadOptions(type: string) {
store.list = (rows || []).map((item) =>
normalizeDisplayResource(item, 'props', type, typeLabel),
);
hydrateSelectedItemsFromResources(store.list);
store.loaded = true;
} finally {
store.loading = false;