From 9a82bce9cf0ed4a51c1b0b0669eaa38cedbace07 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 16 七月 2020 16:35:58 +0800 Subject: [PATCH] 2020-07-16 --- src/mob/datasource/verifycard/settingform/index.jsx | 445 ++++++++++++++++++++++++++----------------------------- 1 files changed, 211 insertions(+), 234 deletions(-) diff --git a/src/mob/datasource/verifycard/settingform/index.jsx b/src/mob/datasource/verifycard/settingform/index.jsx index 9720ab4..33115ba 100644 --- a/src/mob/datasource/verifycard/settingform/index.jsx +++ b/src/mob/datasource/verifycard/settingform/index.jsx @@ -1,8 +1,16 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { fromJS } from 'immutable' -import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification, InputNumber } from 'antd' +// import { fromJS } from 'immutable' +import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification } from 'antd' import moment from 'moment' +// import CodeMirror from '@uiw/react-codemirror' + +// import 'codemirror/theme/monokai.css' +// import 'codemirror/theme/eclipse.css' +// import 'codemirror/addon/selection/active-line' +// import 'codemirror/addon/hint/javascript-hint' +// import 'codemirror/addon/hint/show-hint' +// import 'codemirror/addon/hint/show-hint.css' import Api from '@/api' import Utils from '@/utils/utils.js' @@ -13,28 +21,26 @@ class SettingForm extends Component { static propTpyes = { - type: PropTypes.string, // 鑿滃崟绫诲瀷 dict: PropTypes.object, // 瀛楀吀椤� - menu: PropTypes.object, // 鑿滃崟淇℃伅 - config: PropTypes.object, // 椤甸潰閰嶇疆淇℃伅 - formlist: PropTypes.array, // 琛ㄥ崟淇℃伅 + menuId: PropTypes.string, // 鑿滃崟Id + setting: PropTypes.object, // 鏁版嵁婧愰厤缃� + columns: PropTypes.array, // 鍒楄缃� + scripts: PropTypes.array, // 鑷畾涔夎剼鏈� } state = { - + interType: this.props.setting.interType || 'inner', + structure: this.props.setting.structure || 'array' } handleConfirm = (otype) => { - const { menu } = this.props - const { setting } = this.state + const { setting } = this.props // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭� return new Promise((resolve, reject) => { this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { - values = {...setting, ...values} - // 鏁版嵁婧愬墠绔獙璇� - if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && !values.dataresource) { + if (values.interType === 'inner' && !values.innerFunc && values.execute !== 'false' && !values.dataresource) { notification.warning({ top: 92, message: '璇峰~鍐欏唴閮ㄥ嚱鏁版垨鏁版嵁婧愶紒', @@ -42,7 +48,7 @@ }) reject() return - } else if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && values.dataresource) { + } else if (values.interType === 'inner' && !values.innerFunc && values.execute !== 'false' && values.dataresource) { let _quot = values.dataresource.match(/'{1}/g) let _lparen = values.dataresource.match(/\({1}/g) let _rparen = values.dataresource.match(/\){1}/g) @@ -57,6 +63,7 @@ message: '鏁版嵁婧愪腑\'蹇呴』鎴愬鍑虹幇', duration: 5 }) + reject() return } else if (_lparen !== _rparen) { notification.warning({ @@ -64,6 +71,7 @@ message: '鏁版嵁婧愪腑()蹇呴』鎴愬鍑虹幇', duration: 5 }) + reject() return } else if (/--/ig.test(values.dataresource)) { notification.warning({ @@ -71,6 +79,7 @@ message: '鏁版嵁婧愪腑锛屼笉鍙嚭鐜板瓧绗� -- 锛屾敞閲婅鐢� /*鍐呭*/', duration: 5 }) + reject() return } @@ -89,15 +98,13 @@ // 鏁版嵁婧愪繚瀛� if ( - values.interType === 'inner' && !values.innerFunc && - values.default !== 'false' && - /[^\s]+\s+[^\s]+/ig.test(values.dataresource) && - this.props.config.setting.dataresource !== values.dataresource + values.interType === 'inner' && !values.innerFunc && values.execute !== 'false' && + /[^\s]+\s+[^\s]+/ig.test(values.dataresource) && setting.dataresource !== values.dataresource ) { let param = { func: 's_DataSrc_Save', LText: values.dataresource, - MenuID: menu.MenuID + MenuID: this.props.menuId } param.LText = Utils.formatOptions(param.LText) @@ -107,17 +114,7 @@ Api.getLocalConfig(param) } - if (otype === 'change') { - this.setState({ - setting: values, - }, () => { - resolve() - }) - } else { - values.customScript = this.getCustomScript(values) - - this.sqlverify(values, resolve, reject) - } + resolve(values) } else { reject(err) } @@ -127,217 +124,23 @@ onRadioChange = (e, key) => { let value = e.target.value - let _formlist = fromJS(this.state.formlist).toJS() if (key === 'interType') { this.setState({ - formlist: _formlist.map(item => { - item.hidden = false - - if (value === 'inner' && ['sysInterface', 'interface', 'outerFunc'].includes(item.key)) { - item.initVal = this.props.form.getFieldValue(item.key) - item.hidden = true - } else if (value === 'outer' && ['innerFunc', 'dataresource', 'queryType'].includes(item.key)) { - item.initVal = this.props.form.getFieldValue(item.key) - item.hidden = true - } - - return item - }) + interType: value }) - } else if (key === 'sysInterface') { - if (value === 'true') { - this.props.form.setFieldsValue({ - interface: window.GLOB.mainSystemApi || '' - }) - } + } else if (key === 'structure') { this.setState({ - formlist: _formlist.map(item => { - if (item.key === 'interface') { - item.readonly = value === 'true' - } - - return item - }) + structure: value }) } } - getFields(formlist) { - const { getFieldDecorator } = this.props.form - const fields = [] - - formlist.forEach((item, index) => { - if (item.hidden || item.forbid) return - - if (item.type === 'text') { // 鏂囨湰鎼滅储 - let rules = item.rules || [] - - fields.push( - <Col span={8} key={index}> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <Icon type="question-circle" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal || '', - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - }, - ...rules - ] - })(<Input placeholder={item.placeholder || ''} autoComplete="off" disabled={item.readonly} onPressEnter={this.handleSubmit} />)} - </Form.Item> - </Col> - ) - } else if (item.type === 'number') { - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <Icon type="question-circle" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal || 6, - rules: [ - { - required: item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(<InputNumber min={item.min} max={item.max} precision={0} />)} - </Form.Item> - </Col> - ) - } else if (item.type === 'select') { // 涓嬫媺鎼滅储 - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal || '', - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' - } - ] - })( - <Select - showSearch - filterOption={(input, option) => { - return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 || - option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0 - }} - onChange={(value) => {this.selectChange(item.key, value)}} - getPopupContainer={() => document.getElementById('model-table-setting-form')} - > - {item.options.map((option, i) => - <Select.Option id={i} key={i} value={option.value}> - {option.text} - </Select.Option> - )} - </Select> - )} - </Form.Item> - </Col> - ) - } else if (item.type === 'radio') { - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.tooltip ? - <Tooltip placement="topLeft" title={item.tooltip}> - <Icon type="question-circle" /> - {item.label} - </Tooltip> : item.label - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' - } - ] - })( - <Radio.Group onChange={(e) => {this.onRadioChange(e, item.key)}}> - { - item.options.map((option, i) => { - return ( - <Radio key={i} value={option.value}>{option.text}</Radio> - ) - }) - } - </Radio.Group>, - )} - </Form.Item> - </Col> - ) - } else if (item.type === 'datasource') { - fields.push( - <Col span={24} key={index} style={{paddingLeft: '7px'}}> - <Form.Item labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} } help={item.help} label={ - <Tooltip placement="topLeft" title={item.tooltip}> - <Icon type="question-circle" /> - {item.label} - </Tooltip> - }> - {getFieldDecorator(item.key, { - initialValue: item.initVal - })(<TextArea rows={4} />)} - </Form.Item> - </Col> - ) - } else if (item.type === 'textarea') { - fields.push( - <Col span={20} offset={4} key={index}> - <Form.Item className="text-area"> - {getFieldDecorator(item.key, { - initialValue: item.initVal, - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.input'] + item.label + '!' - } - ] - })(<TextArea rows={4} />)} - </Form.Item> - </Col> - ) - } else if (item.type === 'multiselect') { // 澶氶�� - fields.push( - <Col span={12} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal || [] - })( - <Select - showSearch - mode="multiple" - filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - > - {item.options.map((option, i) => - <Select.Option id={i} key={i} value={option.value}>{option.text}</Select.Option> - )} - </Select> - )} - </Form.Item> - </Col> - ) - } - }) - - return fields - } - render() { + const { columns, setting } = this.props const { getFieldDecorator } = this.props.form - // const { formlist } = this.state + const { interType, structure } = this.state + const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -350,22 +153,196 @@ } return ( - <div className="model-table-setting-form-box"> - <Form {...formItemLayout} className="model-table-setting-form"> + <div className="mob-datasource-setting-form-box"> + <Form {...formItemLayout} className="mob-setting-form"> <Row gutter={24}> <Col span={8}> <Form.Item label="鍚嶇О"> - {getFieldDecorator('label', { - initialValue: '', + {getFieldDecorator('name', { + initialValue: setting.name, rules: [ { required: true, - message: this.props.dict['form.required.input'] + '鍚嶇О!' + message: this.props.dict['mob.required.input'] + '鍚嶇О!' }, ] })(<Input placeholder={''} autoComplete="off" />)} </Form.Item> </Col> + <Col span={8}> + <Form.Item label="琛ㄥ悕"> + {getFieldDecorator('tableName', { + initialValue: setting.tableName, + rules: [ + { + required: true, + message: this.props.dict['mob.required.input'] + '琛ㄥ悕!' + }, + ] + })(<Input placeholder={''} autoComplete="off" />)} + </Form.Item> + </Col> + <Col span={8}> + <Form.Item label="鏁版嵁缁撴瀯"> + {getFieldDecorator('structure', { + initialValue: structure, + rules: [ + { + required: true, + message: this.props.dict['mob.required.select'] + '琛ㄥ悕!' + }, + ] + })( + <Radio.Group onChange={(e) => {this.onRadioChange(e, 'structure')}}> + <Radio value="array">鏁扮粍</Radio> + <Radio value="field">瀛楁</Radio> + </Radio.Group>)} + </Form.Item> + </Col> + <Col span={8}> + <Form.Item label="鎺ュ彛绫诲瀷"> + {getFieldDecorator('interType', { + initialValue: interType, + rules: [ + { + required: true, + message: this.props.dict['mob.required.select'] + '鎺ュ彛绫诲瀷!' + }, + ] + })( + <Radio.Group onChange={(e) => {this.onRadioChange(e, 'interType')}}> + <Radio value="inner">鍐呴儴</Radio> + <Radio value="outer">澶栭儴</Radio> + </Radio.Group>)} + </Form.Item> + </Col> + {interType === 'inner' ? <Col span={8}> + <Form.Item label="鍐呴儴鍑芥暟"> + {getFieldDecorator('innerFunc', { + initialValue: setting.innerFunc || '', + rules: [ + + ] + })(<Input placeholder={''} autoComplete="off" />)} + </Form.Item> + </Col> : null} + {interType === 'outer' ? <Col span={8}> + <Form.Item label="鎺ュ彛鍦板潃"> + {getFieldDecorator('interface', { + initialValue: setting.interface || '', + rules: [ + { + required: true, + message: this.props.dict['mob.required.input'] + '鎺ュ彛鍦板潃!' + }, + ] + })(<Input placeholder={''} autoComplete="off" />)} + </Form.Item> + </Col> : null} + {interType === 'outer' ? <Col span={8}> + <Form.Item label="澶栭儴鍑芥暟"> + {getFieldDecorator('outerFunc', { + initialValue: setting.outerFunc || '', + rules: [ + + ] + })(<Input placeholder={''} autoComplete="off" />)} + </Form.Item> + </Col> : null} + {interType === 'inner' ? <Col span={24} className="data-source" style={{paddingLeft: '7px'}}> + <Form.Item labelCol={{xs: { span: 24 }, sm: { span: 2 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 22 }} } label={ + <Tooltip placement="topLeft" title={'浣跨敤绯荤粺鍑芥暟鏃讹紝闇�濉啓鏁版嵁婧愩�傛敞锛氭暟鎹潈闄愭浛鎹㈢ $@ -> /* 鎴� \'\'銆� @$ -> */ 鎴� \'\''}> + <Icon type="question-circle" /> + 鏁版嵁婧� + </Tooltip> + }> + {getFieldDecorator('dataresource', { + initialValue: setting.dataresource || '' + })(<TextArea rows={4} />)} + {/* <CodeMirror + value={'code'} + options={{ + theme: 'eclipse', + lineNumbers: false, + mode: 'SQL', + extraKeys: {"Ctrl": "autocomplete"}, + styleActiveLine: true + }} + /> */} + </Form.Item> + </Col> : null} + {interType === 'inner' ? <Col span={8}> + <Form.Item label={ + <Tooltip placement="topLeft" title={'鏌ヨ鏃讹紝鎼滅储鏉′欢浠here鏉′欢鎷兼帴杩涘叆sql锛岀粺璁℃椂锛屽皢鏁版嵁婧愪腑浠モ�淍+鎼滅储瀛楁+@鈥濈殑鍐呭锛屼互鎼滅储鏉′欢涓殑鍊艰繘琛屾浛鎹㈠悗锛屾彁浜ゆ煡璇紝娉細鏌ヨ绫诲瀷浠呭湪浣跨敤绯荤粺鍑芥暟鏃舵湁鏁堛��'}> + <Icon type="question-circle" /> + 鏌ヨ绫诲瀷 + </Tooltip> + }> + {getFieldDecorator('queryType', { + initialValue: setting.queryType || 'query' + })( + <Radio.Group> + <Radio value="query">鏌ヨ</Radio> + <Radio value="statistics">缁熻</Radio> + </Radio.Group>)} + </Form.Item> + </Col> : null} + {structure === 'array' ? <Col span={8}> + <Form.Item label="涓婚敭"> + {getFieldDecorator('primaryKey', { + initialValue: setting.primaryKey || '' + })( + <Select onChange={(value) => {this.selectChange('primaryKey', value)}}> + {columns.map((option, i) => + <Select.Option key={i} value={option.value}> + {option.text} + </Select.Option> + )} + </Select> + )} + </Form.Item> + </Col> : null} + {structure === 'array' ? <Col span={8}> + <Form.Item label="榛樿鎺掑簭"> + {getFieldDecorator('order', { + initialValue: setting.order || '' + })(<Input placeholder={'ID asc, UID desc'} autoComplete="off" />)} + </Form.Item> + </Col> : null} + {structure === 'array' ? <Col span={8}> + <Form.Item label="鍒嗛〉"> + {getFieldDecorator('laypage', { + initialValue: setting.laypage || 'true' + })( + <Radio.Group> + <Radio value="true">鏄�</Radio> + <Radio value="false">鍚�</Radio> + </Radio.Group>)} + </Form.Item> + </Col> : null} + + {interType === 'inner' ? <Col span={8}> + <Form.Item label="榛樿sql"> + {getFieldDecorator('execute', { + initialValue: setting.execute || 'true' + })( + <Radio.Group> + <Radio value="true">鎵ц</Radio> + <Radio value="false">涓嶆墽琛�</Radio> + </Radio.Group>)} + </Form.Item> + </Col> : null} + <Col span={8}> + <Form.Item label="鎼滅储鏉′欢"> + {getFieldDecorator('search', { + initialValue: setting.search || 'true' + })( + <Radio.Group> + <Radio value="true">鎺ユ敹</Radio> + <Radio value="false">涓嶆帴鏀�</Radio> + </Radio.Group>)} + </Form.Item> + </Col> </Row> </Form> </div> -- Gitblit v1.8.0