timingSetting.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view class="timing-setting-page">
  3. <custom-card>
  4. <block slot="backText">定时设置</block>
  5. <block slot="right">
  6. <view class="right-icons">
  7. <u-icon name="more-dot-fill" color="#333333" size="36rpx" style="margin-right: 16rpx;" />
  8. <u-icon name="camera" color="#333333" size="36rpx" />
  9. </view>
  10. </block>
  11. </custom-card>
  12. <view class="timing-content">
  13. <!-- 定时卡片列表 -->
  14. <view
  15. class="timer-card"
  16. v-for="(timer, index) in timerList"
  17. :key="index"
  18. >
  19. <!-- 定时标题和开关 -->
  20. <view class="timer-header">
  21. <text class="timer-title">定时{{ index + 1 }}</text>
  22. <switch
  23. :checked="timer.enabled"
  24. @change="onSwitchChange($event, index)"
  25. color="#00c853"
  26. class="timer-switch"
  27. />
  28. </view>
  29. <!-- 单选按钮组 -->
  30. <view class="radio-group">
  31. <view
  32. class="radio-item"
  33. :class="{ active: timer.frequency === 'once' }"
  34. @click="selectFrequency(index, 'once')"
  35. >
  36. <view class="radio-icon">
  37. <view v-if="timer.frequency === 'once'" class="radio-dot"></view>
  38. </view>
  39. <text class="radio-text">仅一次</text>
  40. </view>
  41. <view
  42. class="radio-item"
  43. :class="{ active: timer.frequency === 'daily' }"
  44. @click="selectFrequency(index, 'daily')"
  45. >
  46. <view class="radio-icon">
  47. <view v-if="timer.frequency === 'daily'" class="radio-dot"></view>
  48. </view>
  49. <text class="radio-text">每天一次</text>
  50. </view>
  51. </view>
  52. <!-- 时间选择器 -->
  53. <picker
  54. mode="time"
  55. :value="timer.time"
  56. @change="onTimeChange($event, index)"
  57. >
  58. <view class="time-picker">
  59. <text class="time-text" :class="{ placeholder: !timer.time }">
  60. {{ timer.time || '请选择时间' }}
  61. </text>
  62. <u-icon name="clock" color="#999999" size="32rpx" />
  63. </view>
  64. </picker>
  65. </view>
  66. <!-- 确定按钮 -->
  67. <view class="confirm-btn" @click="handleConfirm">
  68. <text class="confirm-text">确定</text>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. timerList: [
  78. { enabled: false, frequency: 'once', time: '' },
  79. { enabled: false, frequency: 'once', time: '' },
  80. { enabled: false, frequency: 'once', time: '' },
  81. { enabled: false, frequency: 'once', time: '' },
  82. { enabled: false, frequency: 'once', time: '' },
  83. ],
  84. };
  85. },
  86. methods: {
  87. // 开关状态改变
  88. onSwitchChange(e, index) {
  89. this.timerList[index].enabled = e.detail.value;
  90. },
  91. // 选择频率
  92. selectFrequency(index, frequency) {
  93. this.timerList[index].frequency = frequency;
  94. },
  95. // 时间改变
  96. onTimeChange(e, index) {
  97. this.timerList[index].time = e.detail.value;
  98. },
  99. // 确认按钮
  100. handleConfirm() {
  101. const enabledTimers = this.timerList.filter((timer, index) => {
  102. if (timer.enabled) {
  103. if (!timer.time) {
  104. uni.showToast({
  105. title: `定时${index + 1}请选择时间`,
  106. icon: 'none'
  107. });
  108. return false;
  109. }
  110. return true;
  111. }
  112. return false;
  113. });
  114. console.log('保存的定时设置:', enabledTimers);
  115. uni.showToast({
  116. title: '保存成功',
  117. icon: 'success'
  118. });
  119. // TODO: 调用接口保存定时设置
  120. },
  121. },
  122. };
  123. </script>
  124. <style scoped lang="scss">
  125. uni-page-body {
  126. position: relative;
  127. height: 100%;
  128. }
  129. .timing-setting-page {
  130. min-height: 100%;
  131. background: linear-gradient(180deg, #e6f7f0 0%, #ffffff 100%);
  132. overflow-x: hidden;
  133. overflow-y: auto;
  134. .right-icons {
  135. display: flex;
  136. align-items: center;
  137. }
  138. .timing-content {
  139. padding: 24rpx 32rpx;
  140. }
  141. // 定时卡片
  142. .timer-card {
  143. background: #ffffff;
  144. border-radius: 12rpx;
  145. padding: 24rpx;
  146. margin-bottom: 20rpx;
  147. // 卡片头部
  148. .timer-header {
  149. display: flex;
  150. justify-content: space-between;
  151. align-items: center;
  152. margin-bottom: 24rpx;
  153. .timer-title {
  154. font-size: 32rpx;
  155. font-weight: 600;
  156. color: #333333;
  157. font-family: 'Source Han Sans CN';
  158. }
  159. .timer-switch {
  160. transform: scale(0.9);
  161. }
  162. }
  163. // 单选按钮组
  164. .radio-group {
  165. display: flex;
  166. margin-bottom: 24rpx;
  167. .radio-item {
  168. display: flex;
  169. align-items: center;
  170. margin-right: 48rpx;
  171. cursor: pointer;
  172. .radio-icon {
  173. width: 36rpx;
  174. height: 36rpx;
  175. border: 4rpx solid #cccccc;
  176. border-radius: 50%;
  177. display: flex;
  178. align-items: center;
  179. justify-content: center;
  180. margin-right: 12rpx;
  181. box-sizing: border-box;
  182. .radio-dot {
  183. width: 18rpx;
  184. height: 18rpx;
  185. background: #00c853;
  186. border-radius: 50%;
  187. }
  188. }
  189. &.active {
  190. .radio-icon {
  191. border-color: #00c853;
  192. }
  193. .radio-text {
  194. color: #333333;
  195. }
  196. }
  197. .radio-text {
  198. font-size: 28rpx;
  199. color: #999999;
  200. font-family: 'Source Han Sans CN';
  201. }
  202. }
  203. }
  204. // 时间选择器
  205. .time-picker {
  206. display: flex;
  207. justify-content: space-between;
  208. align-items: center;
  209. padding: 20rpx 24rpx;
  210. background: #f5f5f5;
  211. border-radius: 8rpx;
  212. .time-text {
  213. font-size: 28rpx;
  214. color: #333333;
  215. font-family: 'Source Han Sans CN';
  216. &.placeholder {
  217. color: #999999;
  218. }
  219. }
  220. }
  221. }
  222. // 确定按钮
  223. .confirm-btn {
  224. width: 100%;
  225. height: 88rpx;
  226. background: #00c853;
  227. border-radius: 12rpx;
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. margin-top: 20rpx;
  232. .confirm-text {
  233. font-size: 32rpx;
  234. font-weight: 500;
  235. color: #ffffff;
  236. font-family: 'Source Han Sans CN';
  237. }
  238. }
  239. }
  240. </style>