页面接口推介
This commit is contained in:
@@ -88,7 +88,9 @@
|
||||
<view
|
||||
class="temp-list-item"
|
||||
:class="{
|
||||
'temp-list-item-active': formData.tempFiles.some((item2) => item2.id === item.id),
|
||||
'temp-list-item-active': formData.tempFiles.some(
|
||||
(item2) => item2.id === item.id || item2.topoId === item.id,
|
||||
),
|
||||
}"
|
||||
v-for="(item, index) in tempList"
|
||||
@click="chooseTempItem(item)"
|
||||
@@ -104,7 +106,7 @@
|
||||
</template>
|
||||
<script>
|
||||
import { pinyin } from 'pinyin-pro'
|
||||
import { addAppProject } from '../../common/api/project'
|
||||
import { addAppProject, updateAppProject } from '../../common/api/project'
|
||||
import { getTopoTemplate } from '../../common/api/device'
|
||||
import { queryEngineering } from '@/common/api/engineering.js'
|
||||
export default {
|
||||
@@ -125,7 +127,7 @@ export default {
|
||||
},
|
||||
engineeringList: [],
|
||||
tempList: [],
|
||||
project: '',
|
||||
project: null,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -150,6 +152,9 @@ export default {
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.project) {
|
||||
uni.setNavigationBarTitle({
|
||||
title: '编辑项目',
|
||||
})
|
||||
this.project = JSON.parse(decodeURIComponent(options.project))
|
||||
console.log(this.project)
|
||||
for (let key in this.formData) {
|
||||
@@ -172,6 +177,20 @@ export default {
|
||||
getTopoTemplate().then((res) => {
|
||||
console.log(res)
|
||||
this.tempList = res.data
|
||||
if (this.project) {
|
||||
this.project.topologyDiagramPaths.forEach((item) => {
|
||||
if (this.tempList.some((item2) => item2.id === item.topoId)) {
|
||||
this.formData.tempFiles.push(item)
|
||||
} else {
|
||||
this.formData.files.push({
|
||||
url: item.filePath,
|
||||
extname: item.name.split('.')[1],
|
||||
name: item.name,
|
||||
...item,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
@@ -179,8 +198,10 @@ export default {
|
||||
this.formData.tempFiles.splice(index, 1)
|
||||
},
|
||||
chooseTempItem(item) {
|
||||
if (this.formData.tempFiles.some((item2) => item2.id === item.id)) {
|
||||
this.formData.tempFiles = this.formData.tempFiles.filter((item2) => item2.id !== item.id)
|
||||
if (this.formData.tempFiles.some((item2) => item2.id === item.id || item2.topoId === item.id)) {
|
||||
this.formData.tempFiles = this.formData.tempFiles.filter(
|
||||
(item2) => item2.id !== item.id && item2.topoId !== item.id,
|
||||
)
|
||||
} else {
|
||||
this.formData.tempFiles.push(item)
|
||||
}
|
||||
@@ -243,27 +264,33 @@ export default {
|
||||
uri: item.url,
|
||||
})
|
||||
}
|
||||
this.formData.topoIds = this.formData.tempFiles.map((item) => item.id)
|
||||
this.formData.topoIds = this.formData.tempFiles.map((item) => (item.topoId ? item.topoId : item.id))
|
||||
let data = JSON.parse(JSON.stringify(this.formData))
|
||||
delete data.files
|
||||
addAppProject(data, arr).then((res) => {
|
||||
console.warn(res)
|
||||
if (res.length === 1) {
|
||||
this.$util.toast(res[0].message)
|
||||
return
|
||||
}
|
||||
console.log(res)
|
||||
let result = JSON.parse(res[1].data)
|
||||
if (result.code === 'A0000') {
|
||||
this.$util.toast('项目创建成功')
|
||||
this.$util.prePage().store?.reload()
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({ delta: 1 })
|
||||
}, 1500)
|
||||
let res = {}
|
||||
if (this.project) {
|
||||
data.id = this.project.id
|
||||
res = await updateAppProject(data, arr)
|
||||
} else {
|
||||
res = await addAppProject(data, arr)
|
||||
}
|
||||
console.log(res)
|
||||
if (res.length === 1) {
|
||||
this.$util.toast(res[0].message)
|
||||
return
|
||||
}
|
||||
let result = JSON.parse(res[1].data)
|
||||
if (result.code === 'A0000') {
|
||||
if (this.project) {
|
||||
this.$util.toast('项目修改成功')
|
||||
this.$util.refreshPrePage(2)
|
||||
} else {
|
||||
this.$util.toast(result.message)
|
||||
this.$util.toast('项目创建成功')
|
||||
this.$util.refreshPrePage()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.$util.toast(result.message)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user