PageSearch.js 5.3 KB
Newer Older
1 2 3
import React, { Fragment } from 'react';
import { InputNumber, message } from 'antd';
import {
4 5 6 7 8
	defaultConfigInfo,
	defaultItemConfigInfo,
	fieldTypeList,
	fontFamilyList,
	templateCode,
9 10 11 12
} from '@/webPublic/zyd_private/DragAndPrint/ViewPrint/config';
import { getInfo } from '@/highOrderComponent/Service';

const saveItemConfig = (data, getPage) => {
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
	if (typeof data.newY !== 'undefined' || typeof data.newX !== 'undefined') {
		let info = { ...data };
		info.x = (typeof data.newX !== 'undefined' && data.newX) || info.x;
		info.y = (typeof data.newY !== 'undefined' && data.newY) || info.y;
		getInfo(
			{
				contentStr: JSON.stringify([info]),
			},
			'/PublicPrintApi/update',
		).then((x) => {
			if (x) {
				getPage();
				message.success('保存成功');
			}
		});
	}
29 30 31
};

const handleColumns = (props) => {
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
	return [
		{
			dataIndex: 'title',
			title: '字段',
			type: 'input',
		},
		{
			dataIndex: 'content',
			title: '显示内容',
			type: 'input',
		},
		{
			dataIndex: 'mark',
			title: '换行分隔符',
			type: 'input',
		},
		{
			dataIndex: 'fieldType',
			title: '显示类型',
			type: 'select',
			options: fieldTypeList,
			render: (text) => {
				for (let item of fieldTypeList) {
					if (item.key === text) {
						return item.name;
					}
				}
				return text;
			},
		},
		{
			dataIndex: 'high',
			title: '显示高度',
			type: 'inputNumber',
		},
		{
			dataIndex: 'wide',
			title: '显示宽度',
			type: 'inputNumber',
		},
		{
			dataIndex: 'hasHidden',
			title: '是否隐藏',
			type: 'select',
			options: [{ key: 'true', name: '是' }, { key: 'false', name: '否' }],
			render: (text) => {
				return text ? '是' : '否';
			},
		},
		{
			dataIndex: 'fieldFont',
			title: '字体',
			type: 'select',
			options: fontFamilyList,
		},
		{
			dataIndex: 'fieldFontSize',
			title: '文字大小',
			type: 'inputNumber',
			min: 12,
			max: 100,
			precision: 0,
		},
		{
			dataIndex: 'x',
			title: 'x轴偏移量',
			type: 'inputNumber',
			renderConfig: {
				type: 'component',
				render: function({ text, record, getPage }) {
					return (
						<Fragment>
							{text}
							<InputNumber
								precision={0}
								onChange={(value) => {
									record.newX = value;
								}}
								defaultValue={text}
							/>
						</Fragment>
					);
				},
			},
			precision: 0,
		},
		{
			dataIndex: 'y',
			title: 'y轴偏移量',
			type: 'inputNumber',
			precision: 0,
			renderConfig: {
				type: 'component',
				render: function({ text, record, getPage }) {
					return (
						<Fragment>
							{text}
							<InputNumber
								precision={0}
								onChange={(value) => {
									record.newY = value;
								}}
								defaultValue={text}
							/>
						</Fragment>
					);
				},
			},
		},
		{
			dataIndex: 'save',
			title: '保存',
			renderConfig: {
				type: 'component',
				render: function({ text, record, getPage }) {
					return (
						<a
							onClick={() => {
								saveItemConfig(record, getPage);
							}}>
							保存
						</a>
					);
				},
			},
		},
		{
			dataIndex: 'fieldPattern',
			title: '显示格式',
			type: 'input',
		},
		{
			dataIndex: 'transform',
			title: '旋转角度',
			type: 'inputNumber',
			min: 0,
			max: 360,
			precision: 0,
		},
	];
172 173 174
};

const pageSearch = ({ changeConfigAll, configAll, location }) => {
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
	const columns = handleColumns();
	const fields = columns
		.filter((y) => {
			return y.type;
		})
		.map((x) => {
			if (x.type) {
				return {
					...x,
					name: x.title,
					key: x.dataIndex,
				};
			} else {
				return null;
			}
		});
	fields.push({
		key: 'info',
		name: '其他配置项JSON',
		type: 'textarea',
	});
	columns.push({
		dataIndex: 'operation',
		title: '操作',
		renderConfig: {
			type: 'ModalEdit',
			name: '编辑',
			width: 900,
			fileSpan: { big: 2, small: 2 },
			nameSpan: { big: 7, small: 7 },
			url: '/PublicPrintApi/update',
			fields,
			beforeUpdate: (record, formValues) => {
				formValues.info = formValues.info || JSON.stringify(defaultItemConfigInfo); // 其他配置项JSON
				return {
					contentStr: JSON.stringify([
						{
							...record,
							...formValues,
						},
					]),
				};
			},
			responseCallBack: (response) => {
				if (!response) {
					return false;
				} else {
					return response;
				}
			},
		},
	});
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 255 256 257 258 259 260 261 262 263 264 265 266
	return {
		search: {
			url: '/PublicPrintApi/query',
			field: {
				code: {
					defaultValue: (location && location.state && location.state.code) || 'studentCard',
					required: true,
				},
			},
			scroll: { x: 'max-content' },
			giveFieldsToFormValues: true,
			responseCallBack: (response) => {
				changeConfigAll(response);
				return response.config;
			},
			afterFormValuesChange: (key, oldValue, getPage) => {
				if (key === 'code') {
					getPage();
				}
			},
			condition: [
				{
					key: 'code',
					name: '业务功能',
					type: 'select',
					options: templateCode.map((x) => {
						return {
							key: x.code,
							name: x.name,
						};
					}),
				},
			],
			nameSpan: { big: 8, small: 9 },
			fileSpan: { big: 4, small: 4 },
		},
		tableRowKey: 'id',
		columns,
	};
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
};

/****
 * content: "${name}"
 errCode: ""
 errLog: ""
 errMsg: ""
 fieldCode: "name"
 fieldFont: "黑体"
 fieldFontSize: null
 fieldPattern: ""
 fieldType: "0"
 hasHidden: false
 id: 6
 respcode: "00"
 respdesc: ""
 title: "姓名"
 transform: 0
 x: 648
 y: 798
 *
 * */
export default pageSearch;