utils.ts 544 B

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