diff --git a/api/article/article.js b/api/article/article.js index 7e45014..22e7206 100644 --- a/api/article/article.js +++ b/api/article/article.js @@ -47,3 +47,22 @@ export function getPrivacyPolicy() { }, }) } + +/** + * 获取最新公告 + * @param {Object} params - 查询参数 + * @param {string} params.appId - 应用ID,默认为1 + * @param {string} params.type - 类型,4表示公告 + * @returns {Promise} 返回最新公告数据 + */ +export function getNewAnnouncement(params = {}) { + return request({ + url: '/app/article/getNew', + method: 'GET', + params: { + appId: '1', + type: '4', + ...params, + }, + }) +} diff --git a/config/dev.js b/config/dev.js index b38ac16..fa484ce 100644 --- a/config/dev.js +++ b/config/dev.js @@ -2,7 +2,7 @@ export const DEV_CONFIG = { // 临时token,用于开发测试 TEMP_TOKEN: - 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImY3OTUyZDY4LTI3NWItNDQ2ZS1iNjAwLWZkNGFiYmVkZjkyYSJ9.Nw8an_L7efznUuF3NdFrpCOOlK5xLGcgQ6xhAwat8kxiNkmDLsgJ3rprFD_o3yueApzomDj1vZSOMLcEsBa8Dg', + ' eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImVmZmVjZjk4LWUzZWMtNDY4YS04Y2VlLTcyMjUyOTllOGI2OSJ9.4u5ypyRjZCiQr-E02MJ2UQ0dV-PGK-s402Ex7CtAIO_8YDaUoQ0MTmwfFqS2IZenlrB7H5RB80P__U9zXB68Pg', // 是否使用临时token USE_TEMP_TOKEN: true, diff --git a/pages/index/index.vue b/pages/index/index.vue index 4c39415..4ddc734 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -39,6 +39,7 @@ import commonEnum from '../../enum/commonEnum' import AnnouncementBar from '../../components/announcement-bar/announcement-bar.vue' import BannerSwiper from '../../components/banner-swiper/banner-swiper.vue' import EquipmentList from '../../components/equipment-list/equipment-list.vue' +import { getNewAnnouncement } from '../../api/article/article.js' export default { components: { @@ -58,6 +59,7 @@ export default { // 页面数据 companyName: '福鼎创特物联科技有限公司', announcementText: '暂无更多公告! 暂无更多公告! 暂无更多公告!', + currentAnnouncement: null, // 当前公告数据 equipmentTitle: '我的租赁设备', navItems: ['首页', '申请租赁', '个人中心'], activeNavIndex: 0, @@ -101,7 +103,29 @@ export default { } }, + // 生命周期钩子 + onLoad() { + this.fetchAnnouncement() + }, + methods: { + // 获取最新公告 + async fetchAnnouncement() { + try { + const response = await getNewAnnouncement() + if (response.code === 200 && response.data) { + this.currentAnnouncement = response.data + // 更新公告文本,去除HTML标签 + const content = response.data.content || '' + const plainText = content.replace(/<[^>]*>/g, '') + this.announcementText = response.data.title || plainText || '暂无更多公告!' + } + } catch (error) { + console.error('获取公告失败:', error) + this.announcementText = '暂无更多公告!' + } + }, + // 头部点击事件 onLocationClick() { uni.showToast({ @@ -112,10 +136,22 @@ export default { // 公告栏点击事件 onAnnouncementClick() { - uni.showToast({ - title: '查看公告详情', - icon: 'none', - }) + if (this.currentAnnouncement) { + // 显示公告详情 + uni.showModal({ + title: this.currentAnnouncement.title || '公告详情', + content: this.currentAnnouncement.content ? + this.currentAnnouncement.content.replace(/<[^>]*>/g, '') : + '暂无公告内容', + showCancel: false, + confirmText: '知道了' + }) + } else { + uni.showToast({ + title: '暂无公告', + icon: 'none', + }) + } }, // 轮播图变化事件