后端:公告√
注意数据库新建notice表
This commit is contained in:
@@ -28,7 +28,10 @@
|
||||
<!-- 公告栏:自动轮播,可点击查看详情 -->
|
||||
<view class="notice">
|
||||
<view class="notice-left">公告</view>
|
||||
<swiper class="notice-swiper" circular autoplay interval="4000" duration="400" vertical>
|
||||
<view v-if="loadingNotices" class="notice-swiper" style="display:flex;align-items:center;color:#6b5a2a;">加载中...</view>
|
||||
<view v-else-if="noticeError" class="notice-swiper" style="display:flex;align-items:center;color:#dd524d;">{{ noticeError }}</view>
|
||||
<view v-else-if="!notices.length" class="notice-swiper" style="display:flex;align-items:center;color:#6b5a2a;">暂无公告</view>
|
||||
<swiper v-else class="notice-swiper" circular autoplay interval="4000" duration="400" vertical>
|
||||
<swiper-item v-for="(n, idx) in notices" :key="idx">
|
||||
<view class="notice-item" @click="onNoticeTap(n)">
|
||||
<text class="notice-text">{{ n.text }}</text>
|
||||
@@ -77,6 +80,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { get } from '../../common/http.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -84,12 +88,9 @@
|
||||
monthProfit: '0.00',
|
||||
stockQty: '0.00',
|
||||
activeTab: 'home',
|
||||
notices: [
|
||||
{ text: '选材精工:不锈钢、合金钢,耐腐蚀更耐用', tag: '品质' },
|
||||
{ text: '表面工艺:电镀锌/镀镍/发黑处理,性能均衡', tag: '工艺' },
|
||||
{ text: '库存齐全:螺丝、螺母、垫圈、膨胀螺栓等现货', tag: '库存' },
|
||||
{ text: '企业采购支持:批量优惠,次日发货', tag: '服务' }
|
||||
],
|
||||
notices: [],
|
||||
loadingNotices: false,
|
||||
noticeError: '',
|
||||
features: [
|
||||
{ key: 'customer', title: '客户', img: '/static/icons/customer.png', emoji: '👥' },
|
||||
{ key: 'sale', title: '销售', img: '/static/icons/sale.png', emoji: '💰' },
|
||||
@@ -103,7 +104,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.fetchNotices()
|
||||
},
|
||||
methods: {
|
||||
async fetchNotices() {
|
||||
this.loadingNotices = true
|
||||
this.noticeError = ''
|
||||
try {
|
||||
const list = await get('/api/notices')
|
||||
this.notices = Array.isArray(list) ? list.map(n => ({
|
||||
text: n.content || n.title || '',
|
||||
tag: n.tag || ''
|
||||
})) : []
|
||||
} catch (e) {
|
||||
this.noticeError = (e && e.message) || '公告加载失败'
|
||||
} finally {
|
||||
this.loadingNotices = false
|
||||
}
|
||||
},
|
||||
onFeatureTap(item) {
|
||||
uni.showToast({ title: item.title + '(开发中)', icon: 'none' })
|
||||
},
|
||||
@@ -113,7 +132,7 @@
|
||||
onNoticeTap(n) {
|
||||
uni.showModal({
|
||||
title: '公告',
|
||||
content: n.text,
|
||||
content: n && (n.text || n.title || n.content) || '',
|
||||
showCancel: false
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user