index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. <!-- 完成表扬开关 -->
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  96. export default {
  97. mixins: [fontScaleMixin],
  98. data() {
  99. return {
  100. loading: true,
  101. saving: false,
  102. enabled: 1,
  103. channels: [],
  104. selectedChannels: [],
  105. timingMode: 'after_timeout',
  106. offsetMinutes: 60,
  107. completionPraiseEnabled: 0,
  108. selectedPraiseChannels: ['wechat', 'in_app'],
  109. _loaded: false
  110. }
  111. },
  112. computed: {
  113. offsetLabel: function() {
  114. return this.timingMode === 'before_deadline' ? '提前' : '超时后'
  115. },
  116. offsetHint: function() {
  117. if (!this.offsetMinutes || this.offsetMinutes < 1 || this.offsetMinutes > 1440) {
  118. return '请输入1-1440 之间的分钟数'
  119. }
  120. if (this.timingMode === 'before_deadline') {
  121. return '将在任务截止前' + this.offsetMinutes + ' 分钟提醒'
  122. }
  123. return '将在任务超时后' + this.offsetMinutes + ' 分钟提醒'
  124. },
  125. channelTip: function() {
  126. var selected = this.selectedChannels || []
  127. if (selected.length === 0) {
  128. return '请至少选择一个提醒渠道'
  129. }
  130. return '已选择 ' + selected.length + ' 个提醒渠道'
  131. }
  132. },
  133. onLoad: function() {
  134. var self = this
  135. this.loading = true
  136. getReminderConfig().then(function(res) {
  137. self.loading = false
  138. self._loaded = true
  139. if (res && res.code === 200 && res.data) {
  140. var d = res.data
  141. self.enabled = d.enabled === 0 ? 0 : 1
  142. self.timingMode = d.timingMode || 'after_timeout'
  143. self.offsetMinutes = d.offsetMinutes || 60
  144. self.selectedChannels = Array.isArray(d.channels) ? d.channels.slice() : []
  145. self.channels = Array.isArray(d.availableChannels) ? d.availableChannels.filter(function(c) {
  146. return c && c.type !== 'in_app'
  147. }) : []
  148. self.completionPraiseEnabled = d.completionPraiseEnabled === 1 ? 1 : 0
  149. self.selectedPraiseChannels = Array.isArray(d.completionPraiseChannels) ? d.completionPraiseChannels.slice() : ['wechat', 'in_app']
  150. }
  151. }).catch(function() {
  152. self.loading = false
  153. uni.showToast({ title: '加载失败,请重试', icon: 'none' })
  154. })
  155. },
  156. methods: {
  157. getChannelKey: function(ch, index) {
  158. return ch.type + '_' + index
  159. },
  160. getPraiseKey: function(pIndex) {
  161. return 'p-' + pIndex
  162. },
  163. toggleEnabled: function() {
  164. this.enabled = this.enabled === 1 ? 0 : 1
  165. },
  166. togglePraiseEnabled: function() {
  167. this.completionPraiseEnabled = this.completionPraiseEnabled === 1 ? 0 : 1
  168. },
  169. isSelected: function(type) {
  170. return (this.selectedChannels || []).indexOf(type) >= 0
  171. },
  172. isPraiseSelected: function(type) {
  173. return (this.selectedPraiseChannels || []).indexOf(type) >= 0
  174. },
  175. toggleChannel: function(ch) {
  176. if (!ch.available) return
  177. var idx = this.selectedChannels.indexOf(ch.type)
  178. if (idx >= 0) {
  179. this.selectedChannels.splice(idx, 1)
  180. } else {
  181. this.selectedChannels.push(ch.type)
  182. }
  183. },
  184. togglePraiseChannel: function(ch) {
  185. if (!ch.available) return
  186. var idx = this.selectedPraiseChannels.indexOf(ch.type)
  187. if (idx >= 0) {
  188. this.selectedPraiseChannels.splice(idx, 1)
  189. } else {
  190. this.selectedPraiseChannels.push(ch.type)
  191. }
  192. },
  193. switchTiming: function(mode) {
  194. this.timingMode = mode
  195. },
  196. onOffsetInput: function(e) {
  197. var v = e && e.detail && e.detail.value
  198. var n = parseInt(v, 10)
  199. this.offsetMinutes = isNaN(n) ? 0 : n
  200. },
  201. saveConfig: function() {
  202. var self = this
  203. if (!this.selectedChannels || this.selectedChannels.length === 0) {
  204. uni.showToast({ title: '请至少选择一个提醒渠道', icon: 'none' })
  205. return
  206. }
  207. var offset = this.offsetMinutes || 0
  208. if (offset < 1 || offset > 1440) {
  209. uni.showToast({ title: '偏移分钟需在1-1440 之间', icon: 'none' })
  210. return
  211. }
  212. if (this.saving) return
  213. this.saving = true
  214. saveReminderConfig({
  215. channels: this.selectedChannels.slice(),
  216. timingMode: this.timingMode,
  217. offsetMinutes: offset,
  218. enabled: this.enabled === 1 ? 1 : 0,
  219. completionPraiseEnabled: this.completionPraiseEnabled === 1 ? 1 : 0,
  220. completionPraiseChannels: this.selectedPraiseChannels.slice()
  221. }).then(function(res) {
  222. self.saving = false
  223. if (res && res.code === 200) {
  224. uni.showToast({ title: '保存成功', icon: 'success' })
  225. setTimeout(function() {
  226. uni.navigateBack()
  227. }, 1000)
  228. } else {
  229. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  230. }
  231. }).catch(function(err) {
  232. self.saving = false
  233. uni.showToast({ title: (err && err.message) || '保存失败', icon: 'none' })
  234. })
  235. }
  236. }
  237. }
  238. </script>
  239. <style scoped lang="scss">
  240. .reminder-config-page {
  241. box-sizing: border-box;
  242. min-height: 100vh;
  243. background: $uni-bg-color;
  244. overflow: hidden;
  245. }
  246. .content {
  247. padding: $uni-space-page;
  248. box-sizing: border-box;
  249. width: 100%;
  250. overflow: hidden;
  251. }
  252. .cfg-card {
  253. background-color: $app-surface;
  254. border-radius: 24rpx;
  255. padding: $uni-space-page;
  256. margin-bottom: $uni-space-lg;
  257. box-shadow: 0 4rpx 16rpx rgba(249, 115, 22, 0.08);
  258. }
  259. .cfg-card-header {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. }
  264. .cfg-card-title {
  265. font-size: calc(30rpx * var(--font-scale, 1));
  266. font-weight: 600;
  267. color: $uni-text-color;
  268. }
  269. .cfg-card-desc {
  270. display: block;
  271. margin-top: 12rpx;
  272. font-size: calc(24rpx * var(--font-scale, 1));
  273. color: $app-text-subtle;
  274. line-height: 1.6;
  275. }
  276. .cfg-switch {
  277. padding: 10rpx 28rpx;
  278. border-radius: 999rpx;
  279. font-size: calc(26rpx * var(--font-scale, 1));
  280. background: $uni-border-color-light;
  281. color: $uni-text-color-secondary;
  282. }
  283. .cfg-switch-on {
  284. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  285. color: $app-surface;
  286. font-weight: 600;
  287. }
  288. .channel-list {
  289. display: flex;
  290. flex-wrap: wrap;
  291. gap: 20rpx;
  292. margin-top: 24rpx;
  293. }
  294. .channel-item {
  295. box-sizing: border-box;
  296. position: relative;
  297. display: flex;
  298. align-items: center;
  299. padding: 16rpx 24rpx;
  300. border: 2rpx solid $uni-border-color-light;
  301. border-radius: 24rpx;
  302. background: $app-surface;
  303. min-width: 200rpx;
  304. }
  305. .channel-selected {
  306. border-color: $brand-primary;
  307. background: $brand-primary;
  308. }
  309. .channel-disabled {
  310. opacity: 0.55;
  311. }
  312. .channel-check {
  313. position: absolute;
  314. top: -8rpx;
  315. right: -8rpx;
  316. width: 32rpx;
  317. height: 32rpx;
  318. border-radius: 50%;
  319. background-color: $app-surface;
  320. color: $brand-primary;
  321. font-size: calc(20rpx * var(--font-scale, 1));
  322. font-weight: 700;
  323. display: flex;
  324. align-items: center;
  325. justify-content: center;
  326. z-index: 2;
  327. box-shadow: 0 2rpx 4rpx rgba(0,0,0,0.1);
  328. }
  329. .channel-info {
  330. display: flex;
  331. flex-direction: column;
  332. gap: 6rpx;
  333. }
  334. .channel-name {
  335. font-size: calc(26rpx * var(--font-scale, 1));
  336. color: $uni-text-color;
  337. font-weight: 500;
  338. }
  339. .channel-selected .channel-name {
  340. color: $app-surface;
  341. }
  342. .channel-reason {
  343. font-size: calc(20rpx * var(--font-scale, 1));
  344. color: $app-text-subtle;
  345. }
  346. .channel-tip {
  347. width: 100%;
  348. margin-top: 16rpx;
  349. }
  350. .channel-tip-text {
  351. font-size: calc(24rpx * var(--font-scale, 1));
  352. color: $uni-info;
  353. }
  354. .timing-list {
  355. display: flex;
  356. gap: 20rpx;
  357. margin-top: 24rpx;
  358. }
  359. .timing-item {
  360. flex: 1;
  361. box-sizing: border-box;
  362. padding: 24rpx;
  363. border: 2rpx solid $uni-border-color-light;
  364. border-radius: 24rpx;
  365. display: flex;
  366. flex-direction: column;
  367. gap: 8rpx;
  368. }
  369. .timing-active {
  370. border-color: $brand-primary;
  371. background: $uni-primary-pale;
  372. }
  373. .timing-name {
  374. font-size: calc(28rpx * var(--font-scale, 1));
  375. font-weight: 600;
  376. color: $uni-text-color;
  377. }
  378. .timing-active .timing-name {
  379. color: $brand-primary-dark;
  380. }
  381. .timing-desc {
  382. font-size: calc(22rpx * var(--font-scale, 1));
  383. color: $app-text-subtle;
  384. }
  385. .offset-row {
  386. display: flex;
  387. align-items: center;
  388. margin-top: $uni-space-lg;
  389. padding: 20rpx 24rpx;
  390. background: $facade-fill-slate-50;
  391. border-radius: 16rpx;
  392. }
  393. .offset-label {
  394. font-size: calc(26rpx * var(--font-scale, 1));
  395. color: $uni-text-color;
  396. margin-right: 20rpx;
  397. }
  398. .offset-input {
  399. flex: 1;
  400. font-size: calc(28rpx * var(--font-scale, 1));
  401. color: $uni-text-color;
  402. }
  403. .offset-unit {
  404. font-size: calc(24rpx * var(--font-scale, 1));
  405. color: $app-text-subtle;
  406. margin-left: 12rpx;
  407. }
  408. .offset-hint {
  409. display: block;
  410. margin-top: 12rpx;
  411. font-size: calc(22rpx * var(--font-scale, 1));
  412. color: $app-text-subtle;
  413. }
  414. .tip-card {
  415. background: $tint-sky-blue;
  416. border-radius: 16rpx;
  417. padding: 24rpx $uni-space-page;
  418. margin-bottom: $uni-space-lg;
  419. }
  420. .tip-text {
  421. font-size: calc(24rpx * var(--font-scale, 1));
  422. color: $uni-info;
  423. line-height: 1.6;
  424. }
  425. .save-area {
  426. padding: 40rpx $uni-space-page;
  427. }
  428. .save-btn {
  429. background: linear-gradient(135deg, $brand-primary, $brand-primary-dark);
  430. color: $app-surface;
  431. text-align: center;
  432. padding: 28rpx 0;
  433. border-radius: 999rpx;
  434. font-size: calc(30rpx * var(--font-scale, 1));
  435. font-weight: 600;
  436. box-shadow: 0 6rpx 20rpx rgba(249, 115, 22, 0.3);
  437. }
  438. .save-btn:active {
  439. opacity: 0.9;
  440. transform: scale(0.98);
  441. }
  442. </style>