获取最新公告,当公告栏显示公告title

This commit is contained in:
WindowBird 2025-08-18 17:49:55 +08:00
parent 2a4d00a50a
commit 1d4aa8cb67
3 changed files with 60 additions and 5 deletions

View File

@ -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,
},
})
}

View File

@ -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,

View File

@ -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',
})
}
},
//