fix: 修复物模型导入问题

This commit is contained in:
wangshuaiswim 2023-03-31 16:06:00 +08:00
parent 39d6a156a8
commit ad14ce0242
2 changed files with 20 additions and 13 deletions

View File

@ -13,6 +13,9 @@
<j-input-number v-model:value="_value.scale" size="small" :min="0" :max="2147483647" :precision="0" <j-input-number v-model:value="_value.scale" size="small" :min="0" :max="2147483647" :precision="0"
style="width: 100%" placeholder="请输入精度"></j-input-number> style="width: 100%" placeholder="请输入精度"></j-input-number>
</j-form-item> </j-form-item>
<j-form-item label="时间格式" :name="name.concat(['format'])" v-if="['date'].includes(_value.type)" v-show="false">
<j-input v-model:value="_value.format" size="small"></j-input>
</j-form-item>
<j-form-item label="布尔值" name="booleanConfig" v-if="['boolean'].includes(_value.type)"> <j-form-item label="布尔值" name="booleanConfig" v-if="['boolean'].includes(_value.type)">
<BooleanParam :name="name" v-model:value="_value"></BooleanParam> <BooleanParam :name="name" v-model:value="_value"></BooleanParam>
</j-form-item> </j-form-item>
@ -159,6 +162,9 @@ const changeType = (val: SelectValue) => {
if (['file'].includes(val as string)) { if (['file'].includes(val as string)) {
_value.value.fileType = _value.value.fileType || 'url' _value.value.fileType = _value.value.fileType || 'url'
} }
if (['date'].includes(val as string)) {
_value.value.format = _value.value.format || 'yyyy-MM-DD HH:mm:ss'
}
emit('changeType', val as string) emit('changeType', val as string)
} }

View File

@ -49,7 +49,7 @@
</j-tooltip> </j-tooltip>
</j-space> </j-space>
</template> </template>
<JMonacoEditor v-model="formModel.import" theme="vs" style="height: 300px" lang="javascript"></JMonacoEditor> <JMonacoEditor v-model="formModel.import" theme="vs" style="height: 300px" lang="json"></JMonacoEditor>
</j-form-item> </j-form-item>
</j-form> </j-form>
</j-modal> </j-modal>
@ -206,14 +206,14 @@ const handleImport = async () => {
loading.value = true loading.value = true
const { id } = route.params || {} const { id } = route.params || {}
if (data.metadata === 'alink') { if (data.metadata === 'alink') {
const res = await convertMetadata('from', 'alink', data.import).catch(err => err) const res = await convertMetadata('from', 'alink', JSON.parse(data.import)).catch(err => err)
if (res.status === 200) { if (res.status === 200) {
const metadata = operateLimits(res.result) const metadata = operateLimits(res.result)
let result; let result;
if (props?.type === 'device') { if (props?.type === 'device') {
result = await saveMetadata(id as string, metadata).catch(err => err) result = await saveMetadata(id as string, metadata).catch(err => err)
} else { } else {
result = await modify(id as string, { metadata: metadata }).catch(err => err) result = await modify(id as string, { id, metadata: JSON.stringify(metadata) }).catch(err => err)
} }
if (result.success) { if (result.success) {
message.success('导入成功') message.success('导入成功')
@ -224,10 +224,11 @@ const handleImport = async () => {
// message.error('!') // message.error('!')
return return
} }
let resp
if (props?.type === 'device') { if (props?.type === 'device') {
instanceStore.refresh(id as string) await instanceStore.refresh(id as string)
} else { } else {
productStore.refresh(id as string) await productStore.refresh(id as string)
} }
metadataStore.set('importMetadata', true) metadataStore.set('importMetadata', true)
// Store.set(SystemConst.GET_METADATA, true) // Store.set(SystemConst.GET_METADATA, true)
@ -258,21 +259,21 @@ const handleImport = async () => {
loading.value = false loading.value = false
if (resp.success) { if (resp.success) {
if (props?.type === 'device') { if (props?.type === 'device') {
const detail = instanceStore.current // const detail = instanceStore.current
detail.metadata = JSON.stringify(paramsDevice) // detail.metadata = JSON.stringify(paramsDevice)
instanceStore.setCurrent(detail) // instanceStore.setCurrent(detail)
message.success('导入成功') message.success('导入成功')
} else { } else {
const detail = productStore.current // const detail = productStore.current
detail.metadata = params.metadata // detail.metadata = params.metadata
productStore.setCurrent(detail) // productStore.setCurrent(detail)
message.success('导入成功') message.success('导入成功')
} }
} }
if (props?.type === 'device') { if (props?.type === 'device') {
instanceStore.refresh(id as string) await instanceStore.refresh(id as string)
} else { } else {
productStore.refresh(id as string) await productStore.refresh(id as string)
} }
metadataStore.set('importMetadata', true) metadataStore.set('importMetadata', true)
// Store.set(SystemConst.GET_METADATA, true) // Store.set(SystemConst.GET_METADATA, true)