Kaynağa Gözat

feat: build offline package

chenlei 2 hafta önce
ebeveyn
işleme
f4eb1bbe38

+ 0 - 2
components.d.ts

@@ -7,9 +7,7 @@ export {}
 /* prettier-ignore */
 declare module 'vue' {
   export interface GlobalComponents {
-    ElDialog: typeof import('element-plus/es')['ElDialog']
     ElImage: typeof import('element-plus/es')['ElImage']
-    ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
     RouterLink: typeof import('vue-router')['RouterLink']
     RouterView: typeof import('vue-router')['RouterView']
   }

+ 4 - 2
package.json

@@ -1,11 +1,12 @@
 {
   "name": "vite-scene-web",
-  "version": "1.0.0",
+  "version": "2.0.0",
   "private": true,
   "type": "module",
   "scripts": {
     "serve": "cross-env VITE_APP_TITLE=大理洱海科普馆 VITE_APP_HOT_DOMAIN=./hotspot.html vite",
-    "build:test": "cross-env VITE_APP_TITLE=大理洱海科普馆 run-p type-check \"build-only {@}\" --",
+    "build:test": "cross-env VITE_APP_TITLE=大理洱海科普馆 VITE_APP_HOT_DOMAIN=./hotspot.html run-p type-check \"build-only {@}\" --",
+    "build:offline": "cross-env VITE_APP_OFFLINE=1 npm run build:test && cross-env node ./scripts/generate-offline-config.js && replace-in-file --configFile ./scripts/offline-replace-config.json",
     "push:test": "cross-env node ./scripts/publish.js",
     "preview": "vite preview",
     "build-only": "vite build",
@@ -35,6 +36,7 @@
     "cross-env": "^7.0.3",
     "less": "^4.2.1",
     "npm-run-all2": "^7.0.1",
+    "replace-in-file": "^8.3.0",
     "sass": "^1.81.0",
     "typescript": "~5.6.3",
     "unplugin-auto-import": "^0.18.5",

Dosya farkı çok büyük olduğundan ihmal edildi
+ 2533 - 1941
pnpm-lock.yaml


+ 1 - 1
public/js/main_2020_show.js

@@ -14814,7 +14814,7 @@ window.Modernizr = function(n, e, t) {
 
                 if (data.showCad){ 
                     $.ajax({
-                      url: '//super.4dage.com/data/'+ window.number +'/floor.json', 
+                      url: 'https://super.4dage.com/data/'+ window.number +'/floor.json', 
                       method: 'GET',
                       success(res) {
                         grendCAD(res, document.documentElement, data.cadSignColor, data.cadBorderColor, data.cadBorderWidth)

+ 1 - 1
public/js/manage.js

@@ -1021,7 +1021,7 @@ Manage.prototype.dealURL = function(src, type){
     }else{
         //add https://
         var prefix = g_Prefix.replace('https://','').replace('http://','') 
-        if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix)){
+        if(!src.includes('http:/') && !src.includes('https:/') && src.includes(prefix) && src.indexOf('./') !== 0){
             src = 'https://'+src
         }
         return src

+ 18 - 0
scripts/generate-offline-config.js

@@ -0,0 +1,18 @@
+import { fileURLToPath } from 'node:url';
+import { dirname } from 'node:path';
+import fs from 'node:fs';
+
+const _filename = fileURLToPath(import.meta.url);
+const _dirname = dirname(_filename);
+
+const scene = process.env.VITE_APP_SCENE;
+
+const configContent = `{
+  "files": "build${scene ? '/' + scene : ''}/js/*.js",
+  "from": "https://super.4dage.com",
+  "to": "."
+}`;
+
+fs.writeFileSync(`${_dirname}/offline-replace-config.json`, configContent, 'utf-8');
+
+console.log(`offline-replace-config.json 已生成,场景: ${scene}`);

+ 5 - 0
scripts/offline-replace-config.json

@@ -0,0 +1,5 @@
+{
+  "files": "build/js/*.js",
+  "from": "https://super.4dage.com",
+  "to": "."
+}

+ 16 - 10
src/hotspot/views/hotspot/index.vue

@@ -29,14 +29,16 @@
         @slideChange="handleChange"
       >
         <SwiperSlide v-for="(item, index) in curList" :key="item.url">
-          <template v-if="myType === 'model'">
-            <iframe v-if="index === myInd" :src="item" frameborder="0" />
-          </template>
-          <template v-else-if="myType === 'video'">
-            <video ref="videos" controls :src="item.url" />
-          </template>
-          <template v-else-if="myType === 'img'">
-            <el-image :src="item" fit="contain" @click="handlePreview(index)" />
+          <template v-if="swiperInited">
+            <template v-if="myType === 'model'">
+              <iframe v-if="index === myInd" :src="item" frameborder="0" />
+            </template>
+            <template v-else-if="myType === 'video'">
+              <video ref="videos" controls :src="item.url" />
+            </template>
+            <template v-else-if="myType === 'img'">
+              <el-image :src="item" fit="contain" @click="handlePreview(index)" />
+            </template>
           </template>
         </SwiperSlide>
       </Swiper>
@@ -80,7 +82,7 @@
       :class="{ isTop: !flooTab.length && !isMobile }"
     >
       <h3>{{ myTitle }}</h3>
-      <p>{{ myTxt }}</p>
+      <div v-html="myTxt" />
     </div>
   </div>
 </template>
@@ -121,6 +123,7 @@
         isOneAduio: false,
         // 音频状态
         audioSta: false,
+        swiperInited: false,
 
         data: {
           // 模型数组
@@ -178,7 +181,9 @@
     methods: {
       async getData() {
         // https://www.4dmodel.com/
-        let url = `https://super.4dage.com/data/${this.id}/hot/js/data.js?time=${Math.random()}`;
+        let url = `${
+          Boolean(Number(import.meta.env.VITE_APP_OFFLINE)) ? '.' : 'https://super.4dage.com'
+        }/data/${this.id}/hot/js/data.js?time=${Math.random()}`;
         let result = await fetch(url).then((response) => response.json());
         const resData = result[this.m];
         console.log('----', resData);
@@ -259,6 +264,7 @@
 
       initSwiper(swiper) {
         this.swiper = swiper;
+        this.swiperInited = true;
       },
       handleChange({ activeIndex }) {
         this.myInd = activeIndex;

+ 1 - 1
src/index/views/home/components/hot-spot-list/index.tsx

@@ -15,7 +15,7 @@ export default defineComponent({
           <ul></ul>
         </div>
         <div id="hotListBottom">
-          <img id="hotListClose" src="/images/hotListClose.png" alt="" />
+          <img id="hotListClose" src="./images/hotListClose.png" alt="" />
         </div>
       </div>
     );