liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
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
<template>
  <div class="app-container" style="padding: 0">
    <div slot="header" class="clearfix">
      <el-button style="float: right; padding: 8px; margin-left:8px" type="text"
                 icon="el-icon-setting"
                 @click="saveSetting">
        保存配置
      </el-button>
      <el-button style="float: right; padding: 8px; margin-left:8px" type="text"
                 icon="el-icon-setting"
                 @click="reset()">
        重新选择底图
      </el-button>
    </div>
    <el-row>
      <el-col :span="18">
        <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>
      </el-col>
      <el-col :span="6" style="height: calc(100vh - 165px); overflow: auto">
        <el-table :data="tags" border>
          <el-table-column label="参数" align="center" prop="param"/>
          <el-table-column label="采集点" align="center" prop="tag">
            <template slot-scope="scope">
              <el-autocomplete popper-class="my-autocomplete"
                               v-model="scope.row['tag']"
                               :fetch-suggestions="querySearch"
                               placeholder="请输入指标编码">
                <template slot-scope="{ item }">
                  <div class="name">{{ item.value }}</div>
                  <span class="addr">{{ item.name }}</span>
                </template>
              </el-autocomplete>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import {
  getAllCollectTag,
  getConfigure,
  saveSetting,
  updateEquipmentfile
} from "@/api/basicSetup/equipmentfile";
import {getToken} from "@/utils/auth";
 
export default {
  name: "ConfigureView",
  data() {
    return {
      currentNode: '',
      form: {
        nodeId: '',
        fileName: '',
        svgType:''
      },
      filePath: '空节点',
      svgHtml: '',
      tags: [],
      uploadData: {
        headers: {
          Authorization: "Bearer " + getToken()
        },
        url: process.env.VUE_APP_BASE_API + "/basicSetup/equipmentfile/upload"
      },
    }
  },
  methods: {
    changeModelNode(modelNode) {
      this.currentNode = modelNode;
      this.filePath = '空节点';
      getConfigure(modelNode.id).then(response => {
        this.tags = [];
        this.svgHtml = '';
        if (response.code === 200) {
          if (response.data) {
            this.filePath = process.env.VUE_APP_BASE_API + response.data.filePath;
            this.tags = response.data.infoList;
            this.getSvg();
          }
        } else {
          this.msgError(response.msg);
        }
      });
    },
    // 初始化svg
    getSvg() {
      /* 创建xhr对象 */
      const xhr = new XMLHttpRequest();
      xhr.open("GET", this.filePath, true);
      xhr.send();
      /* 监听xhr对象 */
      xhr.addEventListener("load", () => {
        this.svgHtml = 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(this.tags.length,tagTemps.length);
        if (this.tags.length === 0 || this.tags.length!=tagTemps.length) {
          this.tags=[];
          this.tags=tagTemps;
          console.log("222",this.tags.length,tagTemps.length);
        }
      });
    },
    //上传成功后
    handleFileSuccess(response, file, fileList) {
      if (response.code === 200) {
        this.$refs.upload.clearFiles();
        this.form.nodeId = this.currentNode.id;
        this.form.filePath = response.msg;
        this.form.svgType = 'COLLECT';
        updateEquipmentfile(this.form).then(result => {
          if (result.code === 200) {
            this.filePath = process.env.VUE_APP_BASE_API + response.msg;
            this.tags=[];
            this.getSvg();
          } else {
            this.msgError(result.msg);
          }
        });
      } else {
        this.msgError(response.msg);
      }
    },
    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);
        });
      }
    },
    saveSetting() {
      saveSetting(this.currentNode.id, this.tags).then(response => {
        if (response.code === 200) {
          this.$message.success(response.msg);
        } else {
          this.$message.error(response.msg);
        }
      });
    },
    reset() {
      this.filePath = '空节点';
    }
  }
}
</script>
<style scoped lang="scss">
.el-autocomplete {
  width: 100%;
}
 
.my-autocomplete li {
  line-height: normal;
  padding: 7px;
}
 
.my-autocomplete li .name {
  text-overflow: ellipsis;
  overflow: hidden;
}
 
.my-autocomplete li .addr {
  font-size: 12px;
  color: #b4b4b4;
}
 
.my-autocomplete li .highlighted .addr {
  color: #ddd;
}
</style>