如题
要做一个可以在范围内随意拖动 旋转 缩放的 APP
然后还要提供文本和图文的编辑功能
所以想做成组件的形式
通过传入的数组来生成不同的内容在范围中移动
最后就出现这样的情况了
- 发布:2021-01-29 16:07
- 更新:2021-01-29 16:39
- 阅读:823
1***@163.com (作者) - 不会前端的后端不是好运维
uni-painter.vue 和 css
<template>
<view class="uni-painter-container">
<movable-area class="movable-area">
<movable-view style="width: 20px;height: 20px;background-color: #2C405A;" direction="all"></movable-view>
<block v-for="(item , index) in painterData" :key="index">
<block v-if="item.type == 'text'">
<uni-painter-text :objData="item"></uni-painter-text>
</block>
</block>
</movable-area>
</view>
</template>
<script>
import uniPainterText from "@/components/uni-painter-text/uni-painter-text"
export default {
components:{
uniPainterText
},
props:{
painterData:{
type:Array,
default:[]
}
},
onReady() {
const query = uni.createSelectorQuery();
query.select('movable-area').boundingClientRect(data=>{
console.log(data);
})
},
data() {
return {
}
},
methods: {
}
}
</script>
<style>
@import "./css/uni-painter.css";
</style>
.uni-painter-container{
width: 50vw;
height: 50vh;
background-color: #FFF;
border-radius: 10px;
}
.movable-area {
width: 50vw;
height: 50vh;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
position: relative;
}
.text-content{
width: auto;
height: auto;
border: #2C405A 1px solid;
}
1***@163.com (作者) - 不会前端的后端不是好运维
uni-painter-text.vue 和 css
<template>
<movable-view :out-of-bounds="false" class="uni-painter-text-container" :x="x" :y="y" direction="all" @change="move">
{{objData.data}}
</movable-view>
</template>
<script>
export default {
props:{
objData:{
type:Object,
default:{}
}
},
created() {
this.x = this.objData.x
this.y = this.objData.y
},
data() {
return {
x:0,
y:0,
};
},
methods:{
move(event){
},
}
}
</script>
<style>
@import "./css/uni-painter-text.css";
</style>
.uni-painter-text-container {
width: auto;
height: auto;
background-color: #4CD964;
}