Skip to content

Commit

Permalink
fix: 决策表暂不支持带有英文双引号(") 的输入值 --story=120814409
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 24953
  • Loading branch information
ywywZhou authored and luofann committed Nov 27, 2024
1 parent edbdc45 commit 8e58f28
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export const parseValue = (data = '', config) => {
}
}

// 检查value是否包含(")
if (typeof data === 'string' && /\"/g.test(data)) {
message = '暂不支持带有英文双引号(") 的输入值';
return { value, type, message };
}

// 定义一个函数来验证整数
const validateInt = (val) => {
if (!intRegex.test(val)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<value-selector
:key="`${item.left.obj.key}-${item.compare}-value`"
v-model="item.right.obj.value"
v-validate="{ required: judgeRequired(item, 'right') }"
v-validate="{ required: judgeRequired(item, 'right'), decisionValueRegex: { pattern: valueRegex } }"
:class="[
'value-input',
{
Expand Down Expand Up @@ -157,11 +157,13 @@
acc[cur.id] = cur.type;
return acc;
}, {});
const valueRegex = /^((?!\").)*$/;
return {
ruleInfo: {},
fieldList: this.inputs,
fieldTypeMap,
optionList: [],
valueRegex,
};
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
:label="$t('选项名称')"
:required="true"
:property="'name'"
:rules="rules.required">
:rules="rules.name">
<bk-input
v-model="optionFormData.name"
:maxlength="16"
Expand All @@ -66,7 +66,7 @@
:label="$t('选项值')"
:required="true"
:property="'id'"
:rules="rules.required">
:rules="rules.value">
<bk-input
ref="idInput"
v-model="optionFormData.id" />
Expand Down Expand Up @@ -108,6 +108,7 @@
<script>
import VueDraggable from 'vuedraggable';
import tools from '@/utils/tools.js';
import i18n from '@/config/i18n/index.js';
export default {
name: 'SelectField',
components: {
Expand Down Expand Up @@ -137,13 +138,25 @@
dropRowIndex: -1,
optionFormData: {},
rules: {
required: [
name: [
{
required: true,
message: this.$t('必填项'),
trigger: 'blur',
},
],
value: [
{
required: true,
message: this.$t('必填项'),
trigger: 'blur',
},
{
validator: val => (!/\"/g.test(val)),
message: i18n.t('暂不支持带有英文双引号(") 的输入值'),
trigger: 'change',
},
],
},
};
},
Expand Down Expand Up @@ -275,12 +288,15 @@
if (optionInfo) {
optionInfo.name = name;
optionInfo.id = id;
optionInfo.incomplete = !name || !id;
optionInfo.incomplete = !name || !id || /\"/g.test(id);
}
this.optionFormData = {};
},
handlePopoverShow(index) {
this.$refs.optionPopover[index].showHandler();
this.$nextTick(() => {
this.optionFormData.id && this.$refs.optionForm[index].validate();
});
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@
},
validate() {
return this.$refs.fieldForm.validate().then((valid) => {
if (valid) {
return this.formData.options.items.every(item => item.id && item.name);
if (valid && this.formData.type === 'select') {
return this.formData.options.items.every(item => item.id && item.name && !/\"/g.test(item.id));
}
return valid;
});
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/components/DecisionTable/components/TableBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,19 @@
}
});
}
// 校验文本内容值是否包含英文双引号(")
if (result) {
row.forEach((cell) => {
const { from, type } = cell.column;
if (type === 'string') {
const value = from === 'outputs' ? cell.condition.value : cell.condition.right.obj.value;
if (/\"/g.test(value)) {
cell.isError = true;
result = false;
}
}
});
}
});
return result;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class="is-error"
@click="toggleEditing">
<i
v-bk-tooltips="$t('内容填写不完整')"
v-bk-tooltips="{ content: errorTipContent }"
class="bk-icon icon-exclamation-circle-shape" />
</div>
</div>
Expand All @@ -44,6 +44,7 @@
import OutputCell from './components/OutputCell.vue';
import { generateCellText } from '../../common/field.js';
import tools from '@/utils/tools.js';
import i18n from '@/config/i18n/index.js';
export default {
name: 'DecisionTableCell',
components: {
Expand Down Expand Up @@ -93,6 +94,9 @@
const { rowIndex, colIndex } = this.cell;
return rowIndex === this.editCell.rowIndex && colIndex === this.editCell.colIndex;
},
errorTipContent() {
return this.cellText ? i18n.t('暂不支持带有英文双引号(") 的输入值') : i18n.t('内容填写不完整');
},
},
watch: {
cell: {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/config/i18n/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ const cn = {
待复用调试任务: '待复用调试任务',
复用成功: '复用成功',
id或name不唯一: 'id或name不唯一',
'暂不支持带有英文双引号(") 的输入值': '暂不支持带有英文双引号(") 的输入值',
};

export default cn;
1 change: 1 addition & 0 deletions frontend/src/config/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ const en = {
待复用调试任务: 'Pending Reuse Debug Task',
复用成功: 'Reuse success',
id或name不唯一: 'ID or name is not unique',
'暂不支持带有英文双引号(") 的输入值': 'Input values containing English double quotes (\") are not supported at the moment',
};

export default en;
9 changes: 9 additions & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ Validator.extend('integer', {
getMessage: (field, args) => args + i18n.t('间隔时间必须是正整数'),
validate: value => Number(value) >= 1 && Number(value) % 1 === 0,
});
// 扩展自定义值正则表达式规则
Validator.extend('decisionValueRegex', {
validate(value, { pattern }) {
const regex = new RegExp(pattern);
return regex.test(value);
},
params: ['pattern'], // 定义参数
getMessage: () => i18n.t('暂不支持带有英文双引号(") 的输入值'),
});
Validator.localize({
en: {
messages: {
Expand Down

0 comments on commit 8e58f28

Please sign in to comment.