class-content.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import ColField from '@/components/col-field'
  2. import ColFieldGroup from '@/components/col-field-group'
  3. import ColPopup from '@/components/col-popup'
  4. import ColUpload from '@/components/col-upload'
  5. import ColUploadVideo from '@/components/col-upload-video'
  6. import {
  7. Button,
  8. Col,
  9. Dialog,
  10. Field,
  11. Form,
  12. Icon,
  13. Row,
  14. Sticky,
  15. Switch
  16. } from 'vant'
  17. import { defineComponent } from 'vue'
  18. import styles from './class-content.module.less'
  19. import { createState } from './createState'
  20. import MusicAlbum from './model/music-album'
  21. export default defineComponent({
  22. name: 'ClassContent',
  23. data() {
  24. return {
  25. url: '',
  26. checked: null,
  27. musicStatus: false,
  28. selectItem: {} as any // 选中的课程
  29. }
  30. },
  31. methods: {
  32. onSubmit(values: any) {
  33. createState.active = 3
  34. },
  35. addItem() {
  36. createState.lessonList.push({
  37. videoTitle: '',
  38. videoContent: '',
  39. videoUrl: '',
  40. coverUrl: '',
  41. relationList: [],
  42. posterUrl: '' // 视频封面图
  43. })
  44. },
  45. removeItem(index: number) {
  46. // 最少一节课
  47. if (createState.lessonList.length <= 1) return
  48. Dialog.confirm({
  49. title: '操作',
  50. message: `确定删除该条数据吗?`,
  51. confirmButtonColor: '#2DC7AA'
  52. }).then(() => {
  53. createState.lessonList.splice(index, 1)
  54. })
  55. },
  56. getName(item: any) {
  57. const relation =
  58. item.relationList.length > 0 ? item.relationList[0] : null
  59. return relation
  60. ? (relation.relationMusicAlbum === 'ALBUM' ? '专辑:' : '曲目:') +
  61. relation.musicAlbumName
  62. : ''
  63. }
  64. },
  65. render() {
  66. return (
  67. <Form
  68. class={styles['class-content']}
  69. onSubmit={this.onSubmit}
  70. scrollToError
  71. >
  72. <div class={styles.createVideoTips}>
  73. 您可为每个视频关联曲目或专辑作为本课程教学内容推荐
  74. </div>
  75. {createState.lessonList.map((item: any, index: number) => (
  76. <>
  77. <div class={styles.titleSection}>
  78. <span class={styles.title}>第{index + 1}课</span>
  79. <Icon
  80. name="delete-o"
  81. style={{ fontWeight: 600 }}
  82. class={
  83. createState.lessonList.length <= 1 ? styles.disabled : null
  84. }
  85. onClick={() => this.removeItem(index)}
  86. size={20}
  87. />
  88. </div>
  89. <ColFieldGroup>
  90. <ColField title="课程标题" required>
  91. <Field
  92. v-model={item.videoTitle}
  93. maxlength={50}
  94. rules={[{ required: true, message: '请输入课程标题' }]}
  95. name="videoTitle"
  96. placeholder="请输入您的课程标题"
  97. />
  98. </ColField>
  99. <ColField title="课程内容" required>
  100. <Field
  101. v-model={item.videoContent}
  102. type="textarea"
  103. rows="2"
  104. autosize
  105. showWordLimit
  106. maxlength={200}
  107. rules={[{ required: true, message: '请输入课程内容' }]}
  108. name="videoContent"
  109. placeholder="请输入您的课程内容"
  110. />
  111. </ColField>
  112. <ColField title="课程视频及视频封面" required border={false}>
  113. <Row
  114. justify="space-between"
  115. style={{ width: '100%', paddingTop: '12px' }}
  116. >
  117. <Col span={12}>
  118. <Field
  119. style={{ padding: 0 }}
  120. name="videoUrl"
  121. rules={[{ required: true, message: '请上传课程视频' }]}
  122. v-slots={{
  123. input: () => (
  124. <ColUploadVideo
  125. bucket="video-course"
  126. v-model={item.videoUrl}
  127. v-model:posterUrl={item.posterUrl}
  128. class={styles.upload}
  129. tips="点击上传视频"
  130. />
  131. )
  132. }}
  133. />
  134. </Col>
  135. <Col span={12}>
  136. <Field
  137. style={{ padding: 0 }}
  138. name="coverUrl"
  139. rules={[{ required: true, message: '请上传课程封面' }]}
  140. error
  141. v-slots={{
  142. input: () => (
  143. <ColUpload
  144. class={styles.upload}
  145. cropper
  146. bucket="video-course"
  147. options={{
  148. fixedNumber: [1.77, 1],
  149. autoCropWidth: 750,
  150. autoCropHeight: 424
  151. }}
  152. v-model={item.coverUrl}
  153. tips="点击上传视频封面"
  154. />
  155. )
  156. }}
  157. />
  158. </Col>
  159. </Row>
  160. </ColField>
  161. {/* <van-icon name="clear" /> */}
  162. <ColField title="关联曲目或专辑">
  163. <Field
  164. modelValue={
  165. item.relationList.length > 0 &&
  166. item.relationList[0].musicAlbumId
  167. ? this.getName(item)
  168. : ''
  169. }
  170. readonly
  171. isLink
  172. clickable={false}
  173. clearable
  174. rightIcon={
  175. item.relationList.length > 0 &&
  176. item.relationList[0].musicAlbumId
  177. ? 'clear'
  178. : ''
  179. }
  180. onClick-right-icon={(e: MouseEvent) => {
  181. e.stopPropagation()
  182. item.relationList[0].musicAlbumId = 0
  183. item.relationList[0].musicAlbumName = ''
  184. }}
  185. onClick={() => {
  186. this.selectItem = item
  187. this.musicStatus = true
  188. }}
  189. placeholder="请选择关联曲目或专辑"
  190. />
  191. </ColField>
  192. </ColFieldGroup>
  193. </>
  194. ))}
  195. <Button
  196. class={styles['add-item']}
  197. block
  198. icon="add-o"
  199. onClick={this.addItem}
  200. >
  201. 添加课程
  202. </Button>
  203. <Sticky offsetBottom={0} position="bottom" zIndex={999999}>
  204. <div class={['btnGroup', 'btnMore']}>
  205. <Button
  206. block
  207. round
  208. type="primary"
  209. plain
  210. onClick={() => {
  211. createState.active = 1
  212. }}
  213. >
  214. 上一步
  215. </Button>
  216. <Button block round type="primary" native-type="submit">
  217. 提交
  218. </Button>
  219. </div>
  220. </Sticky>
  221. <ColPopup v-model={this.musicStatus} zIndex={999999}>
  222. <MusicAlbum
  223. subjectId={createState.lessonGroup.lessonSubject}
  224. onSelect={(item: any) => {
  225. this.musicStatus = false
  226. if (this.selectItem.relationList.length > 0) {
  227. this.selectItem.relationList[0].musicAlbumId = item.id
  228. this.selectItem.relationList[0].musicAlbumName =
  229. item.selectType === 'ALBUM'
  230. ? item.albumName
  231. : item.musicSheetName
  232. this.selectItem.relationList[0].relationMusicAlbum =
  233. item.selectType
  234. } else {
  235. this.selectItem.relationList = [
  236. {
  237. musicAlbumId: item.id,
  238. musicAlbumName:
  239. item.selectType === 'ALBUM'
  240. ? item.albumName
  241. : item.musicSheetName,
  242. relationMusicAlbum: item.selectType,
  243. useRelationType: 'RECOMMEND'
  244. }
  245. ]
  246. }
  247. }}
  248. />
  249. </ColPopup>
  250. </Form>
  251. )
  252. }
  253. })