Bläddra i källkod

完成了登录注册页面的验证

yerong 4 år sedan
förälder
incheckning
d66d28ddc6

+ 13 - 2
src/components/device/device.vue

@@ -6,9 +6,9 @@
           <div class="line"></div>
           <div class="title">我的设备</div>
         </div>
-        <div class="my_msg">
+        <div class="my_msg" @click="get_toy_list">
           <text class="cuIcon-mark"></text>
-          <text class="under_line">消息中心</text>
+          <text class="under_line">获取设备列表</text>
         </div>
       </div>
       <div v-if="connect_toy==0">
@@ -89,6 +89,7 @@ import toy_connecting from '@/components/device/toy/connecting'
 //获取个人信息
 import {userDetail} from "../../requests/user";
 import Toast from '../../../static/vant/toast/toast';
+import {game_devices} from "../../requests/game";
 
 
 let $this;
@@ -692,9 +693,19 @@ export default {
         }
       )
       return hexArr.join('');
+    },
+
+    //  获取游戏设备玩具
+    get_toy_list(){
+      game_devices().then((res)=>{
+        let $data = res.data
+      })
     }
 
   },
+  mounted(){
+    $this.get_toy_list()
+  },
   created() {
     $this = this
   },

+ 6 - 6
src/components/device/toy/connecting.vue

