Browse Source

新增公众号端逻辑代码/优化检查更新功能模块

fanghuisheng 1 year ago
parent
commit
08d968713a

+ 0 - 32
src/App.vue

@@ -83,38 +83,6 @@ function pushListener() {
   });
 }
 
-function wechatToken() {
-  //获取当前页面的url
-  let link = window.location.href;
-  console.log(link, "link");
-  let code = null;
-  // 判断link中有没有code=字符串,
-  if (link.indexOf("code=") == -1) {
-    //没有code= 发请求
-    let appid = "wx41e478e592f9e04a";
-    let uri = encodeURIComponent(link);
-    let authURL = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`;
-    window.location.href = authURL;
-  } else {
-    //回调函数已经执行 返回的链接存在code= 地址解析
-    let temp = link.split("code=")[1];
-    code = temp.split("&")[0];
-    console.log(code, "code");
-    //存储code
-    uni.setStorageSync("code", code);
-    //对后台发送请求传参code获取token和用户信息
-    const params = code;
-
-    console.log(params);
-
-    // this.$httpApi.getUserInfo(params).then((res) => {
-    //   console.log("idnex 认证原文件", res);
-    //   uni.setStorageSync("mtoken", res);
-    //   console.log("token storage", res);
-    // });
-  }
-}
-
 watchEffect(() => {
   //#ifdef APP-PLUS || MP-WEIXIN
   if (uni.getStorageSync("serveUrl")) {

+ 0 - 4
src/components/oa-scroll/index.vue

@@ -117,10 +117,6 @@ const props = defineProps({
 
 const { pageSize, total, scrollTop, customClass, customStyle, refresherLoad, lowerThreshold, refresherEnabled, refresherThreshold, refresherDefaultStyle, refresherBackground } = toRefs(props);
 
-const defaultOption = reactive({});
-
-const {} = toRefs(defaultOption);
-
 const defaultArray = reactive({
   triggered: false,
   topTis: "松手刷新",

+ 24 - 15
src/components/oa-upgrade/index.vue

@@ -1,5 +1,5 @@
 <template>
-  <view class="upgrade-popup">
+  <view class="upgrade-popup" v-if="isModalShow">
     <image class="header-bg" src="@/static/images/common/oa-upgrade.png" mode="widthFix"></image>
     <view
       class="iconfont ucicon-oa-upgrade header-bg"
@@ -54,7 +54,7 @@
       </view>
     </view>
   </view>
-  <view class="upgrade-show"></view>
+  <view class="upgrade-show" v-if="isModalShow"></view>
 </template>
 <script setup>
 import { onReady, onLoad, onShow, onNavigationBarButtonTap, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
@@ -64,25 +64,21 @@ import { downloadApp, installApp } from "@/utils/upgrade.js";
 
 const { proxy } = getCurrentInstance();
 const props = defineProps({
-  //弹窗数据
-  modalArray: {
-    type: Object,
-    default: {},
-  },
   //主题颜色
   themesColor: {
     type: String,
     default: "#3f99ff",
   },
 });
-const emits = defineEmits(["closeModal"]);
-const { modalArra, themesColor } = toRefs(props);
+const emits = defineEmits([]);
+const { themesColor } = toRefs(props);
 
 const checkInfo = reactive({
+  isModalShow: false, //是否打开弹窗
   isForceUpdate: false, //是否强制更新
-  versionName: props.modalArray.buildVersion, //版本名称
-  versionDesc: props.modalArray.buildUpdateDescription.replace(/\\n/, "\n"), //更新说明
-  downloadUrl: props.modalArray.downloadURL, //APP下载链接
+  versionName: undefined, //版本名称
+  versionDesc: undefined, //更新说明
+  downloadUrl: undefined, //APP下载链接
   isDownloadFinish: false, //是否下载完成
   hasProgress: false, //是否能显示进度条
   currentPercent: 0, //当前下载百分比
@@ -90,7 +86,7 @@ const checkInfo = reactive({
   newFileName: "", //下载后app本地路径名称
 });
 
-const { modalTitle, modalContent, isForceUpdate, versionName, versionDesc, downloadUrl, isDownloadFinish, hasProgress, currentPercent, isStartDownload, newFileName } = toRefs(checkInfo);
+const { isModalShow, isForceUpdate, versionName, versionDesc, downloadUrl, isDownloadFinish, hasProgress, currentPercent, isStartDownload, newFileName } = toRefs(checkInfo);
 
 //设置进度条样式,实时更新进度位置
 const setProStyle = computed(() => {
@@ -143,17 +139,30 @@ function handleInstallApp() {
   if (isDownloadFinish.value && newFileName.value) {
     installApp(newFileName.value, () => {
       //安装成功,关闭升级弹窗
-      emits("closeModal", false);
+      isModalShow.value = false;
     });
   }
 }
 
+/** 打开弹窗 */
+function openUpgrade(e) {
+  isModalShow.value = true;
+
+  versionName.value = e.modalArray.buildVersion;
+  versionDesc.value = e.modalArray.buildUpdateDescription.replace(/\\n/, "\n");
+  downloadUrl.value = e.modalArray.downloadURL;
+}
+
 /** 取消按钮 */
 function handleCancel() {
-  emits("closeModal", false);
+  isModalShow.value = false;
 }
 
 onLoad((option) => {});
+
+defineExpose({
+  openUpgrade,
+});
 </script>
 
 <style lang="scss" scoped>

+ 0 - 2
src/pages/index.vue

@@ -111,11 +111,9 @@
 <script setup>
 import { onReady, onLoad, onShow, onNavigationBarButtonTap, onPullDownRefresh, onReachBottom } from "@dcloudio/uni-app";
 import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance, toRefs } from "vue";
-import { getToken } from "@/utils/auth";
 import { useStores, commonStores } from "@/store/modules/index";
 
 import { scan_push, getHomePageData, getFunctionalModuleStatistics, getAppRouters, qrCodeSend, getMobileBanner } from "@/api/index";
-import searchSelect from "@/components/searchSelect/searchSelect.vue";
 import * as jwx from "@/utils/jssdk.js"; //引入js sdk的封装
 
 const useStore = useStores();

+ 8 - 14
src/pages/mine.vue

@@ -29,7 +29,7 @@
               <view>我的信息</view>
             </view>
           </view>
-          <view class="list-cell list-cell-arrow" @click="proxy.$settingStore.handleToSecure()">
+          <view class="list-cell list-cell-arrow" @click="proxy.$settingStore.handleToSecure()" v-if="proxy.$common.isVisible()">
             <view class="menu-item">
               <view class="iconfont ucicon-yanzheng menu-item-icon"></view>
               <view>账号与安全</view>
@@ -41,7 +41,7 @@
               <view>关于我们</view>
             </view>
           </view>
-          <view class="list-cell list-cell-arrow" @click="proxy.$settingStore.handleHelp()">
+          <view class="list-cell list-cell-arrow" @click="proxy.$settingStore.handleHelp()" v-if="proxy.$common.isVisible()">
             <view class="menu-item">
               <view class="iconfont ucicon-Help menu-item-icon"></view>
               <view>常见问题</view>
@@ -55,7 +55,7 @@
             </view>
           </view>
 
-          <view class="list-cell list-cell-arrow" @click="handleToUpgrade">
+          <view class="list-cell list-cell-arrow" @click="handleToUpgrade" v-if="proxy.$common.isVisible()">
             <view class="menu-item">
               <view class="iconfont ucicon-jianchagengxin menu-item-icon"></view>
               <view>检查更新</view>
@@ -108,7 +108,7 @@
           </view>
         </view>
 
-        <view class="menu-list" @click="proxy.$settingStore.handleLogout">
+        <view class="menu-list" @click="proxy.$settingStore.handleLogout" v-if="proxy.$common.isVisible()">
           <view class="list-cell">
             <view class="menu-item">
               <view class="button">退 出 登 录</view>
@@ -153,7 +153,7 @@
       </view>
     </view>
 
-    <oa-upgrade v-if="modalShow" :modalArray="modalArray" :themesColor="proxy.$settingStore.themeColor.color" @closeModal="closeModal" />
+    <oa-upgrade ref="oaUpgradeRef" :themesColor="proxy.$settingStore.themeColor.color" />
   </view>
 
   <oa-tabbar :tabbarValue="2"></oa-tabbar>
@@ -212,8 +212,9 @@ function handleToUpgrade() {
       if (res.data.buildHaveNewVersion == true) {
         //安卓手机弹窗升级
         if (platform === "android") {
-          modalShow.value = true;
-          modalArray.value = res.data;
+          proxy.$refs["oaUpgradeRef"].openUpgrade({
+            modalArray: res.data,
+          });
         }
         //IOS无法在线升级提示到商店下载
         else {
@@ -232,13 +233,6 @@ function handleToUpgrade() {
   });
 }
 
-/**
- * @关闭弹窗
- */
-function closeModal(flag) {
-  modalShow.value = flag;
-}
-
 /**
  * @推送设置
  */

+ 2 - 5
src/pages/register.vue

@@ -1,10 +1,10 @@
 <template>
   <view id="register-container">
-    <view class="top-area">
+    <view class="top-area" v-if="proxy.$common.isVisible()">
       <u-icon name="arrow-left" size="17px" color="#000" :bold="true" @click="navigateTo"></u-icon>
     </view>
 
-    <view class="content-area">
+    <view class="content-area" v-if="proxy.$common.isVisible()">
       <text class="content-area-title">注册</text>
     </view>
 
@@ -52,9 +52,7 @@ import { ref, onMounted, inject, shallowRef, reactive, toRefs, getCurrentInstanc
 import { useStores, commonStores } from "@/store/modules/index";
 import { getToken, setToken, removeToken } from "@/utils/auth";
 
-const commonStore = commonStores();
 const useStore = useStores();
-
 const { proxy } = getCurrentInstance();
 
 const dataList = reactive({
@@ -136,7 +134,6 @@ function handleSubmit() {
 function navigateTo() {
   proxy.$tab.navigateBack(1);
 }
-
 onLoad((options) => {});
 </script>
 

+ 28 - 5
src/plugins/common.plugins.js

@@ -24,7 +24,6 @@ export default {
     }
     return result;
   },
-
   /**
    * @一键拨号
    */
@@ -38,7 +37,6 @@ export default {
       }
     });
   },
-
   /**
    * @复制粘贴板
    * @param {传入值} content 
@@ -86,7 +84,6 @@ export default {
     textarea.remove()
     // #endif
   },
-
   /**
    * @param {时间处理(今日,昨日)} 
    * @param {传入值} time 
@@ -111,7 +108,6 @@ export default {
       return newTime
     }
   },
-
   /**
    * @指定获取开始时间结束时间
    */
@@ -147,7 +143,6 @@ export default {
     }
     return fmt;
   },
-
   /**
    * @数组对象去重
    * @methods data 需要去重的数据
@@ -168,5 +163,33 @@ export default {
 
       return peon;
     }
+  },
+  /**
+   * @判断是否为微信公众号
+   */
+  isWechatMp() {
+    var ua = navigator.userAgent.toLowerCase();
+    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
+      return true;
+    } else {
+      // 不在微信内置浏览器中
+      return false;
+    }
+  },
+  /**
+   * @是否显示容器
+   * @判断是否为微信公众号
+   */
+  isVisible() {
+    let visible = true;
+    //#ifdef H5
+    visible = !this.isWechatMp();
+    //#endif
+
+    //#ifdef APP-PLUS || MP-WEIXIN
+    visible = true;
+    //#endif
+    return visible;
   }
+
 };

+ 3 - 10
src/store/modules/setting.js

@@ -104,20 +104,13 @@ const settingStore = defineStore("storage-setting", {
                 geocode: true,
                 highAccuracyExpireTime: 5000,
                 success: function (res) {
-                    console.log(res);
                     params.longitude = res.longitude.toString();
-                    params.latitude = res.latitude.toString() ;
+                    params.latitude = res.latitude.toString();
 
-                    console.log(params)
-
-                    baseAppInfoApi(params).then((res) => {
-                        console.log(res)
-                    })
+                    baseAppInfoApi(params).then((res) => { })
                 },
                 fail: function (res) {
-                    baseAppInfoApi(params).then((res) => {
-                        console.log(res)
-                    })
+                    baseAppInfoApi(params).then((res) => { })
                 },
             });
         },

+ 10 - 8
src/utils/request.js

@@ -13,20 +13,22 @@ let timeout = 10000;
  * @param {控制台打印} reject 
  */
 function verification(res, resolve, reject) {
-  const useStore = useStores();
   const data = typeof res.data === "string" ? JSON.parse(res.data) : res.data;
   const code = data.code || 200;
 
   if (code === 401) {
-    // modal.confirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then((res) => {
-    //   if (res) {
-    //     useStore.LogOut().then((res) => {
-    //       uni.reLaunch({ url: "/pages/login" });
-    //     });
-    //   }
-    // });
+    //#ifdef H5
+    if (common.isWechatMp()) {
+      uni.reLaunch({ url: "/pages/register" });
+    } else {
+      uni.reLaunch({ url: "/pages/login" });
+    }
+    //#endif
 
+    //#ifdef APP-PLUS || MP-WEIXIN
     uni.reLaunch({ url: "/pages/login" });
+    //#endif
+
     modal.closeLoading();
     reject("无效的会话,或者会话已过期,请重新登录。");
   } else if (code === 404 || res.statusCode === 404) {