|
@@ -8,54 +8,84 @@ import {accidentPhotos} from "@/store/accidentPhotos";
|
|
|
import {roadPhotos} from "@/store/roadPhotos";
|
|
|
import {debounce, getId} from '@/utils'
|
|
|
import {watch} from "vue";
|
|
|
+import {params} from "@/hook";
|
|
|
+import router from "@/router";
|
|
|
|
|
|
-axios.get("/attach/sceneStore")
|
|
|
- .then((data) => {
|
|
|
- if (data.status === 200) {
|
|
|
- list.value = data.data.measures || []
|
|
|
- baseLines.value = data.data.baseLines || []
|
|
|
- basePoints.value = data.data.basePoints || []
|
|
|
- fixPoints.value = data.data.fixPoints || []
|
|
|
- photos.value = data.data.photos || []
|
|
|
- accidentPhotos.value = data.data.accidentPhotos || []
|
|
|
- roadPhotos.value = data.data.roadPhotos || []
|
|
|
+const global = window as any
|
|
|
+const api = import.meta.env.DEV && !global.android
|
|
|
+ ? {
|
|
|
+ async setStore(data) {
|
|
|
+ return axios.post("sceneStore", data)
|
|
|
+ },
|
|
|
+ async getStore() {
|
|
|
+ return (await axios.get("/attach/sceneStore")).data
|
|
|
+ },
|
|
|
+ async uploadImage(file) {
|
|
|
+ return (await axios({
|
|
|
+ url: "/upload",
|
|
|
+ headers: { "Content-Type": "multipart/form-data" },
|
|
|
+ method: 'post',
|
|
|
+ data: { file }
|
|
|
+ })).data.data
|
|
|
+ },
|
|
|
+ async downloadImage(file) {
|
|
|
+ window.open(URL.createObjectURL(file))
|
|
|
+ },
|
|
|
+ closePage() {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
+ : {
|
|
|
+ async setStore(data) {
|
|
|
+ global.android.setSceneStore(params.m, data)
|
|
|
+ },
|
|
|
+ async getStore() {
|
|
|
+ return global.android.getSceneStore(params.m)
|
|
|
+ },
|
|
|
+ async uploadImage(file) {
|
|
|
+ return global.android.uploadImage(params.m, file)
|
|
|
+ },
|
|
|
+ async downloadImage(file) {
|
|
|
+ global.android.downloadImage(params.m, file)
|
|
|
+ },
|
|
|
+ closePage() {
|
|
|
|
|
|
- // roadPhotos.value.map(data => {
|
|
|
- // data.url = data.photoUrl
|
|
|
- // })
|
|
|
- // accidentPhotos.value.map(data => {
|
|
|
- // data.url = data.photoUrl
|
|
|
- // })
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- syncSceneStore()
|
|
|
- })
|
|
|
+export const back = () => {
|
|
|
+ if (history.state.back) {
|
|
|
+ router.back()
|
|
|
+ } else {
|
|
|
+ api.closePage()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const loadStore = async () => {
|
|
|
+ const data = await api.getStore()
|
|
|
+ list.value = data?.measures || []
|
|
|
+ baseLines.value = data?.baseLines || []
|
|
|
+ basePoints.value = data?.basePoints || []
|
|
|
+ fixPoints.value = data?.fixPoints || []
|
|
|
+ photos.value = data?.photos || []
|
|
|
+ accidentPhotos.value = data?.accidentPhotos || []
|
|
|
+ roadPhotos.value = data?.roadPhotos || []
|
|
|
|
|
|
-export const updateSceneStore = debounce((data) => {
|
|
|
- axios.post("sceneStore", data)
|
|
|
-}, 1000)
|
|
|
+ syncSceneStore()
|
|
|
+}
|
|
|
|
|
|
-export const uploadImage = async (blob: Blob) => {
|
|
|
+export const updateSceneStore = debounce(api.setStore, 1000)
|
|
|
+export const uploadImage = (blob: Blob) => {
|
|
|
const file = new File([blob], `${getId()}.jpg`)
|
|
|
- const res = await axios({
|
|
|
- url: "/upload",
|
|
|
- headers: { "Content-Type": "multipart/form-data" },
|
|
|
- method: 'post',
|
|
|
- data: { file }
|
|
|
- });
|
|
|
- return res.data.data
|
|
|
+ return api.uploadImage(file)
|
|
|
}
|
|
|
|
|
|
export const downloadImage = async (data: Blob | string, name: string = getId()) => {
|
|
|
const blob: Blob = typeof data === "string"
|
|
|
? (await axios.get(data, { responseType: "blob" })).data
|
|
|
: data
|
|
|
-
|
|
|
- if (import.meta.env.DEV) {
|
|
|
- window.open(URL.createObjectURL(blob))
|
|
|
- } else {
|
|
|
- const file = new File([blob], name)
|
|
|
- }
|
|
|
+ const file = new File([blob], name, {type: "image/jpeg"})
|
|
|
+ await api.downloadImage(file)
|
|
|
}
|
|
|
|
|
|
const syncSceneStore = () => {
|
|
@@ -74,4 +104,10 @@ const syncSceneStore = () => {
|
|
|
},
|
|
|
{ deep: true }
|
|
|
)
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+loadStore()
|
|
|
+ .catch((e) => {
|
|
|
+ console.error(e)
|
|
|
+ alert("场景数据加载失败")
|
|
|
+ })
|