| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219 |
- import { defineComponent as D, openBlock as W, createElementBlock as I, withDirectives as T, createElementVNode as x, normalizeStyle as H, vShow as N, createCommentVNode as k, normalizeClass as F, toDisplayString as S, ref as C, resolveComponent as q, createBlock as V, withCtx as X, createVNode as M, unref as j, createTextVNode as $ } from "vue";
- import { n as Q, B as Z } from "./index2.js";
- import { _ as G, a as J } from "./index10.js";
- const A = {};
- A.getData = (t) => new Promise((e, s) => {
- let i = {};
- K(t).then((h) => {
- i.arrayBuffer = h;
- try {
- i.orientation = it(h);
- } catch (r) {
- i.orientation = -1;
- }
- e(i);
- }).catch((h) => {
- s(h);
- });
- });
- function K(t) {
- let e = null;
- return new Promise((s, i) => {
- if (t.src)
- if (/^data\:/i.test(t.src))
- e = et(t.src), s(e);
- else if (/^blob\:/i.test(t.src)) {
- var h = new FileReader();
- h.onload = function(o) {
- e = o.target.result, s(e);
- }, tt(t.src, function(o) {
- h.readAsArrayBuffer(o);
- });
- } else {
- var r = new XMLHttpRequest();
- r.onload = function() {
- if (this.status == 200 || this.status === 0)
- e = r.response, s(e);
- else
- throw "Could not load image";
- r = null;
- }, r.open("GET", t.src, !0), r.responseType = "arraybuffer", r.send(null);
- }
- else
- i("img error");
- });
- }
- function tt(t, e) {
- var s = new XMLHttpRequest();
- s.open("GET", t, !0), s.responseType = "blob", s.onload = function(i) {
- (this.status == 200 || this.status === 0) && e(this.response);
- }, s.send();
- }
- function et(t, e) {
- e = e || t.match(/^data\:([^\;]+)\;base64,/mi)[1] || "", t = t.replace(/^data\:([^\;]+)\;base64,/gmi, "");
- for (var s = atob(t), i = s.length % 2 == 0 ? s.length : s.length + 1, h = new ArrayBuffer(i), r = new Uint16Array(h), o = 0; o < i; o++)
- r[o] = s.charCodeAt(o);
- return h;
- }
- function st(t, e, s) {
- var i = "", h;
- for (h = e, s += e; h < s; h++)
- i += String.fromCharCode(t.getUint8(h));
- return i;
- }
- function it(t) {
- var e = new DataView(t), s = e.byteLength, i, h, r, o, a, c, n, l, u, p;
- if (e.getUint8(0) === 255 && e.getUint8(1) === 216)
- for (u = 2; u < s; ) {
- if (e.getUint8(u) === 255 && e.getUint8(u + 1) === 225) {
- n = u;
- break;
- }
- u++;
- }
- if (n && (h = n + 4, r = n + 10, st(e, h, 4) === "Exif" && (c = e.getUint16(r), a = c === 18761, (a || c === 19789) && e.getUint16(r + 2, a) === 42 && (o = e.getUint32(r + 4, a), o >= 8 && (l = r + o)))), l) {
- for (s = e.getUint16(l, a), p = 0; p < s; p++)
- if (u = l + p * 12 + 2, e.getUint16(u, a) === 274) {
- u += 8, i = e.getUint16(u, a);
- break;
- }
- }
- return i;
- }
- const ht = (t, e) => {
- const s = t.__vccOpts || t;
- for (const [i, h] of e)
- s[i] = h;
- return s;
- }, rt = D({
- data: function() {
- return {
- // 容器高宽
- w: 0,
- h: 0,
- // 图片缩放比例
- scale: 1,
- // 图片偏移x轴
- x: 0,
- // 图片偏移y轴
- y: 0,
- // 图片加载
- loading: !0,
- // 图片真实宽度
- trueWidth: 0,
- // 图片真实高度
- trueHeight: 0,
- move: !0,
- // 移动的x
- moveX: 0,
- // 移动的y
- moveY: 0,
- // 开启截图
- crop: !1,
- // 正在截图
- cropping: !1,
- // 裁剪框大小
- cropW: 0,
- cropH: 0,
- cropOldW: 0,
- cropOldH: 0,
- // 判断是否能够改变
- canChangeX: !1,
- canChangeY: !1,
- // 改变的基准点
- changeCropTypeX: 1,
- changeCropTypeY: 1,
- // 裁剪框的坐标轴
- cropX: 0,
- cropY: 0,
- cropChangeX: 0,
- cropChangeY: 0,
- cropOffsertX: 0,
- cropOffsertY: 0,
- // 支持的滚动事件
- support: "",
- // 移动端手指缩放
- touches: [],
- touchNow: !1,
- // 图片旋转
- rotate: 0,
- isIos: !1,
- orientation: 0,
- imgs: "",
- // 图片缩放系数
- coe: 0.2,
- // 是否正在多次缩放
- scaling: !1,
- scalingSet: "",
- coeStatus: "",
- // 控制emit触发频率
- isCanShow: !0,
- // 图片是否等于截图大小
- imgIsQqualCrop: !1
- };
- },
- props: {
- img: {
- type: [String, Blob, null, File],
- default: ""
- },
- // 输出图片压缩比
- outputSize: {
- type: Number,
- default: 1
- },
- outputType: {
- type: String,
- default: "jpeg"
- },
- info: {
- type: Boolean,
- default: !0
- },
- // 是否开启滚轮放大缩小
- canScale: {
- type: Boolean,
- default: !0
- },
- // 是否自成截图框
- autoCrop: {
- type: Boolean,
- default: !1
- },
- autoCropWidth: {
- type: [Number, String],
- default: 0
- },
- autoCropHeight: {
- type: [Number, String],
- default: 0
- },
- // 是否开启固定宽高比
- fixed: {
- type: Boolean,
- default: !1
- },
- // 宽高比 w/h
- fixedNumber: {
- type: Array,
- default: () => [1, 1]
- },
- // 固定大小 禁止改变截图框大小
- fixedBox: {
- type: Boolean,
- default: !1
- },
- // 输出截图是否缩放
- full: {
- type: Boolean,
- default: !1
- },
- // 是否可以拖动图片
- canMove: {
- type: Boolean,
- default: !0
- },
- // 是否可以拖动截图框
- canMoveBox: {
- type: Boolean,
- default: !0
- },
- // 上传图片按照原始比例显示
- original: {
- type: Boolean,
- default: !1
- },
- // 截图框能否超过图片
- centerBox: {
- type: Boolean,
- default: !1
- },
- // 是否根据dpr输出高清图片
- high: {
- type: Boolean,
- default: !0
- },
- // 截图框展示宽高类型
- infoTrue: {
- type: Boolean,
- default: !1
- },
- // 可以压缩图片宽高 默认不超过200
- maxImgSize: {
- type: [Number, String],
- default: 2e3
- },
- // 倍数 可渲染当前截图框的n倍 0 - 1000;
- enlarge: {
- type: [Number, String],
- default: 1
- },
- // 自动预览的固定宽度
- preW: {
- type: [Number, String],
- default: 0
- },
- /*
- 图片布局方式 mode 实现和css背景一样的效果
- contain 居中布局 默认不会缩放 保证图片在容器里面 mode: 'contain'
- cover 拉伸布局 填充整个容器 mode: 'cover'
- 如果仅有一个数值被给定,这个数值将作为宽度值大小,高度值将被设定为auto。 mode: '50px'
- 如果有两个数值被给定,第一个将作为宽度值大小,第二个作为高度值大小。 mode: '50px 60px'
- */
- mode: {
- type: String,
- default: "contain"
- },
- //限制最小区域,可传1以上的数字和字符串,限制长宽都是这么大
- // 也可以传数组[90,90]
- limitMinSize: {
- type: [Number, Array, String],
- default: () => 10,
- validator: function(t) {
- return Array.isArray(t) ? Number(t[0]) >= 0 && Number(t[1]) >= 0 : Number(t) >= 0;
- }
- },
- // 导出时,填充背景颜色
- fillColor: {
- type: String,
- default: ""
- }
- },
- computed: {
- cropInfo() {
- let t = {};
- if (t.top = this.cropOffsertY > 21 ? "-21px" : "0px", t.width = this.cropW > 0 ? this.cropW : 0, t.height = this.cropH > 0 ? this.cropH : 0, this.infoTrue) {
- let e = 1;
- this.high && !this.full && (e = window.devicePixelRatio), this.enlarge !== 1 & !this.full && (e = Math.abs(Number(this.enlarge))), t.width = t.width * e, t.height = t.height * e, this.full && (t.width = t.width / this.scale, t.height = t.height / this.scale);
- }
- return t.width = t.width.toFixed(0), t.height = t.height.toFixed(0), t;
- },
- isIE() {
- return !!window.ActiveXObject || "ActiveXObject" in window;
- },
- passive() {
- return this.isIE ? null : {
- passive: !1
- };
- },
- // 是否处于左右旋转
- isRotateRightOrLeft() {
- return [1, -1, 3, -3].includes(this.rotate);
- }
- },
- watch: {
- // 如果图片改变, 重新布局
- img() {
- this.checkedImg();
- },
- imgs(t) {
- t !== "" && this.reload();
- },
- cropW() {
- this.showPreview();
- },
- cropH() {
- this.showPreview();
- },
- cropOffsertX() {
- this.showPreview();
- },
- cropOffsertY() {
- this.showPreview();
- },
- scale(t, e) {
- this.showPreview();
- },
- x() {
- this.showPreview();
- },
- y() {
- this.showPreview();
- },
- autoCrop(t) {
- t && this.goAutoCrop();
- },
- // 修改了自动截图框
- autoCropWidth() {
- this.autoCrop && this.goAutoCrop();
- },
- autoCropHeight() {
- this.autoCrop && this.goAutoCrop();
- },
- mode() {
- this.checkedImg();
- },
- rotate() {
- this.showPreview(), this.autoCrop ? this.goAutoCrop(this.cropW, this.cropH) : (this.cropW > 0 || this.cropH > 0) && this.goAutoCrop(this.cropW, this.cropH);
- }
- },
- methods: {
- getVersion(t) {
- var e = navigator.userAgent.split(" "), s = "";
- let i = 0;
- const h = new RegExp(t, "i");
- for (var r = 0; r < e.length; r++)
- h.test(e[r]) && (s = e[r]);
- return s ? i = s.split("/")[1].split(".") : i = ["0", "0", "0"], i;
- },
- checkOrientationImage(t, e, s, i) {
- if (this.getVersion("chrome")[0] >= 81)
- e = -1;
- else if (this.getVersion("safari")[0] >= 605) {
- const o = this.getVersion("version");
- o[0] > 13 && o[1] > 1 && (e = -1);
- } else {
- const o = navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?) like mac os/);
- if (o) {
- let a = o[1];
- a = a.split("_"), (a[0] > 13 || a[0] >= 13 && a[1] >= 4) && (e = -1);
- }
- }
- let h = document.createElement("canvas"), r = h.getContext("2d");
- switch (r.save(), e) {
- case 2:
- h.width = s, h.height = i, r.translate(s, 0), r.scale(-1, 1);
- break;
- case 3:
- h.width = s, h.height = i, r.translate(s / 2, i / 2), r.rotate(180 * Math.PI / 180), r.translate(-s / 2, -i / 2);
- break;
- case 4:
- h.width = s, h.height = i, r.translate(0, i), r.scale(1, -1);
- break;
- case 5:
- h.height = s, h.width = i, r.rotate(0.5 * Math.PI), r.scale(1, -1);
- break;
- case 6:
- h.width = i, h.height = s, r.translate(i / 2, s / 2), r.rotate(90 * Math.PI / 180), r.translate(-s / 2, -i / 2);
- break;
- case 7:
- h.height = s, h.width = i, r.rotate(0.5 * Math.PI), r.translate(s, -i), r.scale(-1, 1);
- break;
- case 8:
- h.height = s, h.width = i, r.translate(i / 2, s / 2), r.rotate(-90 * Math.PI / 180), r.translate(-s / 2, -i / 2);
- break;
- default:
- h.width = s, h.height = i;
- }
- r.drawImage(t, 0, 0, s, i), r.restore(), h.toBlob(
- (o) => {
- let a = URL.createObjectURL(o);
- URL.revokeObjectURL(this.imgs), this.imgs = a;
- },
- "image/" + this.outputType,
- 1
- );
- },
- // checkout img
- checkedImg() {
- if (this.img === null || this.img === "") {
- this.imgs = "", this.clearCrop();
- return;
- }
- this.loading = !0, this.scale = 1, this.rotate = 0, this.imgIsQqualCrop = !1, this.clearCrop();
- let t = new Image();
- if (t.onload = () => {
- if (this.img === "")
- return this.$emit("img-load", new Error("图片不能为空")), !1;
- let s = t.width, i = t.height;
- A.getData(t).then((h) => {
- this.orientation = h.orientation || 1;
- let r = Number(this.maxImgSize);
- if (!this.orientation && s < r & i < r) {
- this.imgs = this.img;
- return;
- }
- s > r && (i = i / s * r, s = r), i > r && (s = s / i * r, i = r), this.checkOrientationImage(t, this.orientation, s, i);
- }).catch((h) => {
- this.$emit("img-load", "error"), this.$emit("img-load-error", h);
- });
- }, t.onerror = (s) => {
- this.$emit("img-load", "error"), this.$emit("img-load-error", s);
- }, this.img.substr(0, 4) !== "data" && (t.crossOrigin = ""), this.isIE) {
- var e = new XMLHttpRequest();
- e.onload = function() {
- var s = URL.createObjectURL(this.response);
- t.src = s;
- }, e.open("GET", this.img, !0), e.responseType = "blob", e.send();
- } else
- t.src = this.img;
- },
- // 当按下鼠标键
- startMove(t) {
- if (t.preventDefault(), this.move && !this.crop) {
- if (!this.canMove)
- return !1;
- this.moveX = ("clientX" in t ? t.clientX : t.touches[0].clientX) - this.x, this.moveY = ("clientY" in t ? t.clientY : t.touches[0].clientY) - this.y, t.touches ? (window.addEventListener("touchmove", this.moveImg), window.addEventListener("touchend", this.leaveImg), t.touches.length == 2 && (this.touches = t.touches, window.addEventListener("touchmove", this.touchScale), window.addEventListener("touchend", this.cancelTouchScale))) : (window.addEventListener("mousemove", this.moveImg), window.addEventListener("mouseup", this.leaveImg)), this.$emit("img-moving", {
- moving: !0,
- axis: this.getImgAxis()
- });
- } else
- this.cropping = !0, window.addEventListener("mousemove", this.createCrop), window.addEventListener("mouseup", this.endCrop), window.addEventListener("touchmove", this.createCrop), window.addEventListener("touchend", this.endCrop), this.cropOffsertX = t.offsetX ? t.offsetX : t.touches[0].pageX - this.$refs.cropper.offsetLeft, this.cropOffsertY = t.offsetY ? t.offsetY : t.touches[0].pageY - this.$refs.cropper.offsetTop, this.cropX = "clientX" in t ? t.clientX : t.touches[0].clientX, this.cropY = "clientY" in t ? t.clientY : t.touches[0].clientY, this.cropChangeX = this.cropOffsertX, this.cropChangeY = this.cropOffsertY, this.cropW = 0, this.cropH = 0;
- },
- // 移动端缩放
- touchScale(t) {
- t.preventDefault();
- let e = this.scale;
- var s = {
- x: this.touches[0].clientX,
- y: this.touches[0].clientY
- }, i = {
- x: t.touches[0].clientX,
- y: t.touches[0].clientY
- }, h = {
- x: this.touches[1].clientX,
- y: this.touches[1].clientY
- }, r = {
- x: t.touches[1].clientX,
- y: t.touches[1].clientY
- }, o = Math.sqrt(
- Math.pow(s.x - h.x, 2) + Math.pow(s.y - h.y, 2)
- ), a = Math.sqrt(
- Math.pow(i.x - r.x, 2) + Math.pow(i.y - r.y, 2)
- ), c = a - o, n = 1;
- n = n / this.trueWidth > n / this.trueHeight ? n / this.trueHeight : n / this.trueWidth, n = n > 0.1 ? 0.1 : n;
- var l = n * c;
- if (!this.touchNow) {
- if (this.touchNow = !0, c > 0 ? e += Math.abs(l) : c < 0 && e > Math.abs(l) && (e -= Math.abs(l)), this.touches = t.touches, setTimeout(() => {
- this.touchNow = !1;
- }, 8), !this.checkoutImgAxis(this.x, this.y, e))
- return !1;
- this.scale = e;
- }
- },
- cancelTouchScale(t) {
- window.removeEventListener("touchmove", this.touchScale);
- },
- // 移动图片
- moveImg(t) {
- if (t.preventDefault(), t.touches && t.touches.length === 2)
- return this.touches = t.touches, window.addEventListener("touchmove", this.touchScale), window.addEventListener("touchend", this.cancelTouchScale), window.removeEventListener("touchmove", this.moveImg), !1;
- let e = "clientX" in t ? t.clientX : t.touches[0].clientX, s = "clientY" in t ? t.clientY : t.touches[0].clientY, i, h;
- i = e - this.moveX, h = s - this.moveY, this.$nextTick(() => {
- if (this.centerBox) {
- let r = this.getImgAxis(i, h, this.scale), o = this.getCropAxis(), a = this.trueHeight * this.scale, c = this.trueWidth * this.scale, n, l, u, p;
- switch (this.rotate) {
- case 1:
- case -1:
- case 3:
- case -3:
- n = this.cropOffsertX - this.trueWidth * (1 - this.scale) / 2 + (a - c) / 2, l = this.cropOffsertY - this.trueHeight * (1 - this.scale) / 2 + (c - a) / 2, u = n - a + this.cropW, p = l - c + this.cropH;
- break;
- default:
- n = this.cropOffsertX - this.trueWidth * (1 - this.scale) / 2, l = this.cropOffsertY - this.trueHeight * (1 - this.scale) / 2, u = n - c + this.cropW, p = l - a + this.cropH;
- break;
- }
- r.x1 >= o.x1 && (i = n), r.y1 >= o.y1 && (h = l), r.x2 <= o.x2 && (i = u), r.y2 <= o.y2 && (h = p);
- }
- this.x = i, this.y = h, this.$emit("img-moving", {
- moving: !0,
- axis: this.getImgAxis()
- });
- });
- },
- // 移动图片结束
- leaveImg(t) {
- window.removeEventListener("mousemove", this.moveImg), window.removeEventListener("touchmove", this.moveImg), window.removeEventListener("mouseup", this.leaveImg), window.removeEventListener("touchend", this.leaveImg), this.$emit("img-moving", {
- moving: !1,
- axis: this.getImgAxis()
- });
- },
- // 缩放图片
- scaleImg() {
- this.canScale && window.addEventListener(this.support, this.changeSize, this.passive);
- },
- // 移出框
- cancelScale() {
- this.canScale && window.removeEventListener(this.support, this.changeSize);
- },
- // 改变大小函数
- changeSize(t) {
- t.preventDefault();
- let e = this.scale;
- var s = t.deltaY || t.wheelDelta, i = navigator.userAgent.indexOf("Firefox");
- s = i > 0 ? s * 30 : s, this.isIE && (s = -s);
- var h = this.coe;
- h = h / this.trueWidth > h / this.trueHeight ? h / this.trueHeight : h / this.trueWidth;
- var r = h * s;
- r < 0 ? e += Math.abs(r) : e > Math.abs(r) && (e -= Math.abs(r));
- let o = r < 0 ? "add" : "reduce";
- if (o !== this.coeStatus && (this.coeStatus = o, this.coe = 0.2), this.scaling || (this.scalingSet = setTimeout(() => {
- this.scaling = !1, this.coe = this.coe += 0.01;
- }, 50)), this.scaling = !0, !this.checkoutImgAxis(this.x, this.y, e))
- return !1;
- this.scale = e;
- },
- // 修改图片大小函数
- changeScale(t) {
- let e = this.scale;
- t = t || 1;
- var s = 20;
- if (s = s / this.trueWidth > s / this.trueHeight ? s / this.trueHeight : s / this.trueWidth, t = t * s, t > 0 ? e += Math.abs(t) : e > Math.abs(t) && (e -= Math.abs(t)), !this.checkoutImgAxis(this.x, this.y, e))
- return !1;
- this.scale = e;
- },
- // 创建截图框
- createCrop(t) {
- t.preventDefault();
- var e = "clientX" in t ? t.clientX : t.touches ? t.touches[0].clientX : 0, s = "clientY" in t ? t.clientY : t.touches ? t.touches[0].clientY : 0;
- this.$nextTick(() => {
- var i = e - this.cropX, h = s - this.cropY;
- if (i > 0 ? (this.cropW = i + this.cropChangeX > this.w ? this.w - this.cropChangeX : i, this.cropOffsertX = this.cropChangeX) : (this.cropW = this.w - this.cropChangeX + Math.abs(i) > this.w ? this.cropChangeX : Math.abs(i), this.cropOffsertX = this.cropChangeX + i > 0 ? this.cropChangeX + i : 0), !this.fixed)
- h > 0 ? (this.cropH = h + this.cropChangeY > this.h ? this.h - this.cropChangeY : h, this.cropOffsertY = this.cropChangeY) : (this.cropH = this.h - this.cropChangeY + Math.abs(h) > this.h ? this.cropChangeY : Math.abs(h), this.cropOffsertY = this.cropChangeY + h > 0 ? this.cropChangeY + h : 0);
- else {
- var r = this.cropW / this.fixedNumber[0] * this.fixedNumber[1];
- r + this.cropOffsertY > this.h ? (this.cropH = this.h - this.cropOffsertY, this.cropW = this.cropH / this.fixedNumber[1] * this.fixedNumber[0], i > 0 ? this.cropOffsertX = this.cropChangeX : this.cropOffsertX = this.cropChangeX - this.cropW) : this.cropH = r, this.cropOffsertY = this.cropOffsertY;
- }
- });
- },
- // 改变截图框大小
- changeCropSize(t, e, s, i, h) {
- t.preventDefault(), window.addEventListener("mousemove", this.changeCropNow), window.addEventListener("mouseup", this.changeCropEnd), window.addEventListener("touchmove", this.changeCropNow), window.addEventListener("touchend", this.changeCropEnd), this.canChangeX = e, this.canChangeY = s, this.changeCropTypeX = i, this.changeCropTypeY = h, this.cropX = "clientX" in t ? t.clientX : t.touches[0].clientX, this.cropY = "clientY" in t ? t.clientY : t.touches[0].clientY, this.cropOldW = this.cropW, this.cropOldH = this.cropH, this.cropChangeX = this.cropOffsertX, this.cropChangeY = this.cropOffsertY, this.fixed && this.canChangeX && this.canChangeY && (this.canChangeY = 0), this.$emit("change-crop-size", {
- width: this.cropW,
- height: this.cropH
- });
- },
- // 正在改变
- changeCropNow(t) {
- t.preventDefault();
- var e = "clientX" in t ? t.clientX : t.touches ? t.touches[0].clientX : 0, s = "clientY" in t ? t.clientY : t.touches ? t.touches[0].clientY : 0;
- let i = this.w, h = this.h, r = 0, o = 0;
- if (this.centerBox) {
- let n = this.getImgAxis(), l = n.x2, u = n.y2;
- r = n.x1 > 0 ? n.x1 : 0, o = n.y1 > 0 ? n.y1 : 0, i > l && (i = l), h > u && (h = u);
- }
- const [a, c] = this.checkCropLimitSize();
- this.$nextTick(() => {
- var n = e - this.cropX, l = s - this.cropY;
- if (this.canChangeX && (this.changeCropTypeX === 1 ? this.cropOldW - n < a ? (this.cropW = a, this.cropOffsertX = this.cropOldW + this.cropChangeX - r - a) : this.cropOldW - n > 0 ? (this.cropW = i - this.cropChangeX - n <= i - r ? this.cropOldW - n : this.cropOldW + this.cropChangeX - r, this.cropOffsertX = i - this.cropChangeX - n <= i - r ? this.cropChangeX + n : r) : (this.cropW = Math.abs(n) + this.cropChangeX <= i ? Math.abs(n) - this.cropOldW : i - this.cropOldW - this.cropChangeX, this.cropOffsertX = this.cropChangeX + this.cropOldW) : this.changeCropTypeX === 2 && (this.cropOldW + n < a ? this.cropW = a : this.cropOldW + n > 0 ? (this.cropW = this.cropOldW + n + this.cropOffsertX <= i ? this.cropOldW + n : i - this.cropOffsertX, this.cropOffsertX = this.cropChangeX) : (this.cropW = i - this.cropChangeX + Math.abs(n + this.cropOldW) <= i - r ? Math.abs(n + this.cropOldW) : this.cropChangeX - r, this.cropOffsertX = i - this.cropChangeX + Math.abs(n + this.cropOldW) <= i - r ? this.cropChangeX - Math.abs(n + this.cropOldW) : r))), this.canChangeY && (this.changeCropTypeY === 1 ? this.cropOldH - l < c ? (this.cropH = c, this.cropOffsertY = this.cropOldH + this.cropChangeY - o - c) : this.cropOldH - l > 0 ? (this.cropH = h - this.cropChangeY - l <= h - o ? this.cropOldH - l : this.cropOldH + this.cropChangeY - o, this.cropOffsertY = h - this.cropChangeY - l <= h - o ? this.cropChangeY + l : o) : (this.cropH = Math.abs(l) + this.cropChangeY <= h ? Math.abs(l) - this.cropOldH : h - this.cropOldH - this.cropChangeY, this.cropOffsertY = this.cropChangeY + this.cropOldH) : this.changeCropTypeY === 2 && (this.cropOldH + l < c ? this.cropH = c : this.cropOldH + l > 0 ? (this.cropH = this.cropOldH + l + this.cropOffsertY <= h ? this.cropOldH + l : h - this.cropOffsertY, this.cropOffsertY = this.cropChangeY) : (this.cropH = h - this.cropChangeY + Math.abs(l + this.cropOldH) <= h - o ? Math.abs(l + this.cropOldH) : this.cropChangeY - o, this.cropOffsertY = h - this.cropChangeY + Math.abs(l + this.cropOldH) <= h - o ? this.cropChangeY - Math.abs(l + this.cropOldH) : o))), this.canChangeX && this.fixed) {
- var u = this.cropW / this.fixedNumber[0] * this.fixedNumber[1];
- u < c ? (this.cropH = c, this.cropW = this.fixedNumber[0] * c / this.fixedNumber[1], this.changeCropTypeX === 1 && (this.cropOffsertX = this.cropChangeX + (this.cropOldW - this.cropW))) : u + this.cropOffsertY > h ? (this.cropH = h - this.cropOffsertY, this.cropW = this.cropH / this.fixedNumber[1] * this.fixedNumber[0], this.changeCropTypeX === 1 && (this.cropOffsertX = this.cropChangeX + (this.cropOldW - this.cropW))) : this.cropH = u;
- }
- if (this.canChangeY && this.fixed) {
- var p = this.cropH / this.fixedNumber[1] * this.fixedNumber[0];
- p < a ? (this.cropW = a, this.cropH = this.fixedNumber[1] * a / this.fixedNumber[0], this.cropOffsertY = this.cropOldH + this.cropChangeY - this.cropH) : p + this.cropOffsertX > i ? (this.cropW = i - this.cropOffsertX, this.cropH = this.cropW / this.fixedNumber[0] * this.fixedNumber[1]) : this.cropW = p;
- }
- });
- },
- checkCropLimitSize() {
- let { cropW: t, cropH: e, limitMinSize: s } = this, i = new Array();
- return Array.isArray(s) ? i = s : i = [s, s], t = parseFloat(i[0]), e = parseFloat(i[1]), [t, e];
- },
- // 结束改变
- changeCropEnd(t) {
- window.removeEventListener("mousemove", this.changeCropNow), window.removeEventListener("mouseup", this.changeCropEnd), window.removeEventListener("touchmove", this.changeCropNow), window.removeEventListener("touchend", this.changeCropEnd);
- },
- // 根据比例x/y,最小宽度,最小高度,现有宽度,现有高度,得到应该有的宽度和高度
- calculateSize(t, e, s, i, h, r) {
- const o = t / e;
- let a = h, c = r;
- return a < s && (a = s, c = Math.ceil(a / o)), c < i && (c = i, a = Math.ceil(c * o), a < s && (a = s, c = Math.ceil(a / o))), a < h && (a = h, c = Math.ceil(a / o)), c < r && (c = r, a = Math.ceil(c * o)), { width: a, height: c };
- },
- // 创建完成
- endCrop() {
- this.cropW === 0 && this.cropH === 0 && (this.cropping = !1);
- let [t, e] = this.checkCropLimitSize();
- const { width: s, height: i } = this.fixed ? this.calculateSize(
- this.fixedNumber[0],
- this.fixedNumber[1],
- t,
- e,
- this.cropW,
- this.cropH
- ) : { width: t, height: e };
- s > this.cropW && (this.cropW = s, this.cropOffsertX + s > this.w && (this.cropOffsertX = this.w - s)), i > this.cropH && (this.cropH = i, this.cropOffsertY + i > this.h && (this.cropOffsertY = this.h - i)), window.removeEventListener("mousemove", this.createCrop), window.removeEventListener("mouseup", this.endCrop), window.removeEventListener("touchmove", this.createCrop), window.removeEventListener("touchend", this.endCrop);
- },
- // 开始截图
- startCrop() {
- this.crop = !0;
- },
- // 停止截图
- stopCrop() {
- this.crop = !1;
- },
- // 清除截图
- clearCrop() {
- this.cropping = !1, this.cropW = 0, this.cropH = 0;
- },
- // 截图移动
- cropMove(t) {
- if (t.preventDefault(), !this.canMoveBox)
- return this.crop = !1, this.startMove(t), !1;
- if (t.touches && t.touches.length === 2)
- return this.crop = !1, this.startMove(t), this.leaveCrop(), !1;
- window.addEventListener("mousemove", this.moveCrop), window.addEventListener("mouseup", this.leaveCrop), window.addEventListener("touchmove", this.moveCrop), window.addEventListener("touchend", this.leaveCrop);
- let e = "clientX" in t ? t.clientX : t.touches[0].clientX, s = "clientY" in t ? t.clientY : t.touches[0].clientY, i, h;
- i = e - this.cropOffsertX, h = s - this.cropOffsertY, this.cropX = i, this.cropY = h, this.$emit("crop-moving", {
- moving: !0,
- axis: this.getCropAxis()
- });
- },
- moveCrop(t, e) {
- let s = 0, i = 0;
- t && (t.preventDefault(), s = "clientX" in t ? t.clientX : t.touches[0].clientX, i = "clientY" in t ? t.clientY : t.touches[0].clientY), this.$nextTick(() => {
- let h, r, o = s - this.cropX, a = i - this.cropY;
- if (e && (o = this.cropOffsertX, a = this.cropOffsertY), o <= 0 ? h = 0 : o + this.cropW > this.w ? h = this.w - this.cropW : h = o, a <= 0 ? r = 0 : a + this.cropH > this.h ? r = this.h - this.cropH : r = a, this.centerBox) {
- let c = this.getImgAxis();
- h <= c.x1 && (h = c.x1), h + this.cropW > c.x2 && (h = c.x2 - this.cropW), r <= c.y1 && (r = c.y1), r + this.cropH > c.y2 && (r = c.y2 - this.cropH);
- }
- this.cropOffsertX = h, this.cropOffsertY = r, this.$emit("crop-moving", {
- moving: !0,
- axis: this.getCropAxis()
- });
- });
- },
- // 算出不同场景下面 图片相对于外层容器的坐标轴
- getImgAxis(t, e, s) {
- t = t || this.x, e = e || this.y, s = s || this.scale;
- let i = {
- x1: 0,
- x2: 0,
- y1: 0,
- y2: 0
- }, h = this.trueWidth * s, r = this.trueHeight * s;
- switch (this.rotate) {
- case 0:
- i.x1 = t + this.trueWidth * (1 - s) / 2, i.x2 = i.x1 + this.trueWidth * s, i.y1 = e + this.trueHeight * (1 - s) / 2, i.y2 = i.y1 + this.trueHeight * s;
- break;
- case 1:
- case -1:
- case 3:
- case -3:
- i.x1 = t + this.trueWidth * (1 - s) / 2 + (h - r) / 2, i.x2 = i.x1 + this.trueHeight * s, i.y1 = e + this.trueHeight * (1 - s) / 2 + (r - h) / 2, i.y2 = i.y1 + this.trueWidth * s;
- break;
- default:
- i.x1 = t + this.trueWidth * (1 - s) / 2, i.x2 = i.x1 + this.trueWidth * s, i.y1 = e + this.trueHeight * (1 - s) / 2, i.y2 = i.y1 + this.trueHeight * s;
- break;
- }
- return i;
- },
- // 获取截图框的坐标轴
- getCropAxis() {
- let t = {
- x1: 0,
- x2: 0,
- y1: 0,
- y2: 0
- };
- return t.x1 = this.cropOffsertX, t.x2 = t.x1 + this.cropW, t.y1 = this.cropOffsertY, t.y2 = t.y1 + this.cropH, t;
- },
- leaveCrop(t) {
- window.removeEventListener("mousemove", this.moveCrop), window.removeEventListener("mouseup", this.leaveCrop), window.removeEventListener("touchmove", this.moveCrop), window.removeEventListener("touchend", this.leaveCrop), this.$emit("crop-moving", {
- moving: !1,
- axis: this.getCropAxis()
- });
- },
- getCropChecked(t) {
- let e = document.createElement("canvas"), s = e.getContext("2d"), i = new Image(), h = this.rotate, r = this.trueWidth, o = this.trueHeight, a = this.cropOffsertX, c = this.cropOffsertY;
- i.onload = () => {
- if (this.cropW !== 0) {
- let p = 1;
- this.high & !this.full && (p = window.devicePixelRatio), this.enlarge !== 1 & !this.full && (p = Math.abs(Number(this.enlarge)));
- let f = this.cropW * p, O = this.cropH * p, d = r * this.scale * p, g = o * this.scale * p, v = (this.x - a + this.trueWidth * (1 - this.scale) / 2) * p, w = (this.y - c + this.trueHeight * (1 - this.scale) / 2) * p;
- switch (u(f, O), s.save(), h) {
- case 0:
- this.full ? (u(f / this.scale, O / this.scale), s.drawImage(
- i,
- v / this.scale,
- w / this.scale,
- d / this.scale,
- g / this.scale
- )) : s.drawImage(i, v, w, d, g);
- break;
- case 1:
- case -3:
- this.full ? (u(f / this.scale, O / this.scale), v = v / this.scale + (d / this.scale - g / this.scale) / 2, w = w / this.scale + (g / this.scale - d / this.scale) / 2, s.rotate(h * 90 * Math.PI / 180), s.drawImage(
- i,
- w,
- -v - g / this.scale,
- d / this.scale,
- g / this.scale
- )) : (v = v + (d - g) / 2, w = w + (g - d) / 2, s.rotate(h * 90 * Math.PI / 180), s.drawImage(i, w, -v - g, d, g));
- break;
- case 2:
- case -2:
- this.full ? (u(f / this.scale, O / this.scale), s.rotate(h * 90 * Math.PI / 180), v = v / this.scale, w = w / this.scale, s.drawImage(
- i,
- -v - d / this.scale,
- -w - g / this.scale,
- d / this.scale,
- g / this.scale
- )) : (s.rotate(h * 90 * Math.PI / 180), s.drawImage(i, -v - d, -w - g, d, g));
- break;
- case 3:
- case -1:
- this.full ? (u(f / this.scale, O / this.scale), v = v / this.scale + (d / this.scale - g / this.scale) / 2, w = w / this.scale + (g / this.scale - d / this.scale) / 2, s.rotate(h * 90 * Math.PI / 180), s.drawImage(
- i,
- -w - d / this.scale,
- v,
- d / this.scale,
- g / this.scale
- )) : (v = v + (d - g) / 2, w = w + (g - d) / 2, s.rotate(h * 90 * Math.PI / 180), s.drawImage(i, -w - d, v, d, g));
- break;
- default:
- this.full ? (u(f / this.scale, O / this.scale), s.drawImage(
- i,
- v / this.scale,
- w / this.scale,
- d / this.scale,
- g / this.scale
- )) : s.drawImage(i, v, w, d, g);
- }
- s.restore();
- } else {
- let p = r * this.scale, f = o * this.scale;
- switch (s.save(), h) {
- case 0:
- u(p, f), s.drawImage(i, 0, 0, p, f);
- break;
- case 1:
- case -3:
- u(f, p), s.rotate(h * 90 * Math.PI / 180), s.drawImage(i, 0, -f, p, f);
- break;
- case 2:
- case -2:
- u(p, f), s.rotate(h * 90 * Math.PI / 180), s.drawImage(i, -p, -f, p, f);
- break;
- case 3:
- case -1:
- u(f, p), s.rotate(h * 90 * Math.PI / 180), s.drawImage(i, -p, 0, p, f);
- break;
- default:
- u(p, f), s.drawImage(i, 0, 0, p, f);
- }
- s.restore();
- }
- t(e);
- };
- var n = this.img.substr(0, 4);
- n !== "data" && (i.crossOrigin = "Anonymous"), i.src = this.imgs;
- const l = this.fillColor;
- function u(p, f) {
- e.width = Math.round(p), e.height = Math.round(f), l && (s.fillStyle = l, s.fillRect(0, 0, e.width, e.height));
- }
- },
- // 获取转换成base64 的图片信息
- getCropData(t) {
- this.getCropChecked((e) => {
- t(e.toDataURL("image/" + this.outputType, this.outputSize));
- });
- },
- //canvas获取为blob对象
- getCropBlob(t) {
- this.getCropChecked((e) => {
- e.toBlob(
- (s) => t(s),
- "image/" + this.outputType,
- this.outputSize
- );
- });
- },
- // 自动预览函数
- showPreview() {
- if (this.isCanShow)
- this.isCanShow = !1, setTimeout(() => {
- this.isCanShow = !0;
- }, 16);
- else
- return !1;
- let t = this.cropW, e = this.cropH, s = this.scale;
- var i = {};
- i.div = {
- width: `${t}px`,
- height: `${e}px`
- };
- let h = (this.x - this.cropOffsertX) / s, r = (this.y - this.cropOffsertY) / s, o = 0;
- i.w = t, i.h = e, i.url = this.imgs, i.img = {
- width: `${this.trueWidth}px`,
- height: `${this.trueHeight}px`,
- transform: `scale(${s})translate3d(${h}px, ${r}px, ${o}px)rotateZ(${this.rotate * 90}deg)`
- }, i.html = `
- <div class="show-preview" style="width: ${i.w}px; height: ${i.h}px,; overflow: hidden">
- <div style="width: ${t}px; height: ${e}px">
- <img src=${i.url} style="width: ${this.trueWidth}px; height: ${this.trueHeight}px; transform:
- scale(${s})translate3d(${h}px, ${r}px, ${o}px)rotateZ(${this.rotate * 90}deg)">
- </div>
- </div>`, this.$emit("real-time", i);
- },
- // reload 图片布局函数
- reload() {
- let t = new Image();
- t.onload = () => {
- this.w = parseFloat(window.getComputedStyle(this.$refs.cropper).width), this.h = parseFloat(window.getComputedStyle(this.$refs.cropper).height), this.trueWidth = t.width, this.trueHeight = t.height, this.original ? this.scale = 1 : this.scale = this.checkedMode(), this.$nextTick(() => {
- this.x = -(this.trueWidth - this.trueWidth * this.scale) / 2 + (this.w - this.trueWidth * this.scale) / 2, this.y = -(this.trueHeight - this.trueHeight * this.scale) / 2 + (this.h - this.trueHeight * this.scale) / 2, this.loading = !1, this.autoCrop && this.goAutoCrop(), this.$emit("img-load", "success"), setTimeout(() => {
- this.showPreview();
- }, 20);
- });
- }, t.onerror = () => {
- this.$emit("img-load", "error");
- }, t.src = this.imgs;
- },
- // 背景布局的函数
- checkedMode() {
- let t = 1, e = this.trueWidth, s = this.trueHeight;
- const i = this.mode.split(" ");
- switch (i[0]) {
- case "contain":
- this.trueWidth > this.w && (t = this.w / this.trueWidth), this.trueHeight * t > this.h && (t = this.h / this.trueHeight);
- break;
- case "cover":
- e = this.w, t = e / this.trueWidth, s = s * t, s < this.h && (s = this.h, t = s / this.trueHeight);
- break;
- default:
- try {
- let h = i[0];
- if (h.search("px") !== -1) {
- h = h.replace("px", ""), e = parseFloat(h);
- const r = e / this.trueWidth;
- let o = 1, a = i[1];
- a.search("px") !== -1 && (a = a.replace("px", ""), s = parseFloat(a), o = s / this.trueHeight), t = Math.min(r, o);
- }
- if (h.search("%") !== -1 && (h = h.replace("%", ""), e = parseFloat(h) / 100 * this.w, t = e / this.trueWidth), i.length === 2 && h === "auto") {
- let r = i[1];
- r.search("px") !== -1 && (r = r.replace("px", ""), s = parseFloat(r), t = s / this.trueHeight), r.search("%") !== -1 && (r = r.replace("%", ""), s = parseFloat(r) / 100 * this.h, t = s / this.trueHeight);
- }
- } catch (h) {
- t = 1;
- }
- }
- return t;
- },
- // 自动截图函数
- goAutoCrop(t, e) {
- if (this.imgs === "" || this.imgs === null)
- return;
- this.clearCrop(), this.cropping = !0;
- let s = this.w, i = this.h;
- if (this.centerBox) {
- const o = Math.abs(this.rotate) % 2 > 0;
- let a = (o ? this.trueHeight : this.trueWidth) * this.scale, c = (o ? this.trueWidth : this.trueHeight) * this.scale;
- s = a < s ? a : s, i = c < i ? c : i;
- }
- var h = t || parseFloat(this.autoCropWidth), r = e || parseFloat(this.autoCropHeight);
- (h === 0 || r === 0) && (h = s * 0.8, r = i * 0.8), h = h > s ? s : h, r = r > i ? i : r, this.fixed && (r = h / this.fixedNumber[0] * this.fixedNumber[1]), r > this.h && (r = this.h, h = r / this.fixedNumber[1] * this.fixedNumber[0]), this.changeCrop(h, r);
- },
- // 手动改变截图框大小函数
- changeCrop(t, e) {
- if (this.centerBox) {
- let s = this.getImgAxis();
- t > s.x2 - s.x1 && (t = s.x2 - s.x1, e = t / this.fixedNumber[0] * this.fixedNumber[1]), e > s.y2 - s.y1 && (e = s.y2 - s.y1, t = e / this.fixedNumber[1] * this.fixedNumber[0]);
- }
- this.cropW = t, this.cropH = e, this.checkCropLimitSize(), this.$nextTick(() => {
- this.cropOffsertX = (this.w - this.cropW) / 2, this.cropOffsertY = (this.h - this.cropH) / 2, this.centerBox && this.moveCrop(null, !0);
- });
- },
- // 重置函数, 恢复组件置初始状态
- refresh() {
- this.img, this.imgs = "", this.scale = 1, this.crop = !1, this.rotate = 0, this.w = 0, this.h = 0, this.trueWidth = 0, this.trueHeight = 0, this.imgIsQqualCrop = !1, this.clearCrop(), this.$nextTick(() => {
- this.checkedImg();
- });
- },
- // 向左边旋转
- rotateLeft() {
- this.rotate = this.rotate <= -3 ? 0 : this.rotate - 1;
- },
- // 向右边旋转
- rotateRight() {
- this.rotate = this.rotate >= 3 ? 0 : this.rotate + 1;
- },
- // 清除旋转
- rotateClear() {
- this.rotate = 0;
- },
- // 图片坐标点校验
- checkoutImgAxis(t, e, s) {
- t = t || this.x, e = e || this.y, s = s || this.scale;
- let i = !0;
- if (this.centerBox) {
- let h = this.getImgAxis(t, e, s), r = this.getCropAxis();
- h.x1 >= r.x1 && (i = !1), h.x2 <= r.x2 && (i = !1), h.y1 >= r.y1 && (i = !1), h.y2 <= r.y2 && (i = !1), i || this.changeImgScale(h, r, s);
- }
- return i;
- },
- // 缩放图片,将图片坐标适配截图框坐标
- changeImgScale(t, e, s) {
- let i = this.trueWidth, h = this.trueHeight, r = i * s, o = h * s;
- if (r >= this.cropW && o >= this.cropH)
- this.scale = s;
- else {
- const a = this.cropW / i, c = this.cropH / h, n = this.cropH <= h * a ? a : c;
- this.scale = n, r = i * n, o = h * n;
- }
- this.imgIsQqualCrop || (t.x1 >= e.x1 && (this.isRotateRightOrLeft ? this.x = e.x1 - (i - r) / 2 - (r - o) / 2 : this.x = e.x1 - (i - r) / 2), t.x2 <= e.x2 && (this.isRotateRightOrLeft ? this.x = e.x1 - (i - r) / 2 - (r - o) / 2 - o + this.cropW : this.x = e.x2 - (i - r) / 2 - r), t.y1 >= e.y1 && (this.isRotateRightOrLeft ? this.y = e.y1 - (h - o) / 2 - (o - r) / 2 : this.y = e.y1 - (h - o) / 2), t.y2 <= e.y2 && (this.isRotateRightOrLeft ? this.y = e.y2 - (h - o) / 2 - (o - r) / 2 - r : this.y = e.y2 - (h - o) / 2 - o)), (r < this.cropW || o < this.cropH) && (this.imgIsQqualCrop = !0);
- }
- },
- mounted() {
- this.support = "onwheel" in document.createElement("div") ? "wheel" : document.onmousewheel !== void 0 ? "mousewheel" : "DOMMouseScroll";
- let t = this;
- var e = navigator.userAgent;
- this.isIOS = !!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), HTMLCanvasElement.prototype.toBlob || Object.defineProperty(HTMLCanvasElement.prototype, "toBlob", {
- value: function(s, i, h) {
- for (var r = atob(this.toDataURL(i, h).split(",")[1]), o = r.length, a = new Uint8Array(o), c = 0; c < o; c++)
- a[c] = r.charCodeAt(c);
- s(new Blob([a], { type: t.type || "image/png" }));
- }
- }), this.showPreview(), this.checkedImg();
- },
- unmounted() {
- window.removeEventListener("mousemove", this.moveCrop), window.removeEventListener("mouseup", this.leaveCrop), window.removeEventListener("touchmove", this.moveCrop), window.removeEventListener("touchend", this.leaveCrop), this.cancelScale();
- }
- }), ot = {
- key: 0,
- class: "cropper-box"
- }, at = ["src"], ct = { class: "cropper-view-box" }, nt = ["src"], lt = { key: 1 };
- function pt(t, e, s, i, h, r) {
- return W(), I("div", {
- class: "vue-cropper",
- ref: "cropper",
- onMouseover: e[28] || (e[28] = (...o) => t.scaleImg && t.scaleImg(...o)),
- onMouseout: e[29] || (e[29] = (...o) => t.cancelScale && t.cancelScale(...o))
- }, [
- t.imgs ? (W(), I("div", ot, [
- T(x("div", {
- class: "cropper-box-canvas",
- style: H({
- width: t.trueWidth + "px",
- height: t.trueHeight + "px",
- transform: "scale(" + t.scale + "," + t.scale + ") translate3d(" + t.x / t.scale + "px," + t.y / t.scale + "px,0)rotateZ(" + t.rotate * 90 + "deg)"
- })
- }, [
- x("img", {
- src: t.imgs,
- alt: "cropper-img",
- ref: "cropperImg"
- }, null, 8, at)
- ], 4), [
- [N, !t.loading]
- ])
- ])) : k("", !0),
- x("div", {
- class: F(["cropper-drag-box", { "cropper-move": t.move && !t.crop, "cropper-crop": t.crop, "cropper-modal": t.cropping }]),
- onMousedown: e[0] || (e[0] = (...o) => t.startMove && t.startMove(...o)),
- onTouchstart: e[1] || (e[1] = (...o) => t.startMove && t.startMove(...o))
- }, null, 34),
- T(x("div", {
- class: "cropper-crop-box",
- style: H({
- width: t.cropW + "px",
- height: t.cropH + "px",
- transform: "translate3d(" + t.cropOffsertX + "px," + t.cropOffsertY + "px,0)"
- })
- }, [
- x("span", ct, [
- x("img", {
- style: H({
- width: t.trueWidth + "px",
- height: t.trueHeight + "px",
- transform: "scale(" + t.scale + "," + t.scale + ") translate3d(" + (t.x - t.cropOffsertX) / t.scale + "px," + (t.y - t.cropOffsertY) / t.scale + "px,0)rotateZ(" + t.rotate * 90 + "deg)"
- }),
- src: t.imgs,
- alt: "cropper-img"
- }, null, 12, nt)
- ]),
- x("span", {
- class: "cropper-face cropper-move",
- onMousedown: e[2] || (e[2] = (...o) => t.cropMove && t.cropMove(...o)),
- onTouchstart: e[3] || (e[3] = (...o) => t.cropMove && t.cropMove(...o))
- }, null, 32),
- t.info ? (W(), I("span", {
- key: 0,
- class: "crop-info",
- style: H({ top: t.cropInfo.top })
- }, S(t.cropInfo.width) + " × " + S(t.cropInfo.height), 5)) : k("", !0),
- t.fixedBox ? k("", !0) : (W(), I("span", lt, [
- x("span", {
- class: "crop-line line-w",
- onMousedown: e[4] || (e[4] = (o) => t.changeCropSize(o, !1, !0, 0, 1)),
- onTouchstart: e[5] || (e[5] = (o) => t.changeCropSize(o, !1, !0, 0, 1))
- }, null, 32),
- x("span", {
- class: "crop-line line-a",
- onMousedown: e[6] || (e[6] = (o) => t.changeCropSize(o, !0, !1, 1, 0)),
- onTouchstart: e[7] || (e[7] = (o) => t.changeCropSize(o, !0, !1, 1, 0))
- }, null, 32),
- x("span", {
- class: "crop-line line-s",
- onMousedown: e[8] || (e[8] = (o) => t.changeCropSize(o, !1, !0, 0, 2)),
- onTouchstart: e[9] || (e[9] = (o) => t.changeCropSize(o, !1, !0, 0, 2))
- }, null, 32),
- x("span", {
- class: "crop-line line-d",
- onMousedown: e[10] || (e[10] = (o) => t.changeCropSize(o, !0, !1, 2, 0)),
- onTouchstart: e[11] || (e[11] = (o) => t.changeCropSize(o, !0, !1, 2, 0))
- }, null, 32),
- x("span", {
- class: "crop-point point1",
- onMousedown: e[12] || (e[12] = (o) => t.changeCropSize(o, !0, !0, 1, 1)),
- onTouchstart: e[13] || (e[13] = (o) => t.changeCropSize(o, !0, !0, 1, 1))
- }, null, 32),
- x("span", {
- class: "crop-point point2",
- onMousedown: e[14] || (e[14] = (o) => t.changeCropSize(o, !1, !0, 0, 1)),
- onTouchstart: e[15] || (e[15] = (o) => t.changeCropSize(o, !1, !0, 0, 1))
- }, null, 32),
- x("span", {
- class: "crop-point point3",
- onMousedown: e[16] || (e[16] = (o) => t.changeCropSize(o, !0, !0, 2, 1)),
- onTouchstart: e[17] || (e[17] = (o) => t.changeCropSize(o, !0, !0, 2, 1))
- }, null, 32),
- x("span", {
- class: "crop-point point4",
- onMousedown: e[18] || (e[18] = (o) => t.changeCropSize(o, !0, !1, 1, 0)),
- onTouchstart: e[19] || (e[19] = (o) => t.changeCropSize(o, !0, !1, 1, 0))
- }, null, 32),
- x("span", {
- class: "crop-point point5",
- onMousedown: e[20] || (e[20] = (o) => t.changeCropSize(o, !0, !1, 2, 0)),
- onTouchstart: e[21] || (e[21] = (o) => t.changeCropSize(o, !0, !1, 2, 0))
- }, null, 32),
- x("span", {
- class: "crop-point point6",
- onMousedown: e[22] || (e[22] = (o) => t.changeCropSize(o, !0, !0, 1, 2)),
- onTouchstart: e[23] || (e[23] = (o) => t.changeCropSize(o, !0, !0, 1, 2))
- }, null, 32),
- x("span", {
- class: "crop-point point7",
- onMousedown: e[24] || (e[24] = (o) => t.changeCropSize(o, !1, !0, 0, 2)),
- onTouchstart: e[25] || (e[25] = (o) => t.changeCropSize(o, !1, !0, 0, 2))
- }, null, 32),
- x("span", {
- class: "crop-point point8",
- onMousedown: e[26] || (e[26] = (o) => t.changeCropSize(o, !0, !0, 2, 2)),
- onTouchstart: e[27] || (e[27] = (o) => t.changeCropSize(o, !0, !0, 2, 2))
- }, null, 32)
- ]))
- ], 4), [
- [N, t.cropping]
- ])
- ], 544);
- }
- const ut = /* @__PURE__ */ ht(rt, [["render", pt], ["__scopeId", "data-v-a742df44"]]), dt = { class: "cropper-preview" }, gt = ["src"], ft = {
- key: 1,
- class: "cropper-preview-tip"
- }, mt = {
- __name: "CropperModal",
- emits: ["cropper-ok", "cropper-no"],
- setup(t, { expose: e, emit: s }) {
- const i = s, h = C(!1), r = C(!1), o = C(800), a = C(360), c = C(""), n = C(""), l = C("png"), u = C(!1), p = C([1, 1]), f = C(320), O = C(320), d = C({}), g = C();
- let v = {};
- function w(m) {
- if (m === 0 || m === "0") return null;
- if (typeof m == "string" && m.includes(":")) {
- const [y, Y] = m.split(":").map((L) => Number(L));
- return y > 0 && Y > 0 ? [y, Y] : [1, 1];
- }
- const b = Number(m);
- return b > 0 ? [b, 1] : [1, 1];
- }
- function z(m) {
- if (!m) return [320, 320];
- const y = m[0] / m[1];
- return y >= 1 ? [320, Math.round(320 / y)] : [Math.round(320 * y), 320];
- }
- const _ = (m = {}) => {
- const b = w(m.aspectRatio), [y, Y] = z(b);
- v = m, n.value = m.img || "", c.value = m.title || window.$l("图片裁剪"), l.value = m.outputType || "png", u.value = !b, p.value = b || [1, 1], f.value = y, O.value = Y, d.value = {}, r.value = !1, h.value = !0;
- }, B = (m) => {
- d.value = m || {};
- }, E = () => {
- h.value = !1, r.value = !1, i("cropper-no");
- }, P = () => {
- g.value && (r.value = !0, g.value.getCropBlob((m) => {
- r.value = !1, h.value = !1, i("cropper-ok", { blob: m, file: v.file });
- }));
- };
- return e({ edit: _ }), (m, b) => {
- const y = J, Y = G, L = Z, R = q("s-modal");
- return W(), V(R, {
- value: h.value,
- "onUpdate:value": b[0] || (b[0] = (U) => h.value = U),
- title: c.value,
- width: o.value,
- "mask-closable": !1,
- onHandCancel: E
- }, {
- footer: X(() => [
- M(L, { onClick: E }, {
- default: X(() => [
- $(S(m.$l("取消")), 1)
- ]),
- _: 1
- }),
- M(L, {
- type: "primary",
- loading: r.value,
- onClick: P
- }, {
- default: X(() => [
- $(S(m.$l("保存")), 1)
- ]),
- _: 1
- }, 8, ["loading"])
- ]),
- default: X(() => [
- M(Y, { gutter: 16 }, {
- default: X(() => [
- M(y, {
- xs: 24,
- md: 12,
- style: H({ height: a.value + "px" })
- }, {
- default: X(() => [
- M(j(ut), {
- ref_key: "cropper",
- ref: g,
- img: n.value,
- "auto-crop": !0,
- fixed: !u.value,
- "fixed-number": p.value,
- "fixed-box": !1,
- "center-box": !0,
- "can-move": !0,
- "can-scale": !0,
- info: !0,
- "info-true": !0,
- full: !1,
- "auto-crop-width": f.value,
- "auto-crop-height": O.value,
- "output-type": l.value,
- "output-size": 0.92,
- style: { width: "100%", height: "100%" },
- onRealTime: B
- }, null, 8, ["img", "fixed", "fixed-number", "auto-crop-width", "auto-crop-height", "output-type"])
- ]),
- _: 1
- }, 8, ["style"]),
- M(y, {
- xs: 24,
- md: 12,
- style: H({ height: a.value + "px" })
- }, {
- default: X(() => [
- x("div", dt, [
- d.value.url ? (W(), I("div", {
- key: 0,
- class: "preview-box",
- style: H(d.value.div)
- }, [
- x("img", {
- src: d.value.url,
- style: H(d.value.img),
- alt: ""
- }, null, 12, gt)
- ], 4)) : (W(), I("span", ft, S(m.$l("拖动裁剪框调整范围")), 1))
- ])
- ]),
- _: 1
- }, 8, ["style"])
- ]),
- _: 1
- })
- ]),
- _: 1
- }, 8, ["value", "title", "width"]);
- };
- }
- }, Ct = /* @__PURE__ */ Q(mt, [["__scopeId", "data-v-4d7c647d"]]);
- export {
- Ct as default
- };
|