| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- // import { dictionary } from "./dictionary";
- /**为数组条件增加order属性 */
- function appendOrder(pageResult) {
- let r = [];
- let start = (pageResult.pageNumber - 1) * pageResult.pageSize + 1;
- if (pageResult.list) {
- pageResult.list.forEach((element) => {
- r.push({ order: start++, ...element });
- });
- }
- return r;
- }
- function findMaxIndex(array) {
- if (!array || array.length === 0) {
- return;
- }
- let max = Math.max(...array);
- return array.indexOf(max);
- }
- function setEchartsTooltip(
- myChart,
- xTooptipFormatter,
- yTooltipFormatter,
- seriesTooltipFormatter
- ) {
- myChart.on("mouseover", (params) => {
- xLabel = params.value;
- if (params.componentType === "yAxis") {
- myChart.setOption({
- tooltip: {
- formatter: yTooltipFormatter ? yTooltipFormatter : formateTooltip,
- alwaysShowContent: true,
- },
- });
- } else if (params.componentType === "series") {
- myChart.setOption({
- tooltip: {
- formatter: seriesTooltipFormatter,
- alwaysShowContent: true,
- },
- });
- } else if (params.componentType === "xAxis") {
- myChart.setOption({
- tooltip: {
- formatter: xTooptipFormatter ? xTooptipFormatter : formateTooltip,
- alwaysShowContent: true,
- },
- });
- } else {
- return;
- }
- let offsetX = params.event.offsetX + 10;
- let offsetY = params.event.offsetY + 10;
- myChart.dispatchAction({
- type: "showTip",
- seriesIndex: 0,
- dataIndex: 0,
- position: [offsetX, offsetY],
- });
- });
- myChart.on("mouseout", (params) => {
- xLabel = "";
- myChart.setOption({
- tooltip: {
- formatter: null,
- alwaysShowContent: false,
- },
- });
- });
- }
- var xLabel = "";
- function formateTooltip(params) {
- return xLabel;
- }
- function getChartDOMSize(chart) {
- if (!chart) {
- return;
- }
- let width = chart._dom.clientWidth;
- let height = chart._dom.clientHeight;
- return { width, height };
- }
- /**
- * 生成树
- * treelist:所有机构列表
- * topOrgId:顶级机构id,没有则自动查找
- * miniorType:显示到的最低级机构类型,没有则显示全部
- */
- function getOrgTree(treelist, topOrgId, miniorType) {
- let data = treelist;
- if (!data || data.length === 0) {
- this.selectedOrg = null;
- this.defaultExpandedKeys = [];
- return [];
- } else {
- if (!topOrgId) {
- const topOrg = data.find(
- (d) => !data.find((d2) => d2.orgId == d.parentId)
- );
- if (topOrg) {
- topOrgId = topOrg.orgId;
- } else {
- return [];
- }
- }
- let temp = data.find((d) => d.orgId == topOrgId);
- if (!temp) {
- return [];
- }
- let top = { id: temp.orgId, label: temp.orgName };
- top.children = convertToTreeData(data, temp, miniorType);
- return [top];
- }
- }
- //将机构列表转换为树结构
- function convertToTreeData(array, parent, miniorType) {
- if (!parent || parent.orgType == miniorType) {
- return [];
- }
- let nodes = array.filter((i) => i.parentId == parent.orgId);
- let list = [];
- nodes.forEach((child) => {
- let c = { id: child.orgId, label: child.orgName };
- let children = convertToTreeData(array, child, miniorType);
- if (children && children.length > 0) {
- c.children = children;
- }
- list.push(c);
- });
- return list;
- }
- // /**找到该机构的上级分行 */
- // function getBranchOrg(orgList, current) {
- // if (dictionary.orgType.isBranchType(current.orgType)) {
- // return current;
- // }
- // var up = current;
- // while (!dictionary.orgType.isBranchType(up.orgType)) {
- // up = orgList.find((o) => o.orgId == up.parentId);
- // if (!up) {
- // return;
- // }
- // }
- // return up;
- // }
- // function getBranchOrgById(orgList, orgId) {
- // let org = orgList.find((org) => org.orgId == orgId);
- // return getBranchOrg(orgList, org);
- // }
- function getURLParam(url, queryName) {
- if (!url) {
- return null;
- }
- let strs = url.split("?");
- if (strs.length < 2) {
- return "";
- }
- var query = strs[1];
- var vars = query.split("&");
- for (var i = 0; i < vars.length; i++) {
- var pair = vars[i].split("=");
- if (pair[0] == queryName) {
- return pair[1];
- }
- }
- return null;
- }
- function replaceEmptyProperty(obj, defaultValue) {
- let copy = { ...obj };
- for (var p in copy) {
- if ((typeof copy[p] == "string" && copy[p] == "") || copy[p] == null) {
- copy[p] = defaultValue;
- }
- }
- return copy;
- }
- /**********************时间周期定制 **************/
- /**返回时间周期tab中的下一个 */
- function getNextPeriod(periods, current) {
- let currentIndex = periods.map((t) => t.value).indexOf(current);
- var nextIndex = periods.length - 1 == currentIndex ? 0 : currentIndex + 1;
- let next = periods[nextIndex].value;
- return next;
- }
- /**返回时间周期对应的文件描述 */
- function getPeriodText(periods, value) {
- const period = periods.find((p) => p.value == value);
- if (period) {
- return period.text;
- }
- return "";
- }
- /**********************时间周期定制 **************/
- export {
- appendOrder,
- findMaxIndex,
- setEchartsTooltip,
- getChartDOMSize,
- getOrgTree,
- getURLParam,
- replaceEmptyProperty,
- getNextPeriod,
- getPeriodText
- };
|