index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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, 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. <!-- 完成表扬开关 -->
  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, pIndex) in channels" :key="getPraiseKey(pIndex)"
  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. getChannelKey: function(ch, index) {
  156. return ch.type + '_' + index
  157. },
  158. getPraiseKey: function(pIndex) {
  159. return 'p-' + pIndex
  160. },
  161. toggleEnabled: function() {
  162. this.enabled = this.enabled === 1 ? 0 : 1
  163. },
  164. togglePraiseEnabled: function() {
  165. this.completionPraiseEnabled = this.completionPraiseEnabled === 1 ? 0 : 1
  166. },
  167. isSelected: function(type) {
  168. return (this.selectedChannels || []).indexOf(type) >= 0
  169. },
  170. isPraiseSelected: function(type) {
  171. return (this.selectedPraiseChannels || []).indexOf(type) >= 0
  172. },
  173. toggleChannel: function(ch) {
  174. if (!ch.available) return
  175. var idx = this.selectedChannels.indexOf(ch.type)
  176. if (idx >= 0) {
  177. this.selectedChannels.splice(idx, 1)
  178. } else {
  179. this.selectedChannels.push(ch.type)
  180. }
  181. },
  182. togglePraiseChannel: function(ch) {
  183. if (!ch.available) return
  184. var idx = this.selectedPraiseChannels.indexOf(ch.type)
  185. if (idx >= 0) {
  186. this.selectedPraiseChannels.splice(idx, 1)
  187. } else {
  188. this.selectedPraiseChannels.push(ch.type)
  189. }
  190. },
  191. switchTiming: function(mode) {
  192. this.timingMode = mode
  193. },
  194. onOffsetInput: function(e) {
  195. var v = e && e.detail && e.detail.value
  196. var n = parseInt(v, 10)
  197. this.offsetMinutes = isNaN(n) ? 0 : n
  198. },
  199. saveConfig: function() {
  200. var self = this
  201. if (!this.selectedChannels || this.selectedChannels.length === 0) {
  202. uni.showToast({ title: '请至少选择一个提醒渠道', icon: 'none' })
  203. return
  204. }
  205. var offset = this.offsetMinutes || 0
  206. if (offset < 1 || offset > 1440) {
  207. uni.showToast({ title: '偏移分钟需在1-1440 之间', icon: 'none' })
  208. return
  209. }
  210. if (this.saving) return
  211. this.saving = true
  212. saveReminderConfig({
  213. channels: this.selectedChannels.slice(),
  214. timingMode: this.timingMode,
  215. offsetMinutes: offset,
  216. enabled: this.enabled === 1 ? 1 : 0,
  217. completionPraiseEnabled: this.completionPraiseEnabled === 1 ? 1 : 0,
  218. completionPraiseChannels: this.selectedPraiseChannels.slice()
  219. }).then(function(res) {
  220. self.saving = false
  221. if (res && res.code === 200) {
  222. uni.showToast({ title: '保存成功', icon: 'success' })
  223. setTimeout(function() {
  224. uni.navigateBack()
  225. }, 1000)
  226. } else {
  227. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  228. }
  229. }).catch(function(err) {
  230. self.saving = false
  231. uni.showToast({ title: (err && err.message) || '保存失败', icon: 'none' })
  232. })
  233. }
  234. }
  235. }
  236. </script>
  237. <style scoped lang="scss">
  238. .reminder-config-page {
  239. box-sizing: border-box;
  240. min-height: 100vh;
  241. background: #F5F9FC;
  242. overflow: hidden;
  243. }
  244. .content {
  245. padding: 30rpx;
  246. box-sizing: border-box;
  247. width: 100%;
  248. overflow: hidden;
  249. }
  250. .cfg-card {
  251. background-color: #FFFFFF;
  252. border-radius: 24rpx;
  253. padding: 30rpx;
  254. margin-bottom: 30rpx;
  255. box-shadow: 0 4rpx 16rpx rgba(249, 115, 22, 0.08);
  256. }
  257. .cfg-card-header {
  258. display: flex;
  259. align-items: center;
  260. justify-content: space-between;
  261. }
  262. .cfg-card-title {
  263. font-size: 30rpx;
  264. font-weight: 600;
  265. color: #1E293B;
  266. }
  267. .cfg-card-desc {
  268. display: block;
  269. margin-top: 12rpx;
  270. font-size: 24rpx;
  271. color: #94A3B8;
  272. line-height: 1.6;
  273. }
  274. .cfg-switch {
  275. padding: 10rpx 28rpx;
  276. border-radius: 999rpx;
  277. font-size: 26rpx;
  278. background: #E2E8F0;
  279. color: #64748B;
  280. }
  281. .cfg-switch-on {
  282. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  283. color: #FFFFFF;
  284. font-weight: 600;
  285. }
  286. .channel-list {
  287. display: flex;
  288. flex-wrap: wrap;
  289. gap: 20rpx;
  290. margin-top: 24rpx;
  291. }
  292. .channel-item {
  293. box-sizing: border-box;
  294. position: relative;
  295. display: flex;
  296. align-items: center;
  297. padding: 16rpx 24rpx;
  298. border: 2rpx solid #E2E8F0;
  299. border-radius: 20rpx;
  300. background: #FFFFFF;
  301. min-width: 200rpx;
  302. }
  303. .channel-selected {
  304. border-color: $brand-primary;
  305. background: $brand-primary;
  306. }
  307. .channel-disabled {
  308. opacity: 0.55;
  309. }
  310. .channel-check {
  311. position: absolute;
  312. top: -8rpx;
  313. right: -8rpx;
  314. width: 32rpx;
  315. height: 32rpx;
  316. border-radius: 50%;
  317. background-color: #FFFFFF;
  318. color: $brand-primary;
  319. font-size: 20rpx;
  320. font-weight: 900;
  321. display: flex;
  322. align-items: center;
  323. justify-content: center;
  324. z-index: 2;
  325. box-shadow: 0 2rpx 4rpx rgba(0,0,0,0.1);
  326. }
  327. .channel-info {
  328. display: flex;
  329. flex-direction: column;
  330. gap: 6rpx;
  331. }
  332. .channel-name {
  333. font-size: 26rpx;
  334. color: #1E293B;
  335. font-weight: 500;
  336. }
  337. .channel-selected .channel-name {
  338. color: #FFFFFF;
  339. }
  340. .channel-reason {
  341. font-size: 20rpx;
  342. color: #94A3B8;
  343. }
  344. .channel-tip {
  345. width: 100%;
  346. margin-top: 16rpx;
  347. }
  348. .channel-tip-text {
  349. font-size: 24rpx;
  350. color: $uni-info;
  351. }
  352. .timing-list {
  353. display: flex;
  354. gap: 20rpx;
  355. margin-top: 24rpx;
  356. }
  357. .timing-item {
  358. flex: 1;
  359. box-sizing: border-box;
  360. padding: 24rpx;
  361. border: 2rpx solid #E2E8F0;
  362. border-radius: 20rpx;
  363. display: flex;
  364. flex-direction: column;
  365. gap: 8rpx;
  366. }
  367. .timing-active {
  368. border-color: $brand-primary;
  369. background: $uni-primary-pale;
  370. }
  371. .timing-name {
  372. font-size: 28rpx;
  373. font-weight: 600;
  374. color: #1E293B;
  375. }
  376. .timing-active .timing-name {
  377. color: $brand-primary-dark;
  378. }
  379. .timing-desc {
  380. font-size: 22rpx;
  381. color: #94A3B8;
  382. }
  383. .offset-row {
  384. display: flex;
  385. align-items: center;
  386. margin-top: 30rpx;
  387. padding: 20rpx 24rpx;
  388. background: #F8FAFC;
  389. border-radius: 16rpx;
  390. }
  391. .offset-label {
  392. font-size: 26rpx;
  393. color: #1E293B;
  394. margin-right: 20rpx;
  395. }
  396. .offset-input {
  397. flex: 1;
  398. font-size: 28rpx;
  399. color: #1E293B;
  400. }
  401. .offset-unit {
  402. font-size: 24rpx;
  403. color: #94A3B8;
  404. margin-left: 12rpx;
  405. }
  406. .offset-hint {
  407. display: block;
  408. margin-top: 12rpx;
  409. font-size: 22rpx;
  410. color: #94A3B8;
  411. }
  412. .tip-card {
  413. background: #D6EAF8;
  414. border-radius: 16rpx;
  415. padding: 24rpx 30rpx;
  416. margin-bottom: 30rpx;
  417. }
  418. .tip-text {
  419. font-size: 24rpx;
  420. color: $uni-info;
  421. line-height: 1.6;
  422. }
  423. .save-area {
  424. padding: 40rpx 30rpx;
  425. }
  426. .save-btn {
  427. background: linear-gradient(135deg, $brand-primary, $brand-primary-dark);
  428. color: #FFFFFF;
  429. text-align: center;
  430. padding: 28rpx 0;
  431. border-radius: 999rpx;
  432. font-size: 30rpx;
  433. font-weight: 600;
  434. box-shadow: 0 6rpx 20rpx rgba(249, 115, 22, 0.3);
  435. }
  436. .save-btn:active {
  437. opacity: 0.9;
  438. transform: scale(0.98);
  439. }
  440. </style>