Compare commits

...

2 Commits

Author SHA1 Message Date
zhx
8043571cec 修复区域飘屏 2026-05-25 22:10:54 +08:00
zhx
0ddf3bd3bd 区域飘屏 2026-05-25 21:59:19 +08:00
2 changed files with 41 additions and 4 deletions

View File

@ -14,6 +14,7 @@ const props = withDefaults(
placeholder?: string; placeholder?: string;
sysOrigin: string; sysOrigin: string;
value?: any; value?: any;
valueField?: 'id' | 'regionCode';
}>(), }>(),
{ {
clearable: false, clearable: false,
@ -22,6 +23,7 @@ const props = withDefaults(
multiple: false, multiple: false,
placeholder: '请选择', placeholder: '请选择',
value: '', value: '',
valueField: 'id',
}, },
); );
@ -36,7 +38,10 @@ const selectValue = ref<any>(props.value);
const regionOptions = computed(() => const regionOptions = computed(() =>
list.value.map((item) => ({ list.value.map((item) => ({
label: item.regionName || '-', label: item.regionName || '-',
value: item.id as any, value:
props.valueField === 'regionCode'
? (item.regionCode || item.code || item.id)
: (item.id as any),
})), })),
); );
@ -67,8 +72,13 @@ watch(
function emitChange(value: any) { function emitChange(value: any) {
emit('update:value', value); emit('update:value', value);
const item = const item = list.value.find((current) => {
list.value.find((current) => String(current.id) === String(value)) || null; const currentValue =
props.valueField === 'regionCode'
? current.regionCode || current.code || current.id
: current.id;
return String(currentValue) === String(value);
}) || null;
emit('change', value, item); emit('change', value, item);
} }

View File

@ -10,6 +10,7 @@ import {
startRegionBroadcastWorker, startRegionBroadcastWorker,
stopRegionBroadcastWorker, stopRegionBroadcastWorker,
} from '#/api/legacy/region-broadcast'; } from '#/api/legacy/region-broadcast';
import { regionConfigTable } from '#/api/legacy/system';
import { getAllowedSysOrigins } from '#/views/system/shared'; import { getAllowedSysOrigins } from '#/views/system/shared';
import SystemRegionSelect from './components/system-region-select.vue'; import SystemRegionSelect from './components/system-region-select.vue';
@ -69,6 +70,7 @@ const form = reactive<Record<string, any>>({
const sending = ref(false); const sending = ref(false);
const workerLoading = ref(false); const workerLoading = ref(false);
const resultText = ref(''); const resultText = ref('');
const regionList = ref<Array<Record<string, any>>>([]);
const workerStatus = ref<Record<string, any>>({}); const workerStatus = ref<Record<string, any>>({});
const workerForm = reactive<Record<string, any>>({ const workerForm = reactive<Record<string, any>>({
betAmounts: '100,200,500,1000', betAmounts: '100,200,500,1000',
@ -103,11 +105,20 @@ watch(
form.regionCode = ''; form.regionCode = '';
workerForm.regionCodes = []; workerForm.regionCodes = [];
if (value) { if (value) {
void loadRegionList();
void refreshWorkerStatus(); void refreshWorkerStatus();
} }
}, },
); );
async function loadRegionList() {
if (!form.sysOrigin) {
regionList.value = [];
return;
}
regionList.value = (await regionConfigTable({ sysOrigin: form.sysOrigin })) || [];
}
function handleRegionChange(_value: any, item: Record<string, any> | null) { function handleRegionChange(_value: any, item: Record<string, any> | null) {
form.regionCode = item?.regionCode || item?.code || String(item?.id || ''); form.regionCode = item?.regionCode || item?.code || String(item?.id || '');
} }
@ -199,11 +210,25 @@ function buildWorkerPayload() {
maxDelaySeconds: Number(workerForm.maxDelaySeconds || 0), maxDelaySeconds: Number(workerForm.maxDelaySeconds || 0),
minDelaySeconds: Number(workerForm.minDelaySeconds || 0), minDelaySeconds: Number(workerForm.minDelaySeconds || 0),
multiples: parseFloatList(workerForm.multiples), multiples: parseFloatList(workerForm.multiples),
regionCodes: workerForm.regionCodes || [], regionCodes: normalizeWorkerRegionCodes(workerForm.regionCodes || []),
sysOrigin: form.sysOrigin, sysOrigin: form.sysOrigin,
}; };
} }
function normalizeWorkerRegionCodes(values: any[]) {
return values
.map((value) => {
const raw = String(value || '').trim();
const item = regionList.value.find((region) =>
[region.id, region.regionCode, region.code, region.regionName]
.filter((current) => current !== undefined && current !== null)
.some((current) => String(current).trim() === raw),
);
return String(item?.regionCode || item?.code || item?.regionName || raw).trim();
})
.filter(Boolean);
}
async function refreshWorkerStatus() { async function refreshWorkerStatus() {
workerLoading.value = true; workerLoading.value = true;
try { try {
@ -214,6 +239,7 @@ async function refreshWorkerStatus() {
} }
async function handleStartWorker() { async function handleStartWorker() {
await loadRegionList();
const payload = buildWorkerPayload(); const payload = buildWorkerPayload();
if (!payload.sysOrigin) { if (!payload.sysOrigin) {
message.warning('请选择系统来源'); message.warning('请选择系统来源');
@ -342,6 +368,7 @@ async function handleStopWorker() {
v-model:value="workerForm.regionCodes" v-model:value="workerForm.regionCodes"
multiple multiple
:sys-origin="form.sysOrigin" :sys-origin="form.sysOrigin"
value-field="regionCode"
placeholder="可多选" placeholder="可多选"
/> />
</FormItem> </FormItem>