🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 模型字段变量函数 [TOC] ## text 文本框 ~~~ function text($fieldinfo){ //字段名 $field = $fieldinfo['field']; //反序列化设置项 $setting = unserialize($fieldinfo['setting']); //默认值 $value = $setting['defaultvalue']; //是否密码框 $type = "text"; if( $setting['ispassword'] ) { $type = "password"; } $form = <<<EOF <input id="info_$field" name="info[$field]" type="$type" class="form-control" value="$value"> EOF; return $form; } ~~~ ## textarea 多行文本框 ~~~ function textarea($fieldinfo){ //字段名 $field = $fieldinfo['field']; //反序列化设置项 $setting = unserialize($fieldinfo['setting']); //默认值 $value = $setting['defaultvalue']; $height = $setting['height'].'px'; $form = <<<EOF <textarea type="text" id="info_$field" name="info[$field]" class="form-control" style="height:$height">$value</textarea> EOF; return $form; } ~~~ ## number 数字 ~~~ function number($fieldinfo){ //字段名 $field = $fieldinfo['field']; //反序列化设置项 $setting = unserialize($fieldinfo['setting']); //默认值 $value = $setting['defaultvalue']; $form = <<<EOF <input id="info_$field" name="info[$field]" type="text" class="form-control" value="$value"> EOF; return $form; } ~~~ ## datetime 日期时间 ~~~ function datetime($fieldinfo){ //字段名 $field = $fieldinfo['field']; //反序列化设置项 $setting = unserialize($fieldinfo['setting']); //默认值 $value = $setting['defaultvalue']; //字段类型 $fieldtype = $setting['fieldtype']; $date = is_null($fieldinfo['realvalue']) ? date('Y-m-d') : $fieldinfo['realvalue']; $datetime = is_null($fieldinfo['realvalue']) ? date('Y-m-d H:i:s') : $fieldinfo['realvalue']; if( $fieldtype=='date' ) { $str = <<<EOF <label class="laydate-icon"></label> <input class="form-control layer-date" name="info[$field]" value="$date" onclick="laydate({format: 'YYYY-MM-DD'})"> EOF; }elseif( $fieldtype=='datetime' ) { $str = <<<EOF <label class="laydate-icon"></label> <input class="form-control layer-date" name="info[$field]" value="$datetime" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"> EOF; } return $str; } ~~~ ## image 单图上传 ~~~ function image($fieldinfo){ //字段名 $field = $fieldinfo['field']; $form = <<<EOF <div id="file-pretty"> <input type="file" id="info_$field" name="info[$field]" class="form-control"> </div> EOF; return $form; } ~~~ ## images 多图上传 ~~~ function images($fieldinfo){ //字段名 $field = $fieldinfo['field']; $form = <<<EOF <div id="uploader" class="xb-uploader"> <div class="queueList"> <div class="placeholder"> <div class="filePicker"></div> <p>或将照片拖到这里,单次最多可选300张</p> </div> </div> <div class="statusBar" style="display:none;"> <div class="progress"> <span class="text">0%</span> <span class="percentage"></span> </div> <div class="info"></div> <div class="btns"> <div class="webuploader-container filePicker2"> <div class="webuploader-pick">继续添加</div> <div style="position: absolute; top: 0px; left: 0px; width: 1px; height: 1px; overflow: hidden;" id="rt_rt_1armv2159g1o1i9c2a313hadij6"> </div> </div> <div class="uploadBtn">开始上传</div> </div> </div> </div> EOF; return $form; } ~~~ ## downfile 单文件上传 ~~~ function downfile($fieldinfo){ //字段名 $field = $fieldinfo['field']; $form = <<<EOF <div id="file-pretty"> <input type="file" id="info_$field" name="info[$field]" class="form-control"> </div> EOF; return $form; } ~~~ ## downfiles 多文件上传 ~~~ function downfiles($fieldinfo){ //字段名 $field = $fieldinfo['field']; $form = <<<EOF <div id="uploader" class="xb-uploader"> <div class="queueList"> <div class="placeholder"> <div class="filePicker"></div> <p>或将文件拖到这里</p> </div> </div> <div class="statusBar" style="display:none;"> <div class="progress"> <span class="text">0%</span> <span class="percentage"></span> </div> <div class="info"></div> <div class="btns"> <div class="webuploader-container filePicker2"> <div class="webuploader-pick">继续添加</div> <div style="position: absolute; top: 0px; left: 0px; width: 1px; height: 1px; overflow: hidden;" id="rt_rt_1armv2159g1o1i9c2a313hadij6"> </div> </div> <div class="uploadBtn">开始上传</div> </div> </div> </div> EOF; return $form; } ~~~ ## editor 编辑器 ~~~ function editor($fieldinfo){ //字段名 $field = $fieldinfo['field']; //反序列化设置项 $setting = unserialize($fieldinfo['setting']); //默认值 $value = $setting['defaultvalue']; //高度 $height = $setting['height']; // 插件地址 $admin = config("view_replace_str.__ADMIN__"); $str = <<<EOF <script id="container" name="content" type="text/plain">$value</script> <script src="$admin/plugins/ueditor1_4_3_3/ueditor.config.js"></script> <script src="$admin/plugins/ueditor1_4_3_3/ueditor.all.js"></script> <script> var um = UE.getEditor('container',{ initialFrameHeight:$height, autoHeightEnabled:false, catchRemoteImageEnable:true }); </script> EOF; return $str; } ~~~ ## box 选项 ~~~ function box($fieldinfo){ //字段名 $field = $fieldinfo['field']; //反序列化设置项 $setting = unserialize($fieldinfo['setting']); //默认值 $defaultvalue = $setting['defaultvalue']; $options = explode("\n",$setting['options']); foreach ($options as $name_value) { $v = explode('|', $name_value); $k = trim($v['1']); $option[$k] = $v['0']; }//return $option; switch ($setting['boxtype']) { case 'radio': $radio = ''; $state = ''; foreach ($option as $key => $value) { $state = $defaultvalue == $key ? 'checked' : ''; $radio .="<input type='radio' name='$field' value='$key' $state> <i></i> $value&nbsp;&nbsp;&nbsp;&nbsp;"; } $str = <<<EOF <div class="radio i-checks"> <label style="padding-left:0"> $radio </label> </div> EOF; break; case 'checkbox': $checkbox = ''; $state = ''; $defaultvalues = explode(",",$defaultvalue); foreach ($option as $key => $value) { $state = in_array($key,$defaultvalues) ? 'checked' : ''; $checkbox .="<input type='checkbox' name='$field' value='$key' $state> <i></i> $value&nbsp;&nbsp;&nbsp;&nbsp;"; } $str = <<<EOF <div class="checkbox i-checks"> <label style="padding-left:0"> $checkbox </label> </div> EOF; break; case 'select': $select = ''; $state = ''; foreach ($option as $key => $value) { $state = $defaultvalue == $key ? 'selected' : ''; $select .="<option value='$key' $state>$value</option>"; } $str = <<<EOF <select class="form-control m-b" name="$field"> $select </select> EOF; break; case 'multiple': $multiple = ''; $state = ''; $defaultvalues = explode(",",$defaultvalue); foreach ($option as $key => $value) { $state = in_array($key,$defaultvalues) ? 'selected' : ''; $multiple .="<option value='$key' $state>$value</option>"; } $str = <<<EOF <select class="form-control m-b" name="$field" multiple> $multiple </select> EOF; break; } return $str; } ~~~