feat: 删除已经迁移vben/utils 下的工具类

pull/90/MERGE
xingyu4j 2025-05-06 21:35:10 +08:00
parent 5af8a3c40c
commit b724ca2917
4 changed files with 0 additions and 287 deletions

View File

@ -1,47 +0,0 @@
// 迁移至 packages/@core/base/shared/src/utils/time.ts
import dayjs from 'dayjs';
/** 时间段选择器拓展 */
export const rangePickerExtend = () => {
return {
showTime: {
format: 'HH:mm:ss',
defaultValue: [
dayjs('00:00:00', 'HH:mm:ss'),
dayjs('23:59:59', 'HH:mm:ss'),
],
},
// 如果需要10位时间戳秒级可以使用 valueFormat: 'X'
valueFormat: 'YYYY-MM-DD HH:mm:ss',
format: 'YYYY-MM-DD HH:mm:ss', // 显示格式
placeholder: ['开始时间', '结束时间'],
ranges: {
: [dayjs().startOf('day'), dayjs().endOf('day')],
: [
dayjs().subtract(1, 'day').startOf('day'),
dayjs().subtract(1, 'day').endOf('day'),
],
: [dayjs().startOf('week'), dayjs().endOf('day')],
: [dayjs().startOf('month'), dayjs().endOf('day')],
7: [
dayjs().subtract(7, 'day').startOf('day'),
dayjs().endOf('day'),
],
30: [
dayjs().subtract(30, 'day').startOf('day'),
dayjs().endOf('day'),
],
},
transformDateFunc: (dates: any) => {
if (dates && dates.length === 2) {
return [dates.createTime[0], dates.createTime[1]].join(','); // 格式化为后台支持的时间格式
}
return {};
},
};
};

View File

@ -1,42 +0,0 @@
import dayjs from 'dayjs';
// TODO @芋艿:后续整理下 迁移至 packages/core/base/shared/src/utils/date.ts,后续删除 使用 @vben/utils 的 getRangePickerDefaultProps
/** 时间段选择器拓展 */
export function getRangePickerDefaultProps(): any {
return {
showTime: {
format: 'HH:mm:ss',
defaultValue: [
dayjs('00:00:00', 'HH:mm:ss'),
dayjs('23:59:59', 'HH:mm:ss'),
],
},
valueFormat: 'YYYY-MM-DD HH:mm:ss',
format: 'YYYY-MM-DD HH:mm:ss',
placeholder: ['开始时间', '结束时间'],
ranges: {
: [dayjs().startOf('day'), dayjs().endOf('day')],
: [
dayjs().subtract(1, 'day').startOf('day'),
dayjs().subtract(1, 'day').endOf('day'),
],
: [dayjs().startOf('week'), dayjs().endOf('day')],
: [dayjs().startOf('month'), dayjs().endOf('day')],
'最近 7 天': [
dayjs().subtract(7, 'day').startOf('day'),
dayjs().endOf('day'),
],
'最近 30 天': [
dayjs().subtract(30, 'day').startOf('day'),
dayjs().endOf('day'),
],
},
transformDateFunc: (dates: any) => {
if (dates && dates.length === 2) {
return [dates.createTime[0], dates.createTime[1]].join(','); // 格式化为后台支持的时间格式
}
return {};
},
};
}

View File

