This commit is contained in:
97
src/api/modules/gateway.ts
Normal file
97
src/api/modules/gateway.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { BaseService } from '../BaseService'
|
||||
import type { BaseResponse, PaginationResponse } from '@/types/api/common'
|
||||
import type {
|
||||
GatewayOptions,
|
||||
StopResumeRecord,
|
||||
StopResumeQuery,
|
||||
CardStopResumeQuery,
|
||||
GatewayRule,
|
||||
GatewayRuleQuery,
|
||||
GatewayRuleInput,
|
||||
GatewayRuleTestInput,
|
||||
GatewayRuleTestResult,
|
||||
GatewayGroup,
|
||||
GatewayGroupQuery,
|
||||
GatewayGroupInput,
|
||||
GatewayCarrierStats,
|
||||
GatewayCarrierTrend
|
||||
} from '@/types/api/gateway'
|
||||
|
||||
const rulesUrl = '/api/admin/gateway-error-classifications'
|
||||
const groupsUrl = '/api/admin/polling-rate-limit-groups'
|
||||
|
||||
export class GatewayService extends BaseService {
|
||||
static getRecords(params: StopResumeQuery): Promise<PaginationResponse<StopResumeRecord>> {
|
||||
return this.get('/api/admin/card-stop-resume-records', params)
|
||||
}
|
||||
|
||||
static getCardRecords(
|
||||
id: number,
|
||||
params?: CardStopResumeQuery
|
||||
): Promise<PaginationResponse<StopResumeRecord>> {
|
||||
return this.get(`/api/admin/iot-cards/${id}/stop-resume-records`, params)
|
||||
}
|
||||
|
||||
static getRules(params?: GatewayRuleQuery): Promise<PaginationResponse<GatewayRule>> {
|
||||
return this.get(rulesUrl, params)
|
||||
}
|
||||
|
||||
static createRule(data: GatewayRuleInput): Promise<BaseResponse<GatewayRule>> {
|
||||
return this.post(rulesUrl, data)
|
||||
}
|
||||
|
||||
static updateRule(id: number, data: GatewayRuleInput): Promise<BaseResponse<GatewayRule>> {
|
||||
return this.put(`${rulesUrl}/${id}`, data)
|
||||
}
|
||||
|
||||
static setRuleStatus(id: number, status: number): Promise<BaseResponse<unknown>> {
|
||||
return this.put(`${rulesUrl}/${id}/status`, { status })
|
||||
}
|
||||
|
||||
static deleteRule(id: number): Promise<BaseResponse<unknown>> {
|
||||
return this.delete(`${rulesUrl}/${id}`)
|
||||
}
|
||||
|
||||
static testRule(data: GatewayRuleTestInput): Promise<BaseResponse<GatewayRuleTestResult>> {
|
||||
return this.post(`${rulesUrl}/test`, data)
|
||||
}
|
||||
|
||||
static getOptions(): Promise<BaseResponse<GatewayOptions>> {
|
||||
return this.get('/api/admin/polling-options')
|
||||
}
|
||||
|
||||
static getGroups(params?: GatewayGroupQuery): Promise<PaginationResponse<GatewayGroup>> {
|
||||
return this.get(groupsUrl, params)
|
||||
}
|
||||
|
||||
static createGroup(data: GatewayGroupInput): Promise<BaseResponse<GatewayGroup>> {
|
||||
return this.post(groupsUrl, data)
|
||||
}
|
||||
|
||||
static getGroup(id: number): Promise<BaseResponse<GatewayGroup>> {
|
||||
return this.get(`${groupsUrl}/${id}`)
|
||||
}
|
||||
|
||||
static updateGroup(id: number, data: GatewayGroupInput): Promise<BaseResponse<GatewayGroup>> {
|
||||
return this.put(`${groupsUrl}/${id}`, data)
|
||||
}
|
||||
|
||||
static setGroupStatus(id: number, status: number): Promise<BaseResponse<unknown>> {
|
||||
return this.put(`${groupsUrl}/${id}/status`, { status })
|
||||
}
|
||||
|
||||
static deleteGroup(id: number): Promise<BaseResponse<unknown>> {
|
||||
return this.delete(`${groupsUrl}/${id}`)
|
||||
}
|
||||
|
||||
static getCarrierStats(minutes = 15): Promise<BaseResponse<GatewayCarrierStats>> {
|
||||
return this.get('/api/admin/polling-stats/carriers', { minutes })
|
||||
}
|
||||
|
||||
static getCarrierTrend(
|
||||
carrierId: number,
|
||||
params: { minutes?: number; bucket_minutes?: number } = {}
|
||||
): Promise<BaseResponse<GatewayCarrierTrend>> {
|
||||
return this.get(`/api/admin/polling-stats/carriers/${carrierId}/trend`, params)
|
||||
}
|
||||
}
|
||||
@@ -60,3 +60,4 @@ export { PollingPriorityQueueService } from './pollingPriorityQueue'
|
||||
export { AssetWalletService } from './assetWallet'
|
||||
|
||||
export { OperationsReportsService } from './operationsReports'
|
||||
export { GatewayService } from './gateway'
|
||||
|
||||
65
src/components/business/gateway/GatewayDynamicData.vue
Normal file
65
src/components/business/gateway/GatewayDynamicData.vue
Normal file
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<div>
|
||||
<ArtTableHeader v-model:columns="columnChecks" @refresh="$emit('refresh')" />
|
||||
<ArtTable
|
||||
:data="rows"
|
||||
:pagination="false"
|
||||
empty-text="暂无统计数据"
|
||||
max-height="460"
|
||||
:index="false"
|
||||
>
|
||||
<ElTableColumn
|
||||
v-for="key in visibleKeys"
|
||||
:key="key"
|
||||
:label="key"
|
||||
min-width="180"
|
||||
show-overflow-tooltip
|
||||
>
|
||||
<template #default="{ row }">{{ gatewayDisplayValue(row[key], key) }}</template>
|
||||
</ElTableColumn>
|
||||
</ArtTable>
|
||||
<ElCollapse>
|
||||
<ElCollapseItem title="查看完整响应数据(时间已格式化)" name="raw">
|
||||
<pre class="gateway-data">{{ responseText }}</pre>
|
||||
</ElCollapseItem>
|
||||
</ElCollapse>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { gatewayRows, gatewayDisplayValue } from '@/utils/business/gateway'
|
||||
defineEmits<{ refresh: [] }>()
|
||||
const props = defineProps<{ values: unknown[]; data: unknown }>()
|
||||
const rows = computed(() => gatewayRows(props.values))
|
||||
const keys = computed(() => [...new Set(rows.value.flatMap((row) => Object.keys(row)))])
|
||||
const responseText = computed(() => {
|
||||
const text = gatewayDisplayValue(props.data)
|
||||
if (props.data == null || typeof props.data !== 'object') return text
|
||||
return JSON.stringify(JSON.parse(text), null, 2)
|
||||
})
|
||||
const columnChecks = ref<{ prop: string; label: string; checked: boolean }[]>([])
|
||||
watch(
|
||||
keys,
|
||||
(values) => {
|
||||
columnChecks.value = values.map((key) => ({
|
||||
prop: key,
|
||||
label: key,
|
||||
checked: columnChecks.value.find((column) => column.prop === key)?.checked ?? true
|
||||
}))
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
const visibleKeys = computed(() =>
|
||||
columnChecks.value.filter((column) => column.checked).map((column) => column.prop)
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.gateway-data {
|
||||
max-height: 400px;
|
||||
overflow: auto;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
</style>
|
||||
22
src/components/business/gateway/GatewayOptionsNotice.vue
Normal file
22
src/components/business/gateway/GatewayOptionsNotice.vue
Normal file
@@ -0,0 +1,22 @@
|
||||
<template>
|
||||
<ElAlert
|
||||
v-if="error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
:title="title || '网关枚举加载失败'"
|
||||
>
|
||||
<template #default>
|
||||
{{ error }}
|
||||
<ElButton link type="primary" :loading="loading" @click="$emit('retry')">重新加载</ElButton>
|
||||
</template>
|
||||
</ElAlert>
|
||||
<div v-else-if="loading" role="status">{{
|
||||
title ? '正在加载运营商账户…' : '正在加载网关枚举…'
|
||||
}}</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{ error: string; loading: boolean; title?: string }>()
|
||||
defineEmits<{ retry: [] }>()
|
||||
</script>
|
||||
41
src/components/business/gateway/GatewayRuleFields.vue
Normal file
41
src/components/business/gateway/GatewayRuleFields.vue
Normal file
@@ -0,0 +1,41 @@
|
||||
<template>
|
||||
<ElForm label-width="130px" :disabled="disabled">
|
||||
<ElFormItem label="错误分类" required>
|
||||
<ElSelect v-model="model.category"
|
||||
><ElOption v-for="opt in options.error_categories" :key="opt.value" v-bind="opt"
|
||||
/></ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="关键字或正则" required
|
||||
><ElInput v-model="model.keyword" maxlength="200" show-word-limit
|
||||
/></ElFormItem>
|
||||
<ElFormItem label="匹配方式" required>
|
||||
<ElSelect v-model="model.match_type"
|
||||
><ElOption v-for="opt in options.match_types" :key="opt.value" v-bind="opt"
|
||||
/></ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="适用操作">
|
||||
<ElSelect v-model="model.operations" multiple clearable placeholder="留空表示全部操作"
|
||||
><ElOption v-for="opt in options.gateway_operations" :key="opt.value" v-bind="opt"
|
||||
/></ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="上游可能已受理"><ElSwitch v-model="model.maybe_accepted" /></ElFormItem>
|
||||
<ElFormItem label="匹配优先级"
|
||||
><ElInputNumber v-model="model.priority" :min="1" :max="10000" :precision="0" /><span
|
||||
>数值越小越先匹配</span
|
||||
></ElFormItem
|
||||
>
|
||||
<ElFormItem label="状态"
|
||||
><ElSelect v-model="model.status"
|
||||
><ElOption label="启用" :value="1" /><ElOption label="停用" :value="0" /></ElSelect
|
||||
></ElFormItem>
|
||||
<ElFormItem label="备注"
|
||||
><ElInput v-model="model.remark" type="textarea" maxlength="500" show-word-limit
|
||||
/></ElFormItem>
|
||||
</ElForm>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { GatewayRuleInput, GatewayOptions } from '@/types/api/gateway'
|
||||
const model = defineModel<GatewayRuleInput>({ required: true })
|
||||
defineProps<{ options: GatewayOptions; disabled?: boolean }>()
|
||||
</script>
|
||||
268
src/components/business/gateway/StopResumeRecords.vue
Normal file
268
src/components/business/gateway/StopResumeRecords.vue
Normal file
@@ -0,0 +1,268 @@
|
||||
<template>
|
||||
<div class="gateway-page" :id="cardId == null ? 'table-full-screen' : undefined">
|
||||
<GatewayOptionsNotice :error="optionsError" :loading="optionsLoading" @retry="loadOptions" />
|
||||
<GatewayOptionsNotice
|
||||
v-if="cardId == null"
|
||||
title="运营商账户加载失败"
|
||||
:error="carrierError"
|
||||
:loading="carrierLoading"
|
||||
@retry="searchCarriers()"
|
||||
/>
|
||||
<ArtSearchBar
|
||||
:filter="searchFilters"
|
||||
:items="searchItems"
|
||||
:show-expand="searchItems.length >= 4"
|
||||
label-width="100px"
|
||||
@update:filter="updateFilters"
|
||||
@search="search"
|
||||
@reset="reset"
|
||||
/>
|
||||
<ElCard shadow="never" class="art-table-card">
|
||||
<ArtTableHeader v-model:columns="columnChecks" @refresh="load">
|
||||
<template #left
|
||||
><span class="gateway-help"
|
||||
>时间跨度不超过 31 天;单卡清空时间时查询最近 31 天。</span
|
||||
></template
|
||||
>
|
||||
</ArtTableHeader>
|
||||
<ElAlert
|
||||
v-if="error"
|
||||
class="gateway-error"
|
||||
type="error"
|
||||
:title="error"
|
||||
:closable="false"
|
||||
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"
|
||||
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 || 140"
|
||||
show-overflow-tooltip
|
||||
>
|
||||
<template #default="{ row }">{{ recordValue(row, col.prop) }}</template>
|
||||
</ElTableColumn>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, reactive, watch } from 'vue'
|
||||
import { GatewayService } from '@/api/modules/gateway'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import {
|
||||
useGatewayList,
|
||||
useGatewayOptions,
|
||||
useGatewayColumns,
|
||||
useGatewayCarriers
|
||||
} from '@/composables/useGateway'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import type { StopResumeQuery, StopResumeRecord } from '@/types/api/gateway'
|
||||
import {
|
||||
compactGatewayQuery,
|
||||
gatewayTimeRange,
|
||||
recentGatewayRange,
|
||||
gatewayDisplayValue,
|
||||
gatewayOptionalId,
|
||||
validateGatewayInteger
|
||||
} from '@/utils/business/gateway'
|
||||
import GatewayOptionsNotice from './GatewayOptionsNotice.vue'
|
||||
|
||||
const props = defineProps<{ cardId?: number; permission: string }>()
|
||||
const { hasAuth } = useAuth()
|
||||
const {
|
||||
options: carrierOptions,
|
||||
loading: carrierLoading,
|
||||
error: carrierError,
|
||||
search: searchCarriers,
|
||||
label: carrierLabel,
|
||||
select: selectCarrier
|
||||
} = useGatewayCarriers(props.cardId == null)
|
||||
const {
|
||||
options,
|
||||
error: optionsError,
|
||||
loading: optionsLoading,
|
||||
ready: optionsReady,
|
||||
load: loadOptions,
|
||||
label
|
||||
} = useGatewayOptions()
|
||||
const range = ref<[Date | string, Date | string] | null>(recentGatewayRange())
|
||||
const filters = reactive({
|
||||
iccid: '',
|
||||
carrier_id: undefined as number | undefined,
|
||||
action: '',
|
||||
source: '',
|
||||
result: '',
|
||||
error_category: '',
|
||||
range
|
||||
})
|
||||
const { rows, total, loading, error, pagination, load, search, clear } =
|
||||
useGatewayList<StopResumeRecord>(
|
||||
(page) => {
|
||||
const time = gatewayTimeRange(range.value, props.cardId == null)
|
||||
if (props.cardId != null) {
|
||||
validateGatewayInteger(props.cardId, 0, Number.MAX_SAFE_INTEGER, '卡 ID')
|
||||
return GatewayService.getCardRecords(props.cardId, { ...page, ...time })
|
||||
}
|
||||
return GatewayService.getRecords(
|
||||
compactGatewayQuery({
|
||||
...filters,
|
||||
range: undefined,
|
||||
carrier_id: gatewayOptionalId(filters.carrier_id),
|
||||
...page,
|
||||
...time
|
||||
}) as StopResumeQuery
|
||||
)
|
||||
},
|
||||
() => hasAuth(props.permission)
|
||||
)
|
||||
const columnDefinitions: { prop: keyof StopResumeRecord; label: string; width?: number }[] = [
|
||||
{ prop: 'created_at', label: '创建时间', width: 200 },
|
||||
{ prop: 'iccid', label: 'ICCID', width: 220 },
|
||||
{ prop: 'action', label: '动作' },
|
||||
{ prop: 'result', label: '结果' },
|
||||
{ prop: 'error_category', label: '错误类别' },
|
||||
{ prop: 'provider_message', label: '上游返回信息', width: 240 },
|
||||
{ prop: 'reason', label: '原因', width: 200 },
|
||||
{ prop: 'source', label: '来源' },
|
||||
{ prop: 'scene', label: '场景' },
|
||||
{ prop: 'attempt', label: '尝试次数' },
|
||||
{ prop: 'duration_ms', label: '耗时(毫秒)' },
|
||||
{ prop: 'provider_code', label: '上游返回码' },
|
||||
{ prop: 'command_id', label: '命令 ID' },
|
||||
{ prop: 'card_id', label: '卡 ID' },
|
||||
{ prop: 'carrier_id', label: '运营商账户' },
|
||||
{ prop: 'id', label: '记录 ID' }
|
||||
]
|
||||
const { columns, columnChecks } = useGatewayColumns(columnDefinitions)
|
||||
const searchFilters = filters
|
||||
function updateFilters(value: Record<string, unknown>) {
|
||||
const { range: time, ...rest } = value
|
||||
Object.assign(filters, rest)
|
||||
range.value = time as typeof range.value
|
||||
}
|
||||
const searchItems = computed<SearchFormItem[]>(() => [
|
||||
...(props.cardId == null
|
||||
? [
|
||||
{
|
||||
label: 'ICCID',
|
||||
prop: 'iccid',
|
||||
type: 'input' as const,
|
||||
config: { clearable: true, maxlength: 30, placeholder: '请输入 ICCID' }
|
||||
},
|
||||
{
|
||||
label: '运营商账户',
|
||||
prop: 'carrier_id',
|
||||
type: 'select' as const,
|
||||
options: carrierOptions.value,
|
||||
onChange: ({ val }: { val: unknown }) => selectCarrier(val),
|
||||
config: {
|
||||
clearable: true,
|
||||
filterable: true,
|
||||
remote: true,
|
||||
remoteMethod: searchCarriers,
|
||||
loading: carrierLoading.value,
|
||||
placeholder: '请输入运营商名称搜索'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '动作',
|
||||
prop: 'action',
|
||||
type: 'select' as const,
|
||||
options: options.value.stop_resume_actions,
|
||||
config: { clearable: true, disabled: !optionsReady.value }
|
||||
},
|
||||
{
|
||||
label: '来源',
|
||||
prop: 'source',
|
||||
type: 'input' as const,
|
||||
config: { clearable: true, maxlength: 50 }
|
||||
},
|
||||
{
|
||||
label: '结果',
|
||||
prop: 'result',
|
||||
type: 'select' as const,
|
||||
options: options.value.stop_resume_results,
|
||||
config: { clearable: true, disabled: !optionsReady.value }
|
||||
},
|
||||
{
|
||||
label: '错误类别',
|
||||
prop: 'error_category',
|
||||
type: 'select' as const,
|
||||
options: options.value.error_categories,
|
||||
config: { clearable: true, disabled: !optionsReady.value }
|
||||
}
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: '记录时间',
|
||||
prop: 'range',
|
||||
type: 'datetimerange',
|
||||
config: {
|
||||
type: 'datetimerange',
|
||||
rangeSeparator: '至',
|
||||
startPlaceholder: '开始时间',
|
||||
endPlaceholder: '结束时间',
|
||||
valueFormat: 'YYYY-MM-DDTHH:mm:ssZ',
|
||||
clearable: true
|
||||
}
|
||||
}
|
||||
])
|
||||
function changePage(page: number) {
|
||||
pagination.page = page
|
||||
void load()
|
||||
}
|
||||
function changeSize(size: number) {
|
||||
pagination.page_size = size
|
||||
pagination.page = 1
|
||||
void load()
|
||||
}
|
||||
function recordValue(row: StopResumeRecord, prop: keyof StopResumeRecord) {
|
||||
if (prop === 'carrier_id') return carrierLabel(row.carrier_id)
|
||||
if (prop === 'action') return row.action_name || label('stop_resume_actions', row.action)
|
||||
if (prop === 'result') return label('stop_resume_results', row.result)
|
||||
if (prop === 'error_category')
|
||||
return row.error_category_name || label('error_categories', row.error_category)
|
||||
return gatewayDisplayValue(row[prop], prop)
|
||||
}
|
||||
function reset() {
|
||||
Object.assign(filters, {
|
||||
iccid: '',
|
||||
carrier_id: undefined,
|
||||
action: '',
|
||||
source: '',
|
||||
result: '',
|
||||
error_category: ''
|
||||
})
|
||||
range.value = recentGatewayRange()
|
||||
void search()
|
||||
}
|
||||
watch(
|
||||
() => [props.cardId, props.permission],
|
||||
() => {
|
||||
clear()
|
||||
pagination.page = 1
|
||||
void load()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use '@/views/polling-management/gateway';
|
||||
</style>
|
||||
183
src/composables/useGateway.ts
Normal file
183
src/composables/useGateway.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, shallowRef, watch } from 'vue'
|
||||
import { GatewayService } from '@/api/modules/gateway'
|
||||
import { CarrierService } from '@/api/modules/carrier'
|
||||
import type { GatewayOptions } from '@/types/api/gateway'
|
||||
import type { PaginationParams, PaginationResponse } from '@/types/api/common'
|
||||
import {
|
||||
gatewayData,
|
||||
gatewayError,
|
||||
gatewayLabel,
|
||||
requireGatewayAccess
|
||||
} from '@/utils/business/gateway'
|
||||
|
||||
export function useGatewayOptions() {
|
||||
const options = ref<GatewayOptions>({
|
||||
error_categories: [],
|
||||
exempt_sources: [],
|
||||
gateway_operations: [],
|
||||
match_types: [],
|
||||
rate_limit_modes: [],
|
||||
stop_resume_actions: [],
|
||||
stop_resume_results: []
|
||||
})
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
const ready = ref(false)
|
||||
let active = true
|
||||
async function load() {
|
||||
if (loading.value) return
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = gatewayData(await GatewayService.getOptions())
|
||||
if (!active) return
|
||||
// 不用空数组掩盖异常契约。
|
||||
for (const key of Object.keys(options.value) as (keyof GatewayOptions)[]) {
|
||||
if (!Array.isArray(data[key])) throw new Error(`枚举响应缺少 ${key}`)
|
||||
}
|
||||
options.value = data
|
||||
ready.value = true
|
||||
} catch (cause) {
|
||||
if (active) {
|
||||
error.value = gatewayError(cause)
|
||||
ready.value = false
|
||||
}
|
||||
} finally {
|
||||
if (active) loading.value = false
|
||||
}
|
||||
}
|
||||
onMounted(load)
|
||||
onBeforeUnmount(() => {
|
||||
active = false
|
||||
})
|
||||
const label = (key: keyof GatewayOptions, value?: string | null) =>
|
||||
gatewayLabel(options.value[key], value)
|
||||
return { options, error, loading, ready, load, label }
|
||||
}
|
||||
|
||||
export function useGatewayList<T>(
|
||||
request: (pagination: PaginationParams) => Promise<PaginationResponse<T>>,
|
||||
allowed: () => boolean
|
||||
) {
|
||||
const rows = shallowRef<T[]>([])
|
||||
const total = ref(0)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const pagination = reactive({ page: 1, page_size: 20 })
|
||||
let sequence = 0
|
||||
const canRead = computed(allowed)
|
||||
async function load() {
|
||||
const current = ++sequence
|
||||
error.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
requireGatewayAccess(canRead.value)
|
||||
const data = gatewayData(await request({ ...pagination }))
|
||||
if (current !== sequence) return
|
||||
rows.value = data.items || []
|
||||
total.value = data.total
|
||||
pagination.page = data.page
|
||||
pagination.page_size = data.size
|
||||
} catch (cause) {
|
||||
if (current !== sequence) return
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = gatewayError(cause)
|
||||
} finally {
|
||||
if (current === sequence) loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
pagination.page = 1
|
||||
return load()
|
||||
}
|
||||
function resize() {
|
||||
pagination.page = 1
|
||||
return load()
|
||||
}
|
||||
function clear() {
|
||||
++sequence
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
error.value = ''
|
||||
loading.value = false
|
||||
}
|
||||
onBeforeUnmount(clear)
|
||||
watch(canRead, (allowed) => {
|
||||
clear()
|
||||
if (allowed) void load()
|
||||
else error.value = '无权查看此页面'
|
||||
})
|
||||
return { rows, total, pagination, loading, error, load, search, resize, clear, canRead }
|
||||
}
|
||||
|
||||
export function useGatewayColumns<T extends { prop: string; label: string }>(definitions: T[]) {
|
||||
const columnChecks = ref(definitions.map((column) => ({ ...column, checked: true })))
|
||||
const showColumn = (prop: string) =>
|
||||
columnChecks.value.some((column) => column.prop === prop && column.checked)
|
||||
const columns = computed(() =>
|
||||
columnChecks.value
|
||||
.filter((column) => column.checked && column.prop !== 'operation')
|
||||
.map((column) => definitions.find((definition) => definition.prop === column.prop)!)
|
||||
)
|
||||
return { columnChecks, showColumn, columns }
|
||||
}
|
||||
|
||||
/** 所有网关页面共用按运营商名称搜索的账户候选,不把名称提交成 carrier_id。 */
|
||||
export function useGatewayCarriers(loadOnMount = true) {
|
||||
const candidates = ref<{ value: number; label: string }[]>([])
|
||||
const remembered = ref<{ value: number; label: string }[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
let sequence = 0
|
||||
function remember(id: number | null | undefined, name?: string) {
|
||||
if (id == null || !name) return
|
||||
remembered.value = [
|
||||
...remembered.value.filter((option) => option.value !== id),
|
||||
{ value: id, label: name }
|
||||
]
|
||||
}
|
||||
function select(value: unknown) {
|
||||
const id = Number(value)
|
||||
if (value == null || value === '' || !Number.isSafeInteger(id)) return
|
||||
const selected = options.value.find((option) => option.value === id)
|
||||
if (selected) remember(selected.value, selected.label)
|
||||
}
|
||||
const options = computed(() => {
|
||||
const values = new Map(remembered.value.map((option) => [option.value, option]))
|
||||
candidates.value.forEach((option) => values.set(option.value, option))
|
||||
return [...values.values()]
|
||||
})
|
||||
async function search(query = '') {
|
||||
const current = ++sequence
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = gatewayData(
|
||||
await CarrierService.getCarriers({ page: 1, page_size: 20, carrier_name: query.trim() })
|
||||
)
|
||||
if (current !== sequence) return
|
||||
if (!Array.isArray(data.items)) throw new Error('运营商账户响应缺少 items')
|
||||
candidates.value = data.items.map((carrier) => ({
|
||||
value: carrier.id,
|
||||
label: carrier.carrier_name
|
||||
}))
|
||||
} catch (cause) {
|
||||
if (current === sequence) {
|
||||
error.value = gatewayError(cause)
|
||||
candidates.value = []
|
||||
}
|
||||
} finally {
|
||||
if (current === sequence) loading.value = false
|
||||
}
|
||||
}
|
||||
const label = (id: number) =>
|
||||
options.value.find((option) => option.value === id)?.label || `运营商账户(${id})`
|
||||
onMounted(() => {
|
||||
if (loadOnMount) void search()
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
++sequence
|
||||
})
|
||||
return { options, loading, error, search, remember, select, label }
|
||||
}
|
||||
12
src/config/constants/gateway.ts
Normal file
12
src/config/constants/gateway.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const GATEWAY_PERMISSIONS = {
|
||||
records: { page: 'card_stop_resume_record:page' },
|
||||
rules: { page: 'gateway_error_classification:page', test: 'gateway_error_classification:test' },
|
||||
groups: {
|
||||
page: 'gateway_rate_limit_group:page',
|
||||
detailPage: 'gateway_rate_limit_group:detail_page',
|
||||
detail: 'gateway_rate_limit_group:detail'
|
||||
},
|
||||
stats: { page: 'gateway_call_stats:page', trend: 'gateway_call_stats:trend' },
|
||||
cardHistory: 'iot_info:stop_resume_records',
|
||||
deviceCardHistory: 'device_info:stop_resume_records'
|
||||
} as const
|
||||
@@ -4,6 +4,7 @@ import { BULK_PURCHASE_PERMISSIONS } from '@/config/constants/bulkPurchase'
|
||||
import { JULY_PERMISSIONS } from '@/config/constants/julyIteration'
|
||||
import { AUDIT_PERMISSIONS } from '@/config/constants/audit'
|
||||
import { AUGUST_PERMISSIONS } from '@/config/constants/augustIteration'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import { PAYMENT_MERCHANT_POOL_PERMISSIONS } from '@/config/constants/paymentMerchantPools'
|
||||
import {
|
||||
EXPORT_TASK_DETAIL_PAGE_PERMISSION,
|
||||
@@ -1347,6 +1348,57 @@ export const asyncRoutes: AppRouteRecord[] = [
|
||||
keepAlive: true,
|
||||
permissions: [AUGUST_PERMISSIONS.pollingPriorityQueue.page]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'stop-resume-records',
|
||||
name: 'GatewayStopResumeRecords',
|
||||
component: RoutesAlias.GatewayStopResumeRecords,
|
||||
meta: {
|
||||
title: '停复机记录',
|
||||
keepAlive: true,
|
||||
permissions: [GATEWAY_PERMISSIONS.records.page]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'error-classifications',
|
||||
name: 'GatewayErrorClassifications',
|
||||
component: RoutesAlias.GatewayErrorClassifications,
|
||||
meta: {
|
||||
title: '上游错误分类',
|
||||
keepAlive: true,
|
||||
permissions: [GATEWAY_PERMISSIONS.rules.page]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'rate-limit-groups',
|
||||
name: 'GatewayRateLimitGroups',
|
||||
component: RoutesAlias.GatewayRateLimitGroups,
|
||||
meta: {
|
||||
title: '网关限流组',
|
||||
keepAlive: true,
|
||||
permissions: [GATEWAY_PERMISSIONS.groups.page]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'gateway-stats',
|
||||
name: 'GatewayCallStats',
|
||||
component: RoutesAlias.GatewayCallStats,
|
||||
meta: {
|
||||
title: '网关调用统计',
|
||||
keepAlive: true,
|
||||
permissions: [GATEWAY_PERMISSIONS.stats.page]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'rate-limit-groups/detail/:id',
|
||||
name: 'GatewayRateLimitGroupDetail',
|
||||
component: RoutesAlias.GatewayRateLimitGroupDetail,
|
||||
meta: {
|
||||
title: '网关限流组详情',
|
||||
isHide: true,
|
||||
keepAlive: false,
|
||||
permissions: [GATEWAY_PERMISSIONS.groups.detailPage]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -144,6 +144,11 @@ export enum RoutesAlias {
|
||||
ManualTrigger = '/polling-management/manual-trigger', // 手动触发
|
||||
PollingMonitor = '/polling-management/monitor', // 轮询监控
|
||||
PollingPriorityQueue = '/polling-management/priority-queue', // 优先队列
|
||||
GatewayStopResumeRecords = '/polling-management/stop-resume-records',
|
||||
GatewayErrorClassifications = '/polling-management/error-classifications',
|
||||
GatewayRateLimitGroups = '/polling-management/rate-limit-groups',
|
||||
GatewayRateLimitGroupDetail = '/polling-management/rate-limit-groups/detail',
|
||||
GatewayCallStats = '/polling-management/gateway-stats',
|
||||
|
||||
// 公共组件
|
||||
Success = '/result/success', // 成功
|
||||
|
||||
129
src/types/api/gateway.ts
Normal file
129
src/types/api/gateway.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import type { PaginationParams } from './common'
|
||||
|
||||
export interface GatewayOption {
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface GatewayOptions {
|
||||
error_categories: GatewayOption[]
|
||||
exempt_sources: GatewayOption[]
|
||||
gateway_operations: GatewayOption[]
|
||||
match_types: GatewayOption[]
|
||||
rate_limit_modes: GatewayOption[]
|
||||
stop_resume_actions: GatewayOption[]
|
||||
stop_resume_results: GatewayOption[]
|
||||
}
|
||||
|
||||
export interface StopResumeRecord {
|
||||
id: number
|
||||
card_id: number
|
||||
carrier_id: number
|
||||
iccid: string
|
||||
action: string
|
||||
action_name?: string
|
||||
attempt: number
|
||||
command_id: string
|
||||
created_at: string
|
||||
duration_ms: number
|
||||
error_category: string
|
||||
error_category_name?: string
|
||||
provider_code: string
|
||||
provider_message: string
|
||||
reason: string
|
||||
result: string
|
||||
scene: string
|
||||
source: string
|
||||
}
|
||||
|
||||
export interface CardStopResumeQuery extends PaginationParams {
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
}
|
||||
|
||||
export interface StopResumeQuery extends CardStopResumeQuery {
|
||||
start_time: string
|
||||
end_time: string
|
||||
iccid?: string
|
||||
carrier_id?: number
|
||||
action?: string
|
||||
source?: string
|
||||
result?: string
|
||||
error_category?: string
|
||||
}
|
||||
|
||||
export interface GatewayRuleInput {
|
||||
category: string
|
||||
keyword: string
|
||||
match_type: string
|
||||
maybe_accepted?: boolean
|
||||
operations?: string[]
|
||||
priority?: number
|
||||
remark?: string
|
||||
status?: number
|
||||
}
|
||||
|
||||
export interface GatewayRule extends GatewayRuleInput {
|
||||
id: number
|
||||
category_name?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface GatewayRuleQuery extends PaginationParams {
|
||||
category?: string
|
||||
status?: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface GatewayRuleTestInput {
|
||||
operation: string
|
||||
message: string
|
||||
draft?: GatewayRuleInput
|
||||
}
|
||||
|
||||
export interface GatewayRuleTestResult {
|
||||
matched: boolean
|
||||
rule_id: number
|
||||
category: string
|
||||
category_name: string
|
||||
keyword: string
|
||||
maybe_accepted: boolean
|
||||
}
|
||||
|
||||
export interface GatewayGroupInput {
|
||||
carrier_id?: number | null
|
||||
group_code: string
|
||||
group_name: string
|
||||
max_qps: number
|
||||
operations: string[]
|
||||
high_priority_operations?: string[]
|
||||
reserved_qps?: number
|
||||
status?: number
|
||||
}
|
||||
|
||||
export interface GatewayGroup extends GatewayGroupInput {
|
||||
id: number
|
||||
carrier_name?: string
|
||||
status_name?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface GatewayGroupQuery extends PaginationParams {
|
||||
carrier_id?: number
|
||||
only_global?: boolean
|
||||
status?: number
|
||||
}
|
||||
|
||||
// 文档没有定义数组内部字段,保留真实结构,不假定指标名称。
|
||||
export interface GatewayCarrierStats {
|
||||
minutes: number
|
||||
mode: string
|
||||
carriers: unknown[]
|
||||
}
|
||||
|
||||
export interface GatewayCarrierTrend {
|
||||
carrier_id: number
|
||||
points: unknown[]
|
||||
}
|
||||
@@ -158,3 +158,4 @@ export * from './assetWallet'
|
||||
|
||||
// 运营报表相关
|
||||
export * from './operationsReport'
|
||||
export * from './gateway'
|
||||
|
||||
4
src/types/components.d.ts
vendored
4
src/types/components.d.ts
vendored
@@ -148,6 +148,9 @@ declare module 'vue' {
|
||||
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||
ElWatermark: typeof import('element-plus/es')['ElWatermark']
|
||||
ExportTaskCreateDialog: typeof import('./../components/business/ExportTaskCreateDialog.vue')['default']
|
||||
GatewayDynamicData: typeof import('./../components/business/gateway/GatewayDynamicData.vue')['default']
|
||||
GatewayOptionsNotice: typeof import('./../components/business/gateway/GatewayOptionsNotice.vue')['default']
|
||||
GatewayRuleFields: typeof import('./../components/business/gateway/GatewayRuleFields.vue')['default']
|
||||
HorizontalSubmenu: typeof import('./../components/core/layouts/art-menus/art-horizontal-menu/widget/HorizontalSubmenu.vue')['default']
|
||||
ImportDialog: typeof import('./../components/business/ImportDialog.vue')['default']
|
||||
LoginLeftView: typeof import('./../components/core/views/login/LoginLeftView.vue')['default']
|
||||
@@ -169,6 +172,7 @@ declare module 'vue' {
|
||||
ShopCreditLimitDialog: typeof import('./../components/business/ShopCreditLimitDialog.vue')['default']
|
||||
SidebarSubmenu: typeof import('./../components/core/layouts/art-menus/art-sidebar-menu/widget/SidebarSubmenu.vue')['default']
|
||||
SpeedLimitDialog: typeof import('./../components/device/SpeedLimitDialog.vue')['default']
|
||||
StopResumeRecords: typeof import('./../components/business/gateway/StopResumeRecords.vue')['default']
|
||||
SwitchCardDialog: typeof import('./../components/device/SwitchCardDialog.vue')['default']
|
||||
TableContextMenuHint: typeof import('./../components/core/others/TableContextMenuHint.vue')['default']
|
||||
ThemeSettings: typeof import('./../components/core/layouts/art-settings-panel/widget/ThemeSettings.vue')['default']
|
||||
|
||||
122
src/utils/business/gateway.ts
Normal file
122
src/utils/business/gateway.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import type { BaseResponse } from '@/types/api/common'
|
||||
import type { GatewayGroupInput, GatewayRuleInput, GatewayOption } from '@/types/api/gateway'
|
||||
import { formatDateTime } from './format'
|
||||
|
||||
export function gatewayData<T>(response: BaseResponse<T>): T {
|
||||
if (response.code !== 0) throw new Error(response.msg || response.message || '请求失败')
|
||||
return response.data
|
||||
}
|
||||
|
||||
export function gatewayError(error: unknown): string {
|
||||
return error instanceof Error ? error.message : '请求失败,请重试'
|
||||
}
|
||||
|
||||
export function requireGatewayAccess(allowed: boolean): void {
|
||||
if (!allowed) throw new Error('无权执行此操作')
|
||||
}
|
||||
|
||||
export function compactGatewayQuery<T extends object>(query: T): T {
|
||||
return Object.fromEntries(
|
||||
Object.entries(query).filter(
|
||||
([, value]) => value !== '' && value !== null && value !== undefined
|
||||
)
|
||||
) as T
|
||||
}
|
||||
|
||||
export function validateGatewayInteger(value: unknown, min: number, max: number, label: string) {
|
||||
if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max) {
|
||||
throw new Error(`${label}须为 ${min}–${max} 的整数`)
|
||||
}
|
||||
}
|
||||
|
||||
export function gatewayOptionalId(value: unknown): number | undefined {
|
||||
if (value === undefined || value === null || value === '') return undefined
|
||||
const id = Number(value)
|
||||
validateGatewayInteger(id, 0, Number.MAX_SAFE_INTEGER, '运营商账户 ID')
|
||||
return id
|
||||
}
|
||||
|
||||
export function gatewayTimeRange(range: unknown, required = true) {
|
||||
if ((!Array.isArray(range) || range.length === 0) && !required) return {}
|
||||
if (!Array.isArray(range) || range.length !== 2 || range.some((value) => !value)) {
|
||||
throw new Error('请选择完整的开始和结束时间')
|
||||
}
|
||||
const start = new Date(range[0]).getTime()
|
||||
const end = new Date(range[1]).getTime()
|
||||
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) {
|
||||
throw new Error('时间范围无效,结束时间不得早于开始时间')
|
||||
}
|
||||
if (end - start > 31 * 86400000) throw new Error('时间跨度不能超过 31 天')
|
||||
return { start_time: new Date(start).toISOString(), end_time: new Date(end).toISOString() }
|
||||
}
|
||||
|
||||
export function recentGatewayRange(): [Date, Date] {
|
||||
const end = new Date()
|
||||
return [new Date(end.getTime() - 7 * 86400000), end]
|
||||
}
|
||||
|
||||
function requiredText(value: string, max: number, label: string) {
|
||||
if (!value?.trim() || value.length > max) throw new Error(`${label}必填且不能超过 ${max} 字符`)
|
||||
}
|
||||
|
||||
export function validateGatewayRule(data: GatewayRuleInput) {
|
||||
requiredText(data.category, 100, '错误分类')
|
||||
requiredText(data.keyword, 200, '关键字或正则')
|
||||
requiredText(data.match_type, 100, '匹配方式')
|
||||
if (data.priority !== undefined) validateGatewayInteger(data.priority, 1, 10000, '优先级')
|
||||
if ((data.remark?.length || 0) > 500) throw new Error('备注不能超过 500 字符')
|
||||
}
|
||||
|
||||
export function validateGatewayGroup(data: GatewayGroupInput) {
|
||||
requiredText(data.group_code, 50, '组标识')
|
||||
requiredText(data.group_name, 100, '组名称')
|
||||
validateGatewayInteger(data.max_qps, 1, 10000, '每秒请求上限')
|
||||
const reserved = data.reserved_qps ?? 0
|
||||
validateGatewayInteger(reserved, 0, data.max_qps - 1, '预留额度')
|
||||
if (!data.operations.length) throw new Error('请至少选择一个组内操作')
|
||||
const high = data.high_priority_operations || []
|
||||
if (high.some((operation) => !data.operations.includes(operation))) {
|
||||
throw new Error('高优先级操作必须属于组内操作')
|
||||
}
|
||||
if (reserved > 0 && !high.length) throw new Error('设置预留额度时必须选择高优先级操作')
|
||||
if (data.carrier_id != null) {
|
||||
validateGatewayInteger(data.carrier_id, 0, Number.MAX_SAFE_INTEGER, '运营商账户 ID')
|
||||
}
|
||||
}
|
||||
|
||||
export function gatewayLabel(options: GatewayOption[] = [], value?: string | null): string {
|
||||
return options.find((option) => option.value === value)?.label || value || '-'
|
||||
}
|
||||
|
||||
export function gatewayValue(value: unknown): string {
|
||||
if (value === undefined || value === null || value === '') return '-'
|
||||
return typeof value === 'object' ? JSON.stringify(value) : String(value)
|
||||
}
|
||||
|
||||
export function gatewayRows(values: unknown[]): Record<string, unknown>[] {
|
||||
return values.map((value) =>
|
||||
value !== null && typeof value === 'object' && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: { value }
|
||||
)
|
||||
}
|
||||
|
||||
/** 与店铺列表统一:展示 YYYY-MM-DD HH:mm:ss,原始响应与请求不改写。 */
|
||||
export function gatewayDisplayValue(value: unknown, key = ''): string {
|
||||
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}/.test(value)) {
|
||||
return formatDateTime(value)
|
||||
}
|
||||
if (typeof value === 'number' && /(?:^|_)(?:at|time|timestamp)$/.test(key)) {
|
||||
return formatDateTime(value)
|
||||
}
|
||||
if (value !== null && typeof value === 'object') {
|
||||
return JSON.stringify(value, (field, nested) =>
|
||||
typeof nested === 'string' && /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}/.test(nested)
|
||||
? formatDateTime(nested)
|
||||
: typeof nested === 'number' && /(?:^|_)(?:at|time|timestamp)$/.test(field)
|
||||
? formatDateTime(nested)
|
||||
: nested
|
||||
)
|
||||
}
|
||||
return gatewayValue(value)
|
||||
}
|
||||
@@ -9,6 +9,22 @@
|
||||
</ElTag>
|
||||
</div>
|
||||
<div class="card-header-right">
|
||||
<ElButton
|
||||
v-if="
|
||||
cardInfo?.asset_type === 'card' &&
|
||||
Number.isInteger(cardInfo.asset_id) &&
|
||||
hasAuth('iot_info:stop_resume_records')
|
||||
"
|
||||
type="primary"
|
||||
link
|
||||
@click="
|
||||
emit('showStopResumeRecords', {
|
||||
cardId: cardInfo.asset_id,
|
||||
iccid: cardInfo.iccid || cardInfo.identifier
|
||||
})
|
||||
"
|
||||
>停复机记录</ElButton
|
||||
>
|
||||
<ElButton v-if="auditTarget" type="primary" link @click="openAssetAudit">
|
||||
{{ isSubjectActivityView ? '活动记录' : '审计记录' }}
|
||||
</ElButton>
|
||||
@@ -485,6 +501,17 @@
|
||||
</div>
|
||||
|
||||
<div class="binding-card-actions">
|
||||
<ElButton
|
||||
v-if="bindingCard.card_id != null && hasAuth('device_info:stop_resume_records')"
|
||||
type="primary"
|
||||
@click="
|
||||
emit('showStopResumeRecords', {
|
||||
cardId: bindingCard.card_id,
|
||||
iccid: bindingCard.iccid
|
||||
})
|
||||
"
|
||||
>停复机记录</ElButton
|
||||
>
|
||||
<ElButton
|
||||
v-if="bindingCard.network_status === 0 && hasAuth('iot_info:start')"
|
||||
type="success"
|
||||
@@ -910,6 +937,7 @@
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'showStopResumeRecords', payload: { cardId: number; iccid: string }): void
|
||||
(e: 'update:pollingEnabled', value: boolean): void
|
||||
(e: 'enableCard'): void
|
||||
(e: 'disableCard'): void
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
@show-set-wifi="showSetWiFiDialog"
|
||||
@show-realname-policy="showRealnamePolicyDialog"
|
||||
@show-speed-limit="speedLimitDialogVisible = true"
|
||||
@show-stop-resume-records="showStopResumeRecords"
|
||||
@show-update-realname-status="showUpdateRealnameStatusDialog"
|
||||
@enable-binding-card="handleEnableBindingCard"
|
||||
@disable-binding-card="handleDisableBindingCard"
|
||||
@@ -109,6 +110,19 @@
|
||||
</ElCard>
|
||||
|
||||
<!-- 对话框组件 -->
|
||||
<ElDialog
|
||||
v-model="stopResumeVisible"
|
||||
:title="`停复机记录:${stopResumeTarget?.iccid || ''}`"
|
||||
width="min(1200px, 96vw)"
|
||||
destroy-on-close
|
||||
>
|
||||
<StopResumeRecords
|
||||
v-if="stopResumeVisible && stopResumeTarget"
|
||||
:key="stopResumeTarget.cardId"
|
||||
:card-id="stopResumeTarget.cardId"
|
||||
:permission="stopResumePermission"
|
||||
/>
|
||||
</ElDialog>
|
||||
<SwitchCardDialog
|
||||
v-model="switchCardDialogVisible"
|
||||
:device-info="cardInfo?.virtual_no || ''"
|
||||
@@ -183,6 +197,8 @@
|
||||
import { CardService, DeviceService } from '@/api/modules'
|
||||
import { JULY_PERMISSIONS } from '@/config/constants'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { GATEWAY_PERMISSIONS } from '@/config/constants/gateway'
|
||||
import StopResumeRecords from '@/components/business/gateway/StopResumeRecords.vue'
|
||||
import {
|
||||
formatRemainingTime,
|
||||
FrontendRateLimitError,
|
||||
@@ -285,6 +301,40 @@
|
||||
const rechargeDialogVisible = ref(false)
|
||||
const dailyRecordsDialogVisible = ref(false)
|
||||
const orderHistoryDialogVisible = ref(false)
|
||||
const stopResumeVisible = ref(false)
|
||||
const stopResumeTarget = ref<{ cardId: number; iccid: string } | null>(null)
|
||||
const stopResumePermission = computed(() =>
|
||||
cardInfo.value?.asset_type === 'card'
|
||||
? GATEWAY_PERMISSIONS.cardHistory
|
||||
: GATEWAY_PERMISSIONS.deviceCardHistory
|
||||
)
|
||||
function showStopResumeRecords(target: { cardId: number; iccid: string }) {
|
||||
if (
|
||||
!hasAuth(stopResumePermission.value) ||
|
||||
!Number.isInteger(target.cardId) ||
|
||||
target.cardId < 0
|
||||
)
|
||||
return
|
||||
const asset = cardInfo.value
|
||||
const belongsToAsset =
|
||||
asset?.asset_type === 'card'
|
||||
? target.cardId === asset.asset_id
|
||||
: asset?.cards?.some(
|
||||
(card: { card_id: number; iccid: string }) =>
|
||||
card.card_id === target.cardId && card.iccid === target.iccid
|
||||
)
|
||||
if (!belongsToAsset) return
|
||||
stopResumeTarget.value = { ...target }
|
||||
stopResumeVisible.value = true
|
||||
}
|
||||
watch(
|
||||
() =>
|
||||
`${cardInfo.value?.asset_type}:${cardInfo.value?.asset_id}:${cardInfo.value?.identifier}:${JSON.stringify(cardInfo.value?.cards?.map((card: { card_id?: number; iccid: string }) => [card.card_id, card.iccid]))}`,
|
||||
() => {
|
||||
stopResumeVisible.value = false
|
||||
stopResumeTarget.value = null
|
||||
}
|
||||
)
|
||||
const realnamePolicyDialogVisible = ref(false)
|
||||
const updateRealnameStatusDialogVisible = ref(false)
|
||||
const selectedPackageUsageId = ref<number | null>(null)
|
||||
@@ -598,7 +648,9 @@
|
||||
*/
|
||||
const handleBindingCardRealnameStatusSuccess = async () => {
|
||||
if (bindingCardRealnameStatusAsset && cardInfo.value === bindingCardRealnameStatusAsset) {
|
||||
await fetchAssetDetail(bindingCardRealnameStatusAsset.identifier, { preservePackageList: true })
|
||||
await fetchAssetDetail(bindingCardRealnameStatusAsset.identifier, {
|
||||
preservePackageList: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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