fix: 运营商管理
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 54s

This commit is contained in:
luo
2026-09-29 09:15:05 +08:00
parent 6655638116
commit 5364916b1d
26 changed files with 1095 additions and 40 deletions

View File

@@ -45,9 +45,15 @@
<ElDialog
v-model="dialogVisible"
:title="dialogType === 'add' ? '新增运营商' : '编辑运营商'"
width="30%"
width="min(94vw, 760px)"
>
<ElForm ref="formRef" :model="form" :rules="rules" label-width="120px">
<ElForm
ref="formRef"
:model="form"
:rules="rules"
label-width="120px"
class="carrier-form-grid"
>
<ElFormItem label="运营商编码" prop="carrier_code">
<ElInput
v-model="form.carrier_code"
@@ -80,7 +86,7 @@
/>
</ElSelect>
</ElFormItem>
<ElFormItem label="运营商描述" prop="description">
<ElFormItem label="运营商描述" prop="description" class="carrier-form-span">
<ElInput
v-model="form.description"
type="textarea"
@@ -102,6 +108,42 @@
运营商每月清零网关计数器的日期(1-28日),默认为1日
</div>
</ElFormItem>
<ElFormItem v-if="canConfigureTrafficThreshold" label="通道阈值状态">
<ElSelect
v-model="form.traffic_threshold_mode"
placeholder="请选择,留空表示未配置"
style="width: 100%"
@change="handleTrafficThresholdModeChange"
>
<ElOption label="未配置" value="unconfigured" />
<ElOption label="停用" value="disabled" />
<ElOption label="启用" value="enabled" />
</ElSelect>
</ElFormItem>
<template v-if="canConfigureTrafficThreshold">
<ElFormItem label="通道阈值单位" prop="traffic_threshold_unit">
<ElSelect
v-model="form.traffic_threshold_unit"
placeholder="请选择阈值单位"
style="width: 100%"
:disabled="form.traffic_threshold_mode !== 'enabled'"
>
<ElOption label="MB" value="MB" />
<ElOption label="GB" value="GB" />
</ElSelect>
</ElFormItem>
<ElFormItem label="通道阈值数值" prop="traffic_threshold_value">
<ElInput
v-model="form.traffic_threshold_value"
type="number"
min="0"
step="any"
:disabled="form.traffic_threshold_mode !== 'enabled'"
placeholder="请输入大于0的阈值数值"
style="width: 100%"
/>
</ElFormItem>
</template>
<ElFormItem label="实名链接类型" prop="realname_link_type">
<ElSelect
v-model="form.realname_link_type"
@@ -117,6 +159,7 @@
v-if="form.realname_link_type === 'template'"
label="实名链接模板"
prop="realname_link_template"
class="carrier-form-span"
>
<ElInput
v-model="form.realname_link_template"
@@ -145,13 +188,16 @@
<script setup lang="ts">
import { h, watch, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import { CarrierService } from '@/api/modules'
import { ElMessage, ElMessageBox, ElTag, ElSwitch, ElButton } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import type { Carrier, CarrierType } from '@/types/api'
import type { Carrier, CarrierType, CreateCarrierParams } from '@/types/api'
import type { SearchFormItem } from '@/types'
import { useCheckedColumns } from '@/composables/useCheckedColumns'
import { useAuth } from '@/composables/useAuth'
import { usePermission } from '@/composables/usePermission'
import { RoutesAlias } from '@/router/routesAlias'
import { generateCarrierCode } from '@/utils/codeGenerator'
import { formatDateTime } from '@/utils/business/format'
import {
@@ -164,7 +210,10 @@
defineOptions({ name: 'CarrierManagement' })
const router = useRouter()
const { hasAuth } = useAuth()
const { isPlatformAccount } = usePermission()
const canConfigureTrafficThreshold = computed(() => isPlatformAccount.value)
const canUpdateCarrierStatus = hasAuth('carrier:update_status')
const dialogVisible = ref(false)
const loading = ref(false)
@@ -235,6 +284,13 @@
{ label: '运营商名称', prop: 'carrier_name' },
{ label: '运营商类型', prop: 'carrier_type' },
{ label: '运营商描述', prop: 'description' },
...(canConfigureTrafficThreshold.value
? [
{ label: '通道阈值状态', prop: 'traffic_threshold_enabled' },
{ label: '通道阈值单位', prop: 'traffic_threshold_unit' },
{ label: '通道阈值数值', prop: 'traffic_threshold_value' }
]
: []),
...(canUpdateCarrierStatus ? [{ label: '状态', prop: 'status' }] : []),
{ label: '创建时间', prop: 'created_at' }
]
@@ -296,6 +352,9 @@
carrier_type: null,
description: '',
data_reset_day: 1,
traffic_threshold_mode: 'unconfigured',
traffic_threshold_unit: null,
traffic_threshold_value: null,
realname_link_type: 'none',
realname_link_template: ''
})
@@ -314,7 +373,17 @@
prop: 'carrier_name',
label: '运营商名称',
minWidth: 150,
showOverflowTooltip: true
showOverflowTooltip: true,
formatter: (row: Carrier) =>
h(
ElButton,
{
type: 'primary',
link: true,
onClick: () => void router.push(`${RoutesAlias.CarrierDetail}/${row.id}`)
},
() => row.carrier_name || '-'
)
},
{
prop: 'carrier_type',
@@ -335,6 +404,28 @@
minWidth: 200,
showOverflowTooltip: true
},
...(canConfigureTrafficThreshold.value
? [
{
prop: 'traffic_threshold_enabled',
label: '通道阈值状态',
width: 130,
formatter: (row: Carrier) => getThresholdEnabledLabel(row.traffic_threshold_enabled)
},
{
prop: 'traffic_threshold_unit',
label: '通道阈值单位',
width: 120,
formatter: (row: Carrier) => row.traffic_threshold_unit || '未配置'
},
{
prop: 'traffic_threshold_value',
label: '通道阈值数值',
width: 140,
formatter: (row: Carrier) => formatThresholdValue(row.traffic_threshold_value)
}
]
: []),
...(canUpdateCarrierStatus
? [
{
@@ -482,6 +573,9 @@
form.carrier_type = row.carrier_type
form.description = row.description
form.data_reset_day = row.data_reset_day || 1
form.traffic_threshold_mode = getThresholdMode(row.traffic_threshold_enabled)
form.traffic_threshold_unit = row.traffic_threshold_unit ?? null
form.traffic_threshold_value = row.traffic_threshold_value ?? null
form.realname_link_type = row.realname_link_type || 'none'
form.realname_link_template = row.realname_link_template || ''
} else {
@@ -491,6 +585,9 @@
form.carrier_type = null
form.description = ''
form.data_reset_day = 1
form.traffic_threshold_mode = 'unconfigured'
form.traffic_threshold_unit = null
form.traffic_threshold_value = null
form.realname_link_type = 'none'
form.realname_link_template = ''
}
@@ -501,6 +598,49 @@
})
}
const getThresholdEnabledLabel = (enabled?: 0 | 1 | null) => {
if (enabled === 1) return '启用'
if (enabled === 0) return '停用'
return '未配置'
}
const getThresholdMode = (enabled?: 0 | 1 | null) => {
if (enabled === 1) return 'enabled'
if (enabled === 0) return 'disabled'
return 'unconfigured'
}
const handleTrafficThresholdModeChange = (mode: string) => {
if (mode === 'unconfigured') {
form.traffic_threshold_unit = null
form.traffic_threshold_value = null
}
}
const formatThresholdValue = (value?: number | null) =>
value === null || value === undefined ? '未配置' : String(value)
const getTrafficThresholdPayload = () => {
if (!canConfigureTrafficThreshold.value) return {}
if (form.traffic_threshold_mode === 'unconfigured') {
return {
traffic_threshold_enabled: null,
traffic_threshold_unit: null,
traffic_threshold_value: null
}
}
if (form.traffic_threshold_mode === 'disabled') {
return { traffic_threshold_enabled: 0 as const }
}
return {
traffic_threshold_enabled: 1 as const,
traffic_threshold_unit: form.traffic_threshold_unit,
traffic_threshold_value: Number(form.traffic_threshold_value)
}
}
// 处理编码生成
const handleGenerateCarrierCode = () => {
form.carrier_code = generateCarrierCode()
@@ -536,11 +676,22 @@
const handleSubmit = async (formEl: FormInstance | undefined) => {
if (!formEl) return
if (
canConfigureTrafficThreshold.value &&
form.traffic_threshold_mode === 'enabled' &&
(!form.traffic_threshold_unit ||
!Number.isFinite(Number(form.traffic_threshold_value)) ||
Number(form.traffic_threshold_value) <= 0)
) {
ElMessage.warning('启用通道阈值时,请填写阈值单位和大于0的阈值数值')
return
}
await formEl.validate(async (valid) => {
if (valid) {
submitLoading.value = true
try {
const data = {
const data: CreateCarrierParams = {
carrier_code: form.carrier_code,
carrier_name: form.carrier_name,
carrier_type: form.carrier_type as CarrierType,
@@ -548,7 +699,8 @@
data_reset_day: form.data_reset_day || null,
realname_link_type: form.realname_link_type,
realname_link_template:
form.realname_link_type === 'template' ? form.realname_link_template : undefined
form.realname_link_type === 'template' ? form.realname_link_template : undefined,
...getTrafficThresholdPayload()
}
if (dialogType.value === 'add') {
@@ -561,7 +713,8 @@
data_reset_day: form.data_reset_day || null,
realname_link_type: form.realname_link_type,
realname_link_template:
form.realname_link_type === 'template' ? form.realname_link_template : undefined
form.realname_link_type === 'template' ? form.realname_link_template : undefined,
...getTrafficThresholdPayload()
}
await CarrierService.updateCarrier(form.id, updateData)
ElMessage.success('修改成功')
@@ -599,4 +752,28 @@
.carrier-page {
height: 100%;
}
.carrier-form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
column-gap: 24px;
:deep(.el-form-item) {
margin-right: 0;
}
}
.carrier-form-span {
grid-column: 1 / -1;
}
@media (max-width: 640px) {
.carrier-form-grid {
grid-template-columns: minmax(0, 1fr);
}
.carrier-form-span {
grid-column: auto;
}
}
</style>