Prechádzať zdrojové kódy

完成硬件模块,对接其他接口

yerong 4 rokov pred
rodič
commit
c82346ccb0

+ 1 - 1
src/components/device/connected.vue

@@ -53,7 +53,7 @@ export default {
       this.$emit('open_choose_toy')
     },
     change_status($status) {
-      this.$emit('change_toy_connect_status', $status)
+      this.$emit('change_brain_status', $status)
     }
   }
 }

+ 454 - 23
src/components/device/device.vue

@@ -26,7 +26,7 @@
         <!-- 已链接 -->
         <div class="connected_box" v-if="connect_show">
           <device_connected @open_choose_toy="open_choose_toy"
-                            @change_toy_connect_status="change_toy_connect_status"></device_connected>
+                            @change_brain_status="change_device_status"></device_connected>
         </div>
 
       </div>
@@ -35,7 +35,9 @@
         <!--      玩具连接中-->
         <div class="connecting_toy">
           <toy_connecting :connect_toy="connect_toy" @open_choose_toy="open_choose_toy"
-                          @change_toy_connect_status="change_toy_connect_status"></toy_connecting>
+                          @change_toy_connect_status="change_toy_connect_status"
+                          @change_status="change_device_status"
+          ></toy_connecting>
         </div>
       </div>
 
@@ -69,7 +71,8 @@
         <view class="text-gray toy_action_text padding">选择你最感兴趣的项目,点击“选好了”以后将会自动连接</view>
         <button class="cu-btn lg cu-btn-primary text-white text-center padding" @click="choose_ok">选好了</button>
       </div>
-    </van-popup>    <van-toast id="van-toast"/>
+    </van-popup>
+    <van-toast id="van-toast"/>
 
   </div>
 </template>
@@ -88,7 +91,6 @@ import {userDetail} from "../../requests/user";
 import Toast from '../../../static/vant/toast/toast';
 
 
