|
|
@@ -636,7 +636,7 @@
|
|
|
v-model="form.ingredient"
|
|
|
type="textarea"
|
|
|
placeholder="请输入成分"
|
|
|
- @blur="checkForbiddenKeywords"
|
|
|
+ @blur="handleIngredientBlur"
|
|
|
@input="onIngredientInput"
|
|
|
/>
|
|
|
<div v-if="ingredientError" class="el-form-item__error">{{ ingredientError }}</div>
|
|
|
@@ -1855,33 +1855,29 @@ export default {
|
|
|
this.isCheckingLicense = false;
|
|
|
});
|
|
|
},
|
|
|
- // 成分关键字检查
|
|
|
- checkForbiddenKeywords() {
|
|
|
- // Clear error first
|
|
|
- this.ingredientError = '';
|
|
|
-
|
|
|
- if (this.form.ingredient && this.form.ingredient.trim()) {
|
|
|
- selectForbiddenKeywords(this.form.ingredient).then(response => {
|
|
|
- if (response.code === 200) {
|
|
|
- if (!response.data) {
|
|
|
- // Forbidden keywords found
|
|
|
- this.ingredientError = response.msg || '包含禁用关键字';
|
|
|
- // Trigger validation to show error
|
|
|
- this.$nextTick(() => {
|
|
|
- if (this.$refs.form) {
|
|
|
- this.$refs.form.validateField('ingredient');
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- // No forbidden keywords - clear error (this is the key improvement)
|
|
|
- this.ingredientError = '';
|
|
|
- // Clear validation error state
|
|
|
- this.$nextTick(() => {
|
|
|
- if (this.$refs.form) {
|
|
|
- this.$refs.form.clearValidate('ingredient');
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ // 成分输入框失焦时的处理方法关键字检查
|
|
|
+ handleIngredientBlur() {
|
|
|
+ // 检查成分是否包含禁用关键字
|
|
|
+ if (this.form.ingredient && this.form.ingredient.trim() !== '' && this.form.productName && this.form.productName.trim() !== '') {
|
|
|
+ // 创建包含成分和商品名称的参数对象
|
|
|
+ selectForbiddenKeywords(this.form.ingredient, this.form.productName).then(response => {
|
|
|
+ if (response.code === 200 && !response.data) {
|
|
|
+ // 包含禁用词
|
|
|
+ this.ingredientError = response.data.msg || '成分包含禁用关键字';
|
|
|
+ // 设置表单验证错误状态
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.form) {
|
|
|
+ this.$refs.form.validateField('ingredient');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.ingredientError = '';
|
|
|
+ // 清除验证状态
|
|
|
+ this.$nextTick(() => {
|
|
|
+ if (this.$refs.form) {
|
|
|
+ this.$refs.form.clearValidate('ingredient');
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}).catch(error => {
|
|
|
console.error('检查禁用关键字失败:', error);
|
|
|
@@ -1889,12 +1885,10 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
+ //用来清除验证信息
|
|
|
onIngredientInput() {
|
|
|
- // Optionally clear error as user types to provide real-time feedback
|
|
|
if (this.ingredientError) {
|
|
|
this.ingredientError = '';
|
|
|
- // Clear validation state
|
|
|
this.$nextTick(() => {
|
|
|
if (this.$refs.form) {
|
|
|
this.$refs.form.clearValidate('ingredient');
|