瀏覽代碼

app兼容

2662043119@qq.com 1 年之前
父節點
當前提交
e3a0d9d068

+ 4 - 0
.hbuilderx/launch.json

@@ -2,6 +2,10 @@
   // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
     "version": "0.0",
     "configurations": [{
+     	"app-plus" : 
+     	{
+     		"launchtype" : "local"
+     	},
      	"default" : 
      	{
      		"launchtype" : "local"

+ 2 - 1
src/App.vue

@@ -10,12 +10,13 @@ export default {
         logs.unshift(Date.now());
         uni.setStorageSync("logs", logs);
         uni.setStorageSync("mallName", "茶付宝");
-
+        // #ifdef MP-WEIXIN
         let accountInfo = __wxConfig.accountInfo
         this.globalData.shopInfo = {
             shop_name: accountInfo.nickname,
             shop_image: accountInfo.icon
         }
+        // #endif
     },
     onShow() {
         this.autoUpdate();

+ 3 - 3
src/app.scss

@@ -47,9 +47,9 @@ view,text,div {
 /* 在线链接服务仅供平台体验和调试使用,平台不承诺服务的稳定性,企业客户需下载字体包自行发布使用并做好备份。 */
 @font-face {
     font-family: 'iconfont';  /* Project id 3748689 */
-    src: url('//at.alicdn.com/t/c/font_3748689_9skur541wqr.woff2?t=1701678660669') format('woff2'),
-         url('//at.alicdn.com/t/c/font_3748689_9skur541wqr.woff?t=1701678660669') format('woff'),
-         url('//at.alicdn.com/t/c/font_3748689_9skur541wqr.ttf?t=1701678660669') format('truetype');
+    src: url('https://at.alicdn.com/t/c/font_3748689_9skur541wqr.woff2?t=1701678660669') format('woff2'),
+         url('https://at.alicdn.com/t/c/font_3748689_9skur541wqr.woff?t=1701678660669') format('woff'),
+         url('https://at.alicdn.com/t/c/font_3748689_9skur541wqr.ttf?t=1701678660669') format('truetype');
 }
 
 .iconfont {

+ 44 - 5
src/manifest.json

@@ -1,12 +1,15 @@
 {
     "name" : "茶付宝",
-    "appid" : "__UNI__95AE405",
+    "appid" : "__UNI__14DB23C",
     "description" : "",
     "versionName" : "1.0.0",
-    "versionCode" : "100",
+    "versionCode" : 100,
     "transformPx" : false,
     /* 5+App特有相关 */
     "app-plus" : {
+        "compatible" : {
+            "ignoreVersion" : true //true表示忽略版本检查提示框,HBuilderX1.9.0及以上版本支持  
+        },
         "usingComponents" : true,
         "nvueCompiler" : "uni-app",
         "compilerVersion" : 3,
@@ -48,9 +51,45 @@
                 ]
             },
             /* ios打包配置 */
-            "ios" : {},
+            "ios" : {
+                "dSYMs" : false
+            },
             /* SDK配置 */
-            "sdkConfigs" : {}
+            "sdkConfigs" : {
+                "ad" : {}
+            },
+            "icons" : {
+                "android" : {
+                    "hdpi" : "unpackage/res/icons/72x72.png",
+                    "xhdpi" : "unpackage/res/icons/96x96.png",
+                    "xxhdpi" : "unpackage/res/icons/144x144.png",
+                    "xxxhdpi" : "unpackage/res/icons/192x192.png"
+                },
+                "ios" : {
+                    "appstore" : "unpackage/res/icons/1024x1024.png",
+                    "ipad" : {
+                        "app" : "unpackage/res/icons/76x76.png",
+                        "app@2x" : "unpackage/res/icons/152x152.png",
+                        "notification" : "unpackage/res/icons/20x20.png",
+                        "notification@2x" : "unpackage/res/icons/40x40.png",
+                        "proapp@2x" : "unpackage/res/icons/167x167.png",
+                        "settings" : "unpackage/res/icons/29x29.png",
+                        "settings@2x" : "unpackage/res/icons/58x58.png",
+                        "spotlight" : "unpackage/res/icons/40x40.png",
+                        "spotlight@2x" : "unpackage/res/icons/80x80.png"
+                    },
+                    "iphone" : {
+                        "app@2x" : "unpackage/res/icons/120x120.png",
+                        "app@3x" : "unpackage/res/icons/180x180.png",
+                        "notification@2x" : "unpackage/res/icons/40x40.png",
+                        "notification@3x" : "unpackage/res/icons/60x60.png",
+                        "settings@2x" : "unpackage/res/icons/58x58.png",
+                        "settings@3x" : "unpackage/res/icons/87x87.png",
+                        "spotlight@2x" : "unpackage/res/icons/80x80.png",
+                        "spotlight@3x" : "unpackage/res/icons/120x120.png"
+                    }
+                }
+            }
         }
     },
     /* 快应用特有相关 */
@@ -64,7 +103,7 @@
             "postcss" : false,
             "minified" : true
         },
-		"optimization": true,
+        "optimization" : true,
         "usingComponents" : true,
         "permission" : {
             "scope.userLocation" : {

+ 7 - 1
src/pages.json

@@ -188,6 +188,12 @@
 		// 		"enablePullDownRefresh": false
 		// 	}
 		// },
+		{
+			"path": "pages/my/login",
+			"style": {
+				"navigationBarTitleText": "登录"
+			}
+		},
 		{
 			"path": "pages/pay-agreement/index",
 			"style": {
@@ -608,7 +614,7 @@
 		"navigationBarBackgroundColor": "#fff",
 		"backgroundColor": "#fff",
 		"app-plus": {
-			"titleNView": false
+			"titleNView": true
 		}
 	},
 	"condition": {

+ 1 - 1
src/pages/consumerGold/index.vue

@@ -39,7 +39,7 @@
         <!-- 专区-end -->
         <!-- 活动 -->
         <view v-if="activeShow">
-          <view class="single_product">
+          <view class="single_product" v-if="homeImg.length">
             <image
               class="single_product_img"
               mode="widthFix"

+ 133 - 1
src/pages/index/index.vue

@@ -89,6 +89,14 @@
         <h-address @select="selectaddress" :visible.sync="showAddress" />
         <!-- 隐私指引 -->
         <!-- <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>
 </template>
 <script>
@@ -97,6 +105,7 @@ import swiperBanner from "@/components/swiperBanner/index.vue"; //轮播
 import hAddress from "@/components/h-address/address.vue"; //城市选择
 import tabs from '@/static/js/tabs' //专区入口
 import { post } from "@/request/api.js";
+import { formatBytes } from "@/utils/index";
 export default {
     name: "Appindex",
     components: {
@@ -113,13 +122,21 @@ export default {
             searchKey: "", //搜索关键词
             LocationCity: "深圳",
             showAddress: false,
-            tabs
+            tabs,
+            totalBytesWritten: "0B", // 已经下载的数据长度
+            totalBytesExpectedToWrite: "0B", // 预期需要下载的数据总长度
+            filePath:"",
+            percentVal:0,
+            newAppInfo:{}
         };
     },
     onLoad(option) {
         this.getToCity()
         this.loadData()
         // uni.Luserfun()
+        // #ifdef APP-PLUS
+        this.getNewVersion()
+        // #endif
     },
     onShow() {
         this.getBanner(); //获取轮播图
@@ -134,6 +151,26 @@ export default {
                     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) {
@@ -216,6 +253,95 @@ export default {
             this.LocationCity = da.cityName;
             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: {},
     watch: {},
@@ -519,4 +645,10 @@ export default {
         padding: 0 16rpx;
     }
 }
+
+.progressBox{
+    padding: 40rpx;
+    border-radius: 4rpx;
+    background-color: #fff;
+}
 </style>

+ 27 - 2
src/pages/my/index.vue

@@ -53,7 +53,7 @@
                 </view>
             </view>
             <view class="regional flex_r flex_ac" v-if="localInfo.operate.length > 0">
-                <img src="@/static/my/regional.png" alt="" srcset="" class="ico">
+                <image src="@/static/my/regional.png" alt="" srcset="" class="ico" />
                 <view class="flex_r flex_ac">
                     <span class="txtinfo">区域运营节点:</span>
                     <swiper class="notice_swiper" vertical autoplay circular :interval="2000" :duration="1000">
@@ -205,9 +205,14 @@
                 </view>
             </view>
         </view>
+        <!-- #ifdef APP-PLUS || H5 -->
+        <view class="confim flex_r flex_ac flex_jc"  @tap="loginOut">退出登录</view>
+        <!-- #endif -->
         <view class="fz_w_text">
             <view>让数字经济赋能美好生活!</view>
+            <!-- #ifdef MP-WEIXIN -->
             <view v-if="app.globalData.version">{{ app.globalData.version }}</view>
+            <!-- #endif -->
         </view>
         <!-- 授权 -->
         <authorize-module ref="autho" :shopInfo="shopInfo" @authGetTelSuccess="onauthGetTelSuccess" />
@@ -216,7 +221,9 @@
     </view>
 </template>
 <script>
+// #ifdef MP-WEIXIN
 let app = getApp();
+// #endif
 import uniCopy from "@/utils/copy";
 import authorizeModule from "@/components/authorize-module/index";
 import activation from "@/components/activation/activation.vue"
@@ -282,7 +289,7 @@ export default {
             // #endif
 
             // #ifdef  H5 || APP-PLUS
-            // this.goto("/pages/my/login");
+            this.goto("/pages/my/login");
             // #endif
         },
         // 获取手机号
@@ -376,6 +383,14 @@ export default {
                     }
                 }
             });
+        },
+        loginOut(){
+            post("v1/logout").then((res) => {
+            });
+            uni.clearStorageSync();
+            uni.reLaunch({
+                url:'/pages/my/login'
+            })
         }
     },
 };
@@ -707,4 +722,14 @@ page {
         line-height: 40rpx;
     }
 }
+
+.confim {
+    width: 90%;
+    height: 80rpx;
+    border-radius: 40rpx;
+    background: #2db389;
+    color: #fff;
+    font-size: 26rpx;
+    margin: 44rpx auto 0;
+}
 </style>

+ 7 - 4
src/pages/my/login.vue

@@ -2,7 +2,7 @@
     <view class="login">
         <view class="HLogo">
             <!-- <img src="@/static/img/ycjs.png" alt="" /> -->
-            <p>欢迎登录茶付宝</p>
+            <p>欢迎{{signIn?'注册':'登录'}}茶付宝</p>
         </view>
         <view class="phoneL" v-if="LoginType == 1">
             <view class="clearfix"><input v-model="formD2.mobile" placeholder="请输入手机号" type="number" maxlength="11" :focus="Focus == 1" /></view>
@@ -99,9 +99,12 @@ export default {
                         if(i.route != page) break;
                     }
 
-                    uni.navigateBack({
-                        delta: is
-                    });
+                    // uni.navigateBack({
+                    //     delta: is
+                    // });
+                    uni.reLaunch({
+                        url:'/pages/my/index'
+                    })
                 }
             });
         },

