|
@@ -8,10 +8,12 @@
|
|
|
<div class="collapse-group-name">{{ type === 1 ? '白名单' : '黑名单' }}:</div>
|
|
|
<div class="tag-content" v-if="getTargetList(type).length > 0">
|
|
|
<template v-for="item in getTargetList(type)" :key="item.id">
|
|
|
+ <!-- 单个 -->
|
|
|
<el-tag v-if="item.sourceType == 2" effect="light" :closable="ipDeletable" @close="handleDeleteIp(item)"
|
|
|
color="#f4f4f4" round class="ml-1 cursor-pointer" style="margin-bottom: 4px;">
|
|
|
<span class="ellipsis">{{ ipSplicing(item.startIp, item.endIp) }}</span>
|
|
|
</el-tag>
|
|
|
+ <!-- 分组 -->
|
|
|
<el-popover v-else width="200" trigger="hover" placement="top" @show="onLoadDetail(item)">
|
|
|
<div v-if="item.list.length > 0" class="flex flex-wrap break-all">
|
|
|
<span v-for="ip in item.list" :key="String(ip)" class="mr-2">{{ ip }}</span>
|
|
@@ -20,7 +22,8 @@
|
|
|
<template #reference>
|
|
|
<el-tag effect="light" :closable="ipDeletable" @close="handleDeleteIp(item)" color="#f4f4f4" round
|
|
|
class="ml-1 cursor-pointer" style="margin-bottom: 4px;">
|
|
|
- <span class="ellipsis">{{ item.groupName.length > 30 ? item.groupName.substring(0, 30) + '...' : item.groupName }}</span>
|
|
|
+ <span class="ellipsis" v-if="item.groupName">{{ item.groupName.length > 30 ?
|
|
|
+ item.groupName.substring(0, 30) + '...' : item.groupName }}</span>
|
|
|
</el-tag>
|
|
|
</template>
|
|
|
</el-popover>
|
|
@@ -41,7 +44,7 @@ import { ipSplicing } from '/@/utils/ipUpdate';
|
|
|
import { useMessage } from '/@/hooks/message';
|
|
|
|
|
|
interface IpItem {
|
|
|
- id: string;
|
|
|
+ id?: string;
|
|
|
ipMode: number;
|
|
|
ipType: number; // 1: 白名单, 2: 黑名单
|
|
|
sourceType: number;
|
|
@@ -60,7 +63,7 @@ const { t } = useI18n();
|
|
|
const ips = ref<IpItem[]>([]);
|
|
|
const ipDeletable = ref(false);
|
|
|
const listEditOpen = ref(false);
|
|
|
-const delIps = ref<String[]>([]);
|
|
|
+const delIps = ref<string[]>([]);
|
|
|
|
|
|
watch(ips, (newVal) => emit('ips', newVal), { deep: true, immediate: true });
|
|
|
watch(delIps, (newVal) => emit('delIps', newVal), { deep: true, immediate: true });
|
|
@@ -81,8 +84,8 @@ watchEffect(() => {
|
|
|
});
|
|
|
|
|
|
const handleDeleteIp = (deleteItem: IpItem) => {
|
|
|
- if (!deleteItem.modify && !delIps.value.includes(deleteItem.id)) {
|
|
|
- delIps.value.push(deleteItem.id);
|
|
|
+ if (!deleteItem.modify && !delIps.value.includes(deleteItem.id as string)) {
|
|
|
+ delIps.value.push(deleteItem.id as string);
|
|
|
}
|
|
|
ips.value = ips.value.filter(i => {
|
|
|
if (i.id !== deleteItem.id) return true;
|
|
@@ -104,31 +107,30 @@ function addGroupsUnique(newGroups: IpItem[], ipType: number) {
|
|
|
const existIds = new Set(targetList.filter(i => i.sourceType === 1).map(i => i.groupId));
|
|
|
const conflictIds = new Set(conflictList.filter(i => i.sourceType === 1).map(i => i.groupId));
|
|
|
|
|
|
- const conflict = newGroups.find(i => conflictIds.has(i.id));
|
|
|
+ const conflict = newGroups.find(i => conflictIds.has(i.id as string));
|
|
|
if (conflict) {
|
|
|
- useMessage().warning(`分组 ${ conflict.groupName } 已存在于 ${ ipType === 1 ? '黑名单' : '白名单'} 中`);
|
|
|
- return;
|
|
|
-}
|
|
|
+ useMessage().warning(`分组 ${conflict.groupName} 已存在于 ${ipType === 1 ? '黑名单' : '白名单'} 中`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
-const filtered = newGroups.filter(i => !existIds.has(i.id));
|
|
|
-
|
|
|
-if (filtered.length) {
|
|
|
- const processedGroups = filtered.map(item => ({
|
|
|
- ipType,
|
|
|
- sourceType: 1,
|
|
|
- groupId: item.id,
|
|
|
- groupName: item.groupName,
|
|
|
- isMode: 1,
|
|
|
- startIp: '',
|
|
|
- endIp: '',
|
|
|
- modify: true,
|
|
|
- list: item.list || []
|
|
|
- }));
|
|
|
- setTargetList(ipType, [...targetList, ...processedGroups]);
|
|
|
- useMessage().success(t('common.addSuccessText'));
|
|
|
-} else {
|
|
|
- useMessage().warning('该分组已添加到IP集合,无需重复添加');
|
|
|
-}
|
|
|
+ const filtered = newGroups.filter(i => !existIds.has(i.id as string));
|
|
|
+
|
|
|
+ if (filtered.length) {
|
|
|
+ const processedGroups = filtered.map(item => ({
|
|
|
+ ipType,
|
|
|
+ sourceType: 1,
|
|
|
+ groupId: item.id as string,
|
|
|
+ groupName: item.groupName,
|
|
|
+ ipMode: 1,
|
|
|
+ startIp: '',
|
|
|
+ endIp: '',
|
|
|
+ modify: true,
|
|
|
+ list: item.list || [],
|
|
|
+ }));
|
|
|
+ setTargetList(ipType, [...targetList, ...processedGroups]);
|
|
|
+ } else {
|
|
|
+ useMessage().warning('该分组已添加到IP集合,无需重复添加');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function addSinglesUnique(newSingles: IpItem[], ipType: number) {
|
|
@@ -142,30 +144,28 @@ function addSinglesUnique(newSingles: IpItem[], ipType: number) {
|
|
|
const conflict = newSingles.find(i => conflictIps.has(i.startIp));
|
|
|
if (conflict) {
|
|
|
console.log(conflict);
|
|
|
- useMessage().warning(`IP ${ conflict.startIp } 已存在于 ${ ipType === 1 ? '黑名单' : '白名单'} 中`);
|
|
|
- return;
|
|
|
-}
|
|
|
+ useMessage().warning(`IP ${conflict.startIp} 已存在于 ${ipType === 1 ? '黑名单' : '白名单'} 中`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
-const filtered = newSingles.filter(i => !existIps.has(i.startIp));
|
|
|
-
|
|
|
-if (filtered.length) {
|
|
|
- const processedSingles = filtered.map(i => ({
|
|
|
- // id: i.id,
|
|
|
- endIp: i.endIp,
|
|
|
- groupId: '0',
|
|
|
- groupName: '',
|
|
|
- ipMode: i.endIp ? 2 : 1,
|
|
|
- startIp: i.startIp,
|
|
|
- sourceType: 2,
|
|
|
- modify: true,
|
|
|
- ipType,
|
|
|
- list: []
|
|
|
- }));
|
|
|
- setTargetList(ipType, [...targetList, ...processedSingles]);
|
|
|
- useMessage().success(t('common.addSuccessText'));
|
|
|
-} else {
|
|
|
- useMessage().warning('该IP已存在于集合中,无需重复添加');
|
|
|
-}
|
|
|
+ const filtered = newSingles.filter(i => !existIps.has(i.startIp));
|
|
|
+
|
|
|
+ if (filtered.length) {
|
|
|
+ const processedSingles = filtered.map(i => ({
|
|
|
+ endIp: i.endIp,
|
|
|
+ groupId: '',
|
|
|
+ groupName: '',
|
|
|
+ ipMode: i.endIp ? 2 : 1,
|
|
|
+ startIp: i.startIp,
|
|
|
+ sourceType: 2,
|
|
|
+ modify: true,
|
|
|
+ ipType,
|
|
|
+ list: []
|
|
|
+ }));
|
|
|
+ setTargetList(ipType, [...targetList, ...processedSingles]);
|
|
|
+ } else {
|
|
|
+ useMessage().warning('该IP已存在于集合中,无需重复添加');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const addIp = (data: IpItem[], sourceType: 1 | 2, ipType: '1' | '2') => {
|
|
@@ -178,16 +178,13 @@ const addIp = (data: IpItem[], sourceType: 1 | 2, ipType: '1' | '2') => {
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="scss">
|
|
|
+@import '/@/theme/mixins/index.scss';
|
|
|
+
|
|
|
.el-collapse-item__content {
|
|
|
padding: 0;
|
|
|
}
|
|
|
+
|
|
|
.ellipsis {
|
|
|
- max-width: 780px;
|
|
|
- display: -webkit-box; /* 使用弹性盒子布局 */
|
|
|
- -webkit-box-orient: vertical; /* 垂直方向排列 */
|
|
|
- -webkit-line-clamp: 1; /* 限制显示的行数 */
|
|
|
- overflow: hidden; /* 隐藏超出部分 */
|
|
|
- text-overflow: ellipsis; /* 超出时显示省略号 */
|
|
|
- word-break: break-word; /* 允许单词断行(可选) */
|
|
|
+ @include text-ellipsis(1);
|
|
|
}
|
|
|
</style>
|