-
 let $this;
 export default {
   name: "device",
@@ -102,35 +104,61 @@ export default {
       choose_toy_window: {
         show: false
       },
+      //'水柱音箱', '喷雾恐龙(大)', '喷雾恐龙(小)', '轨道车', '碰碰车', '小车(大)', '小车(中)', '小车(小)', '飞行器(大)', '飞行器(小)', '水母灯'
       toy_list: [
         {
           id: 1,
-          name: "智能喷泉",
+          name: "水柱音箱",
           img: "https://img.shuimuai.com/web/toy_car.png"
         },
         {
           id: 2,
-          name: "智能喷雾恐龙",
+          name: "喷雾恐龙(大)",
           img: "https://img.shuimuai.com/web/toy_dinasour.png"
         },
         {
           id: 3,
-          name: "智能喷雾恐龙2",
+          name: "喷雾恐龙(小)",
           img: "https://img.shuimuai.com/web/toy_dinasour.png"
         },
         {
           id: 4,
-          name: "智能轨道车",
+          name: "轨道车",
           img: "https://img.shuimuai.com/web/toy_car_roat.png"
         },
         {
           id: 5,
-          name: "智能越野车",
+          name: "碰碰车",
           img: "https://img.shuimuai.com/web/toy_car.png"
         },
         {
           id: 6,
-          name: "智能越野车2",
+          name: "小车(大)",
+          img: "https://img.shuimuai.com/web/toy_car.png"
+        },
+        {
+          id: 7,
+          name: "小车(中)",
+          img: "https://img.shuimuai.com/web/toy_car.png"
+        },
+        {
+          id: 8,
+          name: "小车(小)",
+          img: "https://img.shuimuai.com/web/toy_car.png"
+        },
+        {
+          id: 9,
+          name: "飞行器(大)",
+          img: "https://img.shuimuai.com/web/toy_car.png"
+        },
+        {
+          id: 10,
+          name: "飞行器(小)",
+          img: "https://img.shuimuai.com/web/toy_car.png"
+        },
+        {
+          id: 11,
+          name: "水母灯",
           img: "https://img.shuimuai.com/web/toy_car.png"
         },
       ],
@@ -139,7 +167,13 @@ export default {
       //连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
       connect_toy: 0,
       code: "jellyfish1234",
-      device: {}
+      device: {},
+      canWrite: false,
+      _deviceId: '',
+      _serviceId: "",
+      _characteristicId: "",
+      chs: [],
+      _device_index: false
     }
   },
   watch: {
@@ -147,13 +181,8 @@ export default {
       //成功连接的方法
       if ($new == 2) {
         $this.connect_show = true
-      }
-    },
-    connect_toy($new, $old) {
-      if ($new == 1) {
-        setTimeout(() => {
-          $this.connect_toy = 2
-        }, 2000)
+      } else if ($new == 0) {
+        $this.connect_show = false
       }
     }
   },
@@ -209,6 +238,8 @@ export default {
     choose_ok() {
       $this.on_close()
       $this.change_toy_connect_status(1)
+      $this._device_index = $this.toy_action - 1
+      $this.connect_toy = 2
     },
     //修改玩具连接状态
     change_toy_connect_status($status = 0) {
@@ -216,8 +247,18 @@ export default {
     },
     //  修改设备连接状态
     change_device_status($status = 0) {
-      console.log($status)
       $this.status = $status
+      //当蓝牙连接已断开
+      if ($status == 0) {
+        $this.connect_toy = $status
+        $this.connect_show = false
+        wx.closeBLEConnection({
+          deviceId: $this._deviceId,
+          success(res) {
+            Toast.success('已成功断开')
+          }
+        })
+      }
     },
 
     //开始蓝牙被发现
@@ -228,7 +269,6 @@ export default {
           console.log('startBluetoothDevicesDiscovery success', res)
           $this.onBluetoothDeviceFound()
           $this.change_device_status(1)
-
         },
         fail(err) {
           $this.change_device_status(3)
@@ -252,9 +292,12 @@ export default {
         })
       })
       setTimeout(() => {
-        $this.stopBluetoothDevicesDiscovery()
-        $this.status = 0
-        Toast.fail('未连接到设备')
+        if (!$this.device.deviceId) {
+          $this.stopBluetoothDevicesDiscovery()
+          $this.status = 0
+          $this.connect_show = false
+          Toast.fail('未连接到设备')
+        }
       }, 7000)
 
     },
@@ -270,15 +313,403 @@ export default {
           console.log('成功连接')
           //成功连接脑环蓝牙
           $this.change_device_status(2)
+          $this.getBLEDeviceServices($this.device.deviceId)
         },
         fail(err) {
           console.log('err', err)
         }
       })
     },
