瀏覽代碼

Merge branch 'master' of ssh://gogs.zfire.top:2222/zfire-front/recycle-mobile

* 'master' of ssh://gogs.zfire.top:2222/zfire-front/recycle-mobile:
  feat: 对接登入
Moss 1 年之前
父節點
當前提交
273b57daf5

+ 101 - 21
src/App.vue

@@ -1,32 +1,65 @@
 <script>
   import Vue from 'vue';
-  import store from '@/store/index.js'
-  // 解析地址栏参数
-  function getQueryVariable(variable) {
-    // 从?开始获取后面的所有数据
-    var query = window.location.search.substring(1);
-    // 从字符串&开始分隔成数组split
-    var vars = query.split('&');
-    // 遍历该数组
-    for (var i = 0; i < vars.length; i++) {
-      // 从等号部分分割成字符
-      var pair = vars[i].split('=');
-      // 如果第一个元素等于 传进来的参的话 就输出第二个元素
-      if (pair[0] == variable) {
-        return pair[1];
-      }
-    }
-    return undefined;
-  }
+
   export default {
     onLaunch: function() {
       // #ifdef H5
+      // 解析地址栏参数
+      function getQueryVariable(variable) {
+        // 从?开始获取后面的所有数据
+        var query = window.location.search.substring(1);
+        // 从字符串&开始分隔成数组split
+        var vars = query.split('&');
+        // 遍历该数组
+        for (var i = 0; i < vars.length; i++) {
+          // 从等号部分分割成字符
+          var pair = vars[i].split('=');
+          // 如果第一个元素等于 传进来的参的话 就输出第二个元素
+          if (pair[0] == variable) {
+            return pair[1];
+          }
+        }
+        return undefined;
+      }
       var token = getQueryVariable("x-token")
       if (token) {
-        store.commit("set_token", token)
+        this.$store.commit("set_token", token)
       }
       // #endif
 
+      // #ifdef MP-WEIXIN
+      console.log(123)
+      // 小程序更新
+      const updateManager = uni.getUpdateManager();
+      // 请求完新版本信息
+      updateManager.onCheckForUpdate(function(res) {
+        // console.log(res.hasUpdate);
+      });
+      // 新的版本已经下载好
+      updateManager.onUpdateReady(function(res) {
+        uni.showModal({
+          title: '更新提示',
+          content: '新版本已经准备好,是否重启应用?',
+          success(res) {
+            if (res.confirm) {
+              // 调用 applyUpdate 应用新版本并重启
+              updateManager.applyUpdate();
+            }
+          },
+        });
+      });
+      // 新的版本下载失败
+      updateManager.onUpdateFailed(function(res) {
+        that.$toast('更新失败!');
+      });
+
+      uni.$on('updateUserInfo', () => {
+        this.updateUserInfo();
+      });
+
+      this.updateUserInfo();
+      // #endif
+
       uni.getSystemInfo({
         success: function(e) {
           console.log(e);
@@ -53,7 +86,54 @@
     },
     onHide: function() {
 
-    }
+    },
+    methods: {
+      // #ifdef MP-WEIXIN
+      async updateUserInfo() {
+        // if (this.$store.state.isLogin) {
+        //   const data = await this.$getUserInfo();
+        //   if (!data) {
+        //     this.$store.commit('changeLoginStatus', false);
+        //     this.$store.commit('changeToken', '');
+        //     uni.removeStorageSync('isLogin');
+        //     uni.removeStorageSync('token');
+        //   }
+        // }
+        // this.$isResolve();
+
+        // uni.login({
+        //   provider: 'weixin',
+        //   success: (loginRes) => {
+        //     console.log(loginRes.code)
+        //     this.$axios({
+        //       url: '/v1app/user/auth',
+        //       params: {
+        //         code: loginRes.code,
+        //       },
+        //     }).then((res) => {
+        //       try {
+        //         console.log('====token====', res.data.token);
+        //         if (this.$store.state.isLogin) {
+        //           this.$store.commit('changeToken', res.data.token);
+        //           uni.setStorageSync('token', res.data.token);
+        //           this.$getUserInfo();
+        //         }
+        //         this.$isResolve();
+        //       } catch (e) {
+        //         console.error(e);
+        //       }
+        //     }).catch(res => {
+        //       this.$store.commit('changeLoginStatus', false);
+        //       this.$store.commit('changeToken', '');
+        //       uni.removeStorageSync('isLogin');
+        //       uni.removeStorageSync('token');
+        //       this.$isResolve();
+        //     })
+        //   },
+        // });
+      },
+      // #endif
+    },
   }
 </script>
 
@@ -62,4 +142,4 @@
   @import "uview-ui/index.scss";
 
   @import "styles/iconfont.css";
-</style>
+</style>

+ 6 - 6
src/common/utils/navPag.js

@@ -7,7 +7,7 @@ import {
 import store from '@/store/index.js'
 export const navToPage = (function() {
   var gopageid = null
-  return function(p) {
+  return function(p, goToType = "navigateTo") {
     var {
       url,
       ...data
@@ -22,9 +22,9 @@ export const navToPage = (function() {
               clearTimeout(gopageid)
             }
             i++
-            if (uniWebview && uniWebview.navigateTo) {
+            if (uniWebview && uniWebview[goToType]) {
               // h5跳转小程序
-              uniWebview.navigateTo({
+              uniWebview[goToType]({
                 url: url,
                 ...data
               })
@@ -37,7 +37,7 @@ export const navToPage = (function() {
           })()
         } else {
           // 当前环境跳转
-          uni.navigateTo({
+          uni[goToType]({
             url: url,
             ...data
           })
@@ -45,7 +45,7 @@ export const navToPage = (function() {
       })
     } else {
       // 当前环境跳转
-      uni.navigateTo({
+      uni[goToType]({
         url: url,
         ...data
       })
@@ -53,7 +53,7 @@ export const navToPage = (function() {
     // #endif
     // #ifndef H5
     // 当前环境跳转
-    uni.navigateTo({
+    uni[goToType]({
       url: url,
       ...data
     })

+ 1 - 1
src/main.js

@@ -94,4 +94,4 @@ RouterMount(app, router, '#app')
 
 // #ifndef H5
 app.$mount(); //为了兼容小程序及app端必须这样写才有效果
-// #endif
+// #endif

+ 1 - 1
src/manifest.json

@@ -46,7 +46,7 @@
     "mp-weixin" : {
         /* 小程序特有相关 */
         "requiredPrivateInfos" : [ "chooseLocation", "getLocation", "chooseAddress" ],
-        "appid" : "wx930bbe7fd37277e6",
+        "appid" : "wx6330b74c3be6a5a2",
         "setting" : {
             "urlCheck" : false,
             "es6" : true,

+ 0 - 8
src/pages.json

@@ -1,13 +1,5 @@
 {
   "pages": [
-    //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-    // {
-    //   "path": "pages/login/index",
-    //   "style": {
-    //     "navigationBarBackgroundColor": "#f4f2f2",
-    //     "navigationBarTitleText": ""
-    //   }
-    // },
     {
       "path": "pages/index/index",
       "style": {

+ 62 - 40
src/pages/login/indexs.vue

@@ -9,9 +9,10 @@
       </view>
     </view>
     <view class="loginForm">
+      <!-- #ifdef H5 -->
       <u--form labelPosition="left" :model="model" :rules="rules" ref='model'>
         <u-form-item label="" prop="mobile">
-          <u--input clearable shape='circle' placeholder="请输入手机号"  v-model="model.mobile">
+          <u--input clearable shape='circle' placeholder="请输入手机号" v-model="model.mobile">
             <view class="" style="" slot='prefix'>
               <image class="icon" src="@/static/login/icon_login_account.png" mode=""></image>
             </view>
@@ -29,19 +30,19 @@
         </u-form-item>
       </u--form>
       <u-button @click='loginFn' class='loginBtn' type="primary" shape="circle" size="" text="登录"></u-button>
+      <!-- #endif -->
+      <!-- #ifdef MP-WEIXIN -->
+      <u-button type="primary" size="large" shape="circle" text="手机号快捷登录" open-type="getPhoneNumber"
+        @getphonenumber="getPhoneNumber">
+      </u-button>
+      <!-- #endif -->
     </view>
-    <zjDialogVerification
-        ref="verification" 
-        :isShow="isShowCodeDialog" 
-        :top="codeObj.yHeight" 
-        :bgImg="codeObj.bigImage" 
-        :maskImg="codeObj.smallImage" 
-        :isSuccess="codeObj.isSuccess" 
-        :isFail="codeObj.isFail" 
-        @close="isShowCodeDialog = false" 
-        @refresh="refresh" 
-        @finish="finish">
-      </zjDialogVerification>
+    <!-- #ifdef H5 -->
+    <zjDialogVerification ref="verification" :isShow="isShowCodeDialog" :top="codeObj.yHeight" :bgImg="codeObj.bigImage"
+      :maskImg="codeObj.smallImage" :isSuccess="codeObj.isSuccess" :isFail="codeObj.isFail"
+      @close="isShowCodeDialog = false" @refresh="refresh" @finish="finish">
+    </zjDialogVerification>
+    <!-- #endif -->
   </view>
 </template>
 
@@ -49,20 +50,20 @@
   import zjDialogVerification from "@/components/zj-dialog-verification.vue";
   import api from '@/common/http/'
   export default {
-    components:{
+    components: {
       zjDialogVerification
     },
     data() {
       return {
-        isShowCodeDialog:false,
+        isShowCodeDialog: false,
         codeObj: {
-					bigImage: '',
-					smallImage: '',
-					key: '',
-					yHeight: '',
-					isSuccess: false,
-					isFail: false,
-				},
+          bigImage: '',
+          smallImage: '',
+          key: '',
+          yHeight: '',
+          isSuccess: false,
+          isFail: false,
+        },
         model: {
           mobile: '',
           code: '',
@@ -84,22 +85,43 @@
         countDown: 0,
       }
     },
-    watch:{
-      countDown(){
-        if(this.countDown>0){
-          setTimeout(()=>{
+    watch: {
+      countDown() {
+        if (this.countDown > 0) {
+          setTimeout(() => {
             this.countDown--
-          },1000)
+          }, 1000)
         }
       }
     },
     methods: {
-      async getImgV(){
+      // 获取手机号
+      getPhoneNumber(e) {
+        if (!e.detail.iv) {
+          return this.$toast('获取手机号失败');
+        }
+        uni.login({
+          provider: 'weixin',
+          success: (loginRes) => {
+            api.get('/wechat/user/auth', {
+              code: loginRes.code,
+              phoneCode: e.detail.code,
+            }).then(res => {
+              this.$store.commit("set_token", res.data.token)
+              this.$store.commit("set_openId", res.data.openId)
+              this.$store.commit("set_name", res.data.name)
+              this.$store.commit("set_avatar", res.data.avatar)
+              this.$navToPage("/pages/index/index")
+            })
+          }
+        });
+      },
+      async getImgV() {
         try {
-          if(this.countDown==0){
-            this.$refs.model.validateField("mobile",(res)=>{
-              if(!res.length){
-                api.get('/admin/user/getVerifi').then(res=>{
+          if (this.countDown == 0) {
+            this.$refs.model.validateField("mobile", (res) => {
+              if (!res.length) {
+                api.get('/admin/user/getVerifi').then(res => {
                   this.codeObj = res.data;
                   this.isShowCodeDialog = true
                 })
@@ -108,15 +130,15 @@
           }
         } catch (e) {}
       },
-      refresh(){
+      refresh() {
         this.getImgV()
       },
-      finish(val){
-        api.postJson('/admin/user/smsCode',{
-          mobile:this.model.mobile,
-          code:this.codeObj.key,
-          codeValue:parseInt(val),
-        }).then(res=>{
+      finish(val) {
+        api.postJson('/admin/user/smsCode', {
+          mobile: this.model.mobile,
+          code: this.codeObj.key,
+          codeValue: parseInt(val),
+        }).then(res => {
           this.isShowCodeDialog = false
           this.codeObj = {
             bigImage: '',
@@ -193,4 +215,4 @@
     background: linear-gradient(135deg, #7fdaff 0%, #6da7ff 100%);
     border-radius: 50rpx;
   }
-</style>
+</style>

+ 7 - 32
src/store/modules/user/actions.js

@@ -6,34 +6,14 @@ export default {
   async autoLogin({
     commit
   }, params) {
-    let res = await api.get('/wechat/user/auth', params);
-    let {
-      data
-    } = res;
 
-    console.log(data)
-
-    commit('set_token', data.token);
-    commit('set_username', data.accountBase.accountName);
-    commit('set_usercode', data.accountBase.accountCode);
-    uni.setStorageSync('recycle_mobile_token', data.token);
   },
-  
+
   // 登录
   async login({
     commit
   }, params) {
-    let res = await api.post('/wechat/user/mobile-login', params);
-    let {
-      data
-    } = res;
 
-    console.log(data)
-
-    commit('set_token', data.token);
-    commit('set_username', data.accountBase.accountName);
-    commit('set_usercode', data.accountBase.accountCode);
-    uni.setStorageSync('recycle_mobile_token', data.token);
   },
 
   // 获取用户信息
@@ -41,13 +21,7 @@ export default {
     commit,
     state
   }) {
-    let res = await api.post('/account/getaccountinfo', {
-      accountCode: state.usercode
-    });
-    let {
-      data
-    } = res;
-    uni.setStorageSync('recycle_mobile_user', data);
+
   },
 
   // 清除登录信息
@@ -55,11 +29,12 @@ export default {
     commit
   }) {
     return new Promise(resolve => {
-      commit('set_token', '')
-      commit('set_username', '')
-      commit('set_usercode', '')
+      commit("set_token", "")
+      commit("set_openId", "")
+      commit("set_name", "")
+      commit("set_avatar", "")
       resolve()
     })
   },
 
-}
+}

+ 3 - 6
src/store/modules/user/index.js

@@ -1,14 +1,11 @@
 import actions from "./actions"
 import mutations from "./mutations"
 
-const userinfo = uni.getStorageSync('recycle_mobile_user');
-
 const state = {
-  username: userinfo ? userinfo.accountBase.accountName : '',
-  usercode: userinfo ? userinfo.accountBase.accountCode : '',
+  openId: uni.getStorageSync('recycle_mobile_openId') || '',
   token: uni.getStorageSync('recycle_mobile_token') || '',
-  downloadFlag: userinfo ? userinfo.accountBase.downloadFlag : '',
-
+  name: uni.getStorageSync('recycle_mobile_name') || '',
+  avatar: uni.getStorageSync('recycle_mobile_avatar') || '',
 }
 export default {
   namespaced: true,

+ 29 - 5
src/store/modules/user/mutations.js

@@ -2,14 +2,38 @@ export default {
   //
   set_token: (state, token) => {
     state.token = token
+    if (token) {
+      uni.setStorageSync('recycle_mobile_token', token)
+    } else {
+      uni.removeStorageSync("recycle_mobile_token")
+    }
   },
 
-  set_username: (state, username) => {
-    state.username = username
+  set_openId: (state, openId) => {
+    state.openId = openId
+    if (openId) {
+      uni.setStorageSync('recycle_mobile_openId', openId)
+    } else {
+      uni.removeStorageSync("recycle_mobile_openId")
+    }
   },
 
-  set_usercode: (state, usercode) => {
-    state.usercode = usercode
+  set_name: (state, name) => {
+    state.name = name
+    if (name) {
+      uni.setStorageSync('recycle_mobile_name', name)
+    } else {
+      uni.removeStorageSync("recycle_mobile_name")
+    }
   },
 
-}
+  set_avatar: (state, avatar) => {
+    state.avatar = avatar
+    if (avatar) {
+      uni.setStorageSync('recycle_mobile_avatar', avatar)
+    } else {
+      uni.removeStorageSync("recycle_mobile_avatar")
+    }
+  },
+
+}