在上一篇笔记《PHP日程计划管理功能之日期计算器(1)》中波波记录了日程计划中核心的日期计算方法,本篇笔记记录日程计划设置的HTML页面。
由于本源码是结合PHP数据渲染编写的,故而在源代码中可能包含一部分PHP表示的变量,包括一些下拉框也是采用PHP输出的。分享本源码的意义仅供参考。以及layui如何实现点击单选框显示不同的表单。
- {block name="content"}
- <form onsubmit="return false;" action="__SELF__" data-auto="true" method="post" class='form-horizontal layui-form' style='padding-top:20px;height: 500px'>
- <div class="layui-form-item">
- <label class="layui-form-label">计划类型</label>
- <div class="layui-input-block">
- <input type="radio" name="type" value="year" title="年" {if isset($sched.type) and $sched.type eq 'year'}checked{/if} lay-filter="ttype">
- <input type="radio" name="type" value="month" title="月" {if isset($sched.type) and $sched.type eq 'month'}checked{/if} lay-filter="ttype">
- <input type="radio" name="type" value="week" title="周" {if isset($sched.type) and $sched.type eq 'week'}checked{/if} lay-filter="ttype">
- <input type="radio" name="type" value="day" title="日" {if isset($sched.type) and $sched.type eq 'day'}checked{/if} lay-filter="ttype">
- <input type="radio" name="type" value="hour" title="运行时长" {if isset($sched.type) and $sched.type eq 'hour'}checked{/if} lay-filter="ttype">
- </div>
- </div>
- <!--分割线-->
- <div class="hr-line-dashed"></div>
- <div class="form-group" data-storage-type="year">
- <div class="layui-form-item">
- <div class="layui-input-block">
- <input type="radio" name="cycle_type" value="week" title="按周" {if isset($sched.cycle_type) and $sched.cycle_type eq 'week'}checked{/if} lay-filter="cycle_type">
- <input type="radio" name="cycle_type" value="month" title="按月" {if isset($sched.cycle_type) and $sched.cycle_type eq 'month'}checked{/if} lay-filter="cycle_type" >
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="year-week" lay-filter="year-week">
- <div class="layui-form-item">
- <label class="layui-form-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid">年重复,</div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">在</label>
- <div class="layui-input-inline">
- <select name="month" style="width: 30%" required="required" lay-filter="selc_month">
- <option value="0">请选择</option>
- <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>一月</option>
- <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>二月</option>
- <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>三月</option>
- <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>四月</option>
- <option value="5" {if isset($sched.month) and $sched.month eq 1}selected{/if}>五月</option>
- <option value="6" {if isset($sched.month) and $sched.month eq 1}selected{/if}>六月</option>
- <option value="7" {if isset($sched.month) and $sched.month eq 1}selected{/if}>七月</option>
- <option value="8" {if isset($sched.month) and $sched.month eq 1}selected{/if}>八月</option>
- <option value="9" {if isset($sched.month) and $sched.month eq 1}selected{/if}>九月</option>
- <option value="10" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十月</option>
- <option value="11" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十一月</option>
- <option value="12" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十二月</option>
- </select>
- </div>
- <div class="layui-input-inline">
- <select name="week" style="width: 30%" required="required" lay-filter="selc_week">
- <option value="0">请选择</option>
- <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第一周</option>
- <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第二周</option>
- <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第三周</option>
- <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第四周</option>
- </select>
- </div>
- <div class="layui-input-inline">
- <select name="weekday" style="width: 30%" required="required" lay-filter="selc_weekday">
- <option value="0">请选择</option>
- <option value="monday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期一</option>
- <option value="tuesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期二</option>
- <option value="wednesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期三</option>
- <option value="thursday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期四</option>
- <option value="friday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期五</option>
- <option value="saturday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期六</option>
- <option value="sunday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期日</option>
- </select>
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">开始时间</label>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="year-month" lay-filter="year-month">
- <div class="layui-form-item">
- <label class="layui-form-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid">年重复,</div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">在</label>
- <div class="layui-input-inline">
- <select name="month" style="width: 30%" required="required" lay-filter="selc_month">
- <option value="0">请选择</option>
- <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>一月</option>
- <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>二月</option>
- <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>三月</option>
- <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>四月</option>
- <option value="5" {if isset($sched.month) and $sched.month eq 1}selected{/if}>五月</option>
- <option value="6" {if isset($sched.month) and $sched.month eq 1}selected{/if}>六月</option>
- <option value="7" {if isset($sched.month) and $sched.month eq 1}selected{/if}>七月</option>
- <option value="8" {if isset($sched.month) and $sched.month eq 1}selected{/if}>八月</option>
- <option value="9" {if isset($sched.month) and $sched.month eq 1}selected{/if}>九月</option>
- <option value="10" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十月</option>
- <option value="11" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十一月</option>
- <option value="12" {if isset($sched.month) and $sched.month eq 1}selected{/if}>十二月</option>
- </select>
- </div>
- <div class="layui-form-mid">第</div>
- <div class="layui-input-inline">
- <select name="day" style="width: 15%" lay-filter="selc" required>
- {if isset($sched.day)}{:dayOptions($sched.day)}{else /}{:dayOptions()}{/if}
- </select>
- </div>
- <div class="layui-form-mid">天,</div>
- <label class="layui-form-mid">开始时间</label>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="month">
- <div class="layui-form-item">
- <div class="layui-input-block">
- <input type="radio" name="cycle_type" value="week" title="按周" {if isset($sched.cycle_type) and $sched.cycle_type eq 'week'}checked{/if} lay-filter="cycle_type">
- <input type="radio" name="cycle_type" value="day" title="按天" {if isset($sched.cycle_type) and $sched.cycle_type eq 'day'}checked{/if} lay-filter="cycle_type">
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="month-week" lay-filter="month-week" style="margin-left: 40px">
- <div class="layui-form-item">
- <label class="layui-form-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid text-explode">月重复,</div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">在</label>
- <div class="layui-input-inline">
- <select name="week" style="width: 30%" lay-filter="selc_week">
- <option value="0">请选择</option>
- <option value="1" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第一周</option>
- <option value="2" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第二周</option>
- <option value="3" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第三周</option>
- <option value="4" {if isset($sched.month) and $sched.month eq 1}selected{/if}>第四周</option>
- </select>
- </div>
- <div class="layui-input-inline">
- <select name="weekday" style="width: 30%" lay-filter="selc_weekday">
- <option value="0">请选择</option>
- <option value="monday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期一</option>
- <option value="tuesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期二</option>
- <option value="wednesday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期三</option>
- <option value="thursday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期四</option>
- <option value="friday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期五</option>
- <option value="saturday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期六</option>
- <option value="sunday" {if isset($sched.month) and $sched.month eq 1}selected{/if}>星期日</option>
- </select>
- </div>
- <label class="layui-form-label">开始时间</label>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="month-day" lay-filter="month-day" style="margin-left: 40px">
- <div class="layui-form-item">
- <label class="layui-form-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid">月重复,</div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">在第</label>
- <div class="layui-input-inline">
- <select name="day" lay-filter="selc">
- {if isset($sched.day)}{:dayOptions($sched.day)}{else /}{:dayOptions()}{/if}
- </select>
- </div>
- <div class="layui-form-mid">天,</div>
- <label class="layui-form-label">开始时间</label>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="day">
- <div class="layui-form-item">
- <label class="col-sm-2 control-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid text-explode">天重复,开始时间</div>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="week">
- <div class="layui-form-item">
- <label class="col-sm-2 control-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid text-explode">周重复,开始时间</div>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="col-sm-2 control-label" required="required">选择星期:</label>
- <div class="layui-input-block">
- <input type="checkbox" name="cweek[monday]" lay-skin="primary" title="星期一" {if isset($sched.week.monday) and $sched.week.monday eq 1}checked{/if}>
- <input type="checkbox" name="cweek[tuesday]" lay-skin="primary" title="星期二" {if isset($sched.week.tuesday) and $sched.week.tuesday eq 1}checked{/if}>
- <input type="checkbox" name="cweek[wednesday]" lay-skin="primary" title="星期三" {if isset($sched.week.wednesday) and $sched.week.wednesday eq 1}checked{/if}>
- <input type="checkbox" name="cweek[thursday]" lay-skin="primary" title="星期四" {if isset($sched.week.thursday) and $sched.week.thursday eq 1}checked{/if}>
- <input type="checkbox" name="cweek[friday]" lay-skin="primary" title="星期五" {if isset($sched.week.friday) and $sched.week.friday eq 1}checked{/if}>
- <input type="checkbox" name="cweek[saturday]" lay-skin="primary" title="星期六" {if isset($sched.week.saturday) and $sched.week.saturday eq 1}checked{/if}>
- <input type="checkbox" name="cweek[sunday]" lay-skin="primary" title="星期日" {if isset($sched.week.sunday) and $sched.week.sunday eq 1}checked{/if}>
- </div>
- </div>
- </div>
- <div class="form-group" data-storage-type="hour">
- <div class="layui-form-item">
- <label class="col-sm-2 control-label">每隔</label>
- <div class='layui-input-inline'>
- <input name="gap" required="required" value="{$sched.gap|default='1'}" class="layui-input" autocomplete="off">
- </div>
- <div class="layui-form-mid text-explode">小时重复,开始时间</div>
- <div class="layui-input-inline">
- <input name="begin_time" required="begin_time" value="{$sched.begin_time|default='00:00'}" class="layui-input">
- </div>
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">开始日期</label>
- <div class="layui-input-inline">
- <input name="start_time" id="start_time" value="{$vo.start_time|default=''}" required="required" title="请设置开始时间" class="layui-input">
- </div>
- <label class="layui-form-label">结束时间</label>
- <div class="layui-input-inline">
- <input name="finish_time" id="finish_time" value="{$vo.finish_time|default=''}" required="required" title="请设置结束时间" class="layui-input">
- </div>
- </div>
- <div class="hr-line-dashed"></div>
- <div class="col-sm-4 col-sm-offset-2">
- <div class="layui-form-item text-center">
- {if isset($id)}<input type='hidden' value='{$id}' name='id'/>{/if}
- <button class="layui-btn" type="submit">保存计划</button>
- <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消日程设置吗?" data-close>取消日程</button>
- </div>
- </div>
- </form>
- {/block}
- {block name="script"}
- <script>
- window.form.render();
- //表单初始化
- var type_value = "{$sched.type|default='day'}";
- var elem_hide = $("[data-storage-type='" + type_value + "']");
- $("[data-storage-type]").not(elem_hide.show()).hide();
- //解决input内容改变值不变BUG
- $("input[name=gap]").change(function(e){
- $("input[name=gap]").val(e.delegateTarget.value);
- })
- layui.use(['form','jquery','laydate'],function (){
- var form = layui.form,$=layui.jquery,laydate=layui.laydate;
- //点击type单选框切换表单
- form.on('radio(ttype)',function (data){
- var $tips = $("[data-storage-type='" + data.value + "']");
- $("[data-storage-type]").not($tips.show()).hide();
- form.render();
- })
- form.on('radio(cycle_type)',function (data){
- var ttpye = $('[name=type]:checked').val();
- var $tips = $("[data-storage-type='" + ttpye +"-" + data.value + "']");
- $("[data-storage-type]").not($tips.show()).hide();
- $("[data-storage-type='"+ttpye+"']").show();
- form.render();
- })
- form.on('select(selc)',function (data){
- $("select[name=day]").val(data.value);
- })
- form.on('select(selc_month)',function (data){
- $("select[name=month]").val(data.value);
- })
- form.on('select(selc_week)',function (data){
- $("select[name=week]").val(data.value);
- })
- form.on('select(selc_weekday)',function (data){
- $("select[name=weekday]").val(data.value);
- })
- //阻止多个日期点击冒泡事件
- $("#start_time").on("click",function(){
- laydate.render({
- elem:'#start_time',format:'yyyy-MM-dd',closeStop:'#start_time',value:this.value
- })
- })
- $("#finish_time").on("click",function(){
- laydate.render({
- elem:'#finish_time',format:'yyyy-MM-dd',closeStop:'#finish_time',value:this.value
- })
- })
- //阻止laydate冒泡事件
- $("input[name='begin_time']").on('click',function (){
- laydate.render({
- elem:this,
- type:'time',
- format:'HH:mm',
- value:this.value,
- change:function (value){
- $("input[name='begin_time']").val(value);
- }
- });
- })
- })
- </script>
- {/block}