+    //获取蓝牙设备服务
+    getBLEDeviceServices(deviceId) {
+      wx.getBLEDeviceServices({
+        deviceId,
+        success: (res) => {
+          for (let i = 0; i < res.services.length; i++) {
+            if (res.services[i].isPrimary) {
+              this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid)
+              return
+            }
+          }
+        }
+      })
+    },
+    //获取蓝牙设备某个服务中所有特征值
+    getBLEDeviceCharacteristics(deviceId, serviceId) {
+      wx.getBLEDeviceCharacteristics({
+        deviceId,
+        serviceId,
+        success: (res) => {
+          console.log('getBLEDeviceCharacteristics success', res.characteristics)
+          for (let i = 0; i < res.characteristics.length; i++) {
+            let item = res.characteristics[i]
+            if (item.properties.read) {
+              wx.readBLECharacteristicValue({
+                deviceId,
+                serviceId,
+                characteristicId: item.uuid,
+              })
+            }
+            if (item.properties.write) {
+              $this.canWrite = true
+              $this._deviceId = deviceId
+              $this._serviceId = serviceId
+              $this._characteristicId = item.uuid
+              $this.sendPause()
+            }
+            if (item.properties.notify || item.properties.indicate) {
+              wx.notifyBLECharacteristicValueChange({
+                deviceId,
+                serviceId,
+                characteristicId: item.uuid,
+                state: true,
+              })
+            }
+          }
+        },
+        fail(res) {
+          console.error('getBLEDeviceCharacteristics', res)
+        }
+      })
+      // 操作之前先监听,保证第一时间获取数据
+      wx.onBLECharacteristicValueChange((characteristic) => {
+        console.log("收到" + $this.ab2hex(characteristic.value));
+        let hexStr = $this.ab2hex(characteristic.value)
+
+        if (hexStr.substring(0, 10) == 'aadd0a0000') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '未找到教具',
+            icon: 'none',
+            duration: 1500
+          })
+          console.log("无连接设备")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0001') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到水柱音箱',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+          console.log("水柱音箱")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0002') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到喷雾恐龙(大)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("喷雾恐龙(大)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0003') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到喷雾恐龙(小)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("喷雾恐龙(小)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0004') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到轨道车',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("轨道车")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0005') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到碰碰车',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("碰碰车")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0006') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到小车(大)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("小车(大)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0007') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到小车(中)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("小车(中)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0008') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到小车(小)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("小车(小)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0009') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到飞行器(大)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("飞行器(大)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a000a') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到飞行器(小)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("飞行器(小)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a000b') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到水母灯)',
+            icon: 'success',
+            duration: 1500
+          })
+          $this.sendControl()
+          $this.connect_toy = 2
+
+          console.log("水母灯")
+        }
+        if (hexStr.substring(0, 10) == 'aadd070000') {
+          $this.sendOpen()
+        }
+      })
+    },
+    //面向蓝牙设备成员发送数据包
+    writeBLECharacteristicValue() {
+      // 向蓝牙设备发送一个0x00的16进制数据
+      let buffer = new ArrayBuffer(1)
+      let dataView = new DataView(buffer)
+      dataView.setUint8(0, Math.random() * 255 | 0)
+      wx.writeBLECharacteristicValue({
+        deviceId: this._deviceId,
+        serviceId: this._deviceId,
+        characteristicId: this._characteristicId,
+        value: buffer,
+      })
+    },
+    // 发送停止发送脑电数据包指令
+    sendPause() {
+      let that = this
+      // 向蓝牙设备发送一个0x00的16进制数据
+      let buffer = new ArrayBuffer(8)
+      let dataView = new DataView(buffer)
+      dataView.setUint8(0, '0xaa')
+      dataView.setUint8(1, '0xcc')
+      dataView.setUint8(2, '0x03')
+      dataView.setUint8(3, '0x00')
+      dataView.setUint8(4, '0x00')
+      dataView.setUint8(5, '0x00')
+      dataView.setUint8(6, '0x00')
+      dataView.setUint8(7, '0xfc')
+      // 向低功耗蓝牙设备特征值中写入二进制数据
+      console.log(buffer)
+      wx.writeBLECharacteristicValue({
+        deviceId: that._deviceId,
+        serviceId: that._serviceId,
+        characteristicId: that._characteristicId,
+        value: buffer,
+        success: function (res) {
+          console.log('停止数据发送成功')
+          console.log(res)
+        },
+        fail: function (err) {
+          console.log('停止数据发送失败')
+          console.log(err)
+        }
+      })
+    },
+    // 发送开启脑电数据包指令
+    sendOpen() {
+      const that = this
+      // 向蓝牙设备发送一个0x00的16进制数据
+      let buffer = new ArrayBuffer(8)
+      let dataView = new DataView(buffer)
+      dataView.setUint8(0, '0xaa')
+      dataView.setUint8(1, '0xcc')
+      dataView.setUint8(2, '0x03')
+      dataView.setUint8(3, '0x00')
+      dataView.setUint8(4, '0x00')
+      dataView.setUint8(5, '0x00')
+      dataView.setUint8(6, '0xff')
+      dataView.setUint8(7, '0xfd')
+      // 向低功耗蓝牙设备特征值中写入二进制数据
+      console.log(buffer)
+      wx.writeBLECharacteristicValue({
+        deviceId: that._deviceId,
+        serviceId: that._serviceId,
+        characteristicId: that._characteristicId,
+        value: buffer,
+        success: function (res) {
+          console.log('开启脑电数据包成功')
+          console.log(res)
+        },
+        fail: function (err) {
+          console.log('开启脑电数据包失败')
+          console.log(err)
+        }
+
+      })
+    },
+    // 发送开启教具脑控指令
+    sendControl() {
+      const that = this
+      // 向蓝牙设备发送一个0x00的16进制数据
+      let buffer = new ArrayBuffer(8)
+      let dataView = new DataView(buffer)
+      dataView.setUint8(0, '0xaa')
+      dataView.setUint8(1, '0xcc')
+      dataView.setUint8(2, '0x03')
+      dataView.setUint8(3, '0x00')
+      dataView.setUint8(4, '0x00')
+      dataView.setUint8(5, '0x00')
+      dataView.setUint8(6, '0x07')
+      dataView.setUint8(7, '0xf5')
+      // 向低功耗蓝牙设备特征值中写入二进制数据
+      console.log(buffer)
+      wx.writeBLECharacteristicValue({
+        deviceId: that._deviceId,
+        serviceId: that._serviceId,
+        characteristicId: that._characteristicId,
+        value: buffer,
+        success: function (res) {
+          console.log('开启教具脑控成功')
+          // that.sendOpen()
+          console.log(res)
+        },
+        fail: function (err) {
+          console.log('开启教具脑控失败')
+          console.log(err)
+        }
+
+      })
+    },
+    // 发送连接玩具指令
+    sendConnect(index) {
+      const that = this
+      // 玩具对应指令数组
+      console.log(index)
+      let arr = ['0x01', '0x02', '0x03', '0x04', '0x05', '0x06', '0x07', '0x08', '0x09', '0x0a', '0x0b']
+      let arr1 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b]
+      let CheckSum = ((0x03 + 0x00 + arr1[index] + 0x00 + 0x0a) ^ 0xFFFFFFFF) & 0xFF
+      // 向蓝牙设备发送指令
+      let buffer = new ArrayBuffer(8)
+      let dataView = new DataView(buffer)
+      dataView.setUint8(0, '0xaa')
+      dataView.setUint8(1, '0xcc')
+      dataView.setUint8(2, '0x03')
+      dataView.setUint8(3, '0x00')
+      dataView.setUint8(4, arr[index])
+      dataView.setUint8(5, '0x00')
+      dataView.setUint8(6, '0x0a')
+      dataView.setUint8(7, '0xf1')
+      // 向低功耗蓝牙设备特征值中写入二进制数据
+      console.log(buffer)
+      wx.writeBLECharacteristicValue({
+        deviceId: that._deviceId,
+        serviceId: that._serviceId,
+        characteristicId: that._characteristicId,
+        value: buffer,
+        success: function (res) {
+          console.log('发送连接玩具指令成功')
+          wx.showLoading({
+            title: '正在创建连接',
+          })
+          console.log(res)
+        },
+        fail: function (err) {
+          console.log('发送连接玩具指令失败')
+          wx.showModal({
+            showCancel: false,
+            title: '提示',
+            content: '指令发送失败',
+          })
+          console.log(err)
+        }
+
+      })
+    },
+    inArray(arr, key, val) {
+      for (let i = 0; i < arr.length; i++) {
+        if (arr[i][key] === val) {
+          return i;
+        }
+      }
+      return -1;
+    },
+    // ArrayBuffer转16进度字符串示例
+    ab2hex(buffer) {
+      var hexArr = Array.prototype.map.call(
+        new Uint8Array(buffer),
+        function (bit) {
+          return ('00' + bit.toString(16)).slice(-2)
+        }
+      )
+      return hexArr.join('');
+    }
+
   },
   created() {
     $this = this
+  },
+  onLoad(options) {
+    // 原有的code
+    let $_code = wx.getStorageSync('code')
+    if (options.q) {
+      let url = decodeURIComponent(options.q)
+      let $code = url.match(/\?code=(.*)/)[1];
+      //判断新的code 和 旧的code 是否一致 不一致则重新登录
+      console.log('1---' + $_code, '2---' + $code)
+      if ($_code && $_code != $code) {
+        Toast.fail('该用户已绑定邀请码')
+      }
+    }
   }
 }
 </script>

