Selaa lähdekoodia

fix: micro适配

lvkun996 2 vuotta sitten
vanhempi
commit
1ce4833f9f
4 muutettua tiedostoa jossa 63 lisäystä ja 57 poistoa
  1. BIN
      cloudlink.zip
  2. 5 1
      src/main.ts
  3. 5 3
      src/router/index.ts
  4. 53 53
      vue.config.js

BIN
cloudlink.zip


+ 5 - 1
src/main.ts

@@ -54,8 +54,10 @@ const render = (props: any = {}) => {
   if (window.__POWERED_BY_QIANKUN__) {
     data.store.useJLYAppRouter().setChildrenSiderRoutes(routes.map(item => item.children).filter(_ => !!_))
   }
-
+  console.log('当前加载是qiankun么:', window.__POWERED_BY_QIANKUN__)
+  console.log('当前加载容器是否存在:', container)
   instance = createApp(App)
+  console.log('当前应用实例:', instance)
   instance.use(router)
     .use(pinia)
     .use(antd)
@@ -66,6 +68,8 @@ const render = (props: any = {}) => {
   instance.mount(container ? container.querySelector('#cloudlink-ui') : '#cloudlink-ui') as any
 }
 
+console.log('是否是window.__POWERED_BY_QIANKUN__:', window.__POWERED_BY_QIANKUN__)
+
 /** eslint-disable */
 if (!window.__POWERED_BY_QIANKUN__) {
   render()

+ 5 - 3
src/router/index.ts

@@ -1,6 +1,6 @@
 import { useIsMicro } from '@/hooks/effect'
 import vueRouter, { NavigationFailure, RouteRecordRaw, createRouter, createWebHistory, RouterView } from 'vue-router'
-
+import dashboard from '@/pages/iot/dashboard/deviceAccess/index.vue'
 const iot = {
   path: '/iot',
   name: '物联网',
@@ -14,7 +14,7 @@ const iot = {
       path: '/dashboard',
       name: '系统概览',
       icon: 'DashboardOutlined',
-      component: () => import('@/pages/iot/dashboard/deviceAccess/index.vue')
+      component: dashboard
     },
     {
       path: '/product',
@@ -484,8 +484,10 @@ const microRouter = useIsMicro()
     ]
   : routes
 
+const baseUri = window.__POWERED_BY_QIANKUN__ ? '/cloudlink/' : process.env.NODE_ENV === 'development' ? './' : '/child/cloudlink/'
+
 const router = createRouter({
-  history: createWebHistory(window.__POWERED_BY_QIANKUN__ ? '/cloudlink' : '/'),
+  history: createWebHistory(baseUri),
   routes: microRouter
 })
 

+ 53 - 53
vue.config.js

@@ -1,53 +1,53 @@
-const { defineConfig } = require('@vue/cli-service')
-const proxy = require('./config/proxy.ts')
-const path = require('path')
-const { resolve } = require('path')
-const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
-const packageName = require('./package.json').name
-
-module.exports = defineConfig({
-  // publicPath: '',
-  transpileDependencies: true,
-  devServer: {
-    proxy: proxy.dev,
-    headers: {
-      'Access-Control-Allow-Origin': '*'
-    },
-    port: 10800
-  },
-  pluginOptions: {
-    'style-resources-loader': {
-      preProcessor: 'less',
-      patterns: [
-        path.resolve(__dirname, '@/src/styes/*.less')
-      ]
-    }
-  },
-  chainWebpack: config => {
-    config.resolve.alias
-      .set('ThingsUi', resolve(__dirname, '/'))
-      .set('AppConfig', resolve(__dirname, './config/defaultSetting'))
-    config.stats('none')
-    config.mode('development')
-  },
-  configureWebpack: {
-    plugins: [
-      // new BundleAnalyzerPlugin()
-    ],
-    output: {
-      library: `${packageName}`,
-      libraryTarget: 'umd',
-      // libraryTarget: 'window',
-      chunkLoadingGlobal: `webpackJsonp_${packageName}`
-    }
-  },
-  css: {
-    loaderOptions: {
-      less: {
-        lessOptions: {
-          javascriptEnabled: true
-        }
-      }
-    }
-  }
-})
+const { defineConfig } = require('@vue/cli-service')
+const proxy = require('./config/proxy.ts')
+const path = require('path')
+const { resolve } = require('path')
+const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
+const packageName = require('./package.json').name
+
+module.exports = defineConfig({
+  // publicPath: process.env.NODE_ENV === 'development' ? '' : '',
+  publicPath: process.env.NODE_ENV === 'development' ? './' : '/child/cloudlink/',
+  transpileDependencies: true,
+  devServer: {
+    proxy: proxy.dev,
+    headers: {
+      'Access-Control-Allow-Origin': '*'
+    },
+    port: 10800
+  },
+  pluginOptions: {
+    'style-resources-loader': {
+      preProcessor: 'less',
+      patterns: [
+        path.resolve(__dirname, '@/src/styes/*.less')
+      ]
+    }
+  },
+  chainWebpack: config => {
+    config.resolve.alias
+      .set('ThingsUi', resolve(__dirname, '/'))
+      .set('AppConfig', resolve(__dirname, './config/defaultSetting'))
+    config.stats('none')
+    config.mode('development')
+  },
+  configureWebpack: {
+    plugins: [
+      // new BundleAnalyzerPlugin()
+    ],
+    output: {
+      library: `${packageName}`,
+      libraryTarget: 'umd',
+      chunkLoadingGlobal: `webpackJsonp_${packageName}`
+    }
+  },
+  css: {
+    loaderOptions: {
+      less: {
+        lessOptions: {
+          javascriptEnabled: true
+        }
+      }
+    }
+  }
+})