completeTask.vue 14 KB

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