feat: 商品详情的调整

This commit is contained in:
2025-09-06 16:24:44 +08:00
parent 7973743644
commit f6821ade2d
6 changed files with 136 additions and 32 deletions

View File

@@ -61,8 +61,8 @@ const ERROR_MESSAGES = {
* @typedef {Object} FormCardProps
* @property {string} title - 表单标题
* @property {Object} form - 表单数据对象
* @property {string} form.name - 姓名
* @property {string} form.phone - 手机号
* @property {string} form.visitorName - 姓名
* @property {string} form.contactPhone - 手机号
* @property {boolean} showDeleteIcon - 是否显示删除图标
*/
const props = defineProps({
@@ -73,12 +73,16 @@ const props = defineProps({
form: {
type: Object,
default: () => ({
name: "",
phone: "",
visitorName: "",
contactPhone: "",
}),
validator: (value) => {
return value && typeof value === 'object' &&
'name' in value && 'phone' in value;
return (
value &&
typeof value === "object" &&
"visitorName" in value &&
"contactPhone" in value
);
},
},
showDeleteIcon: {
@@ -90,11 +94,15 @@ const props = defineProps({
/**
* FormCard 组件事件
* @typedef {Object} FormCardEmits
* @property {Function} update:name - 更新姓名事件
* @property {Function} update:phone - 更新手机号事件
* @property {Function} update:visitorName - 更新姓名事件
* @property {Function} update:contactPhone - 更新手机号事件
* @property {Function} delete - 删除表单事件
*/
const emit = defineEmits(["update:name", "update:phone", "delete"]);
const emit = defineEmits([
"update:visitorName",
"update:contactPhone",
"delete",
]);
// 响应式状态
const nameError = ref("");
@@ -102,16 +110,16 @@ const phoneError = ref("");
// 计算属性 - 双向绑定
const nameValue = computed({
get: () => props.form?.name || "",
set: (value) => emit("update:name", value?.trim() || ""),
get: () => props.form?.visitorName || "",
set: (value) => emit("update:visitorName", value?.trim() || ""),
});
const phoneValue = computed({
get: () => props.form?.phone || "",
get: () => props.form?.contactPhone || "",
set: (value) => {
// 只允许数字输入
const numericValue = value.replace(/\D/g, "");
emit("update:phone", numericValue);
emit("update:contactPhone", numericValue);
},
});
@@ -145,11 +153,11 @@ const getPhoneError = (phone) => {
// 验证方法
const validateName = () => {
nameError.value = getNameError(props.form?.name);
nameError.value = getNameError(props.form?.visitorName);
};
const validatePhone = () => {
phoneError.value = getPhoneError(props.form?.phone);
phoneError.value = getPhoneError(props.form?.contactPhone);
};
// 事件处理