ACS
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
<template>
|
||||
<div class="domain-whitelist-container">
|
||||
<!-- 搜索和操作栏 -->
|
||||
<el-card class="filter-container" shadow="never">
|
||||
<el-form :inline="true" :model="queryParams" class="search-form">
|
||||
<el-form-item label="域名">
|
||||
<el-input v-model="queryParams.domain" placeholder="请输入域名" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="action-bar">
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>新增域名
|
||||
</el-button>
|
||||
<el-button type="danger" :disabled="!selectedRows.length" @click="handleBatchDelete">
|
||||
<el-icon><delete /></el-icon>批量删除
|
||||
</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 域名列表 -->
|
||||
<el-card class="table-container" shadow="never">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="domainList"
|
||||
@selection-change="handleSelectionChange"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="Id" label="ID" width="80" />
|
||||
<el-table-column prop="Domain" label="域名" min-width="200" >
|
||||
<template #default="{ row }">
|
||||
<el-link :href="`http://${row.Domain}`" target="_blank" type="primary">{{ row.Domain }}</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="CreatedAt" label="创建时间" width="180" :formatter="parseCreatedAt" />
|
||||
<el-table-column prop="UpdatedAt" label="更新时间" width="180" :formatter="parseUpdatedAt" />
|
||||
<el-table-column label="操作" width="100" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<el-pagination
|
||||
v-model:current-page="queryParams.pageNum"
|
||||
v-model:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="total"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
background
|
||||
class="pagination"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 域名表单对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
title="新增域名"
|
||||
width="500px"
|
||||
append-to-body
|
||||
>
|
||||
<el-form
|
||||
ref="domainFormRef"
|
||||
:model="domainForm"
|
||||
:rules="domainRules"
|
||||
label-width="80px"
|
||||
>
|
||||
<el-form-item label="域名" prop="domain">
|
||||
<el-input v-model="domainForm.domain" placeholder="请输入域名,例如: example.com" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Delete } from '@element-plus/icons-vue'
|
||||
import { getDomainList, addDomain, deleteDomain, batchDeleteDomain } from '@/api/domain'
|
||||
|
||||
// 查询参数
|
||||
const queryParams = reactive({
|
||||
domain: '',
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
// 域名表单
|
||||
const domainForm = reactive({
|
||||
domain: ''
|
||||
})
|
||||
|
||||
// 表单规则
|
||||
const domainRules = {
|
||||
domain: [
|
||||
{ required: true, message: '请输入域名', trigger: 'blur' },
|
||||
{
|
||||
pattern: /^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$/,
|
||||
message: '请输入有效的域名格式',
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// 数据加载和分页相关
|
||||
const loading = ref(false)
|
||||
const total = ref(0)
|
||||
const domainList = ref([])
|
||||
const selectedRows = ref([])
|
||||
const dialogVisible = ref(false)
|
||||
const domainFormRef = ref(null)
|
||||
|
||||
// 获取域名列表数据
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = {
|
||||
page: queryParams.pageNum,
|
||||
count: queryParams.pageSize,
|
||||
key_word: queryParams.domain
|
||||
}
|
||||
|
||||
const res = await getDomainList(params)
|
||||
domainList.value = res.data.data
|
||||
total.value = res.data.all_count
|
||||
} catch (error) {
|
||||
console.error('获取域名列表失败:', error)
|
||||
ElMessage.error('获取域名列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 查询按钮
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNum = 1
|
||||
|
||||
getList()
|
||||
}
|
||||
|
||||
// 重置查询条件
|
||||
const resetQuery = () => {
|
||||
queryParams.domain = ''
|
||||
queryParams.dateRange = []
|
||||
queryParams.pageNum = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
// 表格复选框选择
|
||||
const handleSelectionChange = (selection) => {
|
||||
selectedRows.value = selection
|
||||
}
|
||||
|
||||
// 分页大小变化处理
|
||||
const handleSizeChange = (size) => {
|
||||
queryParams.pageSize = size
|
||||
getList()
|
||||
}
|
||||
|
||||
// 分页页码变化处理
|
||||
const handleCurrentChange = (page) => {
|
||||
queryParams.pageNum = page
|
||||
getList()
|
||||
}
|
||||
|
||||
// 打开添加域名对话框
|
||||
const handleAdd = () => {
|
||||
domainForm.domain = ''
|
||||
dialogVisible.value = true
|
||||
// 下一帧等DOM渲染后获取表单ref
|
||||
setTimeout(() => {
|
||||
if (domainFormRef.value) {
|
||||
domainFormRef.value.resetFields()
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
// 提交添加域名表单
|
||||
const submitForm = () => {
|
||||
if (!domainFormRef.value) return
|
||||
|
||||
domainFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
await addDomain({ domain: domainForm.domain })
|
||||
ElMessage.success('添加域名成功')
|
||||
dialogVisible.value = false
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('添加域名失败:', error)
|
||||
ElMessage.error('添加域名失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const parseCreatedAt = (item) => {
|
||||
return item.CreatedAt.replace('T', ' ').substring(0, 19)
|
||||
}
|
||||
|
||||
const parseUpdatedAt = (item) => {
|
||||
return item.UpdatedAt.replace('T', ' ').substring(0, 19)
|
||||
}
|
||||
// 删除单个域名
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确认删除域名 ${row.domain} 吗?`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
try {
|
||||
await deleteDomain(row.Id)
|
||||
ElMessage.success('删除成功')
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('删除域名失败:', error)
|
||||
ElMessage.error('删除失败')
|
||||
}
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 批量删除域名
|
||||
const handleBatchDelete = () => {
|
||||
if (selectedRows.value.length === 0) {
|
||||
ElMessage.warning('请选择要删除的域名')
|
||||
return
|
||||
}
|
||||
|
||||
const ids = selectedRows.value.map(item => item.Id)
|
||||
const domains = selectedRows.value.map(item => item.domain).join('、')
|
||||
|
||||
ElMessageBox.confirm(`确认删除以下域名吗?\n${domains}`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
try {
|
||||
try {
|
||||
await batchDeleteDomain(ids)
|
||||
ElMessage.success('批量删除成功')
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('批量删除域名失败:', error)
|
||||
ElMessage.error('批量删除失败')
|
||||
}
|
||||
await batchDeleteDomain(ids)
|
||||
ElMessage.success('批量删除成功')
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('批量删除域名失败:', error)
|
||||
ElMessage.error('批量删除失败')
|
||||
}
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.domain-whitelist-container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user