@@ -166,12 +166,12 @@ export default {
     }
   },
   watch: {
-    pay_type($new, $old) {
-      if ($new > 0) {
-        $this.change_toy_connect_status(4)
-        $this.to_playing()
-      }
-    }
+    // pay_type($new, $old) {
+    //   if ($new > 0) {
+    //     $this.change_toy_connect_status(4)
+    //     $this.to_playing()
+    //   }
+    // }
   },
   methods: {
     open_choose_toy() {

+ 37 - 11
src/components/index/login.vue

@@ -5,32 +5,58 @@
     </view>
     <view class="text-df text-center slogen">在此你将会体验到操控专注力的神奇感觉</view>
     <div class="sub_slogen text-center">
-      现在,开始你的专注力旅程吧
+      现在,开始你的专注力旅程吧!
     </div>
 
     <div class="text-center padding">
-      <button class="cu-btn lg cu-btn-primary text-white text-center" @click="to_scan">开始体验</button>
+      <button class="cu-btn lg cu-btn-primary text-white text-center" @click="to_regist(0)">开始体验</button>
     </div>
     <view class="text-center text-xs">
       <text class="text-gray">如果您在我们的实体店,请在店员的指导下链接脑环</text>
     </view>
-    <view class="text-center text-lg padding" @click="to_regist">
+    <view class="text-center text-lg padding" @click="to_regist(1)">
       <text class="text-gray under_line">账号登录</text>
     </view>
+    <van-toast id="van-toast"/>
+
   </div>
 </template>
 <script>
-  export default {
-    name:"login_container",
-    methods:{
-      to_regist(){
-        this.$emit('changeStatus','regist')
-      },
-      to_scan(){
-        this.$emit('to_scan','scan')
+import Toast from '../../../static/vant/toast/toast';
+
+export default {
+  name: "login_container",
+  methods: {
+    to_regist($status) {
+      this.$emit('changeStatus', 'regist')
+      this.$emit('changeTitle', $status)
+    },
+    to_scan() {
+      this.$emit('to_scan', 'scan')
+    }
+  },
+  onLoad(options) {
+    // 原有的code
+    let $_code = wx.getStorageSync('code')
+
+    if (options.q) {
+      let url = decodeURIComponent(options.q)
+      let $code = url.match(/\?code=(.*)/)[1];
+
+      this.$store.commit('set_invite_code', $code)
+      console.log('1---' + $_code, '2---' + $code)
+      //判断新的code 和 旧的code 是否一致 不一致则重新登录
+      if ($_code && $_code != $code) {
+        Toast.fail('该用户已绑定邀请码')
       }
+
     }
+    // else {
+    //   // 跳转到关于水母页面
+    //   this.$emit('changeStatus', 'scan')
+    // }
   }
+}
 </script>
 <style>
 

+ 20 - 18
src/components/index/personal.vue

@@ -4,7 +4,7 @@
     <div class="userinfo">
       <van-row class="padding">
         <van-col span="3" offset="2">
-          <view class="cu-avatar radius lg" :style="'background-image:url('+userinfo.protrait+');'"></view>
+          <view class="cu-avatar radius lg" :style="'background-image:url('+userinfo.portrait+');'"></view>
         </van-col>
         <van-col span="12" offset="1">
           <div class="flex flex-direction align-start justify-start">
@@ -49,7 +49,7 @@
             </div>
           </div>
         </van-col>
-        <van-col span="5" >
+        <van-col span="5">
           <view class="text" @click="to_user_center">
             <text class="cuIcon-people"></text>
             <text class="under_line">会员中心</text>
@@ -156,7 +156,7 @@ export default {
   data() {
     return {
       userinfo: {
-        protrait: 'https://img.shuimuai.com/weixintouxiang.png',
+        portrait: 'https://img.shuimuai.com/weixintouxiang.png',
         user_name: "小疯兔屁屁",
         phone: "15627202057",
         experience: "0",
@@ -186,27 +186,29 @@ export default {
         url: "/pages/user_center/recharge/main"
       })
     },
-    //  用户用户详细信息
-    get_user_info() {
-      userDetail().then((res) => {
-        let $data = res.data
-        if (!$data['code']) {
-          $this.userinfo = $data['data']
-        }
-      })
-    },
     //跳转用户中心
-    to_user_center(){
+    to_user_center() {
       mpvue.navigateTo({
-        url:"/pages/user_center/main"
+        url: "/pages/user_center/main"
       })
     }
   },
   mounted() {
-    //  判断不是第一次游戏 并且 游玩时间不足
-    // if (this.userinfo.playtime == 0 && this.first == 0) {
-    //   this.pop_show = true
-    // }
+    //获取用户信息
+    //获取用户信息
+    userDetail().then((res) => {
+      let $data = res.data
+      //判断如果是第一次登录就 弹出领取体验卡
+      $this.userinfo = $data.data
+      // if ($this.userinfo.login_time == 0) {
+      //   $this.first = true
+      // } else if ($this.userinfo.play_time == 0) {
+      //   $this.pop_show = true
+      // }
+      $this.$store.commit('set_userinfo', $data.data);
+    })
+
+
   },
   created() {
     $this = this

+ 64 - 76
src/components/index/regist.vue

@@ -2,14 +2,14 @@
   <div id="index_login_container" class="animation-slide-right">
     <view class="solid-bottom text-xl padding text-center">
       <img class="back regist_back_btn" @click="goIndex" src="https://img.shuimuai.com/fanhui.png"/>
-      <text class=" text-bold title_color">注册会员</text>
+      <text class=" text-bold title_color">{{ title }}</text>
     </view>
     <view class="text-df text-center slogen">请输入手机号码,以便更好的享受我们的服务</view>
     <div class="register_form_container text-center">
       <form action="">
         <view class="cu-form-group">
           <view class="title">手机号码</view>
-          <input placeholder="请输入手机号" v-model="phone" maxlength="11" />
+          <input placeholder="请输入手机号" v-model="phone" maxlength="11"/>
           <view class="cu-capsule radius">
             <view class='cu-tag bg-blue '>
               +86
@@ -31,7 +31,8 @@
     </div>
 
     <div class="text-center padding">
-      <button class="cu-btn lg cu-btn-primary text-white text-center" open-type="getUserInfo" @getuserinfo="getUserinfo"
+      <button class="cu-btn lg cu-btn-primary text-white text-center" open-type="getUserInfo"
+              @getuserinfo="get_Userinfo"
               v-if="auth_login">
         微信授权登录
       </button>
@@ -53,13 +54,20 @@ var $this
 
 export default {
   name: "regist",
+  props: ['title'],
   data() {
     return {
       phone: "",
       verfiy_code: "",
       time_out: 0,
-      invite: 2,
-      auth_login: false
+      invite: 0,
+      js_code: "",
+      auth_login: false,
+      _userinfo: {
+        nickName: "",
+        avatarUrl: "",
+        gender: ""
+      },
     }
   },
   watch: {
@@ -92,7 +100,13 @@ export default {
     },
     //微信授权登录
     wechat_login($userinfo) {
-      let $reg = /\d{6}/
+      console.log('登录')
+      let $reg = /(13\d|14[579]|15[^4\D]|17[^49\D]|18\d)\d{8}/
+      if ($reg.test($this.phone) == false) {
+        Toast.fail('请输入正确手机号')
+        return false;
+      }
+      $reg = /\d{6}/
       if ($reg.test($this.verfiy_code) == false) {
         Toast.fail('请输入正确的验证码')
         return false;
@@ -102,42 +116,41 @@ export default {
         forbidClick: true,
         message: '操作中...',
       });
-      mpvue.login({
-        success($res) {
-          let $params = {
+
+      let $params = {
+        phone: $this.phone,
+        code: $this.verfiy_code,
+        js_code: $this.js_code,
+        invite: $this.invite,
+      }
+      if ($this._userinfo) {
+        $params['user_name'] = $this._userinfo.nickName
+        $params['portrait'] = $this._userinfo.avatarUrl
+        $params['sex'] = $this._userinfo.gender
+      }
+      //用户注册
+      userRegister($params).then((res) => {
+        let $data = res.data
+        if (!$data['code']) {
+          Toast.clear()
+          $this.login_success($data)
+        } else if ($data['code'] == 201) {
+          // 判断用户已经注册了 就进行登录的操作
+          $params = {
             phone: $this.phone,
             code: $this.verfiy_code,
-            js_code: $res.code,
-            invite: $this.invite,
-            user_name: $userinfo['nickName'],
-            portrait: $userinfo['avatarUrl'],
-            sex: $userinfo['gender']
           }
-          //用户注册
-          userRegister($params).then((res) => {
+          userLogin($params).then((res) => {
             let $data = res.data
+            Toast.clear()
             if (!$data['code']) {
-              Toast.clear()
               $this.login_success($data)
-            } else if ($data['code'] == 201) {
-              // 判断用户已经注册了 就进行登录的操作
-              $params = {
-                phone: $this.phone,
-                code: $this.verfiy_code,
-              }
-              userLogin($params).then((res) => {
-                let $data = res.data
-                Toast.clear()
-                if (!$data['code']) {
-                  $this.login_success($data)
-                } else {
-                  Toast.fail($data['errmsg'])
-                }
-              })
-            } else if ($data['code'] == 204) {
+            } else {
               Toast.fail($data['errmsg'])
             }
           })
+        } else if ($data['code'] == 204) {
+          Toast.fail($data['errmsg'])
         }
       })
     },
@@ -150,7 +163,7 @@ export default {
       //获取用户信息
       userDetail().then((res) => {
         let $data = res.data
-        console.log($data)
+        $this.$store.commit('set_userinfo', $data.data);
       })
     },
     //打开倒计时
@@ -163,26 +176,22 @@ export default {
       }, 1000)
     },
     //  获取用户信息
-    getUserinfo() {
-      let $reg = /\d{6}/
-      if ($reg.test($this.verfiy_code) == false) {
-        Toast.fail('请输入正确的验证码')
-        return false;
-      }
-      wx.authorize({
-        scope: 'scope.userInfo',
-        success(res) {
-          wx.getUserInfo({
-            success($res) {
-              let $userinfo = $res.userInfo
-              console.log($userinfo)
-              $this.wechat_login($userinfo)
-            }
-          })
-        }
-      })
+    get_Userinfo(e) {
+      $this._userinfo = e.mp.detail.userInfo
+      $this.wechat_login()
     }
   },
+  mounted() {
+    // $this.invite = $this.$store.getters.get_invite_code ? $this.$store.getters.get_invite_code : wx.getStorageSync('code')
+    $this.invite = 3
+    console.log('regist-invite', $this.invite)
+    mpvue.login({
+      success($res) {
+        $this.js_code = $res.code
+      }
+    })
+
+  },
   created() {
     $this = this
     wx.getSetting({
@@ -191,34 +200,13 @@ export default {
         if ($authSetting['scope.userInfo']) {
           //改为普通登录
           $this.auth_login = false
+        } else {
+          $this.auth_login = true
         }
+        console.log('auth', $this.auth_login)
       }
     })
   },
-  onLoad(options) {
-    // 原有的code
-    let $_code = wx.getStorageSync('code')
-
-    if (options.q) {
-      let url = decodeURIComponent(options.q)
-      let $code = url.match(/\?code=(.*)/)[1];
-
-      $this.invite = $code + ''
-      console.log('1---' + $_code, '2---' + $code)
-      //判断新的code 和 旧的code 是否一致 不一致则重新登录
-      if ($_code && $_code != $code) {
-        Toast.fail('该用户已绑定邀请码')
-      }
-
-    }
-    // else {
-    //   Toast.fail({
-    //     duration: 0,
-    //     forbidClick: true,
-    //     message: '请通过邀请码进入小程序',
-    //   })
-    // }
-  }
 }
 </script>
 

+ 1 - 1
src/components/index/scan.vue

@@ -10,7 +10,7 @@
     </div>
 
     <div class="text-center padding">
-      <button class="cu-btn lg cu-btn-primary text-white text-center" @click="open_scan"><text class="cuIcon-scan"></text>扫码</button>
+      <button class="cu-btn lg cu-btn-primary text-white text-center">关于水母星球</button>
     </div>
     <view class="text-center text-xs">
       <text class="text-gray">如果您在我们的实体店,请在店员的指导下链接脑环</text>

+ 2 - 2
src/pages/index/index.css

@@ -20,14 +20,14 @@
 
 .sub_slogen {
   font-size: 22px;
-  margin-top: 130px;
+  margin-top: 110px;
   color: #4C4C4C;
 }
 
 /*扫码页*/
 .sub_slogen_sm {
   font-size: 13px;
-  margin: 140px auto 0px;
+  margin: 120px auto 0px;
   color: #4C4C4C;
 }
 

+ 37 - 11
src/pages/index/index.vue

@@ -5,13 +5,17 @@
     <!--    未登录 登录窗口模块-->
     <div class="login_card" v-if="!is_login">
       <!--      登录窗口-->
-      <login_container v-if="status == 'login'" @changeStatus="change_status"
-                       @to_scan="change_status"></login_container>
-      <!--      扫码窗口-->
-      <scan_container v-if="status == 'scan'" @changeStatus='change_status'></scan_container>
+      <login_container v-if="status == 'login'"
+                       @changeStatus="change_status"
+                       @changeTitle="change_title"
+      ></login_container>
+      <!--      关于水母-->
+      <scan_container v-if="status == 'scan'"></scan_container>
       <!--      注册窗口-->
-      <regist_container v-if="status == 'regist'" @changeStatus='change_status'
+      <regist_container v-if="status == 'regist'"
+                        @changeStatus='change_status'
                         @change_login_status="change_login_status"
+                        :title="regist_title"
       ></regist_container>
 
     </div>
@@ -28,12 +32,14 @@
         </div>
       </div>
       <div class="content">
-        <img src="https://img.shuimuai.com/chongzhizhongxin.png" @click="to_recharge"></img>
-        <img src="https://img.shuimuai.com/shebeiguanli.png"></img>
-        <img src="https://img.shuimuai.com/chongzhizhongxin.png"></img>
-        <img src="https://img.shuimuai.com/shebeiguanli.png"></img>
+        <img src="https://img.shuimuai.com/chongzhizhongxin.png" @click="to_page('recharge')"></img>
+        <img src="https://img.shuimuai.com/shebeiguanli.png" @click="to_page('user_center')"></img>
+        <img src="https://img.shuimuai.com/chongzhizhongxin.png" @click="to_page('report')"></img>
+        <img src="https://img.shuimuai.com/shebeiguanli.png" @click="to_page('agent/index')"></img>
       </div>
     </div>
+    <van-toast id="van-toast"/>
+
   </div>
 </template>
 
@@ -44,6 +50,7 @@ import scan_container from '@/components/index/scan'
 import regist_container from '@/components/index/regist'
 import personal_container from "@/components/index/personal";
 import device_container from "@/components/device/device";
+import Toast from '../../../static/vant/toast/toast';
 
 
 export default {
@@ -54,8 +61,9 @@ export default {
   data() {
     return {
       // 三种状态 扫码scan 注册regist 登录login
-      status: "regist",
-      is_login: false
+      status: "login",
+      is_login: false,
+      regist_title: ""
     }
   },
   methods: {
@@ -74,6 +82,24 @@ export default {
     //修改登录状态
     change_login_status() {
       this.is_login = this.$store.getters.get_login_status
+    },
+    // 修改界面的文字
+    change_title($status) {
+      if ($status == 0) {
+        this.regist_title = "注册会员"
+      } else if ($status == 1) {
+        this.regist_title = "会员登录"
+      }
+    },
+    //跳转页面
+    to_page($page) {
+      if (!this.is_login){
+        Toast.fail("请先登录")
+        return false
+      }
+      mpvue.navigateTo({
+        url: "/pages/" + $page + "/main"
+      })
     }
   },
   mounted() {

+ 21 - 0
src/requests/game.js

@@ -0,0 +1,21 @@
+import fly from "./main";
+import store from "@/store/index"
+
+fly.interceptors.request.use((config, promise) => {
+  let $token = wx.getStorageSync('token')
+  //给所有请求添加自定义header
+  config.headers["HTTP_TOKEN"] = $token;
+  return config;
+})
+
+// 设备列表
+export function game_devices($params) {
+  return fly.post('game/device-list', $params)
+}
+
+
+// 开始游戏
+export function game_start($params) {
+  return fly.post('game/game-start', $params)
+}
+

+ 3 - 0
src/store/index.js

@@ -36,6 +36,9 @@ export default new Vuex.Store({
     },
     get_userinfo(state) {
       return state.userinfo
+    },
+    get_invite_code(state) {
+      return state.invite_code
     }
   },