index.js 7.2 KB
Newer Older
1 2
import React from 'react';
import ViewPrint from './index2';
钟是志's avatar
钟是志 committed
3

4
export default class Index extends React.Component {
5 6 7
	render() {
		return <ViewPrint {...this.props} />;
	}
8
}
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254

// import React, { Component, Fragment } from 'react';
// import { queryConfig } from '../services';
// import { getInfo } from '@/highOrderComponent/Service';
// import { message, Button } from 'antd';
// import Shell from '@/baseComponent/Shell';
// import ReactToPrint from 'react-to-print';
// import ButtonDiy from '@/baseComponent/ButtonDiy';
// import router from 'umi/router';
// import styles from '../index.less';
// import DetailDom from './DetailDom';
// import { imageStyleAll, A4Width, A4Height } from './config';
//
// export default class ViewPrint extends Component {
//   constructor(props) {
//     super(props);
//     this.state = {
//       configAll: null,
//       viewData: null,
//       loading: false,
//       minHeight: 0,
//       showWindowPrint: false,
//     };
//     this.getConfigInfo = queryConfig.bind(this);
//   }
//
//   countImageHeight = () => {
//     if (!this.state.configAll) {
//       return false;
//     }
//     const {
//       configAll: { backgroundUrl },
//     } = this.state;
//     const img = new Image();
//     img.src = backgroundUrl;
//     img.onload = () => {
//       this.setState({
//         minHeight: img.height,
//       });
//     };
//   };
//
//   getViewData = () => {
//     const { selectedRows } = this.props;
//     const ids = selectedRows.map((x) => x.id);
//     this.getConfigInfo().then((x) => {
//       this.countImageHeight();
//       if (x && x.queryUrl) {
//         getInfo(
//           {
//             ids: ids.join(','),
//           },
//           x.queryUrl,
//         ).then((viewData) => {
//           if (!viewData || !viewData.length) {
//             message.warning('未查询到可打印的奖状数据');
//             console.error(`${x.queryUrl}接口报错或者没有返回数据`);
//             return false;
//           }
//           for (let item of viewData) {
//             for (let x in item) {
//               if (item[x] === null || item[x] === 'null') {
//                 item[x] = '';
//               }
//             }
//           }
//           this.setState({
//             viewData,
//           });
//         });
//       }
//     });
//   };
//
//
//   beforePrint = () => {
//     console.log('beforePrint');
//   };
//
//   afterPrint = () => {
//     console.log('afterPrint');
//   };
//
//   componentDidMount() {
//     this.getViewData();
//   }
//
//   detailDom = (data) => {
//     const {
//       configAll: { config },
//     } = this.state;
//     const res = [];
//     for (const item of config) {
//       res.push(
//         DetailDom({
//           config: item,
//           data: data[item.fieldCode],
//         }),
//       );
//     }
//     return res;
//   };
//
//   onBeforeGetContent = () => {
//     this.setState({
//       loading: true,
//     });
//
//     return new Promise((resolve, reject) => {
//       const { selectedRows } = this.props;
//       const { configAll } = this.state;
//       const ids = selectedRows.map((x) => {
//         return x.id;
//       });
//       if (configAll.callUrl && false) {
//         // 暂时关闭调用这个接口 不通知后台是否打印了
//         getInfo({ ids: ids.join(',') }, configAll.callUrl).then((x) => {
//           if (x) {
//             this.setState({ showWindowPrint: true }, () => {
//               resolve(true);
//             });
//           } else {
//             resolve(true);
//           }
//         });
//       } else {
//         this.setState({ showWindowPrint: true }, () => {
//           resolve(true);
//         });
//       }
//     });
//   };
//
//   render() {
//     const {
//       loading,
//       configAll,
//       viewData,
//       showWindowPrint,
//       minHeight,
//     } = this.state;
//     if (!viewData || !minHeight) {
//       return null;
//     }
//     if (!configAll.backgroundUrl) {
//       console.error('没有设置模版图片无法使用');
//       return null;
//     }
//     const { hasPrintBackground, backgroundUrl, wide, high } = configAll;
//     const imageStyle = {
//       height: `${high}cm` || A4Height,
//       width: `${wide}cm` || A4Width,
//     };
//
//     return (
//       <Fragment>
//         <Shell styleShell={{ marginTop: '0', marginBottom: '20px' }}>
//           <div style={{ height: '54px', padding: '12px 0 12px 12px' }}>
//             <ReactToPrint
//               trigger={() => (
//                 <Button
//                   shape="round"
//                   type="primary"
//                   loading={loading}
//                   style={{ marginRight: '20px' }}>
//                   打印
//                 </Button>
//               )}
//               content={() => this.content}
//               onBeforeGetContent={this.onBeforeGetContent}
//               onAfterPrint={() => {
//                 this.setState({
//                   showWindowPrint: false,
//                   loading: false,
//                 });
//               }}
//             />
//             <ButtonDiy
//               name={'返回'}
//               handleClick={() => {
//                 router.goBack();
//               }}
//             />
//           </div>
//         </Shell>
//
//         {/** 预览的dom **/}
//         {viewData && viewData.length ? (
//           <div>
//             {viewData.map((info, index) => {
//               return (
//                 <div
//                   className={styles.outSideDivPrint}
//                   key={index + 'divKey'}
//                   style={{
//                     ...imageStyle,
//                   }}>
//                   <img
//                     src={backgroundUrl}
//                     draggable={false}
//                     className={styles.bgimagePrint}
//                     alt={'背景图'}
//                     style={imageStyleAll}
//                   />
//                   {this.detailDom(info)}
//                 </div>
//               );
//             })}
//           </div>
//         ) : null}
//
//         {/**  打印的dom */}
//         {viewData && viewData.length ? (
//           <div
//             ref={(node) => (this.content = node)}
//             style={{
//               display: showWindowPrint /*|| true*/ ? 'block' : 'none',
//             }}>
//             {viewData.map((info, index) => {
//               return (
//                 <div
//                   className={styles.outSideDivPrint}
//                   key={`${index}divKey`}
//                   style={{
//                     ...imageStyle,
//                   }}>
//                   {hasPrintBackground ? (
//                     <img
//                       src={backgroundUrl}
//                       draggable={false}
//                       className={styles.bgimagePrint}
//                       alt={'背景图'}
//                       style={imageStyleAll}
//                     />
//                   ) : null}
//
//                   {this.detailDom(info)}
//                 </div>
//               );
//             })}
//           </div>
//         ) : null}
//       </Fragment>
//     );
//   }
// }