访客页面修改

This commit is contained in:
liyuanchao 2025-08-21 21:33:41 +08:00
parent 9e3c698be9
commit 8d6c55007e
2 changed files with 260 additions and 120 deletions

94
common/upload.js Normal file
View File

@ -0,0 +1,94 @@
// utils/upload.js
export const uploadFiles = ({
files = [],
url = '',
name = 'file',
formData = {},
fileType = 'image',
vm, // 关键:传入 vm 以便访问 vuex_token、vuex_remember 等
}) => {
return new Promise(async (resolve, reject) => {
if (!url) return reject(new Error('上传地址不能为空'));
if (!Array.isArray(files) || files.length === 0) return reject(new Error('文件列表不能为空'));
const results = [];
for (let i = 0; i < files.length; i++) {
const filePath = files[i];
try {
const res = await uploadSingleFile({
filePath,
url,
name,
formData,
fileType,
vm
});
results.push(res);
} catch (err) {
reject(err);
return;
}
}
resolve(results);
});
};
function uploadSingleFile({
filePath,
url,
name,
formData = {},
fileType = 'image',
vm
}) {
return new Promise((resolve, reject) => {
const headers = {
'x-requested-with': 'XMLHttpRequest',
source: 'uniapp',
clientId: 'dab457a1ea14411787c240db05bb0832',
};
// 手动加上 Token
if (vm?.vuex_token) {
headers.Authorization = `Bearer ${vm.vuex_token}`;
}
// 加上 rememberMe
if (vm?.vuex_remember) {
headers['x-remember'] = vm.vuex_remember;
}
console.log('request', headers);
console.log('request:', {
url: url,
filePath: filePath,
name: name,
formData: formData
});
uni.uploadFile({
url,
filePath,
name,
formData,
header: headers,
fileType,
success: (res) => {
try {
const data = JSON.parse(res.data);
console.log('request', data);
if (res.statusCode === 200) {
resolve(data);
} else {
reject(data);
}
} catch (e) {
reject(e);
}
},
fail: (err) => {
reject(err);
console.log('request', err);
}
});
});
}

View File

