fix: 进入设备默认选择

This commit is contained in:
white 2024-10-14 11:52:09 +08:00
parent a631f1df48
commit a53ecc126c
9 changed files with 147 additions and 261 deletions

View File

@ -20,7 +20,7 @@
<view class="btn"> <view class="btn">
<liu-data-select elementId="data-select3" :dataList="deviceList" @change="changeDev" bgColor="#fff" <liu-data-select elementId="data-select3" :dataList="deviceList" @change="changeDev" bgColor="#fff"
color="#000"> color="#000">
<view id="data-select3" class="btn-info1">{{name2? '设备:' + name2 : '选择设备'}}</view> <view id="data-select3" class="btn-info1">{{Activedevice? '设备:' + Activedevice : '选择设备'}}</view>
</liu-data-select> </liu-data-select>
</view> </view>
<view class="btn" @click="outlogin"> <view class="btn" @click="outlogin">
@ -317,6 +317,9 @@
}, },
dataListsNew: { dataListsNew: {
default: [] default: []
},
Activedevice: {
default: ''
} }
}, },
data() { data() {
@ -343,6 +346,9 @@
}, },
mounted() { mounted() {
this.name2 = this.getActiceDevice.device_id this.name2 = this.getActiceDevice.device_id
setTimeout((
console.log(this.name2, '子子子子子子子子子子子子子子')
), 3000)
}, },
onLoad() { onLoad() {
/* /*
@ -388,6 +394,7 @@
methods: { methods: {
getArrMaxValue, getArrMaxValue,
onRefresh(pageNo, pageSize) { onRefresh(pageNo, pageSize) {
console.log('手选')
this.$store.dispatch('api/getIndexData', { this.$store.dispatch('api/getIndexData', {
device_id: this.getActiceDevice.device_id , device_id: this.getActiceDevice.device_id ,
need_arr :[ need_arr :[

View File

@ -16,7 +16,7 @@
<view class="content"> <view class="content">
<!-- 首页数据 --> <!-- 首页数据 -->
<view class="content-wrap" v-if="Sindex == 1"> <view class="content-wrap" v-if="Sindex == 1">
<homeData :dataListsNew="dataListsNew" :deviceList="deviceList" @deviceGet="deviceGet" @pageDetail="pageDetail"></homeData> <homeData :dataListsNew="dataListsNew" :deviceList="deviceList" :Activedevice="Activedevice" @deviceGet="deviceGet" @pageDetail="pageDetail"></homeData>
</view> </view>
<!-- 图表 --> <!-- 图表 -->
@ -89,7 +89,7 @@
name1: '', name1: '',
name2: '', name2: '',
deviceList: [], deviceList: [],
Activedevice: '',
urlLink: '', urlLink: '',
activeType: '', // activeType: '', //
@ -160,8 +160,34 @@
methods: { methods: {
getArrMaxValue, getArrMaxValue,
onRefresh(pageNo, pageSize) { onRefresh(pageNo, pageSize) {
//
this.$store.dispatch('api/getBindUserDeviceId').then(res => {
this.deviceList = res;
//
if (!this.getActiceDevice.device_id) {
if (this.deviceList.length) {
this.name2 = this.deviceList[0].device_id;
this.$store.commit('api/setActiceDevice', this.deviceList[0]);
//
this.$store.dispatch('api/getUserInfo', { device_id: this.deviceList[0].device_id }).then(res => {
this.$store.commit('api/setUserInfo', res);
this.Activedevice = this.deviceList[0].device_id;
this.IndexData(this.deviceList[0].device_id);
});
};
} else {
this.IndexData(this.getActiceDevice.device_id);
this.Activedevice = this.getActiceDevice.device_id;
};
});
},
//
IndexData(device_id) {
this.$store.dispatch('api/getIndexData', { this.$store.dispatch('api/getIndexData', {
device_id: this.getActiceDevice.device_id , device_id: device_id,
need_arr :[ need_arr :[
'pulseReat', 'pulseReat',
'bloodOxygen', 'bloodOxygen',
@ -181,10 +207,6 @@
this.dataListsNew[res[i].name] = this.getNameByKey(res[i].type) this.dataListsNew[res[i].name] = this.getNameByKey(res[i].type)
} }
//
// this.dataListsNew.bodyData = JSON.parse(JSON.stringify(this.dataListsNew.bloodLiquid));
// this.dataListsNew.bodyData.type = 'bodyData';
console.log(this.dataListsNew)
if (this.dataListsNew.ECGData.data_msg) { if (this.dataListsNew.ECGData.data_msg) {
// //
delete this.dataListsNew.ECGData.data_msg.wavefrom; delete this.dataListsNew.ECGData.data_msg.wavefrom;
@ -194,12 +216,7 @@
this.urlLink = `/hybrid/html/ai.html?data=${JSON.stringify(this.dataListsNew)}&user=${JSON.stringify(this.getUserInfo)}&token=${store.getters['api/getApiToken']}&deviceId=${this.getActiceDevice.device_id}`; this.urlLink = `/hybrid/html/ai.html?data=${JSON.stringify(this.dataListsNew)}&user=${JSON.stringify(this.getUserInfo)}&token=${store.getters['api/getApiToken']}&deviceId=${this.getActiceDevice.device_id}`;
this.loading = false; this.loading = false;
} }
); );
this.$store.dispatch('api/getBindUserDeviceId').then(res => {
this.deviceList = res;
});
}, },
mkHourMin(min){ mkHourMin(min){

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -165,26 +165,8 @@
</script> </script>
<!-- 讯飞语音识别 --> <!-- 讯飞语音识别 -->
<script> <script>
window.onload = function () { window.onload = function () {
var demoData = {
bloodGlucose: "血糖",
SleepDatas: "睡眠",
bloodOxygen: "血氧",
bloodPressure: '血压',
meiTuo: '梅脱',
pulseReat: '心率',
bodyTemperature: '体温',
ECGData: '心电图',
bloodLiquid: '血液',
bloodLiquid: '血脂',
bloodLiquid: '尿酸',
bodyData: '身体成分',
stepIndex: '运动',
stepIndex: '步数',
stepIndex: '运动步数',
};
var videoElement = document.getElementById('myVideo'); var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位) var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位) var endTime = 10; // 结束时间(以秒为单位)
@ -274,7 +256,8 @@
let exampleData = JSON.parse(getURLParameter('data')); let exampleData = JSON.parse(getURLParameter('data'));
for (let i = 0; i < exampleData.length; i++) { for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type] exampleData[i].name = demoData[exampleData[i].type]
} };
// 过滤掉非对象类型的值 // 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object'); const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -282,8 +265,7 @@
const arrayOfObjects = filteredData.map(([key, value]) => ({ const arrayOfObjects = filteredData.map(([key, value]) => ({
type: key, type: key,
...value ...value
})); }));
/* /*
* 实例化迅飞语音听写流式版WebAPI * 实例化迅飞语音听写流式版WebAPI
@ -312,15 +294,12 @@
const params = { msg: text }; const params = { msg: text };
// 判断关键字是否存在 // 判断关键字是否存在
console.log('判断')
const result = parseHealthQuery(params.msg); const result = parseHealthQuery(params.msg);
isCallbackExecuted = true; isCallbackExecuted = true;
console.log(result, '判断关键字是否存在')
if (result) { if (result) {
console.log(result.dataKey, result.date, '参数++++++++++++++++++++++++++++++++++++++++')
DetailDay(result.dataKey, result.date).then(res => { DetailDay(result.dataKey, result.date).then(res => {
let TargetData = res.data.data; let TargetData = res.data.data;
var QSindex = containsKeywordRegex(params.msg); var QSindex = containsKeywordRegex(params.msg);
if (result.dataKey == 'ECGData') { if (result.dataKey == 'ECGData') {
@ -388,38 +367,10 @@
</voice> </voice>
</speak> `, </speak> `,
}).then(async(response) => { }).then(async(response) => {
const content_bytes = await response.arrayBuffer();
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
startRec.style.display = "none"; startRec.style.display = "none";
endRec.style.display = "block"; endRec.style.display = "block";
// 字幕文字 NextPlayVideo(response, filterString(str.output.text, ['*', ' ']));
voiceTxt.innerText = filterString(str.output.text, ['*', ' ']);
marquee("marquee", "voice-txt");
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -469,38 +420,10 @@
</voice> </voice>
</speak> `, </speak> `,
}).then(async(response) => { }).then(async(response) => {
const content_bytes = await response.arrayBuffer();
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
startRec.style.display = "none"; startRec.style.display = "none";
endRec.style.display = "block"; endRec.style.display = "block";
// 字幕文字 NextPlayVideo(response, filterString(str.output.text, ['*', ' ']));
voiceTxt.innerText = filterString(str.output.text, ['*', ' ']);
marquee("marquee", "voice-txt");
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -578,8 +501,8 @@
} }
// 查询详情数据 // 查询详情数据
async function DetailDay(type, data) { async function DetailDay(type, data) {
try { try {
// const response = await fetch('https://test.sc2.agrimedia.cn/watch/device/getDeviceListDays', { // const response = await fetch('https://test.sc2.agrimedia.cn/watch/device/getDeviceListDays', {
const response = await fetch('https://ai.agrimedia.cn/watch/device/getDeviceListDays', { const response = await fetch('https://ai.agrimedia.cn/watch/device/getDeviceListDays', {
method: 'POST', method: 'POST',
@ -596,19 +519,20 @@
if (!response.ok) { if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText); throw new Error('Network response was not ok: ' + response.statusText);
} }
const result = await response.json(); const result = await response.json();
return result; return result;
} catch (error) { } catch (error) {
console.error('There was a problem with your fetch operation:', error); console.error('There was a problem with your fetch operation:', error);
throw error; // 可选:重新抛出错误以便上层可以捕获并处理 throw error; // 可选:重新抛出错误以便上层可以捕获并处理
} }
} }
// 语音输出 // 语音输出
function speed(str) { function speed(str) {
console.log(str)
fetch("https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1", { fetch("https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1", {
method: 'POST', method: 'POST',
headers: { headers: {
@ -628,39 +552,46 @@
</voice> </voice>
</speak> `, </speak> `,
}).then(async(response) => { }).then(async(response) => {
const content_bytes = await response.arrayBuffer(); NextPlayVideo(response, str);
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
// 字幕文字
voiceTxt.innerText = str;
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
} }
// 字幕播放视频等操作
async function NextPlayVideo(response, str) {
const content_bytes = await response.arrayBuffer();
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
// 字幕文字
voiceTxt.innerText = str;
marquee("marquee", "voice-txt");
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}
// 防抖 // 防抖
function throttle(fn, wait) { function throttle(fn, wait) {
let lastTime = 0; // 上一次调用的时间 let lastTime = 0; // 上一次调用的时间
@ -690,6 +621,7 @@
} }
} }
// 拿到的数据移除*
function filterString(str, charsToRemove) { function filterString(str, charsToRemove) {
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类character class来构建的 // 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类character class来构建的
// 例如如果charsToRemove是['*', ' '],则正则表达式将是/[* ]/g // 例如如果charsToRemove是['*', ' '],则正则表达式将是/[* ]/g
@ -705,7 +637,6 @@
} }
} }
// 解析文字 // 解析文字
function parseHealthQuery(query, demoData) { function parseHealthQuery(query, demoData) {
if (!demoData) { if (!demoData) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -165,26 +165,8 @@
</script> </script>
<!-- 讯飞语音识别 --> <!-- 讯飞语音识别 -->
<script> <script>
window.onload = function () { window.onload = function () {
var demoData = {
bloodGlucose: "血糖",
SleepDatas: "睡眠",
bloodOxygen: "血氧",
bloodPressure: '血压',
meiTuo: '梅脱',
pulseReat: '心率',
bodyTemperature: '体温',
ECGData: '心电图',
bloodLiquid: '血液',
bloodLiquid: '血脂',
bloodLiquid: '尿酸',
bodyData: '身体成分',
stepIndex: '运动',
stepIndex: '步数',
stepIndex: '运动步数',
};
var videoElement = document.getElementById('myVideo'); var videoElement = document.getElementById('myVideo');
var startTime = 5; // 开始时间(以秒为单位) var startTime = 5; // 开始时间(以秒为单位)
var endTime = 10; // 结束时间(以秒为单位) var endTime = 10; // 结束时间(以秒为单位)
@ -274,7 +256,8 @@
let exampleData = JSON.parse(getURLParameter('data')); let exampleData = JSON.parse(getURLParameter('data'));
for (let i = 0; i < exampleData.length; i++) { for (let i = 0; i < exampleData.length; i++) {
exampleData[i].name = demoData[exampleData[i].type] exampleData[i].name = demoData[exampleData[i].type]
} };
// 过滤掉非对象类型的值 // 过滤掉非对象类型的值
const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object'); const filteredData = Object.entries(exampleData).filter(([key, value]) => typeof value === 'object');
@ -282,8 +265,7 @@
const arrayOfObjects = filteredData.map(([key, value]) => ({ const arrayOfObjects = filteredData.map(([key, value]) => ({
type: key, type: key,
...value ...value
})); }));
/* /*
* 实例化迅飞语音听写流式版WebAPI * 实例化迅飞语音听写流式版WebAPI
@ -312,15 +294,12 @@
const params = { msg: text }; const params = { msg: text };
// 判断关键字是否存在 // 判断关键字是否存在
console.log('判断')
const result = parseHealthQuery(params.msg); const result = parseHealthQuery(params.msg);
isCallbackExecuted = true; isCallbackExecuted = true;
console.log(result, '判断关键字是否存在')
if (result) { if (result) {
console.log(result.dataKey, result.date, '参数++++++++++++++++++++++++++++++++++++++++')
DetailDay(result.dataKey, result.date).then(res => { DetailDay(result.dataKey, result.date).then(res => {
let TargetData = res.data.data; let TargetData = res.data.data;
var QSindex = containsKeywordRegex(params.msg); var QSindex = containsKeywordRegex(params.msg);
if (result.dataKey == 'ECGData') { if (result.dataKey == 'ECGData') {
@ -388,38 +367,10 @@
</voice> </voice>
</speak> `, </speak> `,
}).then(async(response) => { }).then(async(response) => {
const content_bytes = await response.arrayBuffer();
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
startRec.style.display = "none"; startRec.style.display = "none";
endRec.style.display = "block"; endRec.style.display = "block";
// 字幕文字 NextPlayVideo(response, filterString(str.output.text, ['*', ' ']));
voiceTxt.innerText = filterString(str.output.text, ['*', ' ']);
marquee("marquee", "voice-txt");
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -469,38 +420,10 @@
</voice> </voice>
</speak> `, </speak> `,
}).then(async(response) => { }).then(async(response) => {
const content_bytes = await response.arrayBuffer();
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
startRec.style.display = "none"; startRec.style.display = "none";
endRec.style.display = "block"; endRec.style.display = "block";
// 字幕文字 NextPlayVideo(response, filterString(str.output.text, ['*', ' ']));
voiceTxt.innerText = filterString(str.output.text, ['*', ' ']);
marquee("marquee", "voice-txt");
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
@ -578,8 +501,8 @@
} }
// 查询详情数据 // 查询详情数据
async function DetailDay(type, data) { async function DetailDay(type, data) {
try { try {
// const response = await fetch('https://test.sc2.agrimedia.cn/watch/device/getDeviceListDays', { // const response = await fetch('https://test.sc2.agrimedia.cn/watch/device/getDeviceListDays', {
const response = await fetch('https://ai.agrimedia.cn/watch/device/getDeviceListDays', { const response = await fetch('https://ai.agrimedia.cn/watch/device/getDeviceListDays', {
method: 'POST', method: 'POST',
@ -596,19 +519,20 @@
if (!response.ok) { if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText); throw new Error('Network response was not ok: ' + response.statusText);
} }
const result = await response.json(); const result = await response.json();
return result; return result;
} catch (error) { } catch (error) {
console.error('There was a problem with your fetch operation:', error); console.error('There was a problem with your fetch operation:', error);
throw error; // 可选:重新抛出错误以便上层可以捕获并处理 throw error; // 可选:重新抛出错误以便上层可以捕获并处理
} }
} }
// 语音输出 // 语音输出
function speed(str) { function speed(str) {
console.log(str)
fetch("https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1", { fetch("https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1", {
method: 'POST', method: 'POST',
headers: { headers: {
@ -628,39 +552,46 @@
</voice> </voice>
</speak> `, </speak> `,
}).then(async(response) => { }).then(async(response) => {
const content_bytes = await response.arrayBuffer(); NextPlayVideo(response, str);
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
// 字幕文字
voiceTxt.innerText = str;
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}).catch(e => { }).catch(e => {
hideModal(); hideModal();
}); });
} }
// 字幕播放视频等操作
async function NextPlayVideo(response, str) {
const content_bytes = await response.arrayBuffer();
const blob = new Blob([content_bytes], { type: 'audio/mp3' });
const blobUrl = URL.createObjectURL(blob);
// 字幕文字
voiceTxt.innerText = str;
marquee("marquee", "voice-txt");
// 设置音频源
audioElement.src = blobUrl;
// 播放音频
audioElement.play();
// 循环视频
replayVideoSegment(60, 120);
// 监听播放技术
myAudio.addEventListener('ended', function() {
console.log('音频播放已结束!');
// 停止倒计时
startRec.style.display = 'block';
endRec.style.display = 'none';
statusTxt.value = '';
voiceTxt.innerText = '';
voice.stop();
replayVideoSegment(0, 60);
hideModal()
});
}
// 防抖 // 防抖
function throttle(fn, wait) { function throttle(fn, wait) {
let lastTime = 0; // 上一次调用的时间 let lastTime = 0; // 上一次调用的时间
@ -690,6 +621,7 @@
} }
} }
// 拿到的数据移除*
function filterString(str, charsToRemove) { function filterString(str, charsToRemove) {
// 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类character class来构建的 // 这里的正则表达式是通过将charsToRemove数组中的字符转换为字符类character class来构建的
// 例如如果charsToRemove是['*', ' '],则正则表达式将是/[* ]/g // 例如如果charsToRemove是['*', ' '],则正则表达式将是/[* ]/g
@ -705,7 +637,6 @@
} }
} }
// 解析文字 // 解析文字
function parseHealthQuery(query, demoData) { function parseHealthQuery(query, demoData) {
if (!demoData) { if (!demoData) {