Compare commits
No commits in common. "98dda253ce8a20b4994cee39012241cb45803094" and "0b395638ed5ae6ab2d7eedede065d81876aebfbc" have entirely different histories.
98dda253ce
...
0b395638ed
@ -96,7 +96,6 @@
|
|||||||
wx.canvasToTempFilePath({
|
wx.canvasToTempFilePath({
|
||||||
canvasId: 'signatureCanvas',
|
canvasId: 'signatureCanvas',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log(res.tempFilePath)
|
|
||||||
this.setData({
|
this.setData({
|
||||||
signatureImage: res.tempFilePath
|
signatureImage: res.tempFilePath
|
||||||
});
|
});
|
||||||
|
|||||||
@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import pickerColor from "./pickerColor.vue"
|
import pickerColor from "./pickerColor.vue"
|
||||||
import {IMAGE_BASE_URL,BASE_URL} from '@/utils/config';
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
pickerColor
|
pickerColor
|
||||||
@ -395,123 +394,34 @@
|
|||||||
this.ctx.setStrokeStyle(this.lineColor)
|
this.ctx.setStrokeStyle(this.lineColor)
|
||||||
},
|
},
|
||||||
//完成
|
//完成
|
||||||
// 完成
|
|
||||||
subCanvas() {
|
subCanvas() {
|
||||||
if (this.isEmpty()) {
|
if (this.isEmpty()) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '没有任何绘制内容哦',
|
title: '没有任何绘制内容哦',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
});
|
});
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
uni.canvasToTempFilePath({
|
||||||
uni.showLoading({
|
canvasId: 'handWriting',
|
||||||
title: '正在生成图片...'
|
fileType: 'png',
|
||||||
});
|
quality: 1, //图片质量
|
||||||
|
success(res) {
|
||||||
uni.canvasToTempFilePath({
|
uni.showToast({
|
||||||
canvasId: 'handWriting',
|
title: '以保存'
|
||||||
fileType: 'png',
|
});
|
||||||
quality: 1,
|
//保存到系统相册
|
||||||
success: async (res) => {
|
uni.saveImageToPhotosAlbum({
|
||||||
uni.hideLoading();
|
filePath: res.tempFilePath,
|
||||||
|
success(res) {
|
||||||
// 1. 保存到本地相册
|
uni.showToast({
|
||||||
try {
|
title: '已成功保存到相册',
|
||||||
await this.saveToAlbum(res.tempFilePath);
|
duration: 2000
|
||||||
|
});
|
||||||
// 2. 上传到服务器
|
}
|
||||||
uni.showLoading({
|
});
|
||||||
title: '正在上传签名...'
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const uploadRes = await this.uploadSignature(res.tempFilePath);
|
|
||||||
|
|
||||||
uni.hideLoading();
|
|
||||||
uni.showToast({
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
//保存到相册
|
//保存到相册
|
||||||
saveCanvasAsImg() {
|
saveCanvasAsImg() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user