From aed1ff699140de60131bf9cc1332c98063c66721 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 03 七月 2020 09:14:51 +0800 Subject: [PATCH] 2020-07-03 --- src/views/printTemplate/index.jsx | 86 ++++++++++++++++++++++++++++++++----------- 1 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/views/printTemplate/index.jsx b/src/views/printTemplate/index.jsx index 93246c9..3fd7cd4 100644 --- a/src/views/printTemplate/index.jsx +++ b/src/views/printTemplate/index.jsx @@ -251,8 +251,8 @@ _selectItem.left = _left _selectItem.top = _top - - let result = this.resetItem(_selectItem) + + let result = this.resetItem(fromJS(_selectItem).toJS()) if (!is(fromJS(result), fromJS(_preItem))) { _preItem = JSON.parse(JSON.stringify(result)) @@ -559,16 +559,18 @@ } - resetItem = (item) => { - let _item = JSON.parse(JSON.stringify(item)) + resetItem = (_item) => { const { config } = this.state + let oriItem = fromJS(config.elements.filter(ele => ele.uuid === _item.uuid)[0]).toJS() // 婧愮紪杈戝厓绱� + _item.width = +_item.width + _item.height = +_item.height let _boxwidth = +config.width let _boxheight = +config.height let _left = +_item.left let _top = +_item.top - let _width = +_item.width - let _height = +_item.height + let _width = _item.width + let _height = _item.height if (_left < 0) { _item.left = 0 @@ -586,25 +588,58 @@ } if (_item.type === 'barcode') { - if (+_item.barcodeWidth > +_item.width) { - _item.barcodeWidth = +_item.width - } - if (+_item.barcodeHeight > +_item.height) { - _item.barcodeHeight = +_item.height + _item.barcodeWidth = +_item.barcodeWidth + _item.barcodeHeight = +_item.barcodeHeight + + if (oriItem.width !== _item.width || oriItem.height !== _item.height) { + _item.barcodeWidth = _item.width * 0.8 + _item.barcodeHeight = _item.height * 0.6 + } else if (_item.barcodeLabel === 'true') { + if (_item.barcodeWidth > _item.width) { + _item.barcodeWidth = _item.width + } + let fsize = Math.floor(_item.fontSize / 2) + if (_item.barcodeHeight + fsize > _item.height) { + _item.barcodeHeight = _item.height - fsize + } + } else { + if (_item.barcodeWidth > _item.width) { + _item.barcodeWidth = _item.width + } + if (_item.barcodeHeight > _item.height) { + _item.barcodeHeight = _item.height + } } } else if (_item.type === 'qrcode') { - if (+_item.qrcodeWidth > +_item.width) { - _item.qrcodeWidth = +_item.width - } - if (+_item.qrcodeWidth > +_item.height) { - _item.qrcodeWidth = +_item.height + _item.qrcodeWidth = +_item.qrcodeWidth + + if (oriItem.width !== _item.width || oriItem.height !== _item.height) { + if (_item.height > _item.width) { + _item.qrcodeWidth = _item.width * 0.9 + } else if (_item.width > _item.height) { + _item.qrcodeWidth = _item.height * 0.9 + } + } else { + if (_item.qrcodeWidth > _item.width) { + _item.qrcodeWidth = _item.width + } + if (_item.qrcodeWidth > _item.height) { + _item.qrcodeWidth = _item.height + } } } else if (_item.type === 'image') { - if (+_item.imgWidth > +_item.width) { - _item.imgWidth = +_item.width - } - if (+_item.imgHeight > +_item.height) { - _item.imgHeight = +_item.height + _item.imgWidth = +_item.imgWidth + + if (oriItem.width !== _item.width || oriItem.height !== _item.height) { + _item.imgWidth = _item.width * 0.9 + _item.imgHeight = _item.height * 0.9 + } else { + if (_item.imgWidth > _item.width) { + _item.imgWidth = _item.width + } + if (_item.imgHeight > _item.height) { + _item.imgHeight = _item.height + } } } @@ -614,7 +649,8 @@ handleSubmit = () => { const { config } = this.state - this.FormRef.handleConfirm().then(res => { + this.FormRef.handleConfirm().then(response => { + let res = fromJS(response).toJS() if (res.type === 'Template') { res.width = parseInt(res.width) res.height = parseInt(res.height) @@ -640,6 +676,12 @@ } else if (res.type === 'qrcode') { res.url = qrurl } else if (res.type === 'image') { + if (res.value && res.value.length > 0) { + let url = res.value[0].url || res.value[0].response + res.value = url || '' + } else { + res.value = '' + } res.url = imgurl } -- Gitblit v1.8.0