Преглед изворни кода

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

yerong пре 4 година
родитељ
комит
21ea636600

+ 1 - 0
package.json

@@ -25,6 +25,7 @@
   "dependencies": {
     "flyio": "^0.6.14",
     "mpvue": "^2.0.0",
+    "mpvue-echarts": "^0.3.2",
     "vuex": "^3.0.1"
   },
   "devDependencies": {

+ 19 - 381
src/components/device/device.vue

@@ -34,9 +34,12 @@
         <!--      玩具模块-->
         <!--      玩具连接中-->
         <div class="connecting_toy">
-          <toy_connecting :connect_toy="connect_toy" @open_choose_toy="open_choose_toy"
+          <toy_connecting :connect_toy="connect_toy"
+                          :deviceId="_deviceId"
+                          @open_choose_toy="open_choose_toy"
                           @change_toy_connect_status="change_toy_connect_status"
                           @change_status="change_device_status"
+                          @game_start="game_start"
           ></toy_connecting>
         </div>
       </div>
@@ -87,9 +90,10 @@ import device_connected from '@/components/device/connected';
 //连接玩具
 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";
+import game_store from '@/store/game'
+import bluetooth from "@/utils/bluetooth";
 
 
 let $this;
@@ -288,6 +292,8 @@ export default {
           if (device['name'] == $this.code) {
             $this.stopBluetoothDevicesDiscovery()
             $this.device = device
+            game_store.commit('setDeviceId', device.deviceId)
+            $this._deviceId = device.deviceId
             $this.createBLEConnection()
           }
         })
@@ -314,396 +320,28 @@ export default {
           console.log('成功连接')
           //成功连接脑环蓝牙
           $this.change_device_status(2)
-          $this.getBLEDeviceServices($this.device.deviceId)
+          // $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('');
-    },
-
     //  获取游戏设备玩具
