export default {
data() {
return {
iBeaconDevices: [], // 存储搜索到的iBeacon设备
deviceId: [],
data: [],
url: getApp().globalData.url,
innerAudioContext: null,
num: 0, //秒
int: null, //定时器
duration: '111', //总时长
isSliderDisabled: false,
status: false,
audio_status: false,
type: 2
}
},
// 下拉刷新
onPullDownRefresh() {
try {
this.explain()
uni.stopPullDownRefresh(); //停止刷新
} catch (e) {}},
onLoad() {
this.explain()
},
methods: {
play() {
if (!this.status) {
this.int = setInterval(() => {
this.num++
}, 1000)
this.status = true
this.change({
detail: {
value: this.num
}
})
} else {
this.status = false
clearInterval(this.int)
this.innerAudioContext.pause()
}
},
change(e) {
if (this.status) {
this.isSliderDisabled = true;
this.num = e.detail.value;
this.innerAudioContext.seek(e.detail.value)
setTimeout(() => {
this.innerAudioContext.play()
this.isSliderDisabled = false;
}, 500)
}
},
box(deviceid) {
console.log(deviceid, 99909);
let that = this
uni.openBluetoothAdapter({ //蓝牙初始化
success(res) {
uni.getLocation({
success(res) {
uni.startBeaconDiscovery({ //搜索蓝牙设备
uuids: deviceid,
success(res) {
console.log(res, 888);
uni.onBeaconUpdate((res) => { //监听蓝牙搜索到的设备
console.log(res, 999);
uni.hideLoading()
that.type = 1
})
},
fail(res) {
console.log('暂未搜索到蓝牙设备', res);
uni.showToast({
title: '暂未搜索到蓝牙设备,请下拉刷新',
icon: 'none'
})
}
})
},
fail(res) {
uni.showToast({
title: '请打开位置信息,并下拉刷新',
icon: 'none'
})
}
})
},
fail(res) {
console.log('蓝牙未打开', res);
uni.showToast({
title: '请打开蓝牙,并下拉刷新',
icon: 'none'
})
}
})
},
async explain() {
uni.showLoading({
title: '加载中...'
})
const res = await explain({
scenic_id: 3
})
this.data = res.data
if (!this.audio_status) {
this.innerAudioContext = uni.createInnerAudioContext()
this.innerAudioContext.src = this.url + this.data[0].audio;
this.innerAudioContext.onCanplay(() => {
// 获取音频总时长,单位为秒
this.duration = this.innerAudioContext.duration
console.log('音频总时长:', this.innerAudioContext.duration, 9)
})
}
this.audio_status = true
this.box([(res.data[0].deviceid)])
}
},