<template>
<div id="app">
<!-- 输入框 -->
<el-form :model="form" label-position="left">
<el-form-item label="cron表达式" :label-width="formLabelWidth">
<el-input v-model="form.cron_rule" autocomplete="off" placeholder="请输入定时cron表达式" disabled>
<template slot="append">
<el-button type="primary" @click="creatCron">
生成表达式
<i class="el-icon-time el-icon--right"></i>
</el-button>
</template>
</el-input>
</el-form-item>
<!-- cron dialog -->
<el-dialog title="生成 cron" :visible.sync="showCron">
<VueCronEditorBuefy v-model="expression"/>
<div style="color:#2496FF">
<h5>预览cron表达式: {{ expression }}</h5>
<h5>cron表达式解释: {{ explainAddCron }}</h5>
</div>
<el-button type="primary" size="medium" @click="cronConfirm" style="margin-left: 88%;">确定
</el-button>
</el-dialog>
</el-form>
</div>
</template>
<script>
import VueCronEditorBuefy from 'vue-cron-editor-buefy';
import cronstrue from "cronstrue/i18n";
export default {
components: { cronstrue,VueCronEditorBuefy, },
data() {
return {
input: "",
expression: "",
showCron: false,
cronExpression: "*/1 * * * *",
form:{},
formLabelWidth: '120px',
showCron: false
};
},
computed: {
explainAddCron() {
if(this.expression){
// use24HourTimeFormat : 使用24小时制, 默认false 12小时制
return cronstrue.toString(this.expression, { locale: "zh_CN",use24HourTimeFormat:true});
}
}
},
methods: {
creatCron(){
// 生成表达式
this.expression = this.cronExpression
this.showCron = true
},
cronConfirm() {
// 生成表达式确定按钮
this.showCron = false
this.form.cron_rule = this.expression
},
}
};
</script>