| </el-radio-group> |
| 9 | </el-form-item> |
| 10 | </template> |
| 11 |
| 12 | <!-- Direct mode --> |
| 13 | <template v-if="backendMode === 'direct'"> |
| 14 | <div class="field-row two-col"> |
| 15 | <ConfigField label="Local IP" type="text" v-model="form.localIP" placeholder="127.0.0.1" :readonly="readonly" /> |
| 16 | <ConfigField label="Local Port" type="number" v-model="form.localPort" :min="0" :max="65535" prop="localPort" :readonly="readonly" /> |
| 17 | </div> |
| 18 | </template> |
| 19 |
| 20 | <!-- Plugin mode --> |
| 21 | <template v-else> |
| 22 | <div class="field-row two-col"> |
| 23 | <ConfigField label="Plugin Type" type="select" v-model="form.pluginType" |
| 24 | :options="PLUGIN_LIST.map((p) => ({ label: p, value: p }))" :readonly="readonly" /> |
| 25 | <div></div> |
| 26 | </div> |
| 27 |
| 28 | <template v-if="['http2https', 'https2http', 'https2https', 'http2http', 'tls2raw'].includes(form.pluginType)"> |
| 29 | <div class="field-row two-col"> |
| 30 | <ConfigField label="Local Address" type="text" v-model="form.pluginConfig.localAddr" placeholder="127.0.0.1:8080" :readonly="readonly" /> |
| 31 | <ConfigField v-if="['http2https', 'https2http', 'https2https', 'http2http'].includes(form.pluginType)" |
| 32 | label="Host Header Rewrite" type="text" v-model="form.pluginConfig.hostHeaderRewrite" :readonly="readonly" /> |
| 33 | <div v-else></div> |
| 34 | </div> |
| 35 | </template> |
| 36 | <template v-if="['http2https', 'https2http', 'https2https', 'http2http'].includes(form.pluginType)"> |
| 37 | <ConfigField label="Request Headers" type="kv" v-model="pluginRequestHeaders" |
| 38 | key-placeholder="Header" value-placeholder="Value" :readonly="readonly" /> |
| 39 | </template> |
| 40 | <template v-if="['https2http', 'https2https', 'tls2raw'].includes(form.pluginType)"> |
| 41 | <div class="field-row two-col"> |
| 42 | <ConfigField label="Certificate Path" type="text" v-model="form.pluginConfig.crtPath" placeholder="/path/to/cert.pem" :readonly="readonly" /> |
| 43 | <ConfigField label="Key Path" type="text" v-model="form.pluginConfig.keyPath" placeholder="/path/to/key.pem" :readonly="readonly" /> |
| 44 | </div> |
| 45 | </template> |
| 46 | <template v-if="['https2http', 'https2https'].includes(form.pluginType)"> |
| 47 | <ConfigField label="Enable HTTP/2" type="switch" v-model="form.pluginConfig.enableHTTP2" :readonly="readonly" /> |
| 48 | </template> |
| 49 | <template v-if="form.pluginType === 'http_proxy'"> |
| 50 | <div class="field-row two-col"> |
| 51 | <ConfigField label="HTTP User" type="text" v-model="form.pluginConfig.httpUser" :readonly="readonly" /> |
| 52 | <ConfigField label="HTTP Password" type="password" v-model="form.pluginConfig.httpPassword" :readonly="readonly" /> |
| 53 | </div> |
| 54 | </template> |
| 55 | <template v-if="form.pluginType === 'socks5'"> |
| 56 | <div class="field-row two-col"> |
| 57 | <ConfigField label="Username" type="text" v-model="form.pluginConfig.username" :readonly="readonly" /> |
| 58 | <ConfigField label="Password" type="password" v-model="form.pluginConfig.password" :readonly="readonly" /> |
| 59 | </div> |
| 60 | </template> |
| 61 | <template v-if="form.pluginType === 'static_file'"> |
| 62 | <div class="field-row two-col"> |
| 63 | <ConfigField label="Local Path" type="text" v-model="form.pluginConfig.localPath" placeholder="/path/to/files" :readonly="readonly" /> |
| 64 | <ConfigField label="Strip Prefix" type="text" v-model="form.pluginConfig.stripPrefix" :readonly="readonly" /> |
| 65 | </div> |
| 66 | <div class="field-row two-col"> |
| 67 | <ConfigField label="HTTP User" type="text" v-model="form.pluginConfig.httpUser" :readonly="readonly" /> |
| 68 | <ConfigField label="HTTP Password" type="password" v-model="form.pluginConfig.httpPassword" :readonly="readonly" /> |
| 69 | </div> |
| 70 | </template> |
| 71 | <template v-if="form.pluginType === 'unix_domain_socket'"> |
| 72 | <ConfigField label="Unix Socket Path" type="text" v-model="form.pluginConfig.unixPath" placeholder="/tmp/socket.sock" :readonly="readonly" /> |
| 73 | </template> |
| 74 | </template> |
| 75 | </template> |
| 76 |
| 77 | <script setup lang="ts"> |
| 78 | import { ref, computed, watch, nextTick, onMounted } from 'vue' |
| 79 | import type { ProxyFormData } from '../../types' |
| 80 | import ConfigField from '../ConfigField.vue' |
| 81 |
| 82 | const PLUGIN_LIST = [ |
| 83 | 'http2https', 'http_proxy', 'https2http', 'https2https', 'http2http', |
| 84 | 'socks5', 'static_file', 'unix_domain_socket', 'tls2raw', 'virtual_net', |
| 85 | ] |
| 86 |
| 87 | const props = withDefaults(defineProps<{ |
| 88 | modelValue: ProxyFormData |
| 89 | readonly?: boolean |
| 90 | }>(), { readonly: false }) |
| 91 |
| 92 | const emit = defineEmits<{ 'update:modelValue': [value: ProxyFormData] }>() |
| 93 |
| 94 | const form = computed({ |
| 95 | get: () => props.modelValue, |
| 96 | set: (val) => emit('update:modelValue', val), |
| 97 | }) |
| 98 |
| 99 | const backendMode = ref<'direct' | 'plugin'>(form.value.pluginType ? 'plugin' : 'direct') |
| 100 | const isHydrating = ref(false) |
| 101 |
| 102 | const pluginRequestHeaders = computed({ |
| 103 | get() { |
| 104 | const set = form.value.pluginConfig?.requestHeaders?.set |
| 105 | if (!set || typeof set !== 'object') return [] |
| 106 | return Object.entries(set).map(([key, value]) => ({ key, value: String(value) })) |
| 107 | }, |
| 108 | set(val: Array<{ key: string; value: string }>) { |
| 109 | if (!form.value.pluginConfig) form.value.pluginConfig = {} |
| 110 | if (val.length === 0) { |
| 111 | delete form.value.pluginConfig.requestHeaders |
| 112 | } else { |
| 113 | form.value.pluginConfig.requestHeaders = { |
| 114 | set: Object.fromEntries(val.map((e) => [e.key, e.value])), |
| 115 | } |
| 116 | } |
| 117 | }, |
| 118 | }) |
| 119 |
| 120 | watch(() => form.value.pluginType, (newType, oldType) => { |
| 121 | if (isHydrating.value) return |
| 122 | if (!oldType || !newType || newType === oldType) return |
| 123 | if (form.value.pluginConfig && Object.keys(form.value.pluginConfig).length > 0) { |
| 124 | form.value.pluginConfig = {} |
| 125 | } |
| 126 | }) |
| 127 |
| 128 | watch(backendMode, (mode) => { |
| 129 | if (mode === 'direct') { |
| 130 | form.value.pluginType = '' |
| 131 | form.value.pluginConfig = {} |
| 132 | } else if (!form.value.pluginType) { |
| 133 | form.value.pluginType = 'http2https' |
| 134 | } |
| 135 | }) |
| 136 |
| 137 | const hydrate = () => { |
| 138 | isHydrating.value = true |
| 139 | backendMode.value = form.value.pluginType ? 'plugin' : 'direct' |
| 140 | nextTick(() => { isHydrating.value = false }) |
| 141 | } |
| 142 |
| 143 | watch(() => props.modelValue, () => { hydrate() }) |
| 144 | onMounted(() => { hydrate() }) |
| 145 | </script> |
| 146 |
| 147 | <style scoped lang="scss"> |
| 148 | @use '@/assets/css/form-layout'; |
| 149 | </style> |