fix(ts): 精确补全 Mall 表单字段类型,修复 TS2322

- 表单状态字段按需标注 number/string | undefined(不使用 Partial,不改共享 VO)
- UploadImgs 用 computed 兜底 [],避免传入 undefined
- spu 路由 categoryId 从 query 读取转 Number
- 必填字符串字段用 || '' 收口;skuData 改 ref<Sku>() 并由模板 v-if 兜底

ts:check 768 → 748,无新增类型错误
master
YunaiV 2026-06-20 10:46:50 -07:00
parent e566d9f60a
commit 9c95bebc26
11 changed files with 57 additions and 45 deletions

View File

@ -60,16 +60,16 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
userId: undefined,
userNickname: undefined,
userAvatar: undefined,
id: undefined as number | undefined,
userId: undefined as number | undefined,
userNickname: undefined as string | undefined,
userAvatar: undefined as string | undefined,
spuId: 0,
skuId: undefined,
skuId: undefined as number | undefined,
descriptionScores: 5,
benefitScores: 5,
content: undefined,
picUrls: []
content: undefined as string | undefined,
picUrls: [] as string[]
})
const formRules = reactive({
spuId: [{ required: true, message: '商品不能为空', trigger: 'blur' }],
@ -81,11 +81,7 @@ const formRules = reactive({
benefitScores: [{ required: true, message: '服务星级不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const skuData = ref({
id: -1,
name: '',
picUrl: ''
})
const skuData = ref<ProductSpuApi.Sku>()
/** 打开弹窗 */
const open = async (type: string, id?: number) => {

View File

@ -30,8 +30,8 @@ const { t } = useI18n() // 国际化
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined,
replyContent: undefined
id: undefined as number | undefined,
replyContent: undefined as string | undefined
})
const formRules = reactive({
replyContent: [{ required: true, message: '回复内容不能为空', trigger: 'blur' }]

View File

@ -8,7 +8,7 @@
label-width="80px"
>
<el-form-item label="属性编号" prop="category">
<el-input v-model="formData.propertyId" disabled="" />
<el-input v-model="formData.propertyId" disabled />
</el-form-item>
<el-form-item label="名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入名称" />
@ -35,11 +35,16 @@ const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
propertyId: undefined,
const formData = ref<{
id?: number
propertyId?: number
name: string
remark?: string
}>({
id: undefined as number | undefined,
propertyId: undefined as number | undefined,
name: '',
remark: ''
remark: undefined as string | undefined
})
const formRules = reactive({
propertyId: [{ required: true, message: '属性不能为空', trigger: 'blur' }],
@ -98,7 +103,7 @@ const resetForm = () => {
id: undefined,
propertyId: undefined,
name: '',
remark: ''
remark: undefined
}
formRef.value?.resetFields()
}

View File

@ -286,7 +286,7 @@ const queryParams = ref({
pageSize: 10,
tabType: 0,
name: '',
categoryId: undefined,
categoryId: undefined as number | undefined,
createTime: undefined
}) //
const queryFormRef = ref() // Ref
@ -434,7 +434,7 @@ onActivated(() => {
onMounted(async () => {
// categoryId
if (route.query.categoryId) {
queryParams.value.categoryId = route.query.categoryId
queryParams.value.categoryId = Number(route.query.categoryId)
}
//
await getTabsCount()

View File

@ -51,11 +51,11 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
name: undefined,
picUrl: undefined,
status: undefined,
sort: undefined
id: undefined as number | undefined,
name: undefined as string | undefined,
picUrl: undefined as string | undefined,
status: undefined as number | undefined,
sort: undefined as number | undefined
})
const formRules = reactive({
name: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }],

View File

@ -25,7 +25,7 @@
/>
</el-form-item>
<el-form-item label="秒杀轮播图" prop="sliderPicUrls">
<UploadImgs v-model="formData.sliderPicUrls" placeholder="请输入秒杀轮播图" />
<UploadImgs v-model="sliderPicUrls" placeholder="请输入秒杀轮播图" />
</el-form-item>
<el-form-item label="活动状态" prop="status">
<el-radio-group v-model="formData.status">
@ -61,12 +61,12 @@ const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
name: undefined,
startTime: undefined,
endTime: undefined,
sliderPicUrls: undefined,
status: undefined
id: undefined as number | undefined,
name: undefined as string | undefined,
startTime: undefined as string | undefined,
endTime: undefined as string | undefined,
sliderPicUrls: undefined as string[] | undefined,
status: undefined as number | undefined
})
const formRules = reactive({
name: [{ required: true, message: '秒杀时段名称不能为空', trigger: 'blur' }],
@ -75,6 +75,12 @@ const formRules = reactive({
status: [{ required: true, message: '活动状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const sliderPicUrls = computed({
get: () => formData.value.sliderPicUrls || [],
set: (val: string[]) => {
formData.value.sliderPicUrls = val
}
})
/** 打开弹窗 */
const open = async (type: string, id?: number) => {

View File

@ -26,7 +26,10 @@ const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref({
const formData = ref<{
id: number | null | undefined
auditReason: string
}>({
id: undefined, //
auditReason: '' //
})
@ -37,7 +40,7 @@ const open = async (row: AfterSaleApi.TradeAfterSaleVO) => {
resetForm()
//
formData.value.id = row.id
formData.value.auditReason = row.auditReason
formData.value.auditReason = row.auditReason || ''
dialogVisible.value = true
}
defineExpose({ open }) // open

View File

@ -25,8 +25,8 @@ const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined,
auditReason: undefined
id: undefined as number | undefined,
auditReason: undefined as string | undefined
})
const formRules = reactive({
auditReason: [{ required: true, message: '驳回原因不能为空', trigger: 'blur' }]

View File

@ -159,7 +159,7 @@ const queryParams = reactive({
username: undefined,
mobile: undefined,
status: undefined,
deptId: undefined,
deptId: undefined as number | undefined,
createTime: []
})
const queryFormRef = ref() //

View File

@ -31,18 +31,17 @@ const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref({
id: undefined, //
id: undefined as number | undefined, //
adjustPrice: 0, //
payPrice: '', // ()
newPayPrice: '' // ()
})
watch(
() => formData.value.adjustPrice,
(adjustPrice: number | string) => {
(adjustPrice) => {
const numMatch = formData.value.payPrice.match(/\d+(\.\d+)?/)
if (numMatch) {
const payPriceNum = parseFloat(numMatch[0])
adjustPrice = typeof adjustPrice === 'string' ? parseFloat(adjustPrice) : adjustPrice
formData.value.newPayPrice = (payPriceNum + adjustPrice).toFixed(2) + '元'
}
}
@ -55,7 +54,7 @@ const open = async (row: TradeOrderApi.OrderVO) => {
resetForm()
formData.value.id = row.id!
//
formData.value.adjustPrice = formatToFraction(row.adjustPrice!)
formData.value.adjustPrice = Number(formatToFraction(row.adjustPrice!))
formData.value.payPrice = floatToFixed2(row.payPrice!) + '元'
formData.value.newPayPrice = formData.value.payPrice
dialogVisible.value = true

View File

@ -26,7 +26,10 @@ const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref({
const formData = ref<{
id: number | null | undefined
remark: string
}>({
id: undefined, //
remark: '' //
})
@ -37,7 +40,7 @@ const open = async (row: TradeOrderApi.OrderVO) => {
resetForm()
//
formData.value.id = row.id
formData.value.remark = row.remark
formData.value.remark = row.remark || ''
dialogVisible.value = true
}
defineExpose({ open }) // open