wujingjing
2024-10-30 03080e12de7de3fec89b2f77fcf9f73c02bc6cf0
src/utils/getStyleSheets.ts
@@ -1,15 +1,15 @@
import { nextTick } from 'vue';
import * as svg from '@element-plus/icons-vue';
import { nextTick } from 'vue';
// 获取阿里字体图标
const getAlicdnIconfont = () => {
   return new Promise((resolve, reject) => {
      nextTick(() => {
         const styles: any = document.styleSheets;
         let sheetsList = [];
         let sheetsIconList = [];
         const sheetsList = [];
         const sheetsIconList = [];
         for (let i = 0; i < styles.length; i++) {
            if (styles[i].href && styles[i].href.indexOf('at.alicdn.com') > -1) {
            if (styles[i].href && styles[i].href.indexOf('iconfont') > -1 && styles[i].href.indexOf('ywiconfont') === -1) {
               sheetsList.push(styles[i]);
            }
         }
@@ -17,7 +17,38 @@
            for (let j = 0; j < sheetsList[i].cssRules.length; j++) {
               if (sheetsList[i].cssRules[j].selectorText && sheetsList[i].cssRules[j].selectorText.indexOf('.icon-') > -1) {
                  sheetsIconList.push(
                     `${sheetsList[i].cssRules[j].selectorText.substring(1, sheetsList[i].cssRules[j].selectorText.length).replace(/\:\:before/gi, '')}`
                     `${sheetsList[i].cssRules[j].selectorText
                        .substring(1, sheetsList[i].cssRules[j].selectorText.length)
                        .replace(/\:\:before/gi, '')}`
                  );
               }
            }
         }
         if (sheetsIconList.length > 0) resolve(sheetsIconList);
         else reject('未获取到值,请刷新重试');
      });
   });
};
// 获取义维字体图标
const getYwCdnIconfont = () => {
   return new Promise((resolve, reject) => {
      nextTick(() => {
         const styles: any = document.styleSheets;
         const sheetsList = [];
         const sheetsIconList = [];
         for (let i = 0; i < styles.length; i++) {
            if (styles[i].href && styles[i].href.indexOf('ywiconfont') > -1) {
               sheetsList.push(styles[i]);
            }
         }
         for (let i = 0; i < sheetsList.length; i++) {
            for (let j = 0; j < sheetsList[i].cssRules.length; j++) {
               if (sheetsList[i].cssRules[j].selectorText && sheetsList[i].cssRules[j].selectorText.indexOf('.icon-') > -1) {
                  sheetsIconList.push(
                     `${sheetsList[i].cssRules[j].selectorText
                        .substring(1, sheetsList[i].cssRules[j].selectorText.length)
                        .replace(/\:\:before/gi, '')}`
                  );
               }
            }
@@ -48,10 +79,10 @@
   return new Promise((resolve, reject) => {
      nextTick(() => {
         const styles: any = document.styleSheets;
         let sheetsList = [];
         let sheetsIconList = [];
         const sheetsList = [];
         const sheetsIconList = [];
         for (let i = 0; i < styles.length; i++) {
            if (styles[i].href && styles[i].href.indexOf('font-awesome') > -1) {
            if (styles[i].href && styles[i].href.indexOf('fontawesome') > -1) {
               sheetsList.push(styles[i]);
            }
         }
@@ -64,7 +95,9 @@
               ) {
                  if (/::before/.test(sheetsList[i].cssRules[j].selectorText)) {
                     sheetsIconList.push(
                        `${sheetsList[i].cssRules[j].selectorText.substring(1, sheetsList[i].cssRules[j].selectorText.length).replace(/\:\:before/gi, '')}`
                        `${sheetsList[i].cssRules[j].selectorText
                           .substring(1, sheetsList[i].cssRules[j].selectorText.length)
                           .replace(/\:\:before/gi, '')}`
                     );
                  }
               }
@@ -95,6 +128,9 @@
   awe: () => {
      return getAwesomeIconfont();
   },
   yw: () => {
      return getYwCdnIconfont();
   },
};
// 导出方法