Commit 93836002 authored by lvtz's avatar lvtz

fix

parent 86a42d3b
{ {
"navigationBarTitleText": "分享卡片", "navigationBarTitleText": "分享卡片",
"enablePullDownRefresh": false,
"disableScroll": true,
"usingComponents": { "usingComponents": {
"canvasdrawer": "/components/canvasdrawer/canvasdrawer", "canvasdrawer": "/components/canvasdrawer/canvasdrawer",
"canvas-drag": "/components/canvas-drag/index" "canvas-drag": "/components/canvas-drag/index"
......
<wxs src="./../../../filter/index.wxs" module="filter" /> <wxs src="./../../../filter/index.wxs" module="filter" />
<view class="container"> <view class="container">
<view class="swiperwrap"> <view class="swiperwrap">
<view class="card carda" data-posterindex="1" bindtap="generatePoster" > <view class="card {{hasReviewImg.length==0?'card-s':''}} {{selectCardLong?'card-hide':''}}">
<image class="cardbg" src="{{currentImgUrl}}" wx:if="{{hasReviewImg.length>0}}"></image> <image class="cardbg" src="{{currentImgUrl}}"></image>
<image class="cardbg" src="{{imageRoot}}2b/classreviewshare/carda_s.png?{{imageVersion}}" wx:else></image>
<view class="cardcontent"> <view class="cardcontent">
<image class="avatar" src="{{filter.imagify(userInfo.avatar, 'image/resize,w_320/format,jpg/quality,q_50')}}"></image> <image class="avatar" src="{{filter.imagify(userInfo.avatar, 'image/resize,w_320/format,jpg/quality,q_50')}}" wx:if="{{userInfo.avatar}}"></image>
<image class="avatar" src="{{imageRoot}}common/empty/avatar_user.png?{{imageVersion}}" wx:else></image>
<view class="nickname">{{userInfo.nickname}}</view> <view class="nickname">{{userInfo.nickname}}</view>
<view class="imgbox" wx:if="{{hasReviewImg.length>0}}"> <view class="imgbox" wx:if="{{hasReviewImg.length>0}}">
<canvas-drag id="canvas-drag" graph="{{graph}}" width="520" height="440" enableUndo="{{true}}"></canvas-drag> <canvas-drag id="canvas-drag" graph="{{graph2}}" width="520" height="440" enableUndo="{{true}}"></canvas-drag>
<image class="icon-angle icon-angle-lt" src="{{imageRoot}}2b/classreviewshare/icon_angle_lr.png?{{imageVersion}}"></image> <cover-image class="icon-angle icon-angle-lt" src="{{imageRoot}}2b/classreviewshare/icon_angle_lr.png?{{imageVersion}}"></cover-image>
<image class="icon-angle icon-angle-rt" src="{{imageRoot}}2b/classreviewshare/icon_angle_rl.png?{{imageVersion}}"></image> <cover-image class="icon-angle icon-angle-rt" src="{{imageRoot}}2b/classreviewshare/icon_angle_rl.png?{{imageVersion}}"></cover-image>
<image class="icon-angle icon-angle-rb" src="{{imageRoot}}2b/classreviewshare/icon_angle_lr.png?{{imageVersion}}"></image> <cover-image class="icon-angle icon-angle-rb" src="{{imageRoot}}2b/classreviewshare/icon_angle_lr.png?{{imageVersion}}"></cover-image>
<image class="icon-angle icon-angle-lb" src="{{imageRoot}}2b/classreviewshare/icon_angle_rl.png?{{imageVersion}}"></image> <cover-image class="icon-angle icon-angle-lb" src="{{imageRoot}}2b/classreviewshare/icon_angle_rl.png?{{imageVersion}}"></cover-image>
<!-- <image class="review-img" src="{{filter.imagify(hasReviewImg[0].src, 'image/resize,w_320/format,jpg/quality,q_50')}}" mode="aspectFill"></image> -->
</view> </view>
<view class="reviewtext">{{reviewDetailContent.content}}</view> <view class="reviewtext">{{reviewDetailContent.content}}</view>
<image class="icon-audio" src="{{imageRoot}}2b/classreviewshare/icon_audio.png?{{imageVersion}}" wx:if="{{hasReviewAudio.length>0}}"></image> <image class="icon-audio" src="{{imageRoot}}2b/classreviewshare/icon_audio.png?{{imageVersion}}" wx:if="{{hasReviewAudio}}"></image>
</view> </view>
<form report-submit="true" bindsubmit="formIdCreate" class="createidform"> <form report-submit="true" bindsubmit="formIdCreate" class="createidform">
<button form-type="submit" class="createidbutton">生成form</button> <button form-type="submit" class="createidbutton">生成form</button>
</form> </form>
</view> </view>
<view class="{{!selectCardLong?'card-hide':''}}">长图</view>
</view> </view>
<view class="scroll-box"> <view class="scroll-box">
<view class="tab-box"> <view class="tab-box">
...@@ -48,14 +48,18 @@ ...@@ -48,14 +48,18 @@
scroll-left = "{{scrollLeft}}" scroll-left = "{{scrollLeft}}"
wx:if="{{bigType==2}}" wx:if="{{bigType==2}}"
> >
<view class="cardbox {{bigType==2 && currentIndex == index ? 'selected' : ''}}" data-item="{{item}}" bindtap="selectCard" wx:for="{{tempImgArr2}}" wx:key=""> <view class="cardbox {{bigType==2 && currentIndex == index ? 'selected' : ''}}" data-item="{{item}}" data-islong="1" bindtap="selectCard" wx:for="{{tempImgArr2}}" wx:key="">
<view class="card"> <view class="card">
<image class="cardbg" src="{{item.icon_src}}"></image> <image class="cardbg" src="{{item.icon_src}}"></image>
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
<view class="button-boxfix">生成卡片</view> <view class="button-boxfix">
<view class="btn btn-l" wx:if="{{hasReviewImg.length>0 && !selectCardLong}}" bindtap="changeCover">换封面 ({{coverindex+1}}/{{hasReviewImg.length}})</view>
<view class="btn btn-r" bindtap="saveAndGenerate">生成卡片</view>
</view>
</view> </view>
<canvasdrawer painting="{{painting}}" bind:getImage="eventGetImage"/> <canvasdrawer painting="{{painting}}" bind:getImage="eventGetImage"/>
</view> </view>
...@@ -26,6 +26,14 @@ page{ ...@@ -26,6 +26,14 @@ page{
width: 647rpx; width: 647rpx;
height: 826rpx; height: 826rpx;
} }
.card-s {
position: relative;
width: 647rpx;
height: 522rpx;
}
.card-hide{
display: none;
}
.cardbg { .cardbg {
width: 100%; width: 100%;
height: 100%; height: 100%;
...@@ -44,7 +52,7 @@ page{ ...@@ -44,7 +52,7 @@ page{
top: 0; top: 0;
padding: 17rpx 52rpx 0; padding: 17rpx 52rpx 0;
} }
.carda .cardcontent .avatar { .card .cardcontent .avatar {
width: 80rpx; width: 80rpx;
height: 80rpx; height: 80rpx;
margin: 0 auto; margin: 0 auto;
...@@ -53,7 +61,7 @@ page{ ...@@ -53,7 +61,7 @@ page{
border: 3rpx solid rgba(255,255,255,1); border: 3rpx solid rgba(255,255,255,1);
display: block; display: block;
} }
.carda .cardcontent .nickname { .card .cardcontent .nickname {
color: #000; color: #000;
font-size: 24rpx; font-size: 24rpx;
text-align: center; text-align: center;
...@@ -63,7 +71,7 @@ page{ ...@@ -63,7 +71,7 @@ page{
line-height: 1; line-height: 1;
padding-top: 17rpx; padding-top: 17rpx;
} }
.carda .cardcontent .imgbox{ .card .cardcontent .imgbox{
width: 542rpx; width: 542rpx;
height: 463rpx; height: 463rpx;
background: rgba(255,255,255,1); background: rgba(255,255,255,1);
...@@ -73,34 +81,34 @@ page{ ...@@ -73,34 +81,34 @@ page{
padding: 10rpx; padding: 10rpx;
overflow: hidden; overflow: hidden;
} }
.carda .cardcontent .imgbox .icon-angle{ .card .cardcontent .imgbox .icon-angle{
width: 44rpx; width: 44rpx;
height: 44rpx; height: 44rpx;
background: rgba(101,184,244,1); background: rgba(101,184,244,1);
border-radius: 50%; border-radius: 50%;
position: absolute; position: absolute;
} }
.carda .cardcontent .imgbox .icon-angle-lt{ .card .cardcontent .imgbox .icon-angle-lt{
top: 12rpx; top: 12rpx;
left: 12rpx; left: 12rpx;
} }
.carda .cardcontent .imgbox .icon-angle-rt{ .card .cardcontent .imgbox .icon-angle-rt{
top: 12rpx; top: 12rpx;
right: 12rpx; right: 12rpx;
} }
.carda .cardcontent .imgbox .icon-angle-rb{ .card .cardcontent .imgbox .icon-angle-rb{
bottom: 12rpx; bottom: 12rpx;
right: 12rpx; right: 12rpx;
} }
.carda .cardcontent .imgbox .icon-angle-lb{ .card .cardcontent .imgbox .icon-angle-lb{
bottom: 12rpx; bottom: 12rpx;
left: 12rpx; left: 12rpx;
} }
.carda .cardcontent .imgbox .review-img{ .card .cardcontent .imgbox .review-img{
width: 100%; width: 100%;
max-height: 440rpx; max-height: 440rpx;
} }
.carda .reviewtext { .card .reviewtext {
font-size: 20rpx; font-size: 20rpx;
line-height: 28rpx; line-height: 28rpx;
color: #000; color: #000;
...@@ -112,6 +120,9 @@ page{ ...@@ -112,6 +120,9 @@ page{
padding-top: 13rpx; padding-top: 13rpx;
font-weight: 500; font-weight: 500;
} }
.card.card-s .reviewtext{
-webkit-line-clamp: 4;
}
.icon-audio{ .icon-audio{
width: 124rpx; width: 124rpx;
height: 34rpx; height: 34rpx;
...@@ -198,10 +209,46 @@ page{ ...@@ -198,10 +209,46 @@ page{
width: 100%; width: 100%;
height: 100rpx; height: 100rpx;
background: #65B8F4; background: #65B8F4;
font-size: 30rpx; display: flex;
color: #fff; }
font-weight: 500; .button-boxfix .btn{
height: 100%;
flex: 1;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
font-size: 30rpx;
color: #fff;
font-weight: 500;
position: relative;
}
.button-boxfix .btn::after{
content: '';
width: 1px;
height: 100%;
background: #fff;
position: absolute;
right: 0;
top: 0;
transform: scaleX(.5);
}
.button-boxfix .btn:last-of-type::after{
display: none;
}
.button-boxfix .btn-l{
background: #fff;
color: #666;
}
.button-boxfix .btn-l::before{
content: '';
width: 100%;
height: 1px;
background: rgba(0,0,0,.05);
position: absolute;
left: 0;
top: 0;
transform: scaleY(.5);
}
.button-boxfix .btn-l{
} }
\ No newline at end of file
...@@ -7,13 +7,10 @@ function CanvasDrag(options = {}) { ...@@ -7,13 +7,10 @@ function CanvasDrag(options = {}) {
...defaultOptions, ...defaultOptions,
...options, ...options,
}; };
const pages = getCurrentPages(); const pages = getCurrentPages();
const ctx = pages[pages.length - 1]; const ctx = pages[pages.length - 1];
const canvasDrag = ctx.selectComponent(options.selector);
const canvasDrag = ctx.selectComponent(options.selector);
delete options.selector; delete options.selector;
return canvasDrag; return canvasDrag;
} }
...@@ -25,67 +22,12 @@ CanvasDrag.export = () => { ...@@ -25,67 +22,12 @@ CanvasDrag.export = () => {
return CanvasDrag().export(); return CanvasDrag().export();
} }
}; };
CanvasDrag.initByArr = (arr) => {
const canvasDrag = CanvasDrag();
if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!');
} else {
return CanvasDrag().initByArr(arr);
}
};
CanvasDrag.exportJson = () => {
const canvasDrag = CanvasDrag();
if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!');
} else {
return CanvasDrag().exportJson();
}
};
CanvasDrag.changFontColor = (color) => {
const canvasDrag = CanvasDrag();
if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!');
} else {
return CanvasDrag().changColor(color);
}
};
CanvasDrag.changeBgColor = (color) => {
const canvasDrag = CanvasDrag();
if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!');
} else {
return CanvasDrag().changeBgColor(color);
}
};
CanvasDrag.changeBgImage = (bgImage) => {
const canvasDrag = CanvasDrag();
if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!');
} else {
return CanvasDrag().changeBgImage(bgImage);
}
};
CanvasDrag.clearCanvas = () => { CanvasDrag.clearCanvas = () => {
const canvasDrag = CanvasDrag();
if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!');
} else {
return CanvasDrag().clearCanvas();
}
};
CanvasDrag.undo = () => {
const canvasDrag = CanvasDrag(); const canvasDrag = CanvasDrag();
if (!canvasDrag) { if (!canvasDrag) {
console.error('请设置组件的id="canvas-drag"!!!'); console.error('请设置组件的id="canvas-drag"!!!');
} else { } else {
return CanvasDrag().undo(); return CanvasDrag().clearCanvas();
} }
}; };
export default CanvasDrag; export default CanvasDrag;
\ No newline at end of file
// components/canvas-drag/index.js // components/canvas-drag/index.js
const DRAG_ICON = '../../images/2b/classreviewshare/icon_angle_lr.png'; // 缩放按钮 const DRAG_ICON = './icon_angle_rl.png'; // 缩放按钮
const STROKE_COLOR = 'red';
const ROTATE_ENABLED = true; const ROTATE_ENABLED = true;
let isMove = false; // 标识触摸后是否有移动,用来判断是否需要增加操作历史 let isMove = false; // 标识触摸后是否有移动,用来判断是否需要增加操作历史
const DEBUG_MODE = false; // 打开调试后会渲染操作区域边框(无背景时有效) const DEBUG_MODE = false; // 打开调试后会渲染操作区域边框(无背景时有效)
const dragGraph = function ({x = 30, y = 30, w, h, type, text, fontSize = 20, color = 'red', url = null, rotate = 0, sourceId = null, selected = true}, canvas, factor) { const dragGraph = function ({x = 30, y = 30, w, h, type, text, fontSize = 20, color = 'red', url = null, rotate = 0, sourceId = null, selected = true}, canvas, factor) {
if (type === 'text') { this.centerX = x + w / 2;
canvas.setFontSize(fontSize); this.centerY = y + h / 2;
const textWidth = canvas.measureText(text).width; this.w = w;
const textHeight = fontSize + 10; this.h = h;
this.centerX = x + textWidth / 2;
this.centerY = y + textHeight / 2;
this.w = textWidth;
this.h = textHeight;
} else {
this.centerX = x + w / 2;
this.centerY = y + h / 2;
this.w = w;
this.h = h;
}
this.x = x; this.x = x;
this.y = y; this.y = y;
...@@ -52,41 +40,18 @@ dragGraph.prototype = { ...@@ -52,41 +40,18 @@ dragGraph.prototype = {
*/ */
paint() { paint() {
this.ctx.save(); this.ctx.save();
// 由于measureText获取文字宽度依赖于样式,所以如果是文字元素需要先设置样式
let textWidth = 0;
let textHeight = 0;
if (this.type === 'text') {
this.ctx.setFontSize(this.fontSize);
this.ctx.setTextBaseline('middle');
this.ctx.setTextAlign('center');
this.ctx.setFillStyle(this.color);
textWidth = this.ctx.measureText(this.text).width;
textHeight = this.fontSize + 10;
// 字体区域中心点不变,左上角位移
this.x = this.centerX - textWidth / 2;
this.y = this.centerY - textHeight / 2;
}
// 旋转元素 // 旋转元素
this.ctx.translate(this.centerX, this.centerY); this.ctx.translate(this.centerX, this.centerY);
this.ctx.rotate(this.rotate * Math.PI / 180); this.ctx.rotate(this.rotate * Math.PI / 180);
this.ctx.translate(-this.centerX, -this.centerY); this.ctx.translate(-this.centerX, -this.centerY);
// 渲染元素 // 渲染元素
if (this.type === 'text') { if (this.type === 'image') {
this.ctx.fillText(this.text, this.centerX, this.centerY);
} else if (this.type === 'image') {
this.ctx.drawImage(this.fileUrl, this.x, this.y, this.w, this.h); this.ctx.drawImage(this.fileUrl, this.x, this.y, this.w, this.h);
} }
// 如果是选中状态,绘制选择虚线框,和缩放图标 // 如果是选中状态,绘制缩放图标
if (this.selected) { if (this.selected) {
this.ctx.setLineDash([2, 5]);
this.ctx.setLineWidth(2);
this.ctx.setStrokeStyle(STROKE_COLOR);
this.ctx.lineDashOffset = 6;
this.ctx.strokeRect(this.x, this.y, this.w, this.h);
this.ctx.drawImage(DRAG_ICON, this.x + this.w - 15, this.y + this.h - 15, 22, 22); this.ctx.drawImage(DRAG_ICON, this.x + this.w - 15, this.y + this.h - 15, 22, 22);
} }
this.ctx.restore(); this.ctx.restore();
}, },
...@@ -225,19 +190,9 @@ dragGraph.prototype = { ...@@ -225,19 +190,9 @@ dragGraph.prototype = {
*/ */
transform(px, py, x, y, currentGraph) { transform(px, py, x, y, currentGraph) {
// 获取选择区域的宽度高度 // 获取选择区域的宽度高度
if (this.type === 'text') {
this.ctx.setFontSize(this.fontSize); this.centerX = this.x + this.w / 2;
const textWidth = this.ctx.measureText(this.text).width; this.centerY = this.y + this.h / 2;
const textHeight = this.fontSize + 10;
this.w = textWidth;
this.h = textHeight;
// 字体区域中心点不变,左上角位移
this.x = this.centerX - textWidth / 2;
this.y = this.centerY - textHeight / 2;
} else {
this.centerX = this.x + this.w / 2;
this.centerY = this.y + this.h / 2;
}
const diffXBefore = px - this.centerX; const diffXBefore = px - this.centerX;
const diffYBefore = py - this.centerY; const diffYBefore = py - this.centerY;
...@@ -385,6 +340,7 @@ Component({ ...@@ -385,6 +340,7 @@ Component({
} }
}, },
onGraphChange(n, o) { onGraphChange(n, o) {
console.log(n,o,222222)
if (JSON.stringify(n) === '{}') return; if (JSON.stringify(n) === '{}') return;
if(!this.ctx) return; if(!this.ctx) return;
this.drawArr.push(new dragGraph(Object.assign({ this.drawArr.push(new dragGraph(Object.assign({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment