修正了 pages 名为拼音的问题
This commit is contained in:
103
pages/fighter-rules/fighter-rules.js
Normal file
103
pages/fighter-rules/fighter-rules.js
Normal file
@@ -0,0 +1,103 @@
|
||||
Page({
|
||||
onShow() {
|
||||
// 原有代码...
|
||||
|
||||
// 🆕 注册通知组件
|
||||
this.registerNotificationComponent();
|
||||
},
|
||||
|
||||
// 🆕 新增:注册通知组件
|
||||
registerNotificationComponent() {
|
||||
const app = getApp();
|
||||
const notificationComp = this.selectComponent('#global-notification');
|
||||
|
||||
if (notificationComp && notificationComp.showNotification) {
|
||||
console.log('🏪 商城页面注册通知组件');
|
||||
app.globalData.globalNotification = {
|
||||
show: (data) => notificationComp.showNotification(data),
|
||||
hide: () => notificationComp.hideNotification()
|
||||
};
|
||||
}
|
||||
},
|
||||
data: {
|
||||
// 图片URL(带时间戳避免缓存)
|
||||
imageUrl: '',
|
||||
// 容器高度(初始为100vh,加载后调整为图片高度)
|
||||
containerHeight: 0
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 初始设置容器高度为屏幕高度
|
||||
this.getSystemInfo()
|
||||
// 构建图片URL(带时间戳)
|
||||
this.buildImageUrl()
|
||||
},
|
||||
|
||||
// 获取系统信息
|
||||
getSystemInfo() {
|
||||
const res = wx.getSystemInfoSync()
|
||||
this.setData({
|
||||
containerHeight: res.windowHeight
|
||||
})
|
||||
},
|
||||
|
||||
// 构建图片URL(关键:加时间戳避免缓存)
|
||||
buildImageUrl() {
|
||||
const app = getApp()
|
||||
const ossImageUrl = app.globalData.ossImageUrl || ''
|
||||
const dashouguize = app.globalData.dashouguize || ''
|
||||
|
||||
// 加上时间戳参数,强制每次重新加载
|
||||
const timestamp = new Date().getTime()
|
||||
const fullImageUrl = ossImageUrl + dashouguize + '?t=' + timestamp
|
||||
|
||||
//console.log('规则图片URL(带时间戳):', fullImageUrl)
|
||||
|
||||
this.setData({
|
||||
imageUrl: fullImageUrl
|
||||
})
|
||||
},
|
||||
|
||||
// 图片加载成功
|
||||
onImageLoad(e) {
|
||||
//console.log('图片加载成功,原始尺寸:', e.detail.width, 'x', e.detail.height)
|
||||
|
||||
// 根据图片实际高度设置容器高度
|
||||
// 图片宽度为屏幕宽度,高度按比例计算
|
||||
const systemInfo = wx.getSystemInfoSync()
|
||||
const screenWidth = systemInfo.screenWidth // 单位:px
|
||||
|
||||
// 图片的实际像素尺寸
|
||||
const imageWidth = e.detail.width
|
||||
const imageHeight = e.detail.height
|
||||
|
||||
// 计算在小程序中显示的高度(保持比例)
|
||||
// 图片在小程序中宽度为100%屏幕宽度,高度按比例缩放
|
||||
const displayHeight = (imageHeight / imageWidth) * screenWidth
|
||||
|
||||
//console.log('计算后显示高度:', displayHeight, 'px')
|
||||
|
||||
// 设置容器高度为图片高度
|
||||
this.setData({
|
||||
containerHeight: displayHeight
|
||||
})
|
||||
},
|
||||
|
||||
// 图片加载失败
|
||||
onImageError() {
|
||||
console.error('图片加载失败')
|
||||
wx.showToast({
|
||||
title: '图片加载失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
},
|
||||
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
// 重新构建图片URL(带新时间戳)
|
||||
this.buildImageUrl()
|
||||
// 停止下拉刷新
|
||||
wx.stopPullDownRefresh()
|
||||
}
|
||||
})
|
||||
11
pages/fighter-rules/fighter-rules.json
Normal file
11
pages/fighter-rules/fighter-rules.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"global-notification": "/components/global-notification/global-notification"
|
||||
},
|
||||
"navigationBarTitleText": "用户规则",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"navigationBarTextStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"enablePullDownRefresh": false,
|
||||
"backgroundTextStyle": "dark"
|
||||
}
|
||||
12
pages/fighter-rules/fighter-rules.wxml
Normal file
12
pages/fighter-rules/fighter-rules.wxml
Normal file
@@ -0,0 +1,12 @@
|
||||
<!-- 打手规则页面 - 图片完整覆盖 -->
|
||||
<view class="container" style="height:{{containerHeight}}px">
|
||||
<image
|
||||
src="{{ imageUrl }}"
|
||||
mode="widthFix"
|
||||
class="rule-image"
|
||||
bindload="onImageLoad"
|
||||
binderror="onImageError"
|
||||
style="width:100%;height:auto"
|
||||
></image>
|
||||
</view>
|
||||
<global-notification id="global-notification" />
|
||||
15
pages/fighter-rules/fighter-rules.wxss
Normal file
15
pages/fighter-rules/fighter-rules.wxss
Normal file
@@ -0,0 +1,15 @@
|
||||
/* 页面容器 */
|
||||
.container {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
overflow-y: auto;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
/* 规则图片样式 - 绝对定位,从顶部开始 */
|
||||
.rule-image {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: block;
|
||||
}
|
||||
Reference in New Issue
Block a user