Merge branch 'main' of https://gitlab.guxuan.icu/Leo_Ding/JinShan_uniapp
This commit is contained in:
commit
11e2900c47
@ -96,6 +96,7 @@
|
||||
wx.canvasToTempFilePath({
|
||||
canvasId: 'signatureCanvas',
|
||||
success: (res) => {
|
||||
console.log(res.tempFilePath)
|
||||
this.setData({
|
||||
signatureImage: res.tempFilePath
|
||||
});
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
|
||||
<script>
|
||||
import pickerColor from "./pickerColor.vue"
|
||||
import {IMAGE_BASE_URL,BASE_URL} from '@/utils/config';
|
||||
export default {
|
||||
components: {
|
||||
pickerColor
|
||||
@ -394,33 +395,122 @@
|
||||
this.ctx.setStrokeStyle(this.lineColor)
|
||||
},
|
||||
//完成
|
||||
// 完成
|
||||
subCanvas() {
|
||||
if (this.isEmpty()) {
|
||||
uni.showToast({
|
||||
title: '没有任何绘制内容哦',
|
||||
icon: 'none',
|
||||
});
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showLoading({
|
||||
title: '正在生成图片...'
|
||||
});
|
||||
|
||||
uni.canvasToTempFilePath({
|
||||
canvasId: 'handWriting',
|
||||
fileType: 'png',
|
||||
quality: 1, //图片质量
|
||||
success(res) {
|
||||
uni.showToast({
|
||||
title: '以保存'
|
||||
quality: 1,
|
||||
success: async (res) => {
|
||||
uni.hideLoading();
|
||||
|
||||
// 1. 保存到本地相册
|
||||
try {
|
||||
await this.saveToAlbum(res.tempFilePath);
|
||||
|
||||
// 2. 上传到服务器
|
||||
uni.showLoading({
|
||||
title: '正在上传签名...'
|
||||
});
|
||||
//保存到系统相册
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success(res) {
|
||||
|
||||
const uploadRes = await this.uploadSignature(res.tempFilePath);
|
||||
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '已成功保存到相册',
|
||||
title: '签名上传成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
// 3. 可以通过回调或者事件将上传结果返回给父组件
|
||||
// this.$emit('upload-success', {
|
||||
// tempFilePath: res.tempFilePath,
|
||||
// serverPath: uploadRes // 假设服务器返回了图片地址
|
||||
// });
|
||||
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: error.message || '上传失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '生成图片失败',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 保存到相册的方法
|
||||
saveToAlbum(tempFilePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: tempFilePath,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '已保存到相册',
|
||||
duration: 2000
|
||||
});
|
||||
resolve();
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(new Error('保存到相册失败'));
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 上传签名到服务器的方法
|
||||
uploadSignature(tempFilePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 这里替换为你自己的上传接口
|
||||
const uploadUrl = IMAGE_BASE_URL+'/api/v1/upload';
|
||||
uni.uploadFile({
|
||||
url: uploadUrl,
|
||||
filePath: tempFilePath,
|
||||
name: 'file',
|
||||
// formData: {
|
||||
// // 可以添加其他表单数据
|
||||
// userId: '123', // 示例用户ID
|
||||
// type: 'signature'
|
||||
// },
|
||||
success: (uploadRes) => {
|
||||
console.log(uploadRes);
|
||||
console.log(JSON.parse(uploadRes.data))
|
||||
try {
|
||||
const {success,data} = JSON.parse(uploadRes.data);
|
||||
if (success) {
|
||||
resolve(data); // 假设服务器返回了图片URL
|
||||
} else {
|
||||
reject(new Error(success || '上传失败'));
|
||||
}
|
||||
} catch (e) {
|
||||
reject(new Error('解析服务器响应失败'));
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(new Error('上传请求失败'));
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
//保存到相册
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user