增加默认商店配置

This commit is contained in:
zhx 2026-05-18 10:55:20 +08:00
parent 02cbe30117
commit 9ad05f8aef

View File

@ -90,6 +90,8 @@ const adminFreeOptions = [
{ label: '是', value: true as any }, { label: '是', value: true as any },
{ label: '否', value: false as any }, { label: '否', value: false as any },
]; ];
const DEFAULT_STORE_CURRENCY_TYPES = 'GOLD';
const DEFAULT_STORE_VALID_DAYS = '7';
let tableResizeObserver: null | ResizeObserver = null; let tableResizeObserver: null | ResizeObserver = null;
const query = reactive({ const query = reactive({
@ -417,30 +419,39 @@ function getStoreCommodity(record: Record<string, any>) {
} }
function buildStoreShelfPayload(record: Record<string, any>, checked: boolean) { function buildStoreShelfPayload(record: Record<string, any>, checked: boolean) {
const commodity = getStoreCommodity(record); const commodity = getStoreCommodity(record) || {};
return { return {
...commodity, ...commodity,
currencyTypes: commodity.currencyTypes || DEFAULT_STORE_CURRENCY_TYPES,
discount: commodity.discount ?? 0,
label: commodity.label || '', label: commodity.label || '',
propsType: commodity.propsType || record.type, propsType: commodity.propsType || record.type,
shelfStatus: checked, shelfStatus: checked,
sort: commodity.sort ?? 0,
sourceId: commodity.sourceId || record.id, sourceId: commodity.sourceId || record.id,
sysOrigin: commodity.sysOrigin || record.sysOrigin, sysOrigin: commodity.sysOrigin || record.sysOrigin,
validDays: commodity.validDays || DEFAULT_STORE_VALID_DAYS,
}; };
} }
async function handleStoreShelfStatusChange(record: Record<string, any>, checked: boolean) { async function handleStoreShelfStatusChange(record: Record<string, any>, checked: boolean) {
const commodity = getStoreCommodity(record); const commodity = getStoreCommodity(record);
if (!commodity) { const previous = commodity?.shelfStatus;
message.warning('请先在道具商店配置该资源'); const nextCommodity = buildStoreShelfPayload(record, checked);
return; record.storeCommodity = nextCommodity;
}
const previous = commodity.shelfStatus;
commodity.shelfStatus = checked;
try { try {
await addOrUpdatePropsStore(buildStoreShelfPayload(record, checked)); await addOrUpdatePropsStore(nextCommodity);
message.success('道具商店状态已更新'); message.success('道具商店状态已更新');
if (!commodity) {
await loadData();
}
} catch (error) { } catch (error) {
commodity.shelfStatus = previous; if (commodity) {
commodity.shelfStatus = previous;
record.storeCommodity = commodity;
} else {
record.storeCommodity = null;
}
throw error; throw error;
} }
} }
@ -719,12 +730,11 @@ loadData(true);
</template> </template>
<template v-else-if="column.key === 'storeShelfStatus'"> <template v-else-if="column.key === 'storeShelfStatus'">
<Tooltip <Tooltip
:title="getStoreCommodity(record) ? '' : '请先在道具商店配置该资源'" :title="getStoreCommodity(record) ? '' : '点击后默认以金币售卖 7 天'"
> >
<Switch <Switch
class="compact-switch" class="compact-switch"
:checked="Boolean(getStoreCommodity(record)?.shelfStatus)" :checked="Boolean(getStoreCommodity(record)?.shelfStatus)"
:disabled="!getStoreCommodity(record)"
size="small" size="small"
@change=" @change="
(checked: boolean) => handleStoreShelfStatusChange(record, checked) (checked: boolean) => handleStoreShelfStatusChange(record, checked)