@ -1,127 +0,0 @@
// TODO @芋艿:需要优化下每个方法
// TODO @芋艿:是不是可以共用么?
// 后续使用 packages/core/base/shared/src/utils/download.ts 下的方法
import { dataURLtoBlob, urlToBase64 } from './base64Conver';
/**
* Download online pictures
* @param url
* @param filename
* @param mime
* @param bom
*/
export function downloadByOnlineUrl(
url: string,
filename: string,
mime?: string,
bom?: BlobPart,
) {
urlToBase64(url).then((base64) => {
downloadByBase64(base64, filename, mime, bom);
});
}
/**
* Download pictures based on base64
* @param buf
* @param filename
* @param mime
* @param bom
*/
export function downloadByBase64(
buf: string,
filename: string,
mime?: string,
bom?: BlobPart,
) {
const base64Buf = dataURLtoBlob(buf);
downloadByData(base64Buf, filename, mime, bom);
}
/**
* Download according to the background interface file stream
* @param {*} data
* @param {*} filename
* @param {*} mime
* @param {*} bom
*/
export function downloadByData(
data: BlobPart,
filename: string,
mime?: string,
bom?: BlobPart,
) {
const blobData = bom === undefined ? [data] : [bom, data];
const blob = new Blob(blobData, { type: mime || 'application/octet-stream' });
const blobURL = window.URL.createObjectURL(blob);
const tempLink = document.createElement('a');
tempLink.style.display = 'none';
tempLink.href = blobURL;
tempLink.setAttribute('download', filename);
if (tempLink.download === undefined)
tempLink.setAttribute('target', '_blank');
document.body.append(tempLink);
tempLink.click();
tempLink.remove();
window.URL.revokeObjectURL(blobURL);
}
/**
* Download file according to file address
* @param {*} sUrl
*/
export function downloadByUrl({
url,
target = '_blank',
fileName,
}: {
fileName?: string;
target?: '_blank' | '_self';
url: string;
}): boolean {
const isChrome = window.navigator.userAgent.toLowerCase().includes('chrome');
const isSafari = window.navigator.userAgent.toLowerCase().includes('safari');
if (/iP/.test(window.navigator.userAgent)) {
console.error('Your browser does not support download!');
return false;
}
if (isChrome || isSafari) {
const link = document.createElement('a');
link.href = url;
link.target = target;
if (link.download !== undefined)
link.download = fileName || url.slice(url.lastIndexOf('/') + 1);
if (document.createEvent) {
const e = document.createEvent('MouseEvents');
e.initEvent('click', true, true);
link.dispatchEvent(e);
return true;
}
}
if (!url.includes('?')) url += '?download';
openWindow(url, { target });
return true;
}
export function openWindow(
url: string,
opt?: {
noopener?: boolean;
noreferrer?: boolean;
target?: '_blank' | '_self' | string;
},
) {
const { noopener = true, noreferrer = true, target = '__blank' } = opt || {};
const feature: string[] = [];
noopener && feature.push('noopener=yes');
noreferrer && feature.push('noreferrer=yes');
window.open(url, target, feature.join(','));
}

View File

@ -1,71 +0,0 @@
// todo @芋艿:公用逻辑
// 已迁移,后续使用 packages/core/base/shared/src/utils/tree.ts 下的方法
interface TreeNode {
[key: string]: any;
children?: TreeNode[];
}
/**
*
*
* @param {*} data
* @param {*} id id 'id'
* @param {*} parentId 'parentId'
* @param {*} children 'children'
*/
export const handleTree = (
data: TreeNode[],
id: string = 'id',
parentId: string = 'parentId',
children: string = 'children',
): TreeNode[] => {
if (!Array.isArray(data)) {
console.warn('data must be an array');
return [];
}
const config = {
id,
parentId,
childrenList: children,
};
const childrenListMap: Record<number | string, TreeNode[]> = {};
const nodeIds: Record<number | string, TreeNode> = {};
const tree: TreeNode[] = [];
// 1. 数据预处理
// 1.1 第一次遍历,生成 childrenListMap 和 nodeIds 映射
for (const d of data) {
const pId = d[config.parentId];
if (childrenListMap[pId] === undefined) {
childrenListMap[pId] = [];
}
nodeIds[d[config.id]] = d;
childrenListMap[pId].push(d);
}
// 1.2 第二次遍历,找出根节点
for (const d of data) {
const pId = d[config.parentId];
if (nodeIds[pId] === undefined) {
tree.push(d);
}
}
// 2. 构建树结:递归构建子节点
const adaptToChildrenList = (node: TreeNode): void => {
const nodeId = node[config.id];
if (childrenListMap[nodeId]) {
node[config.childrenList] = childrenListMap[nodeId];
// 递归处理子节点
for (const child of node[config.childrenList]) {
adaptToChildrenList(child);
}
}
};
// 3. 从根节点开始构建完整树
for (const rootNode of tree) {
adaptToChildrenList(rootNode);
}
return tree;
};