ACron.vue 2.37 KB
Newer Older
陈浩玮's avatar
陈浩玮 committed
1
<template>
水落(YangLei)'s avatar
水落(YangLei) committed
2 3
    <div class="components-input-demo-presuffix">
        <a-input :placeholder="placeholder" :value="cron" @input="handleinput" :disabled="disabled">
shuiluo's avatar
shuiluo committed
4 5 6 7 8 9 10 11
            <a-icon slot="prefix" type="schedule" :title="$t('corn.title')" @click="openModal" />
            <a-icon
                v-if="cron"
                slot="suffix"
                type="close-circle"
                @click="handleEmpty"
                :title="$t('input.clear')"
            />
水落(YangLei)'s avatar
水落(YangLei) committed
12
        </a-input>
shuiluo's avatar
shuiluo committed
13
        <AntCron ref="innerVueCron" :data="afterCron" @ok="handleOK" />
水落(YangLei)'s avatar
水落(YangLei) committed
14
    </div>
陈浩玮's avatar
陈浩玮 committed
15 16
</template>
<script>
水落(YangLei)'s avatar
水落(YangLei) committed
17 18
import AntCron from './AntCron';
import { replaceWeekName } from './validator';
陈浩玮's avatar
陈浩玮 committed
19
export default {
水落(YangLei)'s avatar
水落(YangLei) committed
20 21 22
    name: 'ACron',
    components: {
        AntCron,
陈浩玮's avatar
陈浩玮 committed
23
    },
水落(YangLei)'s avatar
水落(YangLei) committed
24 25 26 27 28 29 30 31 32 33 34 35
    props: {
        value: {
            required: false,
            type: String,
            default: '',
        },
        placeholder: {
            required: false,
            type: String,
            default: '',
        },
        disabled: Boolean,
陈浩玮's avatar
陈浩玮 committed
36
    },
水落(YangLei)'s avatar
水落(YangLei) committed
37 38 39 40 41
    data() {
        return {
            cron: this.value,
            afterCron: '',
        };
陈浩玮's avatar
陈浩玮 committed
42
    },
水落(YangLei)'s avatar
水落(YangLei) committed
43 44 45 46 47 48 49 50 51 52
    watch: {
        value(val) {
            this.cron = val;
        },
        cron(val) {
            console.log(replaceWeekName(val));
            this.afterCron = replaceWeekName(val);
            console.log(val);
            this.$emit('input', val);
        },
陈浩玮's avatar
陈浩玮 committed
53
    },
水落(YangLei)'s avatar
水落(YangLei) committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    methods: {
        openModal() {
            if (this.disabled) return;
            this.$refs.innerVueCron.show();
        },
        handleOK(val) {
            this.cron = val;
            this.$emit('change', this.cron);
        },
        handleinput(evt) {
            this.cron = evt.target.value;
            if (this.cron !== '') {
                this.$emit('change', this.cron);
            } else {
                this.$emit('change', undefined);
            }
        },
        handleEmpty() {
            if (this.disabled) return;
            this.handleOK('');
        },
    },
    model: {
        prop: 'value',
        event: 'change',
陈浩玮's avatar
陈浩玮 committed
79 80 81
    },
};
</script>
shuiluo's avatar
shuiluo committed
82

陈浩玮's avatar
陈浩玮 committed
83 84
<style scoped>
.components-input-demo-presuffix .anticon-close-circle {
水落(YangLei)'s avatar
水落(YangLei) committed
85 86 87 88
    cursor: pointer;
    color: #ccc;
    transition: color 0.3s;
    font-size: 12px;
陈浩玮's avatar
陈浩玮 committed
89 90
}
.components-input-demo-presuffix .anticon-close-circle:hover {
水落(YangLei)'s avatar
水落(YangLei) committed
91
    color: #f5222d;
陈浩玮's avatar
陈浩玮 committed
92 93
}
.components-input-demo-presuffix .anticon-close-circle:active {
水落(YangLei)'s avatar
水落(YangLei) committed
94
    color: #666;
陈浩玮's avatar
陈浩玮 committed
95
}
水落(YangLei)'s avatar
水落(YangLei) committed
96
</style>