Issue#6·B3: 通道配置列表页实装(契约 #p-acct 表格范式 1:1)——单卡一体:筛选区(搜索!w-56+协议/状态 select+搜索/重置+已选N)+8 列原生 table(CM/SM/SG/HT 彩色圆徽+名称+ID/协议 badge/host:port mono/速率·连接右对齐/上家/状态 badge/操作)+分页条(共N条+页码窗口);操作=编辑(→/channel/edit/:id,B2 编辑页入口断链接通)/测试发送(契约 dialog 范式弹窗,/channels/{id}/test 真实下发+手机号校验)/启停切换(update status);「+ 新建通道」→/channel/edit;验收=vue-tsc 0+Chrome 冒烟 6/6(侧栏入口/8 列真实数据/新建入口/行内编辑跳转/弹窗/校验)

This commit is contained in:
2026-11-18 10:58:18 +08:00
parent a020c8b3a3
commit fb72eb1739
2 changed files with 261 additions and 1 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ export const asyncRoutes: RouteRecordRaw[] = [
{ path: 'record/repush', name: 'record-repush', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '回执工具', icon: 'i-refresh', menu: true, group: '记录中心', roles: ['admin', 'ops', 'service'] } },
{ path: 'record/history', name: 'record-history', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '历史记录', menu: false, group: '记录中心', roles: ['admin', 'ops', 'service', 'group', 'customer'] } },
{ path: 'channel', name: 'channel', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '通道配置', icon: 'i-layer', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
{ path: 'channel', name: 'channel', component: () => import('@/views/channel/ChannelList.vue'), meta: { title: '通道配置', icon: 'i-layer', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
{ path: 'channel/upstream', name: 'channel-upstream', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '上家管理', icon: 'i-srv', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
{ path: 'channel/edit/:id?', name: 'channel-edit', component: () => import('@/views/channel/ChannelEdit.vue'), meta: { title: '通道编辑', group: '通道与策略', roles: ['admin', 'ops'] } },
{ path: 'channel/group', name: 'channel-group', component: () => import('@/views/coming/ComingSoon.vue'), meta: { title: '通道组路由', icon: 'i-route', menu: true, group: '通道与策略', roles: ['admin', 'ops'] } },
+260
View File
@@ -0,0 +1,260 @@
<template>
<!-- 契约表格范式(#p-acct 单卡一体 1:1):筛选区 border-b+原生 table+分页条;入口页,行内编辑接 /channel/edit -->
<div>
<div class="page-header flex items-end justify-between">
<div>
<h2 class="page-title">通道配置</h2>
<p class="page-description">{{ total }} 条通道 · {{ runningHint }}</p>
</div>
<router-link to="/channel/edit" class="btn btn-primary">+ 新建通道</router-link>
</div>
<div class="card">
<!-- 筛选区 -->
<div class="flex flex-wrap items-center gap-2 border-b border-gray-100 p-4 dark:border-dark-700">
<input v-model="filterName" class="input !w-56" placeholder="搜索通道名称 / 接入码" @keyup.enter="search" />
<select v-model="filterProtocol" class="input !w-32">
<option value="">协议:全部</option>
<option value="cmpp">CMPP</option>
<option value="smpp">SMPP</option>
<option value="sgip">SGIP</option>
<option value="http">HTTP</option>
</select>
<select v-model="filterStatus" class="input !w-32">
<option value="">状态:全部</option>
<option value="1">在营</option>
<option value="0">停用</option>
</select>
<button class="btn btn-primary" @click="search">搜索</button>
<button class="btn btn-secondary" @click="reset">重置</button>
<span class="ml-auto text-xs text-gray-400">已选 {{ selected.size }} 项</span>
</div>
<!-- 表格 -->
<div class="table-container m-4 mt-0 border-0">
<table class="table">
<thead>
<tr>
<th><input type="checkbox" class="accent-primary-600" :checked="allChecked" @change="toggleAll" /></th>
<th>通道</th><th>协议</th><th>接入地址</th>
<th class="text-right">速率 / 连接</th><th>上家</th>
<th>状态</th><th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="c in rows" :key="c.id" :class="selected.has(c.id) ? 'bg-gray-50 dark:bg-dark-800/30' : ''">
<td><input type="checkbox" class="accent-primary-600" :checked="selected.has(c.id)" @change="toggle(c.id)" /></td>
<td>
<span class="flex items-center gap-2 font-medium" :class="c.status === 1 ? 'text-gray-900 dark:text-white' : 'text-gray-500'">
<span class="flex h-7 w-7 items-center justify-center rounded-lg text-xs font-bold" :class="badgeClass(c)">{{ protoShort(c.protocol) }}</span>
{{ c.name }} <span class="text-xs text-gray-400">{{ c.id }}</span>
</span>
</td>
<td><span class="badge badge-gray">{{ protoLabel(c) }}</span></td>
<td><span class="font-mono text-xs text-gray-500">{{ c.host }}:{{ c.port }}</span></td>
<td class="text-right font-medium">{{ c.speed }} 条/s <span class="text-xs text-gray-400">· {{ c.conn_count }} 连接</span></td>
<td class="text-gray-500">{{ c.upstream_name || '—' }}</td>
<td><span class="badge" :class="c.status === 1 ? 'badge-success' : 'badge-gray'">{{ c.status === 1 ? '在营' : '停用' }}</span></td>
<td class="text-right">
<router-link :to="`/channel/edit/${c.id}`" class="cursor-pointer text-sm text-primary-600 hover:underline">编辑</router-link>
<button class="cursor-pointer text-sm text-primary-600 hover:underline" @click="openTest(c)">测试</button>
<button class="cursor-pointer text-sm hover:underline" :class="c.status === 1 ? 'text-amber-600' : 'text-emerald-600'" @click="toggleStatus(c)">
{{ c.status === 1 ? '停用' : '启用' }}
</button>
</td>
</tr>
<tr v-if="!loading && rows.length === 0">
<td colspan="8" class="py-10 text-center text-sm text-gray-400">无匹配通道</td>
</tr>
</tbody>
</table>
</div>
<!-- 分页条 -->
<div class="flex items-center justify-between border-t border-gray-100 px-4 py-3 text-sm text-gray-500 dark:border-dark-700">
<span>共 {{ total }} 条记录</span>
<div class="flex items-center gap-1">
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page <= 1" @click="goPage(page - 1)">◀</button>
<button v-for="p in pageButtons" :key="p" class="rounded-xl px-3.5 py-2 text-sm" :class="p === page ? 'bg-primary-600 font-medium text-white' : 'text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800'" @click="goPage(p)">{{ p }}</button>
<span v-if="showEllipsis" class="px-1 text-gray-400">…</span>
<button class="rounded-xl px-3.5 py-2 text-sm text-gray-500 hover:bg-gray-100 dark:hover:bg-dark-800" :disabled="page >= lastPage" @click="goPage(page + 1)">▶</button>
</div>
</div>
</div>
<!-- 测试发送弹窗(契约 dialog 范式:dialog-overlay/container/header/body/footer) -->
<div v-if="testTarget" class="dialog-overlay" @click.self="closeTest">
<div class="dialog-container max-w-md">
<div class="dialog-header">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">测试发送</h3>
<button class="btn-ghost btn-icon" @click="closeTest"><svg class="h-5 w-5"><use href="#i-x" /></svg></button>
</div>
<div class="dialog-body space-y-4">
<p class="text-xs text-gray-500">通道 {{ testTarget.name }} · {{ protoLabel(testTarget) }} · 真实下发一条测试短信</p>
<div>
<label class="input-label">接收手机号 <span class="text-red-500">*</span></label>
<input v-model="testMobile" class="input" placeholder="13800138000" />
</div>
<div>
<label class="input-label">短信内容 <span class="text-red-500">*</span></label>
<textarea v-model="testContent" rows="3" class="input" placeholder="【签名】测试内容"></textarea>
</div>
<div v-if="testResult" class="rounded-xl border-l-4 p-3 text-sm" :class="testResult.ok ? 'border-emerald-500 bg-emerald-50 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-300' : 'border-red-500 bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300'">
{{ testResult.msg }}
</div>
</div>
<div class="dialog-footer">
<button class="btn btn-secondary" @click="closeTest">取消</button>
<button class="btn btn-primary" :disabled="testing" @click="sendTest">{{ testing ? '发送中…' : '发送' }}</button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { channelApi, type Channel } from '@/api/channel'
// Issue#2 keep-alive 锚点:组件名=路由名
defineOptions({ name: 'channel' })
const rows = ref<Channel[]>([])
const total = ref(0)
const page = ref(1)
const pageSize = 10
const loading = ref(false)
const selected = reactive(new Set<number>())
const filterName = ref('')
const filterProtocol = ref('')
const filterStatus = ref('')
const query = reactive({ name: '', protocol: '', status: '' })
const lastPage = computed(() => Math.max(1, Math.ceil(total.value / pageSize)))
const allChecked = computed(() => rows.value.length > 0 && rows.value.every((c) => selected.has(c.id)))
const showEllipsis = computed(() => lastPage.value > 5)
const pageButtons = computed(() => {
const last = lastPage.value
const btns: number[] = []
const from = Math.max(1, Math.min(page.value - 1, last - 4))
for (let p = from; p <= Math.min(last, from + 4); p++) btns.push(p)
return btns
})
const runningHint = computed(() => `${rows.value.filter((c) => c.status === 1).length} 在营(本页)`)
async function load() {
loading.value = true
try {
const res = await channelApi.list({
page: page.value,
page_size: pageSize,
...(query.name ? { name: query.name } : {}),
...(query.protocol ? { protocol: query.protocol } : {}),
...(query.status !== '' ? { status: query.status } : {}),
})
rows.value = res.list
total.value = res.total
} catch {
rows.value = []
total.value = 0
} finally {
loading.value = false
}
}
function search() {
query.name = filterName.value.trim()
query.protocol = filterProtocol.value
query.status = filterStatus.value
page.value = 1
void load()
}
function reset() {
filterName.value = ''
filterProtocol.value = ''
filterStatus.value = ''
search()
}
function goPage(p: number) {
if (p < 1 || p > lastPage.value) return
page.value = p
void load()
}
function toggle(id: number) {
if (selected.has(id)) selected.delete(id)
else selected.add(id)
}
function toggleAll() {
if (allChecked.value) rows.value.forEach((c) => selected.delete(c.id))
else rows.value.forEach((c) => selected.add(c.id))
}
async function toggleStatus(c: Channel) {
const next = c.status === 1 ? 0 : 1
try {
await channelApi.update(c.id, { status: next })
c.status = next
} catch (e) {
testResult.value = { ok: false, msg: e instanceof Error ? e.message : '操作失败' }
}
}
// ---- 测试发送弹窗 ----
const testTarget = ref<Channel | null>(null)
const testMobile = ref('')
const testContent = ref('')
const testing = ref(false)
const testResult = ref<{ ok: boolean; msg: string } | null>(null)
function openTest(c: Channel) {
testTarget.value = c
testMobile.value = ''
testContent.value = '【测试】通道连通性验证'
testResult.value = null
}
function closeTest() {
testTarget.value = null
}
async function sendTest() {
if (!testTarget.value || !/^1\d{10}$/.test(testMobile.value.trim())) {
testResult.value = { ok: false, msg: '请输入正确的 11 位手机号' }
return
}
if (!testContent.value.trim()) {
testResult.value = { ok: false, msg: '短信内容必填' }
return
}
testing.value = true
testResult.value = null
try {
const r = await channelApi.test(testTarget.value.id, { mobile: testMobile.value.trim(), content: testContent.value.trim() })
testResult.value = { ok: true, msg: `已提交 · MsgID ${r.message_id} · 协议 ${r.protocol} · 耗时 ${r.elapsed_ms}ms` }
} catch (e) {
testResult.value = { ok: false, msg: e instanceof Error ? e.message : '发送失败' }
} finally {
testing.value = false
}
}
// ---- 展示工具 ----
function protoShort(p: string): string {
return ({ cmpp: 'CM', smpp: 'SM', http: 'HT', sgip: 'SG' } as Record<string, string>)[p] ?? p.slice(0, 2).toUpperCase()
}
function protoLabel(c: Channel): string {
const ver = c.protocol === 'cmpp' ? (c.protocol_version === 30 ? ' 3.0' : ' 2.0') : c.protocol === 'sgip' ? ' 1.2' : ''
return (c.protocol + ver).toUpperCase()
}
const BADGE = ['bg-primary-100 text-primary-700', 'bg-emerald-100 text-emerald-700', 'bg-amber-100 text-amber-700', 'bg-sky-100 text-sky-700']
function badgeClass(c: Channel): string {
if (c.status !== 1) return 'bg-gray-100 text-gray-500'
return BADGE[c.id % BADGE.length] ?? BADGE[0]!
}
onMounted(() => void load())
</script>