|
845 | 845 | v-model="envvar.name" |
846 | 846 | :label="$t('global.name')" |
847 | 847 | :counter="60" |
| 848 | + :rules="getEnvNameRules(envvar.name, index)" |
| 849 | + :error="isDuplicateEnvVar(envvar.name, index)" |
| 850 | + :error-messages="isDuplicateEnvVar(envvar.name, index) ? [$t('app.form.duplicateEnvVar')] : []" |
848 | 851 | ></v-text-field> |
849 | 852 | </v-col> |
850 | 853 | <v-col cols="12" md="6"> |
@@ -1770,6 +1773,11 @@ export default defineComponent({ |
1770 | 1773 | { title: this.$t('app.form.newValue'), key: 'newValue' }, |
1771 | 1774 | ]; |
1772 | 1775 | }, |
| 1776 | + duplicateEnvVarNames() { |
| 1777 | + const names = this.envVars.map(env => env.name.trim()).filter(name => name !== ''); |
| 1778 | + const duplicates = names.filter((name, index) => names.indexOf(name) !== index); |
| 1779 | + return [...new Set(duplicates)]; |
| 1780 | + }, |
1773 | 1781 | }, |
1774 | 1782 | watch: { |
1775 | 1783 | advanced(newValue) { |
@@ -2551,6 +2559,25 @@ export default defineComponent({ |
2551 | 2559 | } |
2552 | 2560 | } |
2553 | 2561 | }, |
| 2562 | + isDuplicateEnvVar(name: string, currentIndex: number) { |
| 2563 | + if (!name || name.trim() === '') return false; |
| 2564 | + const trimmedName = name.trim(); |
| 2565 | + return this.envVars.some((env, index) => |
| 2566 | + index !== currentIndex && env.name.trim() === trimmedName |
| 2567 | + ); |
| 2568 | + }, |
| 2569 | + getEnvNameRules(name: string, index: number) { |
| 2570 | + const baseRules = [ |
| 2571 | + (v: any) => !!v || this.$t('app.form.envNameRequired'), |
| 2572 | + (v: any) => v.length <= 60 || this.$t('app.form.envNameTooLong'), |
| 2573 | + (v: any) => /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v) || this.$t('app.form.envNameInvalidChars'), |
| 2574 | + ]; |
| 2575 | + |
| 2576 | + const duplicateRule = (v: any) => |
| 2577 | + !this.isDuplicateEnvVar(v, index) || this.$t('app.form.duplicateEnvVar'); |
| 2578 | + |
| 2579 | + return [...baseRules, duplicateRule]; |
| 2580 | + }, |
2554 | 2581 | addSAAnnotationLine() { |
2555 | 2582 | this.sAAnnotations.push({ |
2556 | 2583 | annotation: "", |
|
0 commit comments