@choerodon/master
Version:
A package of Master for Choerodon platform.
165 lines (147 loc) • 6.96 kB
JavaScript
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { useLocalStore } from 'mobx-react-lite';
import { flatMapDeep, map, merge, pick } from 'lodash';
import { axios } from "../../../../../..";
import mappings from "./mappings";
import barThumbnail from "../img/bar.svg";
import lineThumbnail from "../img/line.svg";
import pieThumbnail from "../img/pieNew.png";
import stackedBarThumbnail from "../img/stackedBar.svg";
export default function useStore(projectId) {
return useLocalStore(function () {
return {
initData: [],
setInitData: function setInitData(value) {
this.initData = value;
},
editLayout: [],
setEditLayout: function setEditLayout(value) {
this.editLayout = value;
},
isEdit: false,
setEdit: function setEdit(value) {
this.isEdit = value;
},
customData: new Map(),
setCustomData: function setCustomData(data) {
var customFlag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'agile';
Array.isArray(data) && this.customData.set('agile', new Map(data.map(function (item) {
return ["".concat(customFlag, "-").concat(item.layout.i), _objectSpread(_objectSpread({}, item), {}, {
layout: _objectSpread(_objectSpread({}, item.layout), {}, {
i: "".concat(customFlag, "-").concat(item.layout.i)
}),
name: "".concat(customFlag, "-").concat(item.name),
type: "".concat(customFlag, "-").concat(item.name) // 避免未来有其他模块自定义图表时id重复
})];
}))); // this.customData = data;
},
get customDataList() {
return flatMapDeep(_toConsumableArray(this.customData.values()).map(function (mapItem) {
return _toConsumableArray(mapItem.values());
}));
},
/**
* personalWorkload: {
layout: {
h: 4,
i: 'personalWorkload',
minH: 4,
minW: 4,
w: 6,
x: 0,
y: 33,
},
name: 'personalWorkload',
type: 'personalWorkload',
groupId: 'agile',
title: '个人工作量统计',
describe:
'此模块按问题计数、工时数2种维度统计当前迭代各个团队成员任务总量、完成量和剩余量。',
img: personalWorklo;ad,
},
*/
chartTypeToImg: {
pie: pieThumbnail,
bar: {
src: barThumbnail,
style: {
padding: 12
}
},
line: {
src: lineThumbnail,
style: {
padding: 12
}
},
stackedBar: {
src: stackedBarThumbnail,
style: {
padding: 12
}
}
},
loadAgileCustomData: function loadAgileCustomData() {
var _this = this;
axios.get("agile/v1/projects/".concat(projectId, "/custom_chart")).then(function (res) {
return _this.setCustomData(res === null || res === void 0 ? void 0 : res.map(function (item) {
var layout = {
h: 4,
i: item.id,
minH: 3,
minW: 4,
w: 5,
x: 0,
y: 33,
customFlag: 'agile'
};
return {
layout: layout,
name: item.id,
type: item.id,
// 增添时 会使用
groupId: 'agile',
title: item.name,
describe: item.description || '暂无描述',
customData: item,
img: _this.chartTypeToImg[item.chartType]
};
}));
});
},
getCustomChart: function getCustomChart(i) {
var customFlag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'agile';
if (!this.customData.has(customFlag)) {
return undefined;
}
return this.customData.get(customFlag).get(i);
},
saveConfig: function saveConfig(value) {
var _this2 = this;
var tempObj = map(value, function (item) {
var temp = pick(mappings[item.i] || _this2.getCustomChart(item.i), ['type', 'name', 'layout']);
temp.layout = merge(temp.layout, item);
return temp;
});
axios.post("iam/choerodon/v1/projects/".concat(projectId, "/project_overview_config"), JSON.stringify({
data: JSON.stringify(tempObj)
}));
},
totalOnlineUser: 0,
setTotalOnlineUser: function setTotalOnlineUser(data) {
this.totalOnlineUser = data;
},
get getTotalOnlineUser() {
return this.totalOnlineUser;
}
};
});
}