|
31 | 31 | :key="index">
|
32 | 32 | <WithRelatedClustersColumn
|
33 | 33 | v-model="item.cluster"
|
| 34 | + role="proxy" |
34 | 35 | :selected="selected"
|
35 | 36 | @batch-edit="handleBatchEdit" />
|
36 | 37 | <SingleResourceHostColumn
|
37 |
| - v-model="item.proxy" |
38 |
| - field="proxy.ip" |
| 38 | + v-model="item.new_proxy" |
| 39 | + field="new_proxy.ip" |
39 | 40 | :label="t('新Proxy主机')"
|
40 | 41 | :params="{
|
41 | 42 | for_bizs: [currentBizId, 0],
|
|
94 | 95 | master_domain: string;
|
95 | 96 | }[];
|
96 | 97 | };
|
97 |
| - proxy: { |
| 98 | + new_proxy: { |
98 | 99 | bk_biz_id: number;
|
99 | 100 | bk_cloud_id: number;
|
100 | 101 | bk_host_id: number;
|
|
113 | 114 | master_domain: '',
|
114 | 115 | related_clusters: [],
|
115 | 116 | },
|
116 |
| - proxy: data.proxy || { |
| 117 | + new_proxy: data.new_proxy || { |
117 | 118 | bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
|
118 | 119 | bk_cloud_id: 0,
|
119 | 120 | bk_host_id: 0,
|
|
131 | 132 | const selected = computed(() => formData.tableData.filter((item) => item.cluster.id).map((item) => item.cluster));
|
132 | 133 | // 集群域名到自身及其下集群id、域名映射
|
133 | 134 | const clusterMap = computed(() => {
|
134 |
| - const result = selected.value.reduce<Record<string, { ids: number[]; domains: string[] }>>((acc, cur) => { |
135 |
| - acc[cur.master_domain] = { |
136 |
| - ids: [cur.id, ...cur.related_clusters.map((item) => item.id)], |
137 |
| - domains: [cur.master_domain, ...cur.related_clusters.map((item) => item.master_domain)], |
138 |
| - }; |
| 135 | + const result = selected.value.reduce<Record<string, { domains: string[]; ids: number[] }>>((acc, cur) => { |
| 136 | + Object.assign(acc, { |
| 137 | + [cur.master_domain]: { |
| 138 | + domains: [cur.master_domain, ...cur.related_clusters.map((item) => item.master_domain)], |
| 139 | + ids: [cur.id, ...cur.related_clusters.map((item) => item.id)], |
| 140 | + }, |
| 141 | + }); |
139 | 142 | return acc;
|
140 | 143 | }, {});
|
141 | 144 | return result;
|
142 | 145 | });
|
| 146 | + const newProxyCounter = computed(() => { |
| 147 | + return formData.tableData.reduce( |
| 148 | + (result, item) => { |
| 149 | + Object.assign(result, { |
| 150 | + [item.new_proxy.ip]: (result[item.new_proxy.ip] || 0) + 1, |
| 151 | + }); |
| 152 | + return result; |
| 153 | + }, |
| 154 | + {} as Record<string, number>, |
| 155 | + ); |
| 156 | + }); |
143 | 157 |
|
144 | 158 | const rules = {
|
145 | 159 | 'cluster.master_domain': [
|
146 | 160 | {
|
| 161 | + message: '', |
| 162 | + trigger: 'blur', |
147 | 163 | validator: (value: string) => {
|
148 | 164 | const repeatTarget = Object.keys(clusterMap.value).find(
|
149 | 165 | (domain) => clusterMap.value[domain].domains.includes(value) && domain !== value,
|
150 | 166 | );
|
151 | 167 | return repeatTarget ? t('目标集群是集群target的关联集群_请勿重复添加', { target: repeatTarget }) : true;
|
152 | 168 | },
|
153 |
| - message: '', |
| 169 | + }, |
| 170 | + ], |
| 171 | + 'new_proxy.ip': [ |
| 172 | + { |
| 173 | + message: t('IP 重复'), |
154 | 174 | trigger: 'blur',
|
| 175 | + validator: (value: string, rowData: RowData) => { |
| 176 | + return newProxyCounter.value[rowData.new_proxy.ip] <= 1; |
| 177 | + }, |
| 178 | + }, |
| 179 | + { |
| 180 | + message: t('IP 重复'), |
| 181 | + trigger: 'change', |
| 182 | + validator: (value: string, rowData: RowData) => { |
| 183 | + return newProxyCounter.value[rowData.new_proxy.ip] <= 1; |
| 184 | + }, |
155 | 185 | },
|
156 | 186 | ],
|
157 | 187 | };
|
158 | 188 |
|
159 |
| - const { run: createTicketRun, loading: isSubmitting } = useCreateTicket<{ |
160 |
| - ip_source: 'resource_pool'; |
| 189 | + const { loading: isSubmitting, run: createTicketRun } = useCreateTicket<{ |
161 | 190 | infos: {
|
162 | 191 | cluster_ids: number[];
|
163 | 192 | resource_spec: {
|
164 | 193 | new_proxy: {
|
165 |
| - spec_id: number; |
166 | 194 | hosts: {
|
167 | 195 | bk_biz_id: number;
|
168 | 196 | bk_cloud_id: number;
|
169 | 197 | bk_host_id: number;
|
170 | 198 | ip: string;
|
171 | 199 | }[];
|
| 200 | + spec_id: number; |
172 | 201 | };
|
173 | 202 | };
|
174 | 203 | }[];
|
| 204 | + ip_source: 'resource_pool'; |
175 | 205 | }>(TicketTypes.MYSQL_PROXY_ADD);
|
176 | 206 |
|
177 | 207 | const handleSubmit = async () => {
|
|
181 | 211 | }
|
182 | 212 | createTicketRun({
|
183 | 213 | details: {
|
184 |
| - ip_source: 'resource_pool', |
185 | 214 | infos: formData.tableData.map((item) => ({
|
186 | 215 | cluster_ids: clusterMap.value[item.cluster.master_domain].ids,
|
187 | 216 | resource_spec: {
|
188 | 217 | new_proxy: {
|
| 218 | + hosts: [item.new_proxy], |
189 | 219 | spec_id: 0,
|
190 |
| - hosts: [item.proxy], |
191 | 220 | },
|
192 | 221 | },
|
193 | 222 | })),
|
| 223 | + ip_source: 'resource_pool', |
194 | 224 | },
|
195 | 225 | remark: formData.remark,
|
196 | 226 | });
|
|
0 commit comments