Browse Source

app更新

shish 4 years ago
parent
commit
2292a96d30

+ 2 - 1
ghsApp/src/admin/home/workbench.vue

@@ -96,10 +96,11 @@ import { consoleIndex } from "@/api/workbench";
 import { closeBook } from "@/api/book";
 import productMins from "@/mixins/product";
 import { allProduct } from '@/api/product'
+import autoUpdateMixins from "@/mixins/autoUpdate";
 export default {
 	name: "admin-workbench",
 	components: { NotLogin },
-	mixins: [productMins],
+	mixins: [productMins,autoUpdateMixins],
 	data() {
 		return {
 			getappIdList: {},

+ 4 - 0
ghsApp/src/api/auth/index.js

@@ -9,3 +9,7 @@ export const phoneLogin = data => {
 export const wxMobileLogin = data => { 
 	return	https.post("/auth/wx-mobile-login", data) 
 }
+
+export const getApkVersion = data => {
+	return https.get('/auth/get-apk-version', data)
+}

+ 1 - 0
ghsApp/src/api/console/index.js

@@ -0,0 +1 @@
+import https from '@/plugins/luch-request_0.0.7/request'

+ 1 - 1
ghsApp/src/mixins/animation.js

@@ -17,4 +17,4 @@ export default {
 			}
 		},
 	}
-};
+};

+ 68 - 0
ghsApp/src/mixins/autoUpdate.js

@@ -0,0 +1,68 @@
+import { getApkVersion } from '@/api/auth'
+import { APIHOST } from '@/config'
+export default {
+	data() {
+		return {
+            version:0
+		};
+	},
+    onLoad(){
+        // #ifdef APP-PLUS
+        plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
+            console.log(JSON.stringify(wgtinfo));
+            console.log(wgtinfo.version);
+            this.version = wgtinfo.version
+        });
+        uni.getSystemInfo({  
+            success:(res) => {  
+                console.log(res.platform);  
+                //检测当前平台,如果是安卓则启动安卓更新  
+                if(res.platform=="android"){  
+                    this.androidCheckUpdate()   
+                }  
+            }  
+        })
+        // #endif
+    },
+	methods: {
+        androidCheckUpdate(){
+            getApkVersion().then(res=>{
+                if(res.code == 1){
+                    let version = res.data.version
+                    let mustUpdate = res.data.mustUpdate
+                    let singer = mustUpdate == 1 ? true : false
+                    if(version <= this.version){
+                        return false
+                    }
+
+                    if(plus.networkinfo.getCurrentType()!=3){
+                        let that = this
+                        that.$util.confirmModal({content:'新版本更新',cancelText:'稍后',okText:'使用流量更新'},() => {
+                          this.install(version)
+                        })
+                    }else{
+                        let that = this
+                        that.$util.confirmModal({content:'新版本更新',singer:singer},() => {
+                          this.install(version)
+                        })
+                    }
+                }
+            })            
+        },
+        install(version){
+            console.log(APIHOST+'/apk/'+version+'.apk')
+            uni.showToast({ title: '后台下载中...', mask: false, duration: 1200,icon:"none"})
+            var dtask = plus.downloader.createDownload( APIHOST+'/apk/'+version+'.apk', {}, function ( d, status ) {  
+                // 下载完成  
+                if ( status == 200 ) {   
+                    plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){  
+                        uni.showToast({ title: '安装失败', mask: false, duration: 1500,icon:"none" })
+                    })  
+                } else {  
+                    uni.showToast({ title: '更新失败', mask: false, duration: 1500,icon:"none" })
+                }
+            });
+            dtask.start()
+        }
+	}
+}

+ 3 - 2
ghsApp/src/mixins/globalMixins.js

@@ -8,9 +8,10 @@ import { allProduct } from '@/api/product'
 import { codePay} from "@/api/order/index";
 
 // #ifdef APP-PLUS
-const shangMiPrint = uni.requireNativePlugin('G5KJ-ShangMiPrint')
-const globalEvent = uni.requireNativePlugin('globalEvent')
+//const shangMiPrint = uni.requireNativePlugin('G5KJ-ShangMiPrint')
+//const globalEvent = uni.requireNativePlugin('globalEvent')
 // #endif
+
 export default {
 	data() {
 		return {

+ 2 - 1
ghsApp/src/utils/util.js

@@ -357,6 +357,7 @@ export const confirmModal = (item,okCallback=null,cancelCallback=null) => {
 	let cancelText = item.cancelText || '取消'
 	let cacelTextColor = '#999999'
 	let okTextColor = '#38ADFF'
+	let singer = item.singer || false
 
 	//#ifdef APP-PLUS
 	let options={
@@ -366,7 +367,7 @@ export const confirmModal = (item,okCallback=null,cancelCallback=null) => {
 		cancleTitle:cancelText,//取消按钮文字(可选)
 		okTextColor:"#38ADFF",//确认按钮颜色(可选)
 		cancleTextColor:"#999999",//取消按钮颜色(可选)
-		singer:false,//是否只显示确认按钮,默认false(可选)
+		singer:singer,//是否只显示确认按钮,默认false(可选)
 		textAlign:"center",//对齐方式 //left居左,center居中,right 居右 默认居中
 		conColor:"",
 		bgColor:"#FFFFFF",//自定义弹框颜色

+ 3 - 3
hdApp/src/admin/home/workbench.vue

@@ -76,11 +76,11 @@ import { getWeixinId } from "@/api/invite/index";
 import { getUser } from "@/utils/auth";
 import { consoleIndex } from "@/api/workbench";
 import NotLogin from "@/components/not-login";
+import autoUpdateMixins from "@/mixins/autoUpdate";
 export default {
   name: "workbench",
-  components: {
-    NotLogin
-  },
+  components: { NotLogin },
+  mixins: [autoUpdateMixins],
   data () {
     return {
       constant: this.$constant,

+ 4 - 0
hdApp/src/api/auth/index.js

@@ -8,4 +8,8 @@ export const phoneLogin = data => {
 //微信手机号一键登录 shish 20210121
 export const wxMobileLogin = data => { 
 	return	https.post("/auth/wx-mobile-login", data) 
+}
+
+export const getApkVersion = data => {
+	return https.get('/auth/get-apk-version', data)
 }

+ 68 - 0
hdApp/src/mixins/autoUpdate.js

@@ -0,0 +1,68 @@
+import { getApkVersion } from '@/api/auth'
+import { APIHOST } from '@/config'
+export default {
+	data() {
+		return {
+            version:0
+		};
+	},
+    onLoad(){
+        // #ifdef APP-PLUS
+        plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
+            console.log(JSON.stringify(wgtinfo));
+            console.log(wgtinfo.version);
+            this.version = wgtinfo.version
+        });
+        uni.getSystemInfo({  
+            success:(res) => {  
+                console.log(res.platform);  
+                //检测当前平台,如果是安卓则启动安卓更新  
+                if(res.platform=="android"){  
+                    this.androidCheckUpdate()   
+                }  
+            }  
+        })
+        // #endif
+    },
+	methods: {
+        androidCheckUpdate(){
+            getApkVersion().then(res=>{
+                if(res.code == 1){
+                    let version = res.data.version
+                    let mustUpdate = res.data.mustUpdate
+                    let singer = mustUpdate == 1 ? true : false
+                    if(version <= this.version){
+                        return false
+                    }
+
+                    if(plus.networkinfo.getCurrentType()!=3){
+                        let that = this
+                        that.$util.confirmModal({content:'新版本更新',cancelText:'稍后',okText:'使用流量更新'},() => {
+                          this.install(version)
+                        })
+                    }else{
+                        let that = this
+                        that.$util.confirmModal({content:'新版本更新',singer:singer},() => {
+                          this.install(version)
+                        })
+                    }
+                }
+            })            
+        },
+        install(version){
+            console.log(APIHOST+'/apk/'+version+'.apk')
+            uni.showToast({ title: '后台下载中...', mask: false, duration: 1200,icon:"none"})
+            var dtask = plus.downloader.createDownload( APIHOST+'/apk/'+version+'.apk', {}, function ( d, status ) {  
+                // 下载完成  
+                if ( status == 200 ) {   
+                    plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){  
+                        uni.showToast({ title: '安装失败', mask: false, duration: 1500,icon:"none" })
+                    })  
+                } else {  
+                    uni.showToast({ title: '更新失败', mask: false, duration: 1500,icon:"none" })
+                }
+            });
+            dtask.start()
+        }
+	}
+}

+ 2 - 1
hdApp/src/utils/util.js

@@ -311,6 +311,7 @@ export const confirmModal = (item,okCallback=null,cancelCallback=null) => {
 	let cancelText = item.cancelText || '取消'
 	let cacelTextColor = '#999999'
 	let okTextColor = '#38ADFF'
+	let singer = item.singer || false
 
 	//#ifdef APP-PLUS
 	let options={
@@ -320,7 +321,7 @@ export const confirmModal = (item,okCallback=null,cancelCallback=null) => {
 		cancleTitle:cancelText,//取消按钮文字(可选)
 		okTextColor:"#38ADFF",//确认按钮颜色(可选)
 		cancleTextColor:"#999999",//取消按钮颜色(可选)
-		singer:false,//是否只显示确认按钮,默认false(可选)
+		singer:singer,//是否只显示确认按钮,默认false(可选)
 		textAlign:"center",//对齐方式 //left居左,center居中,right 居右 默认居中
 		conColor:"",
 		bgColor:"#FFFFFF",//自定义弹框颜色