添加api文件

This commit is contained in:
kron
2025-05-10 22:25:06 +08:00
parent 11c373f13e
commit aff7a2d3f6
2 changed files with 39 additions and 1 deletions

21
src/apis.js Normal file
View File

@@ -0,0 +1,21 @@
const BASE_URL = "http://120.79.241.5:8000/api/shoot/index";
// 获取全局配置
export const getAppConfig = () => {
return new Promise((resolve, reject) => {
uni.request({
url: `${BASE_URL}/appConfig`,
method: "GET",
success: (res) => {
resolve(res.data);
},
fail: (err) => {
reject(err);
uni.showToast({
title: "获取配置失败",
icon: "none",
});
},
});
});
};

View File

@@ -1,8 +1,9 @@
<script setup>
import { ref } from "vue";
import { ref, onMounted } from "vue";
import AppFooter from "@/components/AppFooter.vue";
import AppBackground from "@/components/AppBackground.vue";
import UserHeader from "@/components/UserHeader.vue";
import { getAppConfig } from '@/apis'
const userInfo = ref({
name: "打酱油·路过",
@@ -38,6 +39,22 @@ const toQquipmentPage = () => {
url: "/pages/equipment-debug",
});
};
// 获取全局配置
const getConfig = async () => {
try {
const config = await getAppConfig()
console.log('全局配置:', config)
// 这里可以处理配置数据
} catch (error) {
console.error('获取配置失败:', error)
}
}
// 页面加载完成后检查本地存储的用户信息并获取配置
onMounted(() => {
getConfig();
});
</script>
<template>