index.vue
9.93 KB
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
<template>
<view class="containers">
<topWindow :isHome="false" @item-click="handleItemClick"></topWindow>
<goback></goback>
<view class="ComponentsBody">
<view class="productInformation" v-if="current == 'productInformation'">
<InformationModule v-if="informationData != null" :informationData="informationData">
</InformationModule>
</view>
<view class="inspectionInformation" v-else-if="current == 'inspectionInformation'">
<InspectionModule v-if="inspectionData != null" :inspectionData="inspectionData"></InspectionModule>
</view>
<view class="attachmentInformation" v-else-if="current == 'attachmentInformation'">
<AuxiliaryModule v-if="auxiliaryData != null" :auxiliaryData="auxiliaryData"></AuxiliaryModule>
</view>
<view class="repairReportBtnCss" @click="jumpService">
<u-image src="/static/images/icon/repair.png" mode="witFix" :width="$isMobile?'100px':'200px'"
:height="$isMobile?'100px':'200px'"></u-image>
<text class="repairReportTextCss">{{$t("hdk.Repair")}}</text>
</view>
</view>
</view>
</template>
<script>
import config from '@/common/config.js'
import {
getProductFind
} from '@/api/scan'
import topWindow from "@/pages/component/topWindow.vue"
import goback from "@/pages/component/goback.vue"
import InformationModule from '@/pages/component/InformationModule.vue'
import InspectionModule from '@/pages/component/InspectionModule.vue'
import AuxiliaryModule from '@/pages/component/AuxiliaryModule.vue'
export default {
components: {
InformationModule,
InspectionModule,
AuxiliaryModule,
topWindow,
goback
},
data() {
return {
sn: "",
productObject: null,
informationData: null,
inspectionData: null,
auxiliaryData: null,
repairInformation: null,
current: "productInformation"
}
},
computed: {
},
onLoad(data) {
console.log(data);
if (data) {
this.sn = data.sn;
}
this.initData()
},
methods: {
initData() {
// uni.showLoading({title: '查询中...'})
getProductFind(this.sn).then(res => {
uni.hideLoading()
if (res.code == 0) {
console.log("sn查询结果", res)
this.productObject = res.data
this.initializationMethod()
} else {
uni.showToast({
icon: 'error',
title: this.$t('hdk.networkError'),
})
}
})
},
initializationMethod() {
//重新组装产品信息数据
this.informationData = {
lamp: this.productObject.productRespVO?.lamp || null,
lampPath: this.productObject.productRespVO?.lampPath || [require('@/static/images/noPhoto.png')],
sn: this.productObject.sn,
productName: this.productObject.productRespVO?.productName || null,
type: this.productObject.productRespVO?.type || null,
productionTime: this.productObject.productionTime,
productionUserName: this.productObject.productionUserName,
productDatasheet: this.productObject.productRespVO?.productDatasheet || null,
productDatasheetPath: this.productObject.productRespVO?.productDatasheetPath || [],
productManual: this.productObject.productRespVO?.productManual || null,
productManualPath: this.productObject.productRespVO?.productManualPath || []
};
console.log("产品信息", this.informationData);
this.repairInformation = {
sn: this.productObject.sn,
productName: this.productObject.productRespVO?.productName || null,
type: this.productObject.productRespVO?.type || null
}
//重新组装检验信息数据
this.inspectionData = {
softwareVersion: this.productObject.softwareVersion,
hardwareVersion: this.productObject.hardwareVersion,
checkTime: this.productObject.checkTime,
type: this.productObject.productRespVO?.type || null,
power: this.productObject.power,
powerFactor: this.productObject.powerFactor,
tightnessCheckFile: this.productObject.tightnessCheckFile,
tightnessCheckFilePath: this.productObject.tightnessCheckFilePath,
lightIntensityPhoto: [],
lightIntensityFile: ''
};
console.log("检验信息", this.inspectionData);
//重新组装附件信息数据
this.auxiliaryData = this.productObject.attachmentRespVOList || [];
// console.log("重新组装检验信息", this.inspectionData);
if (this.productObject.attachmentRespVOList === null) {
this.auxiliaryData = [];
} else {
this.auxiliaryData = this.productObject.attachmentRespVOList.map(obj => ({
...obj,
current: 0
}));
}
console.log("附件信息", this.auxiliaryData);
//产品数据转图片
if (this.productObject && this.productObject.productRespVO) {
const productRespVO = this.productObject.productRespVO;
// console.log("灯具", productRespVO);
// const modifiedManuals = this.generateDownloadUrls(productRespVO.lamp);
// this.informationData.lamp = modifiedManuals;
this.generateDownloadUrls(productRespVO.lampPath)
.then(modifiedManuals => {
// console.log("灯具==>", modifiedManuals);
this.informationData.lampPath = modifiedManuals;
})
.catch(error => {
console.error(error);
});
}
//光强数据转图片
if (this.productObject && this.productObject.lightIntensityPath) {
if (this.productObject.lightIntensityPath) {
this.generateDownloadUrls(this.productObject.lightIntensityPath)
.then(modifiedManuals => {
// console.log("光强==>", modifiedManuals);
this.inspectionData.lightIntensityPhoto = modifiedManuals.filter(url => this.isPicture(
url));
this.inspectionData.lightIntensityFile = modifiedManuals.filter(filename => !this
.isPicture(filename) && filename.includes('.'));
// 在这里可以访问已更新的inspectionData.lightIntensityPhoto和inspectionData.lightIntensityFile的值
})
.catch(error => {
console.error(error);
});
}
}
//附件信息转图片
if (this.auxiliaryData) {
this.auxiliaryData.forEach(attachment => {
if (attachment.productPicturePath) {
this.generateDownloadUrls(attachment.productPicturePath)
.then(modifiedPictures => {
// console.log("附件图片==>", modifiedPictures);
attachment.productPicturePath = modifiedPictures;
})
.catch(error => {
console.error(error);
});
}
});
}
},
jumpService() {
console.log(this.repairInformation);
uni.navigateTo({
url: "/pages/product/repairReport?repairpObject=" + encodeURIComponent(JSON.stringify(
this.repairInformation)),
})
},
generateDownloadUrls(filenames) {
// console.log("filenames", filenames)
if (!filenames || filenames.length === 0) {
// 如果 filenames 为空或者null,则执行相应的操作
return Promise.resolve(require('@/static/images/noPhoto.png'))
}
const modifiedFilenames = filenames.replace(/;+$/, '');
const modifiedUrls = modifiedFilenames.split(";").map(filename => {
const trimmedFilename = filename.trim();
if (trimmedFilename.endsWith('.png') || trimmedFilename.endsWith('.jpg')) {
// const encodedFilename = Buffer.from(trimmedFilename, 'utf-8').toString('base64');
const url = config.fileUrl + `/${trimmedFilename}`;
// console.log(url);
return this.checkUrlValidity(url).catch(error => {
// console.error(error);
// console.log("请求失败", trimmedFilename)
return Promise.resolve(require('@/static/images/noPhoto.png'));
});
} else if (trimmedFilename.includes('.')) {
return Promise.resolve(trimmedFilename);
} else {
return Promise.resolve(require('@/static/images/noPhoto.png'));
}
});
return Promise.all(modifiedUrls).then(results => {
const validUrls = results.filter(url => url !== null);
if (validUrls.length > 0) {
// console.log("有效地址",validUrls);
return validUrls;
} else {
return [require('@/static/images/noPhoto.png')];
}
});
},
checkUrlValidity(url) {
return new Promise((resolve, reject) => {
uni.request({
url,
method: 'HEAD',
success(res) {
// console.log("检验地址",res);
if (res.statusCode >= 200 && res.statusCode < 400) {
resolve(url); // URL有效
} else {
// console.log("地址无效");
resolve(null); // URL无效
}
},
fail(err) {
reject(err); // 请求失败
}
});
});
},
isPicture(str) {
// 正则表达式判断是否为网址类型的字符串
const pictureRegex = /\.(jpg|jpeg|png|gif)$/i;
return pictureRegex.test(str);
},
handleItemClick(item) {
this.current = item;
console.log('点击的菜单项:', item);
// 在此处处理被点击的菜单项
}
}
}
</script>
<style lang="scss" scoped>
.containers {
width: 100%;
height: 100%;
background: #F9FAF9;
}
.ComponentsBody {
// width:100%;
// display: flex;
// justify-content: center;
// align-items: center;
}
// .productInformation{
// width: 100%;
// }
// .inspectionInformation{
// width: 100%;
// }
// .attachmentInformation{
// width: 100%;
// }
@media screen and (max-width: 767px) {
.repairReportBtnCss {
width: 100px;
height: 100px;
border-radius: 100px;
position: fixed;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
right: 0;
bottom: 100px;
// background-color: #00aeaa;
}
.repairReportTextCss {
position: absolute;
bottom: 30px;
color: #fff;
font-size: 10px;
}
}
// //PC端样式
@media screen and (min-width: 768px) {
.repairReportBtnCss {
width: 100px;
height: 100px;
border-radius: 100px;
position: fixed;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
right: 20px;
bottom: 100px;
// background-color: #00aeaa;
}
.repairReportTextCss {
position: absolute;
bottom: 15px;
color: #fff;
}
}
</style>