Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d41922a7
authored
Jul 04, 2024
by
李伟康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
commit 替换缩放组件
1 parent
48b7c2fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
172 deletions
components/Canvas/wn-canvas.vue
components/Canvas/zoom-pan.vue
components/Canvas/wn-canvas.vue
View file @
d41922a
<
template
>
<
template
>
<view
class=
"wn-canvas"
>
<view
class=
"wn-canvas"
>
<template
v-if=
"false"
>
<template
v-if=
"showPenBox"
>
<view
class=
"pen-box"
>
<view
class=
"pen"
:style=
"
{backgroundColor: currentColor, height: lineWidth+'px'}"
>
</view>
<slider
min=
"1"
max=
"20"
:value=
"lineWidth"
block-size=
"20"
activeColor=
"#84f876"
class=
"pen-slider"
@
change=
"penWidthChange"
/>
<view
class=
"pen-txt"
>
{{
lineWidth
}}
px
</view>
</view>
</
template
>
<image
v-if=
"isLandScape"
src=
"./img/color.png"
mode=
""
class=
"draw-logo"
@
click=
"showTools"
></image>
<view
class=
"tools-box"
v-if=
"toolsShow"
>
<view
class=
"tools"
>
<view
class=
"tools-item "
v-for=
"(item,index) in tools"
:key=
"index"
>
<button
open-type=
"share"
v-if=
"item.key == 'share'"
style=
"background-color: rgba(0,0,0,0);padding: 0;border-radius: none;line-height: 0;borderColor:rgba(0,0,0,0);"
>
<image
class=
"tools-icon"
:src=
"item.active?item.item.activeUrl:item.url"
mode=
"aspectFit"
>
</image>
</button>
<image
@
click=
"chooseTools(item)"
v-else
:src=
"item.active?item.activeUrl:item.url"
class=
"tools-icon"
></image>
</view>
</view>
</view>
</template>
<!-- <movable-area
:class="['canvas-box',{fill:custom}]"
scale-area
:style="{height:height}"
@touchstart="viewTouchStart"
>
<movable-view
class="canvas-view"
scale-min="1"
:scale="!drawStatus"
:disabled="drawStatus"
:direction="scaleValue == 1?'none':'all'"
:scale-value="defaultScaleValue"
@scale="scale"
> -->
<zoom-pan
<zoom-pan
:class=
"['canvas-box',
{fill:custom}]"
:class=
"['canvas-box',
{fill:custom}]"
:disabled="drawStatus"
:disabled="drawStatus"
...
@@ -108,25 +35,6 @@
...
@@ -108,25 +35,6 @@
</template>
</template>
</template>
</template>
</zoom-pan>
</zoom-pan>
<!-- <image class="under-image" :src="drawImage"
mode="scaleToFill"
/> -->
<!-- </movable-view>
</movable-area> -->
<!-- <color
:colorShow="colorShow"
@colorPickTap="colorPickTapHandler"
></color> -->
<!-- <view
class="btn-box"
v-if="showSave"
>
<button
type="primary"
@click="saveImage"
>保存</button>
</view> -->
</view>
</view>
</template>
</template>
...
@@ -899,7 +807,6 @@ export default {
...
@@ -899,7 +807,6 @@ export default {
}
}
},
},
/**缩放 */
/**缩放 */
scale
(
e
)
{
scale
(
e
)
{
this
.
scaleValue
=
e
.
scale
this
.
scaleValue
=
e
.
scale
this
.
$emit
(
'scale'
,
e
.
scale
)
this
.
$emit
(
'scale'
,
e
.
scale
)
...
...
components/Canvas/zoom-pan.vue
View file @
d41922a
<
template
>
<
template
>
<view
<view>
:class=
"['container zoom-pan-container',
{disabled:disabled}]"
<movable-area
@touchstart="handleTouchStart"
class=
"container zoom-pan-container"
@touchmove="handleTouchMove"
@
touchstart=
"handleTouchStart"
@touchend="handleTouchEnd"
@
touchmove=
"handleTouchMove"
@touchcancel="handleTouchEnd"
>
<view
class=
"content"
:style=
"
{ transform: transformStyle ,
'transform-origin': transformOriginStyle
}"
>
>
<slot
name=
"content"
></slot>
<movable-view
</view>
class=
"content"
:style=
"
{ transform: transformStyle ,
'transform-origin': transformOriginStyle
}"
scale
:direction="scale == 1?'none':'all'"
:scale-min="scaleMin"
:scale-max="scaleMax"
:disabled="disabled"
out-of-bounds
@scale="onScale"
>
<slot
name=
"content"
></slot>
</movable-view>
</movable-area>
</view>
</view>
</
template
>
</
template
>
<
script
>
<
script
>
...
@@ -35,25 +43,15 @@ export default {
...
@@ -35,25 +43,15 @@ export default {
},
},
data
()
{
data
()
{
return
{
return
{
startX
:
0
,
startY
:
0
,
moveX
:
0
,
moveY
:
0
,
scale
:
1
,
scale
:
1
,
lastScale
:
1
,
lastTouchDistance
:
0
,
isScaling
:
false
,
isScaling
:
false
,
isDragging
:
false
,
transformOrigin
:
{
x
:
0
,
y
:
0
},
transformStyle
:
''
,
transformStyle
:
''
,
transformOriginStyle
:
'50% 50%'
,
transformOriginStyle
:
'50% 50%'
scaleFactor
:
0.01
,
};
};
},
},
watch
:
{
watch
:
{
watchScaleValue
()
{
watchScaleValue
()
{
this
.
lastScale
=
1
this
.
scale
=
1
this
.
scale
=
1
this
.
transformStyle
=
`scale(1) translate(0px, 0px)`
this
.
transformStyle
=
`scale(1) translate(0px, 0px)`
}
}
...
@@ -66,44 +64,18 @@ export default {
...
@@ -66,44 +64,18 @@ export default {
methods
:
{
methods
:
{
handleTouchStart
(
e
)
{
handleTouchStart
(
e
)
{
if
(
this
.
disabled
)
return
if
(
this
.
disabled
)
return
if
(
e
.
touches
.
length
===
2
)
{
if
(
e
.
touches
.
length
===
2
)
this
.
isScaling
=
true
;
this
.
isScaling
=
true
;
this
.
lastTouchDistance
=
this
.
getTouchDistance
(
e
.
touches
);
// 初始化缩放中心为两指间的中心点
this
.
transformOrigin
=
this
.
getTouchCenter
(
e
.
touches
);
}
else
if
(
e
.
touches
.
length
===
1
)
{
this
.
isDragging
=
true
;
[
this
.
startX
,
this
.
startY
]
=
[
e
.
touches
[
0
].
pageX
,
e
.
touches
[
0
].
pageY
];
this
.
moveX
=
0
this
.
moveY
=
0
}
},
},
handleTouchMove
:
utils
.
throttle
(
function
(
e
)
{
handleTouchMove
:
utils
.
throttle
(
function
(
e
)
{
if
(
this
.
disabled
)
return
if
(
this
.
disabled
)
return
if
(
this
.
isScaling
&&
e
.
touches
.
length
===
2
)
{
if
(
this
.
isScaling
&&
e
.
touches
.
length
===
2
)
{
const
currentDistance
=
this
.
getTouchDistance
(
e
.
touches
);
const
center
=
this
.
getTouchCenter
(
e
.
touches
)
const
deltaDistance
=
currentDistance
-
this
.
lastTouchDistance
;
this
.
transformOriginStyle
=
`
${
center
.
x
}
px
${
center
.
y
}
px`
;
// 根据触点距离变化和缩放因子计算新的缩放比例
const
newScale
=
this
.
lastScale
+
deltaDistance
*
this
.
scaleFactor
;
this
.
setScale
(
newScale
,
this
.
getTouchCenter
(
e
.
touches
));
// 更新缩放同时更新中心点
this
.
lastTouchDistance
=
currentDistance
;
}
else
if
(
this
.
isDragging
&&
e
.
touches
.
length
===
1
&&
this
.
scale
!==
1
)
{
this
.
transformOriginStyle
=
`
${
this
.
startX
}
px
${
this
.
startY
}
px`
;
const
newX
=
e
.
touches
[
0
].
pageX
;
const
newY
=
e
.
touches
[
0
].
pageY
;
this
.
moveX
=
(
newX
-
this
.
startX
)
/
this
.
scale
;
this
.
moveY
=
(
newY
-
this
.
startY
)
/
this
.
scale
;
// 确保计算基于初始未缩放的触摸点,并考虑当前缩放比例
this
.
updatePosition
();
}
}
},
16
),
},
16
),
setScale
(
scale
,
center
)
{
onScale
(
e
)
{
this
.
scale
=
Math
.
min
(
Math
.
max
(
scale
,
this
.
scaleMin
),
this
.
scaleMax
);
// 假设最大缩放为10
this
.
scale
=
e
.
detail
.
scale
this
.
lastScale
=
this
.
scale
;
this
.
$emit
(
'scale'
,
e
.
detail
)
this
.
$emit
(
'scale'
,
{
scale
:
this
.
scale
})
// 更新transform-origin以使缩放围绕两指中心进行
if
(
center
)
this
.
transformOriginStyle
=
`
${
center
.
x
}
px
${
center
.
y
}
px`
;
this
.
updatePosition
();
},
},
getTouchCenter
(
touches
)
{
getTouchCenter
(
touches
)
{
...
@@ -111,28 +83,6 @@ export default {
...
@@ -111,28 +83,6 @@ export default {
const
centerY
=
(
touches
[
0
].
pageY
+
touches
[
1
].
pageY
)
/
2
;
const
centerY
=
(
touches
[
0
].
pageY
+
touches
[
1
].
pageY
)
/
2
;
return
{
x
:
centerX
,
y
:
centerY
};
return
{
x
:
centerX
,
y
:
centerY
};
},
},
handleTouchEnd
()
{
if
(
this
.
disabled
)
return
this
.
isScaling
=
false
;
this
.
isDragging
=
false
;
},
getTouchDistance
(
touches
)
{
const
dx
=
touches
[
1
].
pageX
-
touches
[
0
].
pageX
;
const
dy
=
touches
[
1
].
pageY
-
touches
[
0
].
pageY
;
return
Math
.
sqrt
(
dx
*
dx
+
dy
*
dy
);
},
async
updatePosition
()
{
// 更新位置并确保内容不超出容器
// 注意:此处需根据实际容器大小和内容尺寸进行调整
this
.
transformStyle
=
`translate(
${
this
.
moveX
}
px,
${
this
.
moveY
}
px) scale(
${
this
.
scale
}
)`
;
},
getQueryInfo
(
el
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
createSelectorQuery
().
in
(
this
).
select
(
el
).
boundingClientRect
(
data
=>
{
resolve
(
data
)
}).
exec
()
})
}
},
},
};
};
</
script
>
</
script
>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment