ludc
2025-01-03 7577e0d40354021d70b78d58b712ff8c2e8ad485
Source/plt-web/plt-web-ui/src/util/func.js
@@ -2,8 +2,44 @@
 * 通用工具类
 */
import CryptoJS from 'crypto-js'
import {validatenull} from "@/util/validate";
import {getStore} from "@/util/store";
import {getIcons} from "@/api/UI/Icons";
import store from "@/store/index"
export default class func {
  static getSvgList() {
    const fs = require('fs');
    const path = require('path');
    // 指定文件夹路径
    const directoryPath = "../config/svg"; // 修改为你的文件夹路径
    // 存储 .svg 文件路径的数组
    let svgFiles = [];
    // 读取文件夹
    fs.readdir(directoryPath, (err, files) => {
      if (err) {
        return console.error('无法读取目录: ' + err);
      }
      // 遍历文件
      files.forEach(file => {
        // 检查文件后缀名
        if (path.extname(file).toLowerCase() === '.svg') {
          // 构建文件的完整路径
          const filePath = path.join(directoryPath, file);
          svgFiles.push(filePath);
        }
      });
      // 输出结果
      console.log(JSON.stringify(svgFiles, null, 2));
    });
  }
  /**
   * 单选表格行
   * 时间戳格式化
@@ -92,9 +128,9 @@
   */
  static isEmptyObject(obj) {
    if(obj){
    if (obj) {
      return Object.keys(obj).length === 0;
    }else {
    } else {
      return true;
    }
  }
@@ -281,6 +317,48 @@
    });
    return encrypted.toString();
  }
  /* 根据name获取svg图标
  * @param name
  * @returns {string}
  */
  static getSVGByName(name) {
    let svgHtml = '';
    if(name && name.indexOf(':')!=-1) {
      let iconList = getStore({name: 'icons'});
      if (iconList && iconList.length > 0) {
        let libName = name.split(':')[0];
        let currentLic = iconList.find(item => item.lable == libName);
        if (currentLic && currentLic.list) {
          currentLic.list.find(item => {
            if (item.name == name) {
              svgHtml = item.content;
            }
            return item.name == name;
          })
        }
      }else {
        getIcons().then(res => {
          store.dispatch("setIcons", res.data.data);
          let iconList = res.data.data;
          if (iconList && iconList.length > 0) {
            let libName = name.split(':')[0];
            let currentLic = iconList.find(item => item.lable == libName);
            if (currentLic.list) {
              currentLic.list.find(item => {
                if (item.name == name) {
                  svgHtml = item.content;
                }
                return item.name == name;
              })
            }
          }
          return svgHtml;
        })
      }
    }
    return svgHtml;
  }
}