index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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, nextTick } 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. const swipeRef = ref([])
  100. return () => (
  101. <div
  102. class={[styles.orchestraStory, !state.listState.dataShow && 'emptyRootContainer']}
  103. style={{ overflowY: 'auto' }}
  104. >
  105. {state.listState.dataShow ? (
  106. <List
  107. // v-model:loading={state.listState.loading}
  108. finished={state.listState.finished}
  109. finishedText=" "
  110. class={[styles.liveList]}
  111. onLoad={getList}
  112. immediateCheck={false}
  113. >
  114. <Steps direction="vertical" class={[styles.storySteps, 'storyStepContainer']}>
  115. {state.list.map((item: any, index: number) => (
  116. <Step
  117. v-slots={{
  118. 'inactive-icon': () => <Image src={iconStep} class={styles.iconInactive} />,
  119. 'active-icon': () => <Image src={iconStepCalendar} class={styles.iconActive} />
  120. }}
  121. >
  122. <div class={styles.stepTimes}>
  123. <div class={styles.stepTime}>
  124. {dayjs(item.createTime).format('YYYY年MM月DD日')}
  125. </div>
  126. </div>
  127. <p class={[styles.content, 'van-multi-ellipsis--l2']}>{item.content}</p>
  128. <Swipe ref={(el: any) => (swipeRef.value[index] = el)} class={styles.storySwipe}>
  129. {item.attachments &&
  130. item.attachments.map((child: any) => (
  131. <SwipeItem>
  132. {item.type === 'IMAGE' && (
  133. <div
  134. class={styles.swipeImg}
  135. style={
  136. child.url
  137. ? {
  138. backgroundImage: `url(${child.url})`,
  139. backgroundSize: 'cover'
  140. }
  141. : ''
  142. }
  143. ></div>
  144. )}
  145. {item.type === 'VIDEO' && (
  146. <OVideo
  147. src={child.url}
  148. height={'100%'}
  149. poster={child.coverImage}
  150. class={styles.swipeImg}
  151. ref={(el: any) => (videoRef.value[index] = el)}
  152. onPlay={() => onPlay(index)}
  153. onExitfullscreen={() => {
  154. console.group('重新resize', swipeRef.value)
  155. console.time('开始')
  156. nextTick(() => {
  157. setTimeout(() => {
  158. console.time('结束')
  159. console.groupEnd()
  160. // swipeRef.value?.resize()
  161. swipeRef.value.forEach((item: any) => {
  162. item.resize()
  163. })
  164. }, 600)
  165. })
  166. }}
  167. />
  168. )}
  169. </SwipeItem>
  170. ))}
  171. </Swipe>
  172. </Step>
  173. ))}
  174. </Steps>
  175. </List>
  176. ) : (
  177. <OEmpty btnStatus={false} tips="暂无事迹" style={{ paddingBottom: '30px' }} />
  178. )}
  179. </div>
  180. )
  181. }
  182. })