From 2af5f043b60c1f7ac38ecccc8f5bf44743134325 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期五, 12 十二月 2025 18:08:00 +0800
Subject: [PATCH] test
---
pages/index/backup.vue | 266 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 212 insertions(+), 54 deletions(-)
diff --git a/pages/index/backup.vue b/pages/index/backup.vue
index acdc864..241ef59 100644
--- a/pages/index/backup.vue
+++ b/pages/index/backup.vue
@@ -25,14 +25,20 @@
<view class="list-no-content" v-else>
<!-- <image class="img" src="/images/icon-park-outline_attention.svg" alt=" 鍥剧墖" mode="aspectFit" />-->
<uni-icons color="#ccc" type="info" size="128"></uni-icons>
- <view class="space">娌℃湁鎵惧埌绗﹀悎鏉′欢鐨勫満鏅�/view>
+ <view class="space">{{translate('no_scene_matching_criteria')}}</view>
</view>
- <view class="list-tip">璇烽�鎷╀笂浼犲埌鎵嬫満绔殑鍦烘櫙</view>
+ <view class="list-tip">{{translate('select_scene_to_upload_mobile')}}</view>
<view>
- <a-button :disabled="loading|| sceneIndex < 0" type="primary" class="button"
- @click="clickSaveToLocal">涓婁紶鑷虫墜鏈虹</a-button>
+ <a-button v-if="!loading" :disabled=" sceneIndex < 0" type="primary" class="button"
+ @click="clickSaveToLocal">{{translate('upload_to_mobile')}}</a-button>
+
</view>
+ <view v-if="loading && loadingPage== 0" class="list-progress">
+ {{translate("scene_uploading") }}...
+ <view class="spinner"></view>
+ </view>
+
</view>
</swiper-item>
@@ -51,13 +57,19 @@
<view class="list-no-content" v-else>
<!-- <image class="img" src="/images/icon-park-outline_attention.svg" alt=" 鍥剧墖" mode="aspectFit" />-->
<uni-icons color="#ccc" type="info" size="128"></uni-icons>
- <view class="space">娌℃湁鎵惧埌绗﹀悎鏉′欢鐨勫満鏅�/view>
+ <view class="space">{{translate('no_scene_matching_criteria')}}</view>
</view>
- <view class="list-tip">璇烽�鎷╀笅杞藉埌杞﹁締绔殑鍦烘櫙</view>
+ <view class="list-tip">{{translate('select_scene_to_download_vehicle')}}</view>
<view>
- <a-button :disabled="loading|| sceneIndex2< 0" type="primary" class="button"
- @click="clickSaveToVehicle">涓嬭浇鑷宠溅杈嗙</a-button>
+ <a-button v-if="!loading" :disabled="sceneIndex2< 0" type="primary" class="button"
+ @click="clickSaveToVehicle">{{translate('download_to_vehicle')}}</a-button>
+
</view>
+ <view v-if="loading && loadingPage== 1" class="list-progress">
+ {{translate("scene_downloading") }}...{{saveDBDataStatusStr}}
+ <view class="spinner"></view>
+ </view>
+
</view>
</swiper-item>
@@ -79,11 +91,17 @@
getAllScene,
handoffScene,
saveDBData,
- getDBData
+ getDBData,
+ getSaveDBDataStatus,
+ cancelSaveDBData
+
} from "@/api/vehicle.js"
import {
Button
} from 'antd-mobile-vue-next'
+ import {
+ async
+ } from "rxjs"
export default {
name: "PagesBackup",
components: {
@@ -95,21 +113,76 @@
sceneIndex: -1,
sceneIndex2: -1,
curPageIndex: 0,
+ loadingPage: 0,
+ opType: "",
pageList: [{
- name: "涓婁紶鍦烘櫙",
- title: "ES-GO1鍦烘櫙鍒楄〃",
+ name: this.translate('upload_scenes'),
+ title: `ES-GO1 ${this.translate('scene_list')}`,
list: []
}, {
- name: "涓嬭浇鍦烘櫙",
- title: "鎵嬫満绔繚瀛樼殑鍦烘櫙鍒楄〃",
+ name: this.translate('download_scenes'),
+ title: this.translate('scene_list_on_cellphone'),
list: []
- }]
+ }],
+ saveDBDataStatus: 0,
}
},
- computed: {},
+ computed: {
+
+ saveDBDataStatusStr() {
+ if (this.saveDBDataStatus == 2) {
+ return this.translate("saved_success")
+ } else if (this.saveDBDataStatus == 3) {
+ return this.translate("saved_fail")
+ } else {
+ return this.translate("saving")
+ }
+ }
+ },
onLoad(option) {
this.ip = option.ip || ""
+ this.opType = option.opType || ""
+ if (this.opType == "download") {
+ this.curPageIndex = 1
+ }
+
+ uni.setNavigationBarTitle({
+ title: this.translate('scene_backup')
+ })
this.loadData()
+ },
+ onBackPress() {
+
+ const _this = this
+ if (this.loading) {
+ showModal({
+ title: this.translate("ask_exit_page"),
+ content: this.loadingPage == 1 ? `${this.translate('scene_downloading')}` :
+ `${this.translate('scene_uploading')}`,
+ confirmText: this.translate('yes'),
+ cancelText: this.translate("no"),
+ }).then(async (res) => {
+ if (res) {
+
+ await _this.cancelSaveDBData()
+ _this.saveDBDataStatus = 3
+ _this.setData({
+ loading: false
+ })
+ uni.navigateBack({
+ delta: 1, //杩斿洖灞傛暟锛�鍒欎笂涓婇〉
+ })
+ }
+
+ })
+ return true
+ }
+ if (this.opType == "download") {
+ uni.reLaunch({
+ url: "/pages/index/index"
+ })
+ return true
+ }
},
methods: {
setData(obj) {
@@ -137,10 +210,10 @@
try {
this.pageList[0].list = await this.loadScene()
this.pageList[1].list = await this.loadLocalScene()
-
+
console.log(this.pageList[1].list)
} catch (ex) {
- showError(ex)
+ showError(ex, this.translate('error'))
}
},
async loadScene() {
@@ -149,7 +222,7 @@
const list = res?.sceneList || []
return list
} catch (ex) {
- showError(ex)
+ showError(ex, this.translate('error'))
return []
}
},
@@ -158,7 +231,7 @@
const list = session.getValue("scene_db") || []
return list
} catch (ex) {
- showError(ex)
+ showError(ex, this.translate('error'))
return []
}
},
@@ -197,12 +270,17 @@
const _this = this
let list = this.pageList[1].list
if (list.length > 0) {
- showModal(`涓婁紶璇ュ満鏅細鏇挎崲鎺夊綋鍓嶅凡涓婁紶鐨勫満鏅痐, "鏄惁瑕佽鐩栧満鏅紵").then(async (res) => {
+ showModal({
+ title: this.translate('confirm_replace_scene'),
+ content: this.translate('uploading_will_replace_currently_uploaded_scene'),
+ confirmText: this.translate("confirm"),
+ cancelText: this.translate("cancel"),
+ }).then(async (res) => {
if (res) {
_this.saveToLocal(this.sceneIndex)
}
})
-
+
return
}
_this.saveToLocal(this.sceneIndex)
@@ -210,32 +288,33 @@
async saveToLocal(index) {
try {
this.setData({
- loading: true
+ loading: true,
+ loadingPage: 0,
})
- uni.showLoading({
- title:"姝e湪涓婁紶鍦烘櫙"
- })
+
+ // uni.showLoading({
+ // title: `${this.translate('upload_scenes')}...`
+ // })
const scene = this.pageList[0].list[index]
await handoffScene(this.ip, "", scene)
session.setValue("scene_db", [])
const res = await getDBData(this.ip)
const list = [{
name: scene,
- data: res ||[]
+ data: res || []
}]
session.setValue("scene_db", list)
this.pageList[1].list = list
this.sceneIndex2 = -1
- showToast(`涓婁紶鍦烘櫙[${scene}]鎴愬姛`)
+ showToast(this.translate('upload_success'))
} catch (ex) {
- showError(ex)
-
- }
- finally {
+ showError(ex, this.translate('error'))
+
+ } finally {
this.setData({
loading: false
})
- uni.hideLoading()
+ // uni.hideLoading()
}
},
@@ -244,43 +323,94 @@
const scene = this.pageList[1].list[this.sceneIndex2].name
let list = this.pageList[0].list
const curIndex = list.findIndex((a) => a == scene)
- console.log(curIndex, scene,list)
+ console.log(curIndex, scene, list)
if (curIndex > -1) {
- showModal(`涓嬭浇璇ュ満鏅細鏇挎崲鎺夊凡涓嬭浇鐨勫悓鍚嶅満鏅�`, "鏄惁瑕佽鐩栧満鏅紵").then(async (res) => {
+ showModal({
+ title: this.translate('confirm_replace_scene'),
+ content: this.translate('downloading_will_replace_currently_downloaded_scene'),
+ confirmText: this.translate("confirm"),
+ cancelText: this.translate("cancel"),
+ }).then(async (res) => {
if (res) {
_this.saveToVehicle(this.sceneIndex2)
}
})
-
+
return
}
_this.saveToVehicle(this.sceneIndex2)
},
+ async cancelSaveDBData() {
+ try {
+ await cancelSaveDBData(this.ip)
+ } catch (ex) {
+ showToast(ex)
+ }
+ },
+ async checkSaveDBDataStatus() {
+ try {
+
+ if (this.saveDBDataStatus === 2 || this.saveDBDataStatus === 3) {
+ this.setData({
+ loading: false
+ })
+ if (this.saveDBDataStatus === 2) {
+ const scene = this.pageList[1].list[this.sceneIndex2]?.name
+ this.pageList[0].list.push(scene)
+ showToast(this.translate('download_success'))
+ }
+ return
+ }
+ this.saveDBDataStatus = await getSaveDBDataStatus(this.ip) || 0
+
+ if (this.saveDBDataStatus === 2 || this.saveDBDataStatus === 3) {
+ this.setData({
+ loading: false
+ })
+ if (this.saveDBDataStatus === 2) {
+ const scene = this.pageList[1].list[this.sceneIndex2]?.name
+ this.pageList[0].list.push(scene)
+ showToast(this.translate('download_success'))
+ } else {
+ showToast(`${this.translate('update_fail')}, ${this.translate('saved_fail')} `)
+ }
+ return
+ }
+ setTimeout(this.checkSaveDBDataStatus, 1000);
+ } catch (ex) {
+ showToast(ex)
+ setTimeout(this.checkSaveDBDataStatus, 1000);
+ }
+ },
+
async saveToVehicle(index) {
try {
this.setData({
- loading: true
+ loading: true,
+ loadingPage: 1,
})
- uni.showLoading({
- title:"姝e湪涓嬭浇鍦烘櫙"
- })
-
+ // uni.showLoading({
+ // title: `${this.translate('download_scenes')}...`
+ // })
+
const data = this.pageList[1].list[index].data
const scene = this.pageList[1].list[index].name
+ this.saveDBDataStatus = 1
await saveDBData(this.ip, data)
- this.pageList[0].list.push(scene)
- showToast(`涓嬭浇鍦烘櫙[${scene}]鎴愬姛`)
-
+ this.checkSaveDBDataStatus()
+
+
} catch (ex) {
- showError(ex)
- }
- finally {
this.setData({
loading: false
})
- uni.hideLoading()
+ showError(ex, this.translate('error'))
}
+ },
+ translate(t) {
+ if (typeof this.$t == "function") return this.$t(`page.${t}`)
+ else return t;
},
@@ -298,7 +428,7 @@
.switch-type {
width: calc(100% - 40rpx);
- margin: 20rpx 20rpx 10rpx 20rpx;
+ margin: 20rpx 20rpx 10rpx 20rpx;
align-items: center;
vertical-align: middle;
@@ -345,32 +475,40 @@
flex-direction: column;
padding: 0 10rpx;
+ .list-progress {
+ width: 100%;
+ text-align: center;
+ margin: 20rpx;
+ }
+
.list-tip {
width: 100%;
padding: 15rpx;
color: #888;
+
}
-
+
.list-view {
width: 100%;
//flex: 1;
border-radius: 10rpx;
overflow: auto;
background-color: #fff;
- max-height:500rpx ;
+ max-height: 500rpx;
+
.list-item {
border-bottom: 1px solid #ddd;
display: flex;
flex-direction: row;
- padding:20rpx;
+ padding: 20rpx;
.list-name {
flex: 1;
margin-right: 20rpx;
font-size: 32rpx;
font-weight: 700;
- padding:10rpx 0;
+ padding: 10rpx 0;
}
}
@@ -404,13 +542,33 @@
}
.am-button {
- border-radius: 90rpx;
- height: 90rpx;
+ border-radius: 40rpx;
+ height: 80rpx;
line-height: 60rpx;
}
}
+ /* CSS鍔ㄧ敾绀轰緥锛氭棆杞殑鍦嗙幆 */
+ .spinner {
+ width: 100rpx;
+ height: 100rpx;
+ border: 4px solid #f3f3f3;
+ border-top: 4px solid #007aff;
+ border-radius: 50%;
+ animation: spin 1s linear infinite;
+ margin: 20rpx auto;
+ }
+
+ @keyframes spin {
+ 0% {
+ transform: rotate(0deg);
+ }
+
+ 100% {
+ transform: rotate(360deg);
+ }
+ }
}
--
Gitblit v1.9.1