|
@@ -101,23 +101,24 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
effects: {
|
|
effects: {
|
|
|
- *remoteList(action, { select, call, put, takeEvery, takeLatest }) {
|
|
|
|
|
|
|
+ *fetchList(action, { select, call, put, takeEvery, takeLatest }) {
|
|
|
try {
|
|
try {
|
|
|
const res = yield call(service.fetch, {
|
|
const res = yield call(service.fetch, {
|
|
|
url: URLS.DATASOURCE_LIST,
|
|
url: URLS.DATASOURCE_LIST,
|
|
|
body: {}
|
|
body: {}
|
|
|
});
|
|
});
|
|
|
let data = res.data.data.map((r, i) => {
|
|
let data = res.data.data.map((r, i) => {
|
|
|
- // r.dbConfig = JSON.parse(r.dbConfig);
|
|
|
|
|
|
|
+ let dbConfig = JSON.parse(r.dbConfig);
|
|
|
|
|
+ let tags = JSON.parse(r.dataTag);
|
|
|
return {
|
|
return {
|
|
|
- key: i,
|
|
|
|
|
|
|
+ key: r.dataId,
|
|
|
code: r.dataId,
|
|
code: r.dataId,
|
|
|
name: r.dataName,
|
|
name: r.dataName,
|
|
|
type: r.type || 'database',
|
|
type: r.type || 'database',
|
|
|
- dbType: 'oracle',
|
|
|
|
|
|
|
+ dbType: dbConfig.databaseType,
|
|
|
creator: r.createBy,
|
|
creator: r.createBy,
|
|
|
createTime: new Date(r.createDate),
|
|
createTime: new Date(r.createDate),
|
|
|
- tags: ['tttt', 'accc'],
|
|
|
|
|
|
|
+ tags: tags,
|
|
|
description: r.note
|
|
description: r.note
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -130,6 +131,107 @@ export default {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
+ *remoteAdd(action, { select, call, put }) {
|
|
|
|
|
+ const dataSource = yield select(state => state.present.dataSource);
|
|
|
|
|
+ const model = dataSource.newOne;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const data = {
|
|
|
|
|
+ dataName: model.name,
|
|
|
|
|
+ note: model.description,
|
|
|
|
|
+ loadObject: model.target,
|
|
|
|
|
+ dataTag: model.tags,
|
|
|
|
|
+ type: model.type,
|
|
|
|
|
+ createBy: 'admin',
|
|
|
|
|
+ dbConfig: {
|
|
|
|
|
+ addrass: model.address,
|
|
|
|
|
+ port: model.port,
|
|
|
|
|
+ databaseType: model.dbType,
|
|
|
|
|
+ dataName: model.dbName,
|
|
|
|
|
+ userName: model.userName,
|
|
|
|
|
+ passWord: model.password
|
|
|
|
|
+ },
|
|
|
|
|
+ columnConfig: model.columns.map((c, i) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ columnName: c.name,
|
|
|
|
|
+ columnLable: c.alias,
|
|
|
|
|
+ dataType: c.dataType,
|
|
|
|
|
+ columnType: c.columnType,
|
|
|
|
|
+ isGroup: c.groupable?'1':'0',
|
|
|
|
|
+ isSubsection: c.bucketizable?'1':'0',
|
|
|
|
|
+ isOpen: c.using?'1':'0',
|
|
|
|
|
+ remarks: c.description
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ };
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
|
|
+ url: URLS.DATASOURCE_ADD,
|
|
|
|
|
+ body: data
|
|
|
|
|
+ });
|
|
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
|
|
+ message.success('新增成功!');
|
|
|
|
|
+ yield put({ type: 'fetchList' });
|
|
|
|
|
+ }else {
|
|
|
|
|
+ message.error('新增失败!');
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch(e) {
|
|
|
|
|
+ message.error('新增失败!');
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ *remoteDetail(action, { select, call, put }) {
|
|
|
|
|
+ const dataSource = yield select(state => state.present.dataSource);
|
|
|
|
|
+ const model = dataSource.newOne;
|
|
|
|
|
+ const code = action.code;
|
|
|
|
|
+ if(model.code == code){
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
|
|
+ url: URLS.DATASOURCE_DETAIL,
|
|
|
|
|
+ body: code
|
|
|
|
|
+ });
|
|
|
|
|
+ let resData = res.data.data;
|
|
|
|
|
+ let columnConfig = JSON.parse(resData.columnConfig);
|
|
|
|
|
+ let dbConfig = JSON.parse(resData.dbConfig);
|
|
|
|
|
+ let tags = JSON.parse(resData.dataTag);
|
|
|
|
|
+ let data = {
|
|
|
|
|
+ code: resData.dataId,
|
|
|
|
|
+ name: resData.dataName,
|
|
|
|
|
+ type: resData.type,
|
|
|
|
|
+ dbType: dbConfig.databaseType,
|
|
|
|
|
+ dbName: dbConfig.dataName,
|
|
|
|
|
+ address: dbConfig.addrass,
|
|
|
|
|
+ port: dbConfig.port,
|
|
|
|
|
+ target: resData.loadObject,
|
|
|
|
|
+ creator: resData.createBy,
|
|
|
|
|
+ createTime: new Date(resData.createDate),
|
|
|
|
|
+ userName: dbConfig.userName,
|
|
|
|
|
+ password: dbConfig.passWord,
|
|
|
|
|
+ tags: tags,
|
|
|
|
|
+ description: resData.note,
|
|
|
|
|
+ columns: columnConfig.map((c, i) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ key: i,
|
|
|
|
|
+ using: c.isOpen=='1'?true:false,
|
|
|
|
|
+ name: c.columnName,
|
|
|
|
|
+ alias: c.columnLable,
|
|
|
|
|
+ dataType: c.dataType,
|
|
|
|
|
+ columnType: c.columnType,
|
|
|
|
|
+ groupable: c.isGroup=='1'?true:false,
|
|
|
|
|
+ bucketizable: c.isSubsection=='1'?true:false,
|
|
|
|
|
+ description: c.remarks
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ yield put({ type: 'setNewModel', model: data });
|
|
|
|
|
+ }catch(e) {
|
|
|
|
|
+ message.error('失败');
|
|
|
|
|
+ console.log(e);
|
|
|
|
|
+ yield put({ type: 'list', data: [] });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
*importNewModelColumns(action, { select, call, put }) {
|
|
*importNewModelColumns(action, { select, call, put }) {
|
|
|
const dataSource = yield select(state => state.present.dataSource);
|
|
const dataSource = yield select(state => state.present.dataSource);
|
|
|
const sqlStr = dataSource.newOne.target;
|
|
const sqlStr = dataSource.newOne.target;
|
|
@@ -141,18 +243,18 @@ export default {
|
|
|
});
|
|
});
|
|
|
console.log(res);
|
|
console.log(res);
|
|
|
|
|
|
|
|
- const getDataType = (columnType) => {
|
|
|
|
|
- let dataType = 'string';
|
|
|
|
|
- if(columnType == 'VARCHAR2') {
|
|
|
|
|
- dataType = 'categorical';
|
|
|
|
|
- }else if(columnType == 'NUMBER') {
|
|
|
|
|
- dataType = 'scale'
|
|
|
|
|
- }else if(columnType == 'DATE') {
|
|
|
|
|
- dataType = 'time'
|
|
|
|
|
- }else if(columnType == 'NUMBER') {
|
|
|
|
|
- dataType = 'scale'
|
|
|
|
|
|
|
+ const getColumnType = (dataType) => {
|
|
|
|
|
+ let columnType = 'string';
|
|
|
|
|
+ if(dataType == 'VARCHAR2') {
|
|
|
|
|
+ columnType = 'categorical';
|
|
|
|
|
+ }else if(dataType == 'NUMBER') {
|
|
|
|
|
+ columnType = 'scale'
|
|
|
|
|
+ }else if(dataType == 'DATE') {
|
|
|
|
|
+ columnType = 'time'
|
|
|
|
|
+ }else if(dataType == 'NUMBER') {
|
|
|
|
|
+ columnType = 'scale'
|
|
|
}
|
|
}
|
|
|
- return dataType;
|
|
|
|
|
|
|
+ return columnType;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(!res.err && res.data.code > 0) {
|
|
if(!res.err && res.data.code > 0) {
|
|
@@ -162,8 +264,8 @@ export default {
|
|
|
using: true,
|
|
using: true,
|
|
|
name: d.columnName,
|
|
name: d.columnName,
|
|
|
alias: d.remarks?d.remarks.substring(0, 10):'',
|
|
alias: d.remarks?d.remarks.substring(0, 10):'',
|
|
|
- columnType: d.columnType,
|
|
|
|
|
- dataType: getDataType(d.columnType),
|
|
|
|
|
|
|
+ dataType: d.columnType,
|
|
|
|
|
+ columnType: getColumnType(d.columnType),
|
|
|
groupable: d.columnType == 'VARCHAR2',
|
|
groupable: d.columnType == 'VARCHAR2',
|
|
|
bucketizable: d.columnType == 'NUMBER',
|
|
bucketizable: d.columnType == 'NUMBER',
|
|
|
description: d.remarks
|
|
description: d.remarks
|
|
@@ -172,15 +274,95 @@ export default {
|
|
|
yield put({ type: 'setNewModelField', name: 'columns', value: columns });
|
|
yield put({ type: 'setNewModelField', name: 'columns', value: columns });
|
|
|
}else {
|
|
}else {
|
|
|
yield put({ type: 'setNewModelField', name: 'columns', value: [] });
|
|
yield put({ type: 'setNewModelField', name: 'columns', value: [] });
|
|
|
- // 弹出错误提示
|
|
|
|
|
|
|
+ message.error('请求数据错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ *remoteDelete(action, { select, call, put }) {
|
|
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
|
|
+ url: URLS.DATASOURCE_DELETE,
|
|
|
|
|
+ body: [action.code]
|
|
|
|
|
+ });
|
|
|
|
|
+ yield put({ type: 'fetchList' });
|
|
|
|
|
+ },
|
|
|
|
|
+ *remoteModify(action, { select, call, put }) {
|
|
|
|
|
+ try{
|
|
|
|
|
+ const dataSource = yield select(state => state.present.dataSource);
|
|
|
|
|
+ let model = dataSource.newOne;
|
|
|
|
|
+ const code = action.code;
|
|
|
|
|
+ let list = dataSource.list;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ let data = {
|
|
|
|
|
+ dataId: code,
|
|
|
|
|
+ dataName: model.name,
|
|
|
|
|
+ note: model.description,
|
|
|
|
|
+ loadObject: model.target,
|
|
|
|
|
+ dataTag: model.tags,
|
|
|
|
|
+ type: model.type,
|
|
|
|
|
+ createBy: 'admin',
|
|
|
|
|
+ dbConfig: {
|
|
|
|
|
+ addrass: model.address,
|
|
|
|
|
+ port: model.port,
|
|
|
|
|
+ databaseType: model.dbType,
|
|
|
|
|
+ dataName: model.dbName,
|
|
|
|
|
+ userName: model.userName,
|
|
|
|
|
+ passWord: model.password
|
|
|
|
|
+ },
|
|
|
|
|
+ columnConfig: model.columns.map((c, i) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ columnName: c.name,
|
|
|
|
|
+ columnLable: c.alias,
|
|
|
|
|
+ dataType: c.dataType,
|
|
|
|
|
+ columnType: c.columnType,
|
|
|
|
|
+ isGroup: c.groupable?'1':'0',
|
|
|
|
|
+ isSubsection: c.bucketizable?'1':'0',
|
|
|
|
|
+ isOpen: c.using?'1':'0',
|
|
|
|
|
+ remarks: c.description
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ };
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
|
|
+ url: URLS.DATASOURCE_UPDATE,
|
|
|
|
|
+ body: data
|
|
|
|
|
+ });
|
|
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
|
|
+ list = list.map(l => {
|
|
|
|
|
+ if(l.code == action.code) {
|
|
|
|
|
+ l = model;
|
|
|
|
|
+ }
|
|
|
|
|
+ return l;
|
|
|
|
|
+ });
|
|
|
|
|
+ yield put({ type: 'list', data: list });
|
|
|
|
|
+ message.success('修改成功');
|
|
|
|
|
+ }else {
|
|
|
|
|
+ message.error('修改失败');
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch(e) {
|
|
|
|
|
+ message.error('修改失败');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
subscriptions: {
|
|
subscriptions: {
|
|
|
setup({ dispatch, history }) {
|
|
setup({ dispatch, history }) {
|
|
|
|
|
+ dispatch({ type: 'fetchList' })
|
|
|
return history.listen(({ pathname, query }) => {
|
|
return history.listen(({ pathname, query }) => {
|
|
|
- if(pathname.startsWith('/datasource')) {
|
|
|
|
|
- dispatch({ type: 'remoteList' })
|
|
|
|
|
|
|
+ let detail = pathname.match(/datasource\/(\w+)\/(\w+)/);
|
|
|
|
|
+ if(detail) {
|
|
|
|
|
+ if(pathname.match(/datasource\/(\w+)\/(\w+)\/(\w+)/)) {
|
|
|
|
|
+ detail = pathname.match(/datasource\/(\w+)\/(\w+)\/(\w+)/);
|
|
|
|
|
+ let type = detail[1];
|
|
|
|
|
+ let code = detail[2];
|
|
|
|
|
+ let tab = detail[3];
|
|
|
|
|
+ console.log(type, code, tab);
|
|
|
|
|
+ if(code != 'create') {
|
|
|
|
|
+ dispatch({ type: 'remoteDetail', code: code })
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ // 缺省跳转到属性配置tab
|
|
|
|
|
+ dispatch({ type: 'main/redirect', path: pathname + (pathname.endsWith('/') ? '' : '/') + 'base' })
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|