diff --git a/apps/web-antd/src/components/cropper/index.ts b/apps/web-antd/src/components/cropper/index.ts index 1d232cdb..b74a1272 100644 --- a/apps/web-antd/src/components/cropper/index.ts +++ b/apps/web-antd/src/components/cropper/index.ts @@ -1,8 +1,4 @@ -import { withInstall } from '#/utils'; - -import cropperImage from './src/cropper.vue'; -import avatarCropper from './src/cropper-avatar.vue'; +export { default as CropperImage } from './src/cropper.vue'; +export { default as CropperAvatar } from './src/cropper-avatar.vue'; export type { Cropper } from './src/typing'; -export const CropperImage = withInstall(cropperImage); -export const CropperAvatar = withInstall(avatarCropper); diff --git a/apps/web-antd/src/components/description/index.ts b/apps/web-antd/src/components/description/index.ts index 17a80cf6..46a851f1 100644 --- a/apps/web-antd/src/components/description/index.ts +++ b/apps/web-antd/src/components/description/index.ts @@ -1,7 +1,3 @@ -import { withInstall } from '#/utils'; - -import description from './src/description.vue'; - +export { default as Description } from './src/description.vue'; export * from './src/typing'; export { useDescription } from './src/useDescription'; -export const Description = withInstall(description); diff --git a/apps/web-antd/src/components/dict/index.ts b/apps/web-antd/src/components/dict/index.ts index 9dd84d24..0f0c957c 100644 --- a/apps/web-antd/src/components/dict/index.ts +++ b/apps/web-antd/src/components/dict/index.ts @@ -1,5 +1 @@ -import { withInstall } from '#/utils'; - -import dictTag from './src/index.vue'; - -export const DictTag = withInstall(dictTag); +export { default as DictTag } from './src/index.vue'; diff --git a/apps/web-antd/src/components/tenant-toggle/index.ts b/apps/web-antd/src/components/tenant-toggle/index.ts index 74dadd07..d82e6021 100644 --- a/apps/web-antd/src/components/tenant-toggle/index.ts +++ b/apps/web-antd/src/components/tenant-toggle/index.ts @@ -1,5 +1 @@ -import { withInstall } from '#/utils'; - -import tenantToggle from './src/index.vue'; - -export const TenantToggle = withInstall(tenantToggle); +export { default as TenantToggle } from './src/index.vue'; diff --git a/apps/web-antd/src/components/tinymce/index.ts b/apps/web-antd/src/components/tinymce/index.ts index bc00d6b2..6fe80740 100644 --- a/apps/web-antd/src/components/tinymce/index.ts +++ b/apps/web-antd/src/components/tinymce/index.ts @@ -1,5 +1 @@ -import { withInstall } from '#/utils'; - -import tinymce from './src/editor.vue'; - -export const Tinymce = withInstall(tinymce); +export { default as Tinymce } from './src/editor.vue'; diff --git a/apps/web-antd/src/utils/index.ts b/apps/web-antd/src/utils/index.ts deleted file mode 100644 index 0b8248b1..00000000 --- a/apps/web-antd/src/utils/index.ts +++ /dev/null @@ -1,180 +0,0 @@ -import type { - RouteLocationNormalized, - RouteRecordNormalized, -} from 'vue-router'; - -import type { App, Component } from 'vue'; -import { unref } from 'vue'; - -import { - intersectionWith, - isArray, - isEqual, - isObject, - mergeWith, - unionWith, -} from 'lodash-es'; - -export const noop = () => {}; - -/** - * @description: Set ui mount node - */ -export function getPopupContainer(node?: HTMLElement): HTMLElement { - return (node?.parentNode as HTMLElement) ?? document.body; -} - -/** - * Add the object as a parameter to the URL - * @param baseUrl url - * @param obj - * @returns {string} - * eg: - * let obj = {a: '3', b: '4'} - * setObjToUrlParams('www.baidu.com', obj) - * ==>www.baidu.com?a=3&b=4 - */ -export function setObjToUrlParams(baseUrl: string, obj: any): string { - let parameters = ''; - for (const key in obj) { - parameters += `${key}=${encodeURIComponent(obj[key])}&`; - } - parameters = parameters.replace(/&$/, ''); - return /\?$/.test(baseUrl) - ? baseUrl + parameters - : baseUrl.replace(/\/?$/, '?') + parameters; -} - -/** - * Recursively merge two objects. - * 递归合并两个对象。 - * - * @param source The source object to merge from. 要合并的源对象。 - * @param target The target object to merge into. 目标对象,合并后结果存放于此。 - * @param mergeArrays How to merge arrays. Default is "replace". - * 如何合并数组。默认为replace。 - * - "union": Union the arrays. 对数组执行并集操作。 - * - "intersection": Intersect the arrays. 对数组执行交集操作。 - * - "concat": Concatenate the arrays. 连接数组。 - * - "replace": Replace the source array with the target array. 用目标数组替换源数组。 - * @returns The merged object. 合并后的对象。 - */ -export function deepMerge< - T extends null | object | undefined, - U extends null | object | undefined, ->( - source: T, - target: U, - mergeArrays: 'concat' | 'intersection' | 'replace' | 'union' = 'replace', -): T & U { - if (!target) { - return source as T & U; - } - if (!source) { - return target as T & U; - } - return mergeWith({}, source, target, (sourceValue, targetValue) => { - if (isArray(targetValue) && isArray(sourceValue)) { - switch (mergeArrays) { - case 'concat': { - return [...sourceValue, ...targetValue]; - } - case 'intersection': { - return intersectionWith(sourceValue, targetValue, isEqual); - } - case 'replace': { - return targetValue; - } - case 'union': { - return unionWith(sourceValue, targetValue, isEqual); - } - default: { - throw new Error( - `Unknown merge array strategy: ${mergeArrays as string}`, - ); - } - } - } - if (isObject(targetValue) && isObject(sourceValue)) { - return deepMerge(sourceValue, targetValue, mergeArrays); - } - }); -} - -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(',')); -} - -// dynamic use hook props -export function getDynamicProps, U>( - props: T, -): Partial { - const ret: Record = {}; - - Object.keys(props).forEach((key) => { - ret[key] = unref((props as Record)[key]); - }); - - return ret as Partial; -} - -export function getRawRoute( - route: RouteLocationNormalized, -): RouteLocationNormalized { - if (!route) return route; - const { matched, ...opt } = route; - return { - ...opt, - matched: (matched - ? matched.map((item) => ({ - meta: item.meta, - name: item.name, - path: item.path, - })) - : undefined) as RouteRecordNormalized[], - }; -} - -// https://github.com/vant-ui/vant/issues/8302 -interface EventShim { - new (...args: any[]): { - $props: { - onClick?: (...args: any[]) => void; - }; - }; -} - -export type WithInstall = { - install(app: App): void; -} & EventShim & - T; - -export type CustomComponent = { displayName?: string } & Component; - -export const withInstall = ( - component: T, - alias?: string, -) => { - (component as Record).install = (app: App) => { - const compName = component.name || component.displayName; - if (!compName) return; - app.component(compName, component); - if (alias) { - app.config.globalProperties[alias] = component; - } - }; - return component as WithInstall; -};