优化上下限问题
This commit is contained in:
@@ -339,7 +339,7 @@ const maxCount = ref()
|
|||||||
const checkTaskGateState = ref(null)
|
const checkTaskGateState = ref(null)
|
||||||
const selectedLevels = ref(new Set())
|
const selectedLevels = ref(new Set())
|
||||||
const showLevelDropdown = ref(false)
|
const showLevelDropdown = ref(false)
|
||||||
let hostListMonitorTimer = null
|
const hostListDialogInstanceId = `host-list-dialog-${Math.random().toString(36).slice(2)}`
|
||||||
|
|
||||||
const resolveRestrictedMaxAnchorCount = (fallbackValue = 9999999) => {
|
const resolveRestrictedMaxAnchorCount = (fallbackValue = 9999999) => {
|
||||||
const permissions = getPermissions()
|
const permissions = getPermissions()
|
||||||
@@ -401,15 +401,24 @@ const parsedIds = computed(() => {
|
|||||||
watch(() => props.visible, (newVal) => {
|
watch(() => props.visible, (newVal) => {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
document.body.style.overflow = 'hidden'
|
document.body.style.overflow = 'hidden'
|
||||||
|
loadLocalGateConfig()
|
||||||
|
if (gateEnabled.value) {
|
||||||
|
claimGateOwnership()
|
||||||
|
}
|
||||||
loadHosts()
|
loadHosts()
|
||||||
loadConfig()
|
loadConfig()
|
||||||
} else {
|
} else {
|
||||||
document.body.style.overflow = ''
|
document.body.style.overflow = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshHostListMonitor()
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadLocalGateConfig()
|
loadLocalGateConfig()
|
||||||
|
if (gateEnabled.value) {
|
||||||
|
claimGateOwnership()
|
||||||
|
}
|
||||||
loadConfig()
|
loadConfig()
|
||||||
|
|
||||||
if (props.visible) {
|
if (props.visible) {
|
||||||
@@ -417,11 +426,11 @@ onMounted(() => {
|
|||||||
loadHosts()
|
loadHosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
startHostListMonitor()
|
refreshHostListMonitor()
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
stopHostListMonitor()
|
releaseGateOwnership()
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听过滤器变化,同步到后端配置
|
// 监听过滤器变化,同步到后端配置
|
||||||
@@ -479,32 +488,87 @@ const loadConfig = async () => {
|
|||||||
filters.value.ordinary = config.filters.ordinary
|
filters.value.ordinary = config.filters.ordinary
|
||||||
}
|
}
|
||||||
// 加载在线人数过滤配置
|
// 加载在线人数过滤配置
|
||||||
if (config?.filters?.minOnlineFans !== undefined && config.filters.minOnlineFans > 0) {
|
filters.value.minOnlineFans = config?.filters?.minOnlineFans !== undefined && config.filters.minOnlineFans > 0
|
||||||
filters.value.minOnlineFans = config.filters.minOnlineFans
|
? config.filters.minOnlineFans
|
||||||
}
|
: ''
|
||||||
if (config?.filters?.maxOnlineFans !== undefined && config.filters.maxOnlineFans > 0 && config.filters.maxOnlineFans < 9999999999999) {
|
filters.value.maxOnlineFans = config?.filters?.maxOnlineFans !== undefined
|
||||||
filters.value.maxOnlineFans = config.filters.maxOnlineFans
|
&& config.filters.maxOnlineFans > 0
|
||||||
}
|
&& config.filters.maxOnlineFans < 9999999999999
|
||||||
|
? config.filters.maxOnlineFans
|
||||||
|
: ''
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('加载配置失败:', e)
|
console.error('加载配置失败:', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const startHostListMonitor = () => {
|
const getGateRuntime = () => {
|
||||||
stopHostListMonitor()
|
if (typeof window === 'undefined') {
|
||||||
|
return { ownerId: null, timer: null }
|
||||||
|
}
|
||||||
|
|
||||||
if (!isElectron()) return
|
if (!window.__hostListGateRuntime) {
|
||||||
|
window.__hostListGateRuntime = {
|
||||||
|
ownerId: null,
|
||||||
|
timer: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hostListMonitorTimer = setInterval(async () => {
|
return window.__hostListGateRuntime
|
||||||
if (!gateEnabled.value) return
|
|
||||||
await loadHosts()
|
|
||||||
}, HOST_LIST_MONITOR_INTERVAL_MS)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopHostListMonitor = () => {
|
const isGateOwner = () => {
|
||||||
if (!hostListMonitorTimer) return
|
return getGateRuntime().ownerId === hostListDialogInstanceId
|
||||||
clearInterval(hostListMonitorTimer)
|
}
|
||||||
hostListMonitorTimer = null
|
|
||||||
|
const claimGateOwnership = () => {
|
||||||
|
const runtime = getGateRuntime()
|
||||||
|
if (runtime.ownerId === hostListDialogInstanceId) return
|
||||||
|
|
||||||
|
if (runtime.timer) {
|
||||||
|
clearInterval(runtime.timer)
|
||||||
|
runtime.timer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.ownerId = hostListDialogInstanceId
|
||||||
|
}
|
||||||
|
|
||||||
|
const releaseGateOwnership = () => {
|
||||||
|
const runtime = getGateRuntime()
|
||||||
|
if (runtime.ownerId !== hostListDialogInstanceId) return
|
||||||
|
|
||||||
|
if (runtime.timer) {
|
||||||
|
clearInterval(runtime.timer)
|
||||||
|
runtime.timer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.ownerId = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const refreshHostListMonitor = () => {
|
||||||
|
if (!isElectron()) return
|
||||||
|
|
||||||
|
const runtime = getGateRuntime()
|
||||||
|
const shouldRun = gateEnabled.value && isGateOwner()
|
||||||
|
|
||||||
|
if (!shouldRun) {
|
||||||
|
if (runtime.timer && isGateOwner()) {
|
||||||
|
clearInterval(runtime.timer)
|
||||||
|
runtime.timer = null
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runtime.timer) return
|
||||||
|
|
||||||
|
runtime.timer = setInterval(async () => {
|
||||||
|
if (!gateEnabled.value || !isGateOwner()) {
|
||||||
|
refreshHostListMonitor()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await loadHosts()
|
||||||
|
await syncControlCheckTaskGate()
|
||||||
|
}, HOST_LIST_MONITOR_INTERVAL_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadLocalGateConfig = () => {
|
const loadLocalGateConfig = () => {
|
||||||
@@ -570,6 +634,7 @@ const persistGateState = (value) => {
|
|||||||
const syncControlCheckTaskGate = async (forceSync = false) => {
|
const syncControlCheckTaskGate = async (forceSync = false) => {
|
||||||
if (!isElectron()) return
|
if (!isElectron()) return
|
||||||
if (!gateEnabled.value) return
|
if (!gateEnabled.value) return
|
||||||
|
if (!isGateOwner()) return
|
||||||
|
|
||||||
const hostCount = filteredHosts.value.length
|
const hostCount = filteredHosts.value.length
|
||||||
const upperLimit = Number(maxCount.value)
|
const upperLimit = Number(maxCount.value)
|
||||||
@@ -581,8 +646,10 @@ const syncControlCheckTaskGate = async (forceSync = false) => {
|
|||||||
nextState = false
|
nextState = false
|
||||||
} else if (Number.isFinite(lowerLimit) && lowerLimit >= 0 && hostCount < lowerLimit) {
|
} else if (Number.isFinite(lowerLimit) && lowerLimit >= 0 && hostCount < lowerLimit) {
|
||||||
nextState = true
|
nextState = true
|
||||||
} else if (forceSync && checkTaskGateState.value !== null) {
|
} else if (checkTaskGateState.value !== null) {
|
||||||
nextState = checkTaskGateState.value
|
nextState = checkTaskGateState.value
|
||||||
|
} else if (forceSync) {
|
||||||
|
nextState = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextState === null) return
|
if (nextState === null) return
|
||||||
@@ -699,12 +766,16 @@ watch(gateEnabled, async (enabled) => {
|
|||||||
persistGateEnabled()
|
persistGateEnabled()
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
claimGateOwnership()
|
||||||
|
refreshHostListMonitor()
|
||||||
void syncControlCheckTaskGate(true)
|
void syncControlCheckTaskGate(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
checkTaskGateState.value = null
|
checkTaskGateState.value = null
|
||||||
persistGateState(null)
|
persistGateState(null)
|
||||||
|
releaseGateOwnership()
|
||||||
|
refreshHostListMonitor()
|
||||||
|
|
||||||
if (!isElectron()) return
|
if (!isElectron()) return
|
||||||
|
|
||||||
@@ -762,7 +833,7 @@ const selectNone = () => {
|
|||||||
const invertSelect = () => {
|
const invertSelect = () => {
|
||||||
const next = new Set()
|
const next = new Set()
|
||||||
filteredHosts.value.forEach(h => {
|
filteredHosts.value.forEach(h => {
|
||||||
if (!selected.value.has(h.anchorId)) next.add(h.anchorId)
|
if (!selected.value.has(h.id)) next.add(h.id)
|
||||||
})
|
})
|
||||||
selected.value = next
|
selected.value = next
|
||||||
}
|
}
|
||||||
@@ -781,16 +852,16 @@ const deleteSelected = async () => {
|
|||||||
} else {
|
} else {
|
||||||
console.error('[HostListDialog] 删除失败:', result.error)
|
console.error('[HostListDialog] 删除失败:', result.error)
|
||||||
// fallback: 前端本地删除
|
// fallback: 前端本地删除
|
||||||
hosts.value = hosts.value.filter(h => !selected.value.has(h.anchorId))
|
hosts.value = hosts.value.filter(h => !selected.value.has(h.id))
|
||||||
selected.value = new Set()
|
selected.value = new Set()
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[HostListDialog] 删除异常:', e)
|
console.error('[HostListDialog] 删除异常:', e)
|
||||||
hosts.value = hosts.value.filter(h => !selected.value.has(h.anchorId))
|
hosts.value = hosts.value.filter(h => !selected.value.has(h.id))
|
||||||
selected.value = new Set()
|
selected.value = new Set()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hosts.value = hosts.value.filter(h => !selected.value.has(h.anchorId))
|
hosts.value = hosts.value.filter(h => !selected.value.has(h.id))
|
||||||
selected.value = new Set()
|
selected.value = new Set()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user