6c268f28
杨鑫
最新1
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
shareMsg() {
this.showShareModal = true;
},
// 关闭分享拉起框
closeShareModal() {
this.showShareModal = false;
},
// 生成海报
generatePoster() {
this.closeShareModal()
this.$http.sendRequest(`/cerePromotion/getSharePic/${this.tableData.id}`, 'GET', '', 1).then(res => {
this.posterUrl = this.imgurl + res.data.data
this.imgUrls.push(this.imgurl + res.data.data)
this.mergeImages()
this.showPosterMask = true;
})
// setTimeout(() => {
// this.posterUrl = 'https://dummyimage.com/800x600/ff0000/ffffff'; // 替换为真实的海报图片地址
// this.showPosterMask = true;
// }, 1000);
},
getImageInfo(src) {
return new Promise((resolve, reject) => {
wx.getImageInfo({
src,
success: (res) => resolve(res),
fail: (res) => reject(res)
})
});
},
mergeImages(imgs) {
const imgUrls = this.imgUrls
const imgPromises = imgUrls.map((url) => {
return new Promise((resolve, reject) => {
uni.getImageInfo({
src: url,
success: (res) => {
// 直接传递图片路径,无需创建 Image 对象
resolve({
path: res.path,
width: res.width,
height: res.height
});
},
fail: (err) => {
console.error('获取图片信息失败:', err);
reject(err);
}
});
});
});
Promise.all(imgPromises)
.then((imgInfos) => {
let maxHeight = 400;
let totalWidth = 300;
let scaledWidth = 0
let scaledHeight = 0
imgInfos.forEach((imgInfo, index) => {
if (index === 0) {
const imgInfo = imgInfos[index];
const imgRatio = imgInfo.width / imgInfo.height; // 图片的宽高比例
const canvasRatio = totalWidth / maxHeight; // 画布的宽高比例
if (imgRatio > canvasRatio) {
// 图片更宽,按宽度缩放
scaledWidth = totalWidth;
scaledHeight = maxHeight / imgRatio;
} else {
// 图片更高,按高度缩放
scaledHeight = maxHeight;
scaledWidth = totalWidth * imgRatio;
}
// 设置画布的宽度和高度为缩放后的图片宽度和高度
this.canvasWidth = scaledWidth;
this.canvasHeight = scaledHeight;
}
maxHeight = Math.max(maxHeight, imgInfo.height);
totalWidth += imgInfo.width;
});
if (totalWidth === 0 || maxHeight === 0) {
console.error('计算得到的画布尺寸为0');
return;
}
const ctx = uni.createCanvasContext('mergeCanvas');
uni.getSystemInfo({
success: (systemInfo) => {
// 处理第一张图片,按窗口宽高比例缩放
const firstImgInfo = imgInfos[0];
// 清空画布并设置缩放
ctx.setFillStyle('white');
ctx.fillRect(0, 0, this.canvasWidth, this.canvasHeight);
// 绘制第一张图片作为背景
ctx.drawImage(
firstImgInfo.path,
0,
0,
this.canvasWidth,
this.canvasHeight,
);
const secondImgInfo = imgInfos[1];
// 绘制第二张图片在第一张图片上层右下角
ctx.drawImage(
secondImgInfo.path,
this.canvasWidth-100,
this.canvasHeight-100,
100,
100
);
setTimeout(() => {
// 绘制完成后生成图片
ctx.draw(false, () => {
uni.canvasToTempFilePath({
canvasId: 'mergeCanvas',
success: (res) => {
console.log('生成临时文件成功,路径:', res
.tempFilePath);
this.mergedImageSrc = res
.tempFilePath;
},
fail: (err) => {
console.error('生成临时文件失败', err);
}
});
});
}, 1000)
},
fail: (err) => {
console.error('获取设备信息失败', err);
}
});
})
.catch((err) => {
console.error('获取图片信息失败或图片加载失败', err);
})
},
// 关闭海报遮罩层
closePosterMask() {
this.showPosterMask = false;
this.mergedImageSrc = '';
},
onShareAppMessage() {
return {
title: this.tableData.schemeTitle,
imageUrl: this.imgurl + this.tableData.coverImage,
path: `/pagesA/projectManagement/projectDetails?id=${this.tableData.id}`,
success(res) {
uni.showToast({
icon: 'none',
title: '分享成功'
})
},
fail(err) {
console.log('分享失败', err);
}
};
},
saveImage() {
// 获取图片信息
uni.getImageInfo({
src: this.mergedImageSrc,
success: (res) => {
const tempFilePath = res.path
// 检查保存相册权限
uni.getSetting({
success: (settingRes) => {
if (!settingRes.authSetting['scope.writePhotosAlbum']) {
// 没有权限,请求权限
uni.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
// 授权成功,保存图片
this.saveImageToAlbum(tempFilePath);
},
fail: () => {
// 授权失败,提示用户手动开启权限
uni.showModal({
title: '提示',
content: '请在设置中开启保存相册权限',
success: (modalRes) => {
if (modalRes.confirm) {
uni.openSetting();
}
}
});
}
});
} else {
// 已有权限,保存图片
this.saveImageToAlbum(tempFilePath);
}
}
});
},
fail: (err) => {
console.error('获取图片信息失败:', err);
uni.showToast({
title: '获取图片信息失败',
icon: 'none'
});
}
});
},
saveImageToAlbum(tempFilePath) {
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: () => {
uni.showToast({
title: '图片保存成功',
icon: 'success'
});
},
fail: (err) => {
console.error('保存图片到相册失败:', err);
uni.showToast({
title: '保存图片到相册失败',
icon: 'none'
});
}
});
},
|
6c268f28
杨鑫
最新1
|
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
.share-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.3);
z-index: 99;
}
.share-modal {
position: fixed;
bottom: -200px;
/* 初始位置在屏幕外 */
left: 0;
right: 0;
background-color: #fff;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
// padding: 10px;
z-index: 100;
transition: bottom 0.3s ease;
/* 添加过渡效果 */
}
.share-modal-animate {
bottom: 0;
/* 动画结束位置 */
}
.share-option {
padding: 15px;
text-align: center;
border-bottom: 1px solid #eee;
background-color: #fff;
}
.poster-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 101;
}
.poster-container {
position: relative;
background-color: #fff;
padding: 10px;
border-radius: 10px;
// height: 400px;
width: 90%;
}
.close-btn {
position: absolute;
top: 10px;
right: 10px;
font-size: 20px;
cursor: pointer;
}
button {
padding: 0;
margin: 0;
border: 1px solid transparent;
line-height: 1;
font-size: 14px;
}
button::after {
border: none;
}
|