1. 开发推送以及热更新功能

huipay-app-dev
杨杰 1 year ago
parent 0b7da8dfcf
commit 8f25b05713
  1. 39
      components/downloadUp.vue
  2. 2
      manifest.json
  3. 129
      pages/tabBar/home/home.vue

@ -2,7 +2,7 @@
<view class="content" v-if="bannerShow"> <view class="content" v-if="bannerShow">
<!-- 弹出层 --> <!-- 弹出层 -->
<view class="uni-banner"> <view class="uni-banner">
<!-- <image src="../static/logo.png" class="startUpHeaderLogo" /> --> <image src="../static/logo.png" class="startUpHeaderLogo" />
<view class="banner_box"> <view class="banner_box">
<view class="startUpHeaderBox h6">发现新版本</view> <view class="startUpHeaderBox h6">发现新版本</view>
<view class="conter">{{ msg }}</view> <view class="conter">{{ msg }}</view>
@ -41,10 +41,11 @@
let localAppVersonName = uni.getStorageSync('version'); let localAppVersonName = uni.getStorageSync('version');
// #ifdef APP-PLUS // #ifdef APP-PLUS
let datas = { let datas = {
termType: "app" termType: "APP"
} }
queryVersion(datas).then(res => { queryVersion(datas).then(res => {
if (res.return_code == '000000') { if (res.return_code == '000000') {
that.msg = res.return_data.content;
if (res.return_data.versionType == 1 && that.comparisonVersionHandler(localAppVersonName, if (res.return_data.versionType == 1 && that.comparisonVersionHandler(localAppVersonName,
res.return_data.version)) { res.return_data.version)) {
that.downloadWgt(res.return_data.fileUrl); that.downloadWgt(res.return_data.fileUrl);
@ -67,19 +68,17 @@
const that = this; const that = this;
// wgt // wgt
plus.nativeUI.showWaiting('正在更新...'); plus.nativeUI.showWaiting('正在更新...');
plus.downloader plus.downloader.createDownload(
.createDownload( updateWgtUrl, {
updateWgtUrl, { filename: '_doc/update/'
filename: '_doc/update/' },
}, function(d, status) {
function(d, status) { if (status == 200) {
if (status == 200) { that.installWgt(d.filename); // wgt
that.installWgt(d.filename); // wgt
}
plus.nativeUI.closeWaiting();
} }
) plus.nativeUI.closeWaiting();
.start(); }
).start();
}, },
installWgt(path) { installWgt(path) {
// wgt // wgt
@ -100,7 +99,7 @@
); );
}, },
goUpdate() { goUpdate() {
if (this.type == 2) { // if (this.type == 2) {
// //
var dtask = plus.downloader.createDownload( var dtask = plus.downloader.createDownload(
this.updateApkObj.fileUrl, {}, this.updateApkObj.fileUrl, {},
@ -156,9 +155,9 @@
duration: 1500 duration: 1500
}); });
} }
} else if (this.type == 1) { // iosapp store // } else if (this.type == 1) { // iosapp store
plus.runtime.openURL(updateApkObj.downloadUrl); // plus.runtime.openURL(updateApkObj.downloadUrl);
} // }
}, },
// //
comparisonVersionHandler(reqV, curV) { comparisonVersionHandler(reqV, curV) {
@ -257,8 +256,8 @@
width: 80%; width: 80%;
.startUpHeaderLogo { .startUpHeaderLogo {
width: 256rpx; width: 200rpx;
height: 194rpx; height: 200rpx;
} }
.banner_box { .banner_box {

@ -128,6 +128,6 @@
"key": "7UMBZ-HFEHX-HSD4Q-Z3QY6-OQKN7-2QBDB" "key": "7UMBZ-HFEHX-HSD4Q-Z3QY6-OQKN7-2QBDB"
} }
} }
}, }
} }
} }

@ -103,6 +103,44 @@
}, },
onLoad() { onLoad() {
if (this.userInfo.secUser.objectType == 5) {
let status = 1;
let that = this;
uni.getPushClientId({
success: res => {
that.storeCid = res.cid;
uni.getStorage({
key: "clientId",
success: (res) => {
if (res.data && res.data != undefined && res.data != that
.storeCid) {
status = 2;
}
},
fail(err) {
status = 3;
uni.setStorage({
key: "clientId",
data: that.storeCid
})
}
})
},
fail(err) {
console.log(err);
}
})
setTimeout(function() {
if (status == 1 && that.storeCid) {
that.setTimer();
}
if ((status == 2 || status == 3) && that.storeCid) {
that.connectStoreCid(that.storeCid)
}
}, 1500);
}
uni.onPushMessage((res) => { uni.onPushMessage((res) => {
// console.log("", res.data.content) // // console.log("", res.data.content) //
let conts = res.data.content.split('!@#PUSH#@!'); let conts = res.data.content.split('!@#PUSH#@!');
@ -226,52 +264,73 @@
if (this.userInfo.secUser.objectType == 4) { if (this.userInfo.secUser.objectType == 4) {
this.mermoveHomeCount(); this.mermoveHomeCount();
} }
if (this.userInfo.secUser.objectType == 5) {
this.storemoveHomeCount();
let status = 1;
let that = this;
uni.getPushClientId({
success: res => {
that.storeCid = res.cid;
uni.getStorage({
key: "clientId",
success: (res) => {
if (res.data && res.data != undefined && res.data != that
.storeCid) {
status = 2;
}
},
fail(err) {
status = 1;
uni.setStorage({
key: "clientId",
data: that.storeCid
})
}
})
},
fail(err) {
console.log(err);
}
})
setTimeout(function() {
if (status == 1 && that.storeCid) {
that.connectStoreCid(that.storeCid)
}
}, 1500);
if (this.userInfo.secUser.objectType == 5) {
this.storemoveHomeCount();
} }
this.getDictionaries(); this.getDictionaries();
}, },
methods: { methods: {
Timersockt() {},
//cid //cid
connectStoreCid(item) { connectStoreCid(item) {
let datas = { let datas = {
"cid": item, "cid": item,
"storeId": this.userInfo.store.id "storeId": this.userInfo.store.id
} }
connectStoreCid(datas).then(res => {}) connectStoreCid(datas).then(res => {
this.setTimer();
})
},
setTimer() {
let holdTime = 10;
this.Timersockt = setInterval(() => {
if (holdTime <= 0) {
holdTime = 60;
clearInterval(this.Timersockt);
let status = 1;
let that = this;
uni.getPushClientId({
success: res => {
that.storeCid = res.cid;
uni.getStorage({
key: "clientId",
success: (res) => {
if (res.data && res.data != undefined && res
.data != that
.storeCid) {
status = 2;
}
},
fail(err) {
status = 3;
uni.setStorage({
key: "clientId",
data: that.storeCid
})
}
})
},
fail(err) {
console.log(err);
}
})
setTimeout(function() {
if (status == 1 && that.storeCid) {
that.setTimer();
}
if ((status == 2 || status == 3) && that.storeCid) {
that.connectStoreCid(that.storeCid)
}
}, 1500);
return;
}
holdTime--;
}, 1000)
}, },
// //
voiceSucceed(item) { voiceSucceed(item) {

Loading…
Cancel
Save