更新
This commit is contained in:
42
app/http/form/Factory.php
Normal file
42
app/http/form/Factory.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\form;
|
||||
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class Factory {
|
||||
|
||||
protected $field = [];
|
||||
protected $data = [];
|
||||
|
||||
public function __construct($field, $data){
|
||||
$this->field = $field;
|
||||
$this->data = $data;
|
||||
$this->parseValue();
|
||||
}
|
||||
|
||||
public function display($template = 'show', $data = []){
|
||||
View::config([
|
||||
'view_path' => dirname(__file__) . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR
|
||||
]);
|
||||
View::assign($data);
|
||||
return View::fetch('/' . $template, $this->field);
|
||||
}
|
||||
|
||||
protected function parseValue(){
|
||||
$this->field['value'] = isset($this->data[$this->field['name']]) ? $this->data[$this->field['name']] : '';
|
||||
}
|
||||
|
||||
public function show(){
|
||||
return $this->display($this->field['type']);
|
||||
}
|
||||
}
|
||||
33
app/http/form/Form.php
Normal file
33
app/http/form/Form.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\form;
|
||||
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class Form {
|
||||
|
||||
public static function render($field, $data){
|
||||
if (in_array($field['type'], ['string', 'text'])) {
|
||||
$field['type'] = 'text';
|
||||
}
|
||||
|
||||
$class = "app\\http\\form\\factory\\" . ucfirst($field['type']);
|
||||
|
||||
if (class_exists($class)) {
|
||||
$elem = new $class($field, $data);
|
||||
}else{
|
||||
$elem = new \app\http\form\Factory($field, $data);
|
||||
}
|
||||
|
||||
return $elem->show();
|
||||
}
|
||||
}
|
||||
26
app/http/form/factory/Checkbox.php
Normal file
26
app/http/form/factory/Checkbox.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\form\factory;
|
||||
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class Checkbox extends \app\http\form\Factory {
|
||||
|
||||
public function show(){
|
||||
return $this->display('checkbox');
|
||||
}
|
||||
|
||||
protected function parseValue(){
|
||||
$this->field['value'] = isset($this->data[$this->field['name']]) ? $this->data[$this->field['name']] : [];
|
||||
}
|
||||
|
||||
}
|
||||
22
app/http/form/factory/Text.php
Normal file
22
app/http/form/factory/Text.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\http\form\factory;
|
||||
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后台中间件
|
||||
*/
|
||||
class Text extends \app\http\form\Factory {
|
||||
|
||||
public function show(){
|
||||
return $this->display('text');
|
||||
}
|
||||
|
||||
}
|
||||
6
app/http/form/template/checkbox.html
Normal file
6
app/http/form/template/checkbox.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{volist name="option" id="item"}
|
||||
<div class="checkbox-nice checkbox-inline">
|
||||
<input type="checkbox" name="{$name}[]" id="{$name}-{$key}" value="{$key}" {if in_array($key, $value)}checked{/if}/>
|
||||
<label for="{$name}-{$key}">{$item}</label>
|
||||
</div>
|
||||
{/volist}
|
||||
7
app/http/form/template/editor.html
Normal file
7
app/http/form/template/editor.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<textarea name="{$name}" id="{$name}" style="width: 100%;">{$value}</textarea>
|
||||
<!-- 实例化编辑器代码 -->
|
||||
<script type="text/javascript">
|
||||
var ue = UE.getEditor('{$name}', {
|
||||
serverUrl : "{:url('/upload/ueditor')}"
|
||||
});
|
||||
</script>
|
||||
47
app/http/form/template/images.html
Normal file
47
app/http/form/template/images.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<div class="picker-box">
|
||||
<div id="picker_{$name}" class="picker_button">上传图片</div>
|
||||
{if isset($value) && $value}
|
||||
<input type="hidden" name="{$name}" id="field_{$name}" value="{$value}">
|
||||
{else/}
|
||||
<input type="hidden" name="{$name}" id="field_{$name}" value="">
|
||||
{/if}
|
||||
<div id="fileList_{$name}" class="upload-file-list-info" style="width:280px;">
|
||||
{if $value}
|
||||
{php}
|
||||
$images = get_cover($value);
|
||||
{/php}
|
||||
<li class="affix-list-item" id="WU_FILE_0">
|
||||
<div class="upload-file-info">
|
||||
<span class="webuploader-pick-file-close" data-queued-id="WU_FILE_0" data-id="{$value}" data-fileurl="{$images['path']}"><i class="close"></i></span>
|
||||
<span class="fname"></span>
|
||||
<span class="fsize">上传时间:{$images['create_time']}</span>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="filebox image">
|
||||
<img src="{:config('base_url')}{$images['path']}" class="img-responsive">
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
uploadsize = 2;
|
||||
$(function(){
|
||||
$("#picker_{$name}").SentUploader({
|
||||
compress:false,
|
||||
fileNumLimit:1,
|
||||
uploadEvents: {
|
||||
uploadComplete:function(file){}
|
||||
},
|
||||
listName : 'fileList_{$name}',
|
||||
hiddenName: 'field_{$name}',
|
||||
hiddenValType:1,
|
||||
fileSingleSizeLimit:uploadsize*1024*1024,
|
||||
closeX:true
|
||||
},
|
||||
{
|
||||
fileType: 'service',
|
||||
filename : 'images',
|
||||
});
|
||||
});
|
||||
</script>
|
||||
5
app/http/form/template/select.html
Normal file
5
app/http/form/template/select.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<select class="form-control" name="{$name}" id="{$name}" style="width:auto;">
|
||||
{volist name="option" id="item"}
|
||||
<option value="{$item['key']}" {if $item['key'] == $value}selected{/if}>{$item['label']}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
1
app/http/form/template/text.html
Normal file
1
app/http/form/template/text.html
Normal file
@@ -0,0 +1 @@
|
||||
<input type="text" class="form-control" name="{$name}" id="{$name}" autocomplete="false" value="{$value}">
|
||||
1
app/http/form/template/textarea.html
Normal file
1
app/http/form/template/textarea.html
Normal file
@@ -0,0 +1 @@
|
||||
<textarea class="form-control" name="{$name}" id="{$name}">{$value}</textarea>
|
||||
Reference in New Issue
Block a user