index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import OHeader from '@/components/o-header'
  2. import {
  3. Cell,
  4. CellGroup,
  5. Icon,
  6. Image,
  7. List,
  8. Picker,
  9. Popup,
  10. Step,
  11. Steps,
  12. Swipe,
  13. SwipeItem
  14. } from 'vant'
  15. import { defineComponent, onMounted, reactive, ref, watch } from 'vue'
  16. import { useRoute, useRouter } from 'vue-router'
  17. import styles from './index.module.less'
  18. import iconStep from './images/icon-step.png'
  19. import iconStepCalendar from './images/icon-step-calendar.png'
  20. import request from '@/helpers/request'
  21. import OEmpty from '@/components/o-empty'
  22. import dayjs from 'dayjs'
  23. import OVideo from '@/components/o-video'
  24. import { state as globalState } from '@/state'
  25. export default defineComponent({
  26. name: 'orchestra-story',
  27. props: {
  28. orchestraId: {
  29. type: String,
  30. default: ''
  31. }
  32. },
  33. setup(props) {
  34. const state = reactive({
  35. isClick: false,
  36. list: [] as any,
  37. listState: {
  38. dataShow: true, // 判断是否有数据
  39. loading: false,
  40. finished: false,
  41. refreshing: false,
  42. height: 0 // 页面头部高度,为了处理下拉刷新用的
  43. },
  44. params: {
  45. type: null,
  46. page: 1,
  47. rows: 20
  48. }
  49. })
  50. const getList = async () => {
  51. try {
  52. if (state.isClick) return
  53. state.isClick = true
  54. const res = await request.post(`${globalState.platformApi}/orchestraStory/page`, {
  55. data: {
  56. orchestraId: props.orchestraId
  57. },
  58. hideLoading: true
  59. })
  60. state.listState.loading = false
  61. state.listState.refreshing = false
  62. const result = res.data || {}
  63. // 处理重复请求数据
  64. if (state.list.length > 0 && result.current === 1) {
  65. return
  66. }
  67. state.list = state.list.concat(result.rows || [])
  68. state.listState.finished = result.current >= result.pages
  69. state.params.page = result.current + 1
  70. state.listState.dataShow = state.list.length > 0
  71. state.isClick = false
  72. } catch {
  73. state.listState.dataShow = false
  74. state.listState.finished = true
  75. state.listState.refreshing = false
  76. state.isClick = false
  77. }
  78. }
  79. watch(
  80. () => props.orchestraId,
  81. () => {
  82. state.params.page = 1
  83. state.list = []
  84. state.listState.finished = false
  85. getList()
  86. }
  87. )
  88. const videoRef: any = ref([])
  89. const onPlay = (index: any) => {
  90. videoRef.value.forEach((item: any, child: any) => {
  91. if (child !== index) {
  92. item.onStop()
  93. }
  94. })
  95. }
  96. onMounted(() => {
  97. getList()
  98. })
  99. return () => (
  100. <div
  101. class={[styles.orchestraStory, !state.listState.dataShow && 'emptyRootContainer']}
  102. style={{ height: '100%', minHeight: 'auto' }}
  103. >
  104. {state.listState.dataShow ? (
  105. <List
  106. // v-model:loading={state.listState.loading}
  107. finished={state.listState.finished}
  108. finishedText=" "
  109. class={[styles.liveList]}
  110. onLoad={getList}
  111. immediateCheck={false}
  112. >
  113. <Steps direction="vertical" class={styles.storySteps}>
  114. {state.list.map((item: any, index: number) => (
  115. <Step
  116. v-slots={{
  117. 'inactive-icon': () => <Image src={iconStep} class={styles.iconInactive} />,
  118. 'active-icon': () => <Image src={iconStepCalendar} class={styles.iconActive} />
  119. }}
  120. >
  121. <div class={styles.stepTimes}>
  122. <div class={styles.stepTime}>
  123. {dayjs(item.createTime).format('YYYY年MM月DD日')}
  124. </div>
  125. </div>
  126. <p class={[styles.content, 'van-multi-ellipsis--l2']}>{item.content}</p>
  127. <Swipe class={styles.storySwipe}>
  128. {item.attachments &&
  129. item.attachments.map((child: any) => (
  130. <SwipeItem>
  131. {item.type === 'IMAGE' && (
  132. <div
  133. class={styles.swipeImg}
  134. style={
  135. child.url
  136. ? {
  137. backgroundImage: `url(${child.url})`,
  138. backgroundSize: 'cover'
  139. }
  140. : ''
  141. }
  142. ></div>
  143. )}
  144. {item.type === 'VIDEO' && (
  145. <OVideo
  146. src={child.url}
  147. height={'100%'}
  148. poster={child.coverImage}
  149. class={styles.swipeImg}
  150. ref={(el: any) => (videoRef.value[index] = el)}
  151. onPlay={() => onPlay(index)}
  152. />
  153. )}
  154. </SwipeItem>
  155. ))}
  156. </Swipe>
  157. </Step>
  158. ))}
  159. </Steps>
  160. </List>
  161. ) : (
  162. <OEmpty btnStatus={false} tips="暂无事迹" />
  163. )}
  164. </div>
  165. )
  166. }
  167. })