This commit is contained in:
425
src/views/polling-management/error-classifications/index.vue
Normal file
425
src/views/polling-management/error-classifications/index.vue
Normal file
@@ -0,0 +1,425 @@
|
||||
<template>
|
||||
<ArtTableFullScreen>
|
||||
<div class="gateway-page" id="table-full-screen">
|
||||
<GatewayOptionsNotice :error="optionsError" :loading="optionsLoading" @retry="loadOptions" />
|
||||
<ArtSearchBar
|
||||
:filter="filters"
|
||||
:items="searchItems"
|
||||
:show-expand="searchItems.length >= 4"
|
||||
label-width="100px"
|
||||
@update:filter="(value) => Object.assign(filters, value)"
|
||||
@search="search"
|
||||
@reset="reset"
|
||||
/>
|
||||
<ElCard shadow="never" class="art-table-card">
|
||||
<ArtTableHeader v-model:columns="columnChecks" @refresh="load">
|
||||
<template #left>
|
||||
<ElButton v-if="userStore.isSuperAdmin" :disabled="!optionsReady" @click="openEditor()"
|
||||
>新增规则</ElButton
|
||||
>
|
||||
<ElButton v-if="canTest" type="primary" :disabled="!optionsReady" @click="openTest()"
|
||||
>测试分类</ElButton
|
||||
>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
<ElAlert
|
||||
v-if="error"
|
||||
:title="error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="gateway-error"
|
||||
show-icon
|
||||
/>
|
||||
<ArtTable
|
||||
:loading="loading"
|
||||
:data="rows"
|
||||
row-key="id"
|
||||
:current-page="pagination.page"
|
||||
:page-size="pagination.page_size"
|
||||
:total="total"
|
||||
:page-sizes="[20, 50, 100]"
|
||||
:margin-top="10"
|
||||
:actions="
|
||||
showColumn('operation') && (canTest || userStore.isSuperAdmin) ? getActions : null
|
||||
"
|
||||
:actions-width="240"
|
||||
empty-text="暂无错误分类规则"
|
||||
@current-change="changePage"
|
||||
@size-change="changeSize"
|
||||
>
|
||||
<ElTableColumn
|
||||
v-for="col in columns"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:min-width="col.width || 150"
|
||||
show-overflow-tooltip
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<ElTag v-if="col.prop === 'status'" :type="row.status === 1 ? 'success' : 'info'">{{
|
||||
row.status === 1 ? '启用' : '停用'
|
||||
}}</ElTag>
|
||||
<template v-else>{{ ruleValue(row, col.prop) }}</template>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<ElDialog
|
||||
v-model="editorVisible"
|
||||
:title="editingId == null ? '新增错误分类规则' : '编辑错误分类规则'"
|
||||
width="min(700px, 94vw)"
|
||||
:close-on-click-modal="!saving"
|
||||
:close-on-press-escape="!saving"
|
||||
:show-close="!saving"
|
||||
>
|
||||
<GatewayRuleFields v-model="form" :options="options" :disabled="saving || !optionsReady" />
|
||||
<ElAlert v-if="editorError" :title="editorError" type="error" :closable="false" />
|
||||
<template #footer
|
||||
><ElButton :disabled="saving" @click="editorVisible = false">取消</ElButton
|
||||
><ElButton type="primary" :loading="saving" :disabled="!optionsReady" @click="saveRule"
|
||||
>保存</ElButton
|
||||
></template
|
||||
>
|
||||
</ElDialog>
|
||||
|
||||
<ElDialog
|
||||
v-model="testVisible"
|
||||
title="测试上游错误分类(不写入数据)"
|
||||
width="min(760px, 94vw)"
|
||||
>
|
||||
<ElForm label-width="110px">
|
||||
<ElFormItem label="操作" required
|
||||
><ElSelect v-model="testForm.operation" :disabled="testing || !optionsReady"
|
||||
><ElOption
|
||||
v-for="opt in options.gateway_operations"
|
||||
:key="opt.value"
|
||||
v-bind="opt" /></ElSelect
|
||||
></ElFormItem>
|
||||
<ElFormItem label="上游原始信息" required
|
||||
><ElInput
|
||||
v-model="testForm.message"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
maxlength="1000"
|
||||
show-word-limit
|
||||
:disabled="testing"
|
||||
/></ElFormItem>
|
||||
<ElFormItem label="包含草稿规则"
|
||||
><ElSwitch v-model="includeDraft" :disabled="testing" @change="testResult = null"
|
||||
/></ElFormItem>
|
||||
</ElForm>
|
||||
<GatewayRuleFields
|
||||
v-if="includeDraft"
|
||||
v-model="draft"
|
||||
:options="options"
|
||||
:disabled="testing || !optionsReady"
|
||||
/>
|
||||
<ElAlert v-if="testError" :title="testError" type="error" :closable="false" />
|
||||
<ElDescriptions v-if="testResult" :column="1" border title="测试结果">
|
||||
<ElDescriptionsItem label="是否命中">{{
|
||||
testResult.matched ? '命中' : '未命中'
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="规则 ID"
|
||||
>{{ testResult.rule_id }}(0 表示草稿或未命中)</ElDescriptionsItem
|
||||
>
|
||||
<ElDescriptionsItem label="错误分类">{{
|
||||
testResult.category_name || label('error_categories', testResult.category)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="命中关键字">{{
|
||||
testResult.keyword || '-'
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="上游可能已受理">{{
|
||||
testResult.maybe_accepted ? '是' : '否'
|
||||
}}</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
<template #footer
|
||||
><ElButton @click="testVisible = false">关闭</ElButton
|
||||
><ElButton
|
||||
type="primary"
|
||||
:loading="testing"
|
||||
:disabled="!optionsReady || !canTest"
|
||||
@click="runTest"
|
||||
>开始测试</ElButton
|
||||
></template
|
||||
>
|
||||
</ElDialog>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, reactive, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { GatewayService } from '@/api/modules/gateway'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useGatewayList, useGatewayOptions, useGatewayColumns } from '@/composables/useGateway'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import type { GatewayRule, GatewayRuleInput, GatewayRuleTestResult } from '@/types/api/gateway'
|
||||
import {
|
||||
compactGatewayQuery,
|
||||
gatewayData,
|
||||
gatewayError,
|
||||
gatewayDisplayValue,
|
||||
requireGatewayAccess,
|
||||
validateGatewayRule
|
||||
} from '@/utils/business/gateway'
|
||||
import GatewayOptionsNotice from '@/components/business/gateway/GatewayOptionsNotice.vue'
|
||||
import GatewayRuleFields from '@/components/business/gateway/GatewayRuleFields.vue'
|
||||
|
||||
defineOptions({ name: 'GatewayErrorClassifications' })
|
||||
const userStore = useUserStore()
|
||||
const { hasAuth } = useAuth()
|
||||
const canTest = computed(
|
||||
() => hasAuth(GATEWAY_PERMISSIONS.rules.page) && hasAuth(GATEWAY_PERMISSIONS.rules.test)
|
||||
)
|
||||
const {
|
||||
options,
|
||||
error: optionsError,
|
||||
loading: optionsLoading,
|
||||
ready: optionsReady,
|
||||
load: loadOptions,
|
||||
label
|
||||
} = useGatewayOptions()
|
||||
const filters = reactive({ category: '', status: undefined as number | undefined, keyword: '' })
|
||||
const { rows, total, pagination, loading, error, load, search } = useGatewayList<GatewayRule>(
|
||||
(page) => GatewayService.getRules(compactGatewayQuery({ ...filters, ...page })),
|
||||
() => hasAuth(GATEWAY_PERMISSIONS.rules.page)
|
||||
)
|
||||
const operationsLabel = (values?: string[]) =>
|
||||
values?.length ? values.map((value) => label('gateway_operations', value)).join('、') : '全部'
|
||||
function reset() {
|
||||
Object.assign(filters, { category: '', status: undefined, keyword: '' })
|
||||
void search()
|
||||
}
|
||||
const searchItems = computed<SearchFormItem[]>(() => [
|
||||
{
|
||||
label: '错误分类',
|
||||
prop: 'category',
|
||||
type: 'select',
|
||||
options: options.value.error_categories,
|
||||
config: { clearable: true, disabled: !optionsReady.value }
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
prop: 'status',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '停用', value: 0 }
|
||||
],
|
||||
config: { clearable: true }
|
||||
},
|
||||
{
|
||||
label: '关键字',
|
||||
prop: 'keyword',
|
||||
type: 'input',
|
||||
config: { clearable: true, maxlength: 100, placeholder: '请输入关键字' }
|
||||
}
|
||||
])
|
||||
const { columns, columnChecks, showColumn } = useGatewayColumns([
|
||||
{ prop: 'id', label: 'ID', width: 80 },
|
||||
{ prop: 'category', label: '错误分类', width: 160 },
|
||||
{ prop: 'keyword', label: '关键字或正则', width: 200 },
|
||||
{ prop: 'match_type', label: '匹配方式' },
|
||||
{ prop: 'operations', label: '适用操作', width: 220 },
|
||||
{ prop: 'maybe_accepted', label: '可能已受理' },
|
||||
{ prop: 'priority', label: '优先级', width: 90 },
|
||||
{ prop: 'status', label: '状态', width: 90 },
|
||||
{ prop: 'remark', label: '备注', width: 180 },
|
||||
{ prop: 'created_at', label: '创建时间', width: 180 },
|
||||
{ prop: 'updated_at', label: '更新时间', width: 180 },
|
||||
{ prop: 'operation', label: '操作' }
|
||||
])
|
||||
function ruleValue(row: GatewayRule, key: string) {
|
||||
if (key === 'category') return row.category_name || label('error_categories', row.category)
|
||||
if (key === 'match_type') return label('match_types', row.match_type)
|
||||
if (key === 'operations') return operationsLabel(row.operations)
|
||||
if (key === 'maybe_accepted') return row.maybe_accepted ? '是' : '否'
|
||||
return gatewayDisplayValue(row[key as keyof GatewayRule], key)
|
||||
}
|
||||
function changePage(page: number) {
|
||||
pagination.page = page
|
||||
void load()
|
||||
}
|
||||
function changeSize(size: number) {
|
||||
pagination.page_size = size
|
||||
pagination.page = 1
|
||||
void load()
|
||||
}
|
||||
function getActions(row: GatewayRule) {
|
||||
return [
|
||||
...(canTest.value ? [{ label: '草稿测试', handler: () => openTest(row) }] : []),
|
||||
...(userStore.isSuperAdmin
|
||||
? [
|
||||
{
|
||||
label: '编辑',
|
||||
handler: () => {
|
||||
if (!mutating.value) openEditor(row)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: row.status === 1 ? '停用' : '启用',
|
||||
handler: () => {
|
||||
void changeRule(row, false)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'danger' as const,
|
||||
handler: () => {
|
||||
void changeRule(row, true)
|
||||
}
|
||||
}
|
||||
]
|
||||
: [])
|
||||
]
|
||||
}
|
||||
function emptyRule(): GatewayRuleInput {
|
||||
return {
|
||||
category: '',
|
||||
keyword: '',
|
||||
match_type: '',
|
||||
maybe_accepted: false,
|
||||
operations: [],
|
||||
priority: 10,
|
||||
remark: '',
|
||||
status: 1
|
||||
}
|
||||
}
|
||||
function ruleInput(row: GatewayRule): GatewayRuleInput {
|
||||
return {
|
||||
category: row.category,
|
||||
keyword: row.keyword,
|
||||
match_type: row.match_type,
|
||||
maybe_accepted: row.maybe_accepted ?? false,
|
||||
operations: [...(row.operations || [])],
|
||||
priority: row.priority ?? 10,
|
||||
remark: row.remark || '',
|
||||
status: row.status ?? 1
|
||||
}
|
||||
}
|
||||
const editorVisible = ref(false)
|
||||
const editingId = ref<number | null>(null)
|
||||
const form = ref(emptyRule())
|
||||
const saving = ref(false)
|
||||
const editorError = ref('')
|
||||
function openEditor(row?: GatewayRule) {
|
||||
if (!userStore.isSuperAdmin || !optionsReady.value) return
|
||||
editingId.value = row?.id ?? null
|
||||
form.value = row ? ruleInput(row) : emptyRule()
|
||||
editorError.value = ''
|
||||
editorVisible.value = true
|
||||
}
|
||||
async function saveRule() {
|
||||
if (saving.value) return
|
||||
editorError.value = ''
|
||||
try {
|
||||
requireGatewayAccess(userStore.isSuperAdmin && optionsReady.value)
|
||||
validateGatewayRule(form.value)
|
||||
saving.value = true
|
||||
const data = { ...form.value, operations: [...(form.value.operations || [])] }
|
||||
gatewayData(
|
||||
await (editingId.value == null
|
||||
? GatewayService.createRule(data)
|
||||
: GatewayService.updateRule(editingId.value, data))
|
||||
)
|
||||
ElMessage.success('保存成功')
|
||||
editorVisible.value = false
|
||||
await load()
|
||||
} catch (cause) {
|
||||
editorError.value = gatewayError(cause)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
const mutating = ref(false)
|
||||
async function changeRule(row: GatewayRule, remove: boolean) {
|
||||
if (!userStore.isSuperAdmin || mutating.value) return
|
||||
mutating.value = true
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认${remove ? '删除' : row.status === 1 ? '停用' : '启用'}规则「${row.keyword}」?`,
|
||||
'操作确认',
|
||||
{ type: 'warning' }
|
||||
)
|
||||
requireGatewayAccess(userStore.isSuperAdmin)
|
||||
gatewayData(
|
||||
await (remove
|
||||
? GatewayService.deleteRule(row.id)
|
||||
: GatewayService.setRuleStatus(row.id, row.status === 1 ? 0 : 1))
|
||||
)
|
||||
ElMessage.success('操作成功')
|
||||
if (remove && rows.value.length === 1 && pagination.page > 1) pagination.page--
|
||||
await load()
|
||||
} catch (cause) {
|
||||
if (cause !== 'cancel' && cause !== 'close') ElMessage.error(gatewayError(cause))
|
||||
} finally {
|
||||
mutating.value = false
|
||||
}
|
||||
}
|
||||
const testVisible = ref(false)
|
||||
const includeDraft = ref(false)
|
||||
const draft = ref(emptyRule())
|
||||
const testForm = reactive({ operation: '', message: '' })
|
||||
const testing = ref(false)
|
||||
const testError = ref('')
|
||||
const testResult = ref<GatewayRuleTestResult | null>(null)
|
||||
let testSequence = 0
|
||||
function openTest(row?: GatewayRule) {
|
||||
if (!canTest.value || !optionsReady.value) return
|
||||
++testSequence
|
||||
testing.value = false
|
||||
includeDraft.value = !!row
|
||||
draft.value = row ? ruleInput(row) : emptyRule()
|
||||
Object.assign(testForm, { operation: '', message: '' })
|
||||
testResult.value = null
|
||||
testError.value = ''
|
||||
testVisible.value = true
|
||||
}
|
||||
watch(testVisible, (open) => {
|
||||
if (!open) {
|
||||
++testSequence
|
||||
testing.value = false
|
||||
}
|
||||
})
|
||||
watch(
|
||||
[testForm, draft, includeDraft],
|
||||
() => {
|
||||
testResult.value = null
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
async function runTest() {
|
||||
if (testing.value) return
|
||||
const sequence = ++testSequence
|
||||
testError.value = ''
|
||||
testResult.value = null
|
||||
try {
|
||||
requireGatewayAccess(canTest.value && optionsReady.value)
|
||||
if (!testForm.operation) throw new Error('请选择操作')
|
||||
if (!testForm.message.trim() || testForm.message.length > 1000)
|
||||
throw new Error('原始信息必填且不能超过 1000 字符')
|
||||
if (includeDraft.value) validateGatewayRule(draft.value)
|
||||
testing.value = true
|
||||
const data = gatewayData(
|
||||
await GatewayService.testRule({
|
||||
...testForm,
|
||||
...(includeDraft.value ? { draft: JSON.parse(JSON.stringify(draft.value)) } : {})
|
||||
})
|
||||
)
|
||||
if (sequence === testSequence) testResult.value = data
|
||||
} catch (cause) {
|
||||
if (sequence === testSequence) testError.value = gatewayError(cause)
|
||||
} finally {
|
||||
if (sequence === testSequence) testing.value = false
|
||||
}
|
||||
}
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use '../gateway';
|
||||
</style>
|
||||
226
src/views/polling-management/gateway-stats/index.vue
Normal file
226
src/views/polling-management/gateway-stats/index.vue
Normal file
@@ -0,0 +1,226 @@
|
||||
<template>
|
||||
<div class="gateway-page" id="table-full-screen">
|
||||
<GatewayOptionsNotice
|
||||
title="运营商账户加载失败"
|
||||
:error="carrierError"
|
||||
:loading="carrierLoading"
|
||||
@retry="searchCarriers()"
|
||||
/>
|
||||
<ElAlert
|
||||
type="info"
|
||||
show-icon
|
||||
:closable="false"
|
||||
title="统计接口文档未定义汇总和趋势的内部字段,以下按接口真实字段展示,不推导指标或绘制假定趋势。"
|
||||
/>
|
||||
<ArtSearchBar
|
||||
:filter="summaryFilter"
|
||||
:items="summarySearchItems"
|
||||
label-width="100px"
|
||||
:show-expand="summarySearchItems.length >= 4"
|
||||
@update:filter="(value) => Object.assign(summaryFilter, value)"
|
||||
@search="loadSummary"
|
||||
@reset="resetSummary"
|
||||
/>
|
||||
<ElCard shadow="never" class="art-table-card">
|
||||
<template #header>运营商账户调用汇总</template>
|
||||
<ElAlert v-if="summaryError" :title="summaryError" type="error" :closable="false" />
|
||||
<div v-loading="summaryLoading">
|
||||
<p v-if="summary" class="gateway-help"
|
||||
>实际统计窗口:{{ summary.minutes }} 分钟;统计模式:{{ summary.mode || '-' }}</p
|
||||
>
|
||||
<GatewayDynamicData
|
||||
v-if="summary"
|
||||
:values="summary.carriers"
|
||||
:data="summary"
|
||||
@refresh="loadSummary"
|
||||
/>
|
||||
<ElEmpty v-else-if="!summaryLoading && !summaryError" description="暂无汇总数据" />
|
||||
</div>
|
||||
</ElCard>
|
||||
<ArtSearchBar
|
||||
v-if="canTrend"
|
||||
:filter="trendFilter"
|
||||
:items="trendSearchItems"
|
||||
label-width="110px"
|
||||
:show-expand="trendSearchItems.length >= 4"
|
||||
@update:filter="(value) => Object.assign(trendFilter, value)"
|
||||
@search="loadTrend"
|
||||
@reset="resetTrend"
|
||||
/>
|
||||
<ElCard v-if="canTrend" shadow="never" class="art-table-card">
|
||||
<template #header>单个运营商账户调用趋势</template>
|
||||
<p class="gateway-help">选择“无法解析账户的卡”可查询未归属账户的数据;最多查询最近 7 天。</p>
|
||||
<ElAlert v-if="trendError" :title="trendError" type="error" :closable="false" />
|
||||
<div v-loading="trendLoading">
|
||||
<p v-if="trend" class="gateway-help"
|
||||
>运营商账户:{{
|
||||
trend.carrier_id === 0 ? '无法解析账户的卡' : carrierLabel(trend.carrier_id)
|
||||
}}</p
|
||||
>
|
||||
<GatewayDynamicData
|
||||
v-if="trend"
|
||||
:values="trend.points"
|
||||
:data="trend"
|
||||
@refresh="loadTrend"
|
||||
/>
|
||||
<ElEmpty v-else-if="!trendLoading && !trendError" description="请填写账户并查询趋势" />
|
||||
</div>
|
||||
</ElCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onBeforeUnmount, ref, reactive } from 'vue'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import { GatewayService } from '@/api/modules/gateway'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useGatewayCarriers } from '@/composables/useGateway'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import type { GatewayCarrierStats, GatewayCarrierTrend } from '@/types/api/gateway'
|
||||
import {
|
||||
gatewayData,
|
||||
gatewayError,
|
||||
requireGatewayAccess,
|
||||
validateGatewayInteger
|
||||
} from '@/utils/business/gateway'
|
||||
import GatewayDynamicData from '@/components/business/gateway/GatewayDynamicData.vue'
|
||||
import GatewayOptionsNotice from '@/components/business/gateway/GatewayOptionsNotice.vue'
|
||||
|
||||
defineOptions({ name: 'GatewayCallStats' })
|
||||
const { hasAuth } = useAuth()
|
||||
const {
|
||||
options: carrierOptions,
|
||||
loading: carrierLoading,
|
||||
error: carrierError,
|
||||
search: searchCarriers,
|
||||
label: carrierLabel,
|
||||
select: selectCarrier
|
||||
} = useGatewayCarriers()
|
||||
const canRead = computed(() => hasAuth(GATEWAY_PERMISSIONS.stats.page))
|
||||
const canTrend = computed(() => hasAuth(GATEWAY_PERMISSIONS.stats.trend))
|
||||
const summaryMinutes = ref(15)
|
||||
const summary = ref<GatewayCarrierStats | null>(null)
|
||||
const summaryLoading = ref(false)
|
||||
const summaryError = ref('')
|
||||
let summarySequence = 0
|
||||
async function loadSummary() {
|
||||
if (summaryLoading.value) return
|
||||
const sequence = ++summarySequence
|
||||
summary.value = null
|
||||
summaryError.value = ''
|
||||
try {
|
||||
requireGatewayAccess(canRead.value)
|
||||
validateGatewayInteger(Number(summaryMinutes.value), 1, 60, '汇总分钟数')
|
||||
summaryLoading.value = true
|
||||
const data = gatewayData(await GatewayService.getCarrierStats(Number(summaryMinutes.value)))
|
||||
if (!Array.isArray(data.carriers)) throw new Error('统计响应缺少 carriers 数组')
|
||||
if (sequence === summarySequence) summary.value = data
|
||||
} catch (cause) {
|
||||
if (sequence === summarySequence) summaryError.value = gatewayError(cause)
|
||||
} finally {
|
||||
if (sequence === summarySequence) summaryLoading.value = false
|
||||
}
|
||||
}
|
||||
const carrierId = ref<number | undefined>()
|
||||
const trendMinutes = ref(60)
|
||||
const bucketMinutes = ref(1)
|
||||
const trend = ref<GatewayCarrierTrend | null>(null)
|
||||
const trendLoading = ref(false)
|
||||
const trendError = ref('')
|
||||
let trendSequence = 0
|
||||
async function loadTrend() {
|
||||
if (trendLoading.value) return
|
||||
const sequence = ++trendSequence
|
||||
trend.value = null
|
||||
trendError.value = ''
|
||||
try {
|
||||
requireGatewayAccess(canRead.value && canTrend.value)
|
||||
if (carrierId.value == null || String(carrierId.value) === '')
|
||||
throw new Error('请选择运营商账户')
|
||||
validateGatewayInteger(Number(carrierId.value), 0, Number.MAX_SAFE_INTEGER, '运营商账户 ID')
|
||||
validateGatewayInteger(Number(trendMinutes.value), 1, 10080, '趋势分钟数')
|
||||
validateGatewayInteger(Number(bucketMinutes.value), 1, Number.MAX_SAFE_INTEGER, '聚合粒度')
|
||||
trendLoading.value = true
|
||||
const data = gatewayData(
|
||||
await GatewayService.getCarrierTrend(Number(carrierId.value), {
|
||||
minutes: Number(trendMinutes.value),
|
||||
bucket_minutes: Number(bucketMinutes.value)
|
||||
})
|
||||
)
|
||||
if (!Array.isArray(data.points)) throw new Error('趋势响应缺少 points 数组')
|
||||
if (sequence === trendSequence) trend.value = data
|
||||
} catch (cause) {
|
||||
if (sequence === trendSequence) trendError.value = gatewayError(cause)
|
||||
} finally {
|
||||
if (sequence === trendSequence) trendLoading.value = false
|
||||
}
|
||||
}
|
||||
const summaryFilter = reactive({ minutes: summaryMinutes })
|
||||
const trendFilter = reactive({
|
||||
carrier_id: carrierId,
|
||||
minutes: trendMinutes,
|
||||
bucket_minutes: bucketMinutes
|
||||
})
|
||||
const summarySearchItems: SearchFormItem[] = [
|
||||
{
|
||||
label: '最近分钟数',
|
||||
prop: 'minutes',
|
||||
type: 'input',
|
||||
config: { type: 'number', min: 1, max: 60 }
|
||||
}
|
||||
]
|
||||
const trendSearchItems = computed<SearchFormItem[]>(() => [
|
||||
{
|
||||
label: '运营商账户',
|
||||
prop: 'carrier_id',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: '无法解析账户的卡', value: 0 },
|
||||
...carrierOptions.value.filter((option) => option.value !== 0)
|
||||
],
|
||||
onChange: ({ val }) => selectCarrier(val),
|
||||
config: {
|
||||
clearable: true,
|
||||
filterable: true,
|
||||
remote: true,
|
||||
remoteMethod: searchCarriers,
|
||||
loading: carrierLoading.value,
|
||||
placeholder: '请输入运营商名称搜索'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '最近分钟数',
|
||||
prop: 'minutes',
|
||||
type: 'input',
|
||||
config: { type: 'number', min: 1, max: 10080 }
|
||||
},
|
||||
{
|
||||
label: '聚合粒度(分钟)',
|
||||
prop: 'bucket_minutes',
|
||||
type: 'input',
|
||||
config: { type: 'number', min: 1 }
|
||||
}
|
||||
])
|
||||
function resetSummary() {
|
||||
summaryMinutes.value = 15
|
||||
void loadSummary()
|
||||
}
|
||||
function resetTrend() {
|
||||
++trendSequence
|
||||
trendLoading.value = false
|
||||
carrierId.value = undefined
|
||||
trendMinutes.value = 60
|
||||
bucketMinutes.value = 1
|
||||
trend.value = null
|
||||
trendError.value = ''
|
||||
}
|
||||
onMounted(loadSummary)
|
||||
onBeforeUnmount(() => {
|
||||
++summarySequence
|
||||
++trendSequence
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use '../gateway';
|
||||
</style>
|
||||
65
src/views/polling-management/gateway.scss
Normal file
65
src/views/polling-management/gateway.scss
Normal file
@@ -0,0 +1,65 @@
|
||||
.gateway-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
|
||||
.gateway-toolbar,
|
||||
.gateway-pagination {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.gateway-pagination {
|
||||
justify-content: flex-end;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.el-select {
|
||||
min-width: 160px;
|
||||
}
|
||||
|
||||
.gateway-filters .el-input {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.gateway-filters .el-date-editor {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.gateway-help {
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.gateway-data {
|
||||
max-height: 400px;
|
||||
overflow: auto;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.gateway-error {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
@media (width <= 600px) {
|
||||
.gateway-filters :deep(.el-form-item) {
|
||||
display: flex;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.gateway-filters .el-input,
|
||||
.gateway-filters .el-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gateway-pagination {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
}
|
||||
127
src/views/polling-management/rate-limit-groups/detail.vue
Normal file
127
src/views/polling-management/rate-limit-groups/detail.vue
Normal file
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<div class="gateway-detail-page">
|
||||
<ElCard shadow="never">
|
||||
<div class="detail-header">
|
||||
<ElButton @click="router.back()"
|
||||
><template #icon
|
||||
><ElIcon><ArrowLeft /></ElIcon></template
|
||||
>返回</ElButton
|
||||
>
|
||||
<h2 class="detail-title">网关限流组详情</h2>
|
||||
</div>
|
||||
<GatewayOptionsNotice :error="optionsError" :loading="optionsLoading" @retry="loadOptions" />
|
||||
<div v-loading="loading">
|
||||
<ElAlert v-if="error" :title="error" type="error" :closable="false"
|
||||
><ElButton link type="primary" @click="load">重试</ElButton></ElAlert
|
||||
>
|
||||
<ElDescriptions v-if="detail" :column="width <= 640 ? 1 : 2" border>
|
||||
<ElDescriptionsItem label="ID">{{ detail.id }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="组标识">{{ detail.group_code }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="组名称">{{ detail.group_name }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="运营商账户">{{
|
||||
detail.carrier_id == null
|
||||
? '全局组'
|
||||
: `${detail.carrier_name || '账户'}(${detail.carrier_id})`
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="组内操作">{{
|
||||
operationsLabel(detail.operations)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="高优先级操作">{{
|
||||
operationsLabel(detail.high_priority_operations)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="每秒请求上限">{{ detail.max_qps }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="预留 QPS">{{ detail.reserved_qps ?? '-' }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="状态">{{
|
||||
detail.status_name || (detail.status === 1 ? '启用' : '停用')
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="创建时间">{{
|
||||
formatDateTime(detail.created_at)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="更新时间">{{
|
||||
formatDateTime(detail.updated_at)
|
||||
}}</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</div>
|
||||
</ElCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onBeforeUnmount } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useWindowSize } from '@vueuse/core'
|
||||
import { ArrowLeft } from '@element-plus/icons-vue'
|
||||
import { GatewayService } from '@/api/modules/gateway'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useGatewayOptions } from '@/composables/useGateway'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import {
|
||||
gatewayData,
|
||||
gatewayError,
|
||||
requireGatewayAccess,
|
||||
validateGatewayInteger
|
||||
} from '@/utils/business/gateway'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import type { GatewayGroup } from '@/types/api/gateway'
|
||||
import GatewayOptionsNotice from '@/components/business/gateway/GatewayOptionsNotice.vue'
|
||||
|
||||
defineOptions({ name: 'GatewayRateLimitGroupDetail' })
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const { width } = useWindowSize()
|
||||
const { hasAuth } = useAuth()
|
||||
const {
|
||||
error: optionsError,
|
||||
loading: optionsLoading,
|
||||
load: loadOptions,
|
||||
label
|
||||
} = useGatewayOptions()
|
||||
const detail = ref<GatewayGroup | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
let sequence = 0
|
||||
const operationsLabel = (values?: string[]) =>
|
||||
values?.length ? values.map((value) => label('gateway_operations', value)).join('、') : '-'
|
||||
async function load() {
|
||||
const current = ++sequence
|
||||
detail.value = null
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
requireGatewayAccess(hasAuth(GATEWAY_PERMISSIONS.groups.detailPage))
|
||||
const id = Number(route.params.id)
|
||||
if (route.params.id == null || route.params.id === '') throw new Error('缺少限流组 ID')
|
||||
validateGatewayInteger(id, 0, Number.MAX_SAFE_INTEGER, '限流组 ID')
|
||||
const data = gatewayData(await GatewayService.getGroup(id))
|
||||
if (current === sequence) detail.value = data
|
||||
} catch (cause) {
|
||||
if (current === sequence) error.value = gatewayError(cause)
|
||||
} finally {
|
||||
if (current === sequence) loading.value = false
|
||||
}
|
||||
}
|
||||
watch(() => route.params.id, load, { immediate: true })
|
||||
onBeforeUnmount(() => {
|
||||
++sequence
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.gateway-detail-page {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
</style>
|
||||
429
src/views/polling-management/rate-limit-groups/index.vue
Normal file
429
src/views/polling-management/rate-limit-groups/index.vue
Normal file
@@ -0,0 +1,429 @@
|
||||
<template>
|
||||
<ArtTableFullScreen>
|
||||
<div class="gateway-page" id="table-full-screen">
|
||||
<GatewayOptionsNotice :error="optionsError" :loading="optionsLoading" @retry="loadOptions" />
|
||||
<GatewayOptionsNotice
|
||||
title="运营商账户加载失败"
|
||||
:error="carrierError"
|
||||
:loading="carrierLoading"
|
||||
@retry="searchCarriers()"
|
||||
/>
|
||||
<ArtSearchBar
|
||||
:filter="filters"
|
||||
:items="searchItems"
|
||||
:show-expand="searchItems.length >= 4"
|
||||
label-width="100px"
|
||||
@update:filter="(value) => Object.assign(filters, value)"
|
||||
@search="search"
|
||||
@reset="reset"
|
||||
/>
|
||||
<ElCard shadow="never" class="art-table-card">
|
||||
<ArtTableHeader v-model:columns="columnChecks" @refresh="load">
|
||||
<template #left
|
||||
><ElButton v-if="userStore.isSuperAdmin" :disabled="!optionsReady" @click="openEditor()"
|
||||
>新增限流组</ElButton
|
||||
></template
|
||||
>
|
||||
</ArtTableHeader>
|
||||
<ElAlert
|
||||
v-if="error"
|
||||
:title="error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
class="gateway-error"
|
||||
show-icon
|
||||
/>
|
||||
<ArtTable
|
||||
:loading="loading"
|
||||
:data="rows"
|
||||
row-key="id"
|
||||
:current-page="pagination.page"
|
||||
:page-size="pagination.page_size"
|
||||
:total="total"
|
||||
:page-sizes="[20, 50, 100]"
|
||||
:margin-top="10"
|
||||
:actions="
|
||||
showColumn('operation') && (canDetail || userStore.isSuperAdmin) ? getActions : null
|
||||
"
|
||||
:actions-width="230"
|
||||
empty-text="暂无限流组"
|
||||
@current-change="changePage"
|
||||
@size-change="changeSize"
|
||||
>
|
||||
<ElTableColumn
|
||||
v-for="col in columns"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:min-width="col.width || 160"
|
||||
show-overflow-tooltip
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<ElTag v-if="col.prop === 'status'" :type="row.status === 1 ? 'success' : 'info'">{{
|
||||
row.status_name || (row.status === 1 ? '启用' : '停用')
|
||||
}}</ElTag>
|
||||
<template v-else>{{ groupValue(row, col.prop) }}</template>
|
||||
</template>
|
||||
</ElTableColumn>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<ElDialog
|
||||
v-model="editorVisible"
|
||||
:title="editingId == null ? '新增网关限流组' : '编辑网关限流组'"
|
||||
width="min(700px, 94vw)"
|
||||
:close-on-click-modal="!saving"
|
||||
:close-on-press-escape="!saving"
|
||||
:show-close="!saving"
|
||||
>
|
||||
<ElForm label-width="140px" :disabled="saving || !optionsReady">
|
||||
<ElFormItem label="全局组"><ElSwitch v-model="globalGroup" /></ElFormItem>
|
||||
<ElFormItem v-if="!globalGroup" label="运营商账户" required>
|
||||
<ElSelect
|
||||
v-model="form.carrier_id"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
:remote-method="searchCarriers"
|
||||
:loading="carrierLoading"
|
||||
@change="selectCarrier"
|
||||
placeholder="请输入运营商名称搜索"
|
||||
>
|
||||
<ElOption v-for="option in carrierOptions" :key="option.value" v-bind="option" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="组标识" required
|
||||
><ElInput v-model.trim="form.group_code" maxlength="50"
|
||||
/></ElFormItem>
|
||||
<ElFormItem label="组名称" required
|
||||
><ElInput v-model.trim="form.group_name" maxlength="100"
|
||||
/></ElFormItem>
|
||||
<ElFormItem label="组内操作" required
|
||||
><ElSelect v-model="form.operations" multiple
|
||||
><ElOption
|
||||
v-for="opt in options.gateway_operations"
|
||||
:key="opt.value"
|
||||
v-bind="opt" /></ElSelect
|
||||
></ElFormItem>
|
||||
<ElFormItem label="每秒请求上限" required
|
||||
><ElInputNumber v-model="form.max_qps" :min="1" :max="10000" :precision="0"
|
||||
/></ElFormItem>
|
||||
<ElFormItem label="高优先级操作"
|
||||
><ElSelect v-model="form.high_priority_operations" multiple clearable
|
||||
><ElOption
|
||||
v-for="opt in options.gateway_operations.filter((opt) =>
|
||||
form.operations.includes(opt.value)
|
||||
)"
|
||||
:key="opt.value"
|
||||
v-bind="opt" /></ElSelect
|
||||
></ElFormItem>
|
||||
<ElFormItem label="预留 QPS"
|
||||
><ElInputNumber
|
||||
v-model="form.reserved_qps"
|
||||
:min="0"
|
||||
:max="Math.max(0, (form.max_qps || 1) - 1)"
|
||||
:precision="0"
|
||||
/></ElFormItem>
|
||||
<ElFormItem label="状态"
|
||||
><ElSelect v-model="form.status"
|
||||
><ElOption label="启用" :value="1" /><ElOption label="停用" :value="0" /></ElSelect
|
||||
></ElFormItem>
|
||||
</ElForm>
|
||||
<ElAlert v-if="editorError" :title="editorError" type="error" :closable="false" />
|
||||
<template #footer
|
||||
><ElButton :disabled="saving" @click="editorVisible = false">取消</ElButton
|
||||
><ElButton type="primary" :loading="saving" :disabled="!optionsReady" @click="saveGroup"
|
||||
>保存</ElButton
|
||||
></template
|
||||
>
|
||||
</ElDialog>
|
||||
</div>
|
||||
</ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, reactive, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { GatewayService } from '@/api/modules/gateway'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import {
|
||||
useGatewayList,
|
||||
useGatewayOptions,
|
||||
useGatewayColumns,
|
||||
useGatewayCarriers
|
||||
} from '@/composables/useGateway'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { RoutesAlias } from '@/router/routesAlias'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import type { GatewayGroup, GatewayGroupInput } from '@/types/api/gateway'
|
||||
import {
|
||||
compactGatewayQuery,
|
||||
gatewayData,
|
||||
gatewayError,
|
||||
gatewayDisplayValue,
|
||||
gatewayOptionalId,
|
||||
requireGatewayAccess,
|
||||
validateGatewayGroup
|
||||
} from '@/utils/business/gateway'
|
||||
import GatewayOptionsNotice from '@/components/business/gateway/GatewayOptionsNotice.vue'
|
||||
|
||||
defineOptions({ name: 'GatewayRateLimitGroups' })
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
const {
|
||||
options: carrierOptions,
|
||||
loading: carrierLoading,
|
||||
error: carrierError,
|
||||
search: searchCarriers,
|
||||
remember: rememberCarrier,
|
||||
select: selectCarrier
|
||||
} = useGatewayCarriers()
|
||||
const { hasAuth } = useAuth()
|
||||
const canDetail = computed(
|
||||
() => hasAuth(GATEWAY_PERMISSIONS.groups.page) && hasAuth(GATEWAY_PERMISSIONS.groups.detail)
|
||||
)
|
||||
const {
|
||||
options,
|
||||
error: optionsError,
|
||||
loading: optionsLoading,
|
||||
ready: optionsReady,
|
||||
load: loadOptions,
|
||||
label
|
||||
} = useGatewayOptions()
|
||||
const filters = reactive({
|
||||
carrier_id: undefined as number | undefined,
|
||||
only_global: 0,
|
||||
status: undefined as number | undefined
|
||||
})
|
||||
const { rows, total, pagination, loading, error, load, search } = useGatewayList<GatewayGroup>(
|
||||
(page) => {
|
||||
return GatewayService.getGroups(
|
||||
compactGatewayQuery({
|
||||
...filters,
|
||||
only_global: Boolean(filters.only_global),
|
||||
carrier_id: filters.only_global ? undefined : gatewayOptionalId(filters.carrier_id),
|
||||
...page
|
||||
})
|
||||
)
|
||||
},
|
||||
() => hasAuth(GATEWAY_PERMISSIONS.groups.page)
|
||||
)
|
||||
function reset() {
|
||||
Object.assign(filters, { carrier_id: undefined, only_global: 0, status: undefined })
|
||||
void search()
|
||||
}
|
||||
const operationsLabel = (values?: string[]) =>
|
||||
values?.length ? values.map((value) => label('gateway_operations', value)).join('、') : '-'
|
||||
const editorVisible = ref(false)
|
||||
const searchItems = computed<SearchFormItem[]>(() => [
|
||||
{
|
||||
label: '运营商账户',
|
||||
prop: 'carrier_id',
|
||||
type: 'select',
|
||||
options: carrierOptions.value,
|
||||
onChange: ({ val }) => selectCarrier(val),
|
||||
config: {
|
||||
clearable: true,
|
||||
filterable: true,
|
||||
remote: true,
|
||||
remoteMethod: searchCarriers,
|
||||
loading: carrierLoading.value,
|
||||
disabled: Boolean(filters.only_global),
|
||||
placeholder: '请输入运营商名称搜索'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '只看全局组',
|
||||
prop: 'only_global',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: '全部', value: 0 },
|
||||
{ label: '仅全局组', value: 1 }
|
||||
],
|
||||
config: { clearable: false }
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
prop: 'status',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '停用', value: 0 }
|
||||
],
|
||||
config: { clearable: true }
|
||||
}
|
||||
])
|
||||
const { columns, columnChecks, showColumn } = useGatewayColumns([
|
||||
{ prop: 'id', label: 'ID', width: 80 },
|
||||
{ prop: 'carrier_id', label: '运营商账户', width: 180 },
|
||||
{ prop: 'group_code', label: '组标识' },
|
||||
{ prop: 'group_name', label: '组名称', width: 180 },
|
||||
{ prop: 'operations', label: '组内操作', width: 220 },
|
||||
{ prop: 'max_qps', label: '每秒请求上限' },
|
||||
{ prop: 'high_priority_operations', label: '高优先级操作', width: 180 },
|
||||
{ prop: 'reserved_qps', label: '预留 QPS' },
|
||||
{ prop: 'status', label: '状态', width: 90 },
|
||||
{ prop: 'created_at', label: '创建时间', width: 180 },
|
||||
{ prop: 'updated_at', label: '更新时间', width: 180 },
|
||||
{ prop: 'operation', label: '操作' }
|
||||
])
|
||||
function groupValue(row: GatewayGroup, key: string) {
|
||||
if (key === 'carrier_id')
|
||||
return row.carrier_id == null
|
||||
? '全局组'
|
||||
: `${row.carrier_name || '账户'}(${row.carrier_id})`
|
||||
if (key === 'operations' || key === 'high_priority_operations') return operationsLabel(row[key])
|
||||
return gatewayDisplayValue(row[key as keyof GatewayGroup], key)
|
||||
}
|
||||
function changePage(page: number) {
|
||||
pagination.page = page
|
||||
void load()
|
||||
}
|
||||
function changeSize(size: number) {
|
||||
pagination.page_size = size
|
||||
pagination.page = 1
|
||||
void load()
|
||||
}
|
||||
function getActions(row: GatewayGroup) {
|
||||
return [
|
||||
...(canDetail.value
|
||||
? [
|
||||
{
|
||||
label: '详情',
|
||||
handler: () => {
|
||||
void openDetail(row.id)
|
||||
}
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...(userStore.isSuperAdmin
|
||||
? [
|
||||
{
|
||||
label: '编辑',
|
||||
handler: () => {
|
||||
if (!mutating.value) openEditor(row)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: row.status === 1 ? '停用' : '启用',
|
||||
handler: () => {
|
||||
void changeGroup(row, false)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'danger' as const,
|
||||
handler: () => {
|
||||
void changeGroup(row, true)
|
||||
}
|
||||
}
|
||||
]
|
||||
: [])
|
||||
]
|
||||
}
|
||||
const editingId = ref<number | null>(null)
|
||||
const saving = ref(false)
|
||||
const editorError = ref('')
|
||||
const globalGroup = ref(true)
|
||||
const form = ref<GatewayGroupInput>({
|
||||
group_code: '',
|
||||
group_name: '',
|
||||
max_qps: 20,
|
||||
operations: [],
|
||||
high_priority_operations: [],
|
||||
reserved_qps: 0,
|
||||
status: 1,
|
||||
carrier_id: null
|
||||
})
|
||||
function openEditor(row?: GatewayGroup) {
|
||||
if (!userStore.isSuperAdmin || !optionsReady.value) return
|
||||
rememberCarrier(row?.carrier_id, row?.carrier_name)
|
||||
editingId.value = row?.id ?? null
|
||||
globalGroup.value = row?.carrier_id == null
|
||||
form.value = {
|
||||
group_code: row?.group_code || '',
|
||||
group_name: row?.group_name || '',
|
||||
max_qps: row?.max_qps ?? 20,
|
||||
operations: [...(row?.operations || [])],
|
||||
high_priority_operations: [...(row?.high_priority_operations || [])],
|
||||
reserved_qps: row?.reserved_qps ?? 0,
|
||||
status: row?.status ?? 1,
|
||||
carrier_id: row?.carrier_id ?? null
|
||||
}
|
||||
editorError.value = ''
|
||||
editorVisible.value = true
|
||||
}
|
||||
watch(
|
||||
() => [...form.value.operations],
|
||||
(operations) => {
|
||||
form.value.high_priority_operations = (form.value.high_priority_operations || []).filter(
|
||||
(value) => operations.includes(value)
|
||||
)
|
||||
}
|
||||
)
|
||||
async function saveGroup() {
|
||||
if (saving.value) return
|
||||
editorError.value = ''
|
||||
try {
|
||||
requireGatewayAccess(userStore.isSuperAdmin && optionsReady.value)
|
||||
if (!globalGroup.value && form.value.carrier_id == null)
|
||||
throw new Error('非全局组必须选择运营商账户')
|
||||
const data = {
|
||||
...form.value,
|
||||
carrier_id: globalGroup.value ? null : form.value.carrier_id,
|
||||
operations: [...form.value.operations],
|
||||
high_priority_operations: [...(form.value.high_priority_operations || [])]
|
||||
}
|
||||
validateGatewayGroup(data)
|
||||
saving.value = true
|
||||
gatewayData(
|
||||
await (editingId.value == null
|
||||
? GatewayService.createGroup(data)
|
||||
: GatewayService.updateGroup(editingId.value, data))
|
||||
)
|
||||
ElMessage.success('保存成功')
|
||||
editorVisible.value = false
|
||||
await load()
|
||||
} catch (cause) {
|
||||
editorError.value = gatewayError(cause)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
const mutating = ref(false)
|
||||
async function changeGroup(row: GatewayGroup, remove: boolean) {
|
||||
if (!userStore.isSuperAdmin || mutating.value) return
|
||||
mutating.value = true
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认${remove ? '删除' : row.status === 1 ? '停用' : '启用'}限流组「${row.group_name}」?`,
|
||||
'操作确认',
|
||||
{ type: 'warning' }
|
||||
)
|
||||
requireGatewayAccess(userStore.isSuperAdmin)
|
||||
gatewayData(
|
||||
await (remove
|
||||
? GatewayService.deleteGroup(row.id)
|
||||
: GatewayService.setGroupStatus(row.id, row.status === 1 ? 0 : 1))
|
||||
)
|
||||
ElMessage.success('操作成功')
|
||||
if (remove && rows.value.length === 1 && pagination.page > 1) pagination.page--
|
||||
await load()
|
||||
} catch (cause) {
|
||||
if (cause !== 'cancel' && cause !== 'close') ElMessage.error(gatewayError(cause))
|
||||
} finally {
|
||||
mutating.value = false
|
||||
}
|
||||
}
|
||||
async function openDetail(id: number) {
|
||||
if (!canDetail.value) return
|
||||
await router.push(`${RoutesAlias.GatewayRateLimitGroupDetail}/${id}`)
|
||||
}
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use '../gateway';
|
||||
</style>
|
||||
11
src/views/polling-management/stop-resume-records/index.vue
Normal file
11
src/views/polling-management/stop-resume-records/index.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<ArtTableFullScreen
|
||||
><StopResumeRecords :permission="GATEWAY_PERMISSIONS.records.page"
|
||||
/></ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import StopResumeRecords from '@/components/business/gateway/StopResumeRecords.vue'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
defineOptions({ name: 'GatewayStopResumeRecords' })
|
||||
</script>
|
||||
Reference in New Issue
Block a user