12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // 加载第三方库
- export const loadLib = (() => {
- const cache: Record<string, Promise<void>> = {};
- const load = (
- lib: string,
- success: () => void,
- err: () => void,
- maxReq = 0
- ) => {
- const el = document.createElement("script");
- el.src = lib;
- document.body.appendChild(el);
- el.onload = success;
- el.onerror = () => {
- if (maxReq > 0) {
- load(lib, success, err, --maxReq);
- } else {
- err();
- }
- };
- };
- return (lib: string) => {
- if (!cache[lib]) {
- cache[lib] = new Promise((resolve, reject) => {
- load(lib, resolve, reject, 3);
- });
- }
- return cache[lib];
- };
- })();
- export const togetherCallback = (cbs: (() => void)[]) => () => together(cbs)
- export const together = (cbs: (() => void)[]) => {
- cbs.forEach(cb => cb())
- }
- export const getFileUrl = (file: LocalFile | string) =>
- typeof file === 'string'
- ? file
- : file.url
- export const asyncTimeout = (mis: number = 0) => new Promise(resolve => setTimeout(resolve, mis))
- export const jsonToForm = (data: { [key in string]: any }) => {
- const formData = new FormData()
- for (const [key, val] of Object.entries(data)) {
- formData.append(key, val)
- }
- return formData
- }
- export * from './store-help'
- export * from "./stack";
- export * from "./loading";
- export * from "./route";
- export * from "./asyncBus";
- export * from './mount'
- export * from './watch'
- export * from './diff'
- export * from './params'
|