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

临时提交

上级 5b1795fc
import moment from 'moment';
import uuid from 'uuid/v4';
import _ from 'lodash';
import {} from '../../../services/modules';
import { datasourceApi } from '../../../services/datasource';
import { countTasks, fetchTasks } from '../../../services/bpm';
import config from '../../../utils/config';
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 name = 'task';
const namespace = _.uniqueId(prefix);
......@@ -15,10 +62,17 @@ const modelCreator = () => {
model: {
namespace,
state: {
columns: [],
num: 0,
list: [],
},
reducers: {
queryMetaSuccess(state, { payload: columns }) {
return {
...state,
columns,
}
},
queryCountSuccess(state, { payload: num }) {
return {
...state,
......@@ -33,9 +87,16 @@ const modelCreator = () => {
},
},
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 }) {
const num = Number.parseInt(yield call(countTasks, filters), 10);
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 { split } from '../utils/filter';
import { is } from '../utils/helper';
const parseFilters = filtersIn => (filtersIn || []).map(({ key, filter }) => [
`f-${split(key).map(value => value.replace(/#/g, '##').replace(/|/g, '#|')).join('|')}`,
filter,
]);
// const parseCoordinate = (coordinate) => {
// if (is(coordinate, 'String')) {
// return {
// query:
// }
// }
// }
export const datasourceApi = (coordinate) => {
const { containerType, containerName, datasourceName } = isString(coordinate) ? {
containerType: 'global',
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 queryParams = [
const makeQueryParams = ({ pst, psz, filters = [], params = {} }) => {
return [
...toPairs({ pst, psz }),
...parseFilters(filters),
...normParams(mapKeys(params, (v, k) => `p-${k}`)),
].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 = {} }) {
const queryParams = [
...parseFilters(filters),
...normParams(mapKeys(params, (v, k) => `p-${k}`)),
].filter(isUndefined);
return request(`/api/datasource/${name}/count`, queryParams);
export async function countGlobalDatasource(name, { filters = [], params = {} }) {
return request(`/api/datasource/${name}/count`, makeQueryParams({ filters, params }));
}
export async function getDatasourceMeta(name) {
export async function getGlobalDatasourceMeta(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') {
},
ua = agent || (navigator && navigator.userAgent),
ua = agent || (typeof navigator !== 'undefined' && navigator && navigator.userAgent),
loc = typeof window !== 'undefined' && window.location,
href = loc && loc.href,
m;
......
import fetch from 'dva/fetch';
import _ from 'lodash';
import { Resolver } from 'fastjson_ref_resolver';
import { getCookie, encrypt } from '../utils/helper';
import { cookie } from '../utils/config';
import { errors } from '../utils/error';
......@@ -56,7 +57,8 @@ function parseObject(response, { num2str = true, bool2str = true, nul2str = fals
};
const mapValue = _.curry(mapObj)(_, mapArr);
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) {
return response.text().then((text) => {
return require.ensure([], (require) => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论