feat: babylon和cesium懒加载及打包优化

This commit is contained in:
caoqianming 2025-02-14 10:36:45 +08:00
parent 9558079588
commit 1b5cbcdad0
10 changed files with 213 additions and 97 deletions

View File

@ -17,9 +17,11 @@
"babylonjs": "^6.46.0", "babylonjs": "^6.46.0",
"babylonjs-gui": "^6.46.0", "babylonjs-gui": "^6.46.0",
"babylonjs-loaders": "^6.46.0", "babylonjs-loaders": "^6.46.0",
"cesium": "1.75", "cesium": "^1.126.0",
"codemirror": "^5.65.17", "codemirror": "^5.65.17",
"codemirror-editor-vue3": "^2.7.0", "codemirror-editor-vue3": "^2.7.0",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^12.0.2",
"core-js": "3.29.0", "core-js": "3.29.0",
"cropperjs": "1.5.13", "cropperjs": "1.5.13",
"crypto-browserify": "^3.12.0", "crypto-browserify": "^3.12.0",
@ -37,6 +39,7 @@
"moment": "^2.30.1", "moment": "^2.30.1",
"node-polyfill-webpack-plugin": "^4.0.0", "node-polyfill-webpack-plugin": "^4.0.0",
"nprogress": "0.2.0", "nprogress": "0.2.0",
"path": "^0.12.7",
"print-js": "^1.6.0", "print-js": "^1.6.0",
"qrcodejs2": "0.0.2", "qrcodejs2": "0.0.2",
"sortablejs": "1.15.0", "sortablejs": "1.15.0",

View File

@ -16,14 +16,11 @@ import jsBarCode from "./utils/jsBarCode";
import DataVVue3 from "@kjgl77/datav-vue3"; import DataVVue3 from "@kjgl77/datav-vue3";
import htmlToPdf from "./utils/htmlToPdf"; import htmlToPdf from "./utils/htmlToPdf";
import * as Cesium from "cesium";
const app = createApp(App); const app = createApp(App);
app.use(store); app.use(store);
app.use(router); app.use(router);
app.use(ElementPlus); app.use(ElementPlus);
app.use(Cesium);
app.use(i18n); app.use(i18n);
app.use(scui); app.use(scui);
app.use(xtui); app.use(xtui);

View File

