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({
|
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,6 +34,7 @@
|
|||||||
|
|
||||||
<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
|
||||||
@ -394,34 +395,123 @@
|
|||||||
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({
|
|
||||||
canvasId: 'handWriting',
|
uni.showLoading({
|
||||||
fileType: 'png',
|
title: '正在生成图片...'
|
||||||
quality: 1, //图片质量
|
});
|
||||||
success(res) {
|
|
||||||
uni.showToast({
|
uni.canvasToTempFilePath({
|
||||||
title: '以保存'
|
canvasId: 'handWriting',
|
||||||
});
|
fileType: 'png',
|
||||||
//保存到系统相册
|
quality: 1,
|
||||||
uni.saveImageToPhotosAlbum({
|
success: async (res) => {
|
||||||
filePath: res.tempFilePath,
|
uni.hideLoading();
|
||||||
success(res) {
|
|
||||||
uni.showToast({
|
// 1. 保存到本地相册
|
||||||
title: '已成功保存到相册',
|
try {
|
||||||
duration: 2000
|
await this.saveToAlbum(res.tempFilePath);
|
||||||
});
|
|
||||||
}
|
// 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