whychdw
5 天以前 aa995b8564c6864d5c9f43273c0b303af8f9bd4d
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
<script setup name="StandardParams">
import {ref, onMounted, computed} from "vue";
import ycCard from "@/components/ycCard/index.vue";
import TabButton from "@/components/TabButton/index.vue";
import HdwButton from "@/components/HdwButton/index.vue";
import NoData from "@/components/noData.vue";
import {getPwrStandParamApi, getStandFileApi, uploadStandFileApi} from "@/api/standardParams.js";
import addEdit from "./dialog/addEdit.vue";
import useElement from "@/hooks/useElement.js";
import downloadFile from "@/utils/downloadFile.js";
import {ExportFile} from "@/utils/exportFile.js";
 
const {$loading, $message} = useElement();
const headers = [
  {
    prop: "standName",
    label: "标准编号",
    width: "160",
  },
  {
    prop: "paramType",
    label: "参数类型",
    width: "160",
  },
  {
    prop: "basisVal",
    label: "基准值",
    width: "80",
  },
  {
    prop: "alarmLimith",
    label: "上限",
    width: "80",
  },
  {
    prop: "alarmLimithUpper",
    label: "上上限",
    width: "80",
  },
  {
    prop: "alarmLimitl",
    label: "下限",
    width: "80",
  },
  {
    prop: "alarmLimitlLower",
    label: "下下限",
    width: "80",
  },
  {
    prop: "fileName",
    label: "规范文件名称",
    width: "160",
  },
];
const listRef = ref([]);
const acButton = ref(1);
function changeAcButton(num) {
  acButton.value = num;
  searchData();
}
 
async function searchData() {
  const loading = $loading({
    text: "数据加载中..."
  });
 
  try {
    const rs = await getPwrStandParamApi(acButton.value);
    loading.close();
    if(rs.code === 1 && rs.data) {
      listRef.value = rs.data2;
    }else {
      listRef.value = [];
    }
  }catch (e) {
    console.log(e);
    loading.close();
  }
}
 
const addEditVisible = ref(false);
const dialogTitle = computed(()=>{
  return "参数设定";
});
const selectInfo = ref();
function setParams(info) {
  selectInfo.value = info;
  addEditVisible.value = true;
}
 
const searchText = ref("");
const downloadText =ref("");
const fileList = ref([]);
const selectFile = ref({
  fileName: "",
  standFilePath: "",
});
 
async function searchFileList() {
  if(!searchText.value) {
    $message.warning("请输入文件名称");
    return;
  }
 
  const loading = $loading({
    text: "数据加载中..."
  });
  try {
    const rs = await getStandFileApi(searchText.value, acButton.value);
    loading.close();
    if(rs.code === 1 && rs.data) {
      fileList.value = rs.data2;
    }else {
      fileList.value = [];
    }
  }catch (e) {
    console.log(e);
    loading.close();
  }
}
 
function handleSelectFile(info) {
  console.log(info);
  selectFile.value = info;
}
 
function handleDownloadFile() {
  if(selectFile.value.standFilePath) {
    downloadFile(selectFile.value.standFilePath, "");
  }else {
    $message.warning("请选择下载的文件");
  }
 
}
 
function handleUploadFile(options) {
  console.log(selectInfo.value);
  const formData = new FormData();
  formData.append('multipartFile', options.file); // 添加文件到FormData中
  formData.append('num', selectInfo.value.num); // 添加额外参数
  const loading = $loading();
  uploadStandFileApi(formData).then(res=>{
    loading.close();
    if(res.code === 1 && res.data) {
      $message.success("上传成功!!!");
    }else {
      $message.warning("上传失败!!!");
    }
    searchData();
  }).catch(error=>{
    loading.close();
    console.log(error);
    $message.warning("上传失败,请联系管理员!!!");
  });
}
 
 
function changeSelectRow(info) {
  selectInfo.value = info;
}
 
/**
 * 导出表格数据
 */
function exportExcel() {
  if(!listRef.value.length) {
    $message.warning("无数据,不用导出");
    return;
  }
  let _headers = headers.map(v => {
    let prop = v.prop;
    let label = v.label;
    return {
      prop,
      label
    };
  });
  ExportFile(_headers, listRef.value, "标准参数管理");
}
 
onMounted(()=>{
  changeAcButton(acButton.value);
});
</script>
 
