第一次提交:微信小程序前端最新完整代码
This commit is contained in:
90
pages/guanzhual/guanzhual.js
Normal file
90
pages/guanzhual/guanzhual.js
Normal file
@@ -0,0 +1,90 @@
|
||||
// pages/guanzhual/guanzhual.js
|
||||
const app = getApp()
|
||||
import request from '../../utils/request.js'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
images: [], // 图片完整URL列表
|
||||
lastUpdate: '', // 最新更新时间
|
||||
visitCount: 0, // 浏览次数
|
||||
loading: true, // 加载中
|
||||
ossImageUrl: '' // OSS基础地址
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 获取OSS地址
|
||||
this.setData({
|
||||
ossImageUrl: app.globalData.ossImageUrl || ''
|
||||
})
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.registerNotificationComponent()
|
||||
},
|
||||
|
||||
// 注册全局通知组件
|
||||
registerNotificationComponent() {
|
||||
const notificationComp = this.selectComponent('#global-notification')
|
||||
if (notificationComp && notificationComp.showNotification) {
|
||||
app.globalData.globalNotification = {
|
||||
show: (data) => notificationComp.showNotification(data),
|
||||
hide: () => notificationComp.hideNotification()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 加载数据
|
||||
loadData() {
|
||||
this.setData({ loading: true })
|
||||
|
||||
request({
|
||||
url: '/peizhi/gzal',
|
||||
method: 'POST',
|
||||
header: { 'content-type': 'application/json' }
|
||||
})
|
||||
.then(res => {
|
||||
if (res && res.data && res.data.code === 0) {
|
||||
const data = res.data.data || {}
|
||||
const ossImageUrl = this.data.ossImageUrl
|
||||
// 拼接完整URL
|
||||
const fullImages = (data.images || []).map(url => {
|
||||
if (url && !url.startsWith('http')) {
|
||||
return ossImageUrl + url
|
||||
}
|
||||
return url
|
||||
})
|
||||
this.setData({
|
||||
images: fullImages,
|
||||
lastUpdate: data.last_update || '',
|
||||
visitCount: data.visit_count || 0,
|
||||
loading: false
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: res?.data?.msg || '加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('加载关注阿龙数据失败', err)
|
||||
wx.showToast({
|
||||
title: '网络错误',
|
||||
icon: 'none'
|
||||
})
|
||||
this.setData({ loading: false })
|
||||
})
|
||||
},
|
||||
|
||||
// 图片加载成功(可选)
|
||||
onImageLoad(e) {
|
||||
// 可忽略
|
||||
},
|
||||
|
||||
// 图片加载失败
|
||||
onImageError(e) {
|
||||
console.warn('图片加载失败', e)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user