cuiqian2004
2025-09-19 d8743368ffda9bc0fb2c6818f695a9a6b1079e57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<template>
    <view class="pages-backup">
        <view class="switch-type">
            <view class="switch-button-group">
                <view class="switch-button" v-for="(page,index) in pageList" :key="page.name"
                    :class="curPageIndex ==index?'switch-button-checked':''" @click="onSelectPage(index)">
                    {{page.name}}
                </view>
 
            </view>
        </view>
        <swiper circular indicator-dots class="swiper" :current="curPageIndex" @change="changePageSwiper">
            <swiper-item class="swiper-item">
                <view class="list">
                    <view class="list-tip">{{pageList[0].title}}</view>
                    <view class="list-view" v-if="pageList[0].list.length > 0">
                        <view class="list-item" v-for="(item,index) in pageList[0].list" :key="index"
                            @click="clickSceneItem(index)">
                            <view class="list-name">{{item}}</view>
 
                            <uni-icons v-if="sceneIndex === index" type="checkmarkempty" size="20"
                                color="#1890FF"></uni-icons>
                        </view>
                    </view>
                    <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>
                    <view class="list-tip">请选择上传到手机端的场景</view>
                    <view>
 
                        <a-button :disabled="loading|| sceneIndex < 0" type="primary" class="button"
                            @click="clickSaveToLocal">上传至手机端</a-button>
                    </view>
                </view>
 
            </swiper-item>
            <swiper-item class="swiper-item">
                <view class="list">
                    <view class="ist-tip">{{pageList[1].title}}</view>
                    <view class="list-view" v-if="pageList[1].list.length > 0">
                        <view class="list-item" v-for="(item,index) in pageList[1].list" :key="index"
                            @click="clickSceneItem2(index)">
                            <view class="list-name">{{item.name}}</view>
 
                            <uni-icons v-if="sceneIndex2 === index" type="checkmarkempty" size="20"
                                color="#1890FF"></uni-icons>
                        </view>
                    </view>
                    <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>
                    <view class="list-tip">请选择下载到车辆端的场景</view>
                    <view>
                        <a-button :disabled="loading|| sceneIndex2< 0" type="primary" class="button"
                            @click="clickSaveToVehicle">下载至车辆端</a-button>
                    </view>
                </view>
 
            </swiper-item>
 
        </swiper>
 
    </view>
</template>
 
