index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <!-- 系统通知 -->
  2. <template>
  3. <view class="sys-notice-page">
  4. <view class="sys-notice-nav" :style="{ paddingTop: statusBar + 'px' }">
  5. <view class="sys-notice-nav-row">
  6. <view class="sys-notice-back" @tap="goBack">
  7. <text class="sys-notice-back-icon">←</text>
  8. </view>
  9. <text class="sys-notice-nav-title">{{ copy.title }}</text>
  10. <view class="sys-notice-nav-placeholder" />
  11. </view>
  12. </view>
  13. <scroll-view
  14. scroll-y
  15. class="sys-notice-scroll"
  16. :style="{ height: scrollHeight + 'px' }"
  17. :lower-threshold="120"
  18. @scrolltolower="onScrollToLower"
  19. >
  20. <view class="sys-notice-body" :style="{ paddingBottom: safeBottom + 'px' }">
  21. <view v-if="loading && !rows.length" class="sys-notice-state">
  22. <text class="sys-notice-state-txt">{{ copy.loading }}</text>
  23. </view>
  24. <empty
  25. v-else-if="loaded && !rows.length"
  26. src="notice_default3x"
  27. :text="copy.empty"
  28. />
  29. <view v-else class="sys-notice-list">
  30. <view
  31. v-for="(item, index) in rows"
  32. :key="item.id || index"
  33. class="sys-notice-group"
  34. >
  35. <view v-if="item.createtime_text" class="sys-notice-time">
  36. <text class="sys-notice-time-txt">{{ item.createtime_text }}</text>
  37. </view>
  38. <view class="sys-notice-card" @tap="openDetail(item)">
  39. <view v-if="coverUrl(item)" class="sys-notice-cover-wrap">
  40. <image
  41. class="sys-notice-cover"
  42. :src="coverUrl(item)"
  43. mode="aspectFill"
  44. />
  45. <view class="sys-notice-cover-fade" />
  46. </view>
  47. <view class="sys-notice-card-body">
  48. <view class="sys-notice-badge-row">
  49. <text class="sys-notice-badge">{{ copy.badge }}</text>
  50. </view>
  51. <text class="sys-notice-title">{{ item.title || copy.untitled }}</text>
  52. <text
  53. v-if="item.description"
  54. class="sys-notice-desc"
  55. >{{ item.description }}</text>
  56. <view class="sys-notice-foot">
  57. <text class="sys-notice-more">{{ copy.readMore }}</text>
  58. <text class="sys-notice-arrow">›</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <uni-load-more
  65. v-if="rows.length"
  66. :status="loadStatus"
  67. :content-text="loadMoreContent"
  68. />
  69. </view>
  70. </scroll-view>
  71. </view>
  72. </template>
  73. <script>
  74. import { fetchSystemNoticePage } from '@/features/notice/notice-gateway'
  75. export default {
  76. name: 'SysNoticePage',
  77. data() {
  78. return {
  79. statusBar: 0,
  80. scrollHeight: 600,
  81. safeBottom: 0,
  82. rows: [],
  83. page: 1,
  84. lastPage: 1,
  85. loading: false,
  86. loaded: false,
  87. loadStatus: 'more'
  88. }
  89. },
  90. computed: {
  91. copy() {
  92. const t = this.$t.bind(this)
  93. return {
  94. title: t('notice.system'),
  95. loading: t('notice.loading'),
  96. empty: t('notice.no-system-messages'),
  97. badge: t('notice.badge'),
  98. untitled: t('notice.untitled'),
  99. readMore: t('notice.readMore'),
  100. loadFailed: t('notice.loadFailed')
  101. }
  102. },
  103. loadMoreContent() {
  104. const t = this.$t.bind(this)
  105. return {
  106. contentdown: t('notice.loadMore'),
  107. contentrefresh: t('notice.loading'),
  108. contentnomore: t('notice.noMore')
  109. }
  110. }
  111. },
  112. onLoad() {
  113. this.initLayout()
  114. this.reload()
  115. },
  116. onPullDownRefresh() {
  117. this.reload().finally(() => uni.stopPullDownRefresh())
  118. },
  119. methods: {
  120. initLayout() {
  121. try {
  122. const info = uni.getSystemInfoSync()
  123. this.statusBar = info.statusBarHeight || 0
  124. this.safeBottom = (info.safeAreaInsets && info.safeAreaInsets.bottom) || 0
  125. const navH = this.statusBar + uni.upx2px(88)
  126. this.scrollHeight = (info.windowHeight || info.screenHeight || 600) - navH
  127. } catch (_) {}
  128. },
  129. coverUrl(item) {
  130. if (!item || !item.image || !this.$appKit) return ''
  131. return this.$appKit.oss(item.image, 686, 386)
  132. },
  133. goBack() {
  134. uni.navigateBack({
  135. fail: () => uni.switchTab({ url: '/pages/mine/index' })
  136. })
  137. },
  138. openDetail(item) {
  139. if (!item || item.id == null) return
  140. if (typeof this.onDetails === 'function') {
  141. this.onDetails(item.id, item.title || '')
  142. return
  143. }
  144. uni.navigateTo({
  145. url: `/pages/article/details?id=${item.id}&title=${encodeURIComponent(item.title || '')}`
  146. })
  147. },
  148. async reload() {
  149. this.page = 1
  150. this.lastPage = 1
  151. this.loadStatus = 'more'
  152. this.loaded = false
  153. this.rows = []
  154. await this.loadPage(true)
  155. },
  156. onScrollToLower() {
  157. if (this.loadStatus === 'loading' || this.loadStatus === 'noMore') return
  158. this.loadPage(false)
  159. },
  160. async loadPage(reset) {
  161. if (this.loading) return
  162. if (!reset && this.page >= this.lastPage) {
  163. this.loadStatus = 'noMore'
  164. return
  165. }
  166. const page = reset ? 1 : this.page + 1
  167. this.loading = true
  168. this.loadStatus = 'loading'
  169. try {
  170. const pack = await fetchSystemNoticePage(page)
  171. this.page = pack.currentPage
  172. this.lastPage = pack.lastPage
  173. if (reset) {
  174. this.rows = pack.rows
  175. } else {
  176. this.rows = this.rows.concat(pack.rows)
  177. }
  178. this.loadStatus =
  179. pack.currentPage >= pack.lastPage || !pack.rows.length ? 'noMore' : 'more'
  180. this.loaded = true
  181. } catch (err) {
  182. this.loadStatus = 'more'
  183. if (reset) this.rows = []
  184. this.$appKit && this.$appKit.msg(err.message || this.copy.loadFailed)
  185. this.loaded = true
  186. } finally {
  187. this.loading = false
  188. }
  189. }
  190. }
  191. }
  192. </script>
  193. <style scoped>
  194. .sys-notice-page {
  195. min-height: 100vh;
  196. background-color: #eef3fb;
  197. }
  198. .sys-notice-nav {
  199. background-color: #ffffff;
  200. border-bottom: 1rpx solid #eef1f6;
  201. }
  202. .sys-notice-nav-row {
  203. display: flex;
  204. flex-direction: row;
  205. align-items: center;
  206. height: 88rpx;
  207. padding: 0 24rpx;
  208. box-sizing: border-box;
  209. }
  210. .sys-notice-back {
  211. width: 64rpx;
  212. height: 64rpx;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. }
  217. .sys-notice-back-icon {
  218. font-size: 40rpx;
  219. color: #1a1d26;
  220. line-height: 1;
  221. }
  222. .sys-notice-nav-title {
  223. flex: 1;
  224. text-align: center;
  225. font-size: 32rpx;
  226. font-weight: 600;
  227. color: #1a1d26;
  228. }
  229. .sys-notice-nav-placeholder {
  230. width: 64rpx;
  231. }
  232. .sys-notice-body {
  233. padding: 24rpx 28rpx 0;
  234. box-sizing: border-box;
  235. }
  236. .sys-notice-state {
  237. padding: 120rpx 0;
  238. text-align: center;
  239. }
  240. .sys-notice-state-txt {
  241. font-size: 28rpx;
  242. color: #8a8d9e;
  243. }
  244. .sys-notice-list {
  245. display: flex;
  246. flex-direction: column;
  247. }
  248. .sys-notice-group {
  249. margin-bottom: 8rpx;
  250. }
  251. .sys-notice-time {
  252. display: flex;
  253. flex-direction: row;
  254. justify-content: center;
  255. margin: 12rpx 0 20rpx;
  256. }
  257. .sys-notice-time-txt {
  258. padding: 8rpx 24rpx;
  259. border-radius: 999rpx;
  260. background-color: rgba(255, 255, 255, 0.72);
  261. font-size: 22rpx;
  262. color: #8a8d9e;
  263. line-height: 1.4;
  264. }
  265. .sys-notice-card {
  266. overflow: hidden;
  267. margin-bottom: 24rpx;
  268. background-color: #ffffff;
  269. border-radius: 24rpx;
  270. box-shadow: 0 8rpx 28rpx rgba(74, 140, 255, 0.08);
  271. }
  272. .sys-notice-cover-wrap {
  273. position: relative;
  274. width: 100%;
  275. height: 320rpx;
  276. overflow: hidden;
  277. background-color: #e8edf5;
  278. }
  279. .sys-notice-cover {
  280. width: 100%;
  281. height: 100%;
  282. }
  283. .sys-notice-cover-fade {
  284. position: absolute;
  285. left: 0;
  286. right: 0;
  287. bottom: 0;
  288. height: 80rpx;
  289. background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.92) 100%);
  290. }
  291. .sys-notice-card-body {
  292. padding: 24rpx 28rpx 28rpx;
  293. box-sizing: border-box;
  294. }
  295. .sys-notice-badge-row {
  296. margin-bottom: 12rpx;
  297. }
  298. .sys-notice-badge {
  299. display: inline-block;
  300. padding: 4rpx 16rpx;
  301. border-radius: 999rpx;
  302. font-size: 20rpx;
  303. color: #ffffff;
  304. background: linear-gradient(135deg, #4a8cff 0%, #6ec8ff 100%);
  305. }
  306. .sys-notice-title {
  307. font-size: 32rpx;
  308. font-weight: 600;
  309. color: #1a1d26;
  310. line-height: 1.45;
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. -webkit-line-clamp: 2;
  314. -webkit-box-orient: vertical;
  315. display: -webkit-box;
  316. }
  317. .sys-notice-desc {
  318. margin-top: 12rpx;
  319. font-size: 26rpx;
  320. color: #8a8d9e;
  321. line-height: 1.5;
  322. overflow: hidden;
  323. text-overflow: ellipsis;
  324. -webkit-line-clamp: 2;
  325. -webkit-box-orient: vertical;
  326. display: -webkit-box;
  327. }
  328. .sys-notice-foot {
  329. display: flex;
  330. flex-direction: row;
  331. align-items: center;
  332. justify-content: flex-end;
  333. margin-top: 20rpx;
  334. padding-top: 16rpx;
  335. border-top: 1rpx solid #eef1f6;
  336. }
  337. .sys-notice-more {
  338. font-size: 24rpx;
  339. color: #4a8cff;
  340. }
  341. .sys-notice-arrow {
  342. margin-left: 4rpx;
  343. font-size: 32rpx;
  344. color: #4a8cff;
  345. line-height: 1;
  346. }
  347. </style>