|
@@ -1,94 +1,95 @@
|
|
|
<template>
|
|
|
- <view class="homePage-container">
|
|
|
- <!-- 筛选弹框 -->
|
|
|
- <search-modal v-if="openScreen" :visible="openScreen" :defaultParams="searchForm" @refresh="refresh" @close="openScreen=false"></search-modal>
|
|
|
- <view class="homePage-head">
|
|
|
- <view class="head-con">
|
|
|
- <text class="homePage-tit">交易记录</text>
|
|
|
- <view class="total-con">
|
|
|
- 总计:
|
|
|
- <text class="goleNum">{{ldTotal}}</text>
|
|
|
- <image src="/static/ledou.png" class="ld-icon"></image>
|
|
|
+ <view class="bg">
|
|
|
+ <view class="bgimg">
|
|
|
+ <u-image width="622rpx" height="953rpx" src="/static/ldbg.png"></u-image>
|
|
|
+ </view>
|
|
|
+ <!-- 称重 -->
|
|
|
+ <view class="content">
|
|
|
+ <view @click="toHelp" class="tdrecord">使用帮助</view>
|
|
|
+ <view class="cz-box" @click="toWork">
|
|
|
+ <view :class="loading?'turn':''">
|
|
|
+ <u-image width="100rpx" height="100rpx" src="/static/chengzhong.png"></u-image>
|
|
|
+ <view class="tits">投放称重</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <image class="filter-icon" src="@/static/filter.png" @tap="openScreen=true"></image>
|
|
|
- </view>
|
|
|
- <scroll-view class="scroll-con" scroll-y :scroll-top="scrollTop" @scrolltolower="onreachBottom">
|
|
|
- <!-- 列表数据 -->
|
|
|
- <view class="cell-item-con">
|
|
|
- <view class="cell-item" v-for="(item, index) in listdata" :key="index">
|
|
|
- <view class="cell-item-c">
|
|
|
- <view class="cell-item-label">交易时间</view>
|
|
|
- <view class="cell-item-main">{{item.createDate}}</view>
|
|
|
- </view>
|
|
|
- <view class="cell-item-c">
|
|
|
- <view class="cell-item-label">支付账户</view>
|
|
|
- <view class="cell-item-main">{{item.customerMobile}}</view>
|
|
|
- </view>
|
|
|
- <view class="cell-item-c">
|
|
|
- <view class="cell-item-label">交易数量(个)</view>
|
|
|
- <view :class="['cell-item-main', item.changeType=='ADD' ? 'red' : 'blue']">{{item.changeType=='ADD' ? '+' : item.changeType=='SUB' ? '-' : ''}}{{ item.changeNum }}</view>
|
|
|
- </view>
|
|
|
- <view class="cell-item-c">
|
|
|
- <view class="cell-item-label">备注</view>
|
|
|
- <view class="cell-item-main">{{item.remarks ? item.remarks : '--'}}</view>
|
|
|
- </view>
|
|
|
- <view class="cell-item-c handle-con">
|
|
|
- <view class="cell-item-label">操作</view>
|
|
|
- <view class="cell-item-main">
|
|
|
- <u-button size="mini" v-if="item.changeType=='ADD' && item.cancelFlag==0" class="handle-btn" hover-class="none" :custom-style="customBtnStyle" @click="revokeFun(item)">撤销单据</u-button>
|
|
|
- <text v-if="item.changeType=='ADD' && item.cancelFlag==1" style="color: #909399;">单据已撤销</text>
|
|
|
- <text v-if="item.changeType=='SUB'" style="color: #909399;">扫码支付撤销</text>
|
|
|
- </view>
|
|
|
+ <view class="bindDev" @click="toInit">
|
|
|
+ {{statusStr}}
|
|
|
+ </view>
|
|
|
+ <view class="devList">
|
|
|
+ <view v-for="item in deviceList" :key="item.deviceId">
|
|
|
+ <view class="names">
|
|
|
+ <view>设备名称:{{item.name}}</view>
|
|
|
+ <view class="texts">MAC:{{item.deviceId}}</view>
|
|
|
</view>
|
|
|
+ <view class="btns" @click="connectBlue(item)" v-if="!connectStatus">点击连接</view>
|
|
|
+ <view class="btns" @click="closeBlue('连接已断开,请重新连接设备')" v-else>断开连接</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <u-empty class="nodata" :text="noDataText" v-if="listdata.length==0 && status!='loading'" mode="list"></u-empty>
|
|
|
- <view class="loadmore">
|
|
|
- <u-loadmore v-if="total>pageSize || status=='loading'" :status="status" />
|
|
|
- </view>
|
|
|
- </scroll-view>
|
|
|
-
|
|
|
- <view class="footer-bar">
|
|
|
- <u-button shape="circle" @click="openQuery" size="medium" type="primary">用户乐豆查询/核销</u-button>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
+
|
|
|
<script>
|
|
|
- import searchModal from './searchModal.vue'
|
|
|
+ import {getLookUpDatas} from '@/api/data.js'
|
|
|
import { getUserInfo } from '@/api/user.js'
|
|
|
- import { getGoldLogList, GoldLogCancel, GoldLogTotal } from '@/api/officialPartnerGoldLog.js'
|
|
|
export default {
|
|
|
- components: { searchModal },
|
|
|
data() {
|
|
|
return {
|
|
|
- listdata: [],
|
|
|
- pageNo: 1, // 当前页码
|
|
|
- pageSize: 10, // 每页条数
|
|
|
- total: 0, // 数据总条数
|
|
|
- noDataText: '暂无数据', // 列表请求状态提示语
|
|
|
- status: 'loadmore', // 加载中状态
|
|
|
- openScreen: false, // 是否打开筛选
|
|
|
- searchForm: { // 查询条件
|
|
|
- beginDate: '', // 创建时间默认筛选近7天
|
|
|
- endDate: '', // 创建时间默认筛选近7天
|
|
|
- customerMobile: '' // 支付账户
|
|
|
- },
|
|
|
- customBtnStyle: { // 撤销单据 自定义按钮样式
|
|
|
- borderColor: '#2ab4e5',
|
|
|
- backgroundColor: '#2ab4e5',
|
|
|
- color: '#fff'
|
|
|
- },
|
|
|
- scrollTop: 0, // 滚动条位置
|
|
|
- ldTotal: 0 // 乐豆总计数
|
|
|
+ deviceList:[], // 设备列表
|
|
|
+ deviceId: null,
|
|
|
+ iosMac: null,
|
|
|
+ connectedDeviceId: '',
|
|
|
+ services: [],
|
|
|
+ readsId:'',
|
|
|
+ writeId:'',
|
|
|
+ notifyServicweId: '',
|
|
|
+ writeDatas: '',
|
|
|
+ balanceData: '',
|
|
|
+ hexstr: '',
|
|
|
+ statusStr: '绑定电子秤',
|
|
|
+ connectStatus: false ,// 设备连接状态
|
|
|
+ loading: false ,// 正在连接
|
|
|
}
|
|
|
},
|
|
|
+ onLoad() {
|
|
|
+ let _this = this
|
|
|
+ uni.$on('blueReConnect',function(){
|
|
|
+ uni.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: '正在重连中...'
|
|
|
+ })
|
|
|
+ _this.connectBlue()
|
|
|
+ })
|
|
|
+
|
|
|
+ // 系统信息
|
|
|
+ const sysinfo = uni.getSystemInfoSync();
|
|
|
+ this.platform = sysinfo.platform
|
|
|
+ console.log(sysinfo,'sysinfo')
|
|
|
+ },
|
|
|
onShow() {
|
|
|
- this.openScreen = false // 关闭筛选框
|
|
|
- this.refresh({})
|
|
|
+ // 获取订单状态数据字典
|
|
|
+ // this.getCodeList('RUBBISH_TYPE','vuex_rubbishType')
|
|
|
this.getUserInfo()
|
|
|
+ uni.getSetting({
|
|
|
+ success(res) {
|
|
|
+ if(!res.authSetting['scope.userLocation']){
|
|
|
+ uni.authorize({
|
|
|
+ scope: 'scope.userLocation',
|
|
|
+ success() {
|
|
|
+ console.log('scope.userLocation success')
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log('scope.userLocation fail')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ uni.$off('blueReConnect')
|
|
|
},
|
|
|
- methods:{
|
|
|
+ methods: {
|
|
|
// 获取用户信息
|
|
|
getUserInfo(){
|
|
|
getUserInfo().then(res => {
|
|
@@ -97,215 +98,532 @@
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- openQuery(){
|
|
|
+ // 获取数据字典
|
|
|
+ getCodeList(code,key) {
|
|
|
+ getLookUpDatas({
|
|
|
+ type: code
|
|
|
+ }).then(res => {
|
|
|
+ if (res.status == 200) {
|
|
|
+ this.$u.vuex(key, res.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 使用帮助
|
|
|
+ toHelp(){
|
|
|
uni.navigateTo({
|
|
|
- url: "/pages/userCenter/leDouQuery"
|
|
|
+ url: '/pages/help/help'
|
|
|
})
|
|
|
},
|
|
|
- // 总计
|
|
|
- getGoldLogTotal(){
|
|
|
- GoldLogTotal({
|
|
|
- beginDate: this.searchForm.beginDate,
|
|
|
- endDate: this.searchForm.endDate,
|
|
|
- customerMobile: this.searchForm.customerMobile
|
|
|
- }).then(res => {
|
|
|
- if(res.status == 200){
|
|
|
- this.ldTotal = res.data ? res.data.changeNum : 0
|
|
|
+ // 去认证用户并开始称重
|
|
|
+ toWork(){
|
|
|
+ let _this = this
|
|
|
+ // 连接成功
|
|
|
+ if(this.connectStatus){
|
|
|
+ // ios 设备无法获取mac地址,请手动扫描电子秤的MAC条形码
|
|
|
+ if(this.platform == 'ios'&&this.iosMac==null){
|
|
|
+ uni.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content: '苹果手机无法获取mac地址,请扫描电子秤的MAC二维码',
|
|
|
+ confirmText: '去扫描',
|
|
|
+ complete(e) {
|
|
|
+ if(e.confirm){
|
|
|
+ uni.scanCode({
|
|
|
+ success(res) {
|
|
|
+ console.log(res)
|
|
|
+ _this.iosMac = res.result
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/userAuth/userAuth?macAddress=' + _this.iosMac + '&id=' + _this.deviceId
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}else{
|
|
|
- this.ldTotal = 0
|
|
|
+ // 安卓系统直接跳转
|
|
|
+ uni.navigateTo({
|
|
|
+ url: '/pages/userAuth/userAuth?macAddress=' + (this.platform == 'ios' ? _this.iosMac : _this.deviceId) + '&id=' + _this.deviceId
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ let hasDev = this.deviceList.length
|
|
|
+ if(!this.loading){
|
|
|
+ uni.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content:hasDev ? '请先连接设备':'请先绑定设备',
|
|
|
+ confirmText: hasDev ? '确定':'去绑定',
|
|
|
+ complete(e) {
|
|
|
+ console.log(e)
|
|
|
+ if(e.confirm){
|
|
|
+ if(hasDev == 1){
|
|
|
+ _this.connectBlue(_this.deviceList[0])
|
|
|
+ }
|
|
|
+ if(hasDev == 0){
|
|
|
+ _this.toInit()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
+ uni.getBluetoothDevices({
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'getBluetoothDevices')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 初始化蓝牙
|
|
|
+ toInit(){
|
|
|
+ let _this = this
|
|
|
+ if(this.connectStatus || this.deviceList.length > 0 || this.loading){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uni.openBluetoothAdapter({
|
|
|
+ success(res) {
|
|
|
+ console.log(res, 'openBluetoothAdapter success')
|
|
|
+ _this.loading = true
|
|
|
+ setTimeout(()=>{
|
|
|
+ _this.toFindDev()
|
|
|
+ },500)
|
|
|
+ },
|
|
|
+ fail(err){
|
|
|
+ console.log(err,'openBluetoothAdapter error')
|
|
|
+ _this.loading = false
|
|
|
+ uni.showModal({
|
|
|
+ title:'提示',
|
|
|
+ content: _this.platform == 'ios' ? '请开启蓝牙(如果已开启,还是无法使用,请打开系统设置->微信->蓝牙开关再试)' : '请开启手机蓝牙',
|
|
|
+ showCancel: false,
|
|
|
+ complete(e) {
|
|
|
+ console.log(e)
|
|
|
+ _this.statusStr = '请开启手机蓝牙'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
+ _this.onBluetoothAdapterStateChange()
|
|
|
},
|
|
|
- // 获取查询参数 刷新列表
|
|
|
- refresh(params){
|
|
|
- this.searchForm = params
|
|
|
- this.listdata = []
|
|
|
- this.total = 0
|
|
|
- this.searchHandle(1)
|
|
|
- this.getGoldLogTotal()
|
|
|
+ toFindDev(){
|
|
|
+ let _this = this
|
|
|
+ _this.statusStr = '开始搜寻附近的电子秤,请确认设备已开启'
|
|
|
+ uni.getBluetoothAdapterState({
|
|
|
+ success(res) {
|
|
|
+ console.log(res)
|
|
|
+ if(res.available){
|
|
|
+ // 开始搜寻附近的蓝牙外围设备
|
|
|
+ _this.startBluetoothDevicesDiscovery()
|
|
|
+ }else{
|
|
|
+ _this.statusStr = '请开启手机蓝牙'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
- // 撤销单据
|
|
|
- revokeFun(row){
|
|
|
- const _this = this
|
|
|
- uni.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '撤销单据后乐豆将全部退回给原支付账号,确认撤销吗?',
|
|
|
+ // 监听蓝牙状态
|
|
|
+ onBluetoothAdapterStateChange(){
|
|
|
+ let _this = this
|
|
|
+ // 监听蓝牙适配器状态变化事件
|
|
|
+ uni.onBluetoothAdapterStateChange(function (res) {
|
|
|
+ console.log(res,'适配器变化')
|
|
|
+ if(!res.available){
|
|
|
+ // 关闭连接
|
|
|
+ _this.loading = false
|
|
|
+ if(_this.connectedDeviceId){
|
|
|
+ _this.closeBlue('蓝牙已关闭,请开启手机蓝牙')
|
|
|
+ }else{
|
|
|
+ _this.statusStr = '蓝牙已关闭,请开启手机蓝牙'
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(!res.discovering && !_this.loading){
|
|
|
+ _this.statusStr = _this.connectedDeviceId ? '蓝牙已启用,请连接设备':'蓝牙已启用,请绑定设备'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ startBluetoothDevicesDiscovery(){
|
|
|
+ let _this = this
|
|
|
+ uni.startBluetoothDevicesDiscovery({
|
|
|
+ services: [],
|
|
|
success(res) {
|
|
|
- if (res.confirm) {
|
|
|
- GoldLogCancel({ id: row.id }).then(ret => {
|
|
|
- if(ret.status == 200){
|
|
|
- uni.showToast({ title: ret.message, icon: 'none' })
|
|
|
- _this.searchHandle(1)
|
|
|
- }
|
|
|
- })
|
|
|
+ console.log(res,'startBluetoothDevicesDiscovery')
|
|
|
+ },
|
|
|
+ fail(res){
|
|
|
+ console.log(res,'startBluetoothDevicesDiscovery error')
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 监听寻找到新设备的事件
|
|
|
+ uni.onBluetoothDeviceFound(function (res) {
|
|
|
+ console.log(res,'onBluetoothDeviceFound')
|
|
|
+ let devices = res.devices.filter(item => item.name == 'FAYA')
|
|
|
+ const hasDev = _this.deviceList.find(item => item.deviceId == res.devices[0].deviceId)
|
|
|
+ console.log(devices,hasDev,'devices list')
|
|
|
+ if(devices.length&&!hasDev){
|
|
|
+ _this.statusStr = '已发现设备'
|
|
|
+ _this.deviceList = _this.deviceList.concat(res.devices)
|
|
|
+ _this.loading = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 连接蓝牙设备
|
|
|
+ connectBlue(item){
|
|
|
+ if(this.connectStatus){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // ios 的deviceid 不是真正的mac 地址
|
|
|
+ if(item){
|
|
|
+ this.deviceId = item.deviceId
|
|
|
+ }
|
|
|
+ this.statusStr = '正在连接设备...'
|
|
|
+ this.loading = true
|
|
|
+ this.createBLEConnection()
|
|
|
+ },
|
|
|
+ // 断开蓝牙设备
|
|
|
+ closeBlue(msg){
|
|
|
+ let _this = this
|
|
|
+ uni.closeBLEConnection({
|
|
|
+ deviceId: _this.connectedDeviceId,
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res,msg)
|
|
|
+ _this.connectedDeviceId = null
|
|
|
+ _this.statusStr = msg
|
|
|
+ _this.connectStatus = false
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res)
|
|
|
}
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 开始连接指定设备
|
|
|
+ createBLEConnection(){
|
|
|
+ let _this = this
|
|
|
+ uni.createBLEConnection({
|
|
|
+ // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
|
|
|
+ deviceId:this.deviceId,
|
|
|
+ success(res) {
|
|
|
+ console.log(res)
|
|
|
+ _this.connectedDeviceId = _this.deviceId
|
|
|
+ // 获取连接设备的service服务
|
|
|
+ setTimeout(()=>{
|
|
|
+ _this.getBLEDeviceServices()
|
|
|
+ },1000)
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err,'createBLEConnection error')
|
|
|
+ _this.statusStr = '连接失败,请检查蓝牙是否开启后重试'
|
|
|
+ _this.connectStatus = false
|
|
|
+ _this.loading = false
|
|
|
+ uni.$emit('blueConnectCallback',0)
|
|
|
+ uni.hideLoading()
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- // 搜索查询
|
|
|
- searchHandle (pageNo) {
|
|
|
- this.status = "loading"
|
|
|
- pageNo ? this.pageNo = pageNo : null
|
|
|
- getGoldLogList({
|
|
|
- pageNo: this.pageNo,
|
|
|
- pageSize: this.pageSize,
|
|
|
- beginDate: this.searchForm.beginDate,
|
|
|
- endDate: this.searchForm.endDate,
|
|
|
- customerMobile: this.searchForm.customerMobile
|
|
|
- }).then(res => {
|
|
|
- if (res.status == 200) {
|
|
|
- if(this.pageNo>1){
|
|
|
- this.listdata = this.listdata.concat(res.data.list || [])
|
|
|
- }else{
|
|
|
- this.listdata = res.data.list || []
|
|
|
- this.scrollTop = 0
|
|
|
+ // 获取连接设备的service服务
|
|
|
+ getBLEDeviceServices(){
|
|
|
+ let _this = this
|
|
|
+ uni.getBLEDeviceServices({
|
|
|
+ // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
|
|
|
+ deviceId: _this.deviceId,
|
|
|
+ success(res) {
|
|
|
+ console.log('device services:', res.services)
|
|
|
+ // _this.statusStr = '获取连接设备的service服务成功'
|
|
|
+ _this.services = res.services
|
|
|
+ /* 获取连接设备的所有特征值 */
|
|
|
+ setTimeout(()=>{
|
|
|
+ _this.getBLEDeviceCharacteristics()
|
|
|
+ },500)
|
|
|
+ // 停止搜索
|
|
|
+ uni.stopBluetoothDevicesDiscovery({
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res, '停止搜索')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取连接设备的所有特征值
|
|
|
+ getBLEDeviceCharacteristics(){
|
|
|
+ let _this = this
|
|
|
+ this.notifyServicweId = this.services[1].uuid
|
|
|
+ uni.getBLEDeviceCharacteristics({
|
|
|
+ deviceId: this.connectedDeviceId,
|
|
|
+ serviceId: this.notifyServicweId,
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res)
|
|
|
+ // _this.statusStr = '获取连接设备的所有特征值成功'
|
|
|
+ for (let i = 0; i < res.characteristics.length; i++) {
|
|
|
+ let properties = res.characteristics[i].properties
|
|
|
+ // 读id
|
|
|
+ if(properties.notify&&!properties.read&&!properties.write){
|
|
|
+ _this.readsId = res.characteristics[i].uuid
|
|
|
+ }
|
|
|
+ // 写id
|
|
|
+ if(!properties.notify&&!properties.read&&properties.write){
|
|
|
+ _this.writeId = res.characteristics[i].uuid
|
|
|
+ }
|
|
|
+ console.log(_this.readsId,_this.writeId, '蓝牙特征值 ==========')
|
|
|
+ // 启用低功耗蓝牙设备特征值变化时的 notify 功能
|
|
|
+ setTimeout(()=>{
|
|
|
+ _this.notifyBLECharacteristicValueChange()
|
|
|
+ },500)
|
|
|
}
|
|
|
- this.total = res.data.count || 0
|
|
|
- this.noDataText = '暂无数据'
|
|
|
- } else {
|
|
|
- this.noDataText = res.message
|
|
|
- this.listdata = []
|
|
|
- this.total = 0
|
|
|
+ },
|
|
|
+ fail: function(res) {
|
|
|
+ console.log(res)
|
|
|
}
|
|
|
- this.status = "loadmore"
|
|
|
})
|
|
|
},
|
|
|
- // scroll-view到底部加载更多
|
|
|
- onreachBottom() {
|
|
|
- if(this.listdata.length < this.total){
|
|
|
- this.pageNo += 1
|
|
|
- this.searchHandle()
|
|
|
- }else{
|
|
|
- uni.showToast({ title: '已经到底了', icon: 'none' })
|
|
|
- this.status = "nomore"
|
|
|
- }
|
|
|
- }
|
|
|
+ // 启用低功耗蓝牙设备特征值变化时的 notify 功能
|
|
|
+ notifyBLECharacteristicValueChange() {
|
|
|
+ let that = this;
|
|
|
+ uni.notifyBLECharacteristicValueChange({
|
|
|
+ state: true,
|
|
|
+ deviceId: that.connectedDeviceId,
|
|
|
+ serviceId: that.notifyServicweId,
|
|
|
+ characteristicId: that.readsId,
|
|
|
+ success(res) {
|
|
|
+ console.log(res,'notifyBLECharacteristicValueChange')
|
|
|
+ that.statusStr = '连接成功,请投放称重'
|
|
|
+ if(!that.connectStatus){
|
|
|
+ uni.$emit('blueConnectCallback',1)
|
|
|
+ that.connectStatus = true
|
|
|
+ uni.hideLoading()
|
|
|
+ that.toWork()
|
|
|
+ }
|
|
|
+ that.loading = false
|
|
|
+
|
|
|
+ /*用来监听手机蓝牙设备的数据变化*/
|
|
|
+ uni.onBLECharacteristicValueChange(function(res) {
|
|
|
+ // console.log(res,'read data')
|
|
|
+ that.balanceData = that.buf2string(res.value)
|
|
|
+ that.$u.vuex('vuex_balanceData',that.balanceData)
|
|
|
+ })
|
|
|
+ // 该方法回调中可以用于处理连接意外断开等异常情况
|
|
|
+ uni.onBLEConnectionStateChange(function (res) {
|
|
|
+ // console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
|
|
|
+ if(!res.connected&&that.connectedDeviceId){
|
|
|
+ uni.$emit('blueConnectClose',res)
|
|
|
+ that.statusStr = '连接已断开,请检查蓝牙或电子秤是否开启'
|
|
|
+ that.connectStatus = false
|
|
|
+ that.loading = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res, '启用低功耗蓝牙设备监听失败')
|
|
|
+ that.statusStr = '连接失败,请点击重试'
|
|
|
+ that.closeConnect()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /*转换成需要的格式*/
|
|
|
+ buf2string(buffer) {
|
|
|
+ let arr = Array.prototype.map.call(new Uint8Array(buffer), x => x)
|
|
|
+ return arr.map((char, i) => {
|
|
|
+ return String.fromCharCode(char);
|
|
|
+ }).join('');
|
|
|
+ },
|
|
|
+ receiveData(buf) {
|
|
|
+ return this.hexCharCodeToStr(this.ab2hex(buf))
|
|
|
+ },
|
|
|
+ /*转成二进制*/
|
|
|
+ ab2hex (buffer) {
|
|
|
+ let hexArr = Array.prototype.map.call(
|
|
|
+ new Uint8Array(buffer), function (bit) {
|
|
|
+ return ('00' + bit.toString(16)).slice(-2)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return hexArr.join('')
|
|
|
+ },
|
|
|
+ /*转成可展会的文字*/
|
|
|
+ hexCharCodeToStr(hexCharCodeStr) {
|
|
|
+ let trimedStr = hexCharCodeStr.trim();
|
|
|
+ let rawStr = trimedStr.substr(0, 2).toLowerCase() === '0x' ? trimedStr.substr(2) : trimedStr;
|
|
|
+ let len = rawStr.length;
|
|
|
+ let curCharCode;
|
|
|
+ let resultStr = [];
|
|
|
+ for (let i = 0; i < len; i = i + 2) {
|
|
|
+ curCharCode = parseInt(rawStr.substr(i, 2), 16);
|
|
|
+ resultStr.push(String.fromCharCode(curCharCode));
|
|
|
+ }
|
|
|
+ return resultStr.join('');
|
|
|
+ },
|
|
|
+ // 发送数据
|
|
|
+ sendData(str) {
|
|
|
+ let that = this;
|
|
|
+ let dataBuffer = new ArrayBuffer(3)
|
|
|
+ let dataView = new DataView(dataBuffer)
|
|
|
+
|
|
|
+ dataView.setUint8(0, 0x02)
|
|
|
+ dataView.setUint8(1, 0x41)
|
|
|
+ dataView.setUint8(2, 0x03)
|
|
|
+ let dataHex = that.ab2hex(dataBuffer);
|
|
|
+ this.writeDatas = that.hexCharCodeToStr(dataHex);
|
|
|
+ uni.writeBLECharacteristicValue({
|
|
|
+ deviceId: that.connectedDeviceId,
|
|
|
+ serviceId: that.notifyServicweId,
|
|
|
+ characteristicId: that.writeId,
|
|
|
+ value: dataBuffer,
|
|
|
+ success: function (res) {
|
|
|
+ console.log('发送数据成功:' + that.writeDatas)
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ console.log('发送失败:' + res)
|
|
|
+ },
|
|
|
+ complete: function (res) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 断开设备连接
|
|
|
+ closeConnect() {
|
|
|
+ let that = this;
|
|
|
+ if (that.connectedDeviceId) {
|
|
|
+ uni.closeBLEConnection({
|
|
|
+ deviceId: that.connectedDeviceId,
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res)
|
|
|
+ that.deviceId = null
|
|
|
+ that.iosMac = null
|
|
|
+ that.closeBluetoothAdapter()
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ that.closeBluetoothAdapter()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 关闭蓝牙模块
|
|
|
+ closeBluetoothAdapter() {
|
|
|
+ let that = this;
|
|
|
+ uni.closeBluetoothAdapter({
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res,'closeBluetoothAdapter')
|
|
|
+ that.connectStatus = false
|
|
|
+ that.loading = false
|
|
|
+ that.balanceData = ''
|
|
|
+ that.deviceList = []
|
|
|
+ that.deviceId = null
|
|
|
+ that.iosMac = null
|
|
|
+ },
|
|
|
+ fail: function(err) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.closeConnect()
|
|
|
+ },
|
|
|
+ onShareAppMessage() {
|
|
|
+ },
|
|
|
+ onShareTimeline() {
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
-<style lang="scss">
|
|
|
- page{
|
|
|
- height: 100%;
|
|
|
+<style lang="less">
|
|
|
+ // @import url("bg.less");
|
|
|
+ .bg{
|
|
|
+ height: 100vh;
|
|
|
+ width: 100%;
|
|
|
+ position: relative;
|
|
|
+ background-color: #015a50;
|
|
|
}
|
|
|
- .homePage-container {
|
|
|
+ .bgimg{
|
|
|
+ position: absolute;
|
|
|
+ z-index: 100;
|
|
|
width: 100%;
|
|
|
- height: 100%;
|
|
|
+ height: 100vh;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ }
|
|
|
+ .content{
|
|
|
display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
flex-direction: column;
|
|
|
- padding: 102rpx 0;
|
|
|
- .footer-bar{
|
|
|
- width: 100%;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- height: 102rpx;
|
|
|
- justify-content: center;
|
|
|
- padding: 0 10%;
|
|
|
- position: fixed;
|
|
|
- bottom: 0;
|
|
|
- left: 0;
|
|
|
- }
|
|
|
- // 筛选菜单
|
|
|
- .homePage-head{
|
|
|
- font-size: 30rpx;
|
|
|
- display: flex;
|
|
|
- justify-content: space-between;
|
|
|
- align-items: center;
|
|
|
- position: fixed;
|
|
|
- top: 0;
|
|
|
- left: 0;
|
|
|
- z-index: 9;
|
|
|
- padding: 26rpx 30rpx;
|
|
|
- background-color: #fff;
|
|
|
- box-shadow: 0rpx 0rpx 14rpx rgba(0,0,0,.05);
|
|
|
- width: 100%;
|
|
|
- border-top: 10rpx solid #f8f8f8;
|
|
|
- .head-con{
|
|
|
- flex-grow: 1;
|
|
|
- display: flex;
|
|
|
- align-items: center;
|
|
|
- justify-content: space-between;
|
|
|
- .homePage-tit{
|
|
|
- color: #040301;
|
|
|
- }
|
|
|
- .total-con{
|
|
|
- color: #040301;
|
|
|
- .goleNum{
|
|
|
- color: #eb0000;
|
|
|
- font-size: 30rpx;
|
|
|
- font-weight: bold;
|
|
|
- }
|
|
|
- .ld-icon{
|
|
|
- width: 30rpx;
|
|
|
- height: 30rpx;
|
|
|
- margin: 0 0 0 10rpx;
|
|
|
- vertical-align: middle;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- .filter-icon{
|
|
|
- flex-shrink: 0;
|
|
|
- width: 36rpx;
|
|
|
- height: 36rpx;
|
|
|
- padding-left: 20rpx;
|
|
|
- }
|
|
|
- }
|
|
|
- // 列表
|
|
|
- .scroll-con{
|
|
|
- flex: 1;
|
|
|
- // height: calc(100% - 40);
|
|
|
- overflow: auto;
|
|
|
- }
|
|
|
- // 列表样式
|
|
|
- .cell-item-con{
|
|
|
- margin: 20rpx;
|
|
|
- .cell-item{
|
|
|
- background-color: #fff;
|
|
|
- color: #606266;
|
|
|
- padding: 0 30rpx;
|
|
|
- margin-bottom: 20rpx;
|
|
|
- border-radius: 16rpx;
|
|
|
- font-size: 28rpx;
|
|
|
- box-shadow: 3rpx 3rpx 5rpx #eee;
|
|
|
- .cell-item-c{
|
|
|
- display: flex;
|
|
|
- justify-content: space-between;
|
|
|
- padding: 18rpx 0;
|
|
|
- border-bottom: 1rpx solid #f2f2f2;
|
|
|
- .cell-item-label{
|
|
|
- flex-shrink: 0;
|
|
|
- width: 200rpx;
|
|
|
- color: #303133;
|
|
|
- }
|
|
|
- .cell-item-main{
|
|
|
- flex-grow: 1;
|
|
|
- text-align: right;
|
|
|
- .handle-btn{
|
|
|
- border-color: #fcbd71!important;
|
|
|
- background-color: #fcbd71!important;
|
|
|
- }
|
|
|
- }
|
|
|
- .blue {
|
|
|
- color: #1890FF;
|
|
|
- }
|
|
|
- .green {
|
|
|
- color: #16b50e;
|
|
|
- }
|
|
|
- .red {
|
|
|
- color: red;
|
|
|
- }
|
|
|
- &:last-child{
|
|
|
- border: none;
|
|
|
- }
|
|
|
- }
|
|
|
- .handle-con{
|
|
|
- align-items: center;
|
|
|
- // margin-top: 10rpx;
|
|
|
- // padding-top: 18rpx;
|
|
|
- // padding: 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ height: 100vh;
|
|
|
+ width: 100%;
|
|
|
+ position: absolute;
|
|
|
+ z-index: 1000;
|
|
|
+ }
|
|
|
+ .tdrecord{
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 5%;
|
|
|
+ background: rgba(255,255,255,0.6);
|
|
|
+ border-radius: 150rpx 0 0 150rpx;
|
|
|
+ box-shadow: 2rpx 2rpx 6rpx rgba(0,0,0,0.4);
|
|
|
+ padding: 15rpx 20rpx 15rpx 30rpx;
|
|
|
+ font-size: 26rpx;
|
|
|
+ }
|
|
|
+ .cz-box{
|
|
|
+ text-align: center;
|
|
|
+ background: #01c9b2;
|
|
|
+ border-radius: 300rpx;
|
|
|
+ box-shadow: 3rpx 3rpx 10rpx rgba(0,0,0,0.4);
|
|
|
+ }
|
|
|
+ .cz-box > view{
|
|
|
+ width: 250rpx;
|
|
|
+ height: 250rpx;
|
|
|
+ padding: 50rpx 50rpx 30rpx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ flex-direction: column;
|
|
|
+ }
|
|
|
+ .tits{
|
|
|
+ padding: 20rpx 0;
|
|
|
+ color: #FFFFFF;
|
|
|
+ }
|
|
|
+ .devList{
|
|
|
+ width: 80%;
|
|
|
+ padding:10rpx 30rpx;
|
|
|
+ max-height: 50vh;
|
|
|
+ overflow: auto;
|
|
|
+ }
|
|
|
+ .bindDev{
|
|
|
+ margin: 20rpx 0;
|
|
|
+ padding: 15rpx 40rpx;
|
|
|
+ background: rgba(19,22,30,0.8);
|
|
|
+ box-shadow: 2rpx 2rpx 8rpx rgba(0,0,0,0.2);
|
|
|
+ border-radius: 100rpx;
|
|
|
+ color: #FFFFFF;
|
|
|
+ }
|
|
|
+ .devList > view{
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ color: #666666;
|
|
|
+ border-radius: 20rpx;
|
|
|
+ background: rgba(255,255,255,0.8);
|
|
|
+ box-shadow: 2rpx 2rpx 5rpx rgba(0,0,0,0.2);
|
|
|
+ margin-bottom: 20rpx;
|
|
|
+ }
|
|
|
+ .devList > view .names{
|
|
|
+ flex-grow: 1;
|
|
|
+ padding: 15rpx 40rpx;
|
|
|
+ }
|
|
|
+ .devList > view .texts{
|
|
|
+ font-size: 24rpx;
|
|
|
+ }
|
|
|
+ .devList > view .btns{
|
|
|
+ text-align: center;
|
|
|
+ padding: 15rpx 20rpx;
|
|
|
+ color: #ff5500;
|
|
|
+ }
|
|
|
+ .turn{
|
|
|
+ animation:turn 1s linear infinite;
|
|
|
+ }
|
|
|
+ @keyframes turn{
|
|
|
+ 0%{-webkit-transform:rotate(0deg);}
|
|
|
+ 25%{-webkit-transform:rotate(90deg);}
|
|
|
+ 50%{-webkit-transform:rotate(180deg);}
|
|
|
+ 75%{-webkit-transform:rotate(270deg);}
|
|
|
+ 100%{-webkit-transform:rotate(360deg);}
|
|
|
}
|
|
|
</style>
|