当前位置: 首页> 科技> 数码 > 嘉定网站建设_网页设计师招聘条件_seo技术分享免费咨询_互联网项目推广

嘉定网站建设_网页设计师招聘条件_seo技术分享免费咨询_互联网项目推广

时间:2025/7/9 16:52:44来源:https://blog.csdn.net/weixin_43848576/article/details/144513318 浏览次数:0次
嘉定网站建设_网页设计师招聘条件_seo技术分享免费咨询_互联网项目推广

在这里插入图片描述

装包

"vue-cropper": "0.5.5",

裁剪组件 CutImg.vue

<template><div><div class="user-info-head" @click="editCropper()"><imgv-if="options.img"v-bind:src="options.img"title="点击上传"style="width: 210px;height: 120px;border: 1px solid #ccc;border-radius: 4px;"/><divv-elsestyle="width: 210px;height: 120px;border: 1px solid #ccc;border-radius: 4px;"class="center"><i class="el-icon-plus avatar-uploader-icon"></i><div>点击上传</div></div></div><el-dialog:title="title":visible.sync="open"width="1400px"append-to-body@opened="modalOpened"@close="closeDialog"><el-row><el-col :span="24" :style="{ height: '750px' }"><vue-cropperref="cropper":img="options.img":info="true":autoCrop="options.autoCrop":autoCropWidth="options.autoCropWidth":autoCropHeight="options.autoCropHeight":fixedBox="options.fixedBox":outputType="options.outputType"@realTime="realTime"v-if="visible"/></el-col><!-- <el-col :span="4" :style="{ height: '350px' }"><div class="avatar-upload-preview"><img :src="previews.url" :style="previews.img" /></div></el-col> --></el-row><br /><el-row><el-col :lg="2" :sm="3" :xs="3"><el-uploadaction="#":http-request="requestUpload":show-file-list="false":before-upload="beforeUpload"><el-button size="small">选择<i class="el-icon-upload el-icon--right"></i></el-button></el-upload></el-col><el-col :lg="{ span: 1, offset: 2 }" :sm="2" :xs="2"><el-buttonicon="el-icon-plus"size="small"@click="changeScale(1)"></el-button></el-col><el-col :lg="{ span: 1, offset: 1 }" :sm="2" :xs="2"><el-buttonicon="el-icon-minus"size="small"@click="changeScale(-1)"></el-button></el-col><el-col :lg="{ span: 1, offset: 1 }" :sm="2" :xs="2"><el-buttonicon="el-icon-refresh-left"size="small"@click="rotateLeft()"></el-button></el-col><el-col :lg="{ span: 1, offset: 1 }" :sm="2" :xs="2"><el-buttonicon="el-icon-refresh-right"size="small"@click="rotateRight()"></el-button></el-col><el-col :lg="{ span: 2, offset: 6 }" :sm="2" :xs="2"><el-button type="primary" size="small" @click="uploadImg()">提 交</el-button></el-col></el-row></el-dialog></div>
</template><script>
import { VueCropper } from "vue-cropper";
import { uploadImg } from "@/api/system/user";
import { debounce } from "@/utils";export default {components: { VueCropper },props: ["url"],data() {return {// 是否显示弹出层open: false,// 是否显示croppervisible: false,// 弹出层标题title: "剪裁单位图纸",options: {img: "", //裁剪图片的地址autoCrop: true, // 是否默认生成截图框autoCropWidth: 1225, // 默认生成截图框宽度autoCropHeight: 700, // 默认生成截图框高度fixedBox: true, // 固定截图框大小 不允许改变outputType: "png", // 默认生成截图为PNG格式filename: "avatar", // 文件名称},previews: {},resizeHandler: null,};},watch: {url: {handler(val) {if (val) {this.options.img = process.env.VUE_APP_BASE_API + val;} else {this.options.img = "";}},immediate: true,},},methods: {// 编辑头像editCropper() {this.open = true;},// 打开弹出层结束时的回调modalOpened() {this.visible = true;if (!this.resizeHandler) {this.resizeHandler = debounce(() => {this.refresh();}, 100);}window.addEventListener("resize", this.resizeHandler);},// 刷新组件refresh() {this.$refs.cropper.refresh();},// 覆盖默认的上传行为requestUpload() {},// 向左旋转rotateLeft() {this.$refs.cropper.rotateLeft();},// 向右旋转rotateRight() {this.$refs.cropper.rotateRight();},// 图片缩放changeScale(num) {num = num || 1;this.$refs.cropper.changeScale(num);},// 上传预处理beforeUpload(file) {if (file.type.indexOf("image/") == -1) {this.$modal.msgError("文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。");} else {const reader = new FileReader();reader.readAsDataURL(file);reader.onload = () => {this.options.img = reader.result;this.options.filename = file.name;};}},// 上传图片uploadImg() {this.$refs.cropper.getCropBlob((data) => {let formData = new FormData();formData.append("file", data);uploadImg(formData).then((response) => {this.open = false;this.options.img = process.env.VUE_APP_BASE_API + response.fileName;this.visible = false;this.$emit("update", response.fileName);});});},// 实时预览realTime(data) {this.previews = data;},// 关闭窗口closeDialog() {this.visible = false;window.removeEventListener("resize", this.resizeHandler);},},
};
</script>
<style scoped lang="scss">
.user-info-head {position: relative;display: inline-block;height: 120px;
}
::v-deep .el-dialog .el-dialog__body {padding: 0 20px 20px 20px !important;
}
::v-deep .el-dialog:not(.is-fullscreen) {margin-top: 2vh !important;
}
.user-info-head:hover:after {content: "+";text-align: center;position: absolute;left: 0;right: 0;top: 0;bottom: 0;color: #eee;background: rgba(0, 0, 0, 0.5);font-size: 24px;font-style: normal;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;cursor: pointer;height: 120px;line-height: 120px;// border-radius: 50%;
}
</style>

工具方法 debounce

/*** @param {Function} func* @param {number} wait* @param {boolean} immediate* @return {*}*/
export function debounce(func, wait, immediate) {let timeout, args, context, timestamp, resultconst later = function () {// 据上一次触发时间间隔const last = +new Date() - timestamp// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 waitif (last < wait && last > 0) {timeout = setTimeout(later, wait - last)} else {timeout = null// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用if (!immediate) {result = func.apply(context, args)if (!timeout) context = args = null}}}return function (...args) {context = thistimestamp = +new Date()const callNow = immediate && !timeout// 如果延时不存在,重新设定延时if (!timeout) timeout = setTimeout(later, wait)if (callNow) {result = func.apply(context, args)context = args = null}return result}
}

注册组件

// 裁剪图片组件
import CutImg from "@/components/ququ/CutImg"
Vue.component('CutImg', CutImg)

新增弹窗使用组件

在这里插入图片描述

  <!-- 添加或修改预案推演对话框 --><el-dialog :title="title" :visible.sync="open" width="500px" append-to-body><el-form ref="form" :model="form" :rules="rules" label-width="80px"><el-form-item label="预案名称" prop="planName"><el-inputv-model="form.planName"placeholder="请输入预案名称"maxlength="50"/></el-form-item><el-form-item label="单位名称" prop="unitName"><el-inputv-model="form.unitName"placeholder="请输入单位名称"maxlength="50"/></el-form-item><el-form-item label="单位图纸" prop="planImage"><!-- <ImageUpload v-model="form.planImage" :limit="1" :fileSize="10" /> --><CutImg :url="form.planImage" @update="handleUpload"></CutImg></el-form-item><el-form-item label="备注" prop="remark"><el-inputv-model="form.remark"type="textarea"placeholder="请输入内容"maxlength="200"/></el-form-item></el-form><div slot="footer" class="dialog-footer"><el-button type="primary" @click="submitForm">确 定</el-button><el-button @click="cancel">取 消</el-button></div></el-dialog>handleUpload(file) {this.form.planImage = file;},
关键字:嘉定网站建设_网页设计师招聘条件_seo技术分享免费咨询_互联网项目推广

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: