224 lines
8.2 KiB
Vue
224 lines
8.2 KiB
Vue
<template>
|
||
<ArtTableFullScreen
|
||
><div id="table-full-screen" class="scheduler-page">
|
||
<ArtSearchBar
|
||
:filter="filters"
|
||
:items="searchItems"
|
||
:show-expand="searchItems.length >= 4"
|
||
label-width="110px"
|
||
@search="load"
|
||
@reset="
|
||
() => {
|
||
filters.carrier_id = undefined
|
||
load()
|
||
}
|
||
"
|
||
/>
|
||
<ElCard shadow="never" class="art-table-card">
|
||
<ElAlert v-if="error" :title="error" type="error" :closable="false" />
|
||
<p v-if="data" class="help"
|
||
>全局默认执行上限 {{ data.default_inflight_limit }};每进程并发
|
||
{{ data.default_card_max_in_flight }};订阅进程
|
||
{{ data.subscriber_processes }}。空配置使用全局默认,0 不等同于空。</p
|
||
>
|
||
<SchedulerTable
|
||
:data="rows"
|
||
:definitions="fields"
|
||
:loading="loading"
|
||
row-key="carrier_id"
|
||
@refresh="load"
|
||
>
|
||
<ElTableColumn label="操作" width="210" fixed="right"
|
||
><template #default="{ row }"
|
||
><ElButton
|
||
v-if="hasAuth(P.detail)"
|
||
link
|
||
type="primary"
|
||
@click="detail(row.carrier_id)"
|
||
>详情</ElButton
|
||
><template v-if="user.isSuperAdmin"
|
||
><ElButton link type="primary" @click="edit(row)">编辑</ElButton
|
||
><ElButton link type="danger" :disabled="saving" @click="reset(row)"
|
||
>恢复默认</ElButton
|
||
></template
|
||
></template
|
||
></ElTableColumn
|
||
>
|
||
</SchedulerTable>
|
||
</ElCard>
|
||
<ElDialog
|
||
v-model="visible"
|
||
title="运营商账户调度参数"
|
||
width="min(700px,96vw)"
|
||
:show-close="!saving"
|
||
:close-on-click-modal="!saving"
|
||
>
|
||
<ElForm label-width="200px" :disabled="saving"
|
||
><ElFormItem v-for="item in inputFields" :key="item[0]" :label="item[1]"
|
||
><NullableNumber
|
||
v-model="form[item[0]]"
|
||
:empty-label="item[0] === 'priority_max_ratio' ? '不限' : '使用默认'"
|
||
:min="
|
||
item[0] === 'priority_max_ratio'
|
||
? 0.01
|
||
: item[0].includes('interval') || item[0].includes('delay')
|
||
? 0
|
||
: 1
|
||
"
|
||
:max="item[0] === 'priority_max_ratio' ? 1 : undefined"
|
||
:precision="item[0] === 'priority_max_ratio' ? 2 : 0"
|
||
:controls="false" /></ElFormItem
|
||
></ElForm>
|
||
<p>留空使用默认;当前卡任务容量 {{ capacity }}。停复机容量由服务端独立校验。</p
|
||
><ElAlert v-if="editError" :title="editError" type="error" :closable="false" />
|
||
<template #footer
|
||
><ElButton :disabled="saving" @click="visible = false">取消</ElButton
|
||
><ElButton type="primary" :loading="saving" @click="save">保存</ElButton></template
|
||
>
|
||
</ElDialog>
|
||
</div></ArtTableFullScreen
|
||
>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { computed, reactive, ref, onMounted } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import { ElMessageBox } from 'element-plus'
|
||
import { PollingSchedulerService as Service } from '@/api/modules/pollingScheduler'
|
||
import { useAuth } from '@/composables/useAuth'
|
||
import { useUserStore } from '@/store/modules/user'
|
||
import { useGatewayCarriers } from '@/composables/useGateway'
|
||
import { useSchedulerRequest } from '@/composables/useSchedulerRequest'
|
||
import { SCHEDULER_PERMISSIONS } from '@/config/constants/pollingScheduler'
|
||
import { gatewayData, gatewayError, requireGatewayAccess } from '@/utils/business/gateway'
|
||
import { validateCarrierParams } from '@/utils/business/pollingScheduler'
|
||
import type { CarrierParamsInput, CarrierPollingParams } from '@/types/api/pollingScheduler'
|
||
import type { SearchFormItem } from '@/types'
|
||
import SchedulerTable from '@/components/business/polling/SchedulerTable.vue'
|
||
import NullableNumber from '@/components/business/polling/NullableNumber.vue'
|
||
defineOptions({ name: 'PollingCarrierParams' })
|
||
const P = SCHEDULER_PERMISSIONS.params,
|
||
{ hasAuth } = useAuth(),
|
||
user = useUserStore(),
|
||
router = useRouter()
|
||
const { options, search, loading: carrierLoading } = useGatewayCarriers()
|
||
const filters = reactive({ carrier_id: undefined as number | undefined })
|
||
const searchItems = computed<SearchFormItem[]>(() => [
|
||
{
|
||
label: '运营商账户',
|
||
prop: 'carrier_id',
|
||
type: 'select',
|
||
options: options.value,
|
||
config: {
|
||
remote: true,
|
||
filterable: true,
|
||
clearable: true,
|
||
remoteMethod: search,
|
||
loading: carrierLoading.value
|
||
}
|
||
}
|
||
])
|
||
const { data, loading, error, load } = useSchedulerRequest(
|
||
async () => gatewayData(await Service.getCarrierParams()),
|
||
() => hasAuth(P.page)
|
||
)
|
||
const rows = computed(
|
||
() =>
|
||
data.value?.items.filter(
|
||
(row) => filters.carrier_id == null || row.carrier_id === filters.carrier_id
|
||
) || []
|
||
)
|
||
const fields = [
|
||
['carrier_name', '运营商账户'],
|
||
['is_default', '全局默认'],
|
||
['inflight_limit', '生效执行上限'],
|
||
['configured_inflight_limit', '配置执行上限'],
|
||
['card_max_in_flight', '每进程卡任务并发'],
|
||
['configured_card_max_in_flight', '配置卡任务并发'],
|
||
['consume_capacity', '订阅进程容量'],
|
||
['sr_inflight_limit', '停复机执行上限'],
|
||
['stop_resume_max_in_flight', '停复机每进程并发'],
|
||
['priority_max_ratio', '优先队列占比'],
|
||
['stop_resume_min_interval', '单卡最小间隔(秒)'],
|
||
['stop_resume_confirm_delay', '未知确认延迟(秒)']
|
||
].map(([prop, label]) => ({ prop, label }))
|
||
const inputFields = [
|
||
['card_max_in_flight', '每进程卡任务并发'],
|
||
['inflight_limit', '执行上限'],
|
||
['priority_max_ratio', '优先队列占比'],
|
||
['sr_inflight_limit', '停复机执行上限'],
|
||
['stop_resume_max_in_flight', '停复机每进程并发'],
|
||
['stop_resume_min_interval', '单卡最小间隔(秒)'],
|
||
['stop_resume_confirm_delay', '确认延迟(秒)']
|
||
]
|
||
const form = reactive<Record<string, number | null>>({}),
|
||
visible = ref(false),
|
||
saving = ref(false),
|
||
editError = ref(''),
|
||
id = ref(0),
|
||
capacity = ref(0)
|
||
function detail(carrierId: number) {
|
||
if (hasAuth(P.detail))
|
||
void router.push(`/polling-management/carrier-params/detail/${carrierId}`)
|
||
}
|
||
function edit(row: CarrierPollingParams) {
|
||
if (!user.isSuperAdmin) return
|
||
id.value = row.carrier_id
|
||
capacity.value = row.consume_capacity
|
||
for (const [key] of inputFields)
|
||
form[key] =
|
||
key === 'inflight_limit'
|
||
? row.configured_inflight_limit
|
||
: key === 'card_max_in_flight'
|
||
? row.configured_card_max_in_flight
|
||
: (row[key as keyof CarrierPollingParams] as number | null)
|
||
editError.value = ''
|
||
visible.value = true
|
||
}
|
||
async function save() {
|
||
if (saving.value) return
|
||
try {
|
||
requireGatewayAccess(user.isSuperAdmin)
|
||
validateCarrierParams(form as unknown as CarrierParamsInput, capacity.value)
|
||
saving.value = true
|
||
gatewayData(
|
||
await Service.saveCarrierParam(id.value, { ...form } as unknown as CarrierParamsInput)
|
||
)
|
||
visible.value = false
|
||
await load()
|
||
} catch (e) {
|
||
editError.value = gatewayError(e)
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
async function reset(row: CarrierPollingParams) {
|
||
if (!user.isSuperAdmin || saving.value) return
|
||
saving.value = true
|
||
try {
|
||
await ElMessageBox.confirm(`恢复「${row.carrier_name}」全部参数为全局默认?`, '确认', {
|
||
type: 'warning'
|
||
})
|
||
requireGatewayAccess(user.isSuperAdmin)
|
||
gatewayData(await Service.resetCarrierParam(row.carrier_id))
|
||
await load()
|
||
} catch (e) {
|
||
if (e !== 'cancel' && e !== 'close') error.value = gatewayError(e)
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
onMounted(load)
|
||
</script>
|
||
<style scoped>
|
||
.scheduler-page {
|
||
display: flex;
|
||
flex-direction: column;
|
||
min-width: 0;
|
||
}
|
||
|
||
.help {
|
||
font-size: 13px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
</style>
|