|
@@ -89,6 +89,14 @@
|
|
|
<h-address @select="selectaddress" :visible.sync="showAddress" />
|
|
<h-address @select="selectaddress" :visible.sync="showAddress" />
|
|
|
<!-- 隐私指引 -->
|
|
<!-- 隐私指引 -->
|
|
|
<!-- <xh-privacy title="隐私保护指引" color="#18bb88"></xh-privacy> -->
|
|
<!-- <xh-privacy title="隐私保护指引" color="#18bb88"></xh-privacy> -->
|
|
|
|
|
+ <!-- #ifdef APP-PLUS -->
|
|
|
|
|
+ <uni-popup ref="popup">
|
|
|
|
|
+ <view class="progressBox">
|
|
|
|
|
+ <icon type="loading" size="26"/>
|
|
|
|
|
+ <text class="words">下载中 请勿退出 {{ totalBytesWritten + " / " + totalBytesExpectedToWrite }}</text>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ </uni-popup>
|
|
|
|
|
+ <!-- #endif -->
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
<script>
|
|
<script>
|
|
@@ -97,6 +105,7 @@ import swiperBanner from "@/components/swiperBanner/index.vue"; //轮播
|
|
|
import hAddress from "@/components/h-address/address.vue"; //城市选择
|
|
import hAddress from "@/components/h-address/address.vue"; //城市选择
|
|
|
import tabs from '@/static/js/tabs' //专区入口
|
|
import tabs from '@/static/js/tabs' //专区入口
|
|
|
import { post } from "@/request/api.js";
|
|
import { post } from "@/request/api.js";
|
|
|
|
|
+import { formatBytes } from "@/utils/index";
|
|
|
export default {
|
|
export default {
|
|
|
name: "Appindex",
|
|
name: "Appindex",
|
|
|
components: {
|
|
components: {
|
|
@@ -113,13 +122,21 @@ export default {
|
|
|
searchKey: "", //搜索关键词
|
|
searchKey: "", //搜索关键词
|
|
|
LocationCity: "深圳",
|
|
LocationCity: "深圳",
|
|
|
showAddress: false,
|
|
showAddress: false,
|
|
|
- tabs
|
|
|
|
|
|
|
+ tabs,
|
|
|
|
|
+ totalBytesWritten: "0B", // 已经下载的数据长度
|
|
|
|
|
+ totalBytesExpectedToWrite: "0B", // 预期需要下载的数据总长度
|
|
|
|
|
+ filePath:"",
|
|
|
|
|
+ percentVal:0,
|
|
|
|
|
+ newAppInfo:{}
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
onLoad(option) {
|
|
onLoad(option) {
|
|
|
this.getToCity()
|
|
this.getToCity()
|
|
|
this.loadData()
|
|
this.loadData()
|
|
|
// uni.Luserfun()
|
|
// uni.Luserfun()
|
|
|
|
|
+ // #ifdef APP-PLUS
|
|
|
|
|
+ this.getNewVersion()
|
|
|
|
|
+ // #endif
|
|
|
},
|
|
},
|
|
|
onShow() {
|
|
onShow() {
|
|
|
this.getBanner(); //获取轮播图
|
|
this.getBanner(); //获取轮播图
|
|
@@ -134,6 +151,26 @@ export default {
|
|
|
this.productList = res.data.data;
|
|
this.productList = res.data.data;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ },
|
|
|
|
|
+ getNewVersion(){
|
|
|
|
|
+ post("v1/getAppVersion").then((res) => {
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ console.log(res.data.data);
|
|
|
|
|
+ if(plus.os.name == "Android"){
|
|
|
|
|
+ this.filePath = res.data.data.android.url
|
|
|
|
|
+ this.newAppInfo = res.data.data.android
|
|
|
|
|
+ // 获取当前版本
|
|
|
|
|
+ plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
|
|
|
|
|
+ console.log();
|
|
|
|
|
+ if(wgtinfo.versionCode < this.newAppInfo.version){
|
|
|
|
|
+ this.update()
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
// 跳转到商品详情页
|
|
// 跳转到商品详情页
|
|
|
NavToGoodsDetail(id, type) {
|
|
NavToGoodsDetail(id, type) {
|
|
@@ -216,6 +253,95 @@ export default {
|
|
|
this.LocationCity = da.cityName;
|
|
this.LocationCity = da.cityName;
|
|
|
this.showAddress = false;
|
|
this.showAddress = false;
|
|
|
},
|
|
},
|
|
|
|
|
+ update(){
|
|
|
|
|
+ const _this = this;
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: "版本更新",
|
|
|
|
|
+ content: "APP有新版本发布,点击 立即更新 进行最新版本下载。",
|
|
|
|
|
+ showCancel: this.newAppInfo.is_mast == 1 ? true: false,
|
|
|
|
|
+ confirmText: "立即更新",
|
|
|
|
|
+ cancelText: "稍后进行",
|
|
|
|
|
+ success: function (res) {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ _this.$refs.popup.open()
|
|
|
|
|
+
|
|
|
|
|
+ // _this.show = true; // show变量控制一个下载进度弹框(这个UI样式自己写即可)
|
|
|
|
|
+ // 创建一个下载任务,并根据后端返回的apk静态资源地址filePath进行下载
|
|
|
|
|
+
|
|
|
|
|
+ let downloadTask = uni.downloadFile({
|
|
|
|
|
+ url: _this.filePath,
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ console.log(res, "下载成功");
|
|
|
|
|
+ this.updateProgressShow = false;
|
|
|
|
|
+ if (res.statusCode === 200) {
|
|
|
|
|
+ _this.$refs.popup.close()
|
|
|
|
|
+ plus.runtime.install(
|
|
|
|
|
+ res.tempFilePath,
|
|
|
|
|
+ {},
|
|
|
|
|
+ function () {
|
|
|
|
|
+ console.log("install success...");
|
|
|
|
|
+ plus.runtime.restart();
|
|
|
|
|
+ // uni.hideLoading();
|
|
|
|
|
+ uni.setStorageSync("wgtinfo", null);
|
|
|
|
|
+ },
|
|
|
|
|
+ function (e) {
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: "error",
|
|
|
|
|
+ title: "更新失败",
|
|
|
|
|
+ duration: 1500,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ _this.$refs.popup.close()
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: "error",
|
|
|
|
|
+ title: "更新失败",
|
|
|
|
|
+ duration: 1500,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ _this.$refs.popup.close()
|
|
|
|
|
+ uni.showToast({
|
|
|
|
|
+ icon: "error",
|
|
|
|
|
+ title: "更新失败",
|
|
|
|
|
+ duration: 1500,
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ downloadTask.onProgressUpdate((res) => {
|
|
|
|
|
+ // console.log(res, "进度");
|
|
|
|
|
+ // console.log("下载进度" + res.progress);
|
|
|
|
|
+ // console.log("已经下载的数据长度" + res.totalBytesWritten);
|
|
|
|
|
+ // console.log(
|
|
|
|
|
+ // "预期需要下载的数据总长度" + res.totalBytesExpectedToWrite
|
|
|
|
|
+ // );
|
|
|
|
|
+ let totalBytesWritten = formatBytes(res.totalBytesWritten);
|
|
|
|
|
+ let totalBytesExpectedToWrite = formatBytes(
|
|
|
|
|
+ res.totalBytesExpectedToWrite
|
|
|
|
|
+ );
|
|
|
|
|
+ let num1 = totalBytesWritten.fileSize.split(
|
|
|
|
|
+ totalBytesWritten.matchUnit.unitName
|
|
|
|
|
+ );
|
|
|
|
|
+ let num2 = totalBytesExpectedToWrite.fileSize.split(
|
|
|
|
|
+ totalBytesExpectedToWrite.matchUnit.unitName
|
|
|
|
|
+ );
|
|
|
|
|
+ _this.totalBytesWritten =
|
|
|
|
|
+ Math.floor(num1[0] * 100) / 100 +
|
|
|
|
|
+ totalBytesWritten.matchUnit.unitName;
|
|
|
|
|
+ _this.totalBytesExpectedToWrite =
|
|
|
|
|
+ Math.floor(num2[0] * 100) / 100 +
|
|
|
|
|
+ totalBytesExpectedToWrite.matchUnit.unitName;
|
|
|
|
|
+ _this.percentVal = res.progress;
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (res.cancel) {
|
|
|
|
|
+ console.log("稍后更新");
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
computed: {},
|
|
computed: {},
|
|
|
watch: {},
|
|
watch: {},
|
|
@@ -519,4 +645,10 @@ export default {
|
|
|
padding: 0 16rpx;
|
|
padding: 0 16rpx;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+.progressBox{
|
|
|
|
|
+ padding: 40rpx;
|
|
|
|
|
+ border-radius: 4rpx;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+}
|
|
|
</style>
|
|
</style>
|