审查视图

src/views/deploy/trajectory.vue 15.2 KB
1 2 3 4 5 6
<template>
    <div>
        <el-row>
            <el-card  style="background-color: #F5F7FA">
                <el-row>
                    <el-form :model="queryInfo" :rules="rules" ref="ruleForm">
小范 authored
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
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="" prop="vclN">
                                    <el-input v-model="queryInfo.vclN"  size="small" style="width: 170px"
                                              placeholder="车牌号" clearable required>
                                        <template slot="prepend">车牌号</template>
                                    </el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="" prop="vco">
                                    <div class="my-text-area">
                                        <div class="el-input-group__prepend prepand">车牌类型</div>
                                        <el-select v-model="queryInfo.vco" placeholder="车牌类型" style="width: 100px">
                                            <el-option label="蓝牌" value="1"></el-option>
                                            <el-option label="黄牌" value="2"></el-option>
                                            <el-option label="绿牌" value="3"></el-option>
                                        </el-select>
                                    </div>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="" prop="satellite">
                                    <div class="my-text-area">
                                        <div class="el-input-group__prepend prepand">卫星</div>
                                        <el-select required v-model="satellite" placeholder="卫星" style="width: 100px">
                                            <el-option label="北斗" value="1"></el-option>
                                            <el-option label="GPS" value="2"></el-option>
                                        </el-select>
                                    </div>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="7">
                                <el-form-item label="" prop="qryEtm">
                                    <div class="my-text-area">
                                        <div  class="el-input-group__prepend prepand">开始时间</div>
                                        <!--                            <span class="demonstration">带快捷选项</span>-->
                                        <el-date-picker
                                                v-model="queryInfo.qryEtm"
                                                type="datetime"
                                                value-format="yyyy-MM-dd HH:mm:ss"
                                                format="yyyy-MM-dd HH:mm:ss"
                                                placeholder="选择日期时间"
                                                align="right"  style="width: 170px"
                                                :picker-options="pickerOptions">
                                        </el-date-picker>
                                    </div>
                                </el-form-item>
                            </el-col>
                            <el-col :span="7">
                                <el-form-item label="" prop="qryBtm">
                                    <div class="my-text-area">
                                        <div  class="el-input-group__prepend prepand">结束时间</div>
                                        <!--                            <span class="demonstration">带快捷选项</span>-->
                                        <el-date-picker
                                                v-model="queryInfo.qryBtm"
                                                type="datetime"
                                                value-format="yyyy-MM-dd HH:mm:ss"
                                                format="yyyy-MM-dd HH:mm:ss"
                                                placeholder="选择日期时间"
                                                align="right" style="width: 170px"
                                                :picker-options="pickerOptions">
                                        </el-date-picker>
                                    </div>
                                </el-form-item>
                            </el-col>
                            <el-col :span="1">
                                <el-button type="primary" size="mini" @click="getList()">
                                    查询
                                </el-button>
                            </el-col>
                        </el-row>
81 82 83 84 85 86 87 88 89
                    </el-form>
                </el-row>
            </el-card>
        </el-row>
        <div id="mapContainer" ref="mapContainer" style="width: 100%; height: 500px;"></div>
    </div>
</template>
<script>
    import AMapLoader from '@amap/amap-jsapi-loader';
小范 authored
90
    import { historyTrack,gpshistoryTrack } from '../../api/consigner/vehicle';