@ -157,6 +157,9 @@
</template>
<script>
import {
uploadFiles
} from '@/common/upload.js';
export default {
data() {
const now = new Date();
@ -335,7 +338,7 @@
},
//
submitForm() {
async submitForm() {
const errorMsg = this.validateForm();
if (errorMsg) {
uni.showToast({
@ -346,7 +349,8 @@
}
//
this.formData.visitingBeginTime = `${this.formData.visitingBeginDate} ${this.formData.visitingBeginTime}`;
this.formData.visitingBeginTime =
`${this.formData.visitingBeginDate} ${this.formData.visitingBeginTime}`;
this.formData.visitingEndTime = `${this.formData.visitingEndDate} ${this.formData.visitingEndTime}`;
@ -356,128 +360,170 @@
title: '提交中...',
mask: true
});
const images = [this.formData.facePictures]
// API
setTimeout(() => {
uni.request({
url: this.formData.facePictures
})
// .then(response => response.blob())
.then(blob => {
// Blob
console.log(blob);
const file = new File([blob], 'filename.png', {
type: blob.type
});
// FormData
const formData = new FormData();
formData.append('file', file);
console.log(formData)
//
// this.$u.api.uploadimg()
// Blob
uni.uploadFile({
url: 'http://183.230.235.66:11010/api/resource/oss/qrupload', //
filePath: file.filePath, //
name: 'file', //
// FormData
formData: {
'code': this.formData.qrCodeId //
},
// //
// onProgressUpdate: (res) => {
// this.progress = res.progress;
// console.log(':' + res.progress);
// },
//
success: (res) => {
console.log('上传成功', res);
// this.formData.facePictures = res.data.ossId;
//
const submitData = {
...this.formData,
bookingParkingSpace: this.formData
.bookingParkingSpace ? 0 : 1
};
const parsedData = JSON.parse(res.data);
if (parsedData.code == 200) {
// ossId
const ossId = parsedData.data.ossId;
console.log("ossId", ossId)
submitData.facePictures = ossId;
console.log(submitData)
this.$u.api.fksub(submitData).then(res => {
console.log(res)
if (res.code == 200) {
uni.showToast({
title: "提交成功,请等待审核!",
icon: "success"
})
}
})
}else{
uni.showToast({
title: '上传失败',
icon: 'none'
});
}
// uni.showToast({
// title: '',
// icon: 'success'
// });
},
//
fail: (err) => {
console.error('上传失败', err);
uni.showToast({
title: '上传失败',
icon: 'none'
});
},
//
complete: () => {
this.progress = 0; //
}
});
// this.$u.api.uploadimg(formData).then(res => {
// console.log(res)
// if (res.code == 200) {
// uni.showToast({
// title: "",
// icon: "success"
// })
// } else {
// uni.showToast({
// title: "tp",
// icon: "error"
// })
// }
// })
});
uni.hideLoading();
//
const result = await uploadFiles({
files: images,
url: this.vuex_config.baseUrl + '/resource/oss/upload',
name: 'file',
vm: this // token
});
let parsedData = result[0]
if (parsedData.code == 200) {
const submitData = {
...this.formData,
bookingParkingSpace: this.formData
.bookingParkingSpace ? 0 : 1
};
// ossId
const ossId = parsedData.data.ossId;
console.log("ossId", ossId)
submitData.facePictures = ossId;
console.log(submitData)
this.$u.api.fksub(submitData).then(res => {
console.log(res)
if (res.code == 200) {
this.resetForm();
uni.showToast({
title: "提交成功,请等待审核!",
icon: "success"
})
}else {
uni.showToast({
title: "提交失败",
icon: "none"
})
}
})
} else {
uni.showToast({
title: '提交成功',
icon: 'success',
duration: 2000
title: '上传失败',
icon: 'none'
});
}
uni.hideLoading();
// return
// API
// setTimeout(() => {
// uni.request({
// url: this.formData.facePictures
// })
// // .then(response => response.blob())
// .then(blob => {
// // Blob
// console.log(blob);
// const file = new File([blob], 'filename.png', {
// type: blob.type
// });
// // FormData
// const formData = new FormData();
// formData.append('file', file);
// console.log(formData)
//
// this.$u.api.uploadimg()
// Blob
// uni.uploadFile({
// url: 'http://183.230.235.66:11010/api/resource/oss/upload', //
// filePath: this.formData.facePictures, //
// name: 'file', //
// // FormData
// // formData: {
// // 'code': this.formData.qrCodeId //
// // },
// // //
// // onProgressUpdate: (res) => {
// // this.progress = res.progress;
// // console.log(':' + res.progress);
// // },
// //
// success: (res) => {
// console.log('', res);
//
setTimeout(() => {
//
this.resetForm();
//
// uni.navigateBack();
}, 2000);
}, 1500);
// // this.formData.facePictures = res.data.ossId;
// //
// const submitData = {
// ...this.formData,
// bookingParkingSpace: this.formData
// .bookingParkingSpace ? 0 : 1
// };
// const parsedData = JSON.parse(res.data);
// if (parsedData.code == 200) {
// // ossId
// const ossId = parsedData.data.ossId;
// console.log("ossId", ossId)
// submitData.facePictures = ossId;
// console.log(submitData)
// this.$u.api.fksub(submitData).then(res => {
// console.log(res)
// if (res.code == 200) {
// this.resetForm();
// uni.showToast({
// title: "",
// icon: "success"
// })
// }
// })
// }else{
// uni.showToast({
// title: '',
// icon: 'none'
// });
// }
// // uni.showToast({
// // title: '',
// // icon: 'success'
// // });
// },
// //
// fail: (err) => {
// console.error('', err);
// uni.showToast({
// title: '',
// icon: 'none'
// });
// },
// //
// complete: () => {
// this.progress = 0; //
// }
// });
// this.$u.api.uploadimg(formData).then(res => {
// console.log(res)
// if (res.code == 200) {
// uni.showToast({
// title: "",
// icon: "success"
// })
// } else {
// uni.showToast({
// title: "tp",
// icon: "error"
// })
// }
// })
// });
//
// uni.showToast({
// title: '',
// icon: 'success',
// duration: 2000
// });
// //
// setTimeout(() => {
// //
// this.resetForm();
// //
// // uni.navigateBack();
// }, 2000);
// }, 1500);
},
delimg() {
this.formData.facePictures = ''