|
15 | 15 | <v-expand-transition> |
16 | 16 | <div v-if="radioValue === '1'" style="margin-left: 16px;"> |
17 | 17 | <v-radio-group v-model="githubProxyRadioControl" class="mt-2" hide-details="true"> |
18 | | - <v-radio color="success" v-for="(proxy, idx) in githubProxies" :key="proxy" :value="idx"> |
| 18 | + <v-radio color="success" v-for="(proxy, idx) in githubProxies" :key="proxy" :value="String(idx)"> |
19 | 19 | <template v-slot:label> |
20 | 20 | <div class="d-flex align-center"> |
21 | 21 | <span class="mr-2">{{ proxy }}</span> |
|
37 | 37 | </template> |
38 | 38 | </v-radio> |
39 | 39 | <v-radio color="primary" value="-1" :label="tm('network.proxySelector.custom')"> |
40 | | - <template v-slot:label v-if="githubProxyRadioControl === '-1'"> |
| 40 | + <template v-slot:label v-if="String(githubProxyRadioControl) === '-1'"> |
41 | 41 | <v-text-field density="compact" v-model="selectedGitHubProxy" variant="outlined" |
42 | 42 | style="width: 100vw;" :placeholder="tm('network.proxySelector.custom')" hide-details="true"> |
43 | 43 | </v-text-field> |
@@ -72,9 +72,21 @@ export default { |
72 | 72 | loadingTestingConnection: false, |
73 | 73 | testingProxies: {}, |
74 | 74 | proxyStatus: {}, |
| 75 | + initializing: true, |
75 | 76 | } |
76 | 77 | }, |
77 | 78 | methods: { |
| 79 | + getProxyByControl(control) { |
| 80 | + const normalizedControl = String(control); |
| 81 | + if (normalizedControl === "-1") { |
| 82 | + return ""; |
| 83 | + } |
| 84 | + const index = Number.parseInt(normalizedControl, 10); |
| 85 | + if (Number.isNaN(index)) { |
| 86 | + return ""; |
| 87 | + } |
| 88 | + return this.githubProxies[index] || ""; |
| 89 | + }, |
78 | 90 | async testSingleProxy(idx) { |
79 | 91 | this.testingProxies[idx] = true; |
80 | 92 | |
@@ -118,42 +130,60 @@ export default { |
118 | 130 | }, |
119 | 131 | }, |
120 | 132 | mounted() { |
121 | | - this.selectedGitHubProxy = localStorage.getItem('selectedGitHubProxy') || ""; |
122 | | - this.radioValue = localStorage.getItem('githubProxyRadioValue') || "0"; |
123 | | - this.githubProxyRadioControl = localStorage.getItem('githubProxyRadioControl') || "0"; |
124 | | - if (this.radioValue === "1") { |
125 | | - if (this.githubProxyRadioControl !== "-1") { |
126 | | - this.selectedGitHubProxy = this.githubProxies[this.githubProxyRadioControl] || ""; |
| 133 | + this.initializing = true; |
| 134 | +
|
| 135 | + const savedProxy = localStorage.getItem('selectedGitHubProxy') || ""; |
| 136 | + const savedRadio = localStorage.getItem('githubProxyRadioValue') || "0"; |
| 137 | + const savedControl = String(localStorage.getItem('githubProxyRadioControl') || "0"); |
| 138 | +
|
| 139 | + this.radioValue = savedRadio; |
| 140 | + this.githubProxyRadioControl = savedControl; |
| 141 | +
|
| 142 | + if (savedRadio === "1") { |
| 143 | + if (savedControl !== "-1") { |
| 144 | + this.selectedGitHubProxy = this.getProxyByControl(savedControl); |
| 145 | + } else { |
| 146 | + this.selectedGitHubProxy = savedProxy; |
127 | 147 | } |
128 | 148 | } else { |
129 | 149 | this.selectedGitHubProxy = ""; |
130 | 150 | } |
| 151 | +
|
| 152 | + this.initializing = false; |
131 | 153 | }, |
132 | 154 | watch: { |
133 | 155 | selectedGitHubProxy: function (newVal, oldVal) { |
| 156 | + if (this.initializing) { |
| 157 | + return; |
| 158 | + } |
134 | 159 | if (!newVal) { |
135 | 160 | newVal = "" |
136 | 161 | } |
137 | 162 | localStorage.setItem('selectedGitHubProxy', newVal); |
138 | 163 | }, |
139 | 164 | radioValue: function (newVal) { |
| 165 | + if (this.initializing) { |
| 166 | + return; |
| 167 | + } |
140 | 168 | localStorage.setItem('githubProxyRadioValue', newVal); |
141 | | - if (newVal === "0") { |
| 169 | + if (String(newVal) === "0") { |
142 | 170 | this.selectedGitHubProxy = ""; |
143 | | - } else if (this.githubProxyRadioControl !== "-1") { |
144 | | - this.selectedGitHubProxy = this.githubProxies[this.githubProxyRadioControl] || ""; |
| 171 | + } else if (String(this.githubProxyRadioControl) !== "-1") { |
| 172 | + this.selectedGitHubProxy = this.getProxyByControl(this.githubProxyRadioControl); |
145 | 173 | } |
146 | 174 | }, |
147 | 175 | githubProxyRadioControl: function (newVal) { |
148 | | - localStorage.setItem('githubProxyRadioControl', newVal); |
149 | | - if (this.radioValue !== "1") { |
150 | | - this.selectedGitHubProxy = ""; |
| 176 | + if (this.initializing) { |
151 | 177 | return; |
152 | 178 | } |
153 | | - if (newVal !== "-1") { |
154 | | - this.selectedGitHubProxy = this.githubProxies[newVal] || ""; |
155 | | - } else { |
| 179 | + const normalizedVal = String(newVal); |
| 180 | + localStorage.setItem('githubProxyRadioControl', normalizedVal); |
| 181 | + if (String(this.radioValue) !== "1") { |
156 | 182 | this.selectedGitHubProxy = ""; |
| 183 | + return; |
| 184 | + } |
| 185 | + if (normalizedVal !== "-1") { |
| 186 | + this.selectedGitHubProxy = this.getProxyByControl(normalizedVal); |
157 | 187 | } |
158 | 188 | } |
159 | 189 | } |
|
0 commit comments