Browse Source

看板复制功能调整

zhuth 6 years ago
parent
commit
3b20aa1d6a

+ 12 - 12
src/components/dashboard/copyBox.jsx

@@ -8,26 +8,26 @@ class CopyBox extends React.Component {
     constructor(props) {
         super(props);
         this.state = {
-            currentDataSource: props.currentDataSource ? props.currentDataSource.code : null
+            currentDataConnectCode: props.currentDataConnect ? props.currentDataConnect.code : null
         }
     }
 
     componentDidMount() {
         const { dispatch } = this.props;
-        dispatch({ type: 'dataSource/fetchList' });
+        dispatch({ type: 'dataConnect/fetchList' });
     }
 
     generateOption() {
-        const { dataSource } = this.props;
-        const { currentDataSource } = this.state;
-        const { list } = dataSource;
+        const { dataConnect } = this.props;
+        const { currentDataConnectCode } = this.state;
+        const { list } = dataConnect;
 
-        return list.filter((l) => l.code !== currentDataSource).map((l) => <SelectOption key={l.code} value={l.code}>{l.name}</SelectOption>);
+        return list.filter((l) => l.code !== currentDataConnectCode).map((l) => <SelectOption key={l.code} value={l.code}>{l.name}</SelectOption>);
     }
 
     render() {
         const { visibleBox, hideBox, dispatch, currentDashboardCode } = this.props;
-        const { currentDataSource } = this.state;
+        const { currentDataConnectCode } = this.state;
         const formItemLayout = {
             labelCol: { span: 4 },
             wrapperCol: { span: 8 },
@@ -39,7 +39,7 @@ class CopyBox extends React.Component {
             visible={visibleBox}
             onCancel={hideBox}
             onOk={() => {
-                dispatch({ type: 'dashboard/copy', dashboardCode: currentDashboardCode, dataSourceCode: currentDataSource }).then(() => {
+                dispatch({ type: 'dashboard/copy', dashboardCode: currentDashboardCode, dataConnectCode: currentDataConnectCode }).then(() => {
                     hideBox();
                 });
             }}
@@ -53,11 +53,11 @@ class CopyBox extends React.Component {
                     {...formItemLayout}
                 >
                     <Select
-                        disabled={!currentDataSource}
-                        placeholder={currentDataSource ? '请选择...' : '无需选择数据源'}
+                        disabled={!currentDataConnectCode}
+                        placeholder={currentDataConnectCode ? '请选择...' : '无需选择数据源'}
                         onChange={(value) => {
                             this.setState({
-                                currentDataSource: value
+                                currentDataConnectCode: value
                             })
                         }}
                     >
@@ -69,4 +69,4 @@ class CopyBox extends React.Component {
     }
 }
 
-export default connect(({ present: { dataSource } }) => ({ dataSource }))(CopyBox)
+export default connect(({ present: { dataConnect } }) => ({ dataConnect }))(CopyBox)

+ 2 - 2
src/components/dashboard/list.jsx

@@ -138,7 +138,7 @@ class DashboardList extends React.Component {
                     <Icon type="swap" />移交
                 </Menu.Item>}
                 { selectedRecord && currentUser.code === selectedRecord.creatorCode && <Menu.Divider />}
-                { selectedRecord && (selectedRecord.dataSources.length <= 1) && <Menu.Item
+                { selectedRecord && (selectedRecord.dataConnects.length <= 1) && <Menu.Item
                     onClick={()=>{
                         this.setState({ visibleCopyBox: true})
                     }}
@@ -331,7 +331,7 @@ class DashboardList extends React.Component {
                     visibleBox={visibleCopyBox}
                     hideBox={()=>{this.setState({visibleCopyBox: false})}}
                     currentDashboardCode={selectedRecord.code}
-                    currentDataSource={selectedRecord.dataSources[0]}
+                    currentDataConnect={selectedRecord.dataConnects[0]}
                 />}
             </Layout>
         )

+ 16 - 14
src/components/dashboardDesigner/configSider.jsx

@@ -15,7 +15,7 @@ class ConfigSider extends React.Component {
             visibleChooseChartBox: false,
             visibleCusFilterBox: false,
             copyDisabled: false,
-            copyText: '复制链接'
+            copyText: '生成链接'
         };
     }
 
@@ -94,21 +94,23 @@ class ConfigSider extends React.Component {
                     onChange={(e) => {
                         dispatch({ type: 'dashboardDesigner/setField', name: 'shareCode', value: e.target.value });
                     }}
-                    addonAfter={<span style={{ cursor: copyDisabled ? 'not-allowed' : 'pointer' }} onClick={() => {
-                        if(copyDisabled) {
+                    addonAfter={<span style={{ cursor: (copyDisabled || !dashboardDesigner.shareCode) ? 'not-allowed' : 'pointer' }} onClick={() => {
+                        if(copyDisabled || !dashboardDesigner.shareCode) {
                             return;
                         }
-                        copy(window.location.origin + '/#/dashboard/share/' + dashboardDesigner.shareCode);
-                        this.setState({
-                            copyDisabled: true,
-                            copyText: '已复制'
-                        }, () => {
-                            setTimeout(() => {
-                                this.setState({
-                                    copyDisabled: false,
-                                    copyText: '复制链接'
-                                });
-                            }, 3000)
+                        dispatch({ type: 'dashboardDesigner/encryptCode', shareCode: dashboardDesigner.shareCode }).then(key => {
+                            copy(window.location.origin + '/#/dashboard/share/' + key);
+                            this.setState({
+                                copyDisabled: true,
+                                copyText: '已复制到剪贴板'
+                            }, () => {
+                                setTimeout(() => {
+                                    this.setState({
+                                        copyDisabled: false,
+                                        copyText: '生成链接'
+                                    });
+                                }, 3000)
+                            });
                         });
                     }}>{copyText}</span>}
                 />

+ 2 - 0
src/constants/url.js

@@ -178,6 +178,8 @@ const URLS = {
     
     DASHBOARD_SHARE_DETAIL_BY_KEY: BASE_URL + '/getSharedDashboard', // 通过看板分享链接获取看板数据
 
+    DASHBOARD_ENCRYPT_CODE: BASE_URL + '/encryptCode', // 通过看板编号获得加密串
+
     DASHBOARD_SHARE_DETAIL_BY_CODE: BASE_URL + '/getDashboardByCode', // 通过看板编号获得看板数据
 
     /***************************************浏览记录***************************************/

+ 6 - 2
src/models/chart.js

@@ -132,7 +132,6 @@ export default {
                     method: 'GET',
                     body
                 });
-                console.log('请求图表列表', body, res);
                 if(!res.err && res.data.code > 0) {
                     let list = res.data.data.list.map(d => {
                         let chartOption = d.chartOption ? JSON.parse(d.chartOption) : {};
@@ -141,6 +140,8 @@ export default {
                             name: d.chartName,
                             dataSourceCode: d.dataId + '',
                             dataSourceName: d.dataName,
+                            dataConnectCode: d.dataConnectionId,
+                            dataConnectName: d.dataConnectionName,
                             access: d.authority === '1', // 权限
                             database: d.dbStatus === '0', // 数据源是否还存在
                             type: CHART_TYPE[d.chartType],
@@ -158,7 +159,6 @@ export default {
                     message.error('请求图表列表失败: ' + (res.err || res.data.msg));
                 }
             }catch(e) {
-                console.log(body, e);
                 message.error('请求图表列表失败: ' + e);
             }
         },
@@ -188,6 +188,10 @@ export default {
                         code: resData.chartId + '',
                         creatorCode: resData.createId+'',
                         creatorName: resData.createBy,
+                        dataSourceCode: resData.dataId + '',
+                        dataSourceName: resData.dataName,
+                        dataConnectCode: resData.dataConnectionId,
+                        dataConnectName: resData.dataConnectionName,
                         header: {
                             label: resData.chartName
                         },

+ 18 - 16
src/models/dashboard.js

@@ -60,24 +60,25 @@ export default {
                     let list = resData.map(d => {
                         let items = d.bdConfiguration ? JSON.parse(d.bdConfiguration) : [];
 
-                        const allDataSources = items.map(item => {
+                        const dataSources = [];
+                        const dataConnects = [];
+                        items.forEach(item => {
                             if(item.viewType === 'chart') {
-                                return {
-                                    code: item.dataSourceCode,
-                                    name: item.dataSourceName
+                                if(!dataSources.find(ad => ad.code === item.dataSourceCode)) {
+                                    dataSources.push({
+                                        code: item.dataSourceCode,
+                                        name: item.dataSourceName
+                                    })
+                                }
+                                if(!dataConnects.find(ad => ad.code === item.dataSourceCode)) {
+                                    dataConnects.push({
+                                        code: item.dataConnectCode,
+                                        name: item.dataConnectName
+                                    })
                                 }
-                            }else {
-                                return null
                             }
-                        }).filter(item => !!item);
+                        })
     
-                        const dataSources = [];
-                        allDataSources.forEach(ad => {
-                            if(!dataSources.find(d => d.code === ad.code)) {
-                                dataSources.push(ad);
-                            }
-                        });
-
                         return {
                             key: d.id + '',
                             code:  d.id+'',
@@ -89,6 +90,7 @@ export default {
                             createTime: d.createDate,
                             shareCode: d.bdCode,
                             dataSources: dataSources,
+                            dataConnects: dataConnects,
                             chartCodes: d.chartIds ? d.chartIds.split(',') : [],
                             demo: d.demo
                         }
@@ -532,13 +534,13 @@ export default {
             }
         },
         *copy(action, { select, call, put }) {
-            const { dashboardCode, dataSourceCode } = action;
+            const { dashboardCode, dataConnectCode } = action;
 
             const res = yield call(service.fetch, {
                 url: URLS.DASHBOARD_COPY,
                 body: {
                     dashboardId: dashboardCode,
-                    dataSourceId: dataSourceCode
+                    dataSourceId: dataConnectCode
                 }
             });
             if(!res.err && res.data.code > 0) {

+ 18 - 26
src/models/dashboardDesigner.js

@@ -137,6 +137,8 @@ export default {
                 creatorName: chart.creatorName,
                 dataSourceCode: chart.dataSourceCode+'',
                 dataSourceName: chart.dataSourceName,
+                dataConnectCode: chart.dataConnectCode,
+                dataConnectName: chart.dataConnectName,
                 viewType: 'chart',
                 chartType: chart.type,
                 filters: chart.filters,
@@ -149,32 +151,6 @@ export default {
             });
             return Object.assign({}, state, {items, chartCodes, dataSources, dirty: true});
         },
-        addCharts(state, action) {
-            let { items, chartCodes, dataSources, defaultLayout } = state;
-            const { charts } = action;
-
-            items = items.concat(charts.map(c => {
-                dataSources.findIndex(d => d.code === c.dataSourceCode+'') === -1 && dataSources.push({
-                    code: c.dataSourceCode+'',
-                    name: c.dataSourceName
-                });
-                chartCodes.push(c.code);
-                return {
-                    code: c.code,
-                    chartCode: c.code,
-                    name: c.name,
-                    creatorCode: c.creatorCode,
-                    creatorName: c.creatorName,
-                    viewType: 'chart',
-                    chartType: c.type,
-                    dataSourceCode: c.dataSourceCode+'',
-                    dataSourceName: c.dataSourceName,
-                    filters: c.filters,
-                    layout: defaultLayout,
-                }
-            }));
-            return Object.assign({}, state, {items, chartCodes, dataSources, dirty: true});
-        },
         deleteItem(state, action) {
             let { items, chartCodes, dataSources, relationColumns, dirty } = state;
             const { item } = action;
@@ -489,6 +465,22 @@ export default {
                 console.log(e);
                 message.error('生成缩略图失败: ' + e);
             }
+        },
+        *encryptCode(action, { put, call, select }) {
+            const { shareCode } = action;
+            const res = yield call(service.fetch, {
+                url: URLS.DASHBOARD_ENCRYPT_CODE,
+                method: 'GET',
+                body: {
+                    code: shareCode
+                },
+            });
+            if(!res.err && res.data.code > 0) {
+                let resData = res.data.data;
+                return resData;
+            }else {
+                return false;
+            }
         }
     },
     subscriptions: {