Sfoglia il codice sorgente

图表查看列时间类型格式化/数据链接校验逻辑bug

zhuth 6 anni fa
parent
commit
453fff9a92

+ 8 - 5
src/components/chartDesigner/sections/dataViewConfigForm.jsx

@@ -1,3 +1,6 @@
+/**
+ * 数据视图
+ */
 import React from 'react'
 import { Form, Select, Button } from 'antd'
 import { connect } from 'dva'
@@ -16,6 +19,7 @@ class DataViewConfigForm extends React.Component {
 	
 	render() {
 		const { autoRefresh, dispatch, chartDesigner, formItemLayout } = this.props;
+		const { visibleDisplayColumnBox } = this.state;
 		return (
             <Form layout='horizontal'>
 				<FormItem label="展示列" {...formItemLayout}>
@@ -51,11 +55,10 @@ class DataViewConfigForm extends React.Component {
 						<Option value="desc">降序</Option>
 					</Select>
 				</FormItem>
-				<DisplayColumnBox
-					key={Math.random()}
-					visibleDisplayColumnBox={this.state.visibleDisplayColumnBox}
+				{visibleDisplayColumnBox && <DisplayColumnBox
+					visibleDisplayColumnBox={visibleDisplayColumnBox}
 					hideBox={() => this.setState({visibleDisplayColumnBox:false})}
-					allColumns={chartDesigner.columns}
+					allColumns={chartDesigner.columns.map((c, i) => ({ ...c, key: i }))}
 					defaultSelectedColumns={chartDesigner.dataViewConfig.viewColumns}
 					okHandler={(targetColumns) => {
 						dispatch(
@@ -67,7 +70,7 @@ class DataViewConfigForm extends React.Component {
 							}
 						);
 					}}
-				/>	
+				/>}
 			</Form>
         );
 	}

+ 1 - 1
src/components/chartDesigner/sections/displayColumnBox.jsx

@@ -79,7 +79,7 @@ class DisplayColumnBox extends React.Component {
                 destroyOnClose={true}
             >
                 <Transfer
-                    dataSource={allColumns.map(c => ({ ...c, key: c.name }))}
+                    dataSource={allColumns}
                     showSearch
                     filterOption={(inputValue, option) => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1}
                     listStyle={{

+ 15 - 2
src/components/common/dataPreview/dataPreview.jsx

@@ -1,6 +1,7 @@
 import React from 'react'
 import { Modal, Table } from 'antd'
 import { connect } from 'dva'
+import moment from 'moment'
 import EllipsisTooltip from '../ellipsisTooltip/index'
 import './dataPreview.less'
 
@@ -61,7 +62,9 @@ class DataPreview extends React.Component {
             <Table
                 bordered
                 columns={columns.map((c, i) => {
-                    let obj = { ...c,
+                    let obj = {
+                        title: c.label,
+                        dataIndex: c.name,
                         onCell: () => {
                             return {
                                 style: {
@@ -70,8 +73,18 @@ class DataPreview extends React.Component {
                                 }
                             }
                         },
-                        render: (text) => <EllipsisTooltip title={text}>{text === null ? '空' : text}</EllipsisTooltip>,
                     };
+                    if(c.type === 'time') {
+                        obj.render = (v, r, i) => {
+                            let text = moment(v).isValid() ? moment(v).format('YYYY-MM-DD') : v
+                            return <EllipsisTooltip title={text}>{text}</EllipsisTooltip>
+                        }
+                    }else {
+                        obj.render = v => {
+                            let text = v === null ? '空' : v
+                            return <EllipsisTooltip title={text}>{text}</EllipsisTooltip>
+                        }
+                    }
                     if(i !== columns.length - 1) {
                         obj.width = columnWidth
                     }

+ 7 - 4
src/components/dataSourceDetail/dataConnectBox.jsx

@@ -72,16 +72,19 @@ class DataConnectBox extends React.Component {
         let value = nowValue === undefined  ? newOne[fieldName] : nowValue;
         let status = 'success';
         let help = '';
-        if(required !== undefined && required) {
+        if(status === 'success' && required !== undefined && required) {
             status = (value === undefined || value === null) ? 'error' : ((value + '').trim().length === 0 ? 'error' : 'success');
             help = (value === undefined || value === null) ? fieldLabel + '不能为空' : ((value + '').trim().length === 0 ? fieldLabel + '不能为空' : '');
-        }else if(minLength !== undefined && minLength > 0) {
+        }
+        if(status === 'success' && minLength !== undefined && minLength > 0) {
             status = !!value && (value + '').length < minLength ? 'error' : 'success'
             help = !!value && (value + '').length < minLength ? fieldLabel + '长度不能小于' + minLength + '个字符' : ''
-        }else if(maxLength !== undefined && maxLength > 0) {
+        }
+        if(status === 'success' && maxLength !== undefined && maxLength > 0) {
             status = !!value && (value + '').length > maxLength ? 'error' : 'success'
             help = !!value && (value + '').length > maxLength ? fieldLabel + '长度不能大于' + maxLength + '个字符' : ''
-        }else if(reg !== undefined) {
+        }
+        if(status === 'success' && reg !== undefined) {
             status = !!value.match(new RegExp(reg)) ? 'success' : 'error'
             help = !!value.match(new RegExp(reg)) ? '' : fieldLabel + '格式有误'
         }

+ 3 - 7
src/models/chartDesigner.js

@@ -662,14 +662,10 @@ export default {
                     });;
                     sortColumn = xAxis.column.value;
                 }else if(viewType === 'dataView') {
-                    columns = dataViewConfig.viewColumns.map(c => ({
-                        title: c.label,
-                        dataIndex: c.name,
-                        render: c.type === 'time' ? ((v, r, i) => moment(v).format('YYYY-MM-DD')) : v => v
-                    }));
+                    columns = dataViewConfig.viewColumns;
                     sortColumn = dataViewConfig.sortColumn.key;
                 }
-                columnListName = columns.map(c => c.dataIndex);
+                columnListName = columns.map(c => c.name);
 
                 const body = {
                     id: code,
@@ -701,7 +697,7 @@ export default {
                         { name: 'total', value: total }
                     ] });
                 }else {
-                    // message.error('请求列表数据失败: ' + (res.err || res.data.msg));
+                    message.error('请求列表数据失败: ' + (res.err || res.data.msg));
                     // yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
                 }
             }catch(e) {