index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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="tip-card">
  58. <text class="tip-text">💡 站内消息提醒始终开启,作为兜底通道不随以上设置关闭</text>
  59. </view>
  60. <!-- 保存按钮 -->
  61. <view class="save-area">
  62. <view class="save-btn" @tap="saveConfig">
  63. <text>{{ saving ? '保存中...' : '保存配置' }}</text>
  64. </view>
  65. </view>
  66. </scroll-view>
  67. </view>
  68. </template>
  69. <script>
  70. import { getReminderConfig, saveReminderConfig } from '@/utils/api.js'
  71. export default {
  72. data() {
  73. return {
  74. loading: true,
  75. saving: false,
  76. enabled: 1,
  77. channels: [],
  78. selectedChannels: [],
  79. timingMode: 'after_timeout',
  80. offsetMinutes: 60,
  81. _loaded: false
  82. }
  83. },
  84. computed: {
  85. offsetLabel: function() {
  86. return this.timingMode === 'before_deadline' ? '提前' : '超时后'
  87. },
  88. offsetHint: function() {
  89. if (!this.offsetMinutes || this.offsetMinutes < 1 || this.offsetMinutes > 1440) {
  90. return '请输入 1-1440 之间的分钟数'
  91. }
  92. if (this.timingMode === 'before_deadline') {
  93. return '将在任务截止前 ' + this.offsetMinutes + ' 分钟提醒'
  94. }
  95. return '将在任务超时后 ' + this.offsetMinutes + ' 分钟提醒'
  96. },
  97. channelTip: function() {
  98. var selected = this.selectedChannels || []
  99. if (selected.length === 0) {
  100. return '请至少选择一个提醒渠道'
  101. }
  102. return '已选择 ' + selected.length + ' 个提醒渠道'
  103. }
  104. },
  105. onLoad: function() {
  106. var self = this
  107. this.loading = true
  108. getReminderConfig().then(function(res) {
  109. self.loading = false
  110. self._loaded = true
  111. if (res && res.code === 200 && res.data) {
  112. var d = res.data
  113. self.enabled = d.enabled === 0 ? 0 : 1
  114. self.timingMode = d.timingMode || 'after_timeout'
  115. self.offsetMinutes = d.offsetMinutes || 60
  116. self.selectedChannels = Array.isArray(d.channels) ? d.channels.slice() : []
  117. self.channels = Array.isArray(d.availableChannels) ? d.availableChannels.filter(function(c) {
  118. return c && c.type !== 'in_app'
  119. }) : []
  120. }
  121. }).catch(function() {
  122. self.loading = false
  123. uni.showToast({ title: '加载失败,请重试', icon: 'none' })
  124. })
  125. },
  126. methods: {
  127. toggleEnabled: function() {
  128. this.enabled = this.enabled === 1 ? 0 : 1
  129. },
  130. isSelected: function(type) {
  131. return (this.selectedChannels || []).indexOf(type) >= 0
  132. },
  133. toggleChannel: function(ch) {
  134. if (!ch.available) return
  135. var idx = this.selectedChannels.indexOf(ch.type)
  136. if (idx >= 0) {
  137. this.selectedChannels.splice(idx, 1)
  138. } else {
  139. this.selectedChannels.push(ch.type)
  140. }
  141. },
  142. switchTiming: function(mode) {
  143. this.timingMode = mode
  144. },
  145. onOffsetInput: function(e) {
  146. var v = e && e.detail && e.detail.value
  147. var n = parseInt(v, 10)
  148. this.offsetMinutes = isNaN(n) ? 0 : n
  149. },
  150. saveConfig: function() {
  151. var self = this
  152. if (!this.selectedChannels || this.selectedChannels.length === 0) {
  153. uni.showToast({ title: '请至少选择一个提醒渠道', icon: 'none' })
  154. return
  155. }
  156. var offset = this.offsetMinutes || 0
  157. if (offset < 1 || offset > 1440) {
  158. uni.showToast({ title: '偏移分钟需在 1-1440 之间', icon: 'none' })
  159. return
  160. }
  161. if (this.saving) return
  162. this.saving = true
  163. saveReminderConfig({
  164. channels: this.selectedChannels.slice(),
  165. timingMode: this.timingMode,
  166. offsetMinutes: offset,
  167. enabled: this.enabled === 1 ? 1 : 0
  168. }).then(function(res) {
  169. self.saving = false
  170. if (res && res.code === 200) {
  171. uni.showToast({ title: '保存成功', icon: 'success' })
  172. setTimeout(function() {
  173. uni.navigateBack()
  174. }, 1000)
  175. } else {
  176. uni.showToast({ title: (res && res.message) || '保存失败', icon: 'none' })
  177. }
  178. }).catch(function(err) {
  179. self.saving = false
  180. uni.showToast({ title: (err && err.message) || '保存失败', icon: 'none' })
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style scoped>
  187. .reminder-config-page {
  188. box-sizing: border-box;
  189. min-height: 100vh;
  190. background: #F5F9FC;
  191. overflow: hidden;
  192. }
  193. .content {
  194. padding: 30rpx;
  195. box-sizing: border-box;
  196. width: 100%;
  197. overflow: hidden;
  198. }
  199. .cfg-card {
  200. background-color: #FFFFFF;
  201. border-radius: 24rpx;
  202. padding: 30rpx;
  203. margin-bottom: 30rpx;
  204. box-shadow: 0 4rpx 16rpx rgba(91, 155, 213, 0.08);
  205. }
  206. .cfg-card-header {
  207. display: flex;
  208. align-items: center;
  209. justify-content: space-between;
  210. }
  211. .cfg-card-title {
  212. font-size: 30rpx;
  213. font-weight: 600;
  214. color: #1E293B;
  215. }
  216. .cfg-card-desc {
  217. display: block;
  218. margin-top: 12rpx;
  219. font-size: 24rpx;
  220. color: #94A3B8;
  221. line-height: 1.6;
  222. }
  223. .cfg-switch {
  224. padding: 10rpx 28rpx;
  225. border-radius: 999rpx;
  226. font-size: 26rpx;
  227. background: #E2E8F0;
  228. color: #64748B;
  229. }
  230. .cfg-switch-on {
  231. background: linear-gradient(135deg, #5B9BD5, #8FC5E8);
  232. color: #FFFFFF;
  233. font-weight: 600;
  234. }
  235. .channel-list {
  236. display: flex;
  237. flex-wrap: wrap;
  238. gap: 20rpx;
  239. margin-top: 24rpx;
  240. }
  241. .channel-item {
  242. box-sizing: border-box;
  243. position: relative;
  244. display: flex;
  245. align-items: center;
  246. padding: 16rpx 24rpx;
  247. border: 2rpx solid #E2E8F0;
  248. border-radius: 20rpx;
  249. background: #FFFFFF;
  250. min-width: 200rpx;
  251. }
  252. .channel-selected {
  253. border-color: #5B9BD5;
  254. background: #5B9BD5;
  255. }
  256. .channel-disabled {
  257. opacity: 0.55;
  258. }
  259. .channel-check {
  260. position: absolute;
  261. top: -8rpx;
  262. right: -8rpx;
  263. width: 32rpx;
  264. height: 32rpx;
  265. border-radius: 50%;
  266. background-color: #FFFFFF;
  267. color: #5B9BD5;
  268. font-size: 20rpx;
  269. font-weight: 900;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. z-index: 2;
  274. box-shadow: 0 2rpx 4rpx rgba(0,0,0,0.1);
  275. }
  276. .channel-info {
  277. display: flex;
  278. flex-direction: column;
  279. gap: 6rpx;
  280. }
  281. .channel-name {
  282. font-size: 26rpx;
  283. color: #1E293B;
  284. font-weight: 500;
  285. }
  286. .channel-selected .channel-name {
  287. color: #FFFFFF;
  288. }
  289. .channel-reason {
  290. font-size: 20rpx;
  291. color: #94A3B8;
  292. }
  293. .channel-tip {
  294. width: 100%;
  295. margin-top: 16rpx;
  296. }
  297. .channel-tip-text {
  298. font-size: 24rpx;
  299. color: #5B9BD5;
  300. }
  301. .timing-list {
  302. display: flex;
  303. gap: 20rpx;
  304. margin-top: 24rpx;
  305. }
  306. .timing-item {
  307. flex: 1;
  308. box-sizing: border-box;
  309. padding: 24rpx;
  310. border: 2rpx solid #E2E8F0;
  311. border-radius: 20rpx;
  312. display: flex;
  313. flex-direction: column;
  314. gap: 8rpx;
  315. }
  316. .timing-active {
  317. border-color: #5B9BD5;
  318. background: #F0F7FF;
  319. }
  320. .timing-name {
  321. font-size: 28rpx;
  322. font-weight: 600;
  323. color: #1E293B;
  324. }
  325. .timing-active .timing-name {
  326. color: #3A7CC4;
  327. }
  328. .timing-desc {
  329. font-size: 22rpx;
  330. color: #94A3B8;
  331. }
  332. .offset-row {
  333. display: flex;
  334. align-items: center;
  335. margin-top: 30rpx;
  336. padding: 20rpx 24rpx;
  337. background: #F8FAFC;
  338. border-radius: 16rpx;
  339. }
  340. .offset-label {
  341. font-size: 26rpx;
  342. color: #1E293B;
  343. margin-right: 20rpx;
  344. }
  345. .offset-input {
  346. flex: 1;
  347. font-size: 28rpx;
  348. color: #1E293B;
  349. }
  350. .offset-unit {
  351. font-size: 24rpx;
  352. color: #94A3B8;
  353. margin-left: 12rpx;
  354. }
  355. .offset-hint {
  356. display: block;
  357. margin-top: 12rpx;
  358. font-size: 22rpx;
  359. color: #94A3B8;
  360. }
  361. .tip-card {
  362. background: #D6EAF8;
  363. border-radius: 16rpx;
  364. padding: 24rpx 30rpx;
  365. margin-bottom: 30rpx;
  366. }
  367. .tip-text {
  368. font-size: 24rpx;
  369. color: #3A7CC4;
  370. line-height: 1.6;
  371. }
  372. .save-area {
  373. padding: 40rpx 30rpx;
  374. }
  375. .save-btn {
  376. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  377. color: #FFFFFF;
  378. text-align: center;
  379. padding: 28rpx 0;
  380. border-radius: 999rpx;
  381. font-size: 30rpx;
  382. font-weight: 600;
  383. box-shadow: 0 6rpx 20rpx rgba(91, 155, 213, 0.3);
  384. }
  385. .save-btn:active {
  386. opacity: 0.9;
  387. transform: scale(0.98);
  388. }
  389. </style>