|
@@ -1,46 +1,46 @@
|
|
export const uuid = (len = 16, radix = 10) => {
|
|
export const uuid = (len = 16, radix = 10) => {
|
|
const chars =
|
|
const chars =
|
|
- '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
|
|
|
|
- const uuid = []
|
|
|
|
- let i
|
|
|
|
- radix = radix || chars.length
|
|
|
|
|
|
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
|
|
|
|
+ const uuid = [];
|
|
|
|
+ let i;
|
|
|
|
+ radix = radix || chars.length;
|
|
if (len) {
|
|
if (len) {
|
|
// Compact form
|
|
// Compact form
|
|
- for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]
|
|
|
|
|
|
+ for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
|
|
} else {
|
|
} else {
|
|
// rfc4122, version 4 form
|
|
// rfc4122, version 4 form
|
|
- let r
|
|
|
|
|
|
+ let r;
|
|
|
|
|
|
// rfc4122 requires these characters
|
|
// rfc4122 requires these characters
|
|
- uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
|
|
|
|
- uuid[14] = '4'
|
|
|
|
|
|
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
|
|
|
|
+ uuid[14] = "4";
|
|
|
|
|
|
// Fill in random data. At i==19 set the high bits of clock sequence as
|
|
// Fill in random data. At i==19 set the high bits of clock sequence as
|
|
// per rfc4122, sec. 4.1.5
|
|
// per rfc4122, sec. 4.1.5
|
|
for (i = 0; i < 36; i++) {
|
|
for (i = 0; i < 36; i++) {
|
|
if (!uuid[i]) {
|
|
if (!uuid[i]) {
|
|
- r = 0 | (Math.random() * 16)
|
|
|
|
- uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r]
|
|
|
|
|
|
+ r = 0 | (Math.random() * 16);
|
|
|
|
+ uuid[i] = chars[i === 19 ? (r & 0x3) | 0x8 : r];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return uuid.join('')
|
|
|
|
-}
|
|
|
|
|
|
+ return uuid.join("");
|
|
|
|
+};
|
|
|
|
|
|
export const copy = (data) => {
|
|
export const copy = (data) => {
|
|
- var copy = document.createElement('p')
|
|
|
|
- copy.innerText = data
|
|
|
|
- document.body.append(copy)
|
|
|
|
- var range = document.createRange()
|
|
|
|
- range.selectNode(copy)
|
|
|
|
- var selection = window.getSelection()
|
|
|
|
|
|
+ var copy = document.createElement("p");
|
|
|
|
+ copy.innerText = data;
|
|
|
|
+ document.body.append(copy);
|
|
|
|
+ var range = document.createRange();
|
|
|
|
+ range.selectNode(copy);
|
|
|
|
+ var selection = window.getSelection();
|
|
if (selection) {
|
|
if (selection) {
|
|
- if (selection.rangeCount > 0) selection.removeAllRanges()
|
|
|
|
- selection.addRange(range)
|
|
|
|
|
|
+ if (selection.rangeCount > 0) selection.removeAllRanges();
|
|
|
|
+ selection.addRange(range);
|
|
}
|
|
}
|
|
- document.execCommand('copy')
|
|
|
|
- document.body.removeChild(copy)
|
|
|
|
-}
|
|
|
|
|
|
+ document.execCommand("copy");
|
|
|
|
+ document.body.removeChild(copy);
|
|
|
|
+};
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
@@ -52,22 +52,22 @@ export const copy = (data) => {
|
|
* @description 根据圆心坐标、旋转角度计算旋转后的坐标
|
|
* @description 根据圆心坐标、旋转角度计算旋转后的坐标
|
|
*/
|
|
*/
|
|
export const getRotatePosition = (positionData) => {
|
|
export const getRotatePosition = (positionData) => {
|
|
- const radian = (Math.PI / 180) * positionData.rotate
|
|
|
|
|
|
+ const radian = (Math.PI / 180) * positionData.rotate;
|
|
return {
|
|
return {
|
|
x:
|
|
x:
|
|
(positionData.originPosition.x - positionData.centerPosition.x) *
|
|
(positionData.originPosition.x - positionData.centerPosition.x) *
|
|
- Math.cos(radian) -
|
|
|
|
|
|
+ Math.cos(radian) -
|
|
(positionData.originPosition.y - positionData.centerPosition.y) *
|
|
(positionData.originPosition.y - positionData.centerPosition.y) *
|
|
- Math.sin(radian) +
|
|
|
|
|
|
+ Math.sin(radian) +
|
|
positionData.centerPosition.x,
|
|
positionData.centerPosition.x,
|
|
y:
|
|
y:
|
|
(positionData.originPosition.y - positionData.centerPosition.y) *
|
|
(positionData.originPosition.y - positionData.centerPosition.y) *
|
|
- Math.cos(radian) +
|
|
|
|
|
|
+ Math.cos(radian) +
|
|
(positionData.originPosition.x - positionData.centerPosition.x) *
|
|
(positionData.originPosition.x - positionData.centerPosition.x) *
|
|
- Math.sin(radian) +
|
|
|
|
- positionData.centerPosition.y
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ Math.sin(radian) +
|
|
|
|
+ positionData.centerPosition.y,
|
|
|
|
+ };
|
|
|
|
+};
|
|
|
|
|
|
/**
|
|
/**
|
|
* @description 防抖
|
|
* @description 防抖
|
|
@@ -76,15 +76,15 @@ export const getRotatePosition = (positionData) => {
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
export function _debounce(fn, wait = 500) {
|
|
export function _debounce(fn, wait = 500) {
|
|
- let timer
|
|
|
|
|
|
+ let timer;
|
|
return function () {
|
|
return function () {
|
|
- const context = this
|
|
|
|
- const args = arguments
|
|
|
|
- if (timer) clearTimeout(timer)
|
|
|
|
|
|
+ const context = this;
|
|
|
|
+ const args = arguments;
|
|
|
|
+ if (timer) clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
timer = setTimeout(() => {
|
|
- fn.apply(context, args)
|
|
|
|
- }, wait)
|
|
|
|
- }
|
|
|
|
|
|
+ fn.apply(context, args);
|
|
|
|
+ }, wait);
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -94,20 +94,20 @@ export function _debounce(fn, wait = 500) {
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
export function _throttle(fn, wait = 500) {
|
|
export function _throttle(fn, wait = 500) {
|
|
- let last, timer, now
|
|
|
|
|
|
+ let last, timer, now;
|
|
return function () {
|
|
return function () {
|
|
- now = Date.now()
|
|
|
|
|
|
+ now = Date.now();
|
|
if (last && now - last < wait) {
|
|
if (last && now - last < wait) {
|
|
- clearTimeout(timer)
|
|
|
|
|
|
+ clearTimeout(timer);
|
|
timer = setTimeout(function () {
|
|
timer = setTimeout(function () {
|
|
- last = now
|
|
|
|
- fn.call(this, ...arguments)
|
|
|
|
- }, wait)
|
|
|
|
|
|
+ last = now;
|
|
|
|
+ fn.call(this, ...arguments);
|
|
|
|
+ }, wait);
|
|
} else {
|
|
} else {
|
|
- last = now
|
|
|
|
- fn.call(this, ...arguments)
|
|
|
|
|
|
+ last = now;
|
|
|
|
+ fn.call(this, ...arguments);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -118,34 +118,34 @@ export function _throttle(fn, wait = 500) {
|
|
export const hasPermission = (permissionList, routerName) => {
|
|
export const hasPermission = (permissionList, routerName) => {
|
|
return permissionList.some((permission) => {
|
|
return permissionList.some((permission) => {
|
|
if (permission.code === routerName) {
|
|
if (permission.code === routerName) {
|
|
- return true
|
|
|
|
|
|
+ return true;
|
|
} else {
|
|
} else {
|
|
return (
|
|
return (
|
|
permission.children &&
|
|
permission.children &&
|
|
permission.children.length &&
|
|
permission.children.length &&
|
|
permission.children.find((child) => {
|
|
permission.children.find((child) => {
|
|
if (child.code === routerName) {
|
|
if (child.code === routerName) {
|
|
- return true
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- )
|
|
|
|
|
|
+ );
|
|
}
|
|
}
|
|
- })
|
|
|
|
-}
|
|
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
|
|
// 后端返回二进制流下载文件
|
|
// 后端返回二进制流下载文件
|
|
-export const downloadBlob = (blob, fileName = 'download') => {
|
|
|
|
- const reader = new FileReader()
|
|
|
|
- reader.readAsDataURL(blob)
|
|
|
|
|
|
+export const downloadBlob = (blob, fileName = "download") => {
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
+ reader.readAsDataURL(blob);
|
|
reader.onload = (e) => {
|
|
reader.onload = (e) => {
|
|
- const a = document.createElement('a')
|
|
|
|
- a.download = fileName
|
|
|
|
- a.href = e.target.result
|
|
|
|
- document.body.appendChild(a)
|
|
|
|
- a.click()
|
|
|
|
- document.body.removeChild(a)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ const a = document.createElement("a");
|
|
|
|
+ a.download = fileName;
|
|
|
|
+ a.href = e.target.result;
|
|
|
|
+ document.body.appendChild(a);
|
|
|
|
+ a.click();
|
|
|
|
+ document.body.removeChild(a);
|
|
|
|
+ };
|
|
|
|
+};
|
|
|
|
|
|
/**
|
|
/**
|
|
* @description base64下载word
|
|
* @description base64下载word
|
|
@@ -155,92 +155,92 @@ export const downloadWord = (base64Data, filename) => {
|
|
// 创建Blob对象
|
|
// 创建Blob对象
|
|
var blob = base64ToBlob(
|
|
var blob = base64ToBlob(
|
|
base64Data,
|
|
base64Data,
|
|
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
|
|
- )
|
|
|
|
|
|
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
|
|
+ );
|
|
|
|
|
|
// 创建下载链接
|
|
// 创建下载链接
|
|
- var url = URL.createObjectURL(blob)
|
|
|
|
- var downloadLink = document.createElement('a')
|
|
|
|
|
|
+ var url = URL.createObjectURL(blob);
|
|
|
|
+ var downloadLink = document.createElement("a");
|
|
|
|
|
|
// 设置下载链接属性
|
|
// 设置下载链接属性
|
|
- downloadLink.href = url
|
|
|
|
- downloadLink.download = filename
|
|
|
|
|
|
+ downloadLink.href = url;
|
|
|
|
+ downloadLink.download = filename;
|
|
|
|
|
|
// 触发下载
|
|
// 触发下载
|
|
- document.body.appendChild(downloadLink)
|
|
|
|
- downloadLink.click()
|
|
|
|
- document.body.removeChild(downloadLink)
|
|
|
|
- URL.revokeObjectURL(url) // 清理
|
|
|
|
-}
|
|
|
|
|
|
+ document.body.appendChild(downloadLink);
|
|
|
|
+ downloadLink.click();
|
|
|
|
+ document.body.removeChild(downloadLink);
|
|
|
|
+ URL.revokeObjectURL(url); // 清理
|
|
|
|
+};
|
|
|
|
|
|
export const base64ToBlob = (base64, mimeType) => {
|
|
export const base64ToBlob = (base64, mimeType) => {
|
|
// 解码Base64字符串
|
|
// 解码Base64字符串
|
|
- var byteCharacters = atob(base64.replace(/^data:\w+\/\w+;base64,/, ''))
|
|
|
|
|
|
+ var byteCharacters = atob(base64.replace(/^data:\w+\/\w+;base64,/, ""));
|
|
|
|
|
|
// 将解码的字符串转换为类型化数组
|
|
// 将解码的字符串转换为类型化数组
|
|
- var byteNumbers = new Array(byteCharacters.length)
|
|
|
|
|
|
+ var byteNumbers = new Array(byteCharacters.length);
|
|
for (var i = 0; i < byteCharacters.length; i++) {
|
|
for (var i = 0; i < byteCharacters.length; i++) {
|
|
- byteNumbers[i] = byteCharacters.charCodeAt(i)
|
|
|
|
|
|
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
}
|
|
}
|
|
|
|
|
|
// 创建Blob对象
|
|
// 创建Blob对象
|
|
- var byteArray = new Uint8Array(byteNumbers)
|
|
|
|
- return new Blob([byteArray], { type: mimeType })
|
|
|
|
-}
|
|
|
|
|
|
+ var byteArray = new Uint8Array(byteNumbers);
|
|
|
|
+ return new Blob([byteArray], { type: mimeType });
|
|
|
|
+};
|
|
|
|
|
|
export const downloadExcel = (base64Data, filename, type) => {
|
|
export const downloadExcel = (base64Data, filename, type) => {
|
|
const blobs = type
|
|
const blobs = type
|
|
- ? 'application/vnd.ms-excel'
|
|
|
|
- : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
|
|
|
+ ? "application/vnd.ms-excel"
|
|
|
|
+ : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
// 创建Blob对象
|
|
// 创建Blob对象
|
|
- var blob = base64ToBlob(base64Data, blobs)
|
|
|
|
|
|
+ var blob = base64ToBlob(base64Data, blobs);
|
|
|
|
|
|
// 创建下载链接
|
|
// 创建下载链接
|
|
- var url = URL.createObjectURL(blob)
|
|
|
|
- var downloadLink = document.createElement('a')
|
|
|
|
|
|
+ var url = URL.createObjectURL(blob);
|
|
|
|
+ var downloadLink = document.createElement("a");
|
|
|
|
|
|
// 设置下载链接属性
|
|
// 设置下载链接属性
|
|
- downloadLink.href = url
|
|
|
|
- downloadLink.download = filename
|
|
|
|
|
|
+ downloadLink.href = url;
|
|
|
|
+ downloadLink.download = filename;
|
|
|
|
|
|
// 触发下载
|
|
// 触发下载
|
|
- document.body.appendChild(downloadLink)
|
|
|
|
- downloadLink.click()
|
|
|
|
- document.body.removeChild(downloadLink)
|
|
|
|
- URL.revokeObjectURL(url) // 清理
|
|
|
|
-}
|
|
|
|
|
|
+ document.body.appendChild(downloadLink);
|
|
|
|
+ downloadLink.click();
|
|
|
|
+ document.body.removeChild(downloadLink);
|
|
|
|
+ URL.revokeObjectURL(url); // 清理
|
|
|
|
+};
|
|
// 时间戳转化为时间
|
|
// 时间戳转化为时间
|
|
export function convertTimestamp(timestamp) {
|
|
export function convertTimestamp(timestamp) {
|
|
- const date = new Date(timestamp)
|
|
|
|
- const year = date.getFullYear()
|
|
|
|
- const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
|
|
- const day = String(date.getDate()).padStart(2, '0')
|
|
|
|
- const hours = String(date.getHours()).padStart(2, '0')
|
|
|
|
- const minutes = String(date.getMinutes()).padStart(2, '0')
|
|
|
|
- const seconds = String(date.getSeconds()).padStart(2, '0')
|
|
|
|
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
|
|
|
|
|
+ const date = new Date(timestamp);
|
|
|
|
+ const year = date.getFullYear();
|
|
|
|
+ const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
|
|
+ const day = String(date.getDate()).padStart(2, "0");
|
|
|
|
+ const hours = String(date.getHours()).padStart(2, "0");
|
|
|
|
+ const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
|
|
+ const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
|
|
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
}
|
|
}
|
|
// 格式化时间
|
|
// 格式化时间
|
|
export function formatDate(timestamp, formate) {
|
|
export function formatDate(timestamp, formate) {
|
|
- const date = new Date()
|
|
|
|
- date.setTime(parseInt(timestamp))
|
|
|
|
|
|
+ const date = new Date();
|
|
|
|
+ date.setTime(parseInt(timestamp));
|
|
// 传入formate形式 yyyy-MM-dd yyyy-MM-dd hh:mm
|
|
// 传入formate形式 yyyy-MM-dd yyyy-MM-dd hh:mm
|
|
- formate = formate != null ? formate : 'yyyy-MM-dd'
|
|
|
|
|
|
+ formate = formate != null ? formate : "yyyy-MM-dd";
|
|
const Format = function (fmt) {
|
|
const Format = function (fmt) {
|
|
var o = {
|
|
var o = {
|
|
- 'M+': date.getMonth() + 1, // 月
|
|
|
|
- 'd+': date.getDate(), // 日
|
|
|
|
- 'h+': date.getHours(), // 小时
|
|
|
|
- 'm+': date.getMinutes(), // 分
|
|
|
|
- 's+': date.getSeconds(), // 秒
|
|
|
|
- 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
|
|
|
|
- S: date.getMilliseconds() // 毫秒
|
|
|
|
- }
|
|
|
|
|
|
+ "M+": date.getMonth() + 1, // 月
|
|
|
|
+ "d+": date.getDate(), // 日
|
|
|
|
+ "h+": date.getHours(), // 小时
|
|
|
|
+ "m+": date.getMinutes(), // 分
|
|
|
|
+ "s+": date.getSeconds(), // 秒
|
|
|
|
+ "q+": Math.floor((date.getMonth() + 3) / 3), // 季度
|
|
|
|
+ S: date.getMilliseconds(), // 毫秒
|
|
|
|
+ };
|
|
if (/(y+)/.test(fmt)) {
|
|
if (/(y+)/.test(fmt)) {
|
|
fmt = fmt.replace(
|
|
fmt = fmt.replace(
|
|
RegExp.$1,
|
|
RegExp.$1,
|
|
- (date.getFullYear() + '').substr(4 - RegExp.$1.length)
|
|
|
|
- )
|
|
|
|
|
|
+ (date.getFullYear() + "").substr(4 - RegExp.$1.length)
|
|
|
|
+ );
|
|
}
|
|
}
|
|
// if (/(y+)/.test(fmt))
|
|
// if (/(y+)/.test(fmt))
|
|
// fmt = fmt.replace(
|
|
// fmt = fmt.replace(
|
|
@@ -248,48 +248,111 @@ export function formatDate(timestamp, formate) {
|
|
// (date.getFullYear() + '').substr(4 - RegExp.$1.length)
|
|
// (date.getFullYear() + '').substr(4 - RegExp.$1.length)
|
|
// )
|
|
// )
|
|
for (var k in o) {
|
|
for (var k in o) {
|
|
- if (new RegExp('(' + k + ')').test(fmt)) {
|
|
|
|
|
|
+ if (new RegExp("(" + k + ")").test(fmt)) {
|
|
fmt = fmt.replace(
|
|
fmt = fmt.replace(
|
|
RegExp.$1,
|
|
RegExp.$1,
|
|
RegExp.$1.length === 1
|
|
RegExp.$1.length === 1
|
|
? o[k]
|
|
? o[k]
|
|
- : ('00' + o[k]).substr(('' + o[k]).length)
|
|
|
|
- )
|
|
|
|
|
|
+ : ("00" + o[k]).substr(("" + o[k]).length)
|
|
|
|
+ );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return fmt
|
|
|
|
- }
|
|
|
|
- return Format(formate)
|
|
|
|
|
|
+ return fmt;
|
|
|
|
+ };
|
|
|
|
+ return Format(formate);
|
|
}
|
|
}
|
|
export const jsonToFormData = (json) => {
|
|
export const jsonToFormData = (json) => {
|
|
- const formData = new FormData()
|
|
|
|
|
|
+ const formData = new FormData();
|
|
for (const key in json) {
|
|
for (const key in json) {
|
|
if (Object.prototype.hasOwnProperty.call(json, key)) {
|
|
if (Object.prototype.hasOwnProperty.call(json, key)) {
|
|
- const value = json[key]
|
|
|
|
|
|
+ const value = json[key];
|
|
if (Array.isArray(value)) {
|
|
if (Array.isArray(value)) {
|
|
for (let i = 0; i < value.length; i++) {
|
|
for (let i = 0; i < value.length; i++) {
|
|
- let item
|
|
|
|
- if (typeof value[i] === 'string') {
|
|
|
|
- item = value[i]
|
|
|
|
- formData.append(`${key}[${i}]`, item)
|
|
|
|
|
|
+ let item;
|
|
|
|
+ if (typeof value[i] === "string") {
|
|
|
|
+ item = value[i];
|
|
|
|
+ formData.append(`${key}[${i}]`, item);
|
|
} else if (value[i] instanceof File) {
|
|
} else if (value[i] instanceof File) {
|
|
- item = value[i]
|
|
|
|
- formData.append(`${key}`, item)
|
|
|
|
|
|
+ item = value[i];
|
|
|
|
+ formData.append(`${key}`, item);
|
|
} else {
|
|
} else {
|
|
- item = JSON.stringify(value[i])
|
|
|
|
- formData.append(`${key}[${i}]`, item)
|
|
|
|
|
|
+ item = JSON.stringify(value[i]);
|
|
|
|
+ formData.append(`${key}[${i}]`, item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (value instanceof File) {
|
|
} else if (value instanceof File) {
|
|
- formData.append(key, value)
|
|
|
|
|
|
+ formData.append(key, value);
|
|
} else {
|
|
} else {
|
|
- const item = typeof value === 'string' ? value : JSON.stringify(value)
|
|
|
|
- formData.append(key, item)
|
|
|
|
|
|
+ const item = typeof value === "string" ? value : JSON.stringify(value);
|
|
|
|
+ formData.append(key, item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return formData
|
|
|
|
-}
|
|
|
|
|
|
+ return formData;
|
|
|
|
+};
|
|
|
|
+//下载图表json 文件
|
|
|
|
+export const downLoadChartsJsonFile = (selectJson) => {
|
|
|
|
+ // 创建Blob对象,将selectJson数据转化为JSON字符串
|
|
|
|
+ const jsonStr = JSON.stringify(selectJson, null, 2); // 格式化JSON
|
|
|
|
+ const blob = new Blob([jsonStr], { type: "application/json" });
|
|
|
|
+ // 创建a元素,用于下载Blob内容
|
|
|
|
+ const link = document.createElement("a");
|
|
|
|
+ link.href = URL.createObjectURL(blob);
|
|
|
|
+ link.download = selectJson.layout.title + "_selected_data.json"; // 设置下载的文件名
|
|
|
|
+ // 触发下载
|
|
|
|
+ link.click();
|
|
|
|
+ // 释放URL对象
|
|
|
|
+ URL.revokeObjectURL(link.href);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+//生成新的图表数据
|
|
|
|
+export const creatNewChartsJson = (selectedPoints, fullLayout) => {
|
|
|
|
+ const groupedData = {};
|
|
|
|
+ const addedPoints = {}; // 用于跟踪已添加的 (x, y) 组合
|
|
|
|
+ selectedPoints.forEach((item) => {
|
|
|
|
+ const { name } = item.data;
|
|
|
|
+ if (!groupedData[name]) {
|
|
|
|
+ groupedData[name] = {
|
|
|
|
+ x: [],
|
|
|
|
+ y: [],
|
|
|
|
+ mode: item.data.mode,
|
|
|
|
+ color: item.fullData.marker.color || item.fullData.line.color, // 获取颜色信息
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ // 使用 (x, y) 作为键来跟踪是否已添加
|
|
|
|
+ const pointKey = `${item.x}-${item.y}`;
|
|
|
|
+ if (!addedPoints[pointKey]) {
|
|
|
|
+ groupedData[name].x.push(item.x);
|
|
|
|
+ groupedData[name].y.push(item.y);
|
|
|
|
+ addedPoints[pointKey] = true;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const newPlotlyData = Object.keys(groupedData).map((name) => ({
|
|
|
|
+ x: groupedData[name].x,
|
|
|
|
+ y: groupedData[name].y,
|
|
|
|
+ mode: groupedData[name].mode,
|
|
|
|
+ marker: { color: groupedData[name].color, size: 10 }, // 使用原始颜色
|
|
|
|
+ line: { color: groupedData[name].color }, // 使用原始颜色
|
|
|
|
+ name: name,
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ // 配置新的图表布局
|
|
|
|
+ const layout = {
|
|
|
|
+ title: fullLayout.title.text,
|
|
|
|
+ xaxis: { title: fullLayout.xaxis.title.text },
|
|
|
|
+ yaxis: { title: fullLayout.yaxis.title.text },
|
|
|
|
+ legend: {
|
|
|
|
+ orientation: "h",
|
|
|
|
+ y: -0.2,
|
|
|
|
+ x: 0.5,
|
|
|
|
+ xanchor: "center",
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return { newPlotlyData, layout };
|
|
|
|
+};
|
|
|
|
+
|
|
export default {
|
|
export default {
|
|
uuid,
|
|
uuid,
|
|
copy,
|
|
copy,
|
|
@@ -303,5 +366,7 @@ export default {
|
|
base64ToBlob,
|
|
base64ToBlob,
|
|
downloadExcel,
|
|
downloadExcel,
|
|
convertTimestamp,
|
|
convertTimestamp,
|
|
- formatDate
|
|
|
|
-}
|
|
|
|
|
|
+ formatDate,
|
|
|
|
+ downLoadChartsJsonFile,
|
|
|
|
+ creatNewChartsJson,
|
|
|
|
+};
|