mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	feat: 添加项目版本实时更新检测功能
This commit is contained in:
		
							parent
							
								
									7f02418839
								
							
						
					
					
						commit
						34379b9530
					
				@ -5,7 +5,7 @@
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "dev": "NODE_OPTIONS=--max-old-space-size=4096 vite",
 | 
			
		||||
    "serve": "pnpm dev",
 | 
			
		||||
    "build": "rimraf dist && NODE_OPTIONS=--max-old-space-size=8192 vite build",
 | 
			
		||||
    "build": "rimraf dist && NODE_OPTIONS=--max-old-space-size=8192 vite build && generate-version-file",
 | 
			
		||||
    "build:staging": "rimraf dist && vite build --mode staging",
 | 
			
		||||
    "report": "rimraf dist && vite build",
 | 
			
		||||
    "preview": "vite preview",
 | 
			
		||||
@ -66,6 +66,7 @@
 | 
			
		||||
    "typeit": "^8.7.1",
 | 
			
		||||
    "v-contextmenu": "3.0.0",
 | 
			
		||||
    "v3-infinite-loading": "^1.2.2",
 | 
			
		||||
    "version-rocket": "^1.6.2",
 | 
			
		||||
    "vue": "^3.3.4",
 | 
			
		||||
    "vue-i18n": "^9.2.2",
 | 
			
		||||
    "vue-json-pretty": "^2.2.4",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8727
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8727
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										27
									
								
								src/App.vue
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/App.vue
									
									
									
									
									
								
							@ -7,10 +7,12 @@
 | 
			
		||||
 | 
			
		||||
<script lang="ts">
 | 
			
		||||
import { defineComponent } from "vue";
 | 
			
		||||
import { checkVersion } from "version-rocket";
 | 
			
		||||
import { ElConfigProvider } from "element-plus";
 | 
			
		||||
import zhCn from "element-plus/lib/locale/lang/zh-cn";
 | 
			
		||||
import en from "element-plus/lib/locale/lang/en";
 | 
			
		||||
import { ReDialog } from "@/components/ReDialog";
 | 
			
		||||
import zhCn from "element-plus/lib/locale/lang/zh-cn";
 | 
			
		||||
 | 
			
		||||
export default defineComponent({
 | 
			
		||||
  name: "app",
 | 
			
		||||
  components: {
 | 
			
		||||
@ -21,6 +23,29 @@ export default defineComponent({
 | 
			
		||||
    currentLocale() {
 | 
			
		||||
      return this.$storage.locale?.locale === "zh" ? zhCn : en;
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  beforeCreate() {
 | 
			
		||||
    const { version, name: title } = __APP_INFO__.pkg;
 | 
			
		||||
    const { VITE_PUBLIC_PATH, MODE } = import.meta.env;
 | 
			
		||||
    // https://github.com/guMcrey/version-rocket/blob/main/README.zh-CN.md#api
 | 
			
		||||
    if (MODE === "production") {
 | 
			
		||||
      // 版本实时更新检测,只作用于线上环境
 | 
			
		||||
      checkVersion(
 | 
			
		||||
        // config
 | 
			
		||||
        {
 | 
			
		||||
          // 5分钟检测一次版本
 | 
			
		||||
          pollingTime: 300000,
 | 
			
		||||
          localPackageVersion: version,
 | 
			
		||||
          originVersionFileUrl: `${location.origin}${VITE_PUBLIC_PATH}version.json`
 | 
			
		||||
        },
 | 
			
		||||
        // options
 | 
			
		||||
        {
 | 
			
		||||
          title,
 | 
			
		||||
          description: "检测到新版本",
 | 
			
		||||
          buttonText: "立即更新"
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user