91 92 93 94 95 96 97 98 99 100 101 102 103 104


    export default {
        data() {
            return {
                mapInstance: null,
                queryInfo: {
                    vclN: '',
                    vco: '2',
                    //开始时间
                    qryEtm: '',
                    //结束时间
                    qryBtm: '',
                },
小范 authored
105
                satellite:'1',
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
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                tableData:[],
                myArray: [{
                    "mlg": "24284.1",
                    "agl": "268",
                    "gtm": "20211110/000025",
                    "hgt": "302",
                    "lat": "17783673",
                    "lon": "63774741",
                    "spd": "0.0"
                },
                    {
                        "mlg": "24284.1",
                        "agl": "268",
                        "gtm": "20211110/000055",
                        "hgt": "302",
                        "lat": "17783673",
                        "lon": "63774741",
                        "spd": "0.0"
                    }],
                convertedCoords: [],
                rules: {
                    vclN: [
                        { required: true, message: '请输入车牌号', trigger: 'blur' },
                        // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ],
                    vco: [
                        { required: true, message: '请选择车牌类型', trigger: 'change' }
                    ],
                    qryEtm: [
                        { required: true, message: '请选择开始日期', trigger: 'change' }
                    ],
                    qryBtm: [
                        { required: true, message: '请选择结束日期', trigger: 'change' }
                    ],
                }
            };
        },
        computed:{
        },
        methods: {
            getList() {
小范 authored
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
                if(this.satellite=='1'){
                    this.$refs.ruleForm.validate(valid => {
                        if (!valid) return;
                        const _this = this;
                        historyTrack(this.queryInfo).then((response) => {
                            const res = response.data;
                            if (res.code !== '200') {
                                return _this.$message.error('获取车辆轨迹失败!');
                            }
                            // 调用initMap方法,并将轨迹数据传递过去
                            _this.initMap(res.data.data.trackArray);
                            _this.$message.success('获取车辆轨迹成功!');
                        }).catch(error => {
                            _this.$message.error('获取车辆轨迹失败:' + error.toString());
                        });
                    })
                }else{
                    this.$refs.ruleForm.validate(valid => {
                        if (!valid) return;
                        const _this = this;
                        gpshistoryTrack(this.queryInfo).then((response) => {
                            const res = response.data;
                            if (res.code !== '200') {
                                return _this.$message.error('获取车辆轨迹失败!');
                            }
                            // 调用initMap方法,并将轨迹数据传递过去
                            _this.initMapGPS(res.data.data);
                            _this.$message.success('获取车辆轨迹成功!');
                        }).catch(error => {
                            _this.$message.error('获取车辆轨迹失败:' + error.toString());
                        });
                    })
                }
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
            },
            initMap(trackArray) {
                const _this = this;
                AMapLoader.load({
                    key: 'fdb27c13681d084e85ff8457b5cbe540',
                    version: '2.0',
                    plugins: [], // 可以加载地图插件,比如定位、地图工具等
                }).then((AMap) => {
                    // 创建地图对象并存储在 _this.mapInstance 中
                    _this.map = new AMap.Map('mapContainer', {
                        zoom: 10, // 设置地图缩放级别
                        center: [116.397428, 39.90923], // 设置地图中心点坐标
                    });
                    // 将轨迹数据添加到地图上
                    //var lineArr = trackArray.map((item) => [item.longitude / 600000.0, item.latitude / 600000.0]);
                    this.convertedCoords = this.convertBDToAMap(trackArray);
                    console.log(this.convertedCoords)
                    _this.poly = new AMap.Polyline({
                        path: this.convertedCoords, // 设置折线路径
                        strokeColor: "#3366ff", // 线颜色
                        strokeOpacity: 1, // 线透明度
                        strokeWeight: 3, // 线宽
                        strokeStyle: "solid", // 线样式
                    });
                    _this.poly.setMap(_this.map);
                    _this.map.setCenter(this.convertedCoords[0])
                    //_this.map.setFitView();
                }).catch((err) => {
                    console.error('初始化地图失败:', err);
                });
            },
小范 authored
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
            initMapGPS(DATA) {
                const _this = this;
                AMapLoader.load({
                    key: 'fdb27c13681d084e85ff8457b5cbe540',
                    version: '2.0',
                    plugins: [], // 可以加载地图插件,比如定位、地图工具等
                }).then((AMap) => {
                    // 创建地图对象并存储在 _this.mapInstance 中
                    _this.map = new AMap.Map('mapContainer', {
                        zoom: 10, // 设置地图缩放级别
                        center: [116.397428, 39.90923], // 设置地图中心点坐标
                    });
                    // 将轨迹数据添加到地图上
                    //var lineArr = trackArray.map((item) => [item.longitude / 600000.0, item.latitude / 600000.0]);
                    this.convertedCoords = this.convertBDToAMapGPS(DATA);
                    console.log(this.convertedCoords)
                    _this.poly = new AMap.Polyline({
                        path: this.convertedCoords, // 设置折线路径
                        strokeColor: "#3366ff", // 线颜色
                        strokeOpacity: 1, // 线透明度
                        strokeWeight: 3, // 线宽
                        strokeStyle: "solid", // 线样式
                    });
                    _this.poly.setMap(_this.map);
                    _this.map.setCenter(this.convertedCoords[0])
                    //_this.map.setFitView();
                }).catch((err) => {
                    console.error('初始化地图失败:', err);
                });
            },
269 270 271 272 273 274 275 276 277
            convertBDToAMap(bdCoordData) {
                const aMapCoordData = [];
                bdCoordData.forEach(coord => {
                    const lon = parseFloat(coord.lon) / 600000.0; // 将经度从北斗格式转换为高德地图格式
                    const lat = parseFloat(coord.lat) / 600000.0; // 将纬度从北斗格式转换为高德地图格式
                    aMapCoordData.push([lon, lat]); // 添加到结果数组
                });
                return aMapCoordData;
            },
小范 authored
278 279 280 281 282 283 284 285 286
            convertBDToAMapGPS(bdCoordData) {
                const aMapCoordData = [];
                bdCoordData.forEach(coord => {
                    const lon = parseFloat(coord.lon); // 将经度从北斗格式转换为高德地图格式
                    const lat = parseFloat(coord.lat); // 将纬度从北斗格式转换为高德地图格式
                    aMapCoordData.push([lon, lat]); // 添加到结果数组
                });
                return aMapCoordData;
            },
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

        },

        mounted() {
            this.initMap(this.myArray);
        },
    };
</script>

<style scoped>
    .my-text-area .prepand{
        float: left;
        width:89px;
        height: 28px;
        font-size: 12px;
        line-height: 28px;
    }
</style>
<style>
    .my-text-area .el-textarea__inner{
        min-height: 28px;
        height: 28px;
        border-bottom-left-radius: 0;
        border-top-left-radius: 0;
    }
    .rounded-corner {
        border-radius: 10px; /* 设置圆角的半径为10像素 */
        background-color: #f0f0f0; /* 背景颜色 */
        padding: 10px; /* 内边距 */
        margin: 10px; /* 外边距 */
        box-shadow: 0 0 5px #ddd; /* 盒子阴影效果 */
    }
</style>