feat: 接入三tab导航(首页/中奖记录/我的)、活动规则静态页、奖品详情弹窗;接口切换hnlylaw并透传authorization;缓存键统一Sft后缀;问卷ID切1005;注册增加收货地址;答题计时精确到0.01s及交互优化

This commit is contained in:
lcj
2026-10-30 09:47:31 +08:00
parent 305e22ddc5
commit ead48745c2
21 changed files with 1583 additions and 273 deletions
+309
View File
@@ -0,0 +1,309 @@
<template>
<view class="content">
<view class="page-header">
<text class="header-back" @tap="goBack">‹</text>
<text class="header-title">{{ current.title }}</text>
<text class="header-index">{{ currentIndex + 1 }} / {{ articles.length }}</text>
</view>
<view class="preview-wrap">
<view class="loading-box" v-if="loading">
<u-loading mode="circle" size="40"></u-loading>
<text class="loading-text">内容加载中...</text>
</view>
<scroll-view class="doc-scroll" scroll-y v-if="!loading && !error">
<rich-text class="doc-content" :nodes="htmlContent"></rich-text>
<view style="height:30rpx;"></view>
</scroll-view>
<view class="error-box" v-if="error">
<text class="error-text">{{ error }}</text>
<button class="preview-btn" @tap="loadArticle">重新加载</button>
</view>
</view>
<view class="page-footer">
<button class="nav-btn prev" :disabled="currentIndex <= 0" @tap="prev">上一篇</button>
<button class="nav-btn next" :disabled="currentIndex >= articles.length - 1" @tap="next">下一篇</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
articles: [
{
title: '中华人民共和国宪法',
url: 'https://goldnar.hntgov.net/img/word8.docx'
},
{
title: '中华人民共和国民法典',
url: 'https://goldnar.hntgov.net/img/word4.docx'
},
{
title: '中华人民共和国行政复议法实施条例',
url: 'https://goldnar.hntgov.net/img/word20.docx'
},
{
title: '优化营商环境条例',
url: 'https://goldnar.hntgov.net/img/word22.docx'
}
],
currentIndex: 0,
loading: false,
error: '',
htmlContent: ''
}
},
computed: {
current() {
return this.articles[this.currentIndex] || {}
}
},
onLoad(options) {
const idx = parseInt(options.index)
if (!isNaN(idx) && idx >= 0 && idx < this.articles.length) {
this.currentIndex = idx
} else {
this.currentIndex = 0
}
},
onReady() {
this.loadArticle()
},
methods: {
goBack() {
uni.navigateBack()
},
prev() {
if (this.currentIndex > 0) {
this.currentIndex--
this.loadArticle()
}
},
next() {
if (this.currentIndex < this.articles.length - 1) {
this.currentIndex++
this.loadArticle()
}
},
loadArticle() {
this.loading = true
this.error = ''
this.htmlContent = ''
this.ensureMammoth().then(() => {
return this.fetchDocx(this.current.url)
}).then(arrayBuffer => {
return window.mammoth.convertToHtml({ arrayBuffer })
}).then(result => {
this.htmlContent = result.value || ''
this.loading = false
}).catch(err => {
console.error('加载文档失败', err)
this.loading = false
this.error = '文档加载失败,请重试'
})
},
ensureMammoth() {
if (window.mammoth) return Promise.resolve()
return new Promise((resolve, reject) => {
const urls = [
'/static/mammoth.browser.min.js',
'https://unpkg.com/mammoth@1.6.0/mammoth.browser.min.js'
]
let i = 0
const loadNext = () => {
if (i >= urls.length) {
reject(new Error('解析组件加载失败'))
return
}
const s = document.createElement('script')
s.src = urls[i++]
s.onload = () => window.mammoth ? resolve() : loadNext()
s.onerror = loadNext
document.head.appendChild(s)
}
loadNext()
})
},
fetchDocx(url) {
return new Promise((resolve, reject) => {
if (typeof fetch !== 'undefined') {
fetch(url).then(res => {
if (!res.ok) throw new Error('HTTP ' + res.status)
return res.arrayBuffer()
}).then(resolve).catch(() => this.downloadDocx(url).then(resolve).catch(reject))
return
}
this.downloadDocx(url).then(resolve).catch(reject)
})
},
downloadDocx(url) {
return new Promise((resolve, reject) => {
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode !== 200) {
reject(new Error('下载失败'))
return
}
uni.getFileSystemManager().readFile({
filePath: res.tempFilePath,
success: (r) => resolve(r.data),
fail: () => {
if (res.tempFilePath && typeof fetch !== 'undefined') {
fetch(res.tempFilePath).then(r => r.arrayBuffer()).then(resolve).catch(reject)
} else {
reject(new Error('读取文件失败'))
}
}
})
},
fail: reject
})
})
}
}
}
</script>
<style lang="scss">
page {
background-color: #F8F8F8;
}
.content {
position: relative;
display: flex;
flex-direction: column;
}
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 30rpx;
background: linear-gradient(135deg, #FD5401, #FF7A3D);
flex-shrink: 0;
}
.header-back {
font-size: 48rpx;
color: #fff;
line-height: 1;
margin-right: 16rpx;
padding: 0 10rpx;
}
.header-title {
font-size: 30rpx;
font-weight: 600;
color: #fff;
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.header-index {
font-size: 24rpx;
color: rgba(255,255,255,0.8);
margin-left: 20rpx;
}
.preview-wrap {
flex: 1;
background: #fff;
overflow: hidden;
padding-bottom: 100rpx;
}
.loading-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.loading-text {
font-size: 26rpx;
color: #999;
margin-top: 20rpx;
}
.error-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.error-text {
font-size: 26rpx;
color: #999;
margin-bottom: 30rpx;
}
.preview-btn {
width: 300rpx;
height: 76rpx;
line-height: 76rpx;
background: linear-gradient(135deg, #FD5401, #FF7A3D);
color: #fff;
font-size: 28rpx;
font-weight: 600;
border: none;
border-radius: 38rpx;
}
.doc-scroll {
height: 100%;
padding: 20rpx 30rpx;
box-sizing: border-box;
}
.doc-content {
font-size: 28rpx;
color: #333;
line-height: 1.8;
}
.page-footer {
display: flex;
gap: 24rpx;
padding: 20rpx 30rpx;
position: fixed;
bottom: 0rpx;
width: 750rpx;
background: #fff;
flex-shrink: 0;
border-top: 1rpx solid #f0f0f0;
}
.nav-btn {
flex: 1;
height: 76rpx;
line-height: 76rpx;
font-size: 28rpx;
font-weight: 600;
border: none;
border-radius: 38rpx;
margin: 0;
}
.nav-btn.prev {
background: #f5f5f5;
color: #333;
}
.nav-btn.next {
background: linear-gradient(135deg, #FD5401, #FF7A3D);
color: #fff;
}
.nav-btn[disabled] {
opacity: 0.4;
color: #999;
}
</style>