对接pc-c6pro,加mac地址过滤
This commit is contained in:
parent
606aff2b23
commit
b94025cef6
|
|
@ -5,7 +5,7 @@
|
||||||
<image src="/static/zhong.png"></image>
|
<image src="/static/zhong.png"></image>
|
||||||
<text @click="openBluetoothAdapter">{{bletipstext}}</text>
|
<text @click="openBluetoothAdapter">{{bletipstext}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="duan" @click="handleBack" v-if="isShow&&isConnection == 0">
|
<view class="duan" @click="handleBack" v-if="isShow&&isConnection == 2">
|
||||||
{{$t('Disconnect')}}
|
{{$t('Disconnect')}}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -66,7 +66,17 @@
|
||||||
name: this.$t("oz"),
|
name: this.$t("oz"),
|
||||||
id: "08",
|
id: "08",
|
||||||
unit: "oz"
|
unit: "oz"
|
||||||
}],
|
},
|
||||||
|
{
|
||||||
|
name: this.$t("lb"),
|
||||||
|
id: "03",
|
||||||
|
unit: "lb"
|
||||||
|
}, {
|
||||||
|
name: this.$t("ml"),
|
||||||
|
id: "05",
|
||||||
|
unit: "ml"
|
||||||
|
}
|
||||||
|
],
|
||||||
unitListIndex: 0,
|
unitListIndex: 0,
|
||||||
units: ['kg', 'g', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
|
units: ['kg', 'g', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
|
||||||
'milkml', 'oz', 'floz', 'lboz'
|
'milkml', 'oz', 'floz', 'lboz'
|
||||||
|
|
@ -87,10 +97,9 @@
|
||||||
...mapState(["bleValue", "isBluetoothTyle", "countFoodInfo"]),
|
...mapState(["bleValue", "isBluetoothTyle", "countFoodInfo"]),
|
||||||
weight() {
|
weight() {
|
||||||
let that = this
|
let that = this
|
||||||
let info = that.bleValue
|
let kcal = (Number(that.weightKcal) / 100 * that.bleValue.countWeight).toFixed(2)
|
||||||
let kcal = (Number(that.weightKcal) / 100 * info.countWeight).toFixed(2)
|
that.unit = that.bleValue.unit
|
||||||
that.unit = info.unit
|
that.kcal = that.convertToGrams(kcal, that.bleValue.unit).toFixed(2)
|
||||||
that.kcal = that.convertToGrams(kcal, info.unit).toFixed(2)
|
|
||||||
return this.bleValue.countWeight
|
return this.bleValue.countWeight
|
||||||
},
|
},
|
||||||
isConnection() {
|
isConnection() {
|
||||||
|
|
@ -135,6 +144,7 @@
|
||||||
notify: '',
|
notify: '',
|
||||||
write: '',
|
write: '',
|
||||||
unit: "g",
|
unit: "g",
|
||||||
|
type: 1,
|
||||||
countWeight: "",
|
countWeight: "",
|
||||||
bleTipsText: that.$t('SearchBluetooth'),
|
bleTipsText: that.$t('SearchBluetooth'),
|
||||||
isConnectStatus: 0,
|
isConnectStatus: 0,
|
||||||
|
|
@ -146,12 +156,39 @@
|
||||||
let that = this
|
let that = this
|
||||||
let unit = that.unitList[e.detail.value].unit
|
let unit = that.unitList[e.detail.value].unit
|
||||||
if (that.isShow && that.unit != unit) {
|
if (that.isShow && that.unit != unit) {
|
||||||
that.handletoggleUnit(unit == "oz" ? 0x08 : 0x04)
|
that.handletoggleUnit(that.unitConversion2(unit))
|
||||||
}
|
}
|
||||||
that.unitListIndex = [e.detail.value]
|
that.unitListIndex = [e.detail.value]
|
||||||
that.$store.commit('changeBluetoothValue', {
|
that.$store.commit('changeBluetoothValue', {
|
||||||
unit: that.unitList[e.detail.value].unit
|
unit: unit
|
||||||
})
|
})
|
||||||
|
console.log("单位切换", unit, that.unit, that.unitListIndex)
|
||||||
|
},
|
||||||
|
unitConversion2(unit) {
|
||||||
|
if (unit == 'kg') {
|
||||||
|
return 0x00
|
||||||
|
} else if (unit == '斤') {
|
||||||
|
return 0x01
|
||||||
|
} else if (unit == 'st:lb') {
|
||||||
|
return 0x02
|
||||||
|
} else if (unit == 'lb') {
|
||||||
|
return 0x03
|
||||||
|
} else if (unit == 'g') {
|
||||||
|
return 0x04
|
||||||
|
} else if (unit == 'ml') {
|
||||||
|
return 0x05
|
||||||
|
} else if (unit == 'Waterml') {
|
||||||
|
return 0x06
|
||||||
|
} else if (unit == 'milkml') {
|
||||||
|
return 0x07
|
||||||
|
} else if (unit == 'oz') {
|
||||||
|
return 0x08
|
||||||
|
} else if (unit == 'floz') {
|
||||||
|
return 0x09
|
||||||
|
} else if (unit == 'lboz') {
|
||||||
|
return 0x0A
|
||||||
|
}
|
||||||
|
return unit
|
||||||
},
|
},
|
||||||
handletoggleUnit(unit) {
|
handletoggleUnit(unit) {
|
||||||
let that = this
|
let that = this
|
||||||
|
|
@ -212,7 +249,8 @@
|
||||||
'lb': 453.59237, // 1磅 = 453.59237克
|
'lb': 453.59237, // 1磅 = 453.59237克
|
||||||
'oz': 28.349523125, // 1盎司 = 28.349523125克
|
'oz': 28.349523125, // 1盎司 = 28.349523125克
|
||||||
'kg': 1000, // 1公斤 = 1000克
|
'kg': 1000, // 1公斤 = 1000克
|
||||||
'g': 1
|
'g': 1,
|
||||||
|
'ml': 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
||||||
|
|
@ -223,14 +261,16 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
unitConversion(unit) {
|
unitConversion(unit) {
|
||||||
if (unit == 'kcal') {
|
if (unit == 'kg') {
|
||||||
return '千卡'
|
return this.$t("kg")
|
||||||
} else if (unit == 'g') {
|
} else if (unit == 'g') {
|
||||||
return this.$t("g")
|
return this.$t("g")
|
||||||
} else if (unit == 'lb') {
|
} else if (unit == 'lb') {
|
||||||
return '磅'
|
return this.$t("lb")
|
||||||
} else if (unit == 'oz') {
|
} else if (unit == 'oz') {
|
||||||
return this.$t("oz")
|
return this.$t("oz")
|
||||||
|
} else if (unit == 'ml') {
|
||||||
|
return this.$t("ml")
|
||||||
}
|
}
|
||||||
return unit
|
return unit
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,17 @@
|
||||||
"WhetherTodelete": "هل حذف",
|
"WhetherTodelete": "هل حذف",
|
||||||
"BusinessCooperation": "التعاون التجاري",
|
"BusinessCooperation": "التعاون التجاري",
|
||||||
"verifyActivityCoefficient": "يرجى تحديد معامل النشاط",
|
"verifyActivityCoefficient": "يرجى تحديد معامل النشاط",
|
||||||
|
"devicesTips":"لم يتم تسجيل الجهاز، يرجى التواصل مع البائع لإجراء التحقق من النظام",
|
||||||
|
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,16 @@
|
||||||
"WhetherTodelete": "Ist sie gelöscht",
|
"WhetherTodelete": "Ist sie gelöscht",
|
||||||
"BusinessCooperation": "Kooperation seitens der händler",
|
"BusinessCooperation": "Kooperation seitens der händler",
|
||||||
"verifyActivityCoefficient": "Bitte wählen sie die multiplikatoren",
|
"verifyActivityCoefficient": "Bitte wählen sie die multiplikatoren",
|
||||||
|
"devicesTips":"Gerät nicht registriert. Bitte wenden Sie sich an den Verkäufer zur Systemzertifizierung.",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +146,16 @@
|
||||||
"WhetherTodelete": "Whether to delete",
|
"WhetherTodelete": "Whether to delete",
|
||||||
"BusinessCooperation": "Businesscooperation",
|
"BusinessCooperation": "Businesscooperation",
|
||||||
"verifyActivityCoefficient": "Please select the activity coefficient",
|
"verifyActivityCoefficient": "Please select the activity coefficient",
|
||||||
|
"devicesTips":"The equipment has not been registered. Please contact the seller for system certification.",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +148,16 @@
|
||||||
"WhetherTodelete": "Eliminar sí no",
|
"WhetherTodelete": "Eliminar sí no",
|
||||||
"BusinessCooperation": "Cooperación empresarial",
|
"BusinessCooperation": "Cooperación empresarial",
|
||||||
"verifyActivityCoefficient": "Por favor seleccione el coeficiente de actividad",
|
"verifyActivityCoefficient": "Por favor seleccione el coeficiente de actividad",
|
||||||
|
"devicesTips":"El equipo no está registrado. Por favor, contacte al vendedor para realizar la autenticación del sistema.",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -147,6 +147,15 @@
|
||||||
"WhetherTodelete": "supprimer ou non ",
|
"WhetherTodelete": "supprimer ou non ",
|
||||||
"BusinessCooperation": "coopération commerciale ",
|
"BusinessCooperation": "coopération commerciale ",
|
||||||
"verifyActivityCoefficient ": "veuillez sélectionner des coefficients d’activité.",
|
"verifyActivityCoefficient ": "veuillez sélectionner des coefficients d’activité.",
|
||||||
|
"devicesTips":"L'équipement n'est pas enregistré. Veuillez contacter le vendeur pour une authentification du système.",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,16 @@
|
||||||
"WhetherTodelete": "削除しますか",
|
"WhetherTodelete": "削除しますか",
|
||||||
"BusinessCooperation": "ビジネス提携です",
|
"BusinessCooperation": "ビジネス提携です",
|
||||||
"verifyActivityCoefficient": "活動係数を選択します",
|
"verifyActivityCoefficient": "活動係数を選択します",
|
||||||
|
"devicesTips":"機器は登録されていません。販売者に連絡してシステム認証を行ってください。",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +146,16 @@
|
||||||
"WhetherTodelete": "삭제할지 여부",
|
"WhetherTodelete": "삭제할지 여부",
|
||||||
"BusinessCooperation": "상무 합작",
|
"BusinessCooperation": "상무 합작",
|
||||||
"verifyActivityCoefficient": "활동지수를 선택하십시오",
|
"verifyActivityCoefficient": "활동지수를 선택하십시오",
|
||||||
|
"devicesTips":"장비 등록이 되지 않았습니다. 판매자에게 연락하여 시스템 인증을 진행해 주세요.",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,16 @@
|
||||||
"WhetherTodelete": "Apagar sim não",
|
"WhetherTodelete": "Apagar sim não",
|
||||||
"BusinessCooperation": "Cooperação de negócios",
|
"BusinessCooperation": "Cooperação de negócios",
|
||||||
"verifyActivityCoefficient": "Por favor, selecione o coeficiente de atividade",
|
"verifyActivityCoefficient": "Por favor, selecione o coeficiente de atividade",
|
||||||
|
"devicesTips":"O equipamento não foi registrado. Por favor, entre em contato com o vendedor para realizar a autenticação no sistema.",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +146,16 @@
|
||||||
"WhetherTodelete": "Удалить",
|
"WhetherTodelete": "Удалить",
|
||||||
"BusinessCooperation": "Деловое сотрудничество.",
|
"BusinessCooperation": "Деловое сотрудничество.",
|
||||||
"verifyActivityCoefficient": "Пожалуйста, выберите коэффициент активности",
|
"verifyActivityCoefficient": "Пожалуйста, выберите коэффициент активности",
|
||||||
|
"devicesTips":"Устройство не зарегистрировано, пожалуйста, свяжитесь с продавцом для системной аутентификации",
|
||||||
|
"kg": "kg",
|
||||||
"g": "g",
|
"g": "g",
|
||||||
"oz": "oz"
|
"oz": "oz",
|
||||||
|
"ml": "ml",
|
||||||
|
"lb": "lb",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -145,6 +145,15 @@
|
||||||
"WhetherTodelete": "是否删除",
|
"WhetherTodelete": "是否删除",
|
||||||
"BusinessCooperation": "商务合作",
|
"BusinessCooperation": "商务合作",
|
||||||
"verifyActivityCoefficient": "请选择活动系数",
|
"verifyActivityCoefficient": "请选择活动系数",
|
||||||
|
"devicesTips":"设备未登记,请联系出售方进行系统认证",
|
||||||
|
"kg": "千克",
|
||||||
"g": "克",
|
"g": "克",
|
||||||
"oz": "盎司"
|
"oz": "盎司",
|
||||||
|
"ml": "毫升",
|
||||||
|
"lb": "磅",
|
||||||
|
"milkml": "milkml",
|
||||||
|
"Waterml": "Waterml",
|
||||||
|
"floz": "floz",
|
||||||
|
"lboz": "lboz",
|
||||||
|
"st": "st:lb"
|
||||||
}
|
}
|
||||||
|
|
@ -302,6 +302,9 @@
|
||||||
bleValue: {
|
bleValue: {
|
||||||
handler(newVal, oldVal) {
|
handler(newVal, oldVal) {
|
||||||
this.realTimeWeight(newVal.countWeight, newVal.unit)
|
this.realTimeWeight(newVal.countWeight, newVal.unit)
|
||||||
|
if (newVal.type == 2 && Number(newVal.countWeight) > 0) {
|
||||||
|
this.handletoggleUnit(newVal.countWeight, newVal.unit, this.activeType.nutrients_four)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
}
|
}
|
||||||
|
|
@ -365,16 +368,21 @@
|
||||||
},
|
},
|
||||||
//实时重量
|
//实时重量
|
||||||
realTimeWeight(weight, unit) {
|
realTimeWeight(weight, unit) {
|
||||||
// console.log("实时重量", weight, unit)
|
|
||||||
this.activeType = Object.assign({}, this.activeType, {
|
this.activeType = Object.assign({}, this.activeType, {
|
||||||
weight: this.convertToGrams(weight, unit)
|
weight: this.convertToGrams(weight, unit)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
unitConversion(unit) {
|
unitConversion(unit) {
|
||||||
if (unit == 'kcal') {
|
if (unit == 'kg') {
|
||||||
return '千卡'
|
return this.$t("kg")
|
||||||
} else if (unit == 'g') {
|
} else if (unit == 'g') {
|
||||||
return '克'
|
return this.$t("g")
|
||||||
|
} else if (unit == 'lb') {
|
||||||
|
return this.$t("lb")
|
||||||
|
} else if (unit == 'oz') {
|
||||||
|
return this.$t("oz")
|
||||||
|
} else if (unit == 'ml') {
|
||||||
|
return this.$t("ml")
|
||||||
}
|
}
|
||||||
return unit
|
return unit
|
||||||
},
|
},
|
||||||
|
|
@ -383,7 +391,8 @@
|
||||||
'lb': 453.59, // 1磅 = 453.59237克
|
'lb': 453.59, // 1磅 = 453.59237克
|
||||||
'oz': 28.35, // 1盎司 = 28.349523125克
|
'oz': 28.35, // 1盎司 = 28.349523125克
|
||||||
'kg': 1000, // 1公斤 = 1000克
|
'kg': 1000, // 1公斤 = 1000克
|
||||||
'g': 1
|
'g': 1,
|
||||||
|
'ml': 1
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
||||||
|
|
@ -403,14 +412,113 @@
|
||||||
that.weightKcal = Number(ite.kcal)
|
that.weightKcal = Number(ite.kcal)
|
||||||
if (that.bleValue.serviceId != "") {
|
if (that.bleValue.serviceId != "") {
|
||||||
that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit)
|
that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit)
|
||||||
|
if (that.bleValue.type == 2 && Number(that.bleValue.countWeight) > 0) {
|
||||||
|
that.handletoggleUnit(that.bleValue.countWeight, that.bleValue.unit, ite.nutrients_four)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
that.$store.commit("changeBluetoothValue", {
|
that.$store.commit("changeBluetoothValue", {
|
||||||
countWeight: 100,
|
countWeight: 100,
|
||||||
unit: "g"
|
unit: that.bleValue.unit
|
||||||
})
|
})
|
||||||
that.realTimeWeight(100, "g")
|
that.realTimeWeight(100, that.bleValue.unit)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 下发营养含量
|
||||||
|
handletoggleUnit(val, unit, ite) {
|
||||||
|
let that = this
|
||||||
|
let weight = Number(that.convertToGrams(val, unit)) / 100
|
||||||
|
const dataArray = that.buildNutritionData({
|
||||||
|
fat: weight * ite[2].value,
|
||||||
|
calorie: weight * ite[0].value,
|
||||||
|
carbohydrate: weight * ite[3].value,
|
||||||
|
protein: weight * ite[1].value,
|
||||||
|
fiber: 0
|
||||||
|
});
|
||||||
|
const arrayBuffer = new ArrayBuffer(dataArray.length);
|
||||||
|
const uint8Array = new Uint8Array(arrayBuffer);
|
||||||
|
dataArray.forEach((value, index) => {
|
||||||
|
uint8Array[index] = value;
|
||||||
|
});
|
||||||
|
console.log("arrayBuffer", arrayBuffer)
|
||||||
|
that.sendArrayBuffer(arrayBuffer);
|
||||||
|
},
|
||||||
|
// 构建营养成分数据包
|
||||||
|
buildNutritionData(data) {
|
||||||
|
// 头信息
|
||||||
|
const header = 0xC5; // 同步头
|
||||||
|
const dataLength = 0x11; // 数据长度:17字节
|
||||||
|
const cmd = 0x04; // CMD字节
|
||||||
|
const packetInfo = 0x41; // 包信息:总1包,第1包
|
||||||
|
|
||||||
|
// 转换营养成分值(×10并取整)
|
||||||
|
const fatValue = Math.round(data.fat * 10);
|
||||||
|
const calorieValue = Math.round(data.calorie * 10);
|
||||||
|
const carbValue = Math.round(data.carbohydrate * 10);
|
||||||
|
const fiberValue = Math.round(data.fiber * 10);
|
||||||
|
const proteinValue = Math.round(data.protein * 10);
|
||||||
|
|
||||||
|
// 构建数据数组
|
||||||
|
const dataArray = [];
|
||||||
|
|
||||||
|
// 添加头部
|
||||||
|
dataArray.push(header); // 0xC5
|
||||||
|
dataArray.push(dataLength); // 0x11
|
||||||
|
dataArray.push(cmd); // 0x04
|
||||||
|
dataArray.push(packetInfo); // 0x41
|
||||||
|
|
||||||
|
// 添加脂肪数据(大端序,3字节)
|
||||||
|
dataArray.push((fatValue >> 16) & 0xFF); // 高位字节
|
||||||
|
dataArray.push((fatValue >> 8) & 0xFF); // 中位字节
|
||||||
|
dataArray.push(fatValue & 0xFF); // 低位字节
|
||||||
|
|
||||||
|
// 添加卡路里数据(大端序,3字节)
|
||||||
|
dataArray.push((calorieValue >> 16) & 0xFF);
|
||||||
|
dataArray.push((calorieValue >> 8) & 0xFF);
|
||||||
|
dataArray.push(calorieValue & 0xFF);
|
||||||
|
|
||||||
|
// 添加碳水化合物数据(大端序,3字节)
|
||||||
|
dataArray.push((carbValue >> 16) & 0xFF);
|
||||||
|
dataArray.push((carbValue >> 8) & 0xFF);
|
||||||
|
dataArray.push(carbValue & 0xFF);
|
||||||
|
|
||||||
|
// 添加膳食纤维数据(大端序,3字节)
|
||||||
|
dataArray.push((fiberValue >> 16) & 0xFF);
|
||||||
|
dataArray.push((fiberValue >> 8) & 0xFF);
|
||||||
|
dataArray.push(fiberValue & 0xFF);
|
||||||
|
|
||||||
|
// 添加蛋白质数据(大端序,3字节)
|
||||||
|
dataArray.push((proteinValue >> 16) & 0xFF);
|
||||||
|
dataArray.push((proteinValue >> 8) & 0xFF);
|
||||||
|
dataArray.push(proteinValue & 0xFF);
|
||||||
|
|
||||||
|
// 计算校验和(除同步头外的所有字节的和,取低8位)
|
||||||
|
let checksum = 0;
|
||||||
|
for (let i = 1; i < dataArray.length; i++) {
|
||||||
|
checksum = (checksum + dataArray[i]) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加校验和
|
||||||
|
dataArray.push(checksum);
|
||||||
|
console.log('构建的数据包:', dataArray);
|
||||||
|
console.log('十六进制:', dataArray.map(b => b.toString(16).padStart(2, '0')).join(' '));
|
||||||
|
|
||||||
|
return dataArray;
|
||||||
|
},
|
||||||
|
sendArrayBuffer(buffer) {
|
||||||
|
let that = this
|
||||||
|
uni.writeBLECharacteristicValue({
|
||||||
|
deviceId: that.bleValue.deviceId,
|
||||||
|
serviceId: that.bleValue.serviceId,
|
||||||
|
characteristicId: that.bleValue.write,
|
||||||
|
value: buffer,
|
||||||
|
success: res => {
|
||||||
|
console.log('下发指令成功', res.errMsg)
|
||||||
|
},
|
||||||
|
fail: res => {
|
||||||
|
console.log("下发指令失败", res);
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
//测量返回
|
//测量返回
|
||||||
handleBle(weight, unit, kcal) {
|
handleBle(weight, unit, kcal) {
|
||||||
let that = this
|
let that = this
|
||||||
|
|
@ -1290,6 +1398,9 @@
|
||||||
|
|
||||||
text {
|
text {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -443,7 +443,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
width: 50%;
|
width: 65%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,11 @@ export default new Vuex.Store({
|
||||||
notify: "",
|
notify: "",
|
||||||
write: "",
|
write: "",
|
||||||
unit: "g",
|
unit: "g",
|
||||||
|
type: 1,
|
||||||
oldCountWeight: 0,
|
oldCountWeight: 0,
|
||||||
countWeight: 100,
|
countWeight: 100,
|
||||||
bleTipsText: "",
|
bleTipsText: "",
|
||||||
isConnectStatus: null,
|
isConnectStatus: 0,
|
||||||
},
|
},
|
||||||
isBluetoothTyle: false,
|
isBluetoothTyle: false,
|
||||||
setLocale: "zh"
|
setLocale: "zh"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
import $store from '@/store'
|
import $store from '@/store'
|
||||||
|
import $model from '@/tools/model.js'
|
||||||
|
import $tools from '@/tools/tools.js'
|
||||||
import messages from '@/language/index.js'
|
import messages from '@/language/index.js'
|
||||||
let searchTimer = null
|
let searchTimer = null
|
||||||
let devicesList = []
|
let devicesList = []
|
||||||
|
|
@ -58,28 +60,56 @@ function onBluetoothDeviceFound() {
|
||||||
uni.onBluetoothDeviceFound(res => {
|
uni.onBluetoothDeviceFound(res => {
|
||||||
res.devices.forEach(device => {
|
res.devices.forEach(device => {
|
||||||
console.log("name", device.name)
|
console.log("name", device.name)
|
||||||
if (device.name.indexOf('PC-C02Pro') != -1 || (device.localName && device.localName.indexOf(
|
if (device.name.toLowerCase().indexOf('pc-c06pro') != -1 ||
|
||||||
'PC-C02Pro') != -1)) {
|
device.name.toLowerCase().indexOf('pc-c02pro') != -1 ||
|
||||||
|
device.name.toLowerCase().indexOf('pc-c09pro') != -1 ||
|
||||||
|
(device.localName && device.localName.toLowerCase().indexOf('pc-c06pro') != -1) ||
|
||||||
|
(device.localName && device.localName.toLowerCase().indexOf('pc-c02pro') != -1) ||
|
||||||
|
(device.localName && device.localName.toLowerCase().indexOf('pc-c09pro') != -1)) {
|
||||||
clearTimeout(searchTimer);
|
clearTimeout(searchTimer);
|
||||||
|
const bytes = new Uint8Array(device.advertisData);
|
||||||
|
const macBytes = bytes.slice(6, 12);
|
||||||
|
device.macAddr = $tools.ab2hex(macBytes, ':').toUpperCase()
|
||||||
stopBluetoothDevicesDiscovery()
|
stopBluetoothDevicesDiscovery()
|
||||||
Bluetoothfilter(device.deviceId)
|
Bluetoothfilter(device)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 过滤蓝牙
|
// 过滤蓝牙
|
||||||
function Bluetoothfilter(device_id) {
|
function Bluetoothfilter(device) {
|
||||||
const foundDevices = devicesList
|
const foundDevices = devicesList
|
||||||
const idx = inArray(foundDevices, "deviceId", device_id)
|
const idx = inArray(foundDevices, "deviceId", device.deviceId)
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
devicesList.push(device_id);
|
devicesList.push(device);
|
||||||
connectDevice(device_id)
|
handleDevType(device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 排查设备
|
||||||
|
function handleDevType(device) {
|
||||||
|
let $t = messages[Language]
|
||||||
|
$model.getCheckDevice({
|
||||||
|
mac: device.macAddr,
|
||||||
|
}).then(res => {
|
||||||
|
console.log("排查设备:", device, res)
|
||||||
|
if (res.code == 0) {
|
||||||
|
connectDevice(device.deviceId)
|
||||||
|
} else {
|
||||||
|
devicesList = []
|
||||||
|
$tools.msg($t.devicesTips)
|
||||||
|
$store.commit("changeBluetoothValue", {
|
||||||
|
type: 1,
|
||||||
|
isConnectStatus: 1,
|
||||||
|
bleTipsText: $t.ConnectionTimeout,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//连接设备
|
//连接设备
|
||||||
function connectDevice(device_id) {
|
function connectDevice(device_id) {
|
||||||
|
let $t = messages[Language]
|
||||||
uni.createBLEConnection({
|
uni.createBLEConnection({
|
||||||
deviceId: device_id,
|
deviceId: device_id,
|
||||||
success: res => {
|
success: res => {
|
||||||
|
|
@ -88,6 +118,11 @@ function connectDevice(device_id) {
|
||||||
}, 200)
|
}, 200)
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
|
$store.commit("changeBluetoothValue", {
|
||||||
|
type: 1,
|
||||||
|
isConnectStatus: 1,
|
||||||
|
bleTipsText: $t.ConnectionTimeout,
|
||||||
|
})
|
||||||
console.log("连接失败,点击重新连接", res);
|
console.log("连接失败,点击重新连接", res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -97,6 +132,7 @@ function connectDevice(device_id) {
|
||||||
*/
|
*/
|
||||||
function getBLEDeviceServices(device_id) {
|
function getBLEDeviceServices(device_id) {
|
||||||
let serviceList = [];
|
let serviceList = [];
|
||||||
|
let $t = messages[Language]
|
||||||
uni.getBLEDeviceServices({
|
uni.getBLEDeviceServices({
|
||||||
deviceId: device_id,
|
deviceId: device_id,
|
||||||
success: res => {
|
success: res => {
|
||||||
|
|
@ -112,6 +148,11 @@ function getBLEDeviceServices(device_id) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
|
$store.commit("changeBluetoothValue", {
|
||||||
|
type: 1,
|
||||||
|
isConnectStatus: 1,
|
||||||
|
bleTipsText: $t.ConnectionTimeout,
|
||||||
|
})
|
||||||
console.log('获取设备的UUID失败:', res)
|
console.log('获取设备的UUID失败:', res)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -121,6 +162,7 @@ function getBLEDeviceServices(device_id) {
|
||||||
* 获取指定服务的特征值
|
* 获取指定服务的特征值
|
||||||
*/
|
*/
|
||||||
function getBLEDeviceCharacteristics(deviceId, serviceId) {
|
function getBLEDeviceCharacteristics(deviceId, serviceId) {
|
||||||
|
let $t = messages[Language]
|
||||||
let characteristicsList = [];
|
let characteristicsList = [];
|
||||||
uni.getBLEDeviceCharacteristics({
|
uni.getBLEDeviceCharacteristics({
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
|
|
@ -138,6 +180,11 @@ function getBLEDeviceCharacteristics(deviceId, serviceId) {
|
||||||
getBLECharacteristicValueChange(deviceId, serviceId, notify, write)
|
getBLECharacteristicValueChange(deviceId, serviceId, notify, write)
|
||||||
},
|
},
|
||||||
fail: res => {
|
fail: res => {
|
||||||
|
$store.commit("changeBluetoothValue", {
|
||||||
|
type: 1,
|
||||||
|
isConnectStatus: 1,
|
||||||
|
bleTipsText: $t.ConnectionTimeout,
|
||||||
|
})
|
||||||
console.log('获取特征值失败:', JSON.stringify(res))
|
console.log('获取特征值失败:', JSON.stringify(res))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -159,9 +206,10 @@ function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
|
||||||
notify: notify,
|
notify: notify,
|
||||||
write: write,
|
write: write,
|
||||||
unit: "g",
|
unit: "g",
|
||||||
|
type: 1,
|
||||||
countWeight: "",
|
countWeight: "",
|
||||||
bleTipsText: $t.Measuring,
|
bleTipsText: $t.Measuring,
|
||||||
isConnectStatus: 0
|
isConnectStatus: 2
|
||||||
})
|
})
|
||||||
const units = ['kg', 'g', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
|
const units = ['kg', 'g', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
|
||||||
'milkml', 'oz', 'floz', 'lboz'
|
'milkml', 'oz', 'floz', 'lboz'
|
||||||
|
|
@ -197,6 +245,7 @@ function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
|
||||||
$store.commit("changeBluetoothValue", {
|
$store.commit("changeBluetoothValue", {
|
||||||
countWeight: finalWeight,
|
countWeight: finalWeight,
|
||||||
unit: units[unitIndex],
|
unit: units[unitIndex],
|
||||||
|
type: statusType
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -250,6 +299,7 @@ function closeBluetoothAdapter() {
|
||||||
write: "",
|
write: "",
|
||||||
unit: "g",
|
unit: "g",
|
||||||
countWeight: '',
|
countWeight: '',
|
||||||
|
type: 1,
|
||||||
})
|
})
|
||||||
console.log('蓝牙模块关闭成功');
|
console.log('蓝牙模块关闭成功');
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +325,8 @@ function onBLEConnectionStateChange() {
|
||||||
if (!res.connected) {
|
if (!res.connected) {
|
||||||
$store.commit("changeBluetoothValue", {
|
$store.commit("changeBluetoothValue", {
|
||||||
bleTipsText: $t.ConnectionTimeout,
|
bleTipsText: $t.ConnectionTimeout,
|
||||||
isConnectStatus: 1
|
isConnectStatus: 1,
|
||||||
|
type: 1,
|
||||||
})
|
})
|
||||||
closeBLEConnection()
|
closeBLEConnection()
|
||||||
closeBluetoothAdapter()
|
closeBluetoothAdapter()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,11 @@ export default {
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
getCheckDevice(param) { // 设备过滤
|
||||||
|
return http.post("/de/check_device_msg", param).then(res => {
|
||||||
|
return res
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
// 首页
|
// 首页
|
||||||
getHomeInfo(param) { // 默认数据
|
getHomeInfo(param) { // 默认数据
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -107,7 +107,7 @@ var render = function () {
|
||||||
var _vm = this
|
var _vm = this
|
||||||
var _h = _vm.$createElement
|
var _h = _vm.$createElement
|
||||||
var _c = _vm._self._c || _h
|
var _c = _vm._self._c || _h
|
||||||
var m0 = _vm.isShow && _vm.isConnection == 0 ? _vm.$t("Disconnect") : null
|
var m0 = _vm.isShow && _vm.isConnection == 2 ? _vm.$t("Disconnect") : null
|
||||||
var m1 = _vm.unitConversion(_vm.unit)
|
var m1 = _vm.unitConversion(_vm.unit)
|
||||||
var m2 = _vm.$t("UnitBtn")
|
var m2 = _vm.$t("UnitBtn")
|
||||||
var m3 = _vm.btnType == 2 ? _vm.$t("Save") : null
|
var m3 = _vm.btnType == 2 ? _vm.$t("Save") : null
|
||||||
|
|
@ -189,6 +189,14 @@ var _default = {
|
||||||
name: this.$t("oz"),
|
name: this.$t("oz"),
|
||||||
id: "08",
|
id: "08",
|
||||||
unit: "oz"
|
unit: "oz"
|
||||||
|
}, {
|
||||||
|
name: this.$t("lb"),
|
||||||
|
id: "03",
|
||||||
|
unit: "lb"
|
||||||
|
}, {
|
||||||
|
name: this.$t("ml"),
|
||||||
|
id: "05",
|
||||||
|
unit: "ml"
|
||||||
}],
|
}],
|
||||||
unitListIndex: 0,
|
unitListIndex: 0,
|
||||||
units: ['kg', 'g', 'st:lb', 'lb', 'g', 'ml', 'Waterml', 'milkml', 'oz', 'floz', 'lboz']
|
units: ['kg', 'g', 'st:lb', 'lb', 'g', 'ml', 'Waterml', 'milkml', 'oz', 'floz', 'lboz']
|
||||||
|
|
@ -209,10 +217,9 @@ var _default = {
|
||||||
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["bleValue", "isBluetoothTyle", "countFoodInfo"])), {}, {
|
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["bleValue", "isBluetoothTyle", "countFoodInfo"])), {}, {
|
||||||
weight: function weight() {
|
weight: function weight() {
|
||||||
var that = this;
|
var that = this;
|
||||||
var info = that.bleValue;
|
var kcal = (Number(that.weightKcal) / 100 * that.bleValue.countWeight).toFixed(2);
|
||||||
var kcal = (Number(that.weightKcal) / 100 * info.countWeight).toFixed(2);
|
that.unit = that.bleValue.unit;
|
||||||
that.unit = info.unit;
|
that.kcal = that.convertToGrams(kcal, that.bleValue.unit).toFixed(2);
|
||||||
that.kcal = that.convertToGrams(kcal, info.unit).toFixed(2);
|
|
||||||
return this.bleValue.countWeight;
|
return this.bleValue.countWeight;
|
||||||
},
|
},
|
||||||
isConnection: function isConnection() {
|
isConnection: function isConnection() {
|
||||||
|
|
@ -256,6 +263,7 @@ var _default = {
|
||||||
notify: '',
|
notify: '',
|
||||||
write: '',
|
write: '',
|
||||||
unit: "g",
|
unit: "g",
|
||||||
|
type: 1,
|
||||||
countWeight: "",
|
countWeight: "",
|
||||||
bleTipsText: that.$t('SearchBluetooth'),
|
bleTipsText: that.$t('SearchBluetooth'),
|
||||||
isConnectStatus: 0
|
isConnectStatus: 0
|
||||||
|
|
@ -266,12 +274,39 @@ var _default = {
|
||||||
var that = this;
|
var that = this;
|
||||||
var unit = that.unitList[e.detail.value].unit;
|
var unit = that.unitList[e.detail.value].unit;
|
||||||
if (that.isShow && that.unit != unit) {
|
if (that.isShow && that.unit != unit) {
|
||||||
that.handletoggleUnit(unit == "oz" ? 0x08 : 0x04);
|
that.handletoggleUnit(that.unitConversion2(unit));
|
||||||
}
|
}
|
||||||
that.unitListIndex = [e.detail.value];
|
that.unitListIndex = [e.detail.value];
|
||||||
that.$store.commit('changeBluetoothValue', {
|
that.$store.commit('changeBluetoothValue', {
|
||||||
unit: that.unitList[e.detail.value].unit
|
unit: unit
|
||||||
});
|
});
|
||||||
|
console.log("单位切换", unit, that.unit, that.unitListIndex);
|
||||||
|
},
|
||||||
|
unitConversion2: function unitConversion2(unit) {
|
||||||
|
if (unit == 'kg') {
|
||||||
|
return 0x00;
|
||||||
|
} else if (unit == '斤') {
|
||||||
|
return 0x01;
|
||||||
|
} else if (unit == 'st:lb') {
|
||||||
|
return 0x02;
|
||||||
|
} else if (unit == 'lb') {
|
||||||
|
return 0x03;
|
||||||
|
} else if (unit == 'g') {
|
||||||
|
return 0x04;
|
||||||
|
} else if (unit == 'ml') {
|
||||||
|
return 0x05;
|
||||||
|
} else if (unit == 'Waterml') {
|
||||||
|
return 0x06;
|
||||||
|
} else if (unit == 'milkml') {
|
||||||
|
return 0x07;
|
||||||
|
} else if (unit == 'oz') {
|
||||||
|
return 0x08;
|
||||||
|
} else if (unit == 'floz') {
|
||||||
|
return 0x09;
|
||||||
|
} else if (unit == 'lboz') {
|
||||||
|
return 0x0A;
|
||||||
|
}
|
||||||
|
return unit;
|
||||||
},
|
},
|
||||||
handletoggleUnit: function handletoggleUnit(unit) {
|
handletoggleUnit: function handletoggleUnit(unit) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
@ -335,7 +370,8 @@ var _default = {
|
||||||
// 1盎司 = 28.349523125克
|
// 1盎司 = 28.349523125克
|
||||||
'kg': 1000,
|
'kg': 1000,
|
||||||
// 1公斤 = 1000克
|
// 1公斤 = 1000克
|
||||||
'g': 1
|
'g': 1,
|
||||||
|
'ml': 1
|
||||||
};
|
};
|
||||||
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -343,14 +379,16 @@ var _default = {
|
||||||
return value * conversionFactors[fromUnit];
|
return value * conversionFactors[fromUnit];
|
||||||
},
|
},
|
||||||
unitConversion: function unitConversion(unit) {
|
unitConversion: function unitConversion(unit) {
|
||||||
if (unit == 'kcal') {
|
if (unit == 'kg') {
|
||||||
return '千卡';
|
return this.$t("kg");
|
||||||
} else if (unit == 'g') {
|
} else if (unit == 'g') {
|
||||||
return this.$t("g");
|
return this.$t("g");
|
||||||
} else if (unit == 'lb') {
|
} else if (unit == 'lb') {
|
||||||
return '磅';
|
return this.$t("lb");
|
||||||
} else if (unit == 'oz') {
|
} else if (unit == 'oz') {
|
||||||
return this.$t("oz");
|
return this.$t("oz");
|
||||||
|
} else if (unit == 'ml') {
|
||||||
|
return this.$t("ml");
|
||||||
}
|
}
|
||||||
return unit;
|
return unit;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
<view class="weightPages data-v-5fc22dca"><view class="table data-v-5fc22dca"><view class="text data-v-5fc22dca"><image src="/static/zhong.png" class="data-v-5fc22dca"></image><text data-event-opts="{{[['tap',[['openBluetoothAdapter',['$event']]]]]}}" bindtap="__e" class="data-v-5fc22dca">{{bletipstext}}</text></view><block wx:if="{{isShow&&isConnection==0}}"><view data-event-opts="{{[['tap',[['handleBack',['$event']]]]]}}" class="duan data-v-5fc22dca" bindtap="__e">{{''+$root.m0+''}}</view></block></view><view class="weight-wrap data-v-5fc22dca"><view data-event-opts="{{[['tap',[['inputDialogToggle',['$event']]]]]}}" class="weight data-v-5fc22dca" bindtap="__e"><text class="val data-v-5fc22dca">{{weight==''?'0.0':weight}}</text><text class="unit data-v-5fc22dca">{{$root.m1}}</text></view></view><view class="groupbtn data-v-5fc22dca"><view class="btn danwei data-v-5fc22dca"><view class="lan border-bottom data-v-5fc22dca"><view class="right data-v-5fc22dca"><picker mode="selector" range="{{unitList}}" range-key="name" value="{{unitListIndex}}" data-event-opts="{{[['change',[['changleUnits',['$event']]]]]}}" bindchange="__e" class="data-v-5fc22dca"><view class="uni-input data-v-5fc22dca">{{''+$root.m2+''}}</view></picker></view></view></view><block wx:if="{{btnType==2}}"><view data-event-opts="{{[['tap',[['handlesub',['$event']]]]]}}" class="btn addbtn size14 data-v-5fc22dca" bindtap="__e">{{$root.m3}}</view></block><block wx:if="{{btnType==1}}"><view data-event-opts="{{[['tap',[['handleAddFood',['$event']]]]]}}" class="btn addbtn data-v-5fc22dca" bindtap="__e">+</view></block><view data-event-opts="{{[['tap',[['handleqingling',['$event']]]]]}}" class="btn qingling data-v-5fc22dca" bindtap="__e">{{$root.m4}}</view></view><view class="data-v-5fc22dca"><uni-popup vue-id="cef7e708-1" type="dialog" data-ref="popup" class="data-v-5fc22dca vue-ref" bind:__l="__l" vue-slots="{{['default']}}"><uni-popup-dialog vue-id="{{('cef7e708-2')+','+('cef7e708-1')}}" mode="input" title="{{$root.m5}}" placeholder="{{$root.m6}}" data-event-opts="{{[['^close',[['close']]],['^confirm',[['confirm']]]]}}" bind:close="__e" bind:confirm="__e" class="data-v-5fc22dca" bind:__l="__l"></uni-popup-dialog></uni-popup></view></view>
|
<view class="weightPages data-v-5fc22dca"><view class="table data-v-5fc22dca"><view class="text data-v-5fc22dca"><image src="/static/zhong.png" class="data-v-5fc22dca"></image><text data-event-opts="{{[['tap',[['openBluetoothAdapter',['$event']]]]]}}" bindtap="__e" class="data-v-5fc22dca">{{bletipstext}}</text></view><block wx:if="{{isShow&&isConnection==2}}"><view data-event-opts="{{[['tap',[['handleBack',['$event']]]]]}}" class="duan data-v-5fc22dca" bindtap="__e">{{''+$root.m0+''}}</view></block></view><view class="weight-wrap data-v-5fc22dca"><view data-event-opts="{{[['tap',[['inputDialogToggle',['$event']]]]]}}" class="weight data-v-5fc22dca" bindtap="__e"><text class="val data-v-5fc22dca">{{weight==''?'0.0':weight}}</text><text class="unit data-v-5fc22dca">{{$root.m1}}</text></view></view><view class="groupbtn data-v-5fc22dca"><view class="btn danwei data-v-5fc22dca"><view class="lan border-bottom data-v-5fc22dca"><view class="right data-v-5fc22dca"><picker mode="selector" range="{{unitList}}" range-key="name" value="{{unitListIndex}}" data-event-opts="{{[['change',[['changleUnits',['$event']]]]]}}" bindchange="__e" class="data-v-5fc22dca"><view class="uni-input data-v-5fc22dca">{{''+$root.m2+''}}</view></picker></view></view></view><block wx:if="{{btnType==2}}"><view data-event-opts="{{[['tap',[['handlesub',['$event']]]]]}}" class="btn addbtn size14 data-v-5fc22dca" bindtap="__e">{{$root.m3}}</view></block><block wx:if="{{btnType==1}}"><view data-event-opts="{{[['tap',[['handleAddFood',['$event']]]]]}}" class="btn addbtn data-v-5fc22dca" bindtap="__e">+</view></block><view data-event-opts="{{[['tap',[['handleqingling',['$event']]]]]}}" class="btn qingling data-v-5fc22dca" bindtap="__e">{{$root.m4}}</view></view><view class="data-v-5fc22dca"><uni-popup vue-id="cef7e708-1" type="dialog" data-ref="popup" class="data-v-5fc22dca vue-ref" bind:__l="__l" vue-slots="{{['default']}}"><uni-popup-dialog vue-id="{{('cef7e708-2')+','+('cef7e708-1')}}" mode="input" title="{{$root.m5}}" placeholder="{{$root.m6}}" data-event-opts="{{[['^close',[['close']]],['^confirm',[['confirm']]]]}}" bind:close="__e" bind:confirm="__e" class="data-v-5fc22dca" bind:__l="__l"></uni-popup-dialog></uni-popup></view></view>
|
||||||
|
|
@ -352,6 +352,9 @@ var _default = {
|
||||||
bleValue: {
|
bleValue: {
|
||||||
handler: function handler(newVal, oldVal) {
|
handler: function handler(newVal, oldVal) {
|
||||||
this.realTimeWeight(newVal.countWeight, newVal.unit);
|
this.realTimeWeight(newVal.countWeight, newVal.unit);
|
||||||
|
if (newVal.type == 2 && Number(newVal.countWeight) > 0) {
|
||||||
|
this.handletoggleUnit(newVal.countWeight, newVal.unit, this.activeType.nutrients_four);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
}
|
}
|
||||||
|
|
@ -413,16 +416,21 @@ var _default = {
|
||||||
},
|
},
|
||||||
//实时重量
|
//实时重量
|
||||||
realTimeWeight: function realTimeWeight(weight, unit) {
|
realTimeWeight: function realTimeWeight(weight, unit) {
|
||||||
// console.log("实时重量", weight, unit)
|
|
||||||
this.activeType = Object.assign({}, this.activeType, {
|
this.activeType = Object.assign({}, this.activeType, {
|
||||||
weight: this.convertToGrams(weight, unit)
|
weight: this.convertToGrams(weight, unit)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
unitConversion: function unitConversion(unit) {
|
unitConversion: function unitConversion(unit) {
|
||||||
if (unit == 'kcal') {
|
if (unit == 'kg') {
|
||||||
return '千卡';
|
return this.$t("kg");
|
||||||
} else if (unit == 'g') {
|
} else if (unit == 'g') {
|
||||||
return '克';
|
return this.$t("g");
|
||||||
|
} else if (unit == 'lb') {
|
||||||
|
return this.$t("lb");
|
||||||
|
} else if (unit == 'oz') {
|
||||||
|
return this.$t("oz");
|
||||||
|
} else if (unit == 'ml') {
|
||||||
|
return this.$t("ml");
|
||||||
}
|
}
|
||||||
return unit;
|
return unit;
|
||||||
},
|
},
|
||||||
|
|
@ -434,7 +442,8 @@ var _default = {
|
||||||
// 1盎司 = 28.349523125克
|
// 1盎司 = 28.349523125克
|
||||||
'kg': 1000,
|
'kg': 1000,
|
||||||
// 1公斤 = 1000克
|
// 1公斤 = 1000克
|
||||||
'g': 1
|
'g': 1,
|
||||||
|
'ml': 1
|
||||||
};
|
};
|
||||||
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
if (!conversionFactors.hasOwnProperty(fromUnit)) {
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -452,14 +461,114 @@ var _default = {
|
||||||
that.weightKcal = Number(ite.kcal);
|
that.weightKcal = Number(ite.kcal);
|
||||||
if (that.bleValue.serviceId != "") {
|
if (that.bleValue.serviceId != "") {
|
||||||
that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit);
|
that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit);
|
||||||
|
if (that.bleValue.type == 2 && Number(that.bleValue.countWeight) > 0) {
|
||||||
|
that.handletoggleUnit(that.bleValue.countWeight, that.bleValue.unit, ite.nutrients_four);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
that.$store.commit("changeBluetoothValue", {
|
that.$store.commit("changeBluetoothValue", {
|
||||||
countWeight: 100,
|
countWeight: 100,
|
||||||
unit: "g"
|
unit: that.bleValue.unit
|
||||||
});
|
});
|
||||||
that.realTimeWeight(100, "g");
|
that.realTimeWeight(100, that.bleValue.unit);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 下发营养含量
|
||||||
|
handletoggleUnit: function handletoggleUnit(val, unit, ite) {
|
||||||
|
var that = this;
|
||||||
|
var weight = Number(that.convertToGrams(val, unit)) / 100;
|
||||||
|
var dataArray = that.buildNutritionData({
|
||||||
|
fat: weight * ite[2].value,
|
||||||
|
calorie: weight * ite[0].value,
|
||||||
|
carbohydrate: weight * ite[3].value,
|
||||||
|
protein: weight * ite[1].value,
|
||||||
|
fiber: 0
|
||||||
|
});
|
||||||
|
var arrayBuffer = new ArrayBuffer(dataArray.length);
|
||||||
|
var uint8Array = new Uint8Array(arrayBuffer);
|
||||||
|
dataArray.forEach(function (value, index) {
|
||||||
|
uint8Array[index] = value;
|
||||||
|
});
|
||||||
|
console.log("arrayBuffer", arrayBuffer);
|
||||||
|
that.sendArrayBuffer(arrayBuffer);
|
||||||
|
},
|
||||||
|
// 构建营养成分数据包
|
||||||
|
buildNutritionData: function buildNutritionData(data) {
|
||||||
|
// 头信息
|
||||||
|
var header = 0xC5; // 同步头
|
||||||
|
var dataLength = 0x11; // 数据长度:17字节
|
||||||
|
var cmd = 0x04; // CMD字节
|
||||||
|
var packetInfo = 0x41; // 包信息:总1包,第1包
|
||||||
|
|
||||||
|
// 转换营养成分值(×10并取整)
|
||||||
|
var fatValue = Math.round(data.fat * 10);
|
||||||
|
var calorieValue = Math.round(data.calorie * 10);
|
||||||
|
var carbValue = Math.round(data.carbohydrate * 10);
|
||||||
|
var fiberValue = Math.round(data.fiber * 10);
|
||||||
|
var proteinValue = Math.round(data.protein * 10);
|
||||||
|
|
||||||
|
// 构建数据数组
|
||||||
|
var dataArray = [];
|
||||||
|
|
||||||
|
// 添加头部
|
||||||
|
dataArray.push(header); // 0xC5
|
||||||
|
dataArray.push(dataLength); // 0x11
|
||||||
|
dataArray.push(cmd); // 0x04
|
||||||
|
dataArray.push(packetInfo); // 0x41
|
||||||
|
|
||||||
|
// 添加脂肪数据(大端序,3字节)
|
||||||
|
dataArray.push(fatValue >> 16 & 0xFF); // 高位字节
|
||||||
|
dataArray.push(fatValue >> 8 & 0xFF); // 中位字节
|
||||||
|
dataArray.push(fatValue & 0xFF); // 低位字节
|
||||||
|
|
||||||
|
// 添加卡路里数据(大端序,3字节)
|
||||||
|
dataArray.push(calorieValue >> 16 & 0xFF);
|
||||||
|
dataArray.push(calorieValue >> 8 & 0xFF);
|
||||||
|
dataArray.push(calorieValue & 0xFF);
|
||||||
|
|
||||||
|
// 添加碳水化合物数据(大端序,3字节)
|
||||||
|
dataArray.push(carbValue >> 16 & 0xFF);
|
||||||
|
dataArray.push(carbValue >> 8 & 0xFF);
|
||||||
|
dataArray.push(carbValue & 0xFF);
|
||||||
|
|
||||||
|
// 添加膳食纤维数据(大端序,3字节)
|
||||||
|
dataArray.push(fiberValue >> 16 & 0xFF);
|
||||||
|
dataArray.push(fiberValue >> 8 & 0xFF);
|
||||||
|
dataArray.push(fiberValue & 0xFF);
|
||||||
|
|
||||||
|
// 添加蛋白质数据(大端序,3字节)
|
||||||
|
dataArray.push(proteinValue >> 16 & 0xFF);
|
||||||
|
dataArray.push(proteinValue >> 8 & 0xFF);
|
||||||
|
dataArray.push(proteinValue & 0xFF);
|
||||||
|
|
||||||
|
// 计算校验和(除同步头外的所有字节的和,取低8位)
|
||||||
|
var checksum = 0;
|
||||||
|
for (var i = 1; i < dataArray.length; i++) {
|
||||||
|
checksum = checksum + dataArray[i] & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加校验和
|
||||||
|
dataArray.push(checksum);
|
||||||
|
console.log('构建的数据包:', dataArray);
|
||||||
|
console.log('十六进制:', dataArray.map(function (b) {
|
||||||
|
return b.toString(16).padStart(2, '0');
|
||||||
|
}).join(' '));
|
||||||
|
return dataArray;
|
||||||
|
},
|
||||||
|
sendArrayBuffer: function sendArrayBuffer(buffer) {
|
||||||
|
var that = this;
|
||||||
|
uni.writeBLECharacteristicValue({
|
||||||
|
deviceId: that.bleValue.deviceId,
|
||||||
|
serviceId: that.bleValue.serviceId,
|
||||||
|
characteristicId: that.bleValue.write,
|
||||||
|
value: buffer,
|
||||||
|
success: function success(res) {
|
||||||
|
console.log('下发指令成功', res.errMsg);
|
||||||
|
},
|
||||||
|
fail: function fail(res) {
|
||||||
|
console.log("下发指令失败", res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
//测量返回
|
//测量返回
|
||||||
handleBle: function handleBle(weight, unit, kcal) {
|
handleBle: function handleBle(weight, unit, kcal) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
|
||||||
|
|
@ -663,6 +663,9 @@
|
||||||
}
|
}
|
||||||
.wrapper .box2 .box_list .box_list_item .item .item-left .name text.data-v-d4f38c70 {
|
.wrapper .box2 .box_list .box_list_item .item .item-left .name text.data-v-d4f38c70 {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.wrapper .box2 .box_list .box_list_item .item .item-left .weight.data-v-d4f38c70 {
|
.wrapper .box2 .box_list .box_list_item .item .item-left .weight.data-v-d4f38c70 {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
height: 60rpx;
|
height: 60rpx;
|
||||||
}
|
}
|
||||||
.foodtools .type .title .text.data-v-378efeb4 {
|
.foodtools .type .title .text.data-v-378efeb4 {
|
||||||
width: 50%;
|
width: 65%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue