api封装
This commit is contained in:
parent
465b68fbef
commit
10950db757
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* API 接口封装
|
||||||
|
* 统一管理所有 API 请求
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
* @returns {Promise} 返回用户信息
|
||||||
|
*/
|
||||||
|
export const getUserInfo = () => {
|
||||||
|
return uni.$uv.http.get('/getInfo', {
|
||||||
|
custom: {
|
||||||
|
auth: true // 启用 token 认证
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取仪表板简要信息
|
||||||
|
* @param {Object} params 请求参数
|
||||||
|
* @param {string} params.joinUserId 用户ID
|
||||||
|
* @param {string[]} params.keys 需要获取的数据键名数组
|
||||||
|
* @returns {Promise} 返回仪表板简要信息
|
||||||
|
*/
|
||||||
|
export const getDashboardBrief = ({ joinUserId, keys }) => {
|
||||||
|
// 构建查询参数字符串
|
||||||
|
const params = [`joinUserId=${joinUserId}`];
|
||||||
|
if (keys && Array.isArray(keys)) {
|
||||||
|
keys.forEach((key) => {
|
||||||
|
params.push(`keys=${encodeURIComponent(key)}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const queryString = params.join('&');
|
||||||
|
|
||||||
|
return uni.$uv.http.get(`dashboard/brief?${queryString}`, {
|
||||||
|
custom: {
|
||||||
|
auth: true // 启用 token 认证
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
import { ref, computed, watch, onMounted } from 'vue';
|
import { ref, computed, watch, onMounted } from 'vue';
|
||||||
import { onShow } from '@dcloudio/uni-app';
|
import { onShow } from '@dcloudio/uni-app';
|
||||||
import { useUserStore } from '@/store/user';
|
import { useUserStore } from '@/store/user';
|
||||||
|
import { getUserInfo, getDashboardBrief } from '@/common/api';
|
||||||
|
|
||||||
import FabPlus from '@/components/FabPlus.vue';
|
import FabPlus from '@/components/FabPlus.vue';
|
||||||
import AddEventModal from '@/components/AddEventModal.vue';
|
import AddEventModal from '@/components/AddEventModal.vue';
|
||||||
|
|
@ -126,22 +127,17 @@ const value=ref(0);
|
||||||
|
|
||||||
// 页面加载时请求接口
|
// 页面加载时请求接口
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 请求 /getInfo 接口,配置 auth: true 以自动添加 token
|
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
console.log('当前 token:', userStore.token);
|
console.log('当前 token:', userStore.token);
|
||||||
|
|
||||||
uni.$uv.http.get('/getInfo', {
|
// 请求用户信息接口
|
||||||
custom: {
|
getUserInfo().then(res => {
|
||||||
auth: true // 启用 token 认证
|
|
||||||
}
|
|
||||||
}).then(res => {
|
|
||||||
console.log('getInfo 接口返回:', res);
|
console.log('getInfo 接口返回:', res);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('getInfo 接口请求失败:', err);
|
console.error('getInfo 接口请求失败:', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 请求 dashboard/brief 接口
|
// 请求仪表板简要信息接口
|
||||||
const keys = [
|
const keys = [
|
||||||
'taskStatus',
|
'taskStatus',
|
||||||
'taskTodayCompleted',
|
'taskTodayCompleted',
|
||||||
|
|
@ -158,18 +154,9 @@ onMounted(() => {
|
||||||
'customerMonthFollowCount'
|
'customerMonthFollowCount'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
getDashboardBrief({
|
||||||
const params = ['joinUserId=23'];
|
joinUserId: '23',
|
||||||
keys.forEach((key) => {
|
keys
|
||||||
params.push(`keys=${encodeURIComponent(key)}`);
|
|
||||||
});
|
|
||||||
const queryString = params.join('&');
|
|
||||||
|
|
||||||
|
|
||||||
uni.$uv.http.get(`dashboard/brief?${queryString}`, {
|
|
||||||
custom: {
|
|
||||||
auth: true // 启用 token 认证
|
|
||||||
}
|
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
console.log('dashboard/brief 接口返回:', res);
|
console.log('dashboard/brief 接口返回:', res);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user