Files
one-pipe-system/src/views/settings/package-silence-switch/index.vue
luo f2614d8efb
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 54s
fix: some
2026-10-28 15:18:44 +08:00

88 lines
3.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<ElCard shadow="never" v-if="user.isSuperAdmin">
<h2>沉默期总开关</h2>
<ElAlert
title="默认关闭。开启前须通过全部后端检查;关闭不检查。此页面不会自动切换总开关。"
type="warning"
:closable="false"
/>
<p>当前状态:{{ data ? (data.enabled ? '已开启' : '已关闭') : '未获取' }}</p>
<ElButton :loading="loading" :disabled="saving" @click="load">刷新检查</ElButton>
<ElButton :loading="saving" :disabled="!data || loading" type="primary" @click="toggle">{{
data?.enabled ? '关闭沉默期' : '开启沉默期'
}}</ElButton>
<ElAlert v-if="error" :title="error" type="error" :closable="false" />
<ArtTable
:data="failed.length ? failed : data?.precheck || []"
:pagination="false"
row-key="code"
>
<ElTableColumn prop="code" label="检查编码" min-width="180" /><ElTableColumn
prop="name"
label="检查项"
min-width="200"
/>
<ElTableColumn label="是否通过" width="120"
><template #default="{ row }">{{ row.passed ? '通过' : '未通过' }}</template></ElTableColumn
><ElTableColumn prop="count" label="数量" width="100" />
</ArtTable>
</ElCard>
<ElEmpty v-else description="仅超级管理员可访问" />
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useUserStore } from '@/store/modules/user'
import { useSchedulerRequest } from '@/composables/useSchedulerRequest'
import { PackageSilenceService } from '@/api/modules/packageSilence'
import { gatewayData, gatewayError, requireGatewayAccess } from '@/utils/business/gateway'
import type { SilenceSwitchCheck } from '@/types/api/packageSilence'
defineOptions({ name: 'PackageSilenceSwitch' })
const user = useUserStore(),
saving = ref(false),
failed = ref<SilenceSwitchCheck[]>([])
const {
data,
loading,
error,
load: loadState
} = useSchedulerRequest(
async () => gatewayData(await PackageSilenceService.getSwitch()),
() => user.isSuperAdmin
)
async function load() {
failed.value = []
await loadState()
}
async function toggle() {
if (saving.value || loading.value || !data.value) return
saving.value = true
failed.value = []
try {
requireGatewayAccess(user.isSuperAdmin)
const enabled = !data.value.enabled
await ElMessageBox.confirm(
enabled ? '确认开启沉默期?后端将重新检查全部前置条件。' : '确认关闭沉默期?',
'切换确认',
{ type: 'warning' }
)
requireGatewayAccess(user.isSuperAdmin)
const response = await PackageSilenceService.setSwitch(enabled)
if (response.code !== 0) {
failed.value =
(response.data as unknown as { failed_items?: SilenceSwitchCheck[] })?.failed_items || []
throw new Error(response.msg || '切换失败')
}
await load()
} catch (cause: any) {
if (cause !== 'cancel' && cause !== 'close') {
failed.value = cause?.response?.data?.data?.failed_items || failed.value
error.value = gatewayError(cause)
}
} finally {
saving.value = false
}
}
onMounted(load)
</script>