completeTask.vue 14 KB

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