127 lines
3.2 KiB
JavaScript
Raw Normal View History

2025-06-06 15:17:30 +08:00
const utils = require("../../utils/utils");
const module = require("../index.js");
const SportHandLift = require("../sports/sport-hand-lift");
const AiSport = requirePlugin("aiSport");
const humanDetection = AiSport.humanDetection;
const SportBase = AiSport.sports.SportBase;
//注册自定义运动
SportBase.register(SportHandLift.KEY, SportHandLift.NAME, () => {
return new SportHandLift();
});
Page({
data: {
version: AiSport.version.release,
ve: null,
enhanced: module.judgeEnhanced(),
threshold: 0.25,
sports: utils.clone(SportBase.SPORTS),
sportKey: SportBase.SPORTS[1].key
},
async onLoad() {
this.setData({
enhanced: module.judgeEnhanced()
});
this.initializeVe();
},
initializeVe() {
wx.showLoading({
title: '加载模型...'
});
const that = this;
humanDetection.initialize({
ve: that.data.ve,
enhanced: that.data.enhanced,
callback: (err) => {
wx.hideLoading();
const ve = humanDetection.getVe();
let ehd = false;
if (ve == 1)
ehd = humanDetection.isEnhanced();
if (!err) {
wx.showToast({
icon: 'none',
title: `初始成功引擎ve${ve} ${ehd ? '增强' : ''}`
})
return;
}
wx.setClipboardData({
data: err.message,
success: () => {
wx.showToast({
title: '初始化失败',
icon: 'none'
})
}
});
}
});
},
onShowTips(e) {
const msg = e.currentTarget.dataset.msg;
wx.showModal({
content: msg,
showCancel: false
});
},
onSelectVe(e) {
const v = e.currentTarget.dataset.v;
this.setData({ ve: v !== "null" ? Number(v) : null });
this.initializeVe();
},
onToggleEnhanced() {
this.setData({
enhanced: !this.data.enhanced
});
this.initializeVe()
},
onThresholdChanged(e) {
const reg = /^[0-1](\.\d{1,2})?$/;
const val = e.detail.value;
const th = parseFloat(val);
if (reg.test(val) && th <= 1) {
module.initializePlugin(th, this.data.enhanced);
return;
}
wx.showToast({
icon: 'none',
title: '阈值必须在0-1之间'
});
this.setData({
threshold: 0.35
});
},
onSelectSport(e) {
const key = e.currentTarget.dataset.key;
this.setData({
sportKey: key
});
},
onNavSport() {
wx.navigateTo({
url: `/module-sport/pages/sport?sportKey=${this.data.sportKey}`
});
},
onNavHuman() {
wx.navigateTo({ url: '/module-sport/pages/human' });
},
onShareAppMessage() {
return {
path: '/module-sport/pages/index',
title: '跃动小程序'
};
}
});