<script>
    import {
        session,
        showToast,
        showModal,
        showInfo,
        showError
    } from "@/comm/utils.js"
    import {
        getAllScene,
        handoffScene,
        saveDBData,
        getDBData
    } from "@/api/vehicle.js"
    import {
        Button
    } from 'antd-mobile-vue-next'
    export default {
        name: "PagesBackup",
        components: {
            'a-button': Button
        },
        data() {
            return {
                loading: false,
                sceneIndex: -1,
                sceneIndex2: -1,
                curPageIndex: 0,
                pageList: [{
                    name: "上传场景",
                    title: "ES-GO1场景列表",
                    list: []
                }, {
                    name: "下载场景",
                    title: "手机端保存的场景列表",
                    list: []
                }]
            }
        },
        computed: {},
        onLoad(option) {
            this.ip = option.ip || ""
            this.loadData()
        },
        methods: {
            setData(obj) {
                let that = this;
                let keys = [];
                let val, data;
 
                Object.keys(obj).forEach(function(key) {
                    keys = key.split(".");
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2, index) {
                        if (index + 1 == keys.length) {
                            that.$set(data, key2, val);
                        } else {
                            if (!data[key2]) {
                                that.$set(data, key2, {});
                            }
                        }
                        data = data[key2];
                    });
                });
            },
            async loadData() {
                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)
                }
            },
            async loadScene() {
                try {
                    const res = await getAllScene(this.ip) || []
                    const list = res?.sceneList || []
                    return list
                } catch (ex) {
                    showError(ex)
                    return []
                }
            },
            async loadLocalScene() {
                try {
                    const list = session.getValue("scene_db") || []
                    return list
                } catch (ex) {
                    showError(ex)
                    return []
                }
            },
            changePageSwiper(evt) {
                if (this.loading)
                    return
                let index = evt.target.current || evt.detail.current;
                this.setData({
                    curPageIndex: index
                })
            },
 
            onSelectPage(index) {
                if (this.loading)
                    return
                this.setData({
                    curPageIndex: index
                })
            },
            clickSceneItem(index) {
                if (this.loading)
                    return
                this.setData({
                    sceneIndex: index
                })
            },
            clickSceneItem2(index) {
                if (this.loading)
                    return
                this.setData({
                    sceneIndex2: index
                })
            },
 
            clickSaveToLocal() {
                const _this = this
                let list = this.pageList[1].list
                if (list.length > 0) {
                    showModal(`上传该场景会替换掉当前已上传的场景`, "是否要覆盖场景?").then(async (res) => {
                        if (res) {
                            _this.saveToLocal(this.sceneIndex)
                        }
                    })
                    
                    return
                }
                _this.saveToLocal(this.sceneIndex)
            },
            async saveToLocal(index) {
                try {
                    this.setData({
                        loading: true
                    })
                    uni.showLoading({
                        title:"正在上传场景"
                    })
                    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 ||[] 
                    }]
                    session.setValue("scene_db", list)
                    this.pageList[1].list = list
                    this.sceneIndex2 = -1
                    showToast(`上传场景[${scene}]成功`)
                } catch (ex) {
                    showError(ex)
                
                }
                finally {
                    this.setData({
                        loading: false
                    })
                    uni.hideLoading()
                }
 
            },
            clickSaveToVehicle() {
                const _this = this
                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)
                if (curIndex > -1) {
                    showModal(`下载该场景会替换掉已下载的同名场景。`, "是否要覆盖场景?").then(async (res) => {
                        if (res) {
                            _this.saveToVehicle(this.sceneIndex2)
                        }
                    })
                    
                    return
                }
                _this.saveToVehicle(this.sceneIndex2)
            },
            async saveToVehicle(index) {
                try {
                    this.setData({
                        loading: true
                    })
                    uni.showLoading({
                        title:"正在下载场景"
                    })
                    
                    const data = this.pageList[1].list[index].data
                    const scene = this.pageList[1].list[index].name
                    await saveDBData(this.ip, data)
                    this.pageList[0].list.push(scene)
                    showToast(`下载场景[${scene}]成功`)
                    
                } catch (ex) {
                    showError(ex)
                }
                finally {
                    this.setData({
                        loading: false
                    })
                    uni.hideLoading()
                }
 
            },
 
 
        }
    }
</script>
 
<style lang="scss" scoped>
    .pages-backup {
        display: flex;
        width: 750rpx;
        height: 100vh;
        flex-direction: column;
        background-color: #F5F5F5;
 
        .switch-type {
            width: calc(100% - 40rpx);
            margin: 20rpx  20rpx 10rpx 20rpx;
            align-items: center;
            vertical-align: middle;
 
            .switch-button-group {
                height: 32px;
                border: 1px solid #dfdfdf;
                border-radius: 15rpx;
                background-color: #dfdfdf;
                display: flex;
                flex: row;
 
                .switch-button {
                    flex: 1;
                    border-radius: 15rpx;
                    color: #000000A5;
                    height: 32px;
                    line-height: 32px;
                    text-align: center;
                }
 
                .switch-button-checked {
                    box-shadow: 0px 2px 8px 0px #0000000C;
                    background-color: #fff;
                    color: #262626;
                }
 
            }
 
        }
 
        .swiper {
 
            width: calc(100% - 20rpx);
            margin: 10rpx;
 
            display: flex;
            flex: 1;
        }
 
        .list {
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            padding: 0 10rpx;
 
            .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 ;
                .list-item {
 
                    border-bottom: 1px solid #ddd;
                    display: flex;
                    flex-direction: row;
                    padding:20rpx;
 
                    .list-name {
                        flex: 1;
                        margin-right: 20rpx;
                        font-size: 32rpx;
                        font-weight: 700;
                        padding:10rpx 0;
                    }
                }
 
                .list-item:last-child {
                    border-bottom: 0;
                    /* 右下角 */
                }
            }
 
            .list-no-content {
                flex: 1;
                margin-top: 50px;
                padding: 20rpx 40rpx;
                align-items: center;
                text-align: center;
                display: flex;
                flex-direction: column;
                font-size: 30rpx;
                font-weight: 400;
 
                .img {
                    width: 212rpx;
                    height: 212rpx;
                    color: #ddd;
                }
 
                .space {
                    margin-top: 20rpx;
                }
 
            }
 
            .am-button {
                border-radius: 90rpx;
                height: 90rpx;
                line-height: 60rpx;
            }
 
        }
 
 
 
    }
</style>