|
|
|
|
@ -1,6 +1,13 @@
|
|
|
|
|
<template>
|
|
|
|
|
<Dialog :title="dialogTitle" v-model="dialogVisible" width="720px">
|
|
|
|
|
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="100px" v-loading="formLoading">
|
|
|
|
|
<el-form
|
|
|
|
|
ref="formRef"
|
|
|
|
|
:model="formData"
|
|
|
|
|
:rules="formRules"
|
|
|
|
|
label-width="100px"
|
|
|
|
|
v-loading="formLoading || isFileUploading"
|
|
|
|
|
:element-loading-text="isFileUploading ? t('MoldManagement.MoldBrandFormPage.fileUploadingText') : ''"
|
|
|
|
|
>
|
|
|
|
|
<el-row :gutter="16">
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
<el-form-item :label="t('MoldManagement.MoldBrandFormPage.code')" prop="code">
|
|
|
|
|
@ -63,7 +70,13 @@
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="24">
|
|
|
|
|
<el-form-item :label="t('MoldManagement.MoldBrandFormPage.drawings')" prop="drawings">
|
|
|
|
|
<UploadFile v-model="drawingsValue" :limit="9" :file-type="drawingFileTypes" :is-show-tip="false" />
|
|
|
|
|
<UploadFile
|
|
|
|
|
v-model="drawingsValue"
|
|
|
|
|
:limit="9"
|
|
|
|
|
:file-type="drawingFileTypes"
|
|
|
|
|
:is-show-tip="false"
|
|
|
|
|
@uploading-change="setFileUploading('drawings', $event)"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="24">
|
|
|
|
|
@ -73,6 +86,7 @@
|
|
|
|
|
:limit="9"
|
|
|
|
|
:file-type="manualFileTypes"
|
|
|
|
|
:is-show-tip="false"
|
|
|
|
|
@uploading-change="setFileUploading('operationManual', $event)"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
@ -83,6 +97,7 @@
|
|
|
|
|
:limit="9"
|
|
|
|
|
:file-type="videoFileTypes"
|
|
|
|
|
:is-show-tip="false"
|
|
|
|
|
@uploading-change="setFileUploading('operationVideo', $event)"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
@ -102,7 +117,7 @@
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<el-button type="primary" :disabled="formLoading" @click="submitForm">{{ t('MoldManagement.MoldBrandFormPage.save') }}</el-button>
|
|
|
|
|
<el-button type="primary" :loading="formLoading || isFileUploading" :disabled="formLoading || isFileUploading" @click="submitForm">{{ t('MoldManagement.MoldBrandFormPage.save') }}</el-button>
|
|
|
|
|
<el-button @click="dialogVisible = false">{{ t('MoldManagement.MoldBrandFormPage.close') }}</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</Dialog>
|
|
|
|
|
@ -226,6 +241,12 @@ const productQueryParams = reactive({
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
const dialogTitle = ref('')
|
|
|
|
|
const formLoading = ref(false)
|
|
|
|
|
const fileUploadingMap = reactive({
|
|
|
|
|
drawings: false,
|
|
|
|
|
operationManual: false,
|
|
|
|
|
operationVideo: false
|
|
|
|
|
})
|
|
|
|
|
const isFileUploading = computed(() => Object.values(fileUploadingMap).some(Boolean))
|
|
|
|
|
const formType = ref('')
|
|
|
|
|
const formRef = ref()
|
|
|
|
|
const statusOptions = computed(() => getIntDictOptions(DICT_TYPE.ERP_MOLD_STATUS))
|
|
|
|
|
@ -255,6 +276,16 @@ const manualFileTypes = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'tx
|
|
|
|
|
const videoFileTypes = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'webm']
|
|
|
|
|
const drawingFileTypes = ['dwg', 'dxf', 'step', 'stp', 'igs', 'iges']
|
|
|
|
|
|
|
|
|
|
const setFileUploading = (field: keyof typeof fileUploadingMap, uploading: boolean) => {
|
|
|
|
|
fileUploadingMap[field] = uploading
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resetFileUploading = () => {
|
|
|
|
|
;(Object.keys(fileUploadingMap) as Array<keyof typeof fileUploadingMap>).forEach((field) => {
|
|
|
|
|
fileUploadingMap[field] = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const splitAssetValue = (value: unknown): string[] => {
|
|
|
|
|
if (!value) return []
|
|
|
|
|
if (Array.isArray(value)) return value.flatMap((item) => splitAssetValue(item))
|
|
|
|
|
@ -278,6 +309,61 @@ const splitAssetValue = (value: unknown): string[] => {
|
|
|
|
|
|
|
|
|
|
const normalizeAssetString = (value: unknown) => splitAssetValue(value).join(',')
|
|
|
|
|
|
|
|
|
|
type AssetFileInfo = {
|
|
|
|
|
fileName: string
|
|
|
|
|
fileUrl: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getAssetName = (url: string): string => {
|
|
|
|
|
const cleanUrl = String(url || '').split('?')[0]
|
|
|
|
|
const idx = cleanUrl.lastIndexOf('/')
|
|
|
|
|
const name = idx !== -1 ? cleanUrl.substring(idx + 1) : cleanUrl
|
|
|
|
|
try {
|
|
|
|
|
return decodeURIComponent(name)
|
|
|
|
|
} catch {
|
|
|
|
|
return name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const parseAssetFileInfos = (value: unknown): AssetFileInfo[] => {
|
|
|
|
|
if (!value) return []
|
|
|
|
|
if (Array.isArray(value)) return value.flatMap((item) => parseAssetFileInfos(item))
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
|
const item = value as any
|
|
|
|
|
if (item.fileUrl) {
|
|
|
|
|
const fileUrl = String(item.fileUrl).trim()
|
|
|
|
|
if (!fileUrl) return []
|
|
|
|
|
return [{
|
|
|
|
|
fileName: item.fileName ? String(item.fileName) : getAssetName(fileUrl),
|
|
|
|
|
fileUrl
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const text = String(value).trim()
|
|
|
|
|
if (!text) return []
|
|
|
|
|
if (text.startsWith('{') || text.startsWith('[')) {
|
|
|
|
|
try {
|
|
|
|
|
return parseAssetFileInfos(JSON.parse(text))
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
.replace(/[`'"]/g, '')
|
|
|
|
|
.split(',')
|
|
|
|
|
.map((item) => item.trim())
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
.map((fileUrl) => ({
|
|
|
|
|
fileName: getAssetName(fileUrl),
|
|
|
|
|
fileUrl
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const normalizeAssetFileInfoString = (value: unknown): string => {
|
|
|
|
|
const infos = parseAssetFileInfos(value)
|
|
|
|
|
return infos.length ? JSON.stringify(infos) : ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 图纸字段专用处理函数,支持 JSON 格式
|
|
|
|
|
const parseDrawingValue = (value: unknown): string => {
|
|
|
|
|
if (!value) return ''
|
|
|
|
|
@ -298,13 +384,13 @@ const drawingsValue = computed({
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const operationManualValue = computed({
|
|
|
|
|
get: () => splitAssetValue((formData.value as any).operationManual),
|
|
|
|
|
set: (value: any) => { ;(formData.value as any).operationManual = normalizeAssetString(value) }
|
|
|
|
|
get: () => normalizeAssetFileInfoString((formData.value as any).operationManual),
|
|
|
|
|
set: (value: any) => { ;(formData.value as any).operationManual = normalizeAssetFileInfoString(value) }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const operationVideoValue = computed({
|
|
|
|
|
get: () => splitAssetValue((formData.value as any).operationVideo),
|
|
|
|
|
set: (value: any) => { ;(formData.value as any).operationVideo = normalizeAssetString(value) }
|
|
|
|
|
get: () => normalizeAssetFileInfoString((formData.value as any).operationVideo),
|
|
|
|
|
set: (value: any) => { ;(formData.value as any).operationVideo = normalizeAssetFileInfoString(value) }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const validateCode = (_rule: any, value: any, callback: any) => {
|
|
|
|
|
@ -336,6 +422,7 @@ const formRules = reactive({
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
resetFileUploading()
|
|
|
|
|
formData.value = {
|
|
|
|
|
id: undefined as unknown as number,
|
|
|
|
|
code: '',
|
|
|
|
|
@ -463,6 +550,10 @@ defineExpose({ open })
|
|
|
|
|
const emit = defineEmits(['success'])
|
|
|
|
|
|
|
|
|
|
const submitForm = async () => {
|
|
|
|
|
if (isFileUploading.value) {
|
|
|
|
|
message.warning(t('MoldManagement.MoldBrandFormPage.fileUploadingText'))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
await formRef.value.validate()
|
|
|
|
|
formLoading.value = true
|
|
|
|
|
try {
|
|
|
|
|
@ -471,8 +562,8 @@ const submitForm = async () => {
|
|
|
|
|
...formData.value,
|
|
|
|
|
productIds: Array.isArray(formData.value.productIds) ? formData.value.productIds : [],
|
|
|
|
|
drawings: (formData.value as any).drawings,
|
|
|
|
|
operationManual: normalizeAssetString((formData.value as any).operationManual),
|
|
|
|
|
operationVideo: normalizeAssetString((formData.value as any).operationVideo),
|
|
|
|
|
operationManual: normalizeAssetFileInfoString((formData.value as any).operationManual),
|
|
|
|
|
operationVideo: normalizeAssetFileInfoString((formData.value as any).operationVideo),
|
|
|
|
|
isEnable: Boolean(formData.value.isEnable)
|
|
|
|
|
}
|
|
|
|
|
if (formType.value === 'create') {
|
|
|
|
|
|