12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133 |
- import { mouseposition } from '../global/location';
- import server from './server';
- import luckysheetsizeauto from './resize';
- import { modelHTML } from './constant';
- import {checkProtectionAuthorityNormal} from './protection';
- import { getSheetIndex } from '../methods/get';
- import { setluckysheet_scroll_status } from '../methods/set';
- import { replaceHtml } from '../utils/util';
- import Store from '../store';
- import locale from '../locale/locale';
- import tooltip from '../global/tooltip';
- import method from '../global/method';
- const imageCtrl = {
- imgItem: {
- type: '3', //1移动并调整单元格大小 2移动并且不调整单元格的大小 3不要移动单元格并调整其大小
- src: '', //图片url
- originWidth: null, //图片原始宽度
- originHeight: null, //图片原始高度
- default: {
- width: null, //图片 宽度
- height: null, //图片 高度
- left: null, //图片离表格左边的 位置
- top: null, //图片离表格顶部的 位置
- },
- crop: {
- width: null, //图片裁剪后 宽度
- height: null, //图片裁剪后 高度
- offsetLeft: 0, //图片裁剪后离未裁剪时 左边的位移
- offsetTop: 0, //图片裁剪后离未裁剪时 顶部的位移
- },
- isFixedPos: false, //固定位置
- fixedLeft: null, //固定位置 左位移
- fixedTop: null, //固定位置 右位移
- border: {
- width: 0, //边框宽度
- radius: 0, //边框半径
- style: 'solid', //边框类型
- color: '#000', //边框颜色
- }
- },
- images: null,
- currentImgId: null,
- currentWinW: null,
- currentWinH: null,
- resize: null,
- resizeXY: null,
- move: false,
- moveXY: null,
- cropChange: null,
- cropChangeXY: null,
- cropChangeObj: null,
- copyImgItemObj: null,
- insertImg: function (file) {
- const uploadImage = Store.toJsonOptions && Store.toJsonOptions['uploadImage'];
- if (typeof uploadImage === 'function') {
- // 上传形式
- uploadImage(file).then(url => {
- imageCtrl._insertImg(url);
- }).catch(error => {
- tooltip.info('<i class="fa fa-exclamation-triangle"></i>', '图片上传失败');
- });
- } else {
- // 内部base64形式
- let render = new FileReader();
- render.readAsDataURL(file);
- render.onload = function(event){
- let src = event.target.result;
- imageCtrl._insertImg(src);
- $("#luckysheet-imgUpload").val("");
- }
- }
- },
- _insertImg: function(src){
- let _this = this;
-
- let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
- let rowIndex = last.row_focus || 0;
- let colIndex = last.column_focus || 0;
- let left = colIndex == 0 ? 0 : Store.visibledatacolumn[colIndex - 1];
- let top = rowIndex == 0 ? 0 : Store.visibledatarow[rowIndex - 1];
- let image = new Image();
- image.onload = function(){
- let width = image.width,
- height = image.height;
- let img = {
- src: src,
- left: left,
- top: top,
- originWidth: width,
- originHeight: height
- }
- _this.addImgItem(img);
- }
- let imageUrlHandle = Store.toJsonOptions && Store.toJsonOptions['imageUrlHandle'];
- image.src = typeof imageUrlHandle === 'function' ? imageUrlHandle(src) : src;
- },
- generateRandomId: function(prefix) {
- if(prefix == null){
- prefix = "img";
- }
- let userAgent = window.navigator.userAgent.replace(/[^a-zA-Z0-9]/g, "").split("");
- let mid = "";
- for(let i = 0; i < 12; i++){
- mid += userAgent[Math.round(Math.random() * (userAgent.length - 1))];
- }
- let time = new Date().getTime();
- return prefix + "_" + mid + "_" + time;
- },
- modelHtml: function(id, imgItem) {
- let _this = this;
- let imageUrlHandle = Store.toJsonOptions && Store.toJsonOptions['imageUrlHandle'];
- let src = typeof imageUrlHandle === 'function' ? imageUrlHandle(imgItem.src) : imgItem.src;
- let imgItemParam = _this.getImgItemParam(imgItem);
- let width = imgItemParam.width * Store.zoomRatio;
- let height = imgItemParam.height * Store.zoomRatio;
- let left = imgItemParam.left * Store.zoomRatio;
- let top = imgItemParam.top * Store.zoomRatio;
- let position = imgItemParam.position;
- let borderWidth = imgItem.border.width;
- return `<div id="${id}" class="luckysheet-modal-dialog luckysheet-modal-dialog-image" style="width:${width}px;height:${height}px;padding:0;position:${position};left:${left}px;top:${top}px;z-index:200;">
- <div class="luckysheet-modal-dialog-content" style="width:100%;height:100%;overflow:hidden;position:relative;">
- <img src="${src}" style="position:absolute;width:${imgItem.default.width * Store.zoomRatio}px;height:${imgItem.default.height * Store.zoomRatio}px;left:${-imgItem.crop.offsetLeft * Store.zoomRatio}px;top:${-imgItem.crop.offsetTop * Store.zoomRatio}px;" />
- </div>
- <div class="luckysheet-modal-dialog-border" style="border:${borderWidth}px ${imgItem.border.style} ${imgItem.border.color};border-radius:${imgItem.border.radius * Store.zoomRatio}px;position:absolute;left:${-borderWidth}px;right:${-borderWidth}px;top:${-borderWidth}px;bottom:${-borderWidth}px;"></div>
- </div>`;
- },
- getSliderHtml: function() {
- let imageText = locale().imageText;
- return `<div id="luckysheet-modal-dialog-slider-imageCtrl" class="luckysheet-modal-dialog-slider luckysheet-modal-dialog-slider-imageCtrl" style="display:block;">
- <div class="luckysheet-modal-dialog-slider-title">
- <span>${imageText.imageSetting}</span>
- <span class="luckysheet-model-close-btn" title="${imageText.close}">
- <i class="fa fa-times" aria-hidden="true"></i>
- </span>
- </div>
- <div class="luckysheet-modal-dialog-slider-content">
- <div class="slider-box">
- <div class="slider-box-title">${imageText.conventional}</div>
- <div class="slider-box-radios">
- <div class="radio-item">
- <input type="radio" id="imgItemType1" name="imgItemType" value="1">
- <label for="imgItemType1">${imageText.moveCell1}</label>
- </div>
- <div class="radio-item">
- <input type="radio" id="imgItemType2" name="imgItemType" value="2">
- <label for="imgItemType2">${imageText.moveCell2}</label>
- </div>
- <div class="radio-item">
- <input type="radio" id="imgItemType3" name="imgItemType" value="3">
- <label for="imgItemType3">${imageText.moveCell3}</label>
- </div>
- </div>
- <div class="slider-box-checkbox">
- <input type="checkbox" id="imgItemIsFixedPos">
- <label for="imgItemIsFixedPos">${imageText.fixedPos}</label>
- </div>
- </div>
- <div class="slider-box">
- <div class="slider-box-title">${imageText.border}</div>
- <div class="slider-box-borderConfig">
- <div class="border-item">
- <label>${imageText.width}</label>
- <input type="number" id="imgItemBorderWidth" min="0">
- </div>
- <div class="border-item">
- <label>${imageText.radius}</label>
- <input type="number" id="imgItemBorderRadius" min="0">
- </div>
- <div class="border-item">
- <label>${imageText.style}</label>
- <select id="imgItemBorderStyle">
- <option value="solid">${imageText.solid}</option>
- <option value="dashed">${imageText.dashed}</option>
- <option value="dotted">${imageText.dotted}</option>
- <option value="double">${imageText.double}</option>
- </select>
- </div>
- <div class="border-item">
- <label>${imageText.color}</label>
- <div id="imgItemBorderColor" class="imgItemBorderColor">
- <span></span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>`;
- },
- sliderHtmlShow: function() {
- let _this = this;
- $("#luckysheet-modal-dialog-slider-imageCtrl").remove();
- let sliderHtml = _this.getSliderHtml();
- $("body").first().append(sliderHtml);
- luckysheetsizeauto();
- let imgItem = _this.images[_this.currentImgId];
- //类型
- let type = imgItem.type;
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemType" + type).prop("checked", true);
- //固定位置
- let isFixedPos = imgItem.isFixedPos;
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemIsFixedPos").prop("checked", isFixedPos);
- //边框宽度
- let border = imgItem.border;
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemBorderWidth").val(border.width);
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemBorderRadius").val(border.radius);
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemBorderStyle").val(border.style);
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemBorderColor span").css("background-color", border.color).attr("title", border.color);
-
- _this.init();
- },
- colorSelectDialog: function(currenColor){
- const _locale = locale();
- const locale_button = _locale.button;
- const locale_toolbar = _locale.toolbar;
- const locale_imageCtrl = _locale.imageCtrl;
- $("#luckysheet-modal-dialog-mask").show();
- $("#luckysheet-imageCtrl-colorSelect-dialog").remove();
- $("body").first().append(replaceHtml(modelHTML, {
- "id": "luckysheet-imageCtrl-colorSelect-dialog",
- "addclass": "luckysheet-imageCtrl-colorSelect-dialog",
- "title": locale_imageCtrl.borderTile,
- "content": `<div class="currenColor">
- ${locale_imageCtrl.borderCur}:<span title="${currenColor}" style="background-color:${currenColor}"></span>
- </div>
- <div class="colorshowbox"></div>`,
- "botton": `<button id="luckysheet-imageCtrl-colorSelect-dialog-confirm" class="btn btn-primary">${locale_button.confirm}</button>
- <button class="btn btn-default luckysheet-model-close-btn">${locale_button.cancel}</button>`,
- "style": "z-index:100003"
- }));
- let $t = $("#luckysheet-imageCtrl-colorSelect-dialog")
- .find(".luckysheet-modal-dialog-content")
- .css("min-width", 300)
- .end(),
- myh = $t.outerHeight(),
- myw = $t.outerWidth();
- let winw = $(window).width(), winh = $(window).height();
- let scrollLeft = $(document).scrollLeft(), scrollTop = $(document).scrollTop();
- $("#luckysheet-imageCtrl-colorSelect-dialog").css({
- "left": (winw + scrollLeft - myw) / 2,
- "top": (winh + scrollTop - myh) / 3
- }).show();
-
- //初始化选择颜色插件
- $("#luckysheet-imageCtrl-colorSelect-dialog").find(".colorshowbox").spectrum({
- showPalette: true,
- showPaletteOnly: true,
- preferredFormat: "hex",
- clickoutFiresChange: false,
- showInitial: true,
- showInput: true,
- flat: true,
- hideAfterPaletteSelect: true,
- showSelectionPalette: true,
- showButtons: false,//隐藏选择取消按钮
- maxPaletteSize: 8,
- maxSelectionSize: 8,
- color: currenColor,
- cancelText: locale_button.cancel,
- chooseText: locale_toolbar.confirmColor,
- togglePaletteMoreText: locale_toolbar.customColor,
- togglePaletteLessText: locale_toolbar.collapse,
- togglePaletteOnly: true,
- clearText: locale_toolbar.clearText,
- noColorSelectedText: locale_toolbar.noColorSelectedText,
- localStorageKey: "spectrum.textcolor" + server.gridKey,
- palette: [
- ["#000", "#444", "#666", "#999", "#ccc", "#eee", "#f3f3f3", "#fff"],
- ["#f00", "#f90", "#ff0", "#0f0", "#0ff", "#00f", "#90f", "#f0f"],
- ["#f4cccc", "#fce5cd", "#fff2cc", "#d9ead3", "#d0e0e3", "#cfe2f3", "#d9d2e9", "#ead1dc"],
- ["#ea9999", "#f9cb9c", "#ffe599", "#b6d7a8", "#a2c4c9", "#9fc5e8", "#b4a7d6", "#d5a6bd"],
- ["#e06666", "#f6b26b", "#ffd966", "#93c47d", "#76a5af", "#6fa8dc", "#8e7cc3", "#c27ba0"],
- ["#c00", "#e69138", "#f1c232", "#6aa84f", "#45818e", "#3d85c6", "#674ea7", "#a64d79"],
- ["#900", "#b45f06", "#bf9000", "#38761d", "#134f5c", "#0b5394", "#351c75", "#741b47"],
- ["#600", "#783f04", "#7f6000", "#274e13", "#0c343d", "#073763", "#20124d", "#4c1130"]
- ],
- move: function(color){
- if (color != null) {
- color = color.toHexString();
- }
- else {
- color = "#000";
- }
- $("#luckysheet-imageCtrl-colorSelect-dialog .currenColor span").css("background-color", color).attr("title", color);
- }
- });
- },
- init: function() {
- let _this = this;
- //关闭
- $("#luckysheet-modal-dialog-slider-imageCtrl .luckysheet-model-close-btn").click(function () {
- $("#luckysheet-modal-dialog-slider-imageCtrl").hide();
- luckysheetsizeauto();
- });
- //常规
- $("#luckysheet-modal-dialog-slider-imageCtrl").off("change.radio").on("change.radio", ".radio-item input[type=radio][name=imgItemType]", function() {
- _this.configChange("type", this.value);
- })
- //固定位置
- $("#luckysheet-modal-dialog-slider-imageCtrl").off("change.checkbox").on("change.checkbox", ".slider-box-checkbox input[type=checkbox]", function() {
- _this.configChange("fixedPos", this.checked);
- })
- //边框宽度
- $("#luckysheet-modal-dialog-slider-imageCtrl").off("change.borderWidth").on("change.borderWidth", "#imgItemBorderWidth", function() {
- _this.configChange("border-width", this.valueAsNumber);
- })
- //边框半径
- $("#luckysheet-modal-dialog-slider-imageCtrl").off("change.borderRadius").on("change.borderRadius", "#imgItemBorderRadius", function() {
- _this.configChange("border-radius", this.valueAsNumber);
- })
- //边框样式
- $("#luckysheet-modal-dialog-slider-imageCtrl").off("change.borderStyle").on("change.borderStyle", "#imgItemBorderStyle", function() {
- _this.configChange("border-style", this.value);
- })
- //边框颜色 选择
- $("#luckysheet-modal-dialog-slider-imageCtrl").off("click.color").on("click.color", "#imgItemBorderColor", function() {
- let currenColor = $(this).find("span").attr("title");
- _this.colorSelectDialog(currenColor);
- })
- //边框选择颜色 确定
- $(document).off("click.selectColorConfirm").on("click.selectColorConfirm", "#luckysheet-imageCtrl-colorSelect-dialog-confirm", function(){
- let $parent = $(this).parents("#luckysheet-imageCtrl-colorSelect-dialog");
- $("#luckysheet-modal-dialog-mask").hide();
- $parent.hide();
- let currenColor = $parent.find(".currenColor span").attr("title");
- $("#luckysheet-modal-dialog-slider-imageCtrl #imgItemBorderColor span").css("background-color", currenColor).attr("title", currenColor);
- _this.configChange("border-color", currenColor);
- });
- //image active
- $("#luckysheet-image-showBoxs").off("mousedown.active").on("mousedown.active", ".luckysheet-modal-dialog-image", function(e) {
-
- if(!checkProtectionAuthorityNormal(Store.currentSheetIndex, "editObjects",false)){
- return;
- }
- $(this).hide();
- let id = $(this).attr("id");
- if(_this.currentImgId != null && _this.currentImgId != id){
- _this.cancelActiveImgItem();
- }
- _this.currentImgId = id;
- let item = _this.images[id];
- let imgItemParam = _this.getImgItemParam(item);
- let width = imgItemParam.width * Store.zoomRatio;
- let height = imgItemParam.height * Store.zoomRatio;
- let left = imgItemParam.left * Store.zoomRatio;
- let top = imgItemParam.top * Store.zoomRatio;
- let position = imgItemParam.position;
-
- $("#luckysheet-modal-dialog-activeImage").show().css({
- "width": width,
- "height": height,
- "left": left,
- "top": top,
- "position": position
- });
- let imageUrlHandle = Store.toJsonOptions && Store.toJsonOptions['imageUrlHandle'];
- let imgUrl = typeof imageUrlHandle === 'function' ? imageUrlHandle(item.src) : item.src;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-content").css({
- "background-image": "url(" + imgUrl + ")",
- "background-size": item.default.width * Store.zoomRatio + "px " + item.default.height * Store.zoomRatio + "px",
- "background-position": -item.crop.offsetLeft * Store.zoomRatio + "px " + -item.crop.offsetTop * Store.zoomRatio + "px"
- })
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-border").css({
- "border-width": item.border.width * Store.zoomRatio,
- "border-style": item.border.style,
- "border-color": item.border.color,
- "border-radius": item.border.radius * Store.zoomRatio,
- "left": -item.border.width * Store.zoomRatio,
- "right": -item.border.width * Store.zoomRatio,
- "top": -item.border.width * Store.zoomRatio,
- "bottom": -item.border.width * Store.zoomRatio,
- })
- _this.sliderHtmlShow();
- e.stopPropagation();
- })
- //image move
- $("#luckysheet-modal-dialog-activeImage").off("mousedown.move").on("mousedown.move", ".luckysheet-modal-dialog-content", function(e) {
- if(!checkProtectionAuthorityNormal(Store.currentSheetIndex, "editObjects",false)){
- return;
- }
-
- if(!$("#luckysheet-modal-dialog-slider-imageCtrl").is(":visible")){
- _this.sliderHtmlShow();
- }
-
- _this.move = true;
-
- _this.currentWinW = $("#luckysheet-cell-main")[0].scrollWidth;
- _this.currentWinH = $("#luckysheet-cell-main")[0].scrollHeight;
- let offset = $("#luckysheet-modal-dialog-activeImage").offset();
- _this.moveXY = [
- e.pageX - offset.left,
- e.pageY - offset.top,
- ];
- setluckysheet_scroll_status(true);
- e.stopPropagation();
- })
- //image resize
- $("#luckysheet-modal-dialog-activeImage").off("mousedown.resize").on("mousedown.resize", ".luckysheet-modal-dialog-resize-item", function(e) {
- if(!checkProtectionAuthorityNormal(Store.currentSheetIndex, "editObjects",false)){
- return;
- }
-
- _this.currentWinW = $("#luckysheet-cell-main")[0].scrollWidth;
- _this.currentWinH = $("#luckysheet-cell-main")[0].scrollHeight;
- _this.resize = $(this).data("type");
- let scrollTop = $("#luckysheet-cell-main").scrollTop(),
- scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- let mouse = mouseposition(e.pageX, e.pageY);
- let x = mouse[0] + scrollLeft;
- let y = mouse[1] + scrollTop;
- let position = $("#luckysheet-modal-dialog-activeImage").position();
- let width = $("#luckysheet-modal-dialog-activeImage").width();
- let height = $("#luckysheet-modal-dialog-activeImage").height();
- _this.resizeXY = [
- x,
- y,
- width,
- height,
- position.left + scrollLeft,
- position.top + scrollTop,
- scrollLeft,
- scrollTop
- ];
- setluckysheet_scroll_status(true);
-
- e.stopPropagation();
- })
- //image croppingEnter
- $("#luckysheet-modal-dialog-activeImage").off("mousedown.croppingEnter").on("mousedown.croppingEnter", ".luckysheet-modal-controll-crop", function(e) {
- _this.croppingEnter();
- e.stopPropagation();
- })
- //image croppingExit
- $("#luckysheet-modal-dialog-cropping").off("mousedown.croppingExit").on("mousedown.croppingExit", ".luckysheet-modal-controll-crop", function(e) {
- _this.croppingExit();
- e.stopPropagation();
- })
- //image crop change
- $("#luckysheet-modal-dialog-cropping").off("mousedown.cropChange").on("mousedown.cropChange", ".resize-item", function(e) {
- _this.cropChange = $(this).data("type");
- let scrollTop = $("#luckysheet-cell-main").scrollTop(),
- scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- let mouse = mouseposition(e.pageX, e.pageY);
- let x = mouse[0] + scrollLeft;
- let y = mouse[1] + scrollTop;
- _this.cropChangeXY = [
- x,
- y
- ];
- setluckysheet_scroll_status(true);
-
- e.stopPropagation();
- })
- //image restore
- $("#luckysheet-image-showBoxs").off("mousedown.restore").on("mousedown.restore", ".luckysheet-modal-controll-restore", function(e) {
- _this.restoreImgItem();
- e.stopPropagation();
- })
- //image delete
- $("#luckysheet-image-showBoxs").off("mousedown.delete").on("mousedown.delete", ".luckysheet-modal-controll-del", function(e) {
- _this.removeImgItem();
- e.stopPropagation();
- })
- },
- configChange: function(type, value){
- let _this = this;
- let imgItem = _this.images[_this.currentImgId];
- switch(type){
- case "type":
- imgItem.type = value;
- break;
- case "fixedPos":
- imgItem.isFixedPos = value;
- let imgItemParam = _this.getImgItemParam(imgItem);
- let width = imgItemParam.width;
- let height = imgItemParam.height;
- let left = imgItemParam.left;
- let top = imgItemParam.top;
- let position = imgItemParam.position;
-
- $("#luckysheet-modal-dialog-activeImage").show().css({
- "width": width,
- "height": height,
- "left": left,
- "top": top,
- "position": position
- });
- break;
- case "border-width":
- imgItem.border.width = value;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-border").css({
- "border-width": value,
- "left": -value,
- "right": -value,
- "top": -value,
- "bottom": -value
- });
- break;
- case "border-radius":
- imgItem.border.radius = value;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-border").css("border-radius", value);
- break;
- case "border-style":
- imgItem.border.style = value;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-border").css("border-style", value);
- break;
- case "border-color":
- imgItem.border.color = value;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-border").css("border-color", value);
- break;
- }
-
- _this.ref();
- },
- getImgItemParam(imgItem){
- let isFixedPos = imgItem.isFixedPos;
- let width = imgItem.default.width,
- height = imgItem.default.height,
- left = imgItem.default.left,
- top = imgItem.default.top;
- if(imgItem.crop.width != width || imgItem.crop.height != height){
- width = imgItem.crop.width;
- height = imgItem.crop.height;
- left += imgItem.crop.offsetLeft;
- top += imgItem.crop.offsetTop;
- }
- let position = 'absolute';
- if(isFixedPos){
- position = 'fixed';
- left = imgItem.fixedLeft + imgItem.crop.offsetLeft;
- top = imgItem.fixedTop + imgItem.crop.offsetTop;
- }
- return {
- width: width,
- height: height,
- left: left,
- top: top,
- position: position
- }
- },
- cancelActiveImgItem: function(){
- let _this = this;
- $("#luckysheet-modal-dialog-activeImage").hide();
- $("#luckysheet-modal-dialog-cropping").hide();
- $("#luckysheet-modal-dialog-slider-imageCtrl").hide();
- let imgItem = _this.images[_this.currentImgId];
- let imgItemParam = _this.getImgItemParam(imgItem);
- let width = imgItemParam.width * Store.zoomRatio;
- let height = imgItemParam.height * Store.zoomRatio;
- let left = imgItemParam.left * Store.zoomRatio;
- let top = imgItemParam.top * Store.zoomRatio;
- let position = imgItemParam.position;
- $("#" + _this.currentImgId).show().css({
- "width": width,
- "height": height,
- "left": left,
- "top": top,
- "position": position
- });
- $("#" + _this.currentImgId + " img").css({
- "width": imgItem.default.width * Store.zoomRatio,
- "height": imgItem.default.height * Store.zoomRatio,
- "left": -imgItem.crop.offsetLeft * Store.zoomRatio,
- "top": -imgItem.crop.offsetTop * Store.zoomRatio
- });
- $("#" + _this.currentImgId + " .luckysheet-modal-dialog-border").css({
- "border-width": imgItem.border.width * Store.zoomRatio,
- "border-style": imgItem.border.style,
- "border-color": imgItem.border.color,
- "border-radius": imgItem.border.radius * Store.zoomRatio,
- "left": -imgItem.border.width * Store.zoomRatio,
- "right": -imgItem.border.width * Store.zoomRatio,
- "top": -imgItem.border.width * Store.zoomRatio,
- "bottom": -imgItem.border.width * Store.zoomRatio,
- })
- _this.currentImgId = null;
- },
- addImgItem: function(img) {
- let _this = this;
- let width, height;
- let max = 400;
- if(img.originHeight < img.originWidth){
- height = Math.round(img.originHeight * (max / img.originWidth));
- width = max;
- }
- else{
- width = Math.round(img.originWidth * (max / img.originHeight));
- height = max;
- }
- if(_this.images == null){
- _this.images = {};
- }
- let imgItem = $.extend(true, {}, _this.imgItem);
- imgItem.src = img.src;
- imgItem.originWidth = img.originWidth;
- imgItem.originHeight = img.originHeight;
- imgItem.default.width = width;
- imgItem.default.height = height;
- imgItem.default.left = img.left;
- imgItem.default.top = img.top;
- imgItem.crop.width = width;
- imgItem.crop.height = height;
- let scrollTop = $("#luckysheet-cell-main").scrollTop(),
- scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- imgItem.fixedLeft = img.left - scrollLeft + Store.rowHeaderWidth;
- imgItem.fixedTop = img.top - scrollTop + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight;
- let id = _this.generateRandomId();
- let modelHtml = _this.modelHtml(id, imgItem);
- $("#luckysheet-image-showBoxs .img-list").append(modelHtml);
- _this.images[id] = imgItem;
- _this.ref();
- _this.init();
- },
- moveImgItem: function() {
- let _this = this;
- _this.move = false;
- let obj = $("#luckysheet-modal-dialog-activeImage")[0];
- let item = _this.images[_this.currentImgId];
- if(item.isFixedPos){
- item.fixedLeft = obj.offsetLeft - item.crop.offsetLeft;
- item.fixedTop = obj.offsetTop - item.crop.offsetTop;
- }
- else{
- item.default.left = obj.offsetLeft - item.crop.offsetLeft;
- item.default.top = obj.offsetTop - item.crop.offsetTop;
- }
- _this.ref();
- },
- resizeImgItem: function() {
- let _this = this;
- _this.resize = null;
- let obj = $("#luckysheet-modal-dialog-activeImage")[0];
- let item = _this.images[_this.currentImgId];
- let scaleX = obj.clientWidth / item.crop.width;
- let scaleY = obj.clientHeight / item.crop.height;
- item.default.width = Math.round(item.default.width * scaleX);
- item.default.height = Math.round(item.default.height * scaleY);
- item.crop.width = Math.round(item.crop.width * scaleX);
- item.crop.height = Math.round(item.crop.height * scaleY);
- item.crop.offsetLeft = Math.round(item.crop.offsetLeft * scaleX);
- item.crop.offsetTop = Math.round(item.crop.offsetTop * scaleY);
- if(item.isFixedPos){
- item.fixedLeft = obj.offsetLeft;
- item.fixedTop = obj.offsetTop;
- }
- else{
- item.default.left = obj.offsetLeft - item.crop.offsetLeft;
- item.default.top = obj.offsetTop - item.crop.offsetTop;
- }
- _this.ref();
- },
- croppingEnter: function() {
- let _this = this;
- _this.cropping = true;
- if(!checkProtectionAuthorityNormal(Store.currentSheetIndex, "editObjects",false)){
- return;
- }
- $("#luckysheet-modal-dialog-activeImage").hide();
- $("#luckysheet-modal-dialog-slider-imageCtrl").hide();
- let item = _this.images[_this.currentImgId];
- let imgItemParam = _this.getImgItemParam(item);
- let width = imgItemParam.width;
- let height = imgItemParam.height;
- let left = imgItemParam.left;
- let top = imgItemParam.top;
- let position = imgItemParam.position;
-
- $("#luckysheet-modal-dialog-cropping").show().css({
- "width": width,
- "height": height,
- "left": left,
- "top": top,
- "position": position
- });
- let imageUrlHandle = Store.toJsonOptions && Store.toJsonOptions['imageUrlHandle'];
- let imgSrc = typeof imageUrlHandle === 'function' ? imageUrlHandle(item.src) : item.src;
- $("#luckysheet-modal-dialog-cropping .cropping-mask").css({
- "width": item.default.width,
- "height": item.default.height,
- "background-image": "url(" + imgSrc + ")",
- "left": -item.crop.offsetLeft,
- "top": -item.crop.offsetTop
- })
- $("#luckysheet-modal-dialog-cropping .cropping-content").css({
- "background-image": "url(" + imgSrc + ")",
- "background-size": item.default.width + "px " + item.default.height + "px",
- "background-position": -item.crop.offsetLeft + "px " + -item.crop.offsetTop + "px"
- })
- $("#luckysheet-modal-dialog-cropping .luckysheet-modal-dialog-border").css({
- "border-width": item.border.width,
- "border-style": item.border.style,
- "border-color": item.border.color,
- "border-radius": item.border.radius,
- "left": -item.border.width,
- "right": -item.border.width,
- "top": -item.border.width,
- "bottom": -item.border.width,
- })
- },
- croppingExit: function() {
- let _this = this;
- _this.cropping = false;
- $("#luckysheet-modal-dialog-cropping").hide();
- let item = _this.images[_this.currentImgId];
- let imgItemParam = _this.getImgItemParam(item);
- let width = imgItemParam.width;
- let height = imgItemParam.height;
- let left = imgItemParam.left;
- let top = imgItemParam.top;
- let position = imgItemParam.position;
- $("#luckysheet-modal-dialog-activeImage").show().css({
- "width": width,
- "height": height,
- "left": left,
- "top": top,
- "position": position
- });
- let imageUrlHandle = Store.toJsonOptions && Store.toJsonOptions['imageUrlHandle'];
- let imgSrc = typeof imageUrlHandle === 'function' ? imageUrlHandle(item.src) : item.src;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-content").css({
- "background-image": "url(" + imgSrc + ")",
- "background-size": item.default.width + "px " + item.default.height + "px",
- "background-position": -item.crop.offsetLeft + "px " + -item.crop.offsetTop + "px"
- })
- },
- cropChangeImgItem: function() {
- let _this = this;
- _this.cropChange = null;
- let item = _this.images[_this.currentImgId];
- item.crop.width = _this.cropChangeObj.width;
- item.crop.height = _this.cropChangeObj.height;
- item.crop.offsetLeft = _this.cropChangeObj.offsetLeft;
- item.crop.offsetTop = _this.cropChangeObj.offsetTop;
- _this.ref();
- },
- restoreImgItem: function() {
- let _this = this;
- let imgItem = _this.images[_this.currentImgId];
- imgItem.default.width = imgItem.originWidth;
- imgItem.default.height = imgItem.originHeight;
- imgItem.crop.width = imgItem.originWidth;
- imgItem.crop.height = imgItem.originHeight;
- imgItem.crop.offsetLeft = 0;
- imgItem.crop.offsetTop = 0;
- let imgItemParam = _this.getImgItemParam(imgItem);
- let width = imgItemParam.width;
- let height = imgItemParam.height;
- let left = imgItemParam.left;
- let top = imgItemParam.top;
- let position = imgItemParam.position;
-
- $("#luckysheet-modal-dialog-activeImage").show().css({
- "width": width,
- "height": height,
- "left": left,
- "top": top,
- "position": position
- });
- let imageUrlHandle = Store.toJsonOptions && Store.toJsonOptions['imageUrlHandle'];
- let imgSrc = typeof imageUrlHandle === 'function' ? imageUrlHandle(imgItem.src) : imgItem.src;
- $("#luckysheet-modal-dialog-activeImage .luckysheet-modal-dialog-content").css({
- "background-image": "url(" + imgSrc + ")",
- "background-size": imgItem.default.width + "px " + imgItem.default.height + "px",
- "background-position": -imgItem.crop.offsetLeft + "px " + -imgItem.crop.offsetTop + "px"
- })
- _this.ref();
- },
- removeImgItem: function() {
- let _this = this;
- let imgItem = _this.images[_this.currentImgId];
- // 钩子 imageDeleteBefore
- if(!method.createHookFunction('imageDeleteBefore', imgItem)){
- return;
- }
-
- $("#luckysheet-modal-dialog-activeImage").hide();
- $("#luckysheet-modal-dialog-cropping").hide();
- $("#luckysheet-modal-dialog-slider-imageCtrl").hide();
- $("#" + _this.currentImgId).remove();
- delete _this.images[_this.currentImgId];
- _this.currentImgId = null;
- // 钩子 imageDeleteAfter
- method.createHookFunction('imageDeleteAfter', imgItem);
- _this.ref();
- },
- copyImgItem: function(e) {
- let _this = this;
- _this.copyImgItemObj = $.extend(true, {}, _this.images[_this.currentImgId]);
- let clipboardData = window.clipboardData; //for IE
- if (!clipboardData) { // for chrome
- clipboardData = e.originalEvent.clipboardData;
- }
- let cpdata = '<table data-type="luckysheet_copy_action_image"><tr><td><td></tr></table>';
- if (!clipboardData) {
- let textarea = $("#luckysheet-copy-content");
- textarea.html(cpdata);
- textarea.focus();
- textarea.select();
- document.execCommand("selectAll");
- document.execCommand("Copy");
- // 等50毫秒,keyPress事件发生了再去处理数据
- setTimeout(function () {
- $("#luckysheet-copy-content").blur();
- }, 10);
- }
- else {
- clipboardData.setData('Text', cpdata);
- return false;//否则设不生效
- }
- },
- pasteImgItem: function() {
- let _this = this;
- if(_this.images == null){
- _this.images = {};
- }
- let rowIndex = Store.luckysheet_select_save[0].row_focus || 0;
- let colIndex = Store.luckysheet_select_save[0].column_focus || 0;
- let left = colIndex == 0 ? 0 : Store.visibledatacolumn[colIndex - 1];
- let top = rowIndex == 0 ? 0 : Store.visibledatarow[rowIndex - 1];
- let img = $.extend(true, {}, _this.copyImgItemObj);
-
- img.default.left = left - img.crop.offsetLeft;
- img.default.top = top - img.crop.offsetTop;
- let scrollTop = $("#luckysheet-cell-main").scrollTop(),
- scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- img.fixedLeft = img.default.left - scrollLeft + Store.rowHeaderWidth;
- img.fixedTop = img.default.top - scrollTop + Store.infobarHeight + Store.toolbarHeight + Store.calculatebarHeight + Store.columnHeaderHeight;
- let id = _this.generateRandomId();
- let modelHtml = _this.modelHtml(id, img);
- $("#luckysheet-image-showBoxs .img-list").append(modelHtml);
- _this.images[id] = img;
- _this.ref();
- _this.init();
- },
- allImagesShow: function() {
- let _this = this;
-
- $("#luckysheet-modal-dialog-activeImage").hide();
- $("#luckysheet-modal-dialog-cropping").hide();
- $("#luckysheet-modal-dialog-slider-imageCtrl").hide();
- $("#luckysheet-image-showBoxs .img-list").empty();
- if(_this.images == null){
- return;
- }
- for(let imgId in _this.images){
- let imgItem = _this.images[imgId];
- let modelHtml = _this.modelHtml(imgId, imgItem);
- $("#luckysheet-image-showBoxs .img-list").append(modelHtml);
- }
- },
- moveChangeSize: function(rc, index, size) {
- let _this = this;
- let images = $.extend(true, {}, _this.images);
- if(rc == "row"){
- let row = Store.visibledatarow[index],
- row_pre = index - 1 == -1 ? 0 : Store.visibledatarow[index - 1];
- let changeSize = size - (row - row_pre - 1);
-
- for(let imgId in images){
- let imgItem = images[imgId];
- let imgItemParam = _this.getImgItemParam(imgItem);
- let type = imgItem.type;
- if(type == "1"){
- if(imgItemParam.top >= row){
- imgItem.default.top = imgItemParam.top + changeSize - imgItem.crop.offsetTop;
- }
- else{
- if(imgItemParam.top + imgItemParam.height >= row-2){
- if(imgItemParam.top < row + changeSize){
- let scaleY = (imgItemParam.height + changeSize) / imgItemParam.height;
- imgItem.default.height = Math.round(imgItem.default.height * scaleY);
- imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
- imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
- }
- else{
- let scaleY = (imgItemParam.top + imgItemParam.height - row) / imgItemParam.height;
- imgItem.default.height = Math.round(imgItem.default.height * scaleY);
- imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
- imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
- imgItem.default.top = row + changeSize - imgItem.crop.offsetTop;
- }
- }
- else{
- if(imgItemParam.top > row + changeSize){
- let scaleY = 1 / imgItemParam.height;
- imgItem.default.height = Math.round(imgItem.default.height * scaleY);
- imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
- imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
- imgItem.default.top = row + changeSize - imgItem.crop.offsetTop;
- }
- else if(imgItemParam.top + imgItemParam.height > row + changeSize){
- let scaleY = (row + changeSize - imgItemParam.top) / imgItemParam.height;
- imgItem.default.height = Math.round(imgItem.default.height * scaleY);
- imgItem.crop.height = Math.round(imgItem.crop.height * scaleY);
- imgItem.crop.offsetTop = Math.round(imgItem.crop.offsetTop * scaleY);
- }
- }
- }
- }
- else if(type == "2"){
- if(imgItemParam.top >= row){
- imgItem.default.top = imgItemParam.top + changeSize - imgItem.crop.offsetTop;
- }
- else if(imgItemParam.top > row + changeSize){
- imgItem.default.top = row + changeSize - imgItem.crop.offsetTop;
- }
- }
- }
- }
- else if(rc == "column"){
- let col = Store.visibledatacolumn[index],
- col_pre = index - 1 == -1 ? 0 : Store.visibledatacolumn[index - 1];
- let changeSize = size - (col - col_pre - 1);
- for(let imgId in images){
- let imgItem = images[imgId];
- let imgItemParam = _this.getImgItemParam(imgItem);
- let type = imgItem.type;
- if(type == "1"){
- if(imgItemParam.left >= col){
- imgItem.default.left = imgItemParam.left + changeSize - imgItem.crop.offsetLeft;
- }
- else{
- if(imgItemParam.left + imgItemParam.width >= col-2){
- if(imgItemParam.left < col + changeSize){
- let scaleX = (imgItemParam.width + changeSize) / imgItemParam.width;
- imgItem.default.width = Math.round(imgItem.default.width * scaleX);
- imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
- imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
- }
- else{
- let scaleX = (imgItemParam.left + imgItemParam.width - col) / imgItemParam.width;
- imgItem.default.width = Math.round(imgItem.default.width * scaleX);
- imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
- imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
- imgItem.default.left = col + changeSize - imgItem.crop.offsetLeft;
- }
- }
- else{
- if(imgItemParam.left > col + changeSize){
- let scaleX = 1 / imgItemParam.width;
- imgItem.default.width = Math.round(imgItem.default.width * scaleX);
- imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
- imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
- imgItem.default.left = col + changeSize - imgItem.crop.offsetLeft;
- }
- else if(imgItemParam.left + imgItemParam.width > col + changeSize){
- let scaleX = (col + changeSize - imgItemParam.left) / imgItemParam.width;
- imgItem.default.width = Math.round(imgItem.default.width * scaleX);
- imgItem.crop.width = Math.round(imgItem.crop.width * scaleX);
- imgItem.crop.offsetLeft = Math.round(imgItem.crop.offsetLeft * scaleX);
- }
- }
- }
- }
- else if(type == "2"){
- if(imgItemParam.left >= col){
- imgItem.default.left = imgItemParam.left + changeSize - imgItem.crop.offsetLeft;
- }
- else if(imgItemParam.left > col + changeSize){
- imgItem.default.left = col + changeSize - imgItem.crop.offsetLeft;
- }
- }
- }
- }
- return images;
- },
- ref: function() {
- let _this = this;
- let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
- let images = _this.images;
- if (Store.clearjfundo) {
- Store.jfundo.length = 0;
- Store.jfredo.push({
- "type": "imageCtrl",
- "sheetIndex": Store.currentSheetIndex,
- "images": file.images == null ? null : $.extend(true, {}, file.images),
- "curImages": images
- });
- }
- file.images = $.extend(true, {}, images);
- server.saveParam("all", Store.currentSheetIndex, file.images, { "k": "images" });
- },
- }
- export default imageCtrl;
|