+ 1 - 1
src/request/request.js

@@ -40,7 +40,7 @@ uni.addInterceptor('request', {
 			});
 			setTimeout(() => {
 				// #ifdef  H5 || APP-PLUS
-				// goto("/pages/my/login");
+				uni.reLaunch({ url: "/pages/my/login" });
 				// #endif
 				// #ifdef  MP-WEIXIN
 				uni.switchTab({ url: "/pages/my/index" });

二進制
src/static/icon/share_.png


+ 44 - 0
src/utils/index.js

@@ -0,0 +1,44 @@
+// 文件大小格式化
+export const formatBytes = sizeBytes => {
+    let memoryUnits = [
+      {
+        unitName: 'B',
+        threshold: 1024,
+      },
+      {
+        unitName: 'KB',
+        threshold: 1024,
+      },
+      {
+        unitName: 'MB',
+        threshold: 1024,
+      },
+      {
+        unitName: 'GB',
+        threshold: 1024,
+      },
+      {
+        unitName: 'TB',
+        threshold: 1024,
+      },
+    ]
+  
+    let tempFileSize = sizeBytes;
+    let matchIndex = -1;
+  
+    for (let i = 0, end = false; i < memoryUnits.length; i++) {
+      let memoryUnit = memoryUnits[i], end = i === memoryUnits.length - 1
+      if (tempFileSize <= memoryUnit.threshold || end) {
+        matchIndex = i;
+        break;
+      }
+  
+      tempFileSize = tempFileSize / memoryUnit.threshold
+    }
+    return {
+      fileSize: tempFileSize + memoryUnits[matchIndex].unitName,
+      matchUnit: memoryUnits[matchIndex],
+      originalFileSize: sizeBytes,
+    };
+  }
+