post-media.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /** 动态多图网格布局(最多展示 9 张) */
  2. export const GRID_MAX = 9
  3. export function gridColumnCount(count) {
  4. if (count <= 1) return 1
  5. if (count === 2 || count === 4) return 2
  6. return 3
  7. }
  8. export function gridDisplayImages(images = [], max = GRID_MAX) {
  9. const list = Array.isArray(images) ? images.filter(Boolean) : []
  10. if (list.length <= max) {
  11. return { visible: list, overflow: 0 }
  12. }
  13. return {
  14. visible: list.slice(0, max),
  15. overflow: list.length - max
  16. }
  17. }
  18. /** 构建详情页 URL */
  19. export function detailPageUrl(id, opts = {}) {
  20. const q = [`id=${id}`]
  21. if (opts.focus === 'comments') q.push('focus=comments')
  22. if (opts.img != null && Number(opts.img) > 0) q.push(`img=${Number(opts.img)}`)
  23. return `/pages/dynamics/detail?${q.join('&')}`
  24. }
  25. /** 竖滑视频详情页 */
  26. export function videoDetailUrl(id, opts = {}) {
  27. const q = [`id=${encodeURIComponent(String(id))}`]
  28. const labelId = opts.labelId ?? opts.label_id
  29. if (labelId != null && labelId !== '') {
  30. q.push(`label_id=${encodeURIComponent(String(labelId))}`)
  31. }
  32. const listType = opts.type
  33. if (listType != null && listType !== '') {
  34. q.push(`type=${encodeURIComponent(String(listType))}`)
  35. }
  36. const userNo = opts.user_no ?? opts.userNo
  37. if (userNo != null && userNo !== '') {
  38. q.push(`user_no=${encodeURIComponent(String(userNo))}`)
  39. }
  40. const page = opts.page
  41. if (page != null && String(page) !== '' && String(page) !== '1') {
  42. q.push(`page=${encodeURIComponent(String(page))}`)
  43. }
  44. if (opts.compId != null && opts.compId !== '') {
  45. q.push(`compID=${encodeURIComponent(String(opts.compId))}`)
  46. }
  47. const orderType = opts.orderType ?? opts.order_type
  48. if (orderType != null && orderType !== '') {
  49. q.push(`order_type=${encodeURIComponent(String(orderType))}`)
  50. }
  51. const isHotDian = opts.isHotDian ?? opts.is_hot_dian
  52. if (isHotDian != null && isHotDian !== '') {
  53. q.push(`is_hot_dian=${encodeURIComponent(String(isHotDian))}`)
  54. }
  55. const search = opts.search
  56. if (search != null && String(search) !== '') {
  57. q.push(`search=${encodeURIComponent(String(search))}`)
  58. }
  59. return `/pages/feed/reel?${q.join('&')}`
  60. }
  61. export function absolutizePreviewUrls(images, ossFn) {
  62. return (images || []).map((src) => (typeof ossFn === 'function' ? ossFn(src, 750, 0) : src))
  63. }