You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.4 KiB
72 lines
1.4 KiB
1 year ago
|
import {
|
||
|
defineStore
|
||
|
} from 'pinia';
|
||
|
|
||
|
import {
|
||
|
reactive,
|
||
|
ref
|
||
|
} from 'vue';
|
||
|
|
||
|
import utils from '@/utils/utils.js';
|
||
|
|
||
|
// 创建hooks函数仓库
|
||
|
const useBluetoothStore = defineStore('useBluetoothStore', () => {
|
||
|
/**
|
||
|
* 已连接的蓝牙 && 打印链接成功的蓝牙信息
|
||
|
*/
|
||
|
const bluetoothInfo = reactive({
|
||
|
name: '',
|
||
|
address: '',
|
||
|
status: '',
|
||
|
uuids: [],
|
||
|
op: {},
|
||
|
})
|
||
|
|
||
|
/**
|
||
|
* 设备内已匹配的蓝牙信息组成的数组
|
||
|
*/
|
||
|
const bluetoothList = ref([])
|
||
|
|
||
|
/**
|
||
|
* 蓝牙信息初始化, 获取设备内已匹配的蓝牙信息
|
||
|
*/
|
||
|
const HANDLE_INITBLUETOOTH = () => {
|
||
|
// #ifdef APP
|
||
|
bluetoothList.value = utils.initbl_App()
|
||
|
console.log('bluetoothList.value :>> ', bluetoothList.value);
|
||
|
// #endif
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 选择蓝牙
|
||
|
* @index 蓝牙数组中被选中的索引
|
||
|
*/
|
||
|
const CHOOSE_BLUETOOTH = (index) => {
|
||
|
// 将被选中的值赋给蓝牙信息中
|
||
|
for (let key in bluetoothInfo) {
|
||
|
bluetoothInfo[key] = bluetoothList.value[index][key]
|
||
|
}
|
||
|
console.log('bluetoothInfo :>> ', bluetoothInfo);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 重置已选中蓝牙信息
|
||
|
*/
|
||
|
const CLEAR_BL_INFO = () => {
|
||
|
bluetoothInfo.name = ''
|
||
|
bluetoothInfo.address = ''
|
||
|
bluetoothInfo.status = ''
|
||
|
bluetoothInfo.uuids = []
|
||
|
bluetoothInfo.op = {}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
bluetoothInfo,
|
||
|
bluetoothList,
|
||
|
HANDLE_INITBLUETOOTH,
|
||
|
CHOOSE_BLUETOOTH
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// 导出仓库
|
||
|
export default useBluetoothStore
|