-    get_toy_list(){
-      game_devices().then((res)=>{
+    get_toy_list() {
+      game_devices().then((res) => {
         let $data = res.data
       })
-    }
+    },
 
+    //  开始游戏的方法
+    game_start() {
+      game_store.commit('setToyIndex', $this.toy_action - 1)
+      // bluetooth.sendConnect($this.toy_action - 1, $this._deviceId, $this._serviceId, $this._characteristicId)
+      console.log('device.vue', $this._deviceId)
+    }
   },
-  mounted(){
+  mounted() {
     $this.get_toy_list()
   },
   created() {

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

@@ -130,14 +130,14 @@
 
         <van-row gutter="11">
           <van-col span="11" offset="1">
-            <div class="pay_type_item flex flex-direction justify-center align-center" @click.prevent="choose_pay(1)">
+            <div class="pay_type_item flex flex-direction justify-center align-center" @click.prevent="choose_pay(2)">
               <view class="text-xl padding">
                 <text class="text-white text-bold">消费时间</text>
               </view>
             </div>
           </van-col>
           <van-col span="11">
-            <div class="pay_type_item  flex flex-direction justify-center align-center" @click.prevent="choose_pay(2)">
+            <div class="pay_type_item  flex flex-direction justify-center align-center" @click.prevent="choose_pay(1)">
               <view class="text-xl padding">
                 <text class="text-white text-bold">消费次卡</text>
               </view>
@@ -150,18 +150,23 @@
       </div>
       <img src="https://img.shuimuai.com/web/boy2.png" alt="" class="connected_boy2">
     </van-overlay>
+    <van-toast id="van-toast"/>
+
   </div>
 </template>
 
 <script>
+import {gameStart} from "@/requests/game";
+import Toast from "../../../../static/vant/toast/toast";
+
 let $this;
 export default {
   name: "connected",
-  props: ['connect_toy'],
+  props: ['connect_toy', 'deviceId'],
   data() {
     return {
       pay_window: false,
-      // 0:未选择 1:时间 2:次数
+      //  使用类型 1次数 2时间 0未选择
       pay_type: 0
     }
   },
@@ -184,9 +189,30 @@ export default {
     //选择消费的时间或者次数
     choose_pay($event) {
       $this.pay_type = $event
-      mpvue.navigateTo({
-        url: "/pages/start/main?mode=" + $event
+      let $params = {
+        type: $event,
+        device_id: $this.deviceId,
+        access_token: wx.getStorageSync('token')
+      }
+      gameStart($params).then((res) => {
+        let $data = res.data
+        console.log('游戏开始返回', $data)
+        // if ($data.code == 0) {
+        if ($data.code) {
+          Toast.success({
+            message: $data.errmsg,
+            onClose() {
+              $this.$emit('game_start')
+              mpvue.navigateTo({
+                url: "/pages/start/main?mode=" + $event
+              })
+            }
+          })
+        } else {
+          Toast.fail($data.errmsg)
+        }
       })
+
     },
     //点击隐藏
     onClickHide() {

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

@@ -72,7 +72,7 @@
         <van-col span="6" offset="2">
           <div class="flex flex-direction align-center">
 
-            <text class="text-xxl">{{ userinfo.playtime }}</text>
+            <text class="text-xxl">{{ userinfo.play_time }}</text>
             <text class="font-sm">可用时长(分钟)</text>
           </div>
         </van-col>

+ 17 - 28
src/components/user_center/order_list.vue

@@ -13,34 +13,29 @@
         <div>
           <text class="text-gray">{{ order.create_time }}</text>
           <view class="text-right">
-            <template v-if="order.status">
-              <text class="text-bold">交易完成</text>
+            <template v-if="order.pay_status == 1">
+              <text class="text-bold">未付款</text>
             </template>
             <template>
-              <text>待支付</text>
+              <text>已付款</text>
             </template>
           </view>
         </div>
       </div>
       <!--      图标部分-->
       <div slot="thumb" class="thumb_container">
-        <img  src="https://img.shuimuai.com/web/icon_dingdan.png" class="order_icon" alt="">
+        <img src="https://img.shuimuai.com/web/icon_dingdan.png" class="order_icon" alt="">
       </div>
       <!--      消费产品-->
       <div slot="desc">
         <div>
           <text class="text-gray">消费产品&nbsp;</text>
-          <text>{{ order.production.name }} x {{ order.production.count }}</text>
+          <text>{{ order.goods_name }} x 1</text>
         </div>
         <div class="padding-tb-lg flex justify-between align-center">
           <div>
             <text class="text-gray">付款方式&nbsp;</text>
-            <template v-if="order.pay_type == 'wechat'">
               <text class="text-bold">微信支付</text>
-            </template>
-            <template>
-              <text>其他支付</text>
-            </template>
           </div>
           <div>
             <text class="text-gray">实付款&nbsp;</text>
@@ -61,29 +56,23 @@
 </template>
 
 <script>
+
+var $this
 export default {
   name: "order_list",
-  props: ['status'],
+  props: ['status','orders'],
   data() {
     return {
-      orders: [
-        {
-          id: 1,
-          sn: "201708161601",
-          production:
-            {
-              id: 1,
-              name: '钻石会员卡',
-              count: 1
-            }
-          ,
-          total_price: 23678.99,
-          pay_type: 'wechat',
-          status: 2,
-          create_time: "2018/09/24 10:44"
-        }
-      ],
+
     }
+  },
+  methods: {
+
+  },
+  mounted() {
+  },
+  created(){
+    $this = this
   }
 }
 </script>

+ 6 - 6
src/pages/report/index.vue

@@ -48,7 +48,7 @@
       </view>
     </view>
     <view class="chart">
-      <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" :ec="attCharts"></ec-canvas>
+      <mpvue-echarts :echarts="echarts" :onInit="attCharts" canvasId="demo-canvas"/>
     </view>
     <view class="conclution">专注力良好,你的表现比一般人好。专注力波动较大,比较容易被外界干扰。你大多数时候不能很好地集中注意力,请继续加油。</view>
     <view class="bar">
@@ -73,7 +73,8 @@
 </template>
 
 <script>
-import * as echarts from '../../../static/ec-canvas/echarts.min';
+import mpvueEcharts from 'mpvue-echarts'
+import echarts from '../../../static/echarts.min';
 import util from '../../utils/index'
 
 var att_charts,
@@ -97,12 +98,14 @@ function initAttChart(canvas, width, height) {
 export default {
   name: "index_container",
   components: {
+    mpvueEcharts
   },
   data() {
     return {
       // 0:未选择 1:时间 2:次数
       // 折线图
-      attCharts: {},
+      attCharts: initAttChart,
+      echarts
     }
   },
   methods: {}
@@ -111,9 +114,6 @@ export default {
   },
   created() {
     $this = this;
-    $this.attCharts = {
-      onInit: initAttChart
-    }
   },
   onLoad() {
   }

+ 265 - 18
src/pages/start/index.vue

@@ -67,7 +67,8 @@
         </view>
       </view>
       <view class="chart">
-        <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" :ec="attCharts"></ec-canvas>
+        <mpvue-echarts :echarts="echarts" :onInit="attCharts" canvasId="demo-canvas"/>
+
       </view>
       <view class="bar">
         <view>
@@ -94,7 +95,7 @@
         </view>
       </view>
       <view class="chart">
-        <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" :ec="medCharts"></ec-canvas>
+        <mpvue-echarts :echarts="echarts" :onInit="medCharts" canvasId="demo-canvas-1"/>
       </view>
     </div>
 
@@ -119,8 +120,11 @@
 </template>
 
 <script>
-import * as echarts from '../../../static/ec-canvas/echarts.min';
+import mpvueEcharts from 'mpvue-echarts'
+import echarts from '../../../static/echarts.min';
 import util from '../../utils/index'
+import bluetooth from "../../utils/bluetooth";
+import game_store from "@/store/game";
 
 var att_charts,
   med_charts,
@@ -158,23 +162,24 @@ function initMedChart(canvas, width, height) {
 
 export default {
   name: "index_container",
-  components: {},
+  components: {
+    mpvueEcharts
+  },
   data() {
     return {
-      // 0:未选择 1:时间 2:次数
+      // 使用类型 1次数 2时间 0未选择
       mode: 0,
       mode_list: [
         {
-          id: 1,
+          id: 2,
           name: "会员时间消费",
           time: 20 * 60 * 1000,
           err_title: "本次游玩时间已用完"
         },
         {
-          id: 2,
+          id: 1,
           name: "次卡(10分钟)",
-          // time: 10 * 60 * 1000,
-          time: 1 * 1000,
+          time: 10 * 60 * 1000,
           err_title: "您的会员消费时间已用完",
         }
       ],
@@ -182,14 +187,35 @@ export default {
       pop_show: false,
       elc_power: 100,
       // 折线图
-      attCharts: {},
-      medCharts: {}
+      echarts,
+      attCharts: initAttChart,
+      medCharts: initMedChart,
+      user_info: {},
+      _deviceId: "",
+      _serviceId: "",
+      _characteristicId: "",
+      toy_index: 0
     }
   },
   methods: {
     //游戏结束方法
     game_finished() {
-      $this.to_report()
+      let $deviceId = game_store.getters.getDeviceId
+      let $serviceId = game_store.getters.getServiceId
+      let $charatorId = game_store.getters.getCharacterId
+      //停止控制游戏
+      bluetooth.sendEnd($deviceId, $serviceId, $charatorId)
+      //关闭脑环
+      wx.closeBLEConnection({
+        deviceId: $deviceId,
+        success(res) {
+          Toast.success('已成功断开')
+          //设置游戏状态为 停止游戏
+          game_store.commit('setGameStatus', 0)
+          $this.to_report()
+        }
+      })
+
     },
     //  关闭弹窗
     close_pop() {
@@ -203,21 +229,242 @@ export default {
       mpvue.navigateTo({
         url: "/pages/report/main"
       })
+    },
+    //获取蓝牙设备服务
+    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
+              game_store.commit('setDeviceId', deviceId)
+              game_store.commit('setServiceId', serviceId)
+              game_store.commit('setCid', item.uuid)
+              bluetooth.sendPause(deviceId, serviceId, item.uuid)
+              bluetooth.sendConnect($this.toy_index, deviceId, serviceId, item.uuid)
+            }
+
+            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
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+          console.log("水柱音箱")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0002') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到喷雾恐龙(大)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("喷雾恐龙(大)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0003') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到喷雾恐龙(小)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("喷雾恐龙(小)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0004') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到轨道车',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("轨道车")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0005') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到碰碰车',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("碰碰车")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0006') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到小车(大)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("小车(大)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0007') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到小车(中)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("小车(中)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0008') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到小车(小)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("小车(小)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a0009') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到飞行器(大)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("飞行器(大)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a000a') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到飞行器(小)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("飞行器(小)")
+        }
+        if (hexStr.substring(0, 10) == 'aadd0a000b') {
+          wx.hideLoading()
+          wx.showToast({
+            title: '已连接到水母灯)',
+            icon: 'success',
+            duration: 1500
+          })
+          bluetooth.sendControl($this._deviceId, $this._serviceId, $this._characteristicId)
+          $this.connect_toy = 2
+
+          console.log("水母灯")
+        }
+        if (hexStr.substring(0, 10) == 'aadd070000') {
+          bluetooth.sendOpen($this._deviceId, $this._serviceId, $this._characteristicId)
+        }
+      })
+    },
+
+    // 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('');
     }
   }
   ,
   mounted() {
+    $this._deviceId = game_store.getters.getDeviceId
+    $this.toy_index = game_store.getters.getToyIndex
+    $this.getBLEDeviceServices($this._deviceId)
   },
   created() {
     $this = this;
-    $this.attCharts = {
-      onInit: initAttChart
-    }
-    $this.medCharts = {
-      onInit: initMedChart
-    }
   },
   onLoad($option) {
+    $this.userinfo = wx.getStorageSync('userinfo')
+    $this.mode_list.forEach(($val, $index) => {
+      if ($val['id'] == 2) {
+        $val['time'] = parseInt($this.userinfo['play_time']) * 60 * 1000
+      }
+    })
+    console.log($this.mode_list)
     $this.mode = $option.mode
     $this.mode_list.forEach(($val, $index) => {
       if ($option.mode == $val['id']) {

+ 1 - 2
src/pages/start/main.json

@@ -3,7 +3,6 @@
     "van-row": "../../static/vant/row/index",
     "van-col": "../../static/vant/col/index",
     "van-popup": "../../static/vant/popup/index",
-    "van-count-down": "../../static/vant/count-down/index",
-    "ec-canvas": "../../static/ec-canvas/ec-canvas"
+    "van-count-down": "../../static/vant/count-down/index"
   }
 }

+ 29 - 11
src/pages/user_center/edit/confirm_phone_first/index.vue

@@ -10,7 +10,7 @@
       </view>
 
       <van-field
-        :value="sms"
+        v-model="sms"
         center
         clearable
         label="短信验证码"
@@ -27,20 +27,22 @@
         <button class="cu-btn lg cu-btn-primary text-white text-center " @click="to_finally_confirm">确定修改</button>
       </div>
     </div>
-    <van-toast id="van-toast" />
+    <van-toast id="van-toast"/>
   </div>
 </template>
 
 <script>
 import Toast from '../../../../../static/vant/toast/toast';
+import {userGetCode,userLogin} from "@/requests/user";
+
 var $this
 export default {
   name: "uc_edit_container",
   components: {},
   data() {
     return {
-      base_phone: "18802603801",
-      phone: "18802603801",
+      base_phone: "13038899265",
+      phone: "13038899265",
       sms: "",
       custom_style: `width: 330px;
             height: 49px;
@@ -61,20 +63,36 @@ export default {
     },
     //  发送验证码
     sand_sms() {
+      Toast.loading({
+        duration:0
+      })
       let $param = {
-        phone:$this.base_phone
+        phone: $this.base_phone
       }
-      $this.$fly.post('user/get-code',$param).then((res)=>{
+      userGetCode($param).then((res) => {
+        Toast.clear()
         let $data = res.data
-        if ($data.code != 200){
-          Toast.fail($data.errmsg)
+        if ($data.code != 200) {
+          Toast.success($data.errmsg)
         }
       })
     },
     //跳转最终修改手机的页面
-    to_finally_confirm(){
-      mpvue.navigateTo({
-        url:"/pages/user_center/edit/confirm_phone_finally/main"
+    to_finally_confirm() {
+      Toast.loading({
+        duration:0
+      })
+      userLogin({phone: $this.base_phone, code: $this.sms}).then((res) => {
+                Toast.clear()
+        let $data = res.data
+        if ($data.code == 0) {
+          mpvue.navigateTo({
+            url: "/pages/user_center/edit/confirm_phone_finally/main"
+          })
+          $this.$store.commit('set_token', $data['data'])
+        }else{
+          Toast.fail($data.errmsg)
+        }
       })
     }
   }

+ 31 - 5
src/pages/user_center/orders/index.vue

@@ -2,13 +2,11 @@
   <div class="uc_orders_container">
     <van-tabs :active="0" color="#4B3AB0">
       <van-tab title="全部">
-        <order_list></order_list>
+        <order_list :orders="orders"></order_list>
       </van-tab>
       <van-tab title="待支付">
-        <order_list></order_list>
       </van-tab>
       <van-tab title="已支付">
-        <order_list></order_list>
       </van-tab>
     </van-tabs>
   </div>
@@ -17,6 +15,9 @@
 <script>
 import order_list from "@/components/user_center/order_list";
 
+import {orderList} from "@/requests/orders";
+import {formatTime} from "@/utils/index";
+
 var $this
 export default {
   name: "uc_orders_container",
@@ -24,11 +25,36 @@ export default {
     order_list
   },
   data() {
-    return {}
+    return {
+      orders: [
+        {
+          "order_id": "12",
+          "sn": "DD202009281821264613",
+          "goods_name": "黄金会员",
+          "payment": "",
+          //1未付款 2已付款
+          "pay_status": "1",
+          "create_time": "1601288486"
+        }
+      ],
+    }
   },
-  methods: {}
+  methods: {
+    //获取订单列表
+    get_order_list() {
+      orderList().then((res) => {
+        let $data = res.data
+        // $this.orders = $data.data
+        $this.orders.forEach(($val, $index) => {
+          $this.orders[$index]['create_time'] = formatTime($val['create_time'] * 1000)
+        })
+        console.log($this.orders)
+      })
+    }
+  }
   ,
   mounted() {
+    this.get_order_list()
   },
   created() {
     $this = this;

+ 27 - 1
src/requests/game.js

@@ -10,12 +10,38 @@ fly.interceptors.request.use((config, promise) => {
 
 // 设备列表
 export function game_devices($params) {
+  $params['access_token'] = wx.getStorageSync('token')
   return fly.post('game/device-list', $params)
 }
 
 
 // 开始游戏
-export function game_start($params) {
+export function gameStart($params) {
   return fly.post('game/game-start', $params)
 }
 
+//结束游戏
+export function gameEnd($params) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('game/game-over', $params)
+}
+
+//游戏记录详情
+export function gameDetail($params) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('game/game-detail', $params)
+}
+
+//折线图图表
+export function gameLineChart($params) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('game/line', $params)
+}
+
+
+// 添加折线图的点
+export function gameAddLine($params) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('game/add-line', $params)
+}
+

+ 23 - 0
src/requests/orders.js

@@ -0,0 +1,23 @@
+import fly from "./main";
+import store from "@/store/index"
+
+// 订单列表
+export function orderList() {
+  let $params = {
+    access_token: wx.getStorageSync('token')
+  }
+  return fly.post('order/order-list', $params)
+}
+
+//创建订单
+export function createOrder($params) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('order/create-order', $params)
+}
+
+
+//支付订单
+export function payOrder($params) {
+  $params['access_token'] = wx.getStorageSync('token')
+  return fly.post('order/pay', $params)
+}

+ 51 - 0
src/store/game.js

@@ -0,0 +1,51 @@
+import Vue from 'vue'
+import Vuex from 'vuex'
+
+Vue.use(Vuex)
+
+export default new Vuex.Store({
+  state: {
+    deviceId: "",
+    serviceId: "",
+    characteristicId: "",
+    //游戏状态 0 不在游戏,1游戏中
+    game_status: 0,
+    toy_index: 0
+  },
+  mutations: {
+    setDeviceId(state, deviceId) {
+      state.deviceId = deviceId
+    },
+
+    setServiceId(state, serviceId) {
+      state.serviceId = serviceId
+    },
+    setCid(state, characteristicId) {
+      state.characteristicId = characteristicId
+    },
+    setGameStatus(state, status) {
+      state.game_status = status
+    },
+    setToyIndex(state, toy_index) {
+      state.toy_index = toy_index
+    }
+  },
+  getters: {
+    getDeviceId(state, getters) {
+      return state.deviceId
+    },
+    getServiceId(state, getters) {
+      return state.serviceId
+    },
+    getCharacterId(state, getters) {
+      return state.characteristicId
+    },
+    getGameStatus(state) {
+      return state.game_status
+    },
+    getToyIndex(state) {
+      return state.toy_index
+    }
+  },
+
+})

+ 170 - 0
src/utils/bluetooth.js

@@ -1,3 +1,173 @@
 export default {
+  // 发送开启脑电数据包指令
+  sendOpen(deviceId, serviceId, Cid) {
+    // 向蓝牙设备发送一个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: deviceId,
+      serviceId: serviceId,
+      characteristicId: Cid,
+      value: buffer,
+      success: function (res) {
+        console.log('开启脑电数据包成功')
+        console.log(res)
+      },
+      fail: function (err) {
+        console.log('开启脑电数据包失败')
+        console.log(err)
+      }
 
+    })
+  },
+  // 发送开启教具脑控指令
+  sendControl(deviceId, serviceId, Cid) {
+    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: deviceId,
+      serviceId: serviceId,
+      characteristicId: Cid,
+      value: buffer,
+      success: function (res) {
+        console.log('开启教具脑控成功')
+        // that.sendOpen()
+        console.log(res)
+      },
+      fail: function (err) {
+        console.log('开启教具脑控失败')
+        console.log(err)
+      }
+
+    })
+  },
+  // 发送连接玩具指令
+  sendConnect(index, deviceId, serviceId, Cid) {
+    const that = this
+    // 玩具对应指令数组
+    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: deviceId,
+      serviceId: serviceId,
+      characteristicId: Cid,
+      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)
+      }
+
+    })
+  },
+  //发送断开玩具的指令
+  sendEnd(deviceId, serviceId, Cid) {
+    //AA CC 03 00 00 00 09 F3
+    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, '0x09')
+    dataView.setUint8(7, '0xf3')
+    // 向低功耗蓝牙设备特征值中写入二进制数据
+    console.log(buffer)
+    wx.writeBLECharacteristicValue({
+      deviceId: deviceId,
+      serviceId: serviceId,
+      characteristicId: Cid,
+      value: buffer,
+      success: function (res) {
+        console.log('断开玩具成功')
+        // that.sendOpen()
+        console.log(res)
+      },
+      fail: function (err) {
+        console.log('断开玩具失败')
+        console.log(err)
+      }
+
+    })
+  },
+  // 发送停止发送脑电数据包指令
+  sendPause(deviceId, serviceId, Cid) {
+    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: deviceId,
+      serviceId: serviceId,
+      characteristicId: Cid,
+      value: buffer,
+      success: function (res) {
+        console.log('停止数据发送成功')
+        console.log(res)
+      },
+      fail: function (err) {
+        console.log('停止数据发送失败')
+        console.log(err)
+      }
+    })
+  },
 }

+ 3 - 6
src/utils/index.js

@@ -4,18 +4,15 @@ function formatNumber(n) {
 }
 
 export function formatTime(date) {
-  const year = date.getFullYear()
+  var date = new Date(date)
   const month = date.getMonth() + 1
   const day = date.getDate()
 
   const hour = date.getHours()
-  const minute = date.getMinutes()
-  const second = date.getSeconds()
 
-  const t1 = [year, month, day].map(formatNumber).join('/')
-  const t2 = [hour, minute, second].map(formatNumber).join(':')
+  const t1 = [ month, day].map(formatNumber).join('/')
 
-  return `${t1} ${t2}`
+  return `${t1}`
 }
 
 // 专注力与放松力图表

+ 0 - 250
static/ec-canvas/ec-canvas.js

@@ -1,250 +0,0 @@
-import WxCanvas from './wx-canvas';
-import * as echarts from "./echarts.min";
-
-let ctx;
-
-function compareVersion(v1, v2) {
-  v1 = v1.split('.')
-  v2 = v2.split('.')
-  const len = Math.max(v1.length, v2.length)
-
-  while (v1.length < len) {
-    v1.push('0')
-  }
-  while (v2.length < len) {
-    v2.push('0')
-  }
-
-  for (let i = 0; i < len; i++) {
-    const num1 = parseInt(v1[i])
-    const num2 = parseInt(v2[i])
-
-    if (num1 > num2) {
-      return 1
-    } else if (num1 < num2) {
-      return -1
-    }
-  }
-  return 0
-}
-
-Component({
-  properties: {
-    canvasId: {
-      type: String,
-      value: 'ec-canvas'
-    },
-
-    ec: {
-      type: Object
-    },
-
-    forceUseOldCanvas: {
-      type: Boolean,
-      value: false
-    }
-  },
-
-  data: {
-    isUseNewCanvas: false
-  },
-
-  ready: function () {
-    // Disable prograssive because drawImage doesn't support DOM as parameter
-    // See https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
-    echarts.registerPreprocessor(option => {
-      if (option && option.series) {
-        if (option.series.length > 0) {
-          option.series.forEach(series => {
-            series.progressive = 0;
-          });
-        }
-        else if (typeof option.series === 'object') {
-          option.series.progressive = 0;
-        }
-      }
-    });
-
-    if (!this.data.ec) {
-      console.warn('组件需绑定 ec 变量,例:<ec-canvas id="mychart-dom-bar" '
-        + 'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>');
-      return;
-    }
-
-    if (!this.data.ec.lazyLoad) {
-      this.init();
-    }
-  },
-
-  methods: {
-    init: function (callback) {
-      const version = wx.getSystemInfoSync().SDKVersion
-
-      const canUseNewCanvas = compareVersion(version, '2.9.0') >= 0;
-      const forceUseOldCanvas = this.data.forceUseOldCanvas;
-      const isUseNewCanvas = canUseNewCanvas && !forceUseOldCanvas;
-      this.setData({ isUseNewCanvas });
-
-      if (forceUseOldCanvas && canUseNewCanvas) {
-        console.warn('开发者强制使用旧canvas,建议关闭');
-      }
-
-      if (isUseNewCanvas) {
-        // console.log('微信基础库版本大于2.9.0,开始使用<canvas type="2d"/>');
-        // 2.9.0 可以使用 <canvas type="2d"></canvas>
-        this.initByNewWay(callback);
-      } else {
-        const isValid = compareVersion(version, '1.9.91') >= 0
-        if (!isValid) {
-          console.error('微信基础库版本过低,需大于等于 1.9.91。'
-            + '参见:https://github.com/ecomfe/echarts-for-weixin'
-            + '#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82');
-          return;
-        } else {
-          console.warn('建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能');
-          this.initByOldWay(callback);
-        }
-      }
-    },
-
-    initByOldWay(callback) {
-      // 1.9.91 <= version < 2.9.0:原来的方式初始化
-      ctx = wx.createCanvasContext(this.data.canvasId, this);
-      const canvas = new WxCanvas(ctx, this.data.canvasId, false);
-
-      echarts.setCanvasCreator(() => {
-        return canvas;
-      });
-      // const canvasDpr = wx.getSystemInfoSync().pixelRatio // 微信旧的canvas不能传入dpr
-      const canvasDpr = 1
-      var query = wx.createSelectorQuery().in(this);
-      query.select('.ec-canvas').boundingClientRect(res => {
-        if (typeof callback === 'function') {
-          this.chart = callback(canvas, res.width, res.height, canvasDpr);
-        }
-        else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
-          this.chart = this.data.ec.onInit(canvas, res.width, res.height, canvasDpr);
-        }
-        else {
-          this.triggerEvent('init', {
-            canvas: canvas,
-            width: res.width,
-            height: res.height,
-            canvasDpr: canvasDpr // 增加了dpr,可方便外面echarts.init
-          });
-        }
-      }).exec();
-    },
-
-    initByNewWay(callback) {
-      // version >= 2.9.0:使用新的方式初始化
-      const query = wx.createSelectorQuery().in(this)
-      query
-        .select('.ec-canvas')
-        .fields({ node: true, size: true })
-        .exec(res => {
-          const canvasNode = res[0].node
-          this.canvasNode = canvasNode
-
-          const canvasDpr = wx.getSystemInfoSync().pixelRatio
-          const canvasWidth = res[0].width
-          const canvasHeight = res[0].height
-
-          const ctx = canvasNode.getContext('2d')
-
-          const canvas = new WxCanvas(ctx, this.data.canvasId, true, canvasNode)
-          echarts.setCanvasCreator(() => {
-            return canvas
-          })
-
-          if (typeof callback === 'function') {
-            this.chart = callback(canvas, canvasWidth, canvasHeight, canvasDpr)
-          } else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
-            this.chart = this.data.ec.onInit(canvas, canvasWidth, canvasHeight, canvasDpr)
-          } else {
-            this.triggerEvent('init', {
-              canvas: canvas,
-              width: canvasWidth,
-              height: canvasHeight,
-              dpr: canvasDpr
-            })
-          }
-        })
-    },
-    canvasToTempFilePath(opt) {
-      if (this.data.isUseNewCanvas) {
-        // 新版
-        const query = wx.createSelectorQuery().in(this)
-        query
-          .select('.ec-canvas')
-          .fields({ node: true, size: true })
-          .exec(res => {
-            const canvasNode = res[0].node
-            opt.canvas = canvasNode
-            wx.canvasToTempFilePath(opt)
-          })
-      } else {
-        // 旧的
-        if (!opt.canvasId) {
-          opt.canvasId = this.data.canvasId;
-        }
-        ctx.draw(true, () => {
-          wx.canvasToTempFilePath(opt, this);
-        });
-      }
-    },
-
-    touchStart(e) {
-      if (this.chart && e.touches.length > 0) {
-        var touch = e.touches[0];
-        var handler = this.chart.getZr().handler;
-        handler.dispatch('mousedown', {
-          zrX: touch.x,
-          zrY: touch.y
-        });
-        handler.dispatch('mousemove', {
-          zrX: touch.x,
-          zrY: touch.y
-        });
-        handler.processGesture(wrapTouch(e), 'start');
-      }
-    },
-
-    touchMove(e) {
-      if (this.chart && e.touches.length > 0) {
-        var touch = e.touches[0];
-        var handler = this.chart.getZr().handler;
-        handler.dispatch('mousemove', {
-          zrX: touch.x,
-          zrY: touch.y
-        });
-        handler.processGesture(wrapTouch(e), 'change');
-      }
-    },
-
-    touchEnd(e) {
-      if (this.chart) {
-        const touch = e.changedTouches ? e.changedTouches[0] : {};
-        var handler = this.chart.getZr().handler;
-        handler.dispatch('mouseup', {
-          zrX: touch.x,
-          zrY: touch.y
-        });
-        handler.dispatch('click', {
-          zrX: touch.x,
-          zrY: touch.y
-        });
-        handler.processGesture(wrapTouch(e), 'end');
-      }
-    }
-  }
-});
-
-function wrapTouch(event) {
-  for (let i = 0; i < event.touches.length; ++i) {
-    const touch = event.touches[i];
-    touch.offsetX = touch.x;
-    touch.offsetY = touch.y;
-  }
-  return event;
-}

+ 0 - 4
static/ec-canvas/ec-canvas.json

@@ -1,4 +0,0 @@
-{
-  "component": true,
-  "usingComponents": {}
-}

+ 0 - 4
static/ec-canvas/ec-canvas.wxml

@@ -1,4 +0,0 @@
-<!-- 新的:接口对其了H5 -->
-<canvas wx:if="{{isUseNewCanvas}}" type="2d" class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
-<!-- 旧的 -->
-<canvas wx:else class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>

+ 0 - 4
static/ec-canvas/ec-canvas.wxss

@@ -1,4 +0,0 @@
-.ec-canvas {
-  width: 100%;
-  height: 100%;
-}

+ 0 - 121
static/ec-canvas/wx-canvas.js

@@ -1,121 +0,0 @@
-export default class WxCanvas {
-  constructor(ctx, canvasId, isNew, canvasNode) {
-    this.ctx = ctx;
-    this.canvasId = canvasId;
-    this.chart = null;
-    this.isNew = isNew
-    if (isNew) {
-      this.canvasNode = canvasNode;
-    }
-    else {
-      this._initStyle(ctx);
-    }
-
-    // this._initCanvas(zrender, ctx);
-
-    this._initEvent();
-  }
-
-  getContext(contextType) {
-    if (contextType === '2d') {
-      return this.ctx;
-    }
-  }
-
-  // canvasToTempFilePath(opt) {
-  //   if (!opt.canvasId) {
-  //     opt.canvasId = this.canvasId;
-  //   }
-  //   return wx.canvasToTempFilePath(opt, this);
-  // }
-
-  setChart(chart) {
-    this.chart = chart;
-  }
-
-  attachEvent() {
-    // noop
-  }
-
-  detachEvent() {
-    // noop
-  }
-
-  _initCanvas(zrender, ctx) {
-    zrender.util.getContext = function () {
-      return ctx;
-    };
-
-    zrender.util.$override('measureText', function (text, font) {
-      ctx.font = font || '12px sans-serif';
-      return ctx.measureText(text);
-    });
-  }
-
-  _initStyle(ctx) {
-    var styles = ['fillStyle', 'strokeStyle', 'globalAlpha',
-      'textAlign', 'textBaseAlign', 'shadow', 'lineWidth',
-      'lineCap', 'lineJoin', 'lineDash', 'miterLimit', 'fontSize'];
-
-    styles.forEach(style => {
-      Object.defineProperty(ctx, style, {
-        set: value => {
-          if (style !== 'fillStyle' && style !== 'strokeStyle'
-            || value !== 'none' && value !== null
-          ) {
-            ctx['set' + style.charAt(0).toUpperCase() + style.slice(1)](value);
-          }
-        }
-      });
-    });
-
-    ctx.createRadialGradient = () => {
-      return ctx.createCircularGradient(arguments);
-    };
-  }
-
-  _initEvent() {
-    this.event = {};
-    const eventNames = [{
-      wxName: 'touchStart',
-      ecName: 'mousedown'
-    }, {
-      wxName: 'touchMove',
-      ecName: 'mousemove'
-    }, {
-      wxName: 'touchEnd',
-      ecName: 'mouseup'
-    }, {
-      wxName: 'touchEnd',
-      ecName: 'click'
-    }];
-
-    eventNames.forEach(name => {
-      this.event[name.wxName] = e => {
-        const touch = e.touches[0];
-        this.chart.getZr().handler.dispatch(name.ecName, {
-          zrX: name.wxName === 'tap' ? touch.clientX : touch.x,
-          zrY: name.wxName === 'tap' ? touch.clientY : touch.y
-        });
-      };
-    });
-  }
-
-  set width(w) {
-    if (this.canvasNode) this.canvasNode.width = w
-  }
-  set height(h) {
-    if (this.canvasNode) this.canvasNode.height = h
-  }
-
-  get width() {
-    if (this.canvasNode)
-      return this.canvasNode.width
-    return 0
-  }
-  get height() {
-    if (this.canvasNode)
-      return this.canvasNode.height
-    return 0
-  }
-}

+ 0 - 0
static/ec-canvas/echarts.min.js → static/echarts.min.js