Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4b49cbb5c5
|
|
@ -122,11 +122,11 @@ const scanQrCodeRef = ref(null)
|
||||||
|
|
||||||
// 二维码扫码
|
// 二维码扫码
|
||||||
const codeScan = async () => {
|
const codeScan = async () => {
|
||||||
qrCode.value = ''
|
qrCode.value = '201808-02723'
|
||||||
|
getMaInfoScan()
|
||||||
if (scanQrCodeRef.value) {
|
// if (scanQrCodeRef.value) {
|
||||||
scanQrCodeRef.value.scanQrCode()
|
// scanQrCodeRef.value.scanQrCode()
|
||||||
}
|
// }
|
||||||
// var mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
|
// var mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
|
||||||
// mpaasScanModule.mpaasScan(
|
// mpaasScanModule.mpaasScan(
|
||||||
// {
|
// {
|
||||||
|
|
@ -189,6 +189,11 @@ const changeRadio = (e) => {
|
||||||
|
|
||||||
|
|
||||||
const codeSearch = async () => {
|
const codeSearch = async () => {
|
||||||
|
console.log("xxxxxxxxxxxxx",maInfo.value.maCode)
|
||||||
|
if(!maInfo.value.maCode){
|
||||||
|
uni.showToast({ title: '请先输入设备编码!', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
let param = {
|
let param = {
|
||||||
maCode: maInfo.value.maCode,
|
maCode: maInfo.value.maCode,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,8 +177,8 @@ const onClick = (e, item, itemIndex) => {
|
||||||
if(res.code==200){
|
if(res.code==200){
|
||||||
uni.showToast({ title: '删除成功', icon: 'none' })
|
uni.showToast({ title: '删除成功', icon: 'none' })
|
||||||
getTableList()
|
getTableList()
|
||||||
}else{
|
}else{ un
|
||||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
i.showToast({ title: '删除失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|
@ -201,6 +201,7 @@ const submit = async () => {
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('🚀 ~ submit ~ error:', error)
|
console.log('🚀 ~ submit ~ error:', error)
|
||||||
|
uni.showToast({ title: error.data.msg, icon: 'none' })
|
||||||
} finally {
|
} finally {
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
|
|
||||||
<uni-forms-item>
|
<uni-forms-item>
|
||||||
<button class="scan-btn" @click="scanStart">开始扫码</button>
|
<button class="scan-btn" type="primary" @click="scanStart">开始扫码</button>
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
|
|
||||||
<uni-forms-item label="二维码编码:" name="qrCode">
|
<uni-forms-item label="二维码编码:" name="qrCode">
|
||||||
|
|
|
||||||
|
|
@ -231,46 +231,117 @@ const imgBeseUrl = ref('') //图片展示
|
||||||
const bmFileInfos = ref([]) //图片数组
|
const bmFileInfos = ref([]) //图片数组
|
||||||
//上传
|
//上传
|
||||||
const uploadImg = (item) => {
|
const uploadImg = (item) => {
|
||||||
console.log('🚀 ~ uploadImg ~ item:', item)
|
// if(item.imgBeseUrl){
|
||||||
uni.chooseImage({
|
// uni.showToast({ title: '图片已上传', icon: 'none' })
|
||||||
count: 1, //图片可选择数量
|
// return
|
||||||
sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
|
// }
|
||||||
sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有。
|
// const count = 1 - imgList.value.length
|
||||||
|
// if (count <= 0) {
|
||||||
|
// uni.showToast({ title: '最多上传1张图片', icon: 'none' })
|
||||||
|
// return
|
||||||
|
// }else{
|
||||||
|
uni.showActionSheet({
|
||||||
|
itemList: ['拍照', '从相册选择'],
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log(res)
|
if (res.tapIndex === 0) {
|
||||||
let imgFiles = res.tempFilePaths //图片的本地文件路径列表
|
getCameraFj(item)
|
||||||
item.imgBeseUrl = imgFiles[0]
|
} else if (res.tapIndex === 1) {
|
||||||
// console.log('请求地址', baseURL+"/file/upload")
|
// 从相册选择
|
||||||
uni.uploadFile({
|
getPhotoFj(item)
|
||||||
// url: baseURL+"/file/upload",//app
|
}
|
||||||
url: '/file/upload', //h5
|
|
||||||
filePath: imgFiles[0],
|
|
||||||
name: 'file',
|
|
||||||
success: (res) => {
|
|
||||||
res = JSON.parse(res.data)
|
|
||||||
console.log('上传成功', res)
|
|
||||||
|
|
||||||
if (res.code && res.code == 200) {
|
|
||||||
let obj = {
|
|
||||||
name: res.data.name,
|
|
||||||
url: res.data.url,
|
|
||||||
}
|
|
||||||
item.bmFileInfos = [obj]
|
|
||||||
console.log('上传成功', item)
|
|
||||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
|
||||||
} else {
|
|
||||||
item.bmFileInfos = []
|
|
||||||
uni.showToast({ title: '上传失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('上传失败', err)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
})
|
fail: (err) => {
|
||||||
|
console.error('操作菜单选择失败:', err)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 附件拍照
|
||||||
|
const getCameraFj = (item) => {
|
||||||
|
navigator.camera.getPicture((file) => onCameraSuccessFj(file, item), onCameraErrorFj, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.CAMERA,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 附件从相册选择
|
||||||
|
const getPhotoFj = (item) => {
|
||||||
|
navigator.camera.getPicture((file) => onCameraSuccessFj(file, item), onCameraErrorFj, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraErrorFj = (message) => {
|
||||||
|
console.log(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraSuccessFj = (file, item) => {
|
||||||
|
uploadSignUrlFj(file, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
const generateRandomString = (length) => {
|
||||||
|
let result = '';
|
||||||
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
const charactersLength = characters.length;
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadSignUrlFj = (file, item) => {
|
||||||
|
const base64Data = file
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: '/file/uploadBase64',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
base64File:base64Data,
|
||||||
|
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
|
||||||
|
fileType: 'image/png'
|
||||||
|
},
|
||||||
|
success: (uploadRes) => {
|
||||||
|
console.log("xxxxxxxxxx",uploadRes)
|
||||||
|
if(!uploadRes.data.code){
|
||||||
|
uploadRes = JSON.parse(decryptWithSM4(uploadRes.data))
|
||||||
|
}else{
|
||||||
|
uploadRes = JSON.parse(uploadRes.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uploadRes.code && uploadRes.code == 200) {
|
||||||
|
let obj = {
|
||||||
|
name: uploadRes.data.name,
|
||||||
|
url: uploadRes.data.url,
|
||||||
|
}
|
||||||
|
item.bmFileInfos = [obj]
|
||||||
|
item.imgBeseUrl = uploadRes.data.url
|
||||||
|
// imgList.value.push({
|
||||||
|
// url: uploadRes.data.url, // Show local path first
|
||||||
|
// serverUrl: uploadRes.data.url // Store server URL
|
||||||
|
// })
|
||||||
|
// bmFileInfos.value.push({
|
||||||
|
// name: uploadRes.data.name,
|
||||||
|
// url: uploadRes.data.url,
|
||||||
|
// taskType: '10'
|
||||||
|
// })
|
||||||
|
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('上传失败', err)
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//配件树
|
//配件树
|
||||||
const partTreeData = ref([])
|
const partTreeData = ref([])
|
||||||
const defaultProps = ref({
|
const defaultProps = ref({
|
||||||
|
|
|
||||||
|
|
@ -358,45 +358,117 @@ const imgBeseUrl = ref('') //图片展示
|
||||||
const bmFileInfos = ref([]) //图片数组
|
const bmFileInfos = ref([]) //图片数组
|
||||||
//上传
|
//上传
|
||||||
const uploadImg = (item) => {
|
const uploadImg = (item) => {
|
||||||
uni.chooseImage({
|
// if(item.imgBeseUrl){
|
||||||
count: 1, //图片可选择数量
|
// uni.showToast({ title: '图片已上传', icon: 'none' })
|
||||||
sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
|
// return
|
||||||
sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有。
|
// }
|
||||||
|
// const count = 1 - imgList.value.length
|
||||||
|
// if (count <= 0) {
|
||||||
|
// uni.showToast({ title: '最多上传1张图片', icon: 'none' })
|
||||||
|
// return
|
||||||
|
// }else{
|
||||||
|
uni.showActionSheet({
|
||||||
|
itemList: ['拍照', '从相册选择'],
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log(res)
|
if (res.tapIndex === 0) {
|
||||||
let imgFiles = res.tempFilePaths //图片的本地文件路径列表
|
getCameraFj(item)
|
||||||
item.imgBeseUrl = imgFiles[0]
|
} else if (res.tapIndex === 1) {
|
||||||
// console.log('请求地址', baseURL+"/file/upload")
|
// 从相册选择
|
||||||
uni.uploadFile({
|
getPhotoFj(item)
|
||||||
// url: baseURL+"/file/upload",//app
|
}
|
||||||
url: '/file/upload', //h5
|
|
||||||
filePath: imgFiles[0],
|
|
||||||
name: 'file',
|
|
||||||
success: (res) => {
|
|
||||||
res = JSON.parse(res.data)
|
|
||||||
console.log('上传成功', res)
|
|
||||||
|
|
||||||
if (res.code && res.code == 200) {
|
|
||||||
let obj = {
|
|
||||||
name: res.data.name,
|
|
||||||
url: res.data.url,
|
|
||||||
}
|
|
||||||
item.bmFileInfos = [obj]
|
|
||||||
console.log('上传成功', item)
|
|
||||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
|
||||||
} else {
|
|
||||||
item.bmFileInfos = []
|
|
||||||
uni.showToast({ title: '上传失败', icon: 'none' })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('上传失败', err)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
})
|
fail: (err) => {
|
||||||
|
console.error('操作菜单选择失败:', err)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 附件拍照
|
||||||
|
const getCameraFj = (item) => {
|
||||||
|
navigator.camera.getPicture((file) => onCameraSuccessFj(file, item), onCameraErrorFj, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.CAMERA,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 附件从相册选择
|
||||||
|
const getPhotoFj = (item) => {
|
||||||
|
navigator.camera.getPicture((file) => onCameraSuccessFj(file, item), onCameraErrorFj, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraErrorFj = (message) => {
|
||||||
|
console.log(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraSuccessFj = (file, item) => {
|
||||||
|
uploadSignUrlFj(file, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
const generateRandomString = (length) => {
|
||||||
|
let result = '';
|
||||||
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
const charactersLength = characters.length;
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadSignUrlFj = (file, item) => {
|
||||||
|
const base64Data = file
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: '/file/uploadBase64',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
base64File:base64Data,
|
||||||
|
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
|
||||||
|
fileType: 'image/png'
|
||||||
|
},
|
||||||
|
success: (uploadRes) => {
|
||||||
|
console.log("xxxxxxxxxx",uploadRes)
|
||||||
|
if(!uploadRes.data.code){
|
||||||
|
uploadRes = JSON.parse(decryptWithSM4(uploadRes.data))
|
||||||
|
}else{
|
||||||
|
uploadRes =JSON.parse(uploadRes.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uploadRes.code && uploadRes.code == 200) {
|
||||||
|
let obj = {
|
||||||
|
name: uploadRes.data.name,
|
||||||
|
url: uploadRes.data.url,
|
||||||
|
}
|
||||||
|
item.bmFileInfos = [obj]
|
||||||
|
item.imgBeseUrl = uploadRes.data.url
|
||||||
|
// imgList.value.push({
|
||||||
|
// url: uploadRes.data.url, // Show local path first
|
||||||
|
// serverUrl: uploadRes.data.url // Store server URL
|
||||||
|
// })
|
||||||
|
// bmFileInfos.value.push({
|
||||||
|
// name: uploadRes.data.name,
|
||||||
|
// url: uploadRes.data.url,
|
||||||
|
// taskType: '10'
|
||||||
|
// })
|
||||||
|
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('上传失败', err)
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//配件树
|
//配件树
|
||||||
const partTreeData = ref([])
|
const partTreeData = ref([])
|
||||||
const defaultProps = ref({
|
const defaultProps = ref({
|
||||||
|
|
@ -521,70 +593,88 @@ const imgBeseUrl2 = ref('') //图片展示
|
||||||
const imgList2 = ref([]) // 图片列表,用于回显
|
const imgList2 = ref([]) // 图片列表,用于回显
|
||||||
//上传
|
//上传
|
||||||
const uploadImg2 = () => {
|
const uploadImg2 = () => {
|
||||||
uni.chooseImage({
|
uni.showActionSheet({
|
||||||
count: 3 - imgList2.value.length, // 最多选择3张,减去已选数量
|
itemList: ['拍照', '从相册选择'],
|
||||||
sizeType: ['original', 'compressed'],
|
success: (res) => {
|
||||||
sourceType: ['album', 'camera'],
|
if (res.tapIndex === 0) {
|
||||||
success: async (res) => {
|
getCameraFjBF()
|
||||||
const tempFiles = res.tempFiles
|
} else if (res.tapIndex === 1) {
|
||||||
if (imgList2.value.length + tempFiles.length > 3) {
|
// 从相册选择
|
||||||
uni.showToast({ title: '最多只能上传3张图片', icon: 'none' })
|
getPhotoFjBF()
|
||||||
return
|
}
|
||||||
}
|
},
|
||||||
|
fail: (err) => {
|
||||||
// 显示选择的图片
|
console.error('操作菜单选择失败:', err)
|
||||||
for (let i = 0; i < tempFiles.length; i++) {
|
},
|
||||||
imgList2.value.push({
|
|
||||||
url: tempFiles[i].path,
|
|
||||||
uploading: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传所有图片
|
|
||||||
const uploadPromises = tempFiles.map(file => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
uni.uploadFile({
|
|
||||||
url: '/file/upload',
|
|
||||||
filePath: file.path,
|
|
||||||
name: 'file',
|
|
||||||
success: (uploadRes) => {
|
|
||||||
const resData = JSON.parse(uploadRes.data)
|
|
||||||
if (resData.code === 200) {
|
|
||||||
resolve({
|
|
||||||
name: resData.data.name,
|
|
||||||
url: resData.data.url
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
reject(new Error('上传失败'))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
reject(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
// 附件拍照
|
||||||
const results = await Promise.all(uploadPromises)
|
const getCameraFjBF = () => {
|
||||||
formRight.value.fileList = [...bmFileInfos.value, ...results]
|
navigator.camera.getPicture(onCameraSuccessFjBF, onCameraErrorFjBF, {
|
||||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.CAMERA,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 附件从相册选择
|
||||||
|
const getPhotoFjBF = () => {
|
||||||
|
navigator.camera.getPicture(onCameraSuccessFjBF, onCameraErrorFjBF, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 更新图片状态
|
const onCameraErrorFjBF = (message) => {
|
||||||
imgList2.value = imgList2.value.map(img => {
|
console.log(message)
|
||||||
return {
|
}
|
||||||
...img,
|
|
||||||
uploading: false
|
const onCameraSuccessFjBF = (file) => {
|
||||||
|
uploadSignUrlFjBF(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadSignUrlFjBF = (file) => {
|
||||||
|
const base64Data = file
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: '/file/uploadBase64',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
base64File:base64Data,
|
||||||
|
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
|
||||||
|
fileType: 'image/png'
|
||||||
|
},
|
||||||
|
success: (uploadRes) => {
|
||||||
|
if(!uploadRes.data.code){
|
||||||
|
uploadRes = JSON.parse(decryptWithSM4(uploadRes.data))
|
||||||
|
}else{
|
||||||
|
uploadRes = JSON.parse(uploadRes.data)
|
||||||
|
}
|
||||||
|
if (uploadRes.code && uploadRes.code == 200) {
|
||||||
|
imgList2.value.push({
|
||||||
|
url: uploadRes.data.url, // Show local path first
|
||||||
|
serverUrl: uploadRes.data.url // Store server URL
|
||||||
|
})
|
||||||
|
// bmFileInfos.value.push({
|
||||||
|
// name: uploadRes.data.name,
|
||||||
|
// url: uploadRes.data.url,
|
||||||
|
// taskType: '10'
|
||||||
|
// })
|
||||||
|
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('上传失败', err)
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
uni.showToast({ title: '部分图片上传失败', icon: 'none' })
|
|
||||||
// 移除上传失败的图片
|
|
||||||
imgList2.value = imgList2.value.filter(img => !img.uploading)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 删除图片
|
// 删除图片
|
||||||
const deleteImage2 = (index) => {
|
const deleteImage2 = (index) => {
|
||||||
imgList2.value.splice(index, 1)
|
imgList2.value.splice(index, 1)
|
||||||
|
|
|
||||||
|
|
@ -322,43 +322,86 @@ const imgBeseUrl = ref("") //图片展示
|
||||||
const bmFileInfos = ref([])//图片数组
|
const bmFileInfos = ref([])//图片数组
|
||||||
//上传
|
//上传
|
||||||
const uploadImg = (item) => {
|
const uploadImg = (item) => {
|
||||||
uni.chooseImage({
|
|
||||||
count: 1, //图片可选择数量
|
|
||||||
sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
|
|
||||||
sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有。
|
|
||||||
success: (res) => {
|
|
||||||
console.log(res)
|
|
||||||
let imgFiles = res.tempFilePaths //图片的本地文件路径列表
|
|
||||||
item.imgBeseUrl = imgFiles[0]
|
|
||||||
// console.log('请求地址', baseURL+"/file/upload")
|
|
||||||
uni.uploadFile({
|
|
||||||
// url: baseURL+"/file/upload",//app
|
|
||||||
url: '/file/upload', //h5
|
|
||||||
filePath: imgFiles[0],
|
|
||||||
name: 'file',
|
|
||||||
success: (res) => {
|
|
||||||
res = JSON.parse(res.data)
|
|
||||||
console.log('上传成功', res)
|
|
||||||
|
|
||||||
if (res.code && res.code == 200) {
|
uni.showActionSheet({
|
||||||
let obj = {
|
itemList: ['拍照', '从相册选择'],
|
||||||
name: res.data.name,
|
success: (res) => {
|
||||||
url: res.data.url,
|
if (res.tapIndex === 0) {
|
||||||
}
|
getCameraFj(item)
|
||||||
item.fileList = [obj]
|
} else if (res.tapIndex === 1) {
|
||||||
console.log('上传成功', item)
|
// 从相册选择
|
||||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
getPhotoFj(item)
|
||||||
} else {
|
|
||||||
item.fileList = []
|
|
||||||
uni.showToast({ title: '上传失败', icon: 'none' })
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.error('上传失败', err)
|
console.error('操作菜单选择失败:', err)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
// 附件拍照
|
||||||
|
const getCameraFj = (item) => {
|
||||||
|
navigator.camera.getPicture((file) => onCameraSuccessFj(file, item), onCameraErrorFj, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.CAMERA,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 附件从相册选择
|
||||||
|
const getPhotoFj = (item) => {
|
||||||
|
navigator.camera.getPicture((file) => onCameraSuccessFj(file, item), onCameraErrorFj, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraErrorFj = (message) => {
|
||||||
|
console.log(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraSuccessFj = (file, item) => {
|
||||||
|
uploadSignUrlFj(file, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadSignUrlFj = (file, item) => {
|
||||||
|
const base64Data = file
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: '/file/uploadBase64',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
base64File:base64Data,
|
||||||
|
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
|
||||||
|
fileType: 'image/png'
|
||||||
|
},
|
||||||
|
success: (uploadRes) => {
|
||||||
|
console.log("xxxxxxxxxx",uploadRes)
|
||||||
|
if(!uploadRes.data.code){
|
||||||
|
uploadRes = JSON.parse(decryptWithSM4(uploadRes.data))
|
||||||
|
}else{
|
||||||
|
uploadRes =JSON.parse(uploadRes.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uploadRes.code && uploadRes.code == 200) {
|
||||||
|
let obj = {
|
||||||
|
name: uploadRes.data.name,
|
||||||
|
url: uploadRes.data.url,
|
||||||
|
}
|
||||||
|
item.bmFileInfos = [obj]
|
||||||
|
item.imgBeseUrl = uploadRes.data.url
|
||||||
|
|
||||||
|
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('上传失败', err)
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//配件树
|
//配件树
|
||||||
|
|
@ -484,70 +527,95 @@ const imgBeseUrl2 = ref("") //图片展示
|
||||||
const imgList2 = ref([]) // 图片列表,用于回显
|
const imgList2 = ref([]) // 图片列表,用于回显
|
||||||
//上传
|
//上传
|
||||||
const uploadImg2 = () => {
|
const uploadImg2 = () => {
|
||||||
uni.chooseImage({
|
uni.showActionSheet({
|
||||||
count: 3 - imgList2.value.length, // 最多选择3张,减去已选数量
|
itemList: ['拍照', '从相册选择'],
|
||||||
sizeType: ['original', 'compressed'],
|
success: (res) => {
|
||||||
sourceType: ['album', 'camera'],
|
if (res.tapIndex === 0) {
|
||||||
success: async (res) => {
|
getCameraFjBF()
|
||||||
const tempFiles = res.tempFiles
|
} else if (res.tapIndex === 1) {
|
||||||
if (imgList2.value.length + tempFiles.length > 3) {
|
// 从相册选择
|
||||||
uni.showToast({ title: '最多只能上传3张图片', icon: 'none' })
|
getPhotoFjBF()
|
||||||
return
|
}
|
||||||
}
|
},
|
||||||
|
fail: (err) => {
|
||||||
// 显示选择的图片
|
console.error('操作菜单选择失败:', err)
|
||||||
for (let i = 0; i < tempFiles.length; i++) {
|
},
|
||||||
imgList2.value.push({
|
|
||||||
url: tempFiles[i].path,
|
|
||||||
uploading: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传所有图片
|
|
||||||
const uploadPromises = tempFiles.map(file => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
uni.uploadFile({
|
|
||||||
url: '/file/upload',
|
|
||||||
filePath: file.path,
|
|
||||||
name: 'file',
|
|
||||||
success: (uploadRes) => {
|
|
||||||
const resData = JSON.parse(uploadRes.data)
|
|
||||||
if (resData.code === 200) {
|
|
||||||
resolve({
|
|
||||||
name: resData.data.name,
|
|
||||||
url: resData.data.url
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
reject(new Error('上传失败'))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
reject(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
const generateRandomString = (length) => {
|
||||||
const results = await Promise.all(uploadPromises)
|
let result = '';
|
||||||
formRight.value.fileList = [...bmFileInfos.value, ...results]
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
uni.showToast({ title: '上传成功', icon: 'none' })
|
const charactersLength = characters.length;
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// 更新图片状态
|
// 附件拍照
|
||||||
imgList2.value = imgList2.value.map(img => {
|
const getCameraFjBF = () => {
|
||||||
return {
|
navigator.camera.getPicture(onCameraSuccessFjBF, onCameraErrorFjBF, {
|
||||||
...img,
|
quality: 50,
|
||||||
uploading: false
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.CAMERA,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 附件从相册选择
|
||||||
|
const getPhotoFjBF = () => {
|
||||||
|
navigator.camera.getPicture(onCameraSuccessFjBF, onCameraErrorFjBF, {
|
||||||
|
quality: 50,
|
||||||
|
destinationType: window.Camera.DestinationType.DATA_URL,
|
||||||
|
sourceType: window.Camera.PictureSourceType.SAVEDPHOTOALBUM,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraErrorFjBF = (message) => {
|
||||||
|
console.log(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCameraSuccessFjBF = (file) => {
|
||||||
|
uploadSignUrlFjBF(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadSignUrlFjBF = (file) => {
|
||||||
|
const base64Data = file
|
||||||
|
uni.request({
|
||||||
|
url: '/file/uploadBase64',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
base64File:base64Data,
|
||||||
|
fileName: `${generateRandomString(10)}_${Date.now()}.png`,
|
||||||
|
fileType: 'image/png'
|
||||||
|
},
|
||||||
|
success: (uploadRes) => {
|
||||||
|
if(!uploadRes.data.code){
|
||||||
|
uploadRes = JSON.parse(decryptWithSM4(uploadRes.data))
|
||||||
|
}else{
|
||||||
|
uploadRes = JSON.parse(uploadRes.data)
|
||||||
|
}
|
||||||
|
if (uploadRes.code && uploadRes.code == 200) {
|
||||||
|
imgList2.value.push({
|
||||||
|
url: uploadRes.data.url, // Show local path first
|
||||||
|
serverUrl: uploadRes.data.url // Store server URL
|
||||||
|
})
|
||||||
|
// bmFileInfos.value.push({
|
||||||
|
// name: uploadRes.data.name,
|
||||||
|
// url: uploadRes.data.url,
|
||||||
|
// taskType: '10'
|
||||||
|
// })
|
||||||
|
uni.showToast({ title: '上传成功', icon: 'none' })
|
||||||
|
} else {
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('上传失败', err)
|
||||||
|
uni.showToast({ title: '上传失败', icon: 'none' })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
|
||||||
uni.showToast({ title: '部分图片上传失败', icon: 'none' })
|
|
||||||
// 移除上传失败的图片
|
|
||||||
imgList2.value = imgList2.value.filter(img => !img.uploading)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除图片
|
// 删除图片
|
||||||
const deleteImage2 = (index) => {
|
const deleteImage2 = (index) => {
|
||||||
imgList2.value.splice(index, 1)
|
imgList2.value.splice(index, 1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue