ustcyc
2025-01-08 e58b27d9b5b6b3d63267ca89d28ebe9d3363f94b
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
<template>
    <div class="page">
        <!-- <div class="page-container"> -->
            <!-- <div class="page-container-left"> -->
                <!-- <div class="select-box mt20">
                    <el-form :inline="true" label-width="85px">
                        <el-form-item label="数据模型" prop="energyType">
                            <el-select v-model="modelData" placeholder="请选择模型" filterable @change="changeModel">
                                <el-option v-for="model in modelInfoOptions" :key="model.modelCode"
                                    :label="model.modelName" :value="model.modelCode" />
                            </el-select>
                        </el-form-item>
                    </el-form>
                </div> -->
                <!-- <LeftTree ref="leftTreeRef"  @handleNodeClick="handleNodeClick" /> -->
            <!-- </div> -->
            <!-- <div class="page-container-right"> -->
                <BaseCard :title="currentNode ? currentNode.label + '--节点配置' : '暂无节点配置'">
                    <div class="text-right mt10 mb10 mr10">
                        <el-button type="primary" icon="Setting" @click="reset">重新选择地图</el-button>
                        <el-button type="primary" icon="CircleCheck" @click="handleSaveSetting">保存配置</el-button>
                    </div>
                    <div class="content-box">
                        <div class="svg-box">
                            <el-upload v-if="filePath === '空节点'" class="configure-upload" drag ref="upload" :limit="1"
                                :headers="uploadData.headers" :action="uploadData.url" :with-credentials="true"
                                :on-success="handleFileSuccess" :show-file-list="false">
                                <i class="el-icon-upload"></i>
                                <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
                            </el-upload>
                            <div id="svgHtml" v-if="filePath !== '空节点'">
                                <div v-html="svgHtml" />
                            </div>
                        </div>
                        <div class="table-box">
                            <el-table :data="tags" height="100%">
                                <el-table-column label="参数" align="center" prop="param" />
                                <el-table-column label="采集点" align="center" prop="tag">
                                    <template #default="scope">
                                        <el-autocomplete popper-class="my-autocomplete" v-model="scope.row['tag']"
                                            :fetch-suggestions="querySearch" placeholder="请输入指标编码">
                                            <template #default="{ item }">
                                                <div class="name">{{ item.value }}</div>
                                                <span class="addr">{{ item.name }}</span>
                                            </template>
                                        </el-autocomplete>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                </BaseCard>
            <!-- </div> -->
        <!-- </div> -->
    </div>
</template>
 
<script setup>
import { listModel } from '@/api/modelConfiguration/businessModel'
import { getConfigure, updateEquipmentfile, saveSetting, getAllCollectTag } from "@/api/realTimeMonitor/realTimeMonitor";
import { getToken } from "@/utils/auth";
const { proxy } = getCurrentInstance();
let modelData = ref(null)
let modelInfoOptions = ref([]) //下拉列表
 
let uploadData = {
    headers: {
        Authorization: "Bearer " + getToken()
    },
    url: import.meta.env.VITE_APP_BASE_API + "/equipmentFile/upload"
}
 
//获取下拉列表
function searchList() {
    listModel({ isShow: 1 }).then(response => {
        modelInfoOptions.value = response.data;
        if (modelInfoOptions.value.length > 0) {
            modelData.value = modelInfoOptions.value[0].modelCode;
        }
    });
}
searchList()
//选中下拉
function changeModel(e) {
    modelData.value = e
}
 
//选中树
let currentNode = reactive({
    id: "ec7330c3-8294-4214-8aa3-4a6e84837cc4",
    label: "美林",
    nodeCategory: "0"
})
getConfigureList(currentNode.id)
 
// //选中树
// let currentNode = ref()
// function handleNodeClick(data) {
//     currentNode.value = data
//     getConfigureList(data.id)
// }
 
let filePath = ref()
let tags = ref([])
let svgHtml = ref()
function getConfigureList(id) {
    getConfigure(id).then(response => {
        filePath.value = '空节点'
        console.log(111, response)
        tags.value = [];
        svgHtml.value = ''
        if (response.code === 200) {
            if (response.data) {
                filePath.value = import.meta.env.VITE_APP_BASE_API + response.data.filePath;
                tags.value = response.data.infoList;
                getSvg();
            }
        } else {
            proxy.$modal.msgError(response.msg)
        }
    });
 
}
let from = ref({
    nodeId: '',
    fileName: '',
    svgType: ''
})
function handleFileSuccess(response, file, fileList) {
    console.log('handleFileSuccess-->', response, file, fileList)
    if (response.code === 200) {
        from.value.nodeId = currentNode.value.id;
        from.value.filePath = response.msg;
        from.value.svgType = 'COLLECT';
        updateEquipmentfile(from.value).then(result => {
            if (result.code === 200) {
                filePath.value = import.meta.env.VITE_APP_BASE_API + response.msg;
                tags.value = [];
                getSvg();
            } else {
                proxy.$modal.msgError(result.msg)
            }
        });
    } else {
        proxy.$modal.msgError(response.msg)
    }
}
function getSvg() {
    const xhr = new XMLHttpRequest();
    xhr.open("GET", filePath.value, true);
    xhr.send();
    /* 监听xhr对象 */
    xhr.addEventListener("load", () => {
        svgHtml.value = xhr.responseText;
        let values = xhr.responseXML.getElementsByTagName('text');
        let tagTemps = [];
        for (let i = 0; i < values.length; i++) {
            if (values[i].getAttribute("id") != undefined)
                tagTemps.push({
                    "param": values[i].textContent,
                    "tag": "",
                    "tagType": "COLLECT"
                });
        }
        console.log(tags.value.length, tagTemps.length);
        if (tags.value.length === 0 || tags.value.length != tagTemps.length) {
            tags.value = [];
            tags.value = tagTemps;
            console.log("222", tags.value.length, tagTemps.length);
        }
    });
}
function reset() {
    filePath.value = '空节点';
}
function handleSaveSetting() {
    saveSetting(currentNode.value.id, tags.value).then(response => {
        if (response.code === 200) {
            proxy.$modal.msgSuccess(response.msg);
        } else {
            proxy.$modal.msgError(response.msg);
        }
    });
}
 
function querySearch(queryString, cb) {
    if (queryString) {
        getAllCollectTag({ codeOrName: queryString, indexType: 'COLLECT' }).then(response => {
            // 调用 callback 返回建议列表的数据
            let result = response.data;
            let values = [];
            result.forEach(item => {
                values.push({
                    value: item.code,
                    name: item.name
                })
            });
            cb(values);
        });
    }
}
</script>
 
 
<style scoped lang="scss">
@import "@/assets/styles/page.scss";
 
.tree-box {
    height: calc(100vh - 210px) !important;
    max-height: calc(100vh - 210px) !important;
    margin-top: 0 !important;
}
 
 
 
.content-box {
    height: calc(100vh - 260px);
    display: flex;
 
    .svg-box {
        flex: 1;
        height: 100%;
        overflow: auto;
 
        .el-upload__text {
            height: calc(100vh - 350px);
        }
 
        img {
            height: 100%;
        }
    }
 
    .table-box {
        width: 300px;
        margin: 0;
    }
 
}
</style>