Commit 9fa77b62 by hank

图片裁剪功能

parent 5ca77b73
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
"vant": "^2.0.0", "vant": "^2.0.0",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-awesome-swiper": "^3.1.3", "vue-awesome-swiper": "^3.1.3",
"vue-cropper": "^0.4.9",
"vue-router": "^3.0.3", "vue-router": "^3.0.3",
"vuedraggable": "^2.23.0", "vuedraggable": "^2.23.0",
"vuex": "^3.0.1" "vuex": "^3.0.1"
......
...@@ -107,6 +107,20 @@ ...@@ -107,6 +107,20 @@
@changeSelcetData="changeSelcetData" @changeSelcetData="changeSelcetData"
v-if="selectData.show" v-if="selectData.show"
></selectDataCom> ></selectDataCom>
<div class="cropper-container" v-show="VueCropperOption.img">
<vueCropper
ref="cropper"
:img="VueCropperOption.img"
:canMove="false"
:autoCrop="VueCropperOption.autoCrop"
:outputType="VueCropperOption.outputType"
></vueCropper>
<img :src="VueCropperOption.preImg" alt />
<div class>
<van-button @click="VueCropperOption.img = ''">取消</van-button>
<van-button @click="saveCropper">保存</van-button>
</div>
</div>
</div> </div>
</template> </template>
...@@ -114,6 +128,8 @@ ...@@ -114,6 +128,8 @@
import { upload } from "@/api/api"; import { upload } from "@/api/api";
import { getHostUrl } from "@/utils/index"; import { getHostUrl } from "@/utils/index";
import selectDataCom from "./selectData"; import selectDataCom from "./selectData";
import { VueCropper } from "vue-cropper";
export default { export default {
name: "editMenu", name: "editMenu",
props: { props: {
...@@ -135,7 +151,8 @@ export default { ...@@ -135,7 +151,8 @@ export default {
} }
}, },
components: { components: {
selectDataCom selectDataCom,
VueCropper
}, },
created() { created() {
console.log(this.schemaData); console.log(this.schemaData);
...@@ -148,6 +165,12 @@ export default { ...@@ -148,6 +165,12 @@ export default {
itemKey: "", itemKey: "",
selectData: { selectData: {
show: false show: false
},
VueCropperOption: {
img: "",
outputType: "png",
autoCrop: true,
preImg: ""
} }
}; };
}, },
...@@ -182,7 +205,7 @@ export default { ...@@ -182,7 +205,7 @@ export default {
obj[item] = ""; obj[item] = "";
}); });
this.schemaData[item.dataKey].push(obj); this.schemaData[item.dataKey].push(obj);
console.log(obj) console.log(obj);
} else { } else {
alert("选择类型添加,敬请期待!"); alert("选择类型添加,敬请期待!");
} }
...@@ -192,6 +215,16 @@ export default { ...@@ -192,6 +215,16 @@ export default {
return getHostUrl(this.frameUrl, dataUrl); return getHostUrl(this.frameUrl, dataUrl);
}, },
uploadAfter(file) { uploadAfter(file) {
// console.log(file);
// this.VueCropperOption.img = file.content;
// setTimeout(() => {
// this.$refs.cropper.getCropData(data => {
// // do something
// this.VueCropperOption.preImg = data;
// console.log(data);
// });
// }, 3000);
this.$toast.loading({ this.$toast.loading({
mask: true, mask: true,
duration: 0, duration: 0,
...@@ -229,6 +262,13 @@ export default { ...@@ -229,6 +262,13 @@ export default {
arr.splice(index, 1); arr.splice(index, 1);
this.$emit("setList", this.schemaData); this.$emit("setList", this.schemaData);
}, },
saveCropper() {
this.$refs.cropper.getCropData(data => {
// do something
this.VueCropperOption.preImg = data;
console.log(data);
});
},
setSelectData(item, index) { setSelectData(item, index) {
const myItem = JSON.parse(JSON.stringify(item)); const myItem = JSON.parse(JSON.stringify(item));
this.selectData.show = true; this.selectData.show = true;
...@@ -256,6 +296,19 @@ export default { ...@@ -256,6 +296,19 @@ export default {
.menu-container { .menu-container {
height: calc(100vh - 570px); height: calc(100vh - 570px);
padding: 15px; padding: 15px;
.cropper-container {
.vue-cropper {
height: 50vh;
}
overflow: auto;
top: 0;
left: 0;
width: 100%;
position: fixed;
height: 100%;
z-index: 100000;
}
.image { .image {
height: 50px; height: 50px;
} }
......
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 sign in to comment