<template>
|
<view class="content">
|
<view>
|
<view class="bluetoothConnected">
|
<view class="bluetoothList" v-for="(item,index) in GET_CONNECTBLEDATA" :key="index" @tap="confirm_bluetooth(item)">
|
<view class="bluetoothList-name">名称:{{item.name}}</view>
|
<view class="bluetoothList-mac">地址:{{item.mac}}</view>
|
</view>
|
</view>
|
<button type="default" @click="search_bluetooth">搜索蓝牙</button>
|
<button @click="senBleLabel">打印</button>
|
<view class="bluetoothItem" v-if="GET_INFODATA">
|
<view class="bluetoothList" v-for="(item,index) in GET_INFODATA" :key="index" @tap="confirm_bluetooth(item)">
|
<view class="bluetoothList-name">名称:{{item.name}}</view>
|
<view class="bluetoothList-mac">地址:{{item.mac}}</view>
|
</view>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import printConnect from "@/common/print.js"; //引入打印机模板文件
|
let _this = null;
|
import {
|
mapGetters,
|
mapActions
|
} from 'vuex';
|
import {
|
GET_INFODATA,
|
GET_CONNECTBLEDATA
|
} from "@/store/gettersType.js";
|
import {
|
SET_CONNECTBLEDATA
|
} from '@/store/actionsType.js';
|
// #ifdef APP-PLUS
|
const HanyinPlugin = uni.requireNativePlugin('Hanyin-Plugin'); //汉印
|
// #endif
|
let print;
|
export default {
|
data() {
|
return {
|
bArray: [], //用于搜索蓝牙去重用的
|
no_match_list: [], //没有配对的蓝牙列表
|
match_list: "", //已连接蓝牙打印机
|
val: "",
|
dateTimer: "",
|
valArr: [],
|
print_data: '',
|
mat: '',
|
time: '',
|
// 巴枪参数
|
// broadcase_actions: "com.android.receive_scan_action",
|
// broadcast_flag: "data"
|
};
|
},
|
computed: {
|
...mapGetters([GET_INFODATA, GET_CONNECTBLEDATA])
|
},
|
onShow() {
|
uni.hideLoading();
|
//检查是否已连接蓝牙
|
// this.$check_bluetooth_connect();
|
console.log('onShow');
|
},
|
onHide() {
|
console.log('onHide');
|
},
|
onUnload() {
|
console.log('onUnload');
|
},
|
onLoad(options) {
|
_this = this;
|
this.$init_bluetooth();
|
let that = this
|
const eventChannel = this.getOpenerEventChannel();
|
eventChannel.on('data1', function(data1) {
|
that.mat = data1.data
|
that.time = data1.time
|
console.log(data1);
|
})
|
},
|
methods: {
|
...mapActions([SET_CONNECTBLEDATA]),
|
senBleLabel() {
|
// console.log(this.$Mock.order_data);
|
if(!print) return;
|
console.log(this.mat);
|
this.print_data = this.$Mock.order_data
|
this.print_data.MATNR = this.mat.matnr
|
this.print_data.MAKTX = this.mat.maktx
|
this.print_data.MODI_TIME = this.time
|
print.startPrint(this.print_data);
|
},
|
// 连接打印机
|
confirm_bluetooth(item) {
|
let {
|
name,
|
mac
|
} = item;
|
//判断蓝牙是否打开
|
this.$check_bluetooth_open().then(res => {
|
console.log(res);
|
//进行打印机连接
|
if (res) {
|
print =new printConnect(item); //打印机连接
|
}
|
})
|
},
|
//搜索没匹配的蓝牙设备
|
search_bluetooth(address) {
|
let _this = this;
|
//检查蓝牙是否开启
|
this.$check_bluetooth_open().then(ores => {
|
if (ores) {
|
console.log(ores);
|
//搜索蓝牙
|
_this.$search_bluetooth().then(bres => {
|
console.log(bres);
|
if (bres.code) {
|
_this.$search_pipei().then(pres => {
|
console.log(pres);
|
})
|
}
|
})
|
}
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
.bluetoothItem {
|
width: 100%;
|
height: 100%;
|
|
.bluetoothList {
|
display: flex;
|
flex-direction: column;
|
padding: 20rpx;
|
border-bottom: 1rpx solid #BEBEBE;
|
font-size: 18rpx;
|
}
|
}
|
</style>
|