验收环节优化

This commit is contained in:
Dev
2026-10-08 21:39:12 +08:00
parent 7e3e999b74
commit f0ad9c713f
5 changed files with 89 additions and 29 deletions
+35 -3
View File
@@ -1,5 +1,9 @@
// pages/demand/publish/index.js
import { fetchConfig } from '../../../services/home/home';
// 联系方式:仅允许英文、数字、下划线、中划线(不含中文与特殊字符)
const CONTACT_REG = /^[A-Za-z0-9_-]+$/;
Page({
/**
@@ -10,6 +14,7 @@ Page({
content: '',
budgetAmount: 0,
limitTime: 0,
contactError: '', //联系方式错误提示
tabList: [],
developType: -1,
originFiles: [],
@@ -66,14 +71,31 @@ Page({
});
},
onInputChange(e) {
console.log(e)
const value = e.detail.value;
const { field } = e.currentTarget.dataset; // 获取 data-field 的值
console.log(value)
console.log(field)
this.setData({
[field]: value // 使用动态属性名设置值
});
//输入过程中若已修正为合法联系方式,立即清除错误提示
if (field === 'contact' && this.data.contactError && CONTACT_REG.test(value)) {
this.setData({ contactError: '' });
}
},
// 联系方式失焦校验
onContactBlur(e) {
this.setData({
contactError: this.getContactError(e.detail.value)
});
},
// 联系方式错误提示文案,合法或为空时返回空串(为空由必填校验负责提示)
getContactError(value) {
const val = String(value === undefined || value === null ? '' : value).trim();
if (!val || CONTACT_REG.test(val)) {
return '';
}
return '联系方式只能包含英文、数字、下划线和中划线';
},
onDevelopTypeTap(e) {
const { key } = e.currentTarget.dataset;
@@ -99,6 +121,12 @@ Page({
onSubmit() {
const { developType, attachFiles, originFiles, content, budgetAmount, limitTime, contact } = this.data;
//提交时同步联系方式错误态,让错误提示显示在输入框上
const contactError = this.getContactError(contact);
if (contactError) {
this.setData({ contactError });
}
const validations = [
{
condition: developType == -1,
@@ -115,6 +143,10 @@ Page({
{
condition: !contact.trim(),
message: '请填写联系方式'
},
{
condition: !CONTACT_REG.test(contact.trim()),
message: '联系方式只能包含英文、数字、下划线和中划线'
}
];