create-task.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="form-container">
  4. <view class="form-item">
  5. <text class="label">任务名称</text>
  6. <input class="input" v-model="form.title" placeholder="请输入任务名称" />
  7. </view>
  8. <view class="form-item">
  9. <text class="label">任务描述</text>
  10. <textarea class="textarea" v-model="form.description" placeholder="请输入任务描述" />
  11. </view>
  12. <view class="form-item">
  13. <text class="label">选择成员(可多选)</text>
  14. <checkbox-group @change="onChildrenChange">
  15. <label class="child-checkbox" v-for="child in children" :key="child.id">
  16. <checkbox :value="String(child.id)" :checked="selectedChildIds.includes(String(child.id))" />
  17. <text class="child-name">{{ child.nickname }}</text>
  18. </label>
  19. </checkbox-group>
  20. </view>
  21. <view class="form-item">
  22. <text class="label">积分</text>
  23. <input class="input" type="number" v-model="form.points" placeholder="请输入积分 (1-10)" />
  24. </view>
  25. <view class="form-item">
  26. <text class="label">分类</text>
  27. <picker :range="categories" @change="onCategoryChange">
  28. <view class="picker">
  29. {{ form.category || '请选择分类' }}
  30. </view>
  31. </picker>
  32. </view>
  33. <!-- 小游戏选择(当选择"小游戏类"时显示) -->
  34. <view class="form-item" v-if="form.category === '小游戏类'">
  35. <text class="label">选择小游戏</text>
  36. <picker :range="miniGames" range-key="gameName" @change="onMinigameChange">
  37. <view class="picker">
  38. {{ selectedMinigame ? selectedMinigame.gameName : '请选择小游戏' }}
  39. </view>
  40. </picker>
  41. </view>
  42. <!-- TASK-003: 截止时间设置 -->
  43. <view class="form-item">
  44. <text class="label">截止时间</text>
  45. <picker mode="multiSelector" :range="dateTimeRange" :value="dateTimeIndex" @change="onDateTimeChange" @columnchange="onColumnChange">
  46. <view class="picker">
  47. {{ deadlineText || '请选择截止时间' }}
  48. </view>
  49. </picker>
  50. </view>
  51. <!-- TASK-004: 重复设置 -->
  52. <view class="form-item">
  53. <text class="label">重复设置</text>
  54. <picker :range="repeatTypes" range-key="label" @change="onRepeatChange">
  55. <view class="picker">
  56. {{ repeatTypeLabel || '不重复' }}
  57. </view>
  58. </picker>
  59. </view>
  60. <view class="form-item">
  61. <text class="label">需要审核</text>
  62. <switch :checked="form.needReview" @change="onNeedReviewChange" />
  63. </view>
  64. <!-- TASK-SYS-248: 联动动作 -->
  65. <view class="form-item">
  66. <text class="label">联动动作(可选)</text>
  67. <picker :range="actionTypes" range-key="label" @change="onActionTypeChange">
  68. <view class="picker">
  69. {{ actionTypeLabel || '无(手动完成)' }}
  70. </view>
  71. </picker>
  72. <text class="form-hint">选择后任务按钮将跳转对应功能页</text>
  73. </view>
  74. <view class="form-item" v-if="form.actionType === 'cart' || form.actionType === 'order'">
  75. <text class="label">商品ID(购物任务)</text>
  76. <input class="input" type="number" v-model="form.actionConfig" placeholder="请输入商品ID,如 123" />
  77. <text class="form-hint">购物任务:点开始自动加购并跳转购物车</text>
  78. </view>
  79. <!-- 阅读打卡:三模式配置(指定文章 / 按时长 / 按数量) -->
  80. <view class="form-item" v-if="form.actionType === 'article'">
  81. <text class="label">阅读模式</text>
  82. <radio-group class="read-mode-group" @change="onReadModeChange">
  83. <label class="read-mode-item" v-for="mode in readModes" :key="mode.value">
  84. <radio :value="mode.value" :checked="readMode === mode.value" color="#f97316" />
  85. <text class="read-mode-label">{{ mode.label }}</text>
  86. </label>
  87. </radio-group>
  88. <text class="form-hint">选择「阅读打卡」任务的完成判定方式</text>
  89. </view>
  90. <view class="form-item" v-if="form.actionType === 'article' && readMode === 'ARTICLE'">
  91. <text class="label">指定文章</text>
  92. <picker :range="articleNames" @change="onArticleChange">
  93. <view class="picker">
  94. {{ articleLoading ? '加载中...' : (selectedArticleName || '请选择文章') }}
  95. </view>
  96. </picker>
  97. <text class="form-hint">孩子需读完指定文章并答对测试题(通过率 {{ readQuizPassRate }}%)才算完成任务</text>
  98. </view>
  99. <view class="form-item" v-if="form.actionType === 'article' && readMode !== 'COUNT'">
  100. <text class="label">阅读时长(分钟)</text>
  101. <input class="input" type="number" v-model="readMinutes" placeholder="请输入阅读时长,默认 5 分钟" />
  102. <text class="form-hint">孩子需累计阅读满该时长才算达标(按秒累计,后端计时)</text>
  103. </view>
  104. <view class="form-item" v-if="form.actionType === 'article' && readMode === 'COUNT'">
  105. <text class="label">阅读篇数(N)</text>
  106. <input class="input" type="number" v-model="readTargetCount" placeholder="请输入需完成文章篇数,默认 1" />
  107. <text class="form-hint">孩子每完成一篇(阅读+答题通过)累计 1 篇,达 N 篇自动完成任务</text>
  108. </view>
  109. <view class="form-item" v-if="form.actionType === 'article' && readMode === 'COUNT'">
  110. <text class="label">每日进度</text>
  111. <switch :checked="readIsDailyProgress" @change="onReadIsDailyProgressChange" />
  112. <text class="form-hint">开启后按「每天完成 N 篇」判定;关闭后为一次性累计 N 篇</text>
  113. </view>
  114. <view class="form-item" v-if="form.actionType === 'article' && readMode === 'COUNT'">
  115. <text class="label">每篇需答题通过</text>
  116. <switch :checked="readRequireQuiz" @change="onReadRequireQuizChange" />
  117. <text class="form-hint">开启后每篇文章需答题通过才计入进度</text>
  118. </view>
  119. <view class="form-item" v-if="form.actionType === 'article' && readMode !== 'DURATION' && (readMode !== 'COUNT' || readRequireQuiz)">
  120. <text class="label">答题通过率(%)</text>
  121. <input class="input" type="number" v-model="readQuizPassRate" placeholder="默认 60" />
  122. <text class="form-hint">答题正确率需 ≥ 该比例才算通过,默认 60%</text>
  123. </view>
  124. <view class="form-item">
  125. <text class="label">需先开始再完成(两阶段)</text>
  126. <switch :checked="form.startRequired" @change="onStartRequiredChange" />
  127. <text class="form-hint">小游戏/专注/购物等任务建议开启</text>
  128. </view>
  129. <view class="form-item">
  130. <text class="label">需填写内容后完成</text>
  131. <switch :checked="form.requireInput" @change="onRequireInputChange" />
  132. </view>
  133. <view class="form-item">
  134. <text class="label">预计时长(分钟)</text>
  135. <input class="input" type="number" v-model="form.duration" placeholder="请输入预计完成时长" />
  136. </view>
  137. <button class="btn-primary" :loading="submitting" :disabled="submitting" @click="submit">创建任务</button>
  138. <!-- TASK-SYS-248: 前置/后置任务(流程任务) -->
  139. <view class="form-item form-item--flow">
  140. <text class="label label--pre">前置任务(可选,多选)</text>
  141. <text class="form-hint form-hint--tight">选择本任务执行前必须完成的任务</text>
  142. <view class="task-picker-scroll">
  143. <view v-for="task in prerequisiteTasks" :key="task.id" class="task-checkbox-row" @click="togglePrerequisite(task.id)">
  144. <view class="task-checkbox" :class="{ checked: form.prerequisiteTaskIds.indexOf(task.id) > -1 }">
  145. <text v-if="form.prerequisiteTaskIds.indexOf(task.id) > -1" class="check-icon">✓</text>
  146. </view>
  147. <text class="task-checkbox-label">{{ task.title }}</text>
  148. </view>
  149. <text v-if="prerequisiteTaskList.length === 0" class="form-hint">暂无可用任务</text>
  150. </view>
  151. </view>
  152. <view class="form-item">
  153. <text class="label label--post">后置任务(可选,多选)</text>
  154. <text class="form-hint form-hint--tight">选择本任务完成后自动解锁的任务(任意一个完成即可)</text>
  155. <view class="task-picker-scroll">
  156. <view v-for="task in successorTasks" :key="task.id" class="task-checkbox-row" @click="toggleSuccessor(task.id)">
  157. <view class="task-checkbox" :class="{ checked: form.successorTaskIds.indexOf(task.id) > -1 }">
  158. <text v-if="form.successorTaskIds.indexOf(task.id) > -1" class="check-icon">✓</text>
  159. </view>
  160. <text class="task-checkbox-label">{{ task.title }}</text>
  161. </view>
  162. <text v-if="successorTaskList.length === 0" class="form-hint">暂无可用任务</text>
  163. </view>
  164. </view>
  165. <view class="form-item" v-if="form.prerequisiteTaskIds.length > 0 || form.successorTaskIds.length > 0">
  166. <text class="label">流程任务</text>
  167. <text class="flow-hint">自动标记为流程任务</text>
  168. <text class="form-hint">有前置或后置任务时,本任务将自动保存为流程任务</text>
  169. </view>
  170. </view>
  171. </view>
  172. </template>
  173. <script>
  174. import config from '@/config.js'
  175. import { getChildren, createTask, getTaskListForPicker, getArticleList } from '../../utils/api.js'
  176. import fontScaleMixin from '@/mixins/font-scale.js'
  177. export default {
  178. mixins: [fontScaleMixin],
  179. data() {
  180. return {
  181. form: {
  182. title: '',
  183. description: '',
  184. memberIds: [],
  185. points: 2,
  186. category: '',
  187. minigameCode: '',
  188. deadline: null,
  189. repeatType: 'none',
  190. needReview: false,
  191. duration: null,
  192. actionType: '',
  193. actionConfig: '',
  194. requireInput: false,
  195. startRequired: false,
  196. prerequisiteTaskIds: [],
  197. successorTaskIds: []
  198. },
  199. children: [],
  200. selectedChildIds: [],
  201. categories: ['学习类', '生活类', '运动类', '小游戏类', '其他'],
  202. miniGames: [],
  203. selectedMinigame: null,
  204. prerequisiteTaskList: [],
  205. successorTaskList: [],
  206. // 阅读打卡三模式(ARCH §7.1 / API_REFERENCE §4.12,mode 常量大写)
  207. readModes: [
  208. { value: 'ARTICLE', label: '指定文章' },
  209. { value: 'DURATION', label: '按时长' },
  210. { value: 'COUNT', label: '按数量' }
  211. ],
  212. readMode: 'DURATION',
  213. articleOptions: [],
  214. articleLoading: false,
  215. selectedArticleIndex: -1,
  216. readMinutes: 5,
  217. readTargetCount: 1,
  218. readRequireQuiz: true,
  219. readQuizPassRate: 60,
  220. readIsDailyProgress: false,
  221. repeatTypes: [
  222. { value: 'none', label: '不重复' },
  223. { value: 'daily', label: '每天' },
  224. { value: 'weekly', label: '每周' },
  225. { value: 'every_other_day', label: '隔天' },
  226. { value: 'monthly', label: '每月' }
  227. ],
  228. actionTypes: [
  229. { value: '', label: '无(手动完成)' },
  230. { value: 'minigame', label: '小游戏' },
  231. { value: 'focus', label: '专注训练' },
  232. { value: 'survey', label: '问卷/测评' },
  233. { value: 'article', label: '文章阅读' },
  234. { value: 'activity', label: '活动报名' },
  235. { value: 'cart', label: '购物(加购)' },
  236. { value: 'order', label: '购物(支付/收货)' },
  237. { value: 'diet', label: '饮食打卡' },
  238. { value: 'sleep', label: '睡眠打卡' },
  239. { value: 'exercise', label: '运动打卡' }
  240. ],
  241. dateTimeRange: [[], [], [], [], []],
  242. dateTimeIndex: [0, 0, 0, 0, 0],
  243. deadlineText: '',
  244. submitting: false
  245. }
  246. },
  247. computed: {
  248. repeatTypeLabel() {
  249. const found = this.repeatTypes.find(r => r.value === this.form.repeatType)
  250. return found ? found.label : ''
  251. },
  252. actionTypeLabel() {
  253. const found = this.actionTypes.find(a => a.value === this.form.actionType)
  254. return found ? found.label : ''
  255. },
  256. // 文章选择器 range(标题 + 可读时长标注,禁用 :key 表达式,用方法取值)
  257. articleNames() {
  258. var list = []
  259. var a, i
  260. for (i = 0; i < this.articleOptions.length; i++) {
  261. a = this.articleOptions[i]
  262. list.push((a.title || '未命名文章') + (a.readTime ? '(' + a.readTime + '分钟)' : ''))
  263. }
  264. return list
  265. },
  266. selectedArticleName() {
  267. if (this.selectedArticleIndex >= 0 && this.articleOptions[this.selectedArticleIndex]) {
  268. return this.articleNames[this.selectedArticleIndex]
  269. }
  270. return ''
  271. }
  272. },
  273. onLoad(options) {
  274. this.loadChildren(options.memberId)
  275. this.loadMiniGames()
  276. this.initDateTimePicker()
  277. },
  278. methods: {
  279. async loadChildren(preselectedChildId) {
  280. try {
  281. const res = await getChildren()
  282. this.children = res.data || []
  283. // 如果有 preselect memberId,自动选中该成员
  284. if (preselectedChildId && this.children.length > 0) {
  285. const matched = this.children.find(c => String(c.id) === String(preselectedChildId))
  286. if (matched) {
  287. const idNum = Number(matched.id)
  288. if (!this.form.memberIds.includes(idNum)) {
  289. this.form.memberIds.push(idNum)
  290. this.selectedChildIds.push(String(idNum))
  291. }
  292. }
  293. }
  294. } catch (e) {
  295. console.error(e)
  296. }
  297. },
  298. async loadMiniGames() {
  299. try {
  300. const res = await uni.request({
  301. url: config.api('/api/tasks/minigame-options'),
  302. method: 'POST',
  303. header: {
  304. 'Authorization': `Bearer ${uni.getStorageSync('token')}`
  305. }
  306. })
  307. if (res.data && res.data.code === 200) {
  308. this.miniGames = res.data.data || []
  309. }
  310. } catch (e) {
  311. console.error(e)
  312. }
  313. },
  314. initDateTimePicker() {
  315. // 初始化日期时间选择器
  316. const now = new Date()
  317. const year = now.getFullYear()
  318. const month = now.getMonth() + 1
  319. const day = now.getDate()
  320. const hour = now.getHours()
  321. const minute = now.getMinutes()
  322. // 年(当前年份+未来2年)
  323. const years = []
  324. for (let i = year; i <= year + 2; i++) {
  325. years.push(i + '年')
  326. }
  327. // 月
  328. const months = []
  329. for (let i = 1; i <= 12; i++) {
  330. months.push(i + '月')
  331. }
  332. // 日
  333. const days = []
  334. const daysInMonth = new Date(year, month, 0).getDate()
  335. for (let i = 1; i <= daysInMonth; i++) {
  336. days.push(i + '日')
  337. }
  338. // 时
  339. const hours = []
  340. for (let i = 0; i < 24; i++) {
  341. hours.push(i.toString().padStart(2, '0') + '时')
  342. }
  343. // 分
  344. const minutes = []
  345. for (let i = 0; i < 60; i += 5) {
  346. minutes.push(i.toString().padStart(2, '0') + '分')
  347. }
  348. this.dateTimeRange = [years, months, days, hours, minutes]
  349. // 默认选中当前日期时间
  350. this.dateTimeIndex = [0, month - 1, day - 1, hour, Math.floor(minute / 5)]
  351. },
  352. onChildrenChange(e) {
  353. this.selectedChildIds = e.detail.value
  354. this.form.memberIds = e.detail.value.map(Number)
  355. },
  356. onCategoryChange(e) {
  357. this.form.category = this.categories[e.detail.value]
  358. // 清空小游戏选择
  359. if (this.form.category !== '小游戏类') {
  360. this.form.minigameCode = ''
  361. this.selectedMinigame = null
  362. }
  363. },
  364. onMinigameChange(e) {
  365. this.selectedMinigame = this.miniGames[e.detail.value]
  366. this.form.minigameCode = this.selectedMinigame.gameCode
  367. // 自动填充任务名称
  368. if (!this.form.title) {
  369. this.form.title = this.selectedMinigame.gameName
  370. }
  371. // 自动填充积分
  372. if (this.selectedMinigame.defaultPoints) {
  373. this.form.points = this.selectedMinigame.defaultPoints
  374. }
  375. },
  376. onDateTimeChange(e) {
  377. const vals = e.detail.value
  378. this.dateTimeIndex = vals
  379. const now = new Date()
  380. const year = now.getFullYear() + vals[0]
  381. const month = vals[1] + 1
  382. const day = vals[2] + 1
  383. const hour = vals[3]
  384. const minute = vals[4] * 5
  385. this.deadlineText = `${year}年${month}月${day}日 ${hour.toString().padStart(2, '0')}:${minute.toString().padStart(2, '0')}`
  386. this.form.deadline = new Date(year, month - 1, day, hour, minute)
  387. },
  388. onColumnChange(e) {
  389. const column = e.detail.column
  390. this.$set(this.dateTimeIndex, column, e.detail.value)
  391. // 年、月变化时更新当月天数(含闰年处理)
  392. if (column === 0 || column === 1) {
  393. const now = new Date()
  394. const year = now.getFullYear() + this.dateTimeIndex[0]
  395. const month = this.dateTimeIndex[1] + 1
  396. const daysInMonth = new Date(year, month, 0).getDate()
  397. const days = []
  398. for (let i = 1; i <= daysInMonth; i++) {
  399. days.push(i + '日')
  400. }
  401. this.$set(this.dateTimeRange, 2, days)
  402. // 若选中的日超出新月天数,回退到最后一天
  403. if (this.dateTimeIndex[2] >= daysInMonth) {
  404. this.$set(this.dateTimeIndex, 2, daysInMonth - 1)
  405. }
  406. }
  407. },
  408. onRepeatChange(e) {
  409. const selected = this.repeatTypes[e.detail.value]
  410. this.form.repeatType = selected.value
  411. },
  412. onNeedReviewChange(e) {
  413. this.form.needReview = e.detail.value
  414. },
  415. onActionTypeChange(e) {
  416. const selected = this.actionTypes[e.detail.value]
  417. this.form.actionType = selected.value
  418. if (selected.value !== 'cart' && selected.value !== 'order') {
  419. this.form.actionConfig = ''
  420. }
  421. // 阅读打卡:切换为文章模式时预加载文章列表
  422. if (selected.value === 'article') {
  423. this.readMode = 'DURATION'
  424. this.selectedArticleIndex = -1
  425. if (this.articleOptions.length === 0) {
  426. this.loadArticles()
  427. }
  428. }
  429. },
  430. // 阅读打卡三模式切换
  431. onReadModeChange(e) {
  432. this.readMode = e.detail.value || 'DURATION'
  433. // 进入指定文章模式时按需加载文章列表
  434. if (this.readMode === 'ARTICLE' && this.articleOptions.length === 0) {
  435. this.loadArticles()
  436. }
  437. },
  438. // 文章选择器
  439. onArticleChange(e) {
  440. this.selectedArticleIndex = parseInt(e.detail.value) || 0
  441. },
  442. onReadRequireQuizChange(e) {
  443. this.readRequireQuiz = e.detail.value
  444. },
  445. onReadIsDailyProgressChange(e) {
  446. this.readIsDailyProgress = e.detail.value
  447. },
  448. async loadArticles() {
  449. if (this.articleLoading) return
  450. this.articleLoading = true
  451. try {
  452. var res = await getArticleList({ page: 1, size: 50 })
  453. if (res && res.code === 200 && res.data) {
  454. this.articleOptions = res.data.records || res.data.list || []
  455. }
  456. } catch (e) {
  457. uni.showToast({ title: '文章列表加载失败', icon: 'none' })
  458. } finally {
  459. this.articleLoading = false
  460. }
  461. },
  462. onStartRequiredChange(e) {
  463. this.form.startRequired = e.detail.value
  464. },
  465. onRequireInputChange(e) {
  466. this.form.requireInput = e.detail.value
  467. },
  468. async loadRelatedTasks() {
  469. try {
  470. var res = await getTaskListForPicker({
  471. memberId: this.form.memberIds.length > 0 ? this.form.memberIds[0] : null,
  472. titleKeyword: this.form.category
  473. })
  474. if (res && res.code === 200) {
  475. // 过滤掉已经在表单中选择的任务 ID(排除当前正在创建的任务本身)
  476. const allTasks = res.data || []
  477. this.prerequisiteTaskList = allTasks.filter(t => !this.form.prerequisiteTaskIds.includes(t.id))
  478. this.successorTaskList = allTasks.filter(t => !this.form.successorTaskIds.includes(t.id))
  479. }
  480. } catch (e) {
  481. console.error('加载关联任务列表失败:', e)
  482. }
  483. },
  484. togglePrerequisite(taskId) {
  485. if (this.form.prerequisiteTaskIds.includes(taskId)) {
  486. this.form.prerequisiteTaskIds = this.form.prerequisiteTaskIds.filter(id => id !== taskId)
  487. } else {
  488. this.form.prerequisiteTaskIds.push(taskId)
  489. }
  490. },
  491. toggleSuccessor(taskId) {
  492. if (this.form.successorTaskIds.includes(taskId)) {
  493. this.form.successorTaskIds = this.form.successorTaskIds.filter(id => id !== taskId)
  494. } else {
  495. this.form.successorTaskIds.push(taskId)
  496. }
  497. },
  498. // 阅读打卡:校验并拼装 action_config JSON(键名 camelCase,与 T01 契约一致)
  499. buildArticleActionConfig() {
  500. var mode = this.readMode || 'DURATION'
  501. var cfg = { mode: mode }
  502. var minutes = parseInt(this.readMinutes) || 5
  503. if (minutes <= 0) {
  504. uni.showToast({ title: '请输入有效阅读时长', icon: 'none' })
  505. return null
  506. }
  507. var minSeconds = minutes * 60
  508. if (mode === 'ARTICLE') {
  509. // 指定文章:articleId 必填;requireQuiz 固定 true;quizPassRate A 可配(默认 60%)
  510. var article = this.articleOptions[this.selectedArticleIndex]
  511. if (!article || !article.id) {
  512. uni.showToast({ title: '请选择文章', icon: 'none' })
  513. return null
  514. }
  515. cfg.articleId = article.id
  516. cfg.minSeconds = minSeconds
  517. cfg.requireQuiz = true
  518. cfg.quizPassRate = this.normalizeQuizPassRate()
  519. } else if (mode === 'DURATION') {
  520. // 按时长:仅 minSeconds 单门槛(不要求答题)
  521. cfg.minSeconds = minSeconds
  522. cfg.requireQuiz = false
  523. } else {
  524. // 按数量:targetCount=N;requireQuiz 可配;达 N 后端自动完成
  525. var targetCount = parseInt(this.readTargetCount) || 0
  526. if (targetCount <= 0) {
  527. uni.showToast({ title: '请输入有效阅读篇数', icon: 'none' })
  528. return null
  529. }
  530. cfg.targetCount = targetCount
  531. cfg.requireQuiz = !!this.readRequireQuiz
  532. if (cfg.requireQuiz) {
  533. cfg.quizPassRate = this.normalizeQuizPassRate()
  534. }
  535. }
  536. return JSON.stringify(cfg)
  537. },
  538. // 通过率输入(百分比 0-100)→ 0-1 比例(契约口径:>0 且 ≤1,默认 0.6)
  539. normalizeQuizPassRate() {
  540. var rate = parseInt(this.readQuizPassRate)
  541. if (!rate || rate <= 0) return 0.6
  542. if (rate > 100) rate = 100
  543. return Math.round((rate / 100) * 100) / 100
  544. },
  545. async submit() {
  546. if (this.submitting) return
  547. if (!this.form.title) {
  548. uni.showToast({ title: '请输入任务名称', icon: 'none' })
  549. return
  550. }
  551. if (this.form.memberIds.length === 0) {
  552. uni.showToast({ title: '请选择至少一个成员', icon: 'none' })
  553. return
  554. }
  555. if (!this.form.deadline) {
  556. uni.showToast({ title: '请选择截止时间', icon: 'none' })
  557. return
  558. }
  559. // 小游戏类必须选择具体游戏
  560. if (this.form.category === '小游戏类' && !this.form.minigameCode) {
  561. uni.showToast({ title: '请选择具体小游戏', icon: 'none' })
  562. return
  563. }
  564. // 阅读打卡:按 mode 拼装 action_config(失败时提示并中止)
  565. var articleActionConfig = ''
  566. if (this.form.actionType === 'article') {
  567. articleActionConfig = this.buildArticleActionConfig()
  568. if (!articleActionConfig) return
  569. }
  570. this.submitting = true
  571. uni.showLoading({ title: '创建任务中...' })
  572. const taskData = {
  573. title: this.form.title,
  574. description: this.form.description,
  575. points: parseInt(this.form.points) || 2,
  576. category: this.form.category || '其他',
  577. minigameCode: this.form.minigameCode,
  578. deadline: this.form.deadline.toISOString(),
  579. repeatType: this.form.repeatType,
  580. frequency: this.form.repeatType,
  581. needReview: this.form.needReview ? 1 : 0,
  582. duration: parseInt(this.form.duration) || 0,
  583. // TASK-SYS-248: 行为调度中心字段
  584. actionType: this.form.actionType || '',
  585. actionConfig: this.form.actionType === 'article' ? articleActionConfig : (this.form.actionConfig || ''),
  586. requireInput: this.form.requireInput ? 1 : 0,
  587. startRequired: this.form.startRequired ? 1 : 0,
  588. prerequisiteTaskId: this.form.prerequisiteTaskIds.length > 0 ? this.form.prerequisiteTaskIds[0] : null,
  589. successorTaskIds: this.form.successorTaskIds.length > 0 ? this.form.successorTaskIds : null
  590. }
  591. // 阅读打卡:A/B 模式同步 duration(分钟)为阅读时长;C 每日型传 isDailyProgress/targetValue=N
  592. if (this.form.actionType === 'article') {
  593. var readMinutes = parseInt(this.readMinutes) || 5
  594. if (this.readMode === 'ARTICLE' || this.readMode === 'DURATION') {
  595. taskData.duration = readMinutes
  596. }
  597. if (this.readMode === 'COUNT' && this.readIsDailyProgress) {
  598. taskData.isDailyProgress = 1
  599. taskData.targetValue = parseInt(this.readTargetCount) || 1
  600. }
  601. }
  602. let successCount = 0
  603. let failCount = 0
  604. try {
  605. for (const memberId of this.form.memberIds) {
  606. try {
  607. await createTask({ ...taskData, memberId })
  608. successCount++
  609. } catch (e) {
  610. failCount++
  611. }
  612. }
  613. } finally {
  614. this.submitting = false
  615. uni.hideLoading()
  616. }
  617. if (failCount === 0) {
  618. uni.showToast({ title: `已为${successCount}个成员创建任务`, icon: 'success' })
  619. setTimeout(() => uni.navigateBack(), 1500)
  620. } else if (successCount > 0) {
  621. uni.showToast({ title: `${successCount}个成功,${failCount}个失败`, icon: 'none' })
  622. } else {
  623. uni.showToast({ title: '创建失败', icon: 'none' })
  624. }
  625. }
  626. }
  627. }
  628. </script>
  629. <style scoped lang="scss">
  630. .container { padding: $uni-space-lg; }
  631. .form-container { background: $app-surface; border-radius: 24rpx; padding: $uni-space-lg; }
  632. .form-item { margin-bottom: $uni-space-lg; }
  633. .form-item--flow { margin-top: 20rpx; padding-top: 20rpx; border-top: 1rpx solid $facade-hairline-2; }
  634. .label { display: block; font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-strong; margin-bottom: 10rpx; }
  635. .label--pre { color: $brand-primary; }
  636. .label--post { color: $dim-wisdom; }
  637. .task-picker-scroll { max-height: 200rpx; overflow-y: auto; }
  638. .flow-hint { font-size: calc(24rpx * var(--font-scale, 1)); color: $brand-primary; }
  639. .input, .textarea { border: 1rpx solid $facade-border-soft; border-radius: 8rpx; font-size: calc(28rpx * var(--font-scale, 1)); width: 100%; box-sizing: border-box; }
  640. /* 输入框高度统一 108rpx;line-height 与高度一致,保证微信 input 文字垂直居中 */
  641. .input { height: 108rpx; line-height: 108rpx; padding: 0 24rpx; }
  642. .textarea { height: 150rpx; line-height: 1.5; padding: 20rpx 24rpx; }
  643. .picker { border: 1rpx solid $facade-border-soft; border-radius: 8rpx; font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-body; box-sizing: border-box; height: 108rpx; display: flex; align-items: center; padding: 0 24rpx; }
  644. .form-hint { display: block; font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-top: 8rpx; }
  645. .form-hint--tight { margin-bottom: 10rpx; }
  646. /* 阅读打卡三模式:横向三选一 */
  647. .read-mode-group { display: flex; flex-direction: row; flex-wrap: wrap; gap: 20rpx; margin: 8rpx 0; }
  648. .read-mode-item { display: flex; flex-direction: row; align-items: center; gap: 6rpx; padding: 8rpx 0; }
  649. .read-mode-label { font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-body; }
  650. .child-checkbox { display: flex; align-items: center; padding: 16rpx 0; border-bottom: 1rpx solid $facade-fill; }
  651. .child-checkbox:last-child { border-bottom: none; }
  652. .child-name { font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-strong; margin-left: 10rpx; }
  653. /* 创建按钮:显式 height + line-height 同高,微信 button 文字才能上下居中 */
  654. .btn-primary { background: $brand-primary; color: $app-surface; border-radius: 24rpx; margin-top: 40rpx; width: 100%; height: 96rpx; line-height: 96rpx; font-size: calc(32rpx * var(--font-scale, 1)); border: none; padding: 0; }
  655. /* 清除微信 button 组件默认的 ::after 1px 边框(否则按钮文字与边框视觉不居中) */
  656. .btn-primary::after { border: none; }
  657. </style>