From 0dae04f930427a728cecffa585884713755fac24 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 18 十一月 2024 11:29:48 +0800
Subject: [PATCH] 优化打包

---
 index.html                           |    4 -
 customer_list/yw/index.js            |   67 +++++++++++++++++++++++++++++----
 src/components/chat/libs/markdown.ts |   20 +++++-----
 src/main.ts                          |    3 -
 4 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/customer_list/yw/index.js b/customer_list/yw/index.js
index 18d18a1..87269c0 100644
--- a/customer_list/yw/index.js
+++ b/customer_list/yw/index.js
@@ -14,7 +14,32 @@
 keywordsTag.content = `${briefCorpName}锛�${sysName}`;
 descriptionTag.content = `${briefCorpName}锛�${sysName}`;
 title.innerText = sysName;
-faviconIcon.href = icon;
+faviconIcon.href = icon + `?v=1`;
+
+//#region ====================== LCP Promise ======================
+const loadBaseLCP = new Promise((resolve, reject) => {
+	try {
+		// 妫�鏌ユ槸鍚︽敮鎸� PerformanceObserver 鍜� LCP 鎸囨爣
+		if ('PerformanceObserver' in window && PerformanceObserver.supportedEntryTypes.includes('largest-contentful-paint')) {
+			const observer = new PerformanceObserver((list) => {
+				window.list = list.getEntries();
+				for (const entry of list.getEntries()) {
+					resolve(entry);
+					observer.disconnect(); // 瀹屾垚鍚庢柇寮�瑙傚療鑰�
+				}
+			});
+			observer.observe({ type: 'largest-contentful-paint', buffered: true });
+		} else {
+			// 涓嶆敮鎸佹椂 浣跨敤onLoad 鍔犺浇
+			window.addEventListener('load', () => {
+				resolve(true);
+			});
+		}
+	} catch (error) {
+		reject(error);
+	}
+});
+//#endregion
 
 //#region ====================== 鍔犺浇script ======================
 
@@ -28,14 +53,40 @@
 	document.head.appendChild(script);
 }
 window.eventList = {};
-window.eventList.amisSdkJsPromise = new Promise((resolve, reject) => {
-	loadScript('/static/amis/sdk/sdk.js', (error) => {
-		if (error) {
-			reject(error);
-			return;
-		}
-		resolve();
+
+loadBaseLCP.then(() => {
+	window.eventList.amisSdkJsPromise = new Promise((resolve, reject) => {
+		loadScript('/static/amis/sdk/sdk.js', (error) => {
+			if (error) {
+				reject(error);
+				return;
+			}
+			resolve();
+		});
 	});
 });
 
 //#endregion
+
+//#region ====================== 鍔犺浇鏍峰紡 ======================
+function loadStyles(styles) {
+	for (const path of styles) {
+		const style = document.createElement('link');
+		style.setAttribute('rel', 'stylesheet');
+		style.setAttribute('type', 'text/css');
+		style.setAttribute('href', path);
+		// 璁剧疆 print 鍙互閬垮厤闃诲椤甸潰娓叉煋
+		style.setAttribute('media', 'print');
+		style.onload = () => {
+			style.setAttribute('media', 'all');
+		};
+		document.head.appendChild(style);
+	}
+}
+
+loadBaseLCP.then(() => {
+	loadStyles(['/static/amis/sdk/sdk.css', '/static/amis/sdk/helper.css', '/static/amis/sdk/iconfont.css']);
+
+});
+
+//#endregion
diff --git a/index.html b/index.html
index d59f915..ed93392 100644
--- a/index.html
+++ b/index.html
@@ -13,9 +13,7 @@
 		<script type="module" src="/static/config/pageConfig.js?v=202305725"></script>
 		<script type="module" src="/static/config/route.js?v=202305725"></script>
 		<script type="module" src="/index.js?v=202350725"></script>
-		<link rel="stylesheet" type="text/css" href="/static/amis/sdk/sdk.css"/>
-		<link rel="stylesheet" type="text/css" href="/static/amis/sdk/helper.css"/>
-		<link rel="stylesheet" type="text/css" href="/static/amis/sdk/iconfont.css"/>
+
 
 	</head>
 
diff --git a/src/components/chat/libs/markdown.ts b/src/components/chat/libs/markdown.ts
index 0a002fe..3c75cb9 100644
--- a/src/components/chat/libs/markdown.ts
+++ b/src/components/chat/libs/markdown.ts
@@ -1,4 +1,4 @@
-import highlight from 'highlight.js';
+// import highlight from 'highlight.js';
 import Markdown from 'markdown-it';
 
 const mdOptions: Markdown.Options = {
@@ -7,15 +7,15 @@
 	breaks: true,
 	langPrefix: 'language-',
 	// 浠g爜楂樹寒
-	highlight(str, lang) {
-		if (lang && highlight.getLanguage(lang)) {
-			try {
-				return '<pre class="hljs"><code>' + highlight.highlight(lang, str, true).value + '</code></pre>';
-			} catch (__) {
-      }
-		}
-		return '';
-	},
+	// highlight(str, lang) {
+	// 	if (lang && highlight.getLanguage(lang)) {
+	// 		try {
+	// 			return '<pre class="hljs"><code>' + highlight.highlight(lang, str, true).value + '</code></pre>';
+	// 		} catch (__) {
+    //   }
+	// 	}
+	// 	return '';
+	// },
 };
 
 export const md = new Markdown(mdOptions);
diff --git a/src/main.ts b/src/main.ts
index ad8cab7..f2a3365 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -10,7 +10,6 @@
 
 import ElementPlus from 'element-plus';
 import '/@/theme/index.scss';
-import VueGridLayout from 'vue-grid-layout';
 import * as ElementPlusIconsVue from '@element-plus/icons-vue';
 import { gotoRoute } from '/@/utils/route';
 
@@ -21,7 +20,7 @@
 }
 directive(app);
 other.elSvg(app);
-app.use(pinia).use(router).use(ElementPlus).use(i18n).use(VueGridLayout).mount('#app');
+app.use(pinia).use(router).use(ElementPlus).use(i18n).mount('#app');
 
 window.openPage = (name, siteId) => {
 	if (siteId) {

--
Gitblit v1.9.3