BearJiaIcon.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {createVNode} from 'vue';
  2. import * as $Icon from '@ant-design/icons-vue';
  3. // 实现动态加载antd的图标
  4. export const BearJiaIcon = (props) => {
  5. let iconName = props.icon;
  6. if (iconName) {
  7. // console.log('iconName=' + iconName);
  8. // 转换plus后台配置的图标名称:临时方案,可以直接在菜单管理里修改对应菜单的图标
  9. if (iconName === 'system') {
  10. iconName = 'setting-outlined';
  11. }
  12. if (iconName === 'user') {
  13. iconName = 'user-outlined';
  14. }
  15. if (iconName === 'peoples') {
  16. iconName = 'team-outlined';
  17. }
  18. if (iconName === 'tree-table') {
  19. iconName = 'bars-outlined';
  20. }
  21. if (iconName === 'tree') {
  22. iconName = 'apartment-outlined';
  23. }
  24. if (iconName === 'post') {
  25. iconName = 'flag-outlined';
  26. }
  27. if (iconName === 'dict') {
  28. iconName = 'read-outlined';
  29. }
  30. if (iconName === 'edit') {
  31. iconName = 'profile-outlined';
  32. }
  33. if (iconName === 'monitor') {
  34. iconName = 'monitor-outlined';
  35. }
  36. if (iconName === 'tool') {
  37. iconName = 'tool-outlined';
  38. }
  39. if (iconName === 'code') {
  40. iconName = 'code-outlined';
  41. }
  42. if (iconName === 'guide') {
  43. iconName = 'ie-outlined';
  44. }
  45. if (iconName === 'star') {
  46. iconName = 'filter-outlined';
  47. }
  48. if (iconName === 'form') {
  49. iconName = 'diff-outlined';
  50. }
  51. if (iconName === 'log') {
  52. iconName = 'snippets-outlined';
  53. }
  54. if (iconName === 'logininfor') {
  55. iconName = 'contacts-outlined';
  56. }
  57. if (iconName === 'job') {
  58. iconName = 'field-time-outlined';
  59. }
  60. if (iconName === 'online') {
  61. iconName = 'user-switch-outlined';
  62. }
  63. if (iconName === 'message') {
  64. iconName = 'bell-outlined';
  65. }
  66. // 兼容带横线的icon名称:去掉横线并将每个单词的首字母大写
  67. if (iconName.indexOf('-') != -1) {
  68. let array = iconName.split('-');
  69. iconName = '';
  70. for (let index = 0; index < array.length; index++) {
  71. let str = array[index];
  72. // 首字母大写
  73. str = str.replace(str[0], str[0].toUpperCase());
  74. iconName = iconName + str;
  75. }
  76. }
  77. // console.log('$Icon[iconName]=' + $Icon[iconName]);
  78. if ($Icon[iconName]) {
  79. return createVNode($Icon[iconName]);
  80. } else {
  81. // 获取不到对应图标时,使用默认图标
  82. return createVNode($Icon['BarsOutlined']);
  83. }
  84. } else {
  85. // 如果没有传入icon参数,返回默认图标
  86. return createVNode($Icon['BarsOutlined']);
  87. }
  88. };