zhuth 7 years ago
parent
commit
ff16acf7a4

+ 1 - 0
src/components/chartDesigner/layout.jsx

@@ -15,6 +15,7 @@ class ChartDesigner extends React.Component {
         if(code !== 'create') {
         if(code !== 'create') {
             dispatch({ type: 'chart/remoteDetail', code: code });
             dispatch({ type: 'chart/remoteDetail', code: code });
             dispatch({ type: 'chart/remoteGroupList', code: code });
             dispatch({ type: 'chart/remoteGroupList', code: code });
+            dispatch({ type: 'main/addRecentRecord', tarId: code, recordType: 0})
         }
         }
     }
     }
     render() {
     render() {

+ 3 - 8
src/components/common/CardList.jsx

@@ -25,14 +25,9 @@ const CardGrid = Card.Grid
 class CardList extends React.Component {
 class CardList extends React.Component {
     
     
     generateCard() {
     generateCard() {
-        const { mode, dispatch } = this.props;
-        const modeMapper = {
-            'dashboard': this.props.dashboard,  //这里只是临时指向全体列表,等待专门的收藏列表接口完成后需要修改
-            'chart': this.props.chart //同上
-        }
-        let list = modeMapper[mode].list
+        const { mode, dispatch, list, type } = this.props;
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
-        let filterLabel = modeMapper[mode].filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号
+        let filterLabel = (mode !== 'homepage') ? list.filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ""; // 添加转义符号
         const operationMenu = (
         const operationMenu = (
             <Menu className='menu-operation'>
             <Menu className='menu-operation'>
                 <Menu.Item onClick={() => {
                 <Menu.Item onClick={() => {
@@ -114,7 +109,7 @@ class CardList extends React.Component {
                             </Row>
                             </Row>
                             <Row className='footer' type='flex' justify='end' align='bottom'>
                             <Row className='footer' type='flex' justify='end' align='bottom'>
                                 <Col style={{ textAlign: 'left' }} span={22}>
                                 <Col style={{ textAlign: 'left' }} span={22}>
-                                    <Row>{l.creator} {dateFormat(l.createTime, 'yyyy-MM-dd')}</Row>
+                                    <Row>{l.createBy} {dateFormat(l.createTime, 'yyyy-MM-dd')}</Row>
                                 </Col>
                                 </Col>
                                 <Col span={2} style={{ textAlign: 'right' }}>
                                 <Col span={2} style={{ textAlign: 'right' }}>
                                     <Dropdown overlay={operationMenu} trigger={['click']}>
                                     <Dropdown overlay={operationMenu} trigger={['click']}>

+ 1 - 0
src/components/dashboardDesigner/layout.jsx

@@ -21,6 +21,7 @@ class DashboardDesigner extends React.Component {
         const { code } = this.props.match.params;
         const { code } = this.props.match.params;
         if (code !== 'create') {
         if (code !== 'create') {
             dispatch({ type: 'dashboard/remoteDetail', code: code });
             dispatch({ type: 'dashboard/remoteDetail', code: code });
+            dispatch({ type: 'main/addRecentRecord', tarId: code, recordType: 1})
         }
         }
     }
     }
 
 

+ 11 - 7
src/components/homePage/homePage.jsx

@@ -19,6 +19,12 @@ class HomePage extends React.Component {
         }
         }
     }
     }
 
 
+    componentDidMount() {
+        const { dispatch } = this.props;
+        dispatch({ type: 'main/fetchRecentChart' });
+        dispatch({ type: 'main/fetchRecentDashboard' });
+    }
+
     render() {
     render() {
         return (
         return (
             <Layout>
             <Layout>
@@ -28,16 +34,14 @@ class HomePage extends React.Component {
                             <Card>
                             <Card>
                                 <Markdown source={markdown}/>
                                 <Markdown source={markdown}/>
                             </Card>
                             </Card>
-                            <Card style={{display: 'none'}}>
-                                {/* TODO: 主页尚未上线,暂时隐藏  */}
+                            <Card>
                                 <CardList
                                 <CardList
-                                    mode='chart'
+                                    mode='homepage' type='chart' list={this.props.main.recentChart}
                                 />
                                 />
                             </Card>
                             </Card>
-                            <Card style={{display: 'none'}}>
-                                {/* TODO: 主页尚未上线,暂时隐藏  */}
+                            <Card>
                                 <CardList
                                 <CardList
-                                    mode='dashboard'
+                                    mode='homepage' type='dashboard' list={this.props.main.recentDashboard}
                                 />
                                 />
                             </Card>
                             </Card>
                         </Content>
                         </Content>
@@ -60,4 +64,4 @@ class HomePage extends React.Component {
     }
     }
 }
 }
 
 
-export default connect(({ present: { dashboard, homepage } }) =>  { return { homepage, dashboard}})(HomePage)
+export default connect(({ present: { main } }) =>  { return { main }})(HomePage)

+ 8 - 0
src/constants/url.js

@@ -174,5 +174,13 @@ const URLS = {
 
 
     HISTORY_DASHBOARD_LIST: BASE_URL + '/getDashRecode', // 查询看板浏览记录列表
     HISTORY_DASHBOARD_LIST: BASE_URL + '/getDashRecode', // 查询看板浏览记录列表
 
 
+    /***************************************主页模块***************************************/
+
+    HOMEPAGE_RECENT_CHART_GET: BASE_URL + "/getChartRecode", // 查询最近访问图表  //可能的错字
+
+    HOMEPAGE_RECENT_DASHBOARD_GET: BASE_URL + "/getDashRecode", //查询最近访问看板 //可能的错字
+
+    HOMEPAGE_ADD_RECENT_RECORD: BASE_URL + "/addRecord", //添加最近访问记录 
 }
 }
+
 export default URLS
 export default URLS

+ 100 - 0
src/models/main.js

@@ -1,5 +1,8 @@
 import { routerRedux } from 'dva/router'
 import { routerRedux } from 'dva/router'
 import { message } from 'antd'
 import { message } from 'antd'
+import * as service from '../services/index'
+import URLS from '../constants/url'
+
 
 
 const code = window.localStorage.getItem('usercode');
 const code = window.localStorage.getItem('usercode');
 const account = window.localStorage.getItem('account');
 const account = window.localStorage.getItem('account');
@@ -19,6 +22,8 @@ export default {
             role,
             role,
         },
         },
         currentPage: '',
         currentPage: '',
+        recentChart: [],
+        recentDashboard: []
     },
     },
     reducers: {
     reducers: {
         setPage(state, action) {
         setPage(state, action) {
@@ -37,6 +42,14 @@ export default {
         setAuthenticated(state, action) {
         setAuthenticated(state, action) {
             const { authenticated } = action;
             const { authenticated } = action;
             return { ...state, authenticated };
             return { ...state, authenticated };
+        },
+        listRecentChart(state, action) {
+            const { recentChart } = action;
+            return { ...state, recentChart };
+        },
+        listRecentDashboard(state, action) {
+            const { recentDashboard } = action;
+            return { ...state, recentDashboard };
         }
         }
     },
     },
     effects: {
     effects: {
@@ -76,6 +89,93 @@ export default {
                 console.log(e);
                 console.log(e);
                 message.error('注销失败: ' + e);
                 message.error('注销失败: ' + e);
             }
             }
+        },
+        *fetchRecentChart(action, { select, call, put }) {
+            const body = {};
+            try {
+                const main = yield select(state => state.present.main);
+                if(!action.mandatory && main.recentChart.length > 0) {
+                    return;
+                }
+                const res = yield call(service.fetch, {
+                    url: URLS.HOMEPAGE_RECENT_CHART_GET,
+                    body
+                });
+                
+                console.log('请求最近访问图表', body, res);
+                if(!res.err && res.data.code > 0) {
+                    let recentChart = res.data.data.map((r, i) => {
+                        return {
+                            key: r.chartId,
+                            code: r.chartId,
+                            name: r.chartName,
+                            type: r.chartType,
+                            createBy: r.createBy,
+                            chartOption: r.chartOption,
+                            description: r.describes || "",
+                            createTime: r.createDate,
+                        }
+                    });
+                    yield put({ type: 'listRecentChart', recentChart });
+                }else {
+                    message.error('读取最近访问图表列表错误: ' + (res.err || res.data.msg));
+                }
+            }catch(e) {
+                console.log(e);
+                message.error('读取最近访问图表列表错误: ' + e);
+            }
+        },
+        *fetchRecentDashboard(action, { select, call, put }) {
+            const body = {};
+            try {
+                const main = yield select(state => state.present.main);
+                if(!action.mandatory && main.recentDashboard.length > 0) {
+                    return;
+                }
+                const res = yield call(service.fetch, {
+                    url: URLS.HOMEPAGE_RECENT_DASHBOARD_GET,
+                    body
+                });
+                console.log('请求最近访问看板', body, res);
+                if(!res.err && res.data.code > 0) {
+                    let recentDashboard = res.data.data.map((r, i) => {
+                        return {
+                            key: r.id,
+                            code: r.id,
+                            name: r.bdName,
+                            thumbnail: r.thumbnail,
+                            createBy: r.createBy,
+                            description: r.bdNote || ""
+                        }
+                    });
+                    yield put({ type: 'listRecentDashboard', recentDashboard });
+                }else {
+                    message.error('读取最近访问看板列表错误: ' + (res.err || res.data.msg));
+                }
+            }catch(e) {
+                console.log(e);
+                message.error('读取最近访问看板列表错误: ' + e);
+            }
+            
+        },
+        *addRecentRecord(action, { call }) {
+            const { tarId, recordType } = action
+            console.log(tarId, recordType)
+            try {
+                const res = yield call(service.fetch, {
+                    url: URLS.HOMEPAGE_ADD_RECENT_RECORD,
+                    body: {
+                        tarId: tarId,
+                        type: recordType
+                    }
+                });
+                console.log("添加访问记录: " + res + tarId, recordType)
+            }catch(e) {
+                console.log(e);
+                message.error('添加访问记录错误: ' + e);
+            }
+
+
         }
         }
     },
     },
     subscriptions: {
     subscriptions: {