Skip to content

Instantly share code, notes, and snippets.

/**
* @description 根据当前url和查询字符串生成当前页面的完整路径。
* @example 很多业务在 console 和 platform 都是相同的组件,只是路径不同. 跳转的时候避免不了需要拼接路径.
* 但是路径通常包含当前的位置的动态参数 比如 cluster 和 tenant.
* 可以使用这个函数来生成完整的路径.
* @param additionalPath 附加的路径部分, 默认是空字符串.
* @return 返回当前页面的完整路径字符串.
* @example
* composeUrl('/new-path') // 返回 '/current-path/new-path?query=string
*/
import { v4 } from 'uuid';
export interface GenIdOptions {
/** 指定生成 id 的长度,默认为 6 */
length?: number;
/** id 前缀 */
prefix?: string;
/** id 后缀 */
suffix?: string;
/** 连接符 */
import type { InlineCode, Parent, Text } from "mdast"
import type { Plugin } from "unified"
import { visit } from "unist-util-visit"
const remarkUnderline: Plugin = () => {
return (tree) => {
// 1. 先处理 [text ending “++”] + inlineCode + [text starting “++”]
visit(tree, (node) => {
if (!("children" in node)) return
const children = node.children as any[]
export const fileToBase64 = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result as string);
reader.onerror = (error) => reject(error);
});
};
import React from 'react';
interface ComponentModule {
[key: string]: React.ComponentType<any> | any; // 组件类型或其他类型(比如函数,枚举等等)
}
/** 针对与具名导出的懒加载 */
export function lazyNamedImport<T extends ComponentModule>(
importer: () => Promise<T>,
exportName: keyof T
) {
import _ from 'lodash';
/**
* 生成随机密码
* @param options 密码生成选项
* @returns 生成的密码字符串
*/
export function generatePassword(options: PasswordOptions = {}): string {
// 默认选项
const defaultOptions: Required<PasswordOptions> = {
import { motion, useAnimation } from "motion/react"
import { useEffect, useSyncExternalStore } from "react"
import { createPortal } from "react-dom"
type LoadingState = {
progress: number
animating: boolean
}
function createLoadingStore() {
import { primaryColor } from '@/styles/variants';
import { motion } from 'framer-motion';
import React, { useEffect, useRef, useState } from 'react';
import ReactDOM from 'react-dom';
import styled from 'styled-components';
interface LoadingProps {
visible: boolean;
}
/* eslint-disable react/no-danger */
import { useLangContext } from '@/hooks';
import { EN_US, ZH_CN } from '@/locale/constants';
import { borderColor } from '@/styles/variants';
import { Tooltip } from '@arco-design/web-react';
import { IconDown, IconFile, IconRight } from '@arco-design/web-react/icon';
import { createPatch } from 'diff';
import { html, parse } from 'diff2html';
import 'diff2html/bundles/css/diff2html.min.css';
import React, { useEffect, useState } from 'react';
import { useEffect } from 'react';
type SingleDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
type Fkeys = 'F1' | 'F2' | 'F3' | 'F4' | 'F5' | 'F6' | 'F7' | 'F8' | 'F9' | 'F10' | 'F11' | 'F12';
type SingleLetterUppercase =
| 'A'
| 'B'
| 'C'
| 'D'
| 'E'