index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="reminder-config-page">
  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 in channels" :key="ch.type"
  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. <!-- 完成表扬开关 -->
  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': completionPraiseEnabled === 1 }" @tap="togglePraiseEnabled">
  61. <text class="cfg-switch-text">{{ completionPraiseEnabled === 1 ? '已开启' : '已关闭' }}</text>
  62. </text>
  63. </view>
  64. <text class="cfg-card-desc">任务正常完成时,发送表扬鼓励消息</text>
  65. <view class="channel-list" v-if="completionPraiseEnabled === 1" style="margin-top:20rpx">
  66. <view class="channel-item" v-for="ch in channels" :key="'p-'+ch.type"
  67. :class="{
  68. 'channel-selected': isPraiseSelected(ch.type),
  69. 'channel-disabled': !ch.available
  70. }"
  71. @tap="togglePraiseChannel(ch)">
  72. <view class="channel-check" v-if="isPraiseSelected(ch.type) && ch.available">✓</view>
  73. <view class="channel-info">
  74. <text class="channel-name">{{ ch.label }}</text>
  75. <text class="channel-reason" v-if="!ch.available">{{ ch.reason || '未开通' }}</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- 站内消息兜底说明 -->
  81. <view class="tip-card">
  82. <text class="tip-text">💡 站内消息提醒始终开启,作为兜底通道不随以上设置关闭</text>
  83. </view>
  84. <!-- 保存按钮 -->
  85. <view class="save-area">
  86. <view class="save-btn" @tap="saveConfig">
  87. <text>{{ saving ? '保存中...' : '保存配置' }}</text>
  88. </view>
  89. </view>
  90. </scroll-view>
  91. </view>
  92. </template>
  93. <script>
  94. import { getReminderConfig, saveReminderConfig } from '@/utils/api.js'
  95. export default {
  96. data() {
  97. return {
  98. loading: true,
  99. saving: false,
  100. enabled: 1,
  101. channels: [],
  102. selectedChannels: [],
  103. timingMode: 'after_timeout',
  104. offsetMinutes: 60,
  105. completionPraiseEnabled: 0,
  106. selectedPraiseChannels: ['wechat', 'in_app'],
  107. _loaded: false
  108. }
  109. },
  110. computed: {
  111. offsetLabel: function() {
  112. return this.timingMode === 'before_deadline' ? '提前' : '超时后'
  113. },
  114. offsetHint: function() {
  115. if (!this.offsetMinutes || this.offsetMinutes < 1 || this.offsetMinutes > 1440) {
  116. return '请输入 1-1440 之间的分钟数'
  117. }
  118. if (this.timingMode === 'before_deadline') {
  119. return '将在任务截止前 ' + this.offsetMinutes + ' 分钟提醒'
  120. }
  121. return '将在任务超时后 ' + this.offsetMinutes + ' 分钟提醒'
  122. },
  123. channelTip: function() {
  124. var selected = this.selectedChannels || []
  125. if (selected.length === 0) {
  126. return '请至少选择一个提醒渠道'
  127. }
  128. return '已选择 ' + selected.length + ' 个提醒渠道'
  129. }
  130. },
  131. onLoad: function() {
  132. var self = this
  133. this.loading = true
  134. getReminderConfig().then(function(res) {
  135. self.loading = false
  136. self._loaded = true
  137. if (res && res.code === 200 && res.data) {
  138. var d = res.data
  139. self.enabled = d.enabled === 0 ? 0 : 1
  140. self.timingMode = d.timingMode || 'after_timeout'
  141. self.offsetMinutes = d.offsetMinutes || 60
  142. self.selectedChannels = Array.isArray(d.channels) ? d.channels.slice() : []
  143. self.channels = Array.isArray(d.availableChannels) ? d.availableChannels.filter(function(c) {
  144. return c && c.type !== 'in_app'
  145. }) : []
  146. self.completionPraiseEnabled = d.completionPraiseEnabled === 1 ? 1 : 0
  147. self.selectedPraiseChannels = Array.isArray(d.completionPraiseChannels) ? d.completionPraiseChannels.slice() : ['wechat', 'in_app']
  148. }
  149. }).catch(function() {
  150. self.loading = false
  151. uni.showToast({ title: '加载失败,请重试', icon: 'none' })
  152. })
  153. },
  154. methods: {
  155. toggleEnabled: function() {
  156. this.enabled = this.enabled === 1 ? 0 : 1
  157. },
  158. togglePraiseEnabled: function() {
  159. this.completionPraiseEnabled = this.completionPraiseEnabled === 1 ? 0 : 1
  160. },
  161. isSelected: function(type) {
  162. return (this.selectedChannels || []).indexOf(type) >= 0
  163. },
  164. isPraiseSelected: function(type) {
  165. return (this.selectedPraiseChannels || []).indexOf(type) >= 0
  166. },
  167. toggleChannel: function(ch) {
  168. if (!ch.available) return
  169. var idx = this.selectedChannels.indexOf(ch.type)
  170. if (idx >= 0) {
  171. this.selectedChannels.splice(idx, 1)
  172. } else {
  173. this.selectedChannels.push(ch.type)
  174. }
  175. },
  176. togglePraiseChannel: function(ch) {
  177. if (!ch.available) return
  178. var idx = this.selectedPraiseChannels.indexOf(ch.type)
  179. if (idx >= 0) {
  180. this.selectedPraiseChannels.splice(idx, 1)
  181. } else {
  182. this.selectedPraiseChannels.push(ch.type)
  183. }
  184. },
  185. switchTiming: function(mode) {
  186. this.timingMode = mode
  187. },
  188. onOffsetInput: function(e) {
  189. var v = e && e.detail && e.detail.value
  190. var n = parseInt(v, 10)
  191. this.offsetMinutes = isNaN(n) ? 0 : n
  192. },
  193. saveConfig: function() {
  194. var self = this
  195. if (!this.selectedChannels || this.selectedChannels.length === 0) {
  196. uni.showToast({ title: '请至少选择一个提醒渠道', icon: 'none' })
  197. return
  198. }
  199. var offset = this.offsetMinutes || 0
  200. if (offset < 1 || offset > 1440) {
  201. uni.showToast({ title: '偏移分钟需在 1-1440 之间', icon: 'none' })
  202. return
  203. }
  204. if (this.saving) return
  205. this.saving = true
  206. saveReminderConfig({
  207. channels: this.selectedChannels.slice(),
  208. timingMode: this.timingMode,
  209. offsetMinutes: offset,
  210. enabled: this.enabled === 1 ? 1 : 0,
  211. completionPraiseEnabled: this.completionPraiseEnabled === 1 ? 1 : 0,
  212. completionPraiseChannels: this.selectedPraiseChannels.slice()
  213. }).then(function(res) {
  214. self.saving = false
  215. if (res && res.code === 200) {
  216. uni.showToast({ title: '保存成功', icon: 'success' })
  217. setTimeout(function() {
  218. uni.navigateBack()
  219. }, 1000)
  220. } else {
  221. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  222. }
  223. }).catch(function(err) {
  224. self.saving = false
  225. uni.showToast({ title: (err && err.message) || '保存失败', icon: 'none' })
  226. })
  227. }
  228. }
  229. }
  230. </script>