index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <template>
  2. <view class="reminder-config-page" :style="{ '--font-scale': fontScale }">
  3. <scroll-view class="content" scroll-y>
  4. <!-- 提醒开关 -->
  5. <view class="cfg-card">
  6. <view class="cfg-card-header">
  7. <text class="cfg-card-title">提醒开关</text>
  8. <text class="cfg-switch" :class="{ 'cfg-switch-on': enabled === 1 }" @tap="toggleEnabled">
  9. <text class="cfg-switch-text">{{ enabled === 1 ? '已开启' : '已关闭' }}</text>
  10. </text>
  11. </view>
  12. <text class="cfg-card-desc">开启后,任务打卡未完成时会按以下设置发送提醒</text>
  13. </view>
  14. <!-- 提醒渠道 -->
  15. <view class="cfg-card">
  16. <text class="cfg-card-title">提醒渠道</text>
  17. <view class="channel-list">
  18. <view class="channel-item" v-for="(ch, index) in channels" :key="getChannelKey(ch, index)"
  19. :class="{
  20. 'channel-selected': isSelected(ch.type),
  21. 'channel-disabled': !ch.available
  22. }"
  23. @tap="toggleChannel(ch)">
  24. <view class="channel-check" v-if="isSelected(ch.type) && ch.available">✓</view>
  25. <view class="channel-info">
  26. <text class="channel-name">{{ ch.label }}</text>
  27. <text class="channel-reason" v-if="!ch.available">{{ ch.reason || '未开通' }}</text>
  28. </view>
  29. </view>
  30. <view class="channel-tip" v-if="channelTip">
  31. <text class="channel-tip-text">{{ channelTip }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 提醒时机 -->
  36. <view class="cfg-card">
  37. <text class="cfg-card-title">提醒时机</text>
  38. <view class="timing-list">
  39. <view class="timing-item" :class="{ 'timing-active': timingMode === 'before_deadline' }" @tap="switchTiming('before_deadline')">
  40. <text class="timing-name">任务截止前</text>
  41. <text class="timing-desc">截止时间之前提醒</text>
  42. </view>
  43. <view class="timing-item" :class="{ 'timing-active': timingMode === 'after_timeout' }" @tap="switchTiming('after_timeout')">
  44. <text class="timing-name">任务超时后</text>
  45. <text class="timing-desc">截止时间之后提醒</text>
  46. </view>
  47. </view>
  48. <!-- 偏移分钟 -->
  49. <view class="offset-row">
  50. <text class="offset-label">{{ offsetLabel }}</text>
  51. <input class="offset-input" type="number" :value="String(offsetMinutes)" @input="onOffsetInput" placeholder="分钟数" />
  52. <text class="offset-unit">分钟</text>
  53. </view>
  54. <text class="offset-hint" v-if="offsetHint">{{ offsetHint }}</text>
  55. </view>
  56. <!-- 日提醒(早提醒 + 晚总结,独立开关可叠加;设计契约 task.reminder.daily) -->
  57. <view class="cfg-card">
  58. <view class="cfg-card-header">
  59. <text class="cfg-card-title">日提醒</text>
  60. <text class="cfg-switch" :class="{ 'cfg-switch-on': dailyEnabled === 1 }" @tap="toggleDailyEnabled">
  61. <text class="cfg-switch-text">{{ dailyEnabled === 1 ? '已开启' : '已关闭' }}</text>
  62. </text>
  63. </view>
  64. <text class="cfg-card-desc">开启后,每天早上提醒今日待办,晚上总结今日完成情况并提醒补打卡</text>
  65. <view class="daily-time-row" v-if="dailyEnabled === 1">
  66. <view class="daily-time-item">
  67. <text class="daily-time-label">早提醒</text>
  68. <picker mode="time" :value="morningTime" :start="'00:00'" :end="'07:30'" @change="onMorningTimeChange">
  69. <view class="daily-time-value">{{ morningTime }}</view>
  70. </picker>
  71. </view>
  72. <view class="daily-time-item">
  73. <text class="daily-time-label">晚总结</text>
  74. <picker mode="time" :value="eveningTime" :start="'00:00'" :end="'21:00'" @change="onEveningTimeChange">
  75. <view class="daily-time-value">{{ eveningTime }}</view>
  76. </picker>
  77. </view>
  78. </view>
  79. <text class="daily-time-hint" v-if="dailyEnabled === 1">早提醒不晚于 07:30、晚总结不晚于 21:00(超出该时刻请等待次日)</text>
  80. </view>
  81. <!-- 完成表扬开关 -->
  82. <view class="cfg-card">
  83. <view class="cfg-card-header">
  84. <text class="cfg-card-title">任务完成鼓励</text>
  85. <text class="cfg-switch" :class="{ 'cfg-switch-on': completionPraiseEnabled === 1 }" @tap="togglePraiseEnabled">
  86. <text class="cfg-switch-text">{{ completionPraiseEnabled === 1 ? '已开启' : '已关闭' }}</text>
  87. </text>
  88. </view>
  89. <text class="cfg-card-desc">任务正常完成时,发送表扬鼓励消息</text>
  90. <view class="channel-list" v-if="completionPraiseEnabled === 1" style="margin-top:20rpx">
  91. <view class="channel-item" v-for="(ch, pIndex) in channels" :key="getPraiseKey(pIndex)"
  92. :class="{
  93. 'channel-selected': isPraiseSelected(ch.type),
  94. 'channel-disabled': !ch.available
  95. }"
  96. @tap="togglePraiseChannel(ch)">
  97. <view class="channel-check" v-if="isPraiseSelected(ch.type) && ch.available">✓</view>
  98. <view class="channel-info">
  99. <text class="channel-name">{{ ch.label }}</text>
  100. <text class="channel-reason" v-if="!ch.available">{{ ch.reason || '未开通' }}</text>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. <!-- 站内消息兜底说明 -->
  106. <view class="tip-card">
  107. <text class="tip-text">💌 站内消息提醒始终开启,作为兜底通道不随以上设置关闭</text>
  108. </view>
  109. <!-- 保存按钮 -->
  110. <view class="save-area">
  111. <view class="save-btn" @tap="saveConfig">
  112. <text>{{ saving ? '保存中...' : '保存配置' }}</text>
  113. </view>
  114. </view>
  115. </scroll-view>
  116. </view>
  117. </template>
  118. <script>
  119. import { getReminderConfig, saveReminderConfig } from '@/utils/api.js'
  120. import fontScaleMixin from '@/mixins/font-scale.js'
  121. export default {
  122. mixins: [fontScaleMixin],
  123. data() {
  124. return {
  125. loading: true,
  126. saving: false,
  127. enabled: 1,
  128. channels: [],
  129. selectedChannels: [],
  130. timingMode: 'after_timeout',
  131. offsetMinutes: 60,
  132. completionPraiseEnabled: 0,
  133. selectedPraiseChannels: ['wechat', 'in_app'],
  134. // 设计契约 task.reminder.daily:日提醒三字段(默认关闭,避免上线扰民)
  135. dailyEnabled: 0,
  136. morningTime: '07:30',
  137. eveningTime: '21:00',
  138. _loaded: false
  139. }
  140. },
  141. computed: {
  142. offsetLabel: function() {
  143. return this.timingMode === 'before_deadline' ? '提前' : '超时后'
  144. },
  145. offsetHint: function() {
  146. if (!this.offsetMinutes || this.offsetMinutes < 1 || this.offsetMinutes > 1440) {
  147. return '请输入1-1440 之间的分钟数'
  148. }
  149. if (this.timingMode === 'before_deadline') {
  150. return '将在任务截止前' + this.offsetMinutes + ' 分钟提醒'
  151. }
  152. return '将在任务超时后' + this.offsetMinutes + ' 分钟提醒'
  153. },
  154. channelTip: function() {
  155. var selected = this.selectedChannels || []
  156. if (selected.length === 0) {
  157. return '请至少选择一个提醒渠道'
  158. }
  159. return '已选择 ' + selected.length + ' 个提醒渠道'
  160. }
  161. },
  162. onLoad: function() {
  163. var self = this
  164. this.loading = true
  165. getReminderConfig().then(function(res) {
  166. self.loading = false
  167. self._loaded = true
  168. if (res && res.code === 200 && res.data) {
  169. var d = res.data
  170. self.enabled = d.enabled === 0 ? 0 : 1
  171. self.timingMode = d.timingMode || 'after_timeout'
  172. self.offsetMinutes = d.offsetMinutes || 60
  173. self.selectedChannels = Array.isArray(d.channels) ? d.channels.slice() : []
  174. self.channels = Array.isArray(d.availableChannels) ? d.availableChannels.filter(function(c) {
  175. return c && c.type !== 'in_app'
  176. }) : []
  177. self.completionPraiseEnabled = d.completionPraiseEnabled === 1 ? 1 : 0
  178. self.selectedPraiseChannels = Array.isArray(d.completionPraiseChannels) ? d.completionPraiseChannels.slice() : ['wechat', 'in_app']
  179. // 设计契约 §3.3:日提醒默认关闭;后端已回显 morningTime / eveningTime
  180. self.dailyEnabled = d.dailyEnabled === 1 ? 1 : 0
  181. self.morningTime = d.morningTime || '07:30'
  182. self.eveningTime = d.eveningTime || '21:00'
  183. }
  184. }).catch(function() {
  185. self.loading = false
  186. uni.showToast({ title: '加载失败,请重试', icon: 'none' })
  187. })
  188. },
  189. methods: {
  190. getChannelKey: function(ch, index) {
  191. return ch.type + '_' + index
  192. },
  193. getPraiseKey: function(pIndex) {
  194. return 'p-' + pIndex
  195. },
  196. toggleEnabled: function() {
  197. this.enabled = this.enabled === 1 ? 0 : 1
  198. },
  199. togglePraiseEnabled: function() {
  200. this.completionPraiseEnabled = this.completionPraiseEnabled === 1 ? 0 : 1
  201. },
  202. isSelected: function(type) {
  203. return (this.selectedChannels || []).indexOf(type) >= 0
  204. },
  205. isPraiseSelected: function(type) {
  206. return (this.selectedPraiseChannels || []).indexOf(type) >= 0
  207. },
  208. toggleChannel: function(ch) {
  209. if (!ch.available) return
  210. var idx = this.selectedChannels.indexOf(ch.type)
  211. if (idx >= 0) {
  212. this.selectedChannels.splice(idx, 1)
  213. } else {
  214. this.selectedChannels.push(ch.type)
  215. }
  216. },
  217. togglePraiseChannel: function(ch) {
  218. if (!ch.available) return
  219. var idx = this.selectedPraiseChannels.indexOf(ch.type)
  220. if (idx >= 0) {
  221. this.selectedPraiseChannels.splice(idx, 1)
  222. } else {
  223. this.selectedPraiseChannels.push(ch.type)
  224. }
  225. },
  226. switchTiming: function(mode) {
  227. this.timingMode = mode
  228. },
  229. onOffsetInput: function(e) {
  230. var v = e && e.detail && e.detail.value
  231. var n = parseInt(v, 10)
  232. this.offsetMinutes = isNaN(n) ? 0 : n
  233. },
  234. toggleDailyEnabled: function() {
  235. this.dailyEnabled = this.dailyEnabled === 1 ? 0 : 1
  236. },
  237. onMorningTimeChange: function(e) {
  238. if (e && e.detail && e.detail.value) {
  239. this.morningTime = e.detail.value
  240. }
  241. },
  242. onEveningTimeChange: function(e) {
  243. if (e && e.detail && e.detail.value) {
  244. this.eveningTime = e.detail.value
  245. }
  246. },
  247. saveConfig: function() {
  248. var self = this
  249. if (!this.selectedChannels || this.selectedChannels.length === 0) {
  250. uni.showToast({ title: '请至少选择一个提醒渠道', icon: 'none' })
  251. return
  252. }
  253. var offset = this.offsetMinutes || 0
  254. if (offset < 1 || offset > 1440) {
  255. uni.showToast({ title: '偏移分钟需在1-1440 之间', icon: 'none' })
  256. return
  257. }
  258. if (this.saving) return
  259. this.saving = true
  260. saveReminderConfig({
  261. channels: this.selectedChannels.slice(),
  262. timingMode: this.timingMode,
  263. offsetMinutes: offset,
  264. enabled: this.enabled === 1 ? 1 : 0,
  265. completionPraiseEnabled: this.completionPraiseEnabled === 1 ? 1 : 0,
  266. completionPraiseChannels: this.selectedPraiseChannels.slice(),
  267. // 设计契约 §3.3:前端回传日提醒三字段,后端校验 HH:mm + dailyEnabled ∈ {0,1}
  268. dailyEnabled: this.dailyEnabled === 1 ? 1 : 0,
  269. morningTime: this.morningTime,
  270. eveningTime: this.eveningTime
  271. }).then(function(res) {
  272. self.saving = false
  273. if (res && res.code === 200) {
  274. uni.showToast({ title: '保存成功', icon: 'success' })
  275. setTimeout(function() {
  276. uni.navigateBack()
  277. }, 1000)
  278. } else {
  279. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  280. }
  281. }).catch(function(err) {
  282. self.saving = false
  283. uni.showToast({ title: (err && err.message) || '保存失败', icon: 'none' })
  284. })
  285. }
  286. }
  287. }
  288. </script>
  289. <style scoped lang="scss">
  290. .reminder-config-page {
  291. box-sizing: border-box;
  292. min-height: 100vh;
  293. background: $uni-bg-color;
  294. overflow: hidden;
  295. }
  296. .content {
  297. padding: $uni-space-page;
  298. box-sizing: border-box;
  299. width: 100%;
  300. overflow: hidden;
  301. }
  302. .cfg-card {
  303. background-color: $app-surface;
  304. border-radius: 24rpx;
  305. padding: $uni-space-page;
  306. margin-bottom: $uni-space-lg;
  307. box-shadow: 0 4rpx 16rpx rgba(249, 115, 22, 0.08);
  308. }
  309. .cfg-card-header {
  310. display: flex;
  311. align-items: center;
  312. justify-content: space-between;
  313. }
  314. .cfg-card-title {
  315. font-size: calc(30rpx * var(--font-scale, 1));
  316. font-weight: 600;
  317. color: $uni-text-color;
  318. }
  319. .cfg-card-desc {
  320. display: block;
  321. margin-top: 12rpx;
  322. font-size: calc(24rpx * var(--font-scale, 1));
  323. color: $app-text-subtle;
  324. line-height: 1.6;
  325. }
  326. .cfg-switch {
  327. padding: 10rpx 28rpx;
  328. border-radius: 999rpx;
  329. font-size: calc(26rpx * var(--font-scale, 1));
  330. background: $uni-border-color-light;
  331. color: $uni-text-color-secondary;
  332. }
  333. .cfg-switch-on {
  334. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  335. color: $app-surface;
  336. font-weight: 600;
  337. }
  338. .channel-list {
  339. display: flex;
  340. flex-wrap: wrap;
  341. gap: 20rpx;
  342. margin-top: 24rpx;
  343. }
  344. .channel-item {
  345. box-sizing: border-box;
  346. position: relative;
  347. display: flex;
  348. align-items: center;
  349. padding: 16rpx 24rpx;
  350. border: 2rpx solid $uni-border-color-light;
  351. border-radius: 24rpx;
  352. background: $app-surface;
  353. min-width: 200rpx;
  354. }
  355. .channel-selected {
  356. border-color: $brand-primary;
  357. background: $brand-primary;
  358. }
  359. .channel-disabled {
  360. opacity: 0.55;
  361. }
  362. .channel-check {
  363. position: absolute;
  364. top: -8rpx;
  365. right: -8rpx;
  366. width: 32rpx;
  367. height: 32rpx;
  368. border-radius: 50%;
  369. background-color: $app-surface;
  370. color: $brand-primary;
  371. font-size: calc(20rpx * var(--font-scale, 1));
  372. font-weight: 700;
  373. display: flex;
  374. align-items: center;
  375. justify-content: center;
  376. z-index: 2;
  377. box-shadow: 0 2rpx 4rpx rgba(0,0,0,0.1);
  378. }
  379. .channel-info {
  380. display: flex;
  381. flex-direction: column;
  382. gap: 6rpx;
  383. }
  384. .channel-name {
  385. font-size: calc(26rpx * var(--font-scale, 1));
  386. color: $uni-text-color;
  387. font-weight: 500;
  388. }
  389. .channel-selected .channel-name {
  390. color: $app-surface;
  391. }
  392. .channel-reason {
  393. font-size: calc(20rpx * var(--font-scale, 1));
  394. color: $app-text-subtle;
  395. }
  396. .channel-tip {
  397. width: 100%;
  398. margin-top: 16rpx;
  399. }
  400. .channel-tip-text {
  401. font-size: calc(24rpx * var(--font-scale, 1));
  402. color: $uni-info;
  403. }
  404. .timing-list {
  405. display: flex;
  406. gap: 20rpx;
  407. margin-top: 24rpx;
  408. }
  409. .timing-item {
  410. flex: 1;
  411. box-sizing: border-box;
  412. padding: 24rpx;
  413. border: 2rpx solid $uni-border-color-light;
  414. border-radius: 24rpx;
  415. display: flex;
  416. flex-direction: column;
  417. gap: 8rpx;
  418. }
  419. .timing-active {
  420. border-color: $brand-primary;
  421. background: $uni-primary-pale;
  422. }
  423. .timing-name {
  424. font-size: calc(28rpx * var(--font-scale, 1));
  425. font-weight: 600;
  426. color: $uni-text-color;
  427. }
  428. .timing-active .timing-name {
  429. color: $brand-primary-dark;
  430. }
  431. .timing-desc {
  432. font-size: calc(22rpx * var(--font-scale, 1));
  433. color: $app-text-subtle;
  434. }
  435. .offset-row {
  436. display: flex;
  437. align-items: center;
  438. margin-top: $uni-space-lg;
  439. padding: 20rpx 24rpx;
  440. background: $facade-fill-slate-50;
  441. border-radius: 16rpx;
  442. }
  443. .offset-label {
  444. font-size: calc(26rpx * var(--font-scale, 1));
  445. color: $uni-text-color;
  446. margin-right: 20rpx;
  447. }
  448. .offset-input {
  449. flex: 1;
  450. font-size: calc(28rpx * var(--font-scale, 1));
  451. color: $uni-text-color;
  452. }
  453. .offset-unit {
  454. font-size: calc(24rpx * var(--font-scale, 1));
  455. color: $app-text-subtle;
  456. margin-left: 12rpx;
  457. }
  458. .offset-hint {
  459. display: block;
  460. margin-top: 12rpx;
  461. font-size: calc(22rpx * var(--font-scale, 1));
  462. color: $app-text-subtle;
  463. }
  464. .daily-time-row {
  465. display: flex;
  466. gap: 24rpx;
  467. margin-top: 20rpx;
  468. }
  469. .daily-time-item {
  470. flex: 1;
  471. box-sizing: border-box;
  472. padding: 20rpx 24rpx;
  473. background: $facade-fill-slate-50;
  474. border-radius: 16rpx;
  475. display: flex;
  476. align-items: center;
  477. justify-content: space-between;
  478. }
  479. .daily-time-label {
  480. font-size: calc(26rpx * var(--font-scale, 1));
  481. color: $uni-text-color-secondary;
  482. }
  483. .daily-time-value {
  484. font-size: calc(28rpx * var(--font-scale, 1));
  485. color: $brand-primary-dark;
  486. font-weight: 600;
  487. }
  488. .daily-time-hint {
  489. display: block;
  490. margin-top: 12rpx;
  491. font-size: calc(22rpx * var(--font-scale, 1));
  492. color: $app-text-subtle;
  493. line-height: 1.5;
  494. }
  495. .tip-card {
  496. background: $tint-sky-blue;
  497. border-radius: 16rpx;
  498. padding: 24rpx $uni-space-page;
  499. margin-bottom: $uni-space-lg;
  500. }
  501. .tip-text {
  502. font-size: calc(24rpx * var(--font-scale, 1));
  503. color: $uni-info;
  504. line-height: 1.6;
  505. }
  506. .save-area {
  507. padding: 40rpx $uni-space-page;
  508. }
  509. .save-btn {
  510. background: linear-gradient(135deg, $brand-primary, $brand-primary-dark);
  511. color: $app-surface;
  512. text-align: center;
  513. padding: 28rpx 0;
  514. border-radius: 999rpx;
  515. font-size: calc(30rpx * var(--font-scale, 1));
  516. font-weight: 600;
  517. box-shadow: 0 6rpx 20rpx rgba(249, 115, 22, 0.3);
  518. }
  519. .save-btn:active {
  520. opacity: 0.9;
  521. transform: scale(0.98);
  522. }
  523. </style>