提交 c60b339d authored 作者: vipcxj's avatar vipcxj

临时提交

上级 5b1795fc
import moment from 'moment'; import moment from 'moment';
import uuid from 'uuid/v4'; import uuid from 'uuid/v4';
import _ from 'lodash'; import _ from 'lodash';
import {} from '../../../services/modules'; import { datasourceApi } from '../../../services/datasource';
import { countTasks, fetchTasks } from '../../../services/bpm'; import { countTasks, fetchTasks } from '../../../services/bpm';
import config from '../../../utils/config'; import config from '../../../utils/config';
const prefix = uuid(); const prefix = uuid();
const getMeta = (property, name, parsed = false, defaultValue) => {
if (!property) {
return defaultValue;
}
const names = _.castArray(name);
const result = [];
_.some(names, (v) => {
const ret = property[v];
if (!_.isUndefined(ret)) {
result.push(parsed ? JSON.parse(ret) : ret);
return true;
}
return false;
});
return result.length > 0 ? result[0] : defaultValue;
};
const makeColumns = (meta) => {
return (meta.properties || [])
.filter(property => !property.skip)
.map((property, idx) => ({
title: getMeta(property, ['label', 'title'], false, property.name),
dataIndex: idx,
key: property.name,
filterType: getMeta(property, 'filterType'),
filterEnums: getMeta(property, 'filterEnums', true),
order: _.toNumber(getMeta(property, 'order', false, 0)),
group: getMeta(property, 'group'),
}));
};
const getArrayData = ({ dataType, arrayData, singularData }, meta) => {
if (dataType === 'TABLE') {
return arrayData || [];
} else if (dataType === 'PROPERTIES') {
const data = [];
(meta.properties || [])
.filter(property => !property.skip)
.forEach((property) => {
data.push((singularData || {})[property.name]);
});
return [data];
} else {
throw new Error(`Unsupported data type: ${dataType}`);
}
};
const modelCreator = () => { const modelCreator = () => {
const name = 'task'; const name = 'task';
const namespace = _.uniqueId(prefix); const namespace = _.uniqueId(prefix);
...@@ -15,10 +62,17 @@ const modelCreator = () => { ...@@ -15,10 +62,17 @@ const modelCreator = () => {
model: { model: {
namespace, namespace,
state: { state: {
columns: [],
num: 0, num: 0,
list: [], list: [],
}, },
reducers: { reducers: {
queryMetaSuccess(state, { payload: columns }) {
return {
...state,
columns,
}
},
queryCountSuccess(state, { payload: num }) { queryCountSuccess(state, { payload: num }) {
return { return {
...state, ...state,
...@@ -33,9 +87,16 @@ const modelCreator = () => { ...@@ -33,9 +87,16 @@ const modelCreator = () => {
}, },
}, },
effects: { effects: {
// *fetchData({ payload: { coordinate, pst, psz, params, filters} }, { put, call }) { *fetchData({ payload: { coordinate, pst, psz, params, filters} }, { put, call }) {
// const options = { pst, psz, params, filters };
// } const api = datasourceApi(coordinate);
const meta = api.meta();
yield put({ type: 'queryMetaSuccess', payload: makeColumns(meta) });
const num = yield call(api.count, options);
yield put({ type: 'queryCountSuccess', payload: num });
const dsb = yield call(api.query, options);
yield put({ type: 'queryTasksSuccess', payload: getArrayData(dsb, meta) });
},
*fetchTasks({ payload: { pst, psz, filters } }, { put, call }) { *fetchTasks({ payload: { pst, psz, filters } }, { put, call }) {
const num = Number.parseInt(yield call(countTasks, filters), 10); const num = Number.parseInt(yield call(countTasks, filters), 10);
yield put({ type: 'queryCountSuccess', payload: num }); yield put({ type: 'queryCountSuccess', payload: num });
......
import { mapKeys, toPairs, isUndefined } from 'lodash'; import { mapKeys, toPairs, isUndefined, isString, curry } from 'lodash';
import request, { normParams } from '../utils/request'; import request, { normParams } from '../utils/request';
import { split } from '../utils/filter'; import { split } from '../utils/filter';
import { is } from '../utils/helper';
const parseFilters = filtersIn => (filtersIn || []).map(({ key, filter }) => [ const parseFilters = filtersIn => (filtersIn || []).map(({ key, filter }) => [
`f-${split(key).map(value => value.replace(/#/g, '##').replace(/|/g, '#|')).join('|')}`, `f-${split(key).map(value => value.replace(/#/g, '##').replace(/|/g, '#|')).join('|')}`,
filter, filter,
]); ]);
// const parseCoordinate = (coordinate) => { export const datasourceApi = (coordinate) => {
// if (is(coordinate, 'String')) { const { containerType, containerName, datasourceName } = isString(coordinate) ? {
// return { containerType: 'global',
// query: moduleName: coordinate,
// } } : (coordinate || {});
// } if (containerType === 'global') {
// } return {
query: curry(calcGlobalDatasource)(datasourceName),
count: curry(countGlobalDatasource)(datasourceName),
meta: curry(getGlobalDatasourceMeta)(datasourceName),
};
} else if (containerType === 'module') {
return {
query: curry(calcModuleDatasource)(containerName, datasourceName),
count: curry(countModuleDatasource)(containerName, datasourceName),
meta: curry(getModuleDatasourceMeta)(containerName, datasourceName),
};
} else {
throw new Error(`Unsupported containerType: ${containerType}`);
}
};
export async function calcDatasource(coordinate, { pst, psz, filters = [], params = {} }) { const makeQueryParams = ({ pst, psz, filters = [], params = {} }) => {
const queryParams = [ return [
...toPairs({ pst, psz }), ...toPairs({ pst, psz }),
...parseFilters(filters), ...parseFilters(filters),
...normParams(mapKeys(params, (v, k) => `p-${k}`)), ...normParams(mapKeys(params, (v, k) => `p-${k}`)),
].filter(isUndefined); ].filter(isUndefined);
return request(`/api/datasource/${name}`, queryParams); };
export async function calcGlobalDatasource(name, { pst, psz, filters = [], params = {} }) {
return request(`/api/datasource/${name}`, makeQueryParams({ pst, psz, filters, params }));
} }
export async function countDatasource(name, { filters = [], params = {} }) { export async function countGlobalDatasource(name, { filters = [], params = {} }) {
const queryParams = [ return request(`/api/datasource/${name}/count`, makeQueryParams({ filters, params }));
...parseFilters(filters),
...normParams(mapKeys(params, (v, k) => `p-${k}`)),
].filter(isUndefined);
return request(`/api/datasource/${name}/count`, queryParams);
} }
export async function getDatasourceMeta(name) { export async function getGlobalDatasourceMeta(name) {
return request(`/api/datasource/${name}`); return request(`/api/datasource/${name}`);
} }
export async function calcModuleDatasource(mdName, dsName, { pst, psz, filters = [], params = {} }) {
return request(`/api/modules/module/${mdName}/datasource/${dsName}`, makeQueryParams({ pst, psz, filters, params }));
}
export async function countModuleDatasource(mdName, dsName, { filters = [], params = {} }) {
return request(`/api/modules/module/${mdName}/datasource/${dsName}/count`, makeQueryParams({ filters, params }));
}
export async function getModuleDatasourceMeta(mdName, dsName) {
return request(`/api/modules/module/${mdName}/datasource/${dsName}/meta`);
}
...@@ -1935,7 +1935,7 @@ if (typeof window === 'undefined') { ...@@ -1935,7 +1935,7 @@ if (typeof window === 'undefined') {
}, },
ua = agent || (navigator && navigator.userAgent), ua = agent || (typeof navigator !== 'undefined' && navigator && navigator.userAgent),
loc = typeof window !== 'undefined' && window.location, loc = typeof window !== 'undefined' && window.location,
href = loc && loc.href, href = loc && loc.href,
m; m;
......
import fetch from 'dva/fetch'; import fetch from 'dva/fetch';
import _ from 'lodash'; import _ from 'lodash';
import { Resolver } from 'fastjson_ref_resolver';
import { getCookie, encrypt } from '../utils/helper'; import { getCookie, encrypt } from '../utils/helper';
import { cookie } from '../utils/config'; import { cookie } from '../utils/config';
import { errors } from '../utils/error'; import { errors } from '../utils/error';
...@@ -56,7 +57,8 @@ function parseObject(response, { num2str = true, bool2str = true, nul2str = fals ...@@ -56,7 +57,8 @@ function parseObject(response, { num2str = true, bool2str = true, nul2str = fals
}; };
const mapValue = _.curry(mapObj)(_, mapArr); const mapValue = _.curry(mapObj)(_, mapArr);
if (contentType.indexOf('json') !== -1) { if (contentType.indexOf('json') !== -1) {
return needMap ? response.json().then(mapValue) : response.json(); const json = needMap ? response.json().then(mapValue) : response.json();
return new Resolver(json).resolve();
} else if (contentType.indexOf('xml') !== -1) { } else if (contentType.indexOf('xml') !== -1) {
return response.text().then((text) => { return response.text().then((text) => {
return require.ensure([], (require) => { return require.ensure([], (require) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论