photo.tsx 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import OEmpty from '@/components/o-empty'
  2. import request from '@/helpers/request'
  3. import {
  4. ActionSheet,
  5. Button,
  6. Cell,
  7. CellGroup,
  8. Dialog,
  9. Field,
  10. Image,
  11. List,
  12. Picker,
  13. Popover,
  14. Popup,
  15. showConfirmDialog,
  16. showToast,
  17. Sticky
  18. } from 'vant'
  19. import { defineComponent, onMounted, reactive } from 'vue'
  20. import { useRoute, useRouter } from 'vue-router'
  21. import styles from './photo.module.less'
  22. import iconPhoneDefaut from '../images/icon-photo-default.png'
  23. import iconOrchestra from '@/views/mine-orchestra/images/icon-or.png'
  24. import OSticky from '@/components/o-sticky'
  25. import OHeader from '@/components/o-header'
  26. export default defineComponent({
  27. name: 'phone',
  28. props: {
  29. height: {
  30. type: [String, Number],
  31. default: 'auto'
  32. }
  33. },
  34. setup(props) {
  35. const route = useRoute()
  36. const router = useRouter()
  37. const state = reactive({
  38. oPopover: false,
  39. status: false,
  40. isLoading: false,
  41. photoName: null, // 相册名称
  42. list: [] as any,
  43. listState: {
  44. dataShow: true, // 判断是否有数据
  45. loading: false,
  46. finished: false
  47. },
  48. params: {
  49. page: 1,
  50. rows: 20
  51. },
  52. selectItem: {} as any,
  53. selectType: 'add',
  54. schoolStatus: false,
  55. schoolList: [],
  56. school: {} as any
  57. })
  58. const onAddPhoto = async () => {
  59. try {
  60. if (!state.photoName) {
  61. showToast('请输入相册名称')
  62. state.status = true
  63. return
  64. }
  65. if (state.selectType === 'add') {
  66. await request.post('/api-school/orchestraPhotoAlbum/save', {
  67. data: {
  68. name: state.photoName
  69. }
  70. })
  71. // setTimeout(() => {
  72. // showToast('添加成功')
  73. // }, 100)
  74. state.status = false
  75. state.photoName = null
  76. onSearch()
  77. } else {
  78. await request.post('/api-school/orchestraPhotoAlbum/update', {
  79. data: {
  80. id: state.selectItem.id,
  81. orchestraId: route.query.id,
  82. name: state.photoName
  83. }
  84. })
  85. state.status = false
  86. state.photoName = null
  87. onSearch()
  88. // setTimeout(() => {
  89. // showToast('修改成功')
  90. // }, 100)
  91. }
  92. state.status = false
  93. state.photoName = null
  94. onSearch()
  95. // setTimeout(() => {
  96. // state.photoName = null
  97. // onSearch()
  98. // }, 1100)
  99. } catch {
  100. //
  101. }
  102. }
  103. const onSearch = () => {
  104. state.params.page = 1
  105. state.list = []
  106. state.listState.dataShow = true // 判断是否有数据
  107. state.listState.loading = false
  108. state.listState.finished = false
  109. getList()
  110. }
  111. // 班级列表
  112. const getList = async () => {
  113. try {
  114. if (state.isLoading) return
  115. state.isLoading = true
  116. const res = await request.post('/api-school/orchestraPhotoAlbum/page', {
  117. data: {
  118. ...state.params,
  119. schoolId: state.school.id
  120. }
  121. })
  122. state.listState.loading = false
  123. const result = res.data || {}
  124. // 处理重复请求数据
  125. if (state.list.length > 0 && result.current === 1) {
  126. return
  127. }
  128. const rows = result.rows || []
  129. state.list = state.list.concat(rows)
  130. state.listState.finished = result.current >= result.pages
  131. state.params.page = result.current + 1
  132. state.listState.dataShow = state.list.length > 0
  133. state.isLoading = false
  134. } catch {
  135. state.listState.dataShow = false
  136. state.listState.finished = true
  137. state.isLoading = false
  138. }
  139. }
  140. // const getSchoolList = async () => {
  141. // try {
  142. // const res = await request.post('/api-school/school/page', {
  143. // data: {
  144. // page: 1,
  145. // rows: 999
  146. // }
  147. // })
  148. // if (Array.isArray(res.data?.rows)) {
  149. // state.schoolList = res.data.rows.map((n: any) => {
  150. // return {
  151. // name: n.name || '',
  152. // id: n.id || ''
  153. // }
  154. // })
  155. // const tmpSchool = sessionStorage.getItem('school-photo')
  156. // state.school = tmpSchool ? JSON.parse(tmpSchool) : state.schoolList[0] || {}
  157. // }
  158. // } catch {
  159. // //
  160. // }
  161. // }
  162. const onDetail = (item: any) => {
  163. sessionStorage.setItem('orchestra-detail-tab', 'photo')
  164. router.push({
  165. path: '/orchestra-photo-create',
  166. query: {
  167. orchestraId: route.query.id,
  168. name: item.name,
  169. parentId: item.id
  170. }
  171. })
  172. // router.push({
  173. // path: '/photo-detail',
  174. // query: {
  175. // photoId: item.id,
  176. // name: item.name
  177. // }
  178. // })
  179. }
  180. const onRename = async () => {
  181. state.photoName = state.selectItem.name
  182. state.status = true
  183. }
  184. const onRemove = async () => {
  185. showConfirmDialog({
  186. message: '您确认删除该相册吗?'
  187. }).then(async () => {
  188. try {
  189. await request.post('/api-school/orchestraPhotoAlbum/remove', {
  190. requestType: 'form',
  191. data: {
  192. id: state.selectItem.id
  193. }
  194. })
  195. onSearch()
  196. } catch {
  197. //
  198. }
  199. })
  200. }
  201. onMounted(async () => {
  202. // await getSchoolList()
  203. await getList()
  204. })
  205. return () => (
  206. <div
  207. class={[styles.phone, !state.listState.dataShow && 'emptyRootContainer']}
  208. style={{ minHeight: `calc(100vh - ${props.height}px)` }}
  209. >
  210. <OSticky position="top">
  211. <OHeader>
  212. {{
  213. right: () => (
  214. <span
  215. class={styles.addPhotoTop}
  216. onClick={() => {
  217. state.status = true
  218. state.selectType = 'add'
  219. }}
  220. >
  221. 添加相册
  222. </span>
  223. )
  224. }}
  225. </OHeader>
  226. </OSticky>
  227. {/* <Sticky position="top" offsetTop={props.height} style={{ width: '100%' }}>
  228. <Cell class={styles.select} center isLink onClick={() => (state.schoolStatus = true)}>
  229. {{
  230. icon: () => <img class={styles.icon} src={iconOrchestra} />,
  231. title: () => <div class="van-ellipsis">{state.school.name}</div>
  232. }}
  233. </Cell>
  234. </Sticky> */}
  235. {state.listState.dataShow ? (
  236. <List
  237. // v-model:loading={state.listState.loading}
  238. finished={state.listState.finished}
  239. finishedText=" "
  240. onLoad={getList}
  241. immediateCheck={false}
  242. class={styles.informationGroup}
  243. >
  244. <div class={styles.phoneContainer}>
  245. {state.list.map((item: any) => (
  246. <div class={styles.item} onClick={() => onDetail(item)}>
  247. {/* <i class={styles.more}></i> */}
  248. <i
  249. class={styles.more}
  250. onClick={(e: any) => {
  251. e.stopPropagation()
  252. state.oPopover = true
  253. state.selectItem = item
  254. state.selectType = 'update'
  255. }}
  256. ></i>
  257. <div
  258. class={styles.img}
  259. style={
  260. item.coverUrl
  261. ? { backgroundImage: `url(${item.coverUrl})`, backgroundSize: 'cover' }
  262. : ''
  263. }
  264. ></div>
  265. <p class={[styles.name, 'van-ellipsis']}>{item.name}</p>
  266. <p class={styles.num}>{item.photoCount}张</p>
  267. </div>
  268. ))}
  269. </div>
  270. </List>
  271. ) : (
  272. <OEmpty btnStatus={false} tips="暂无相册" />
  273. )}
  274. <Popup v-model:show={state.status} round style={{ width: '80%' }}>
  275. <div class={styles.container}>
  276. <div class={styles.dialogTitle}>
  277. <i></i>
  278. {state.selectType === 'add' ? '新建相册' : '重命名相册'}
  279. </div>
  280. <Field
  281. class={styles.phoneName}
  282. v-model={state.photoName}
  283. placeholder="请输入相册名称"
  284. maxlength={15}
  285. />
  286. <div class={['van-hairline--top van-dialog__footer']}>
  287. <Button
  288. onClick={() => (state.status = false)}
  289. class={['van-button van-button--default van-button--large van-dialog__cancel']}
  290. >
  291. 取消
  292. </Button>
  293. <Button
  294. onClick={onAddPhoto}
  295. class={[
  296. 'van-button van-button--default van-button--large van-dialog__confirm van-hairline--left'
  297. ]}
  298. >
  299. 确认
  300. </Button>
  301. </div>
  302. </div>
  303. </Popup>
  304. <ActionSheet
  305. cancelText="取消"
  306. v-model:show={state.oPopover}
  307. closeOnClickAction
  308. actions={[
  309. { name: '重命名', callback: () => onRename() },
  310. { name: '删除', color: '#F44541', callback: () => onRemove() }
  311. ]}
  312. />
  313. {/* <Popup v-model:show={state.schoolStatus} position="bottom" round>
  314. <Picker
  315. columns={state.schoolList}
  316. columnsFieldNames={{ text: 'name', value: 'id' }}
  317. onCancel={() => (state.schoolStatus = false)}
  318. onConfirm={({ selectedValues }: any) => {
  319. const val = selectedValues[0] || ''
  320. state.schoolStatus = false
  321. if (val == state.school?.id) {
  322. return
  323. }
  324. const active = state.schoolList.find((n: any) => n.id == val) || {}
  325. state.school = active
  326. sessionStorage.setItem('school-photo', JSON.stringify(active))
  327. onSearch()
  328. }}
  329. />
  330. </Popup> */}
  331. </div>
  332. )
  333. }
  334. })