+ 4 - 1
src/components/device/toy/connecting.vue

@@ -50,7 +50,7 @@
     <!--        按钮组合-->
     <van-row gutter="6">
       <van-col span="8">
-        <button class="cu-btn bg-red lg text-white">
+        <button class="cu-btn bg-red lg text-white" @click="change_status">
           <img src="https://img.shuimuai.com/m_duankainaohuan.png" class="cut_brain_icon" alt="">
           <text class=" cut_text">断开脑环</text>
         </button>
@@ -199,6 +199,9 @@ export default {
     //修改连接状态
     change_toy_connect_status($status) {
       $this.$emit('change_toy_connect_status', $status)
+    },
+    change_status() {
+      $this.$emit('change_status', 0)
     }
   },
   created() {

+ 93 - 33
src/components/index/regist.vue

@@ -9,7 +9,7 @@
       <form action="">
         <view class="cu-form-group">
           <view class="title">手机号码</view>
-          <input placeholder="请输入手机号" v-model="phone"/>
+          <input placeholder="请输入手机号" v-model="phone" maxlength="11" />
           <view class="cu-capsule radius">
             <view class='cu-tag bg-blue '>
               +86
@@ -31,9 +31,12 @@
     </div>
 
     <div class="text-center padding">
-      <button class="cu-btn lg cu-btn-primary text-white text-center" @click="wechat_login">
+      <button class="cu-btn lg cu-btn-primary text-white text-center" open-type="getUserInfo" @getuserinfo="getUserinfo"
+              v-if="auth_login">
         微信授权登录
       </button>
+      <button class="cu-btn lg cu-btn-primary text-white text-center" @click="wechat_login" v-else>微信授权登录
+      </button>
     </div>
     <view class="text-center text-xs">
       <text class="text-gray">如果您在我们的实体店,请在店员的指导下链接脑环</text>
@@ -43,7 +46,7 @@
 </template>
 
 <script>
-import {userGetCode, userRegister, userLogin} from '@/requests/user'
+import {userGetCode, userRegister, userLogin, userDetail} from '@/requests/user'
 import Toast from '../../../static/vant/toast/toast';
 
 var $this
@@ -55,12 +58,13 @@ export default {
       phone: "",
       verfiy_code: "",
       time_out: 0,
-      invite: 0
+      invite: 2,
+      auth_login: false
     }
   },
