更新记录
1.0.1(2025-12-03)
下载此版本
测试中
1.0.0(2025-12-03)
下载此版本
我只是在开发中,各位大佬先别用,我开发好了会公开的
平台兼容性
uni-app(4.54)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
Android插件版本 |
iOS |
iOS插件版本 |
鸿蒙 |
| - |
- |
- |
- |
- |
- |
5.0 |
1.0.1 |
12 |
1.0.1 |
- |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.33)
| Chrome |
Safari |
Android |
Android插件版本 |
iOS |
iOS插件版本 |
鸿蒙 |
微信小程序 |
| - |
- |
5.0 |
1.0.0 |
12 |
1.0.0 |
- |
- |
ts-step-component
开发文档
UTS 语法
UTS API插件
UTS uni-app兼容模式组件
UTS 标准模式组件
Hello UTS
<!-- 我是在开发,没开发好,大佬别急
使用案例>
<!--
今日步数
{{ todayStep.step }}
距离:{{ todayStep.distance }} 米
卡路里:{{ todayStep.calorie }} 千卡
<button @click="initStep" :disabled="isInit">初始化计步</button>
<button @click="startStep" :disabled="!isInit || isRunning">开始计步</button>
<button @click="stopStep" :disabled="!isRunning">停止计步</button>
<button @click="queryHistory">查询历史(近3天)</button>
历史步数
{{ item.date }}:{{ item.step }} 步({{ item.distance }} 米)
{
if (error) {
uni.showToast({ title: error, icon: 'none' });
return;
}
this.todayStep = result; // 实时更新今日步数
});
} else {
uni.showToast({ title: '计步初始化失败', icon: 'none' });
}
} catch (e) {
uni.showToast({ title: '初始化异常:' + (e.message || e), icon: 'none' });
}
},
// 3. 开始计步
async startStep() {
try {
const success = await StepPlugin.startStep();
this.isRunning = success;
if (success) {
uni.showToast({ title: '计步已启动' });
} else {
uni.showToast({ title: '计步启动失败', icon: 'none' });
}
} catch (e) {
uni.showToast({ title: '启动异常:' + (e.message || e), icon: 'none' });
}
},
// 4. 停止计步
async stopStep() {
try {
const success = await StepPlugin.stopStep();
this.isRunning = !success;
if (success) {
uni.showToast({ title: '计步已停止' });
// 停止后保存今日步数(插件内部已处理,这里可选更新UI)
this.todayStep = await StepPlugin.getTodayStep();
}
} catch (e) {
uni.showToast({ title: '停止异常:' + (e.message || e), icon: 'none' });
}
},
// 5. 查询历史步数(近3天)
async queryHistory() {
try {
// 计算近3天日期(格式:YYYY-MM-DD)
const formatDate = (date) => {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
};
const endDate = formatDate(new Date());
const startDate = formatDate(new Date(Date.now() - 3 * 24 * 60 * 60 * 1000));
// 调用历史查询API
this.historyList = await StepPlugin.getHistoryStep({
startDate,
endDate
});
} catch (e) {
uni.showToast({ title: '查询历史失败:' + (e.message || e), icon: 'none' });
}
}
}
};
<style scoped>
.step-container {
padding: 20rpx;
}
.step-info {
text-align: center;
margin: 40rpx 0;
}
.count {
font-size: 80rpx;
font-weight: bold;
color: #2c3e50;
}
.derived-data {
display: flex;
justify-content: space-around;
margin: 40rpx 0;
}
.btn-group {
display: flex;
flex-direction: column;
gap: 20rpx;
}
.btn-group button {
background-color: #42b983;
color: white;
}
.history-title {
font-size: 32rpx;
font-weight: bold;
margin: 20rpx 0;
}
.history-item {
margin: 10rpx 0;
color: #666;
}
</style>
2. 权限配置(双端必需)
(1)Android 权限(自动集成,无需手动改)
插件已在 app-android/AndroidManifest.xml 中声明必需权限,打包时自动合并:
身体传感器权限(计步传感器)
活动识别权限(Android 10+)
前台服务权限(后台保活)
网络权限(Google Fit 通信)
(2)iOS 权限配置(手动添加)
需要在项目的 manifest.json → App 模块配置 → iOS → info.plist 配置 中添加以下内容(健康权限描述):
json
"ios": {
"infoPlist": {
"NSHealthShareUsageDescription": "需要访问健康数据以记录步数",
"NSHealthUpdateUsageDescription": "需要写入健康数据以同步步数"
}
}
作用:iOS 系统要求必须说明权限用途,否则会被拒审,且无法申请健康权限。
3. Android Google Fit 依赖(可选,自动集成)
插件已在 app-android/config.json 中配置 Google Fit 依赖,打包时自动下载,无需手动添加:
json
"dependencies": [
"com.google.android.gms:play-services-fitness:21.1.0",
"com.google.android.gms:play-services-base:18.2.0"
]
二、核心 API 说明
API 名称 作用 参数类型 返回值类型 备注
init(params?) 初始化计步(必需先调用) StepUserParams(可选) Promise 返回 true 表示初始化成功
startStep() 开始计步 无 Promise 返回 true 表示启动成功
stopStep() 停止计步 无 Promise 返回 true 表示停止成功
setStepCallback 设置实时步数回调 StepCallback 无 步数变化时触发
getTodayStep() 获取今日步数 无 Promise 返回步数、距离、卡路里
getHistoryStep 获取历史步数 StepHistoryParams Promise 支持查询日期范围
getIsRunning() 获取计步运行状态 无 boolean true 表示正在计步-->