<template>
|
<view class="container">
|
<cu-custom :bgColor="NavBarColor" :isBack="true" backRouterName="productionTask">
|
<block slot="backText">返回</block>
|
<block slot="content">样件校验</block>
|
</cu-custom>
|
<view class="container">
|
<uni-forms ref="form" :modelValue="formData" validate-trigger="bind" err-show-type="undertext">
|
<uni-group top="1">
|
<uni-forms-item :label-width="100" name="remark" label="文件名称:">
|
<uni-easyinput v-model="formData.equipmentName" />
|
</uni-forms-item>
|
<uni-forms-item :label-width="100" name="outNum" label="设备文档:">
|
<uni-file-picker v-model="fileLists" :extension="['.pdf']" @fail="uploadFail"
|
:list-styles="listStyles" :delIcon="del" :max-count="5" file-mediatype="all"
|
@downloadFile="downloadFile" @select="onFileSelect" @delete="onFileDelete">
|
<button size="mini" type="primary">点击上传</button>
|
</uni-file-picker>
|
</uni-forms-item>
|
<!-- 新增:校验结果单选框 -->
|
<uni-forms-item name="result" :label-width="100" label="检验结果:">
|
<radio-group @change="radioChange">
|
<label style="margin-right: 20rpx;">
|
<radio :checked="formData.result=='qualified'" value="qualified"/>合格
|
</label>
|
|
<label style="margin-right: 20rpx;">
|
<radio :checked="formData.result=='unqualified'" value="unqualified"/>不合格
|
</label>
|
|
|
</radio-group>
|
</uni-forms-item>
|
|
|
</uni-group>
|
</uni-forms>
|
|
<view class="file-list margin-sm">
|
<view class="file-item" v-for="(file, index) in this.selectedFiles" :key="index">
|
<view class="file-icon">
|
<!-- 文件图标 -->
|
<image src="/static/icon_file.png" style="height: 25px; width: 25px; margin-right: 10px;"
|
mode='aspectFit' class="zai-logo "></image>
|
</view>
|
<view class="file-name">
|
<!-- 文件名 -->
|
{{ file.fileName }}
|
</view>
|
<view class="file-actions">
|
<!-- 下载按钮 -->
|
<image v-show="showBtn" src="/static/icon_down.png" @click="downloadFile(file)"
|
style="height: 25px; width: 25px; margin-right: 10px;"></image>
|
</view>
|
</view>
|
</view>
|
|
<!-- 底部操作栏 -->
|
<view class="action-bar">
|
<button class="operation-btn" @click="handleLock">锁定</button>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import {
|
saveAs
|
} from 'file-saver'; // 引入 file-saver 库
|
export default {
|
data() {
|
return {
|
listStyles: {
|
"borderStyle": {
|
"width": "0", // 边框宽度
|
},
|
"border": false, // 是否显示边框
|
"dividline": false
|
},
|
formData: {
|
equipmentName: '',
|
result: ''
|
},
|
fileLists: [],
|
NavBarColor: this.NavBarColor,
|
url: {
|
stallList: "/eam/equipment/queryById",
|
add: 'eam/equipmentAttachment/add',
|
upload: "/eam/sysFiles/batch_upload",
|
downloadFile: 'eam/equipmentAttachment/downloadFile'
|
},
|
id: '',
|
styles: {
|
color: '#2979FF',
|
borderColor: '#2979FF'
|
},
|
msg1Count: 0,
|
msg2Count: 0,
|
msg1Title: ""
|
}
|
},
|
|
computed: {
|
authList() {
|
return this.$store.getters.getAuth || []
|
},
|
top() {
|
return this.CustomBar * 2 + 160
|
},
|
style() {
|
var StatusBar = this.StatusBar;
|
var CustomBar = this.CustomBar;
|
var CustomBar = this.CustomBar;
|
var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
|
return style
|
},
|
},
|
|
onUnload() {
|
this.id = null;
|
this.formData = {}; // 清空数据
|
this.fileLists = [];
|
},
|
|
|
created() {
|
this.getFileList();
|
},
|
methods: {
|
|
authIncludes(code) {
|
return this.authList.some(auth => auth.action === code)
|
},
|
downloadFile(item) {
|
uni.showModal({
|
title: '提示',
|
content: '确认要下载吗',
|
cancelText: '取消',
|
confirmText: '确认',
|
success: res => {
|
if (res.confirm) {
|
this.downFile(item)
|
}
|
}
|
})
|
|
},
|
|
|
downFile(item) {
|
this.$http.download(this.url.downloadFile, {
|
params: {
|
id: item.id
|
},
|
responseType: 'blob' // 确保响应类型为 blob
|
}).then(response => {
|
console.log('Response:', response); // 查看完整响应结构
|
|
// 获取 tempFilePath(Blob URL)
|
const tempFilePath = response.tempFilePath;
|
|
if (!tempFilePath) {
|
uni.showToast({
|
title: '文件下载失败',
|
icon: 'none'
|
});
|
return;
|
}
|
|
let fileName = item.fileName;
|
|
// 创建 <a> 标签并触发下载
|
const link = document.createElement('a');
|
link.href = tempFilePath;
|
link.setAttribute('download', fileName);
|
link.style.display = 'none';
|
|
document.body.appendChild(link);
|
link.click();
|
|
// 清理资源
|
document.body.removeChild(link);
|
|
}).catch(err => {
|
console.error('Download error:', err);
|
uni.showToast({
|
title: '文件下载失败',
|
icon: 'none'
|
});
|
});
|
},
|
getFileList() {
|
this.$http.get(this.url.fileList, {
|
params: {
|
equipmentId: this.id,
|
pageNo: 1,
|
pageSize: 999,
|
column: 'createTime',
|
order: 'desc'
|
},
|
}).then(res => {
|
if (res.data.success) {
|
this.selectedFiles = res.data.result.records || [];
|
|
}
|
}).catch(() => {
|
uni.showToast({
|
title: '获取文件列表失败',
|
icon: 'none'
|
});
|
});
|
},
|
uploadFail(e) {
|
console.log('上传失败:', e)
|
},
|
|
|
onFileSelect(e) {
|
const tempFilePaths = e.tempFilePaths;
|
|
uni.showLoading({
|
title: '上传中...'
|
});
|
|
const uploadPromises = tempFilePaths.map((filePath, index) => {
|
return new Promise((resolve, reject) => {
|
this.$http.upload(this.url.upload, {
|
filePath: filePath,
|
name: 'file'
|
})
|
.then(uploadRes => {
|
const serverFile = uploadRes.data.result[0];
|
console.log(serverFile);
|
// 提取fileSuffix并拼接
|
if (serverFile.fileSuffix && serverFile.fileName && !serverFile
|
.fileName.includes('.')) {
|
serverFile.fileName += '.' + serverFile.fileSuffix;
|
}
|
this.fileLists = [];
|
// 防止重复添加(根据 id 或 fileName 判断)
|
if (!this.fileLists.some(file => file.id === serverFile.id)) {
|
this.fileLists.push(serverFile);
|
}
|
resolve();
|
})
|
.catch(err => {
|
console.error(`文件 ${index + 1} 上传失败`, err);
|
uni.showToast({
|
title: `第 ${index + 1} 个文件上传失败`,
|
icon: 'none'
|
});
|
reject(err);
|
});
|
});
|
});
|
|
Promise.all(uploadPromises)
|
.then(() => {
|
uni.hideLoading();
|
uni.showToast({
|
title: '全部上传成功,正在提交...'
|
});
|
this.submitFileList(); // 自动提交所有文件
|
})
|
.catch(() => {
|
uni.hideLoading();
|
uni.showToast({
|
title: '部分上传失败',
|
icon: 'none'
|
});
|
});
|
},
|
// 文件删除回调
|
onFileDelete(e) {
|
console.log('删除文件:', e.index);
|
},
|
|
// 删除单个文件
|
deleteFile(index) {
|
this.fileLists.splice(index, 1);
|
},
|
|
|
submitFileList() {
|
if (!this.fileLists.length) {
|
uni.showToast({
|
title: '没有可提交的文件',
|
icon: 'none'
|
});
|
return;
|
}
|
console.log(this.fileLists)
|
this.$http.post(this.url.add, {
|
equipmentId: this.id,
|
fileList: this.fileLists
|
}).then(res => {
|
if (res.data.success) {
|
uni.showToast({
|
title: '提交成功'
|
});
|
this.getFileList();
|
} else {
|
uni.showToast({
|
title: '提交失败',
|
icon: 'none'
|
});
|
}
|
}).catch(err => {
|
uni.showToast({
|
title: '提交异常',
|
icon: 'none'
|
});
|
console.error('提交失败:', err);
|
});
|
},
|
},
|
|
}
|
</script>
|
|
<style>
|
|
/* 底部操作栏样式 */
|
.action-bar {
|
position: fixed;
|
bottom: 0;
|
left: 0;
|
right: 0;
|
background-color: #fff;
|
padding: 20rpx;
|
display: flex;
|
justify-content: space-around;
|
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
|
z-index: 999;
|
}
|
|
.operation-btn {
|
padding: 20rpx 40rpx;
|
font-size: 22rpx;
|
border-radius: 12rpx;
|
background-color: #007AFF;
|
color: #fff;
|
border: none;
|
flex: 1;
|
margin: 0 10rpx;
|
}
|
|
|
|
.content {
|
margin-top: 5px;
|
}
|
|
.content scroll-view {
|
scrollIndicator: "none"
|
}
|
|
</style>
|