index.ts 652 B

123456789101112131415161718192021222324252627282930
  1. import { h } from 'vue';
  2. import { NIcon } from 'naive-ui';
  3. /**
  4. * * 生成一个用不重复的ID
  5. * @param { Number } randomLength
  6. */
  7. export function getUUID(randomLength: number) {
  8. return Number(
  9. Math.random()
  10. .toString()
  11. .substr(2, randomLength) + Date.now()
  12. ).toString(36);
  13. }
  14. /**
  15. * * render 图标
  16. */
  17. export const renderIcon = (icon: typeof NIcon) => {
  18. return () => h(NIcon, null, { default: () => h(icon) });
  19. }
  20. /**
  21. * * 处理 vite 中无法使用 require 的问题
  22. * @param name
  23. * @returns
  24. */
  25. export const requireUrl = (path: string, name: string) => {
  26. return new URL(`${path}/${name}`, import.meta.url).href
  27. }