Initial commit: 景耀JY1.0项目
This commit is contained in:
@@ -196,7 +196,8 @@
|
||||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex'
|
||||
import { url } from '@/utils/request'
|
||||
import { url, MESUploadFileNew, MESDownloadFileNew, MESUploadFileNew_BasePath } from '@/utils/request'
|
||||
import axios from 'axios'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -285,8 +286,41 @@ export default {
|
||||
warningExceed() {
|
||||
this.$message.error('仅可上传五张照片')
|
||||
},
|
||||
uploadSuccess(res) { // 上传成功回调
|
||||
this.dialogFormVisible1 = false
|
||||
uploadSuccess(res, file) { // 上传成功回调
|
||||
// 生成文件保存路径: 基础路径/DeliveryRecord/年月日时分秒毫秒.后缀
|
||||
const now = new Date()
|
||||
const timestamp = now.getFullYear().toString() +
|
||||
(now.getMonth() + 1).toString().padStart(2, '0') +
|
||||
now.getDate().toString().padStart(2, '0') +
|
||||
now.getHours().toString().padStart(2, '0') +
|
||||
now.getMinutes().toString().padStart(2, '0') +
|
||||
now.getSeconds().toString().padStart(2, '0') +
|
||||
now.getMilliseconds().toString().padStart(3, '0')
|
||||
const suffix = file.name.split('.').pop() || 'jpg'
|
||||
const savePath = MESUploadFileNew_BasePath + '\\DeliveryRecord\\' + timestamp + '-' + this.listValue + '.' + suffix
|
||||
|
||||
// 构造SQL语句:清空文件内容,更新文件路径
|
||||
const sqlStatement = `update 发货管理_发货单_图片 set 文件内容 = NULL, 文件路径 = N'${savePath}' where id = (select top 1 id from 发货管理_发货单_图片 where 发货单流水号 = ${this.listValue} order by 操作时间 desc)`
|
||||
|
||||
// 调用新接口保存文件到磁盘
|
||||
const formData = new FormData()
|
||||
formData.append('file', file.raw)
|
||||
formData.append('savePath', savePath)
|
||||
formData.append('sqlStatement', sqlStatement)
|
||||
|
||||
axios.post(MESUploadFileNew, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
}).then(response => {
|
||||
if (response.data && response.data[0] && response.data[0].result === '1') {
|
||||
console.log('文件保存成功:', savePath)
|
||||
} else {
|
||||
console.error('文件保存失败:', response.data)
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('文件保存异常:', err)
|
||||
})
|
||||
|
||||
this.dialogFormVisible2 = false
|
||||
this.$refs.upload.clearFiles()
|
||||
},
|
||||
submit2() {
|
||||
@@ -398,8 +432,22 @@ export default {
|
||||
var Data = this.CreateData('11', '发货单_图片_查询数据', param)
|
||||
this.ExecDatabase(Data).then(response => {
|
||||
for (let i = 0; i < response.data.length; i++) {
|
||||
if (response.data[i].文件内容 !== null) {
|
||||
this.urls.push('data:image/png;base64,' + response.data[i].文件内容)
|
||||
const item = response.data[i]
|
||||
// 优先使用文件路径(新方式),否则使用数据库内容(旧方式)
|
||||
if (item.文件路径) {
|
||||
// 从文件系统读取
|
||||
axios.get(MESDownloadFileNew, {
|
||||
params: { filePath: item.文件路径 }
|
||||
}).then(res => {
|
||||
if (res.data && res.data[0] && res.data[0].文件内容) {
|
||||
this.urls.push('data:image/png;base64,' + res.data[0].文件内容)
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('图片加载失败:', err)
|
||||
})
|
||||
} else if (item.文件内容 !== null) {
|
||||
// 兼容旧数据:直接使用数据库中的base64
|
||||
this.urls.push('data:image/png;base64,' + item.文件内容)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user