index.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 } from 'vue'
  16. import { useRoute, useRouter } from 'vue-router'
  17. import styles from './index.module.less'
  18. import iconEdit from './images/icon-edit.png'
  19. import iconStep from './images/icon-step.png'
  20. import iconStepCalendar from './images/icon-step-calendar.png'
  21. import request from '@/helpers/request'
  22. import { state as baseState } from '@/state'
  23. import OFullRefresh from '@/components/o-full-refresh'
  24. import OEmpty from '@/components/o-empty'
  25. import dayjs from 'dayjs'
  26. import OVideo from '@/components/o-video'
  27. export default defineComponent({
  28. name: 'orchestra-story',
  29. setup() {
  30. const route = useRoute()
  31. const router = useRouter()
  32. const state = reactive({
  33. orchestraStatus: false,
  34. orchestraList: [] as any,
  35. selectOrchestra: {} as any,
  36. isClick: false,
  37. list: [] as any,
  38. listState: {
  39. dataShow: true, // 判断是否有数据
  40. loading: false,
  41. finished: false,
  42. refreshing: false,
  43. height: 0 // 页面头部高度,为了处理下拉刷新用的
  44. },
  45. params: {
  46. type: null,
  47. page: 1,
  48. rows: 20
  49. }
  50. })
  51. // 获取乐团列表
  52. const getOrchestras = async () => {
  53. try {
  54. const { data } = await request.post('/api-school/orchestra/page', {
  55. data: {
  56. page: 1,
  57. rows: 100,
  58. schoolId: baseState.user.data.school.id
  59. }
  60. })
  61. const temps = data.rows || []
  62. const s = [] as any
  63. temps.forEach((item: any) => {
  64. s.push({
  65. text: item.name,
  66. value: item.id
  67. })
  68. })
  69. state.orchestraList = [...s]
  70. // 判断是否有乐团
  71. if (s.length > 0) {
  72. state.selectOrchestra = s[0]
  73. getList()
  74. }
  75. } catch {
  76. //
  77. }
  78. }
  79. const getList = async () => {
  80. try {
  81. if (state.isClick) return
  82. state.isClick = true
  83. const res = await request.post('/api-school/orchestraStory/page', {
  84. data: {
  85. orchestraId: state.selectOrchestra.value
  86. }
  87. })
  88. state.listState.loading = false
  89. state.listState.refreshing = false
  90. const result = res.data || {}
  91. // 处理重复请求数据
  92. if (state.list.length > 0 && result.current === 1) {
  93. return
  94. }
  95. state.list = state.list.concat(result.rows || [])
  96. state.listState.finished = result.current >= result.pages
  97. state.params.page = result.current + 1
  98. state.listState.dataShow = state.list.length > 0
  99. state.isClick = false
  100. } catch {
  101. state.listState.dataShow = false
  102. state.listState.finished = true
  103. state.listState.refreshing = false
  104. state.isClick = false
  105. }
  106. }
  107. const onRefresh = () => {
  108. state.params.page = 1
  109. state.list = []
  110. state.listState.dataShow = true // 判断是否有数据
  111. state.listState.loading = false
  112. state.listState.finished = false
  113. getList()
  114. }
  115. const onEdit = async (item: any) => {
  116. router.push({
  117. path: '/story-operation',
  118. query: {
  119. id: item.id
  120. }
  121. })
  122. }
  123. onMounted(async () => {
  124. getOrchestras()
  125. })
  126. return () => (
  127. <div class={styles.orchestraStory}>
  128. <OHeader>
  129. {{
  130. right: () => (
  131. <span
  132. style={{ color: '#777777' }}
  133. onClick={() => {
  134. router.push('/story-operation')
  135. }}
  136. >
  137. 添加
  138. </span>
  139. )
  140. }}
  141. </OHeader>
  142. {state.orchestraList.length > 0 && (
  143. <CellGroup inset class={styles.cellGroup}>
  144. <Cell
  145. title={state.selectOrchestra.text || ' '}
  146. isLink
  147. center
  148. onClick={() => (state.orchestraStatus = true)}
  149. ></Cell>
  150. </CellGroup>
  151. )}
  152. {state.listState.dataShow ? (
  153. // <OFullRefresh
  154. // v-model:modelValue={state.listState.refreshing}
  155. // onRefresh={onRefresh}
  156. // style={{
  157. // minHeight: `calc(100vh - ${state.listState.height}px)`
  158. // }}
  159. // >
  160. <List
  161. v-model:loading={state.listState.loading}
  162. finished={state.listState.finished}
  163. finishedText=" "
  164. class={[styles.liveList]}
  165. onLoad={getList}
  166. immediateCheck={false}
  167. >
  168. <Steps direction="vertical" class={styles.storySteps}>
  169. {state.list.map((item: any) => (
  170. <Step
  171. v-slots={{
  172. 'inactive-icon': () => <Image src={iconStep} class={styles.iconInactive} />,
  173. 'active-icon': () => <Image src={iconStepCalendar} class={styles.iconActive} />
  174. }}
  175. >
  176. <div class={styles.stepTimes}>
  177. <div class={styles.stepTime}>
  178. {dayjs(item.createTime).format('YYYY年MM月DD日')}
  179. </div>
  180. <span class={styles.stepEdit} onClick={() => onEdit(item)}>
  181. <Icon name={iconEdit} />
  182. 编辑
  183. </span>
  184. </div>
  185. <p class={[styles.content, 'van-multi-ellipsis--l2']}>{item.content}</p>
  186. <Swipe class={styles.storySwipe}>
  187. {item.attachments &&
  188. item.attachments.map((child: any) => (
  189. <SwipeItem>
  190. {item.type === 'IMAGE' && (
  191. <Image src={child.url} class={styles.swipeImg} fit="cover" />
  192. )}
  193. {item.type === 'VIDEO' && (
  194. <OVideo
  195. src={child.url}
  196. height={'100%'}
  197. poster={child.coverImage}
  198. class={styles.swipeImg}
  199. />
  200. )}
  201. </SwipeItem>
  202. ))}
  203. </Swipe>
  204. </Step>
  205. ))}
  206. </Steps>
  207. </List>
  208. ) : (
  209. <OEmpty btnStatus={false} tips="暂无事迹" />
  210. )}
  211. <Popup v-model:show={state.orchestraStatus} position="bottom" round>
  212. <Picker
  213. columns={state.orchestraList}
  214. onCancel={() => (state.orchestraStatus = false)}
  215. onConfirm={(val: any) => {
  216. state.selectOrchestra = val.selectedOptions[0]
  217. state.orchestraStatus = false
  218. onRefresh()
  219. }}
  220. />
  221. </Popup>
  222. </div>
  223. )
  224. }
  225. })