月球大数据地理空间分析展示平台-【前端】-月球2期前端
surprise
2023-11-29 36fbd1e5a40e319e6ac5f43d11c99ba4b66e93a3
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
<template>
    <div class="legendBox" v-drag="true">
        <div class="titleLenged">
            <div>
                坡度分析结果
            </div>
            <div>
                <el-icon @click.stop="setCloseLegend" :size="21">
                    <Close />
                </el-icon>
 
            </div>
        </div>
        <div class="legendContent">
            <!-- <el-icon @click.stop="setDownloadLegend" :size="21">
                <Download />
            </el-icon> -->
            <div @click.stop="setClickDownLoadShp()">
                <el-link :underline="false">
                    <el-icon :size="21">
                        <Download />
                    </el-icon>
                    分析边界下载(Shp格式)
                </el-link>
            </div>
            <div @click.stop="setClickDownLoadExcel()">
                <el-link :underline="false">
                    <el-icon :size="21">
                        <Download />
                    </el-icon>
                    分析结果下载(Excel格式)
                </el-link>
            </div>
 
        </div>
        <iframe id="downFrame" src="" style="display: none; border: 0; padding: 0; height: 0; width: 0"></iframe>
    </div>
</template>
 
<script lang="ts" setup>
import {
    ref,
    onMounted,
    onBeforeUnmount,
    reactive,
    defineProps,
    defineEmits,
    nextTick,
    watch,
} from "vue";
import store from "@/store";
import menuTool from '@/assets/js/Map/menuTool';
import { removeToken, getToken } from "@/utils/auth";
import $ from "jquery";
import * as turf from "@turf/turf";
import WKT from "terraformer-wkt-parser";
import { rasterAnalysis_downloadSlopXls } from "@/api/api.js";
const wkt = ref(null)
const title = ref('分析结果')
const setDownloadLegend = () => {
    var geom = menuTool.legendBox;
    var coord = turf.polygon([[
        [geom[0], geom[1]],
        [geom[0], geom[3]],
        [geom[2], geom[3]],
        [geom[2], geom[1]],
        [geom[0], geom[1]],
    ]]);
    wkt.value = WKT.convert(coord.geometry)
 
 
 
}
const setClickDownLoadExcel = () => {
    var res = wkt.value;
    var url = config.proxy + "/rasterAnalysis/downloadSlopXls?token=" + getToken() + "&wkt=" + res;
    $("#downFrame").attr("src", url).click();
}
 
 
const setClickDownLoadShp = () => {
 
    var obj = {
        "bak": null,
        "fillColor": null,
        "id": 10086,
        "name": "图例",
        "opacity": null,
        "type": "rectangle",
        "wkt": wkt.value
    }
    $.ajax({
        url: config.proxy + "/comprehensive/downloadShp?token=" + getToken(),
        type: "POST",
        data: JSON.stringify([obj]),
        dataType: "json", // html、json、jsonp、script、text
        contentType: "application/json", // "application/x-www-form-urlencoded"
        success: (rs) => {
            if (rs && rs.code == 200) {
                setDownLoadFile(rs.result);
            }
        },
        error: function (e) { },
    });
}
const setDownLoadFile = (res) => {
    var a = document.createElement("a"); // 创建一个a标签元素
    a.style.display = "none"; // 设置元素不可见
 
    a.href =
        config.proxy +
        "/comprehensive/downloadFile?token=" +
        getToken() +
        "&guid=" +
        res;
 
    document.body.appendChild(a); // 加入
    a.click(); // 触发点击,下载
    document.body.removeChild(a); // 释放
 
}
const setCloseLegend = () => {
    menuTool.setCloseEsriLayer();
}
onMounted(() => {
    setDownloadLegend();
})
</script>
 
<style  lang="less" scoped>
.legendBox {
 
    top: 70px;
    right: 160px;
    position: absolute;
    z-index: 9999;
    width: 170px;
    /* background: url('@/assets/img/图例.png') no-repeat;
    background-size: 100% 100%; */
    background: rgba(7, 8, 14, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: inset 0px 5px 30px 5px rgba(38, 47, 71, 1);
    padding: 10px;
    border-radius: 5px;
 
    .titleLenged {
        font-family: Source Han Sans SC;
        font-size: 14px;
        color: white;
        display: flex;
        height: 100%;
        align-items: center;
 
        justify-content: space-between;
 
        div {
            height: 100%;
            display: flex;
            align-items: center;
        }
 
    }
 
    .legendContent {
        margin-top: 10px;
 
        :deep(.el-link) {
            color: rgba(255, 255, 255, 0.8);
            font-size: 12px;
            line-height: 20px;
            text-decoration: none;
 
            :hover {
                color: #409eff;
            }
        }
 
        // width: 100px;
        // height: 300px;
        // background: url('@/assets/img/图例.png') no-repeat;
        // background-size: 100% 100%;
    }
 
}
</style>