FamilyFeed.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="family-feed">
  3. <!-- 标题 -->
  4. <view class="feed-header" v-if="showHeader">
  5. <view class="feed-header-left">
  6. <text class="feed-title">动态</text>
  7. <text class="feed-icon">📢</text>
  8. <view v-if="unreadCount > 0" class="feed-count-badge">
  9. <text class="feed-count-text">{{ unreadCount }} 条未读</text>
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 未读动态卡片栈(从下往上翻) -->
  14. <view v-if="displayItems.length > 0" class="feed-stack">
  15. <view
  16. v-for="(item, idx) in displayItems"
  17. :key="getItemKey(item)"
  18. class="feed-card"
  19. :class="{'feed-card-closing': isClosing(item)}"
  20. :style="getCardStyle(idx, item)"
  21. @click="openDetail(item)"
  22. >
  23. <view class="feed-card-icon-wrap">
  24. <text class="feed-card-icon">{{ getItemIcon(item) }}</text>
  25. </view>
  26. <view class="feed-card-body">
  27. <text class="feed-card-title line-clamp-1">{{ getItemTitle(item) }}</text>
  28. <text class="feed-card-time" v-if="item.time">{{ item.time }}</text>
  29. </view>
  30. <text class="feed-card-arrow">›</text>
  31. </view>
  32. </view>
  33. <!-- 空态 -->
  34. <view v-else class="feed-empty">
  35. <text class="feed-empty-text">暂无未读动态</text>
  36. </view>
  37. <!-- 详情弹窗 -->
  38. <view v-if="detailItem" class="feed-detail-mask" @click="closeDetail">
  39. <view class="feed-detail-panel" @click.stop="noop">
  40. <view class="feed-detail-head">
  41. <text class="feed-detail-title">{{ getItemTitle(detailItem) }}</text>
  42. <view class="feed-detail-close" @click="closeDetail">
  43. <text class="feed-detail-close-text">✕</text>
  44. </view>
  45. </view>
  46. <scroll-view class="feed-detail-content" scroll-y>
  47. <text class="feed-detail-body">{{ getItemContent(detailItem) }}</text>
  48. </scroll-view>
  49. <view class="feed-detail-foot">
  50. <text class="feed-detail-time" v-if="detailItem.time">{{ detailItem.time }}</text>
  51. <view class="feed-detail-btn" @click="closeDetail">
  52. <text class="feed-detail-btn-text">我知道了</text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. name: 'FamilyFeed',
  62. props: {
  63. items: {
  64. type: Array,
  65. default: function() { return [] }
  66. },
  67. notices: {
  68. type: Array,
  69. default: function() { return [] }
  70. },
  71. showHeader: {
  72. type: Boolean,
  73. default: true
  74. }
  75. },
  76. data: function() {
  77. return {
  78. detailItem: null,
  79. closingKeys: []
  80. }
  81. },
  82. computed: {
  83. // 公告(notices prop)优先展示,再拼未读动态(items),按 feedKey 去重,
  84. // 避免 familyFeed 在父组件被 slice(0,10) 截断时公告漏显
  85. displayItems: function() {
  86. var seen = {}
  87. var result = []
  88. var i
  89. var notices = this.notices || []
  90. for (i = 0; i < notices.length; i++) {
  91. var n = notices[i]
  92. if (!n) continue
  93. var raw = n.notice || {}
  94. var nKey = 'notice-' + (raw.id !== undefined ? raw.id : '')
  95. if (!nKey || seen[nKey]) continue
  96. seen[nKey] = true
  97. result.push({
  98. text: n.text || raw.title || '公告',
  99. time: n.time || '',
  100. type: 'notice',
  101. title: raw.title || n.text || '公告',
  102. content: raw.content || '',
  103. unread: false,
  104. _feedKey: nKey,
  105. _srcId: raw.id
  106. })
  107. }
  108. var items = this.items || []
  109. for (i = 0; i < items.length; i++) {
  110. var item = items[i]
  111. if (!item) continue
  112. var key = this.getItemKey(item)
  113. if (seen[key]) continue
  114. seen[key] = true
  115. result.push(item)
  116. }
  117. return result
  118. },
  119. unreadCount: function() {
  120. return this.displayItems.length
  121. }
  122. },
  123. methods: {
  124. getItemKey: function(item) {
  125. return item._feedKey || ('feed-' + (item.title || '') + '-' + (item.time || ''))
  126. },
  127. getItemIcon: function(item) {
  128. if (item.type === 'notification') return '📬'
  129. if (item.type === 'notice') return '📢'
  130. if (item.type === 'task') return '🎯'
  131. return '✨'
  132. },
  133. getItemTitle: function(item) {
  134. return item.title || item.text || '动态'
  135. },
  136. getItemContent: function(item) {
  137. return item.content || item.text || '暂无更多内容'
  138. },
  139. // 入场错峰:从下往上逐张翻入(最底下的卡片先入场)
  140. getCardStyle: function(idx, item) {
  141. if (this.isClosing(item)) {
  142. return 'animation-delay:0ms;'
  143. }
  144. var total = this.displayItems.length
  145. var delay = Math.min((total - 1 - idx) * 120, 600)
  146. return 'animation-delay:' + delay + 'ms;'
  147. },
  148. isClosing: function(item) {
  149. var key = this.getItemKey(item)
  150. return this.closingKeys.indexOf(key) !== -1
  151. },
  152. openDetail: function(item) {
  153. if (this.isClosing(item)) return
  154. this.detailItem = item
  155. },
  156. // 关闭:先播放翻出动画,再通知父组件标记已读并从列表移除
  157. closeDetail: function() {
  158. var self = this
  159. var item = this.detailItem
  160. if (!item) return
  161. this.detailItem = null
  162. var key = this.getItemKey(item)
  163. if (this.closingKeys.indexOf(key) === -1) {
  164. this.closingKeys.push(key)
  165. }
  166. setTimeout(function() {
  167. var keys = self.closingKeys.slice()
  168. var i = keys.indexOf(key)
  169. if (i !== -1) keys.splice(i, 1)
  170. self.closingKeys = keys
  171. self.$emit('viewed', item)
  172. }, 380)
  173. },
  174. noop: function() {}
  175. }
  176. }
  177. </script>
  178. <style>
  179. .family-feed {
  180. margin: 12rpx 30rpx 0;
  181. background: #fff;
  182. border-radius: 16rpx;
  183. padding: 10rpx 16rpx;
  184. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  185. overflow: hidden;
  186. }
  187. .feed-header {
  188. display: flex;
  189. flex-direction: row;
  190. align-items: center;
  191. padding: 6rpx 4rpx 12rpx;
  192. }
  193. .feed-header-left {
  194. display: flex;
  195. flex-direction: row;
  196. align-items: center;
  197. gap: 6rpx;
  198. }
  199. .feed-title {
  200. font-size: 28rpx;
  201. font-weight: bold;
  202. color: #333;
  203. }
  204. .feed-icon {
  205. font-size: 24rpx;
  206. }
  207. .feed-count-badge {
  208. margin-left: 12rpx;
  209. background: #ff5b5b;
  210. border-radius: 20rpx;
  211. padding: 2rpx 14rpx;
  212. }
  213. .feed-count-text {
  214. font-size: 20rpx;
  215. color: #fff;
  216. }
  217. /* ===== 翻转卡片栈 ===== */
  218. .feed-stack {
  219. perspective: 800rpx;
  220. }
  221. .feed-card {
  222. display: flex;
  223. flex-direction: row;
  224. align-items: center;
  225. margin-bottom: 12rpx;
  226. padding: 18rpx 20rpx;
  227. background: #f7f8fa;
  228. border-radius: 12rpx;
  229. box-sizing: border-box;
  230. transform-origin: center bottom;
  231. transform-style: preserve-3d;
  232. animation: feedFlipUp 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
  233. }
  234. .feed-card:active {
  235. opacity: 0.85;
  236. }
  237. /* 入场:从下往上翻入 */
  238. @keyframes feedFlipUp {
  239. 0% {
  240. transform: translateY(40rpx) rotateX(-90deg);
  241. opacity: 0;
  242. }
  243. 100% {
  244. transform: translateY(0) rotateX(0deg);
  245. opacity: 1;
  246. }
  247. }
  248. /* 关闭:翻出(向下折叠 + 淡出) */
  249. .feed-card-closing {
  250. animation: feedFlipDown 0.35s ease-in both;
  251. }
  252. @keyframes feedFlipDown {
  253. 0% {
  254. transform: translateY(0) rotateX(0deg);
  255. opacity: 1;
  256. }
  257. 100% {
  258. transform: translateY(-20rpx) rotateX(-75deg);
  259. opacity: 0;
  260. }
  261. }
  262. .feed-card-icon-wrap {
  263. width: 56rpx;
  264. height: 56rpx;
  265. border-radius: 50%;
  266. background: #fff;
  267. display: flex;
  268. align-items: center;
  269. justify-content: center;
  270. flex-shrink: 0;
  271. margin-right: 16rpx;
  272. }
  273. .feed-card-icon {
  274. font-size: 28rpx;
  275. }
  276. .feed-card-body {
  277. flex: 1;
  278. min-width: 0;
  279. display: flex;
  280. flex-direction: column;
  281. }
  282. .feed-card-title {
  283. font-size: 26rpx;
  284. color: #333;
  285. line-height: 34rpx;
  286. }
  287. .feed-card-time {
  288. font-size: 20rpx;
  289. color: #999;
  290. margin-top: 4rpx;
  291. }
  292. .feed-card-arrow {
  293. font-size: 28rpx;
  294. color: #ccc;
  295. margin-left: 12rpx;
  296. flex-shrink: 0;
  297. }
  298. /* ===== 详情弹窗 ===== */
  299. .feed-detail-mask {
  300. position: fixed;
  301. top: 0;
  302. left: 0;
  303. right: 0;
  304. bottom: 0;
  305. background: rgba(0, 0, 0, 0.5);
  306. z-index: 999;
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. padding: 60rpx 40rpx;
  311. perspective: 900rpx;
  312. }
  313. .feed-detail-panel {
  314. width: 100%;
  315. background: #fff;
  316. border-radius: 20rpx;
  317. padding: 30rpx 28rpx;
  318. box-sizing: border-box;
  319. display: flex;
  320. flex-direction: column;
  321. animation: feedPanelIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
  322. }
  323. @keyframes feedPanelIn {
  324. 0% {
  325. transform: translateY(80rpx) rotateX(40deg);
  326. opacity: 0;
  327. }
  328. 100% {
  329. transform: translateY(0) rotateX(0deg);
  330. opacity: 1;
  331. }
  332. }
  333. .feed-detail-head {
  334. display: flex;
  335. flex-direction: row;
  336. align-items: center;
  337. justify-content: space-between;
  338. padding-bottom: 20rpx;
  339. border-bottom: 1rpx solid #f0f0f0;
  340. }
  341. .feed-detail-title {
  342. font-size: 30rpx;
  343. font-weight: bold;
  344. color: #333;
  345. flex: 1;
  346. margin-right: 16rpx;
  347. }
  348. .feed-detail-close {
  349. width: 48rpx;
  350. height: 48rpx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. flex-shrink: 0;
  355. }
  356. .feed-detail-close-text {
  357. font-size: 30rpx;
  358. color: #999;
  359. }
  360. .feed-detail-content {
  361. max-height: 480rpx;
  362. margin-top: 20rpx;
  363. }
  364. .feed-detail-body {
  365. font-size: 26rpx;
  366. color: #555;
  367. line-height: 42rpx;
  368. word-break: break-all;
  369. display: block;
  370. }
  371. .feed-detail-foot {
  372. display: flex;
  373. flex-direction: row;
  374. align-items: center;
  375. justify-content: space-between;
  376. margin-top: 24rpx;
  377. }
  378. .feed-detail-time {
  379. font-size: 22rpx;
  380. color: #999;
  381. }
  382. .feed-detail-btn {
  383. background: linear-gradient(135deg, #6366f1, #8b5cf6);
  384. border-radius: 30rpx;
  385. padding: 12rpx 40rpx;
  386. }
  387. .feed-detail-btn-text {
  388. font-size: 26rpx;
  389. color: #fff;
  390. }
  391. /* ===== 空态 ===== */
  392. .feed-empty {
  393. height: 60rpx;
  394. display: flex;
  395. align-items: center;
  396. justify-content: center;
  397. }
  398. .feed-empty-text {
  399. font-size: 24rpx;
  400. color: #ccc;
  401. }
  402. .line-clamp-1 {
  403. overflow: hidden;
  404. text-overflow: ellipsis;
  405. white-space: nowrap;
  406. }
  407. </style>