|
201 | 201 | </div> |
202 | 202 | <template v-else> |
203 | 203 | <div class="var-key">{{ row.key }}</div> |
| 204 | + <!-- 环境变量冲突提示 --> |
204 | 205 | <i |
205 | | - v-if="row.isPresent" |
206 | | - class="paasng-icon paasng-remind" |
| 206 | + v-if="!!row.conflict?.message" |
| 207 | + :class="['paasng-icon paasng-remind', { warning: row.conflict?.overrideConflicted }]" |
207 | 208 | v-bk-tooltips="{ |
208 | | - content: $t('环境变量不生效,KEY 与{s}增强服务的内置环境变量冲突', { s: row.conflictingService }), |
| 209 | + content: row.conflict?.message, |
209 | 210 | width: 200, |
210 | 211 | }" |
211 | 212 | ></i> |
@@ -587,7 +588,6 @@ export default { |
587 | 588 | return { |
588 | 589 | curItem: {}, |
589 | 590 | envVarList: [], |
590 | | - runtimeImageList: [], |
591 | 591 | rules: { |
592 | 592 | key: [ |
593 | 593 | { |
@@ -649,7 +649,6 @@ export default { |
649 | 649 | }, |
650 | 650 | isLoading: true, |
651 | 651 | isTableLoading: true, |
652 | | -
|
653 | 652 | envSidesliderConf: { |
654 | 653 | visiable: false, |
655 | 654 | }, |
@@ -688,7 +687,6 @@ export default { |
688 | 687 | envEnums: ENV_ENUM, |
689 | 688 | isBatchEdit: false, |
690 | 689 | activeEnvValue: 'all', |
691 | | - builtInEnvVars: {}, |
692 | 690 | showChild: false, |
693 | 691 | varPresetlLength: 0, |
694 | 692 | isDeployEnvVarChange: false, |
@@ -718,67 +716,82 @@ export default { |
718 | 716 | methods: { |
719 | 717 | async init() { |
720 | 718 | this.isLoading = true; |
721 | | - await this.getConfigVarKeys(); |
722 | 719 | this.getEnvVarList(); |
723 | 720 | }, |
724 | | - // 是否已存在该环境变量 |
725 | | - isEnvVarAlreadyExists(varKey) { |
726 | | - let flag = false; |
727 | | - let services = ''; |
728 | | - // 检查是否已存在该环境变量 |
729 | | - for (const key in this.builtInEnvVars) { |
730 | | - if (this.builtInEnvVars[key].includes(varKey)) { |
731 | | - flag = true; |
732 | | - services = key; |
733 | | - break; |
734 | | - } |
735 | | - } |
| 721 | +
|
| 722 | + showErrorMessage(e) { |
| 723 | + this.$paasMessage({ |
| 724 | + theme: 'error', |
| 725 | + message: `${this.$t('获取环境变量失败')},${e.message || e.detail}`, |
| 726 | + }); |
| 727 | + }, |
| 728 | +
|
| 729 | + // 获取环境变量冲突提示 |
| 730 | + getConflictMessage(conflictedKeys, key) { |
| 731 | + const conflictItem = conflictedKeys.find((item) => item.key === key); |
| 732 | +
|
| 733 | + if (!conflictItem) return {}; |
| 734 | +
|
| 735 | + const { conflicted_detail, override_conflicted, conflicted_source } = conflictItem; |
| 736 | + const basicText = override_conflicted ? this.$t('当前配置将覆盖内置变量') : this.$t('当前配置不生效'); |
| 737 | + const conflictSourceMessage = |
| 738 | + conflicted_source === 'builtin_addons' |
| 739 | + ? this.$t('和 {k} 增强服务的环境变量冲突', { k: conflicted_detail }) |
| 740 | + : this.$t('和平台的内置环境变量冲突'); |
| 741 | +
|
736 | 742 | return { |
737 | | - flag, |
738 | | - services, |
| 743 | + message: `${basicText},${conflictSourceMessage}`, |
| 744 | + overrideConflicted: override_conflicted, |
739 | 745 | }; |
740 | 746 | }, |
741 | | - getEnvVarList(isUpdate = true) { |
| 747 | +
|
| 748 | + // 获取冲突的环境变量 |
| 749 | + async getConflictedEnvVariables() { |
| 750 | + try { |
| 751 | + const res = await this.$store.dispatch('envVar/getConflictedEnvVariables', { |
| 752 | + appCode: this.appCode, |
| 753 | + moduleId: this.curModuleId, |
| 754 | + }); |
| 755 | + return res || []; |
| 756 | + } catch (e) { |
| 757 | + return []; |
| 758 | + } |
| 759 | + }, |
| 760 | +
|
| 761 | + // 获取环境列表 |
| 762 | + async getEnvVarList(isUpdate = true) { |
742 | 763 | this.isTableLoading = true; |
743 | | - this.$http |
744 | | - .get( |
745 | | - `${BACKEND_URL}/api/bkapps/applications/${this.appCode}/modules/${this.curModuleId}/config_vars/?order_by=${this.curSortKey}` |
746 | | - ) |
747 | | - .then( |
748 | | - (response) => { |
749 | | - if (isUpdate) this.envVarList = [...response]; |
750 | | - // 添加自定义属性 |
751 | | - this.envVarList.forEach((v) => { |
752 | | - this.$set(v, 'isEdit', false); |
753 | | - const { flag, services } = this.isEnvVarAlreadyExists(v.key); |
754 | | - this.$set(v, 'isPresent', flag); |
755 | | - this.$set(v, 'conflictingService', services); |
756 | | - if (!v.id) { |
757 | | - const id = response.find((item) => item.key === v.key)?.id; |
758 | | - this.$set(v, 'id', id); |
759 | | - } |
760 | | - }); |
761 | | - this.envLocalVarList = cloneDeep(this.envVarList); |
762 | | - if (isUpdate) { |
763 | | - this.handleFilterEnv(this.activeEnvValue); |
764 | | - } else { |
765 | | - this.$store.commit('cloudApi/updatePageEdit', false); |
766 | | - } |
767 | | - }, |
768 | | - (errRes) => { |
769 | | - const errorMsg = errRes.message; |
770 | | - this.$paasMessage({ |
771 | | - theme: 'error', |
772 | | - message: `${this.$t('获取环境变量失败')},${errorMsg}`, |
773 | | - }); |
774 | | - } |
775 | | - ) |
776 | | - .finally(() => { |
777 | | - this.showChild = true; |
778 | | - this.isTableLoading = false; |
779 | | - this.isLoading = false; |
| 764 | + try { |
| 765 | + const conflictedKeys = await this.getConflictedEnvVariables(); |
| 766 | + const res = await this.$store.dispatch('envVar/getEnvVariables', { |
| 767 | + appCode: this.appCode, |
| 768 | + moduleId: this.curModuleId, |
| 769 | + orderBy: this.curSortKey, |
780 | 770 | }); |
| 771 | + if (isUpdate) { |
| 772 | + this.envVarList = [...res]; |
| 773 | + } |
| 774 | + this.envVarList = res.map((item) => ({ |
| 775 | + ...item, |
| 776 | + isEdit: false, // 取消编辑态 |
| 777 | + conflict: conflictedKeys.length > 0 ? this.getConflictMessage(conflictedKeys, item.key) : {}, |
| 778 | + id: item.id || res.find((i) => i.key === item.key)?.id, |
| 779 | + })); |
| 780 | + this.envLocalVarList = cloneDeep(this.envVarList); |
| 781 | + if (isUpdate) { |
| 782 | + this.handleFilterEnv(this.activeEnvValue); |
| 783 | + } else { |
| 784 | + this.$store.commit('cloudApi/updatePageEdit', false); |
| 785 | + } |
| 786 | + } catch (e) { |
| 787 | + this.showErrorMessage(e); |
| 788 | + } finally { |
| 789 | + this.showChild = true; |
| 790 | + this.isTableLoading = false; |
| 791 | + this.isLoading = false; |
| 792 | + } |
781 | 793 | }, |
| 794 | +
|
782 | 795 | // 处理input事件 |
783 | 796 | handleInputEvent(rowItem) { |
784 | 797 | this.curItem = rowItem; |
@@ -1068,30 +1081,25 @@ export default { |
1068 | 1081 | this.handleModuleSelected('', { name: this.curSelectModuleName }); |
1069 | 1082 | }, |
1070 | 1083 |
|
1071 | | - handleModuleSelected(value, { name }) { |
| 1084 | + // 获取其他模块的环境变量 |
| 1085 | + async handleModuleSelected(value, { name }) { |
1072 | 1086 | this.curSelectModuleName = name; |
1073 | 1087 | this.exportDialog.isLoading = true; |
1074 | | - this.$http |
1075 | | - .get( |
1076 | | - `${BACKEND_URL}/api/bkapps/applications/${this.appCode}/modules/${this.curSelectModuleName}/config_vars/?order_by=-created` |
1077 | | - ) |
1078 | | - .then( |
1079 | | - (response) => { |
1080 | | - this.exportDialog.count = (response || []).length; |
1081 | | - }, |
1082 | | - (errRes) => { |
1083 | | - const errorMsg = errRes.detail; |
1084 | | - this.$paasMessage({ |
1085 | | - theme: 'error', |
1086 | | - message: `${this.$t('获取环境变量失败')},${errorMsg}`, |
1087 | | - }); |
1088 | | - } |
1089 | | - ) |
1090 | | - .finally(() => { |
1091 | | - this.exportDialog.isLoading = false; |
| 1088 | + try { |
| 1089 | + const response = await this.$store.dispatch('envVar/getEnvVariables', { |
| 1090 | + appCode: this.appCode, |
| 1091 | + moduleId: this.curModuleId, |
| 1092 | + orderBy: '-created', |
1092 | 1093 | }); |
| 1094 | + this.exportDialog.count = (response || []).length; |
| 1095 | + } catch (e) { |
| 1096 | + this.showErrorMessage(e); |
| 1097 | + } finally { |
| 1098 | + this.exportDialog.isLoading = false; |
| 1099 | + } |
1093 | 1100 | }, |
1094 | 1101 |
|
| 1102 | + // 导入其他模块的环境变量 |
1095 | 1103 | async handleExportConfirm() { |
1096 | 1104 | this.exportDialog.loading = true; |
1097 | 1105 | try { |
@@ -1189,11 +1197,7 @@ export default { |
1189 | 1197 | this.invokeBrowserDownload(response, `bk_paas3_${this.appCode}_${this.curModuleId}_env_vars.yaml`); |
1190 | 1198 | }, |
1191 | 1199 | (errRes) => { |
1192 | | - const errorMsg = errRes.detail; |
1193 | | - this.$paasMessage({ |
1194 | | - theme: 'error', |
1195 | | - message: `${this.$t('获取环境变量失败')},${errorMsg}`, |
1196 | | - }); |
| 1200 | + this.showErrorMessage(errRes); |
1197 | 1201 | } |
1198 | 1202 | ) |
1199 | 1203 | .finally(() => { |
@@ -1444,22 +1448,6 @@ export default { |
1444 | 1448 | this.getEnvVarList(); |
1445 | 1449 | }, |
1446 | 1450 |
|
1447 | | - // 获取增强服务内置环境变量 |
1448 | | - async getConfigVarKeys() { |
1449 | | - try { |
1450 | | - const varKeys = await this.$store.dispatch('envVar/getConfigVarKeys', { |
1451 | | - appCode: this.appCode, |
1452 | | - moduleId: this.curModuleId, |
1453 | | - }); |
1454 | | - this.builtInEnvVars = varKeys; |
1455 | | - } catch (e) { |
1456 | | - this.$paasMessage({ |
1457 | | - theme: 'error', |
1458 | | - message: e.detail || e.message || this.$t('接口异常'), |
1459 | | - }); |
1460 | | - } |
1461 | | - }, |
1462 | | -
|
1463 | 1451 | // 环境变量变更 |
1464 | 1452 | handleEnvVarChange(text, value = true) { |
1465 | 1453 | this.envVarChangeText = text; |
@@ -1935,17 +1923,9 @@ a.is-disabled { |
1935 | 1923 | width: 100%; |
1936 | 1924 | .bk-form-content { |
1937 | 1925 | width: 100%; |
1938 | | - .tooltips-icon { |
1939 | | - right: 2px !important; |
1940 | | - } |
1941 | 1926 | } |
1942 | 1927 | } |
1943 | 1928 | } |
1944 | | -.env-input-cls { |
1945 | | - /deep/ .bk-form-input { |
1946 | | - width: 90%; |
1947 | | - } |
1948 | | -} |
1949 | 1929 |
|
1950 | 1930 | .export-btn-cls { |
1951 | 1931 | font-size: 12px; |
@@ -1983,6 +1963,9 @@ a.is-disabled { |
1983 | 1963 | font-size: 14px; |
1984 | 1964 | color: #ea3636; |
1985 | 1965 | transform: translateY(0); |
| 1966 | + &.warning { |
| 1967 | + color: #ff9c01; |
| 1968 | + } |
1986 | 1969 | } |
1987 | 1970 | .var-key { |
1988 | 1971 | text-overflow: ellipsis; |
|
0 commit comments