Skip to content

Commit

Permalink
feat: 变量的默认值支持为空 (#3557)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuikill authored Oct 10, 2024
1 parent 427046a commit 408111c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
const isCellEditable = (prop: string) => props.editable && ['type', 'default_val', 'memo'].includes(prop);
const isCellValRequired = (prop: string) => props.editable && ['type', 'default_val'].includes(prop);
const isCellValRequired = (prop: string) => props.editable && ['type'].includes(prop);
const getCellVal = (variable: IVariableEditParams, prop: string) => {
if (prop === 'cited') {
Expand All @@ -147,33 +147,24 @@
const validate = () => {
const errors: IErrorDetail = {};
variables.value.forEach((variable) => {
['type', 'default_val'].forEach((key) => {
if (variable[key as keyof typeof variable] === '') {
if (errors[variable.name]) {
errors[variable.name].push(key);
} else {
errors[variable.name] = [key];
}
}
if (variable.type === 'number' && !/^\d*(\.\d+)?$/.test(variable.default_val)) {
if (errors[variable.name]) {
errors[variable.name].push(key);
} else {
errors[variable.name] = [key];
}
}
});
if (variable.type === 'number' && !/^\d*(\.\d+)?$/.test(variable.default_val)) {
if (errors[variable.name]) {
errors[variable.name].push('default_val');
} else {
errors[variable.name] = ['default_val'];
}
const { name, type, default_val } = variable;
if (!type) {
errors[name] = errors[name] || [];
errors[name].push('type');
}
if (default_val === '' && type === 'number') {
errors[name] = errors[name] || [];
errors[name].push('default_val');
} else if (type === 'number' && !/^\d*(\.\d+)?$/.test(default_val)) {
errors[name] = errors[name] || [];
errors[name].push('default_val');
}
});
errorDetails.value = errors;
return Object.keys(errorDetails.value).length === 0;
return Object.keys(errors).length === 0;
};
const change = () => {
Expand All @@ -200,6 +191,7 @@
border: 1px solid #dcdee5;
table-layout: fixed;
border-collapse: collapse;
overflow: hidden;
&.edit-mode {
.td-cell {
background: #f5f7fa;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<bk-option id="number" label="number"></bk-option>
</bk-select>
</bk-form-item>
<bk-form-item :label="t('默认值')" property="default_val" required>
<bk-form-item :label="t('默认值')" property="default_val" :required="localVal.type === 'number'">
<bk-input v-model="localVal.default_val" :placeholder="t('请输入')" @input="change" />
</bk-form-item>
<bk-form-item :label="t('描述')" property="memo">
Expand Down
6 changes: 5 additions & 1 deletion bcs-services/bcs-bscp/ui/src/views/space/variables/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
</template>
</bk-table-column>
<bk-table-column :label="t('类型')" prop="spec.type" width="180"></bk-table-column>
<bk-table-column :label="t('默认值')" prop="spec.default_val"></bk-table-column>
<bk-table-column :label="t('默认值')" prop="spec.default_val">
<template #default="{ row }">
<span v-if="row.spec">{{ row.spec.default_val || '--' }}</span>
</template>
</bk-table-column>
<bk-table-column :label="t('描述')">
<template #default="{ row }">
<span v-if="row.spec">{{ row.spec.memo || '--' }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@
const shouldValidate = ref(false);
const errorLine = ref<errorLineItem[]>([]);
const editorPlaceholder = ref([
t('示例'),
`${t('示例')}:`,
t('变量名 变量类型 变量值 变量描述(可选)'),
'bk_bscp_nginx_ip string 1.1.1.1',
t(' bk_bscp_nginx_port number 8080 nginx端口'),
'bk_bscp_nginx_port number 8080 nginx端口',
'bk_bscp_nginx_access_log string ""(变量值为空的情况) nginx访问日志路径',
]);
watch(
Expand All @@ -104,6 +105,17 @@
},
);
watch(
() => separator.value,
(newVal, oldVal) => {
editorPlaceholder.value.forEach((item, index) => {
if (index > 1) {
editorPlaceholder.value[index] = item.replaceAll(oldVal, newVal);
}
});
},
);
onBeforeUnmount(() => {
codeEditorRef.value.destroy();
});
Expand Down Expand Up @@ -142,6 +154,7 @@
const key = variablesContent[0];
const type = variablesContent[1];
const value = variablesContent[2];
value === '""' && (variablesContent[2] = ''); // "" 转空字符串 代表变量为空值
if (variablesContent.length < 3) {
errorLine.value.push({
errorInfo: t('请检查是否已正确使用分隔符'),
Expand Down

0 comments on commit 408111c

Please sign in to comment.