utils.ts 569 B

1234567891011121314151617181920212223242526272829
  1. import { forInObject, get, has } from "@/cool";
  2. import { icons } from "@/icons";
  3. import type { ClIconContent } from "../../types";
  4. export const getIcon = (name: string): ClIconContent => {
  5. let font = "";
  6. let text = "";
  7. try {
  8. let code = "";
  9. // 遍历字体库查找对应图标
  10. forInObject(icons, (value, key) => {
  11. if (has(value, name)) {
  12. font = key;
  13. code = get(value, name) as string;
  14. }
  15. });
  16. text = String.fromCharCode(parseInt(code, 16));
  17. } catch (e) {
  18. console.error(`图标 ${name} 不存在`, e);
  19. }
  20. return {
  21. font,
  22. text
  23. };
  24. };