修改所有vue文件中的环境变量调用
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<script setup lang="ts">
|
||||
import HomeView from '@/views/HomeView.vue'
|
||||
import FooterView from './component/FooterView.vue';
|
||||
console.log("基础api:",import.meta.env.VITE_API_BASE_URL);
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -323,7 +323,8 @@ interface SpeakerListResponse {
|
||||
const isAllMeetingsPage = ref(false) // 控制显示会议列表页还是主页面
|
||||
|
||||
// 基础配置 - 固定baseurl
|
||||
const baseUrl = 'http://localhost:8080/api'
|
||||
const baseUrl = import.meta.env.VITE_API_BASE_URL;
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
|
||||
// 顶部横幅封面图URL
|
||||
const pageImageUrl = ref('')
|
||||
@@ -376,7 +377,7 @@ const currentSpeaker = ref<Speaker>({
|
||||
// 从后端获取封面图
|
||||
const fetchCoverImage = async () => {
|
||||
try {
|
||||
const response = await axios.post('http://localhost:8080/api/page-image/get', { page: 'AcademicExchange' });
|
||||
const response = await axios.post(`${API_BASE_URL}/page-image/get`, { page: 'AcademicExchange' });
|
||||
if (response.data.message === '查询成功' && response.data.images && response.data.images.length > 0) {
|
||||
pageImageUrl.value = response.data.images[0].image_url;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, onMounted, computed, watch } from 'vue';
|
||||
import { ref, reactive, onMounted, computed } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
@@ -149,11 +149,11 @@ onMounted(() => {
|
||||
fetchCoverImage();
|
||||
fetchBaseInfo();
|
||||
});
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
// 从后端获取封面图
|
||||
const fetchCoverImage = async () => {
|
||||
try {
|
||||
const response = await axios.post('http://localhost:8080/api/page-image/get', { page: 'BaseOverview' });
|
||||
const response = await axios.post(`${API_BASE_URL}/page-image/get`, { page: 'BaseOverview' });
|
||||
if (response.data.message === '查询成功') {
|
||||
pageImageUrl.value = response.data.images[0].image_url;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ const fetchCoverImage = async () => {
|
||||
// 从后端获取基地概况信息并绑定到页面
|
||||
const fetchBaseInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8080/api/base-overview');
|
||||
const response = await axios.get(`${API_BASE_URL}/base-overview`);
|
||||
if (response.data.success) {
|
||||
Object.assign(baseInfo, response.data.data);
|
||||
} else {
|
||||
|
||||
@@ -629,9 +629,9 @@ const initOnlineCourses = async () => {
|
||||
initCourses.value = onlineCourses.value.slice(0, 3);
|
||||
} catch { errorMsg.value = '加载失败'; } finally { loadingInit.value = false; }
|
||||
};
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
const fetchCoursePage = async (page: number, keyword: string): Promise<ApiResponse<Course>> => {
|
||||
const { data } = await axios.post<ApiResponse<Course>>('http://localhost:8080/api/courses/list', {
|
||||
const { data } = await axios.post<ApiResponse<Course>>(`${API_BASE_URL}/courses/list`, {
|
||||
page, size: pageSize.value, status: 1, keyword: keyword || ''
|
||||
});
|
||||
if (!data?.list) throw new Error();
|
||||
@@ -680,7 +680,7 @@ const initCases = async () => {
|
||||
};
|
||||
|
||||
const fetchCasePage = async (page: number, keyword: string): Promise<ApiResponse<TeachingCase>> => {
|
||||
const { data } = await axios.post<ApiResponse<TeachingCase>>('http://localhost:8080/api/teaching-cases/list', {
|
||||
const { data } = await axios.post<ApiResponse<TeachingCase>>(`${API_BASE_URL}/teaching-cases/list`, {
|
||||
page, size: caseSize, keyword: keyword || '', sort: 0
|
||||
});
|
||||
if (!data?.list || typeof data.total !== 'number') throw new Error();
|
||||
@@ -727,7 +727,7 @@ const initVideos = async () => {
|
||||
};
|
||||
|
||||
const fetchVideoPage = async (page: number, keyword: string): Promise<ApiResponse<VideoCase>> => {
|
||||
const { data } = await axios.post<ApiResponse<VideoCase>>('http://localhost:8080/api/video-cases/list', {
|
||||
const { data } = await axios.post<ApiResponse<VideoCase>>(`${API_BASE_URL}/video-cases/list`, {
|
||||
page, size: videoSize, keyword: keyword || '', sort: 0
|
||||
});
|
||||
if (!data?.list || typeof data.total !== 'number') throw new Error();
|
||||
@@ -764,7 +764,7 @@ const backToVideoList = () => { playingVideo.value = null; };
|
||||
const fetchCourseContent = async (id: number) => {
|
||||
loadingChapters.value = true;
|
||||
try {
|
||||
const { data } = await axios.post<ApiResponse<Chapter>>('http://localhost:8080/api/course-content/list', { course_id: id, parent_id: 0 });
|
||||
const { data } = await axios.post<ApiResponse<Chapter>>(`${API_BASE_URL}/course-content/list`, { course_id: id, parent_id: 0 });
|
||||
if (data.code === 0 && Array.isArray(data.data)) {
|
||||
courseChapters.value = data.data.sort((a: Chapter, b: Chapter) => a.sort - b.sort);
|
||||
courseChapters.value.forEach(c => chapters.value[c.id] = { expanded: false });
|
||||
@@ -789,7 +789,7 @@ const fetchResources = async (page = 1, reset = false) => {
|
||||
loadingMoreResources.value = true;
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.post<ApiResponse<Resource>>('http://localhost:8080/api/course-resource/list', {
|
||||
const { data } = await axios.post<ApiResponse<Resource>>(`${API_BASE_URL}/course-resource/list`, {
|
||||
course_id: selectedCourse.value.id,
|
||||
page,
|
||||
page_size: resourcePageSize
|
||||
@@ -826,7 +826,7 @@ const fetchActivities = async (page = 1, reset = false) => {
|
||||
loadingMoreActivities.value = true;
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.post<ApiResponse<Activity>>('http://localhost:8080/api/course-activity/list', {
|
||||
const { data } = await axios.post<ApiResponse<Activity>>(`${API_BASE_URL}/course-activity/list`, {
|
||||
course_id: selectedCourse.value.id,
|
||||
page,
|
||||
page_size: activityPageSize
|
||||
@@ -863,7 +863,7 @@ const fetchTeachers = async (page = 1, reset = false) => {
|
||||
loadingMoreTeachers.value = true;
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.post<ApiResponse<Teacher>>('http://localhost:8080/api/course-teacher/list', {
|
||||
const { data } = await axios.post<ApiResponse<Teacher>>(`${API_BASE_URL}/course-teacher/list`, {
|
||||
course_id: selectedCourse.value.id,
|
||||
page,
|
||||
page_size: teacherPageSize
|
||||
|
||||
@@ -233,12 +233,15 @@ function formatDate(dateStr?: string): string {
|
||||
const date = new Date(dateStr);
|
||||
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
|
||||
}
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
onMounted(()=>{
|
||||
console.log(API_BASE_URL);
|
||||
})
|
||||
// 新闻数据请求
|
||||
const fetchArticlesByTopic = async (topic: string): Promise<NewsItem[]> => {
|
||||
const loading = ElLoading.service({ text: '加载中...' });
|
||||
try {
|
||||
const response = await fetch('http://localhost:8080/api/articles/getarticle', {
|
||||
const response = await fetch(`${API_BASE_URL}/articles/getarticle`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ page: 1, size: 4, topic })
|
||||
@@ -272,7 +275,7 @@ const fetchTeachingCases = async (): Promise<NewsItem[]> => {
|
||||
const loading = ElLoading.service({ text: '加载中...' });
|
||||
try {
|
||||
const response = await axios.post<CaseResponse>(
|
||||
'http://localhost:8080/api/teaching-cases/list',
|
||||
`${API_BASE_URL}/teaching-cases/list`,
|
||||
{ page: 1, size: 20, keyword: "", sort: 0 }
|
||||
);
|
||||
|
||||
@@ -300,7 +303,7 @@ const fetchSocialServices = async (): Promise<NewsItem[]> => {
|
||||
const loading = ElLoading.service({ text: '加载中...' });
|
||||
try {
|
||||
const response = await axios.post<SocialServiceResponse>(
|
||||
'http://localhost:8080/api/social-service/list',
|
||||
`${API_BASE_URL}/social-service/list`,
|
||||
{ page: 1, page_size: 20 }
|
||||
);
|
||||
|
||||
@@ -345,14 +348,14 @@ onMounted(async () => {
|
||||
|
||||
// 轮播图数据
|
||||
const defaultTitles = [
|
||||
'健康生活环境设计研究成果展',
|
||||
'2025健康设计国际学术研讨会',
|
||||
'社区健康服务创新实践'
|
||||
'',
|
||||
'',
|
||||
''
|
||||
];
|
||||
const defaultDescs = [
|
||||
'探索健康设计新路径,引领人居环境创新',
|
||||
'汇聚全球专家智慧,共话健康人居未来',
|
||||
'以设计赋能社区,提升居民生活品质'
|
||||
'',
|
||||
'',
|
||||
''
|
||||
];
|
||||
|
||||
interface CarouselImage {
|
||||
@@ -368,7 +371,7 @@ const carouselImages = ref<CarouselImage[]>([]);
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
'http://localhost:8080/api/page-image/get',
|
||||
`${API_BASE_URL}/page-image/get`,
|
||||
{ page: 'home' }
|
||||
);
|
||||
if (response.data.message === '查询成功') {
|
||||
|
||||
@@ -133,11 +133,11 @@ onMounted(() => {
|
||||
fetchCoverImage();
|
||||
fetchResearchInfo();
|
||||
});
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
// 从后端获取封面图
|
||||
const fetchCoverImage = async () => {
|
||||
try {
|
||||
const response = await axios.post('http://localhost:8080/api/page-image/get', { page: 'ScientificResearch' });
|
||||
const response = await axios.post(`${API_BASE_URL}/page-image/get`, { page: 'ScientificResearch' });
|
||||
if (response.data.message === '查询成功') {
|
||||
pageImageUrl.value = response.data.images[0].image_url;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ const fetchCoverImage = async () => {
|
||||
// 从后端获取科学研究相关信息
|
||||
const fetchResearchInfo = async () => {
|
||||
try {
|
||||
const response = await axios.get('http://localhost:8080/api/devproject/get');
|
||||
const response = await axios.get(`${API_BASE_URL}/devproject/get`);
|
||||
if (response.data.message === '查询成功' && response.data.dev_project) {
|
||||
// 将接口返回的dev_project数据赋值给researchInfo
|
||||
Object.assign(researchInfo, response.data.dev_project);
|
||||
|
||||
@@ -179,7 +179,7 @@ import axios from 'axios';
|
||||
import { ElMessage, ElPagination, ElConfigProvider } from 'element-plus';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
|
||||
const base_url = 'http://localhost:8080/api';
|
||||
const base_url = import.meta.env.VITE_API_BASE_URL;
|
||||
|
||||
// 定义图片项类型
|
||||
interface ImageItem {
|
||||
|
||||
@@ -133,6 +133,8 @@ import axios from 'axios';
|
||||
import { ElIcon, ElButton } from 'element-plus';
|
||||
import { Loading, WarningFilled } from '@element-plus/icons-vue';
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
|
||||
// 状态管理
|
||||
const route = useRoute();
|
||||
const isLoading = ref(false); // 加载状态
|
||||
@@ -169,13 +171,13 @@ const fetchDetail = async () => {
|
||||
let apiUrl = '';
|
||||
switch (type) {
|
||||
case 'case':
|
||||
apiUrl = `http://localhost:8080/api/teaching-cases/${id}`;
|
||||
apiUrl = `${API_BASE_URL}/teaching-cases/${id}`;
|
||||
break;
|
||||
case 'service':
|
||||
apiUrl = `http://localhost:8080/api/social-service/${id}`;
|
||||
apiUrl = `${API_BASE_URL}/social-service/${id}`;
|
||||
break;
|
||||
case 'news':
|
||||
apiUrl = `http://localhost:8080/api/articles/${id}`;
|
||||
apiUrl = `${API_BASE_URL}/articles/${id}`;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,13 +123,13 @@ function formatDate(dateStr: string): string {
|
||||
const date = new Date(dateStr);
|
||||
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
|
||||
}
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
|
||||
// 获取新闻数据(支持分页)
|
||||
const fetchNewsData = async () => {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
const response = await axios.post<ArticleResponse>(
|
||||
'http://localhost:8080/api/articles/getarticle',
|
||||
`${API_BASE_URL}/articles/getarticle`,
|
||||
{
|
||||
page: currentPage.value,
|
||||
size: pageSize.value,
|
||||
|
||||
Reference in New Issue
Block a user