修改DiceLotteryPoolConfig-type改为name映射

This commit is contained in:
2026-03-17 17:09:10 +08:00
parent d4cf708bc1
commit e7b8f4cae9
18 changed files with 64 additions and 115 deletions

View File

@@ -18,7 +18,7 @@
<ElFormItem label="测试数据档位类型" prop="paid_lottery_config_id">
<ElSelect
v-model="form.paid_lottery_config_id"
placeholder="不选则下方自定义档位概率(默认 type=0"
placeholder="不选则下方自定义档位概率(默认 default"
clearable
filterable
style="width: 100%"
@@ -70,7 +70,7 @@
<ElFormItem label="测试数据档位类型" prop="free_lottery_config_id">
<ElSelect
v-model="form.free_lottery_config_id"
placeholder="不选则下方自定义档位概率(默认 type=1"
placeholder="不选则下方自定义档位概率(默认 killScore"
clearable
filterable
style="width: 100%"
@@ -153,22 +153,13 @@
free_s_count: 100,
free_n_count: 100
})
const lotteryOptions = ref<Array<{ id: number; name: string; type: number }>>([])
/** 将 type 转为数字(接口可能返回字符串 "0"/"1" */
function tierTypeNum(r: { type?: number | string }): number {
const t = r.type ?? 0
return typeof t === 'number' ? t : Number(t) || 0
}
/** 付费抽奖券可选档位type=0 */
const paidLotteryOptions = computed(() =>
lotteryOptions.value.filter((r) => tierTypeNum(r) === 0)
)
/**
* 免费抽奖券可选档位:优先 type=1DiceLotteryPoolConfig.type=1若无则显示全部以便下拉有选项
*/
const lotteryOptions = ref<Array<{ id: number; name: string }>>([])
/** 付费抽奖券可选档位name=default */
const paidLotteryOptions = computed(() => lotteryOptions.value.filter((r) => r.name === 'default'))
/** 免费抽奖券可选档位:优先 name=killScore若无则显示全部以便下拉有选项 */
const freeLotteryOptions = computed(() => {
const type1List = lotteryOptions.value.filter((r) => tierTypeNum(r) === 1)
return type1List.length > 0 ? type1List : lotteryOptions.value
const list = lotteryOptions.value.filter((r) => r.name === 'killScore')
return list.length > 0 ? list : lotteryOptions.value
})
const running = ref(false)
@@ -211,22 +202,16 @@
async function loadLotteryOptions() {
try {
const list = await lotteryPoolApi.getOptions()
lotteryOptions.value = list.map(
(r: { id: number; name: string; type?: number | string }) => ({
id: r.id,
name: r.name,
type: tierTypeNum(r)
})
)
// 付费抽奖券默认使用 type=0 的档位类型
const type0 = list.find((r: { type?: number | string }) => tierTypeNum(r) === 0)
if (type0) {
form.paid_lottery_config_id = type0.id
lotteryOptions.value = list.map((r: { id: number; name: string }) => ({ id: r.id, name: r.name }))
// 付费抽奖券默认使用 name=default
const normal = list.find((r: { name?: string }) => r.name === 'default')
if (normal) {
form.paid_lottery_config_id = normal.id
}
// 免费抽奖券默认使用 type=1 的档位类型DiceLotteryPoolConfig.type=1若无 type=1 则默认选第一项
const type1 = list.find((r: { type?: number | string }) => tierTypeNum(r) === 1)
if (type1) {
form.free_lottery_config_id = type1.id
// 免费抽奖券默认使用 name=killScore若无则默认选第一项
const kill = list.find((r: { name?: string }) => r.name === 'killScore')
if (kill) {
form.free_lottery_config_id = kill.id
} else if (list.length > 0) {
form.free_lottery_config_id = list[0].id
}
@@ -312,7 +297,7 @@
}
})
// 切换到免费步骤时,若当前选中 id 不在免费档位列表中,则重置为第一个 type=1 的选项,避免显示错误
// 切换到免费步骤时,若当前选中 id 不在免费档位列表中,则重置为第一个 killScore 的选项,避免显示错误
watch(currentStep, (step) => {
if (step === 1) {
const freeOpts = freeLotteryOptions.value