|
@@ -2,6 +2,7 @@ import React, { Component } from "react";
|
|
|
import ReactDom from "react-dom";
|
|
|
import style from "./index.less";
|
|
|
import Notify from '@commonComp/Notify';
|
|
|
+import $ from 'jquery';
|
|
|
import close from '@common/images/icon_close.png';
|
|
|
/**
|
|
|
* title:标题
|
|
@@ -14,19 +15,106 @@ import close from '@common/images/icon_close.png';
|
|
|
*height:弹窗的高度
|
|
|
* **/
|
|
|
|
|
|
+(function ($) {
|
|
|
+ var opt;
|
|
|
+
|
|
|
+ $.fn.jqprint = function (options) {
|
|
|
+ opt = $.extend({}, $.fn.jqprint.defaults, options);
|
|
|
+
|
|
|
+ var $element = (this instanceof $) ? this : $(this);
|
|
|
+
|
|
|
+ if (opt.operaSupport && $.browser.opera) {
|
|
|
+ var tab = window.open("", "jqPrint-preview");
|
|
|
+ tab.document.open();
|
|
|
+
|
|
|
+ var doc = tab.document;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var $iframe = $("<iframe />");
|
|
|
+
|
|
|
+ if (!opt.debug) { $iframe.css({ position: "absolute", width: "0px", height: "0px", left: "-300px", top: "-300px" }); }
|
|
|
+
|
|
|
+ $iframe.appendTo("body");
|
|
|
+ var doc = $iframe[0].contentWindow.document;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (opt.importCSS) {
|
|
|
+ if ($("link[media=print]").length > 0) {
|
|
|
+ $("link[media=print]").each(function () {
|
|
|
+ doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' media='print' />");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $("link").each(function () {
|
|
|
+ doc.write("<link type='text/css' rel='stylesheet' href='" + $(this).attr("href") + "' />");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (opt.printContainer) { doc.write($element.outer()); }
|
|
|
+ else { $element.each(function () { doc.write($(this).html()); }); }
|
|
|
+
|
|
|
+ doc.close();
|
|
|
+
|
|
|
+ (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).focus();
|
|
|
+ setTimeout(function () { (opt.operaSupport && $.browser.opera ? tab : $iframe[0].contentWindow).print(); if (tab) { tab.close(); } }, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ $.fn.jqprint.defaults = {
|
|
|
+ debug: false,
|
|
|
+ importCSS: true,
|
|
|
+ printContainer: true,
|
|
|
+ operaSupport: true
|
|
|
+ };
|
|
|
+
|
|
|
+ $.fn.outer = function () {
|
|
|
+ return $($('<div></div>').html(this.clone())).html();
|
|
|
+ }
|
|
|
+})($);
|
|
|
+
|
|
|
class ComplexModal extends Component {
|
|
|
constructor(props) {
|
|
|
- super(props)
|
|
|
+ super(props);
|
|
|
+ this.onPrint = this.onPrint.bind(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ onPrint() {
|
|
|
+ // $("#contents").jqprint({
|
|
|
+ // debug: false,
|
|
|
+ // importCSS: true,
|
|
|
+ // printContainer: true,
|
|
|
+ // operaSupport: false,
|
|
|
+ // });
|
|
|
+ let bdhtml=window.document.body.innerHTML;//获取当前页的html代码
|
|
|
+ let sprnstr="<i>111111</i>";//设置打印开始区域
|
|
|
+ let eprnstr="<i>222222</i>";//设置打印结束区域
|
|
|
+ let prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //从开始代码向后取html
|
|
|
+ let domWrap = document.createElement('div')
|
|
|
+ prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//从结束代码向前取html
|
|
|
+ domWrap.innerHTML=prnhtml;
|
|
|
+ console.log(domWrap)
|
|
|
+ $(domWrap).jqprint({
|
|
|
+ debug: false,
|
|
|
+ importCSS: true,
|
|
|
+ printContainer: true,
|
|
|
+ operaSupport: false,
|
|
|
+ });
|
|
|
+ // window.document.body.innerHTML=prnhtml;
|
|
|
+ // window.print()
|
|
|
+ // console.log(prnhtml)
|
|
|
}
|
|
|
+
|
|
|
render() {
|
|
|
const { onclose,title,children,footer,shadeClose,icon,width,top,bottom} = this.props;
|
|
|
const marginLeft = width? -parseInt(width)/2 : '';
|
|
|
//const marginTop = height? -parseInt(height)/2: '';
|
|
|
const domNode = document.getElementById('root');
|
|
|
- return ReactDom.createPortal(<div className={style['container']}>
|
|
|
+ return ReactDom.createPortal(<div className={style['container']} id="contents">
|
|
|
<div className={style['shade']} onClick={shadeClose===false?'':onclose}></div>
|
|
|
+
|
|
|
+ <i>111111</i>
|
|
|
<div className={style['modal']} style = {{width: width?width:'auto', marginLeft:marginLeft, top:top?top+'px':'',bottom:bottom?bottom+'px':''}}>
|
|
|
- <div className={style['close']}>
|
|
|
+ <div className={style['close']} onClick={this.onPrint}>
|
|
|
{icon?<img src={icon} />:''}
|
|
|
{title}
|
|
|
<img src={close} onClick={onclose} className={style['closeIcon']} />
|
|
@@ -34,6 +122,7 @@ class ComplexModal extends Component {
|
|
|
<div className={style["content"]} style = {{width: width?width:'auto'}}>{children}</div>
|
|
|
<div className={style['footer']} style = {{width: width?width:'auto'}}>{footer}</div>
|
|
|
</div>
|
|
|
+ <i>222222</i>
|
|
|
</div>,domNode);
|
|
|
}
|
|
|
}
|