h5-countdown-config.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="countdown-config">
  3. <div class="config-block">
  4. <h3>倒计时配置</h3>
  5. <el-form-item class="time-config" label="时间配置">
  6. <div class="button-group">
  7. <el-radio-group v-model="localConfig.countdownMode" @change="handleModeChange">
  8. <el-radio-button :label="'1'" class="select-button"
  9. :class="{ 'selected': localConfig.countdownMode == '1' }"
  10. >固定截止时间
  11. </el-radio-button>
  12. <el-radio-button :label="'2'" class="select-button"
  13. :class="{ 'selected': localConfig.countdownMode == '2' }"
  14. >固定倒计时长
  15. </el-radio-button>
  16. </el-radio-group>
  17. </div>
  18. <!-- 固定截止时间模式 -->
  19. <template v-if="localConfig.countdownMode == 1">
  20. <div class="datetime-picker">
  21. <el-date-picker
  22. v-model="localConfig.endDateTime"
  23. type="datetime"
  24. placeholder="选择截止日期时间"
  25. format="yyyy-MM-dd HH:mm:ss"
  26. value-format="yyyy-MM-dd HH:mm:ss"
  27. @change="handleEndTimeChange"
  28. ></el-date-picker>
  29. </div>
  30. <div class="help-text">
  31. * 设置一个截至日期固定的倒计时,例如,设置2021-03-04 12:00:00,访客进入页面,该倒计时将会倒计至2021-03-04
  32. 12:00:00结束。
  33. </div>
  34. </template>
  35. <!-- 固定倒计时长模式 -->
  36. <template v-else>
  37. <div class="time-input">
  38. <el-input v-model="localConfig.timeDisplay" @change="handleCountMinusChange" placeholder="分钟">
  39. <template #append>
  40. <i class="el-icon-time"></i>
  41. </template>
  42. </el-input>
  43. </div>
  44. <div class="help-text">
  45. * 固定时长:设置一个固定时长的倒计时,例如,设置5分钟,访客每次进入页面,倒计时均倒计5分钟,若倒计时间结束,用户再次进入页面,倒计时重新开始计时。
  46. </div>
  47. </template>
  48. </el-form-item>
  49. <el-form-item class="color-config" label="颜色">
  50. <el-color-picker
  51. v-model="localConfig.mainColor"
  52. show-alpha
  53. @change="handleColorChange"
  54. ></el-color-picker>
  55. </el-form-item>
  56. <el-form-item class="bg-image-config" label="倒计时底图">
  57. <image-upload v-model="localConfig.bgImage" :file-type='["png", "jpg", "jpeg", "gif"]' :limit="1"/>
  58. </el-form-item>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. export default {
  64. name: 'CountdownConfigComponent',
  65. props: {
  66. config: {
  67. type: Object,
  68. required: false,
  69. default: () => ({
  70. hours: 0,
  71. minutes: 10,
  72. seconds: 0,
  73. endDateTime: null,
  74. timeDisplay: 0,
  75. mainColor: '#FF5722',
  76. bgImage: ''
  77. })
  78. }
  79. },
  80. data() {
  81. return {
  82. localConfig: { ...this.config }
  83. }
  84. },
  85. methods: {
  86. // 数字补零
  87. padZero(num) {
  88. return num.toString().padStart(2, '0')
  89. },
  90. // 格式化时间显示
  91. formatTimeDisplay(hours, minutes, seconds) {
  92. return `${this.padZero(hours)}时 ${this.padZero(minutes)}分 ${this.padZero(seconds)}秒`
  93. },
  94. // 处理倒计时模式变更
  95. handleModeChange(value) {
  96. this.localConfig.countdownMode = value
  97. this.$emit('update:config', { ...this.localConfig })
  98. },
  99. // 处理倒计时长
  100. handleCountMinusChange(value) {
  101. this.localConfig.timeDisplay = value
  102. this.$emit('update:config', { ...this.localConfig })
  103. },
  104. // 处理截止时间变更
  105. handleEndTimeChange(value) {
  106. this.localConfig.endDateTime = value
  107. this.$emit('update:config', { ...this.localConfig })
  108. },
  109. // 处理颜色变更
  110. handleColorChange(value) {
  111. this.localConfig.mainColor = value
  112. this.$emit('update:config', { ...this.localConfig })
  113. }
  114. },
  115. // 监听属性变化
  116. watch: {
  117. 'localConfig.bgImage': {
  118. handler(newVal, oldVal) {
  119. this.localConfig.bgImage = newVal
  120. this.$emit('update:config', { ...this.localConfig })
  121. },
  122. deep: false
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped>
  128. .countdown-config {
  129. width: 100%;
  130. font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  131. }
  132. .config-block {
  133. padding: 0px 15px;
  134. }
  135. h3, h4 {
  136. font-weight: 500;
  137. margin: 15px 0 10px 0;
  138. color: #303133;
  139. }
  140. h3 {
  141. font-size: 16px;
  142. border-bottom: 1px solid #EBEEF5;
  143. padding-bottom: 10px;
  144. }
  145. h4 {
  146. font-size: 14px;
  147. margin-top: 20px;
  148. }
  149. .button-group {
  150. margin: 10px 0;
  151. }
  152. .select-button {
  153. margin-right: -1px;
  154. }
  155. .selected {
  156. color: #fff;
  157. background-color: #409EFF;
  158. border-color: #409EFF;
  159. }
  160. .datetime-picker, .time-input {
  161. margin: 10px 0;
  162. }
  163. .help-text {
  164. color: #909399;
  165. font-size: 12px;
  166. margin-top: 5px;
  167. line-height: 1.5;
  168. }
  169. .color-config {
  170. margin: 15px 0;
  171. }
  172. .color-preview {
  173. height: 30px;
  174. border-radius: 4px;
  175. margin-top: 10px;
  176. }
  177. .image-upload-area {
  178. border: 1px dashed #d9d9d9;
  179. border-radius: 6px;
  180. width: 100%;
  181. height: 108px;
  182. display: flex;
  183. justify-content: center;
  184. align-items: center;
  185. position: relative;
  186. margin: 10px 0;
  187. overflow: hidden;
  188. }
  189. .image-preview {
  190. width: 100%;
  191. height: 100%;
  192. position: relative;
  193. }
  194. .image-preview img {
  195. width: 100%;
  196. height: 100%;
  197. object-fit: contain;
  198. }
  199. .image-actions {
  200. position: absolute;
  201. bottom: 0;
  202. left: 0;
  203. right: 0;
  204. background-color: rgba(0, 0, 0, 0.5);
  205. display: flex;
  206. justify-content: space-around;
  207. padding: 5px 0;
  208. }
  209. .upload-tip {
  210. text-align: center;
  211. color: #909399;
  212. font-size: 12px;
  213. }
  214. .upload-tip i {
  215. font-size: 28px;
  216. color: #C0C4CC;
  217. margin-bottom: 5px;
  218. }
  219. .price-config {
  220. margin-top: 15px;
  221. }
  222. .price-input {
  223. display: flex;
  224. align-items: center;
  225. margin: 10px 0;
  226. }
  227. .color-label {
  228. margin-right: 10px;
  229. min-width: 40px;
  230. }
  231. .price-value {
  232. margin: 10px 0 20px 0;
  233. }
  234. </style>