@ -269,9 +269,18 @@
</template> </template>
<script> <script>
import tool from "@/utils/tool"; import tool from "@/utils/tool";
import * as Cesium from "cesium";
import * as echarts from "echarts"; import * as echarts from "echarts";
import cems from "./enpComponents/cems.vue"; import cems from "./enpComponents/cems.vue";
window.CESIUM_BASE_URL = '/cesium';
let Cesium;
const loadCesium = async () => {
if (Cesium) return;
await import("cesium/Build/Cesium/Widgets/widgets.css");
Cesium = await import('cesium');
Cesium.Ion.defaultAccessToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1Yzg3ZDEzOS0zN2Q1LTQ2N2YtOWJhMy1mNWU4MWY5N2ExYzkiLCJpZCI6MjAxMzIsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NzY4MTIzNzR9.SfNeHedDyXWLIPiNbc4qSsHBACm7uvaqRsQprL2J4Cw";
}
export default { export default {
name: "cesium", name: "cesium",
props: ["activeIndex"], props: ["activeIndex"],
@ -442,17 +451,20 @@ export default {
}; };
}, },
created() { created() {
const scriptInfo = document.createElement("script"); // const scriptInfo = document.createElement("script");
scriptInfo.setAttribute("data-callType", "callScript"); // scriptInfo.setAttribute("data-callType", "callScript");
scriptInfo.src = // scriptInfo.src =
"https://cesium.com/downloads/cesiumjs/releases/1.75/Build/Cesium/Cesium.js"; // "https://cesium.com/downloads/cesiumjs/releases/1.75/Build/Cesium/Cesium.js";
document.head.appendChild(scriptInfo); // document.head.appendChild(scriptInfo);
}, },
mounted() { mounted() {
let that = this; loadCesium().then(res=>{
Cesium.Ion.defaultAccessToken = this.initView();
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1Yzg3ZDEzOS0zN2Q1LTQ2N2YtOWJhMy1mNWU4MWY5N2ExYzkiLCJpZCI6MjAxMzIsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NzY4MTIzNzR9.SfNeHedDyXWLIPiNbc4qSsHBACm7uvaqRsQprL2J4Cw"; })
},
methods: {
initView() {
let that = this;
const viewer = new Cesium.Viewer("cesiumContainer", { const viewer = new Cesium.Viewer("cesiumContainer", {
animation: false, // animation: false, //
baseLayerPicker: false, // baseLayerPicker: false, //
@ -573,8 +585,7 @@ export default {
} }
} }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}, },
methods: {
// //
setTrees(viewer, orientation) { setTrees(viewer, orientation) {
this.modelPosition.forEach((item) => { this.modelPosition.forEach((item) => {

View File

@ -271,20 +271,27 @@
</template> </template>
<script> <script>
import * as echarts from "echarts"; import * as echarts from "echarts";
import * as BABYLON from "babylonjs";
import * as BABYLON_GUI from "babylonjs-gui";
import * as BABYLON_GRID from "@/utils/gridMaterial";
import * as BABYLON_MATERIAL from "@/utils/babylonMaterial";
import value from "./../enm_energy/value.vue"; import value from "./../enm_energy/value.vue";
import config from "@/config"; import config from "@/config";
BABYLON.DracoCompression.Configuration.decoder.wasmUrl =
"./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl =
"./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl =
"./draco_decoder_gltf.js";
import "babylonjs-loaders";
import "animate.css"; import "animate.css";
let BABYLON, BABYLON_GUI, BABYLON_GRID, BABYLON_MATERIAL;
// Babylon.js
const loadBabylon = async () => {
if (BABYLON) return;
BABYLON = await import('babylonjs');
BABYLON_GUI = await import('babylonjs-gui');
BABYLON_GRID = await import('@/utils/gridMaterial');
BABYLON_MATERIAL = await import('@/utils/babylonMaterial');
// Draco
BABYLON.DracoCompression.Configuration.decoder.wasmUrl = "./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl = "./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl = "./draco_decoder_gltf.js";
// Babylon.js
await import('babylonjs-loaders');
};
export default { export default {
beforeRouteLeave(to, from, next) { beforeRouteLeave(to, from, next) {
// //
@ -640,7 +647,29 @@ export default {
}; };
}, },
mounted() { mounted() {
let that = this; loadBabylon().then(()=>{
this.initView()
})
},
beforeUnmount() {
//
if (this.timerTime) {
clearInterval(this.timerTime);}
if (this.timerOther) {
clearInterval(this.timerOther);}
if(this.intervalId1!==null){
clearInterval(this.intervalId1);
}
if(this.intervalId2!==null){
clearInterval(this.intervalId2);
}
if(this.intervalId3!==null){
clearInterval(this.intervalId3);
}
},
methods: {
initView() {
let that = this;
that.bigScreenName = that.bigScreenName =
that.$TOOL.data.get("BASE_INFO").base.bigScreen_name; that.$TOOL.data.get("BASE_INFO").base.bigScreen_name;
that.showTime(); that.showTime();
@ -689,24 +718,7 @@ export default {
that.initializeData(); that.initializeData();
}, 180000); // 3 }, 180000); // 3
}); });
}, },
beforeUnmount() {
//
if (this.timerTime) {
clearInterval(this.timerTime);}
if (this.timerOther) {
clearInterval(this.timerOther);}
if(this.intervalId1!==null){
clearInterval(this.intervalId1);
}
if(this.intervalId2!==null){
clearInterval(this.intervalId2);
}
if(this.intervalId3!==null){
clearInterval(this.intervalId3);
}
},
methods: {
backHome(){ backHome(){
// this.$router.push({ name: "user" }); // this.$router.push({ name: "user" });
this.$router.go(-1); this.$router.go(-1);

View File

@ -294,19 +294,38 @@
</template> </template>
<script> <script>
import * as echarts from "echarts"; import * as echarts from "echarts";
import * as BABYLON from "babylonjs";
import * as BABYLON_GUI from "babylonjs-gui";
import * as BABYLON_GRID from "@/utils/gridMaterial";
import * as BABYLON_MATERIAL from "@/utils/babylonMaterial";
import config from "@/config"; import config from "@/config";
BABYLON.DracoCompression.Configuration.decoder.wasmUrl =
"./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl =
"./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl =
"./draco_decoder_gltf.js";
import "babylonjs-loaders";
import "animate.css"; import "animate.css";
// import * as BABYLON from "babylonjs";
// import * as BABYLON_GUI from "babylonjs-gui";
// import * as BABYLON_GRID from "@/utils/gridMaterial";
// import * as BABYLON_MATERIAL from "@/utils/babylonMaterial";
// BABYLON.DracoCompression.Configuration.decoder.wasmUrl =
// "./draco_wasm_wrapper_gltf.js";
// BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl =
// "./draco_decoder_gltf.wasm";
// BABYLON.DracoCompression.Configuration.decoder.fallbackUrl =
// "./draco_decoder_gltf.js";
// import "babylonjs-loaders";
let BABYLON, BABYLON_GUI, BABYLON_GRID, BABYLON_MATERIAL;
// Babylon.js
const loadBabylon = async () => {
if (BABYLON) return;
BABYLON = await import('babylonjs');
BABYLON_GUI = await import('babylonjs-gui');
BABYLON_GRID = await import('@/utils/gridMaterial');
BABYLON_MATERIAL = await import('@/utils/babylonMaterial');
// Draco
BABYLON.DracoCompression.Configuration.decoder.wasmUrl = "./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl = "./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl = "./draco_decoder_gltf.js";
// Babylon.js
await import('babylonjs-loaders');
};
export default { export default {
data() { data() {
return { return {
@ -629,7 +648,14 @@ export default {
}; };
}, },
mounted() { mounted() {
let that = this; loadBabylon().then(() => {
this.initView();
}
)
},
methods: {
initView() {
let that = this;
that.bigScreenName = that.bigScreenName =
that.$TOOL.data.get("BASE_INFO").base.bigScreen_name; that.$TOOL.data.get("BASE_INFO").base.bigScreen_name;
that.showTime(); that.showTime();
@ -710,8 +736,7 @@ export default {
// that.dataCollect(); // that.dataCollect();
// }, 3600000); // }, 3600000);
}); });
}, },
methods: {
// //
productNum() { productNum() {
let that = this; let that = this;

View File

@ -520,7 +520,6 @@ import carwash from "./enpComponents/smartg_carwash.vue";
import carmanager from "./enpComponents/carManager.vue"; import carmanager from "./enpComponents/carManager.vue";
import videowall from "./enpComponents/video.vue"; import videowall from "./enpComponents/video.vue";
import scScrollTavle from "@/components/scScrollTable.vue"; import scScrollTavle from "@/components/scScrollTable.vue";
// import 'babylonjs-loaders';
import "animate.css"; import "animate.css";
export default { export default {
components: { components: {

View File

@ -341,21 +341,29 @@
</template> </template>
<script> <script>
import * as echarts from "echarts"; import * as echarts from "echarts";
import * as BABYLON from "babylonjs";
import * as BABYLON_GUI from "babylonjs-gui";
import scEcharts from '@/components/scEcharts'; import scEcharts from '@/components/scEcharts';
import * as BABYLON_GRID from "@/utils/gridMaterial";
import * as BABYLON_MATERIAL from "@/utils/babylonMaterial";
import config from "@/config"; import config from "@/config";
BABYLON.DracoCompression.Configuration.decoder.wasmUrl =
"./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl =
"./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl =
"./draco_decoder_gltf.js";
import "babylonjs-loaders";
import "animate.css"; import "animate.css";
import baseUrl from "@/config"; import baseUrl from "@/config";
let BABYLON, BABYLON_GUI, BABYLON_GRID, BABYLON_MATERIAL;
// Babylon.js
const loadBabylon = async () => {
if (BABYLON) return;
BABYLON = await import('babylonjs');
BABYLON_GUI = await import('babylonjs-gui');
BABYLON_GRID = await import('@/utils/gridMaterial');
BABYLON_MATERIAL = await import('@/utils/babylonMaterial');
// Draco
BABYLON.DracoCompression.Configuration.decoder.wasmUrl = "./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl = "./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl = "./draco_decoder_gltf.js";
// Babylon.js
await import('babylonjs-loaders');
};
const configData={ const configData={
header : ['物料批次','未加工','进行中','已完成','合格数'], header : ['物料批次','未加工','进行中','已完成','合格数'],
headerBGC : '#0a3f44', headerBGC : '#0a3f44',
@ -669,7 +677,15 @@ export default {
}; };
}, },
mounted() { mounted() {
let that = this; loadBabylon().then(()=>{
this.initView()
})
},
methods: {
//
initView(){
let that = this;
var windowHeight = window.innerHeight; var windowHeight = window.innerHeight;
var windowWidth = window.innerWidth; var windowWidth = window.innerWidth;
that.pieWidth =Math.round((windowWidth/100*33)/5)+'px'; that.pieWidth =Math.round((windowWidth/100*33)/5)+'px';
@ -733,8 +749,7 @@ export default {
that.showTime(); that.showTime();
that.addListener(); that.addListener();
}) })
}, },
methods: {
// //
getArticles(){ getArticles(){
let that = this; let that = this;

View File

@ -394,19 +394,26 @@
</template> </template>
<script> <script>
import * as echarts from "echarts"; import * as echarts from "echarts";
import * as BABYLON from "babylonjs";
import * as BABYLON_GUI from "babylonjs-gui";
import * as BABYLON_GRID from "@/utils/gridMaterial";
import * as BABYLON_MATERIAL from "@/utils/babylonMaterial";
import config from "@/config"; import config from "@/config";
BABYLON.DracoCompression.Configuration.decoder.wasmUrl =
"./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl =
"./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl =
"./draco_decoder_gltf.js";
import "babylonjs-loaders";
import "animate.css"; import "animate.css";
let BABYLON, BABYLON_GUI, BABYLON_GRID, BABYLON_MATERIAL;
// Babylon.js
const loadBabylon = async () => {
if (BABYLON) return;
BABYLON = await import('babylonjs');
BABYLON_GUI = await import('babylonjs-gui');
BABYLON_GRID = await import('@/utils/gridMaterial');
BABYLON_MATERIAL = await import('@/utils/babylonMaterial');
// Draco
BABYLON.DracoCompression.Configuration.decoder.wasmUrl = "./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl = "./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl = "./draco_decoder_gltf.js";
// Babylon.js
await import('babylonjs-loaders');
};
export default { export default {
data() { data() {
return { return {
@ -575,7 +582,13 @@ export default {
}; };
}, },
mounted() { mounted() {
let that = this; loadBabylon().then(() => {
this.initView();
})
},
methods: {
initView() {
let that = this;
let height = document.getElementById("mainBlock").clientHeight; let height = document.getElementById("mainBlock").clientHeight;
let height0 = height / 3 - 55; let height0 = height / 3 - 55;
let height1 = height0 - 20; let height1 = height0 - 20;
@ -667,8 +680,7 @@ export default {
}); });
this.getPlanRate(); this.getPlanRate();
this.getMaterialList(); this.getMaterialList();
}, },
methods: {
//6---- //6----
getsaleOut() { getsaleOut() {
let that = this; let that = this;

View File

@ -138,13 +138,25 @@
</template> </template>
<script> <script>
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import * as BABYLON from "babylonjs";
import * as BABYLON_GUI from "babylonjs-gui";
import * as BABYLON_GRID from "@/utils/gridMaterial";
import * as BABYLON_MATERIAL from "@/utils/babylonMaterial";
import 'babylonjs-loaders';
import 'animate.css'; import 'animate.css';
let BABYLON, BABYLON_GUI, BABYLON_GRID, BABYLON_MATERIAL;
// Babylon.js
const loadBabylon = async () => {
if (BABYLON) return;
BABYLON = await import('babylonjs');
BABYLON_GUI = await import('babylonjs-gui');
BABYLON_GRID = await import('@/utils/gridMaterial');
BABYLON_MATERIAL = await import('@/utils/babylonMaterial');
// Draco
BABYLON.DracoCompression.Configuration.decoder.wasmUrl = "./draco_wasm_wrapper_gltf.js";
BABYLON.DracoCompression.Configuration.decoder.wasmBinaryUrl = "./draco_decoder_gltf.wasm";
BABYLON.DracoCompression.Configuration.decoder.fallbackUrl = "./draco_decoder_gltf.js";
// Babylon.js
await import('babylonjs-loaders');
};
export default { export default {
data() { data() {
return { return {
@ -203,6 +215,7 @@ export default {
} }
}, },
mounted() { mounted() {
loadBabylon();
let that = this; let that = this;
let height = document.getElementById('mainBlock').clientHeight; let height = document.getElementById('mainBlock').clientHeight;
let height0 = height / 3 - 55; let height0 = height / 3 - 55;

View File

@ -1,5 +1,11 @@
const { defineConfig } = require('@vue/cli-service') const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';
const path = require('path');
const webpack = require('webpack');
const cesiumBaseUrl = "cesium"
module.exports = defineConfig({ module.exports = defineConfig({
//设置为空打包后不分更目录还是多级目录 //设置为空打包后不分更目录还是多级目录
publicPath:'', publicPath:'',
@ -48,6 +54,7 @@ module.exports = defineConfig({
chunks: "all", chunks: "all",
automaticNameDelimiter: '~', automaticNameDelimiter: '~',
name: "scuiChunks", name: "scuiChunks",
maxSize: 4000000, // 限制每个代码块的最大体积,防止生成太大的块
cacheGroups: { cacheGroups: {
//第三方库抽离 //第三方库抽离
vendor: { vendor: {
@ -74,6 +81,14 @@ module.exports = defineConfig({
codemirror: { codemirror: {
name: "codemirror", name: "codemirror",
test: /[\\/]node_modules[\\/]codemirror[\\/]/ test: /[\\/]node_modules[\\/]codemirror[\\/]/
},
babylonjs: {
name: "babylonjs",
test: /[\\/]node_modules[\\/]babylon[\\/]/
},
cesium: {
name: "cesium",
test: /[\\/]node_modules[\\/]cesium[\\/]/
} }
} }
} }
@ -85,10 +100,24 @@ module.exports = defineConfig({
stream: false, stream: false,
} }
}, },
plugins: [new NodePolyfillPlugin()], plugins: [
new NodePolyfillPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: path.join(cesiumSource, cesiumWorkers), to: `${cesiumBaseUrl}/Workers`, },
{ from: path.join(cesiumSource, "ThirdParty"), to: `${cesiumBaseUrl}/ThirdParty`, },
{ from: path.join(cesiumSource, "Assets"), to: `${cesiumBaseUrl}/Assets`, },
{ from: path.join(cesiumSource, "Widgets"), to: `${cesiumBaseUrl}/Widgets`, },
],
}),
new webpack.DefinePlugin({
// Define relative base path in cesium for loading assets
CESIUM_BASE_URL: JSON.stringify(cesiumBaseUrl),
}),
],
externals:{ externals:{
'./cptable':'var cptable' './cptable':'var cptable'
} },
}, },
pluginOptions: { pluginOptions: {
'style-resources-loader': { 'style-resources-loader': {