|
|
@@ -217,9 +217,8 @@
|
|
|
</el-select>
|
|
|
<el-date-picker
|
|
|
v-else-if="attribute.dataType === 'date'"
|
|
|
- v-model="attribute.actualValue"
|
|
|
+ v-model="attribute.dateValue"
|
|
|
type="date"
|
|
|
- value-format="x"
|
|
|
placeholder="请选择日期"
|
|
|
class="w-full"
|
|
|
/>
|
|
|
@@ -304,6 +303,7 @@ interface ExtendAttribute {
|
|
|
unit?: string
|
|
|
defaultValue?: string
|
|
|
actualValue?: string | number | null
|
|
|
+ dateValue?: Date | null
|
|
|
dropdownList?: Array<{ name: string; value: string | number }>
|
|
|
}
|
|
|
|
|
|
@@ -382,14 +382,32 @@ const normalizeExtendAttributes = (data: unknown): ExtendAttribute[] => {
|
|
|
return []
|
|
|
}
|
|
|
|
|
|
+const toDateValue = (value: unknown) => {
|
|
|
+ if (value === undefined || value === null || value === '') return null
|
|
|
+ const timestamp = Number(value)
|
|
|
+ if (!Number.isNaN(timestamp)) {
|
|
|
+ const date = new Date(timestamp)
|
|
|
+ if (!Number.isNaN(date.getTime())) return date
|
|
|
+ }
|
|
|
+ const date = new Date(String(value))
|
|
|
+ return Number.isNaN(date.getTime()) ? null : date
|
|
|
+}
|
|
|
+
|
|
|
+const prepareExtendAttributes = (attributes: ExtendAttribute[]) =>
|
|
|
+ attributes.map((attribute) => ({
|
|
|
+ ...attribute,
|
|
|
+ dateValue:
|
|
|
+ attribute.dataType === 'date'
|
|
|
+ ? toDateValue(attribute.actualValue ?? attribute.defaultValue)
|
|
|
+ : undefined,
|
|
|
+ actualValue: attribute.actualValue ?? attribute.defaultValue ?? ''
|
|
|
+ }))
|
|
|
+
|
|
|
const loadExtendAttributes = async (achievementType: string | number) => {
|
|
|
extendLoading.value = true
|
|
|
try {
|
|
|
const data = await getResultExtendList(achievementType)
|
|
|
- formData.value.extAttributes = normalizeExtendAttributes(data).map((attribute) => ({
|
|
|
- ...attribute,
|
|
|
- actualValue: attribute.actualValue ?? attribute.defaultValue ?? ''
|
|
|
- }))
|
|
|
+ formData.value.extAttributes = prepareExtendAttributes(normalizeExtendAttributes(data))
|
|
|
} finally {
|
|
|
extendLoading.value = false
|
|
|
}
|
|
|
@@ -412,10 +430,7 @@ const openForm = async (type: 'create' | 'update', id?: number) => {
|
|
|
formData.value = {
|
|
|
...createDefaultForm(),
|
|
|
...data,
|
|
|
- extAttributes: normalizeExtendAttributes(data.extAttributes).map((attribute) => ({
|
|
|
- ...attribute,
|
|
|
- actualValue: attribute.actualValue ?? attribute.defaultValue ?? ''
|
|
|
- }))
|
|
|
+ extAttributes: prepareExtendAttributes(normalizeExtendAttributes(data.extAttributes))
|
|
|
}
|
|
|
} finally {
|
|
|
formLoading.value = false
|
|
|
@@ -429,11 +444,23 @@ const submitForm = async () => {
|
|
|
if (!valid) return
|
|
|
formLoading.value = true
|
|
|
try {
|
|
|
+ const payload = {
|
|
|
+ ...formData.value,
|
|
|
+ extAttributes: formData.value.extAttributes.map(({ dateValue, ...attribute }) => ({
|
|
|
+ ...attribute,
|
|
|
+ actualValue:
|
|
|
+ attribute.dataType === 'date'
|
|
|
+ ? dateValue
|
|
|
+ ? dateValue.getTime()
|
|
|
+ : ''
|
|
|
+ : attribute.actualValue
|
|
|
+ }))
|
|
|
+ }
|
|
|
if (formType.value === 'create') {
|
|
|
- await createResult(formData.value)
|
|
|
+ await createResult(payload)
|
|
|
message.success('新增成功')
|
|
|
} else {
|
|
|
- await updateResult(formData.value)
|
|
|
+ await updateResult(payload)
|
|
|
message.success('更新成功')
|
|
|
}
|
|
|
dialogVisible.value = false
|