hookehuyr

feat(微信步数): 添加微信步数同步功能及相关配置

添加微信步数同步API接口及页面跳转逻辑
移除模拟数据生成代码,优化授权流程
更新路由配置和请求参数,添加用户信息权限
/*
* @Date: 2023-12-22 10:29:37
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-01 13:53:17
* @FilePath: /lls_program/src/api/points.js
* @Description: 文件描述
*/
import { fn, fetch } from './fn';
const Api = {
SYNC_WX_STEP: '/srv/?a=point&t=sync_wx_step',
}
/**
* @description: 同步微信步数
* @returns
*/
export const syncWxStepAPI = (params) => fn(fetch.post(Api.SYNC_WX_STEP, params));
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-01 13:08:15
* @LastEditTime: 2025-09-01 14:31:43
* @FilePath: /lls_program/src/app.config.js
* @Description: 文件描述
*/
export default {
pages: [
// 'pages/index/index',
// 'pages/auth/index',
'pages/Welcome/index',
'pages/auth/index',
'pages/Dashboard/index',
'pages/MyFamily/index',
'pages/CreateFamily/index',
......@@ -51,6 +51,9 @@ export default {
},
'scope.werun': {
desc: '您的微信运动数据将用于记录步数和健康统计'
},
'scope.userInfo': {
desc: '您的用户信息将用于个人中心和活动打卡'
}
}
}
......
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-06-28 11:04:17
* @LastEditTime: 2025-09-01 14:32:25
* @FilePath: /lls_program/src/app.js
* @Description: 文件描述
*/
......@@ -9,32 +9,22 @@ import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './app.less'
import { routerStore } from '@/stores/router'
import Taro from '@tarojs/taro'
const App = createApp({
// 对应 onLaunch
onLaunch(options) {
// 未授权状态跳转授权页面,首页不需要权限
const path = options.path;
const query = options.query;
// 缓存没有权限的地址
const router = routerStore();
router.add(path);
// if (path !== 'pages/index/index' && !wx.getStorageSync("sessionid")) {
if (!wx.getStorageSync("sessionid")) {
console.warn("没有权限");
// if (path === 'pages/detail/index') {
// Taro.navigateTo({
// url: `./pages/auth/index?url=${path}&id=${query.id}&start_date=${query.start_date}&end_date=${query.end_date}`,
// })
// } else {
// Taro.navigateTo({
// url: './pages/auth/index?url=' + path,
// })
// }
wx.navigateTo({
url: '/pages/auth/index'
})
}
},
onShow(options) {
onShow() {
},
// 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖
});
......
......@@ -206,11 +206,6 @@ const collectAll = async () => {
floatingItems.value = [];
isCollecting.value = false;
// 模拟2秒后重新生成
// setTimeout(() => {
// floatingItems.value = generateMockData();
// }, 2000);
}, totalAnimationTime);
}
......@@ -243,7 +238,7 @@ defineExpose({
/**
* 初始化数据
*/
const initData = () => {
const initData = async () => {
floatingItems.value = generateMockData();
console.warn('初始化数据')
}
......
......@@ -35,6 +35,8 @@
import { ref, onMounted, defineEmits } from 'vue'
import Taro from '@tarojs/taro'
import { syncWxStepAPI } from '@/api/points'
// 定义事件
const emit = defineEmits(['auth-change', 'steps-update'])
......@@ -141,19 +143,17 @@ const getWeRunData = async () => {
code: loginRes.code
})
// 同步微信步数
const { code, data } = await syncWxStepAPI({ encryptedData: weRunRes.encryptedData, iv: weRunRes.iv });
if (code) {
// 提示获取步数成功
// Taro.showToast({
// title: `获取步数成功:${mockSteps}步`,
// icon: 'none'
// })
// TODO: 实际项目中需要将 encryptedData, iv, code 发送到后端解密
// const decryptedData = await api.decryptWeRunData({
// encryptedData: weRunRes.encryptedData,
// iv: weRunRes.iv,
// code: loginRes.code
// })
console.warn('同步微信步数成功', data);
// todaySteps.value = decryptedData.todaySteps
}
} catch (error) {
console.error('获取微信运动数据失败:', error)
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-05-26 10:17:04
* @FilePath: /meihuaApp/src/pages/auth/index.vue
* @LastEditTime: 2025-09-01 13:57:13
* @FilePath: /lls_program/src/pages/auth/index.vue
* @Description: 文件描述
-->
<template>
......@@ -60,15 +60,9 @@ export default {
// }
// TAG:处理分享跳转问题
const params = getCurrentPageParam();
if (getCurrentPageParam().url === 'pages/detail/index') { // 详情页的分享跳转处理
Taro.reLaunch({
url: `../../${params.url}?id=${params.id}&start_date=${params.start_date}&end_date=${params.end_date}`
})
} else { // 其他页面分享跳首页
Taro.reLaunch({
url: `/pages/index/index?first_in=${wx.getStorageSync("first_in")}`
})
}
Taro.reLaunch({
url: `/pages/Dashboard/index`
})
Taro.hideLoading();
}
} else {
......
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-07-01 11:17:49
* @LastEditTime: 2025-09-01 13:47:06
* @FilePath: /lls_program/src/utils/request.js
* @Description: 简单axios封装,后续按实际处理
*/
......@@ -60,8 +60,7 @@ const service = axios.create({
})
service.defaults.params = {
f: 'room',
client_id: '772428',
f: 'walk',
};
// request interceptor
......@@ -161,7 +160,7 @@ service.interceptors.response.use(
*/
setTimeout(() => {
Taro.navigateTo({
url: '../../pages/auth/index?url=' + routerStore().url
url: '/pages/auth/index?url=' + routerStore().url
});
}, 1000);
}
......