-  watch:{
-    verfiy_code($new,$old){
-      if ($new.length == 6){
+  watch: {
+    verfiy_code($new, $old) {
+      if ($new.length == 6) {
         wx.hideKeyboard()
       }
     }
@@ -72,6 +76,11 @@ export default {
     },
     //获取验证码
     get_verify_code() {
+      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;
+      }
       $this.open_time_down()
       let $params = {
         phone: $this.phone
@@ -82,7 +91,12 @@ export default {
       });
     },
     //微信授权登录
-    wechat_login() {
+    wechat_login($userinfo) {
+      let $reg = /\d{6}/
+      if ($reg.test($this.verfiy_code) == false) {
+        Toast.fail('请输入正确的验证码')
+        return false;
+      }
       Toast.loading({
         duration: 0, // 持续展示 toast
         forbidClick: true,
@@ -94,34 +108,51 @@ export default {
             phone: $this.phone,
             code: $this.verfiy_code,
             js_code: $res.code,
-            invite: $this.invite
+            invite: $this.invite,
+            user_name: $userinfo['nickName'],
+            portrait: $userinfo['avatarUrl'],
+            sex: $userinfo['gender']
           }
           //用户注册
           userRegister($params).then((res) => {
             let $data = res.data
             if (!$data['code']) {
               Toast.clear()
-              Toast.success($data['errmsg'])
-              $this.$store.commit('set_token', $data['data'])
-              $this.$emit('change_login_status', true)
-            } else if ($data['code'] == 204) {
+              $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']) {
-                  Toast.clear()
-                  Toast.success($data['errmsg'])
-                  $this.$store.commit('set_token', $data['data'])
-                  $this.$emit('change_login_status', true)
+                  $this.login_success($data)
                 } else {
                   Toast.fail($data['errmsg'])
                 }
               })
+            } else if ($data['code'] == 204) {
+              Toast.fail($data['errmsg'])
             }
           })
         }
       })
     },
+    //登录成功
+    login_success($data) {
+      Toast.success($data['errmsg'])
+      $this.$store.commit('set_token', $data['data'])
+      $this.$emit('change_login_status', true)
+      $this.$store.commit('set_invite_code', $this.invite)
+      //获取用户信息
+      userDetail().then((res) => {
+        let $data = res.data
+        console.log($data)
+      })
+    },
     //打开倒计时
     open_time_down() {
       $this.time_out = 60
@@ -130,34 +161,63 @@ export default {
           $this.time_out = $this.time_out - 1
         }
       }, 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)
+            }
+          })
+        }
+      })
     }
   },
   created() {
     $this = this
+    wx.getSetting({
+      success(res) {
+        let $authSetting = res.authSetting
+        if ($authSetting['scope.userInfo']) {
+          //改为普通登录
+          $this.auth_login = false
+        }
+      }
+    })
   },
   onLoad(options) {
-    // if (!options == false) {
-    //   console.log(true)
+    // 原有的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: '请通过邀请码进入小程序',
-    //
     //   })
     // }
-    // let url = decodeURIComponent(options.q)
-    // let code = url.match(/\?code=(.*)/)[1];
-    // if (!code) {
-    //   Toast({
-    //     duration:0,
-    //     type: 'fail',
-    //     message: '请通过邀请码进入小程序',
-    //     forbidClick:true
-    //   });
-    // }
-    //
-    // $this.invite = code
-    $this.invite = 'jellyfish1001'
   }
 }
 </script>

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

@@ -1,9 +1,9 @@
 .login_card {
-  height: 410px;
+  height: 350px;
   background-color: #ffffff;
   position: relative;
   z-index: 3;
-  top: -100px;
+  top: -80px;
   margin: 0px 10px;
   background-image: url('https://img.shuimuai.com/shuimugongzhu.png');
   background-position: center;
@@ -27,13 +27,13 @@
 /*扫码页*/
 .sub_slogen_sm {
   font-size: 13px;
-  margin: 180px auto 0px;
+  margin: 140px auto 0px;
   color: #4C4C4C;
 }
 
 /*注册页面*/
 .register_form_container {
-  margin: 120px auto 0px;
+  margin: 70px auto 0px;
   width: 90%;
   height: 108px;
   background: rgba(242, 243, 255, 0.6);
@@ -47,7 +47,7 @@
   width: 100%;
   padding: 5px 7px 35px;
   margin-top: 20px;
-  top: 560px;
+  top: 520px;
 }
 
 .service .content {

+ 2 - 2
src/requests/user.js

@@ -19,9 +19,9 @@ export function userLogin($params) {
 
 //用户详情
 export function userDetail() {
-  let $token = store.get_token()
+  let $token = store.getters.get_token
   let $params = {
     access_token: $token
   }
-  return fly.post('user/login', $params)
+  return fly.post('user/user-detail', $params)
 }

+ 16 - 4
src/store/index.js

@@ -8,7 +8,8 @@ export default new Vuex.Store({
     token: 0,
     user_id: null,
     userinfo: {},
-    is_login:false
+    is_login: false,
+    invite_code: ""
   },
   mutations: {
     set_token(state, token) {
@@ -16,14 +17,25 @@ export default new Vuex.Store({
       wx.setStorageSync('is_login', true)
       state.token = token
       state.is_login = true
+    },
+    set_invite_code(state, code) {
+      state.invite_code = code
+      wx.setStorageSync('code', code)
+    },
+    set_userinfo(state, userinfo) {
+      state.userinfo = userinfo
+      wx.setStorageSync('userinfo', userinfo)
     }
   },
-  getters:{
-    get_token(state){
+  getters: {
+    get_token(state) {
       return state.token
     },
-    get_login_status(state){
+    get_login_status(state) {
       return state.is_login
+    },
+    get_userinfo(state) {
+      return state.userinfo
     }
   },
 

+ 37 - 32
src/utils/index.js

@@ -1,9 +1,9 @@
-function formatNumber (n) {
+function formatNumber(n) {
   const str = n.toString()
   return str[1] ? str : `0${str}`
 }
 
-export function formatTime (date) {
+export function formatTime(date) {
   const year = date.getFullYear()
   const month = date.getMonth() + 1
   const day = date.getDate()
@@ -39,7 +39,7 @@ function getLineOption(lineData_att, lineData_med) {
         color: "#CFCFCF"
       },
       selectedMode: false,
-      show:false
+      show: false
     },
     grid: {
       left: 20,
@@ -99,13 +99,13 @@ function getLineOption(lineData_att, lineData_med) {
       smooth: true,
       data: lineData_att
     },
-    {
-      name: "Med(放松度)",
-      symbol: 'none', //取消折点圆圈
-      type: 'line',
-      smooth: true,
-      data: lineData_med
-    },
+      {
+        name: "Med(放松度)",
+        symbol: 'none', //取消折点圆圈
+        type: 'line',
+        smooth: true,
+        data: lineData_med
+      },
     ],
     animation: false
   }
@@ -130,7 +130,7 @@ function getBaseOption(delta, theta, alpha, beta) {
         fontSize: 10,
         color: "#CFCFCF",
       },
-      show:false
+      show: false
     },
     grid: {
       left: 20,
@@ -190,33 +190,38 @@ function getBaseOption(delta, theta, alpha, beta) {
       smooth: true,
       data: delta
     },
-    {
-      name: "Theta",
-      symbol: 'none', //取消折点圆圈
-      type: 'line',
-      smooth: true,
-      data: theta
-    },
-    {
-      name: "Alpha",
-      symbol: 'none', //取消折点圆圈
-      type: 'line',
-      smooth: true,
-      data: alpha
-    },
-    {
-      name: "Beta",
-      symbol: 'none', //取消折点圆圈
-      type: 'line',
-      smooth: true,
-      data: beta,
-    },
+      {
+        name: "Theta",
+        symbol: 'none', //取消折点圆圈
+        type: 'line',
+        smooth: true,
+        data: theta
+      },
+      {
+        name: "Alpha",
+        symbol: 'none', //取消折点圆圈
+        type: 'line',
+        smooth: true,
+        data: alpha
+      },
+      {
+        name: "Beta",
+        symbol: 'none', //取消折点圆圈
+        type: 'line',
+        smooth: true,
+        data: beta,
+      },
     ],
     animation: false
   }
   return option
 }
 
+//检查 邀请码
+export function check_option(options, Toast, $this) {
+
+}
+
 export default {
   formatNumber,
   formatTime,