completeTask.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <template>
  2. <view class="container">
  3. <scroll-view class="content" scroll-y>
  4. <!-- 标题 -->
  5. <view class="form-section">
  6. <view class="form-label">
  7. <text class="required">*</text>
  8. <text>标题</text>
  9. </view>
  10. <view class="form-input-wrapper">
  11. <textarea
  12. class="form-input"
  13. v-model="formData.title"
  14. placeholder="请输入标题"
  15. maxlength="50"
  16. @input="onTitleInput"
  17. ></textarea>
  18. <view class="char-count">{{ titleLength }}/50</view>
  19. </view>
  20. </view>
  21. <!-- 摘要 -->
  22. <view class="form-section">
  23. <view class="form-label">
  24. <text>摘要 (选填)</text>
  25. </view>
  26. <view class="form-input-wrapper">
  27. <textarea
  28. class="form-input"
  29. v-model="formData.summary"
  30. placeholder="请输入摘要"
  31. maxlength="100"
  32. @input="onSummaryInput"
  33. ></textarea>
  34. <view class="char-count">{{ summaryLength }}/100</view>
  35. </view>
  36. </view>
  37. <!-- 项目分组 -->
  38. <view class="form-section">
  39. <view class="form-label">
  40. <text class="required">*</text>
  41. <text>项目分组</text>
  42. </view>
  43. <view class="form-select" @click="showGroupPicker = true">
  44. <text :class="formData.groupId ? '' : 'placeholder'">
  45. {{ formData.groupName || '请选择分组' }}
  46. </text>
  47. <text class="arrow-right">></text>
  48. </view>
  49. </view>
  50. <!-- 项目标签 -->
  51. <view class="form-section">
  52. <view class="form-label">
  53. <text class="required">*</text>
  54. <text>项目标签</text>
  55. </view>
  56. <view class="form-select" @click="showTagPicker = true">
  57. <text :class="formData.tagId ? '' : 'placeholder'">
  58. {{ formData.tagName || '请选择标签' }}
  59. </text>
  60. <text class="arrow-right">></text>
  61. </view>
  62. </view>
  63. <!-- 上传封面 -->
  64. <view class="form-section">
  65. <view class="form-label">
  66. <text class="required">*</text>
  67. <text>上传封面</text>
  68. </view>
  69. <view class="form-tips">仅支持jpg/png文件,单个图片不超过2M</view>
  70. <view class="upload-cover" @click="chooseCoverImage">
  71. <image class="img" v-if="formData.coverImage" :src="formData.coverImage" mode="aspectFill"></image>
  72. <view v-else class="upload-placeholder">
  73. <image class="w48 h48" src="@/static/image/icon_camera1.png" mode=""></image>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 上传附件 -->
  78. <view class="form-section">
  79. <view class="form-label">
  80. <text class="required">*</text>
  81. <text>上传附件</text>
  82. </view>
  83. <view class="form-tips">支持MP4等文件,单个文件不超过500M</view>
  84. <view class="attachment-list">
  85. <view class="attachment-item" v-for="(item, index) in formData.attachments" :key="index">
  86. <text class="attachment-icon">📎</text>
  87. <view class="attachment-info">
  88. <text class="attachment-name">{{ item.name }}</text>
  89. <text class="attachment-size">{{ item.size }}</text>
  90. </view>
  91. <text class="attachment-delete" @click="removeAttachment(index)">×</text>
  92. </view>
  93. <view class="add-attachment" @click="chooseAttachment">
  94. <text class="add-icon">+</text>
  95. <text>添加附件</text>
  96. </view>
  97. </view>
  98. </view>
  99. </scroll-view>
  100. <!-- 提交按钮 -->
  101. <view class="submit-box">
  102. <view class="submit-btn" @click="handleSubmit">提交</view>
  103. </view>
  104. <!-- 分组选择弹窗 -->
  105. <view class="picker-popup" v-if="showGroupPicker" @click="showGroupPicker = false">
  106. <view class="picker-content" @click.stop>
  107. <view class="picker-header">
  108. <view class="picker-cancel" @click="showGroupPicker = false">取消</view>
  109. <view class="picker-title">选择分组</view>
  110. <view class="picker-confirm" @click="confirmGroup">确定</view>
  111. </view>
  112. <view class="picker-body">
  113. <view class="picker-item"
  114. :class="{ active: tempGroupId === item.id }"
  115. v-for="(item, index) in groupOptions"
  116. :key="index"
  117. @click="tempGroupId = item.id; tempGroupName = item.name">
  118. {{ item.name }}
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. <!-- 标签选择弹窗 -->
  124. <view class="picker-popup" v-if="showTagPicker" @click="showTagPicker = false">
  125. <view class="picker-content" @click.stop>
  126. <view class="picker-header">
  127. <view class="picker-cancel" @click="showTagPicker = false">取消</view>
  128. <view class="picker-title">选择标签</view>
  129. <view class="picker-confirm" @click="confirmTag">确定</view>
  130. </view>
  131. <view class="picker-body">
  132. <view class="picker-item"
  133. :class="{ active: tempTagId === item.id }"
  134. v-for="(item, index) in tagOptions"
  135. :key="index"
  136. @click="tempTagId = item.id; tempTagName = item.name">
  137. {{ item.name }}
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. </view>
  143. </template>
  144. <script>
  145. import { submitTask, getGroupOptions, getTagOptions, uploadFile } from '@/api-js/airClassroom'
  146. export default {
  147. data() {
  148. return {
  149. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  150. taskId: '',
  151. isEdit: false,
  152. showGroupPicker: false,
  153. showTagPicker: false,
  154. tempGroupId: '',
  155. tempGroupName: '',
  156. tempTagId: '',
  157. tempTagName: '',
  158. formData: {
  159. title: '',
  160. summary: '',
  161. groupId: '',
  162. groupName: '',
  163. tagId: '',
  164. tagName: '',
  165. coverImage: '',
  166. attachments: []
  167. },
  168. groupOptions: [
  169. { id: '1', name: '学术' },
  170. { id: '2', name: '临床' },
  171. { id: '3', name: '科研' }
  172. ],
  173. tagOptions: [
  174. { id: '1', name: '长视频' },
  175. { id: '2', name: '短视频' },
  176. { id: '3', name: '文章' }
  177. ]
  178. }
  179. },
  180. computed: {
  181. titleLength() {
  182. return this.formData.title.length
  183. },
  184. summaryLength() {
  185. return this.formData.summary.length
  186. }
  187. },
  188. onLoad(options) {
  189. if (options.id) {
  190. this.taskId = options.id
  191. }
  192. if (options.edit === 'true') {
  193. this.isEdit = true
  194. this.loadTaskData()
  195. }
  196. this.loadOptions()
  197. },
  198. methods: {
  199. goBack() {
  200. uni.navigateBack()
  201. },
  202. onTitleInput(e) {
  203. this.formData.title = e.detail.value
  204. },
  205. onSummaryInput(e) {
  206. this.formData.summary = e.detail.value
  207. },
  208. confirmGroup() {
  209. this.formData.groupId = this.tempGroupId
  210. this.formData.groupName = this.tempGroupName
  211. this.showGroupPicker = false
  212. },
  213. confirmTag() {
  214. this.formData.tagId = this.tempTagId
  215. this.formData.tagName = this.tempTagName
  216. this.showTagPicker = false
  217. },
  218. chooseCoverImage() {
  219. uni.chooseImage({
  220. count: 1,
  221. sizeType: ['compressed'],
  222. sourceType: ['album', 'camera'],
  223. success: async (res) => {
  224. try {
  225. uni.showLoading({ title: '上传中...' })
  226. const uploadRes = await uploadFile({
  227. file: res.tempFilePaths[0],
  228. type: 'cover'
  229. })
  230. uni.hideLoading()
  231. if (uploadRes.code === 200 && uploadRes.data) {
  232. this.formData.coverImage = uploadRes.data.url
  233. }
  234. } catch (e) {
  235. uni.hideLoading()
  236. uni.showToast({ icon: 'none', title: '上传失败' })
  237. }
  238. }
  239. })
  240. },
  241. chooseAttachment() {
  242. uni.chooseFile({
  243. count: 1,
  244. type: 'file',
  245. success: async (res) => {
  246. const file = res.tempFiles[0]
  247. if (file.size > 500 * 1024 * 1024) {
  248. uni.showToast({ icon: 'none', title: '文件大小不能超过500M' })
  249. return
  250. }
  251. try {
  252. uni.showLoading({ title: '上传中...' })
  253. const uploadRes = await uploadFile({
  254. file: file.path,
  255. type: 'attachment'
  256. })
  257. uni.hideLoading()
  258. if (uploadRes.code === 200 && uploadRes.data) {
  259. this.formData.attachments.push({
  260. name: file.name,
  261. size: this.formatFileSize(file.size),
  262. url: uploadRes.data.url
  263. })
  264. }
  265. } catch (e) {
  266. uni.hideLoading()
  267. uni.showToast({ icon: 'none', title: '上传失败' })
  268. }
  269. }
  270. })
  271. },
  272. removeAttachment(index) {
  273. this.formData.attachments.splice(index, 1)
  274. },
  275. formatFileSize(bytes) {
  276. if (bytes < 1024) return bytes + 'B'
  277. if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + 'KB'
  278. return (bytes / (1024 * 1024)).toFixed(2) + 'MB'
  279. },
  280. async loadOptions() {
  281. try {
  282. const [groupRes, tagRes] = await Promise.all([
  283. getGroupOptions(),
  284. getTagOptions()
  285. ])
  286. if (groupRes.code === 200 && groupRes.data) {
  287. this.groupOptions = groupRes.data
  288. }
  289. if (tagRes.code === 200 && tagRes.data) {
  290. this.tagOptions = tagRes.data
  291. }
  292. } catch (e) {
  293. console.error('加载选项失败', e)
  294. }
  295. },
  296. async loadTaskData() {
  297. // 加载已有任务数据
  298. },
  299. async handleSubmit() {
  300. if (!this.formData.title) {
  301. uni.showToast({ icon: 'none', title: '请输入标题' })
  302. return
  303. }
  304. if (!this.formData.groupId) {
  305. uni.showToast({ icon: 'none', title: '请选择项目分组' })
  306. return
  307. }
  308. if (!this.formData.tagId) {
  309. uni.showToast({ icon: 'none', title: '请选择项目标签' })
  310. return
  311. }
  312. if (!this.formData.coverImage) {
  313. uni.showToast({ icon: 'none', title: '请上传封面' })
  314. return
  315. }
  316. if (this.formData.attachments.length === 0) {
  317. uni.showToast({ icon: 'none', title: '请上传附件' })
  318. return
  319. }
  320. try {
  321. uni.showLoading({ title: '提交中...' })
  322. const res = await submitTask({
  323. taskId: this.taskId,
  324. ...this.formData
  325. })
  326. uni.hideLoading()
  327. if (res.code === 200) {
  328. uni.navigateTo({
  329. url: '/pages_task/taskCompleteSuccess'
  330. })
  331. } else {
  332. uni.showToast({ icon: 'none', title: res.msg || '提交失败' })
  333. }
  334. } catch (e) {
  335. uni.hideLoading()
  336. uni.showToast({ icon: 'none', title: '提交失败' })
  337. }
  338. }
  339. }
  340. }
  341. </script>
  342. <style lang="scss" scoped>
  343. .container {
  344. min-height: 100vh;
  345. background: #f5f5f5;
  346. display: flex;
  347. flex-direction: column;
  348. }
  349. .status-bar {
  350. width: 100%;
  351. background: #fff;
  352. }
  353. .header {
  354. position: relative;
  355. height: 88rpx;
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. background: #fff;
  360. border-bottom: 1rpx solid #f0f0f0;
  361. .back-btn {
  362. position: absolute;
  363. left: 24rpx;
  364. width: 40rpx;
  365. height: 40rpx;
  366. image {
  367. width: 100%;
  368. height: 100%;
  369. }
  370. }
  371. .title {
  372. font-size: 36rpx;
  373. font-weight: bold;
  374. color: #333;
  375. }
  376. .header-right {
  377. position: absolute;
  378. right: 24rpx;
  379. display: flex;
  380. align-items: center;
  381. gap: 16rpx;
  382. .more-icon {
  383. font-size: 32rpx;
  384. color: #333;
  385. }
  386. }
  387. }
  388. .content {
  389. flex: 1;
  390. padding: 24rpx;
  391. padding-bottom: 120rpx;
  392. box-sizing: border-box;
  393. }
  394. .form-section {
  395. background: #fff;
  396. border-radius: 16rpx;
  397. padding: 24rpx;
  398. &:last-child{
  399. border-bottom: 0;
  400. }
  401. // margin-bottom: 24rpx;
  402. .form-label {
  403. display: flex;
  404. align-items: center;
  405. margin-bottom: 16rpx;
  406. font-size: 28rpx;
  407. color: #333;
  408. .required {
  409. color: #FF5030;
  410. margin-right: 4rpx;
  411. }
  412. }
  413. .form-tips {
  414. font-size: 24rpx;
  415. color: #999;
  416. margin-bottom: 16rpx;
  417. }
  418. .form-input-wrapper {
  419. position: relative;
  420. border-bottom: 1rpx solid #EBEDF0;
  421. .form-input {
  422. width: 100%;
  423. min-height: 120rpx;
  424. padding: 16rpx;
  425. font-size: 28rpx;
  426. color: #333;
  427. box-sizing: border-box;
  428. }
  429. .char-count {
  430. position: absolute;
  431. right: 16rpx;
  432. bottom: 16rpx;
  433. font-size: 24rpx;
  434. color: #999;
  435. }
  436. }
  437. .form-select {
  438. display: flex;
  439. align-items: center;
  440. justify-content: space-between;
  441. height: 80rpx;
  442. padding: 0 24rpx;
  443. border-bottom: 1rpx solid #EBEDF0;
  444. font-size: 28rpx;
  445. color: #333;
  446. .placeholder {
  447. color: #999;
  448. }
  449. .arrow-right {
  450. font-size: 24rpx;
  451. color: #999;
  452. }
  453. }
  454. .upload-cover {
  455. width: 200rpx;
  456. height: 200rpx;
  457. background: #f5f5f5;
  458. border-radius: 8rpx;
  459. display: flex;
  460. align-items: center;
  461. justify-content: center;
  462. .img {
  463. width: 100%;
  464. height: 100%;
  465. border-radius: 8rpx;
  466. }
  467. .upload-placeholder {
  468. .camera-icon {
  469. font-size: 60rpx;
  470. }
  471. }
  472. }
  473. .attachment-list {
  474. .attachment-item {
  475. display: flex;
  476. align-items: center;
  477. padding: 16rpx;
  478. background: #f5f5f5;
  479. border-radius: 8rpx;
  480. margin-bottom: 16rpx;
  481. .attachment-icon {
  482. font-size: 32rpx;
  483. margin-right: 16rpx;
  484. }
  485. .attachment-info {
  486. flex: 1;
  487. display: flex;
  488. flex-direction: column;
  489. .attachment-name {
  490. font-size: 28rpx;
  491. color: #333;
  492. margin-bottom: 4rpx;
  493. }
  494. .attachment-size {
  495. font-size: 24rpx;
  496. color: #999;
  497. }
  498. }
  499. .attachment-delete {
  500. font-size: 40rpx;
  501. color: #999;
  502. width: 40rpx;
  503. height: 40rpx;
  504. display: flex;
  505. align-items: center;
  506. justify-content: center;
  507. }
  508. }
  509. .add-attachment {
  510. display: flex;
  511. align-items: center;
  512. justify-content: center;
  513. padding: 24rpx;
  514. background: rgba(56,139,255,0.08);
  515. border-radius: 12rpx 12rpx 12rpx 12rpx;
  516. border: 2rpx solid #388BFF;
  517. font-family: PingFang SC, PingFang SC;
  518. font-weight: 400;
  519. font-size: 28rpx;
  520. color: #388BFF;
  521. .add-icon {
  522. font-size: 32rpx;
  523. margin-right: 8rpx;
  524. }
  525. }
  526. }
  527. }
  528. .submit-box{
  529. position: fixed;
  530. bottom: 0;
  531. left: 0;
  532. right: 0;
  533. background: #fff;
  534. z-index: 100;
  535. padding: 24rpx 32rpx;
  536. .submit-btn {
  537. height: 88rpx;
  538. background: #388BFF;
  539. border-radius: 200rpx 200rpx 200rpx 200rpx;
  540. display: flex;
  541. align-items: center;
  542. justify-content: center;
  543. font-size: 32rpx;
  544. color: #fff;
  545. font-weight: 500;
  546. }
  547. }
  548. .picker-popup {
  549. position: fixed;
  550. top: 0;
  551. left: 0;
  552. right: 0;
  553. bottom: 0;
  554. background: rgba(0, 0, 0, 0.5);
  555. z-index: 999;
  556. display: flex;
  557. align-items: flex-end;
  558. }
  559. .picker-content {
  560. width: 100%;
  561. background: #fff;
  562. border-radius: 24rpx 24rpx 0 0;
  563. .picker-header {
  564. display: flex;
  565. align-items: center;
  566. justify-content: space-between;
  567. padding: 24rpx;
  568. border-bottom: 1rpx solid #f0f0f0;
  569. .picker-cancel {
  570. font-size: 30rpx;
  571. color: #666;
  572. }
  573. .picker-title {
  574. font-size: 32rpx;
  575. font-weight: bold;
  576. color: #333;
  577. }
  578. .picker-confirm {
  579. font-size: 30rpx;
  580. color: #388BFF;
  581. }
  582. }
  583. .picker-body {
  584. padding: 24rpx;
  585. max-height: 600rpx;
  586. overflow-y: auto;
  587. .picker-item {
  588. padding: 24rpx 0;
  589. font-size: 30rpx;
  590. color: #333;
  591. border-bottom: 1rpx solid #f0f0f0;
  592. &:last-child {
  593. border-bottom: none;
  594. }
  595. &.active {
  596. color: #388BFF;
  597. font-weight: bold;
  598. }
  599. }
  600. }
  601. }
  602. </style>