123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <div class="countdown-config">
- <div class="config-block">
- <h3>倒计时配置</h3>
- <el-form-item class="time-config" label="时间配置">
- <div class="button-group">
- <el-radio-group v-model="localConfig.countdownMode" @change="handleModeChange">
- <el-radio-button :label="'1'" class="select-button"
- :class="{ 'selected': localConfig.countdownMode == '1' }"
- >固定截止时间
- </el-radio-button>
- <el-radio-button :label="'2'" class="select-button"
- :class="{ 'selected': localConfig.countdownMode == '2' }"
- >固定倒计时长
- </el-radio-button>
- </el-radio-group>
- </div>
- <!-- 固定截止时间模式 -->
- <template v-if="localConfig.countdownMode == 1">
- <div class="datetime-picker">
- <el-date-picker
- v-model="localConfig.endDateTime"
- type="datetime"
- placeholder="选择截止日期时间"
- format="yyyy-MM-dd HH:mm:ss"
- value-format="yyyy-MM-dd HH:mm:ss"
- @change="handleEndTimeChange"
- ></el-date-picker>
- </div>
- <div class="help-text">
- * 设置一个截至日期固定的倒计时,例如,设置2021-03-04 12:00:00,访客进入页面,该倒计时将会倒计至2021-03-04
- 12:00:00结束。
- </div>
- </template>
- <!-- 固定倒计时长模式 -->
- <template v-else>
- <div class="time-input">
- <el-input v-model="localConfig.timeDisplay" @change="handleCountMinusChange" placeholder="分钟">
- <template #append>
- <i class="el-icon-time"></i>
- </template>
- </el-input>
- </div>
- <div class="help-text">
- * 固定时长:设置一个固定时长的倒计时,例如,设置5分钟,访客每次进入页面,倒计时均倒计5分钟,若倒计时间结束,用户再次进入页面,倒计时重新开始计时。
- </div>
- </template>
- </el-form-item>
- <el-form-item class="color-config" label="颜色">
- <el-color-picker
- v-model="localConfig.mainColor"
- show-alpha
- @change="handleColorChange"
- ></el-color-picker>
- </el-form-item>
- <el-form-item class="bg-image-config" label="倒计时底图">
- <image-upload v-model="localConfig.bgImage" :file-type='["png", "jpg", "jpeg", "gif"]' :limit="1"/>
- </el-form-item>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'CountdownConfigComponent',
- props: {
- config: {
- type: Object,
- required: false,
- default: () => ({
- hours: 0,
- minutes: 10,
- seconds: 0,
- endDateTime: null,
- timeDisplay: 0,
- mainColor: '#FF5722',
- bgImage: ''
- })
- }
- },
- data() {
- return {
- localConfig: { ...this.config }
- }
- },
- methods: {
- // 数字补零
- padZero(num) {
- return num.toString().padStart(2, '0')
- },
- // 格式化时间显示
- formatTimeDisplay(hours, minutes, seconds) {
- return `${this.padZero(hours)}时 ${this.padZero(minutes)}分 ${this.padZero(seconds)}秒`
- },
- // 处理倒计时模式变更
- handleModeChange(value) {
- this.localConfig.countdownMode = value
- this.$emit('update:config', { ...this.localConfig })
- },
- // 处理倒计时长
- handleCountMinusChange(value) {
- this.localConfig.timeDisplay = value
- this.$emit('update:config', { ...this.localConfig })
- },
- // 处理截止时间变更
- handleEndTimeChange(value) {
- this.localConfig.endDateTime = value
- this.$emit('update:config', { ...this.localConfig })
- },
- // 处理颜色变更
- handleColorChange(value) {
- this.localConfig.mainColor = value
- this.$emit('update:config', { ...this.localConfig })
- }
- },
- // 监听属性变化
- watch: {
- 'localConfig.bgImage': {
- handler(newVal, oldVal) {
- this.localConfig.bgImage = newVal
- this.$emit('update:config', { ...this.localConfig })
- },
- deep: false
- }
- }
- }
- </script>
- <style scoped>
- .countdown-config {
- width: 100%;
- font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
- }
- .config-block {
- padding: 0px 15px;
- }
- h3, h4 {
- font-weight: 500;
- margin: 15px 0 10px 0;
- color: #303133;
- }
- h3 {
- font-size: 16px;
- border-bottom: 1px solid #EBEEF5;
- padding-bottom: 10px;
- }
- h4 {
- font-size: 14px;
- margin-top: 20px;
- }
- .button-group {
- margin: 10px 0;
- }
- .select-button {
- margin-right: -1px;
- }
- .selected {
- color: #fff;
- background-color: #409EFF;
- border-color: #409EFF;
- }
- .datetime-picker, .time-input {
- margin: 10px 0;
- }
- .help-text {
- color: #909399;
- font-size: 12px;
- margin-top: 5px;
- line-height: 1.5;
- }
- .color-config {
- margin: 15px 0;
- }
- .color-preview {
- height: 30px;
- border-radius: 4px;
- margin-top: 10px;
- }
- .image-upload-area {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- width: 100%;
- height: 108px;
- display: flex;
- justify-content: center;
- align-items: center;
- position: relative;
- margin: 10px 0;
- overflow: hidden;
- }
- .image-preview {
- width: 100%;
- height: 100%;
- position: relative;
- }
- .image-preview img {
- width: 100%;
- height: 100%;
- object-fit: contain;
- }
- .image-actions {
- position: absolute;
- bottom: 0;
- left: 0;
- right: 0;
- background-color: rgba(0, 0, 0, 0.5);
- display: flex;
- justify-content: space-around;
- padding: 5px 0;
- }
- .upload-tip {
- text-align: center;
- color: #909399;
- font-size: 12px;
- }
- .upload-tip i {
- font-size: 28px;
- color: #C0C4CC;
- margin-bottom: 5px;
- }
- .price-config {
- margin-top: 15px;
- }
- .price-input {
- display: flex;
- align-items: center;
- margin: 10px 0;
- }
- .color-label {
- margin-right: 10px;
- min-width: 40px;
- }
- .price-value {
- margin: 10px 0 20px 0;
- }
- </style>
|