Skip to content

Commit

Permalink
feat: 域名解析支持类型和过滤(后端 > 2.14.184)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 19, 2024
1 parent 967f84c commit c3ad63f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.83",
"version": "2.14.84",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,10 @@ export default {
},
'Resolve Domain Operator': {
label: 'Resolve Domain',
des: 'Providers(IPv4 only. Can be controlled by the node field "no-resolve")',
des: 'Providers(can be controlled by the node field "no-resolve")',
options: ['Google', 'IP-API', 'Cloudflare', 'Ali', 'Tencent'],
types: ['IPv4', 'IPv6'],
filters: ['Disabled', 'Remove Failed', 'IP Only', 'IPv4 Only', 'IPv6 Only'],
tipsTitle: 'domain Tips',
tipsDes: '节点域名解析操作说明',
},
Expand Down
4 changes: 3 additions & 1 deletion src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,10 @@ export default {
},
'Resolve Domain Operator': {
label: '域名解析',
des: '提供商(仅 IPv4. 可由节点字段 "no-resolve" 控制)',
des: '提供商(可由节点字段 "no-resolve" 控制)',
options: ['Google', 'IP-API', 'Cloudflare', 'Ali', 'Tencent'],
types: ['IPv4', 'IPv6'],
filters: ['不过滤', '移除失败', '只保留 IP', '只保留 IPv4', '只保留 IPv6'],
tipsTitle: '域名解析操作提示',
tipsDes: '将节点域名解析成为 IP 地址,减少一次额外的 DNS 请求',
},
Expand Down
54 changes: 48 additions & 6 deletions src/views/editor/components/ActionRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,42 @@
</nut-radio>
</nut-radiogroup>
</div>
<template v-if="type === 'Resolve Domain Operator' && newVersion">
<div class="radio-wrapper options-radio">
<p class="des-label">解析类型</p>
<nut-radiogroup direction="horizontal" v-model="rdoType">
<nut-radio v-for="(key, index) in rdoTypeOpt" :label="key" :key="index"
>{{
$t(`editorPage.subConfig.nodeActions['${type}'].types[${index}]`)
}}
</nut-radio>
</nut-radiogroup>
</div>
<div class="radio-wrapper options-radio">
<p class="des-label">过滤结果</p>
<nut-radiogroup direction="horizontal" v-model="rdoFilter">
<nut-radio v-for="(key, index) in rdoFilterOpt" :label="key" :key="index"
>{{
$t(`editorPage.subConfig.nodeActions['${type}'].filters[${index}]`)
}}
</nut-radio>
</nut-radiogroup>
</div>
</template>
</div>
</template>

<script lang="ts" setup>
import semverGt from 'semver/functions/gt';
import { useAppNotifyStore } from '@/store/appNotify';
import { storeToRefs } from 'pinia';
import { useGlobalStore } from '@/store/global';
import { inject, onMounted, ref, watch } from 'vue';
const globalStore = useGlobalStore();
const { showNotify } = useAppNotifyStore();
const { env } = storeToRefs(globalStore);
const { type, id } = defineProps<{
Expand All @@ -37,20 +62,26 @@
const opt = {
'Flag Operator': ['add', 'remove'],
'Sort Operator': ['asc', 'desc', 'random'],
'Resolve Domain Operator': ['Google', 'IP-API', 'Cloudflare'],
'Resolve Domain Operator': ['Google', 'IP-API', 'Cloudflare', 'Ali', 'Tencent'],
};
const rdoTypeOpt = ['IPv4', 'IPv6'];
const rdoFilterOpt = ['disabled', 'removeFailed', 'IPOnly', 'IPv4Only', 'IPv6Only'];
const value = ref();
const newVersion = ref(false);
try {
if (semverGt(env.value.version, '2.14.32')) {
opt['Resolve Domain Operator'] = [...opt['Resolve Domain Operator'], 'Ali', 'Tencent']
}
newVersion.value = semverGt(env.value.version, '2.14.184')
} catch (e) {}
const value = ref();
const rdoType = ref('IPv4');
const rdoFilter = ref('disabled');
// 挂载时读取当前数据,赋值初始状态
onMounted(() => {
const item = form.process.find(item => item.id === id);
if (item) {
switch (type) {
case 'Flag Operator':
Expand All @@ -61,13 +92,21 @@
break;
case 'Resolve Domain Operator':
value.value = item.args?.provider ?? 'Google';
rdoType.value = item.args?.type ?? 'IPv4';
rdoFilter.value = item.args?.filter ?? 'disabled';
break;
}
}
});
// 值变化时实时修改 form 的数据
watch(value, () => {
watch([value, rdoFilter, rdoType], () => {
if (rdoType.value === 'IPv6' && ['IP-API'].includes(value.value)) {
showNotify({
title: `${value.value} 不支持 IPv6`,
type: 'danger',
});
}
const item = form.process.find(item => item.id === id);
switch (type) {
case 'Flag Operator':
Expand All @@ -81,10 +120,13 @@
case 'Resolve Domain Operator':
item.args = {
provider: value.value,
type: rdoType.value,
filter: rdoFilter.value,
};
break;
}
});
</script>

<style lang="scss" scoped>
Expand Down

0 comments on commit c3ad63f

Please sign in to comment.