<template>
  <div class="page-wrapper">
    <div class="page-content">
      <yc-card is-full>
        <div class="page-content-wrapper">
          <div class="page-content-tools page-filter">
            <div class="tools-left">
              <tab-button :active="acButton === 1" @click="changeAcButton(1)">直流电源</tab-button>
              <tab-button style="margin-left: 24px;" :active="acButton === 2" @click="changeAcButton(2)">通信电源</tab-button>
            </div>
            <div class="tools-right">
              <hdw-button @click="exportExcel">导出</hdw-button>
            </div>
          </div>
          <div class="page-content-table-wrapper">
            <div class="page-content-table">
              <div class="pos-rel">
                <div class="pos-abs">
                  <el-table class="yc-table" stripe height="100%" :data="listRef" style="width: 100%">
                    <el-table-column show-overflow-tooltip v-for="header in headers" :key="header.prop" :prop="header.prop" :label="header.label"
                                     :min-width="header.width" align="center">
                    </el-table-column>
                    <el-table-column label="操作" fixed="right" width="180" align="center">
                      <template #default="scope">
                        <el-button type="primary" size="small" @click="setParams(scope.row)">参数设定</el-button>
                        <div class="upload-file">
                          <el-upload
                            ref="uploadRef"
                            class="upload-demo"
                            action=""
                            :show-file-list="false"
                            :http-request="handleUploadFile">
                            <template #trigger>
                              <el-button type="success" size="small" @click="changeSelectRow(scope.row)">上传</el-button>
                            </template>
                          </el-upload>
                        </div>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>
            <div class="file-list-wrapper">
              <div class="file-tools">
                <div class="file-tools-item">
                  <input class="file-tools-input" type="text" v-model="searchText" />
                  <hdw-button icon-class="search-data" @click="searchFileList">查 询</hdw-button>
                </div>
                <div class="file-tools-item bottom">
                  <input v-if="!selectFile.fileName" disabled class="file-tools-input" type="text" v-model="selectFile.fileName" />
                  <el-tooltip
                    v-else
                    class="box-item"
                    effect="dark"
                    :content="selectFile.fileName"
                    placement="top">
                    <input disabled class="file-tools-input" type="text" v-model="selectFile.fileName" />
                  </el-tooltip>
                  <hdw-button type="warning" icon-class="download" @click="handleDownloadFile">下 载</hdw-button>
                </div>
              </div>
              <div class="file-list-content">
                <div class="pos-rel">
                  <div class="pos-abs">
                    <el-scrollbar v-if="fileList.length !== 0">
                      <div class="file-list">
                        <div
                          class="file-item-wrapper"
                          v-for="(item, key) in fileList" :key="'key'+key"
                          @click="handleSelectFile(item)">
                          <el-tooltip
                            class="box-item"
                            effect="dark"
                            :content="item.fileName"
                            placement="left-start">
                            <div class="file-item">{{ item.fileName }}</div>
                          </el-tooltip>
                        </div>
                      </div>
                    </el-scrollbar>
                    <no-data v-else text="暂无规范文件"></no-data>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </yc-card>
    </div>
    <el-dialog
      :title="dialogTitle"
      v-model="addEditVisible"
      :close-on-click-modal="false"
      class="dialog-center"
      align-center
      width="auto"
      draggable
      destroy-on-close
      center>
      <add-edit
        v-model:close="addEditVisible"
        :info="selectInfo" @success="changeAcButton(acButton)"></add-edit>
    </el-dialog>
    <el-dialog title="文件上传">
 
    </el-dialog>
  </div>
</template>
 
<style scoped lang="less">
.page-wrapper {
  display: flex;
  flex-direction: row;
  height: 100%;
  .page-content {
    flex: 1;
  }
}
 
.page-content-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  .page-content-tools {
    padding-bottom: 8px;
    margin-left: 26px;
    margin-right: 26px;
    display: flex;
    flex-direction: row;
    .tools-left {
      flex: 1;
    }
  }
  .page-content-table-wrapper {
    flex: 1;
    display: flex;
    flex-direction: row;
    .page-content-table {
      box-sizing: border-box;
      flex: 1;
      margin-left: 26px;
      margin-right: 8px;
    }
    .file-list-wrapper {
      min-width: 200px;
      padding: 16px;
      background-color: #073451;
      margin-right: 26px;
      display: flex;
      flex-direction: column;
      .file-list-content {
        flex:1;
      }
    }
  }
  .page-content-page {
    padding: 8px 8px 0 8px;
    text-align: center;
 
    .el-page-container {
      display: inline-block;
      padding: 0 16px;
    }
 
    .page-tool {
      display: inline-block;
    }
  }
}
 
.pos-rel {
  position: relative;
  width: 100%;
  height: 100%;
 
  .pos-abs {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
  }
}
.file-tools {
  .file-tools-item {
    &.bottom {
      margin-top: 32px;
    }
    .file-tools-input {
      width: 240px;
      height: 38px;
      border: 0;
      background-color: #FFFFFF10;
      margin-right: 8px;
      color: #FFFFFF;
      font-size: 16px;
      &:hover {
        background-color: #076FE810;
      }
      &:focus {
        outline: 0;
      }
    }
  }
}
 
.file-list {
  padding: 8px 0;
  user-select: none;
  .file-item-wrapper {
    padding: 8px;
    background-color: #1B4C79;
    cursor: pointer;
    margin-top: 4px;
    &:hover {
      font-weight: 700;
    }
    .file-item {
      font-size: 14px;
      white-space: nowrap;
    }
  }
}
.upload-file {
  display: inline-block;
  margin-left: 8px;
}
</style>