mirror of https://gitee.com/karson/fastadmin.git
站点配置->自定义参数可上传文件
parent
34cdae7a3c
commit
0dd970e7ff
|
|
@ -35,7 +35,7 @@ class Sites extends Backend
|
|||
{
|
||||
//从站点管理登录,进入自己的站点配置页
|
||||
if(Session::has("user_site_id")) {
|
||||
$this->redirect('posts/sites/config?addtabs=1');
|
||||
$this->redirect('posts/sites/edit?addtabs=1');
|
||||
}
|
||||
//超级管理员从总后台登录
|
||||
else {
|
||||
|
|
@ -70,88 +70,6 @@ class Sites extends Backend
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Config
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
$row = $this->model->get(Session::get("user_site_id"));
|
||||
|
||||
$settings = ['seo' => [
|
||||
'zh-cn' => [
|
||||
'title'=>'',
|
||||
'keywords'=>'',
|
||||
'description'=>''
|
||||
]
|
||||
], 'custom' => ''];
|
||||
|
||||
if($this->request->isPost()){
|
||||
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
foreach ($params as $k => $v) {
|
||||
if( in_array($k, ['name','domain','lang'])){
|
||||
if($k=='lang')
|
||||
$params[$k] = implode(',', $v);
|
||||
}else{
|
||||
unset($params[$k]);
|
||||
}
|
||||
}
|
||||
$seo = $this->request->post("seo/a");
|
||||
$custom = $this->request->post("custom/a");
|
||||
if ($seo) {
|
||||
$settings['seo'] = json_encode($seo, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if ($custom) {
|
||||
$arr = [];
|
||||
foreach ($custom as $k => $v) {
|
||||
$arr[$v['field']] = $v['value'];
|
||||
}
|
||||
$settings['custom'] = json_encode($arr, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if($row) $params['id'] = $row['id'];
|
||||
try
|
||||
{
|
||||
//是否采用模型验证
|
||||
if ($this->modelValidate)
|
||||
{
|
||||
$name = basename(str_replace('\\', '/', get_class($this->model)));
|
||||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
|
||||
$this->model->validate($validate);
|
||||
}
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
|
||||
if ($result !== false)
|
||||
{
|
||||
$this->model->config()->save($settings);
|
||||
$this->model->refreshRulesCache();
|
||||
$this->success();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
}
|
||||
catch (\think\exception\PDOException $e)
|
||||
{
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
|
||||
$this->view->assign('row', $row);
|
||||
|
||||
if($row) {
|
||||
$settings['seo'] = !empty($row->config->seo) ? json_decode($row->config->seo, true) : null;
|
||||
$settings['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom, true) : null;
|
||||
}
|
||||
$this->view->assign('settings', $settings);
|
||||
$this->view->assign('multilanguage', Seven::build_langs('row[lang]', $row?$row['lang']:'', ['type'=>'checkbox']));
|
||||
return $this->view->fetch();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add
|
||||
*/
|
||||
|
|
@ -222,13 +140,26 @@ class Sites extends Backend
|
|||
*/
|
||||
public function edit($ids = NULL)
|
||||
{
|
||||
if(!$this->auth->isSuperAdmin()) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
if(!$this->auth->isSuperAdmin()){
|
||||
$ids=Session::get("user_site_id");
|
||||
}
|
||||
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row)
|
||||
$this->error(__('No Results were found'));
|
||||
|
||||
$settings = ['seo' => [
|
||||
'zh-cn' => [
|
||||
'title'=>'',
|
||||
'keywords'=>'',
|
||||
'description'=>''
|
||||
]
|
||||
], 'custom' => [
|
||||
'logo' => '',
|
||||
'favicon' => '',
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
if ($this->request->isPost())
|
||||
{
|
||||
|
|
@ -252,6 +183,8 @@ class Sites extends Backend
|
|||
}
|
||||
$settings['custom'] = json_encode($arr, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
if(!$row) $row=$this->model;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -265,7 +198,7 @@ class Sites extends Backend
|
|||
$result = $row->allowField(true)->save($params);
|
||||
if ($result !== false)
|
||||
{
|
||||
$row->config()->save($settings);
|
||||
$row->config->save($settings);
|
||||
$this->model->refreshRulesCache();
|
||||
$this->success();
|
||||
}
|
||||
|
|
@ -281,10 +214,10 @@ class Sites extends Backend
|
|||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$arr['seo'] = !empty($row->config->seo) ? json_decode($row->config->seo,true) : null;
|
||||
$arr['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom,true) : null;
|
||||
$row['seo'] = !empty($row->config->seo) ? json_decode($row->config->seo,true) : null;
|
||||
$row['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom,true) : null;
|
||||
$this->view->assign("row", $row);
|
||||
$this->view->assign('settings', $arr);
|
||||
$this->view->assign('editstyle', $this->auth->isSuperAdmin()?'1':'0');
|
||||
$this->view->assign('multilanguage', Seven::build_langs('row[lang]', $row['lang'], ['type'=>'checkbox']));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,18 @@
|
|||
<style>
|
||||
.input-group .msg-box { left: 100%; }
|
||||
|
||||
.varlist dd { padding:5px 0;display:block;}
|
||||
.varlist .ctype{width:55px;padding:5px 3px;}
|
||||
.custom-val input,
|
||||
.custom-val textarea { width: 100% !important; }
|
||||
.custom-val input.upfile { width: 70% !important; }
|
||||
.panel-heading.panel-default{margin-bottom:5px;background:#efefef;}
|
||||
</style>
|
||||
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
|
||||
<div class="row">
|
||||
<div class="col-md-12 col-sm-12">
|
||||
<div class="panel panel-default panel-intro">
|
||||
{if $editstyle==1}
|
||||
<div class="panel-heading">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#basic" data-toggle="tab">基础信息</a></li>
|
||||
|
|
@ -9,17 +20,26 @@
|
|||
<li><a href="#custom" data-toggle="tab">自定义</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="panel-body">
|
||||
|
||||
<div id="myTabContent" class="tab-content">
|
||||
<div class="tab-pane fade active in" id="basic">
|
||||
{if $editstyle!=1}
|
||||
<div class="panel-heading panel-default">
|
||||
<h3 class="panel-title">{:__('Basic')}</h3>
|
||||
</div>
|
||||
{else /}
|
||||
<div class="form-group">
|
||||
<label for="c-user_id" class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input id="c-user_id" data-rule="required" data-source="auth/admin/selectpage" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id}">
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<input type="hidden" id="c-domain-old" value="{$row.domain}">
|
||||
<input type="hidden" id="c-url-old" value="">
|
||||
<div class="form-group">
|
||||
<label for="c-name" class="control-label col-xs-12 col-sm-2">{:__('name')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
|
@ -38,6 +58,7 @@
|
|||
{$multilanguage}
|
||||
</div>
|
||||
</div>
|
||||
{if $editstyle==1}
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
|
|
@ -49,31 +70,37 @@
|
|||
<div class="col-xs-12 col-sm-8">
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="adv">
|
||||
<div class="tab-pane fade {if $editstyle!=1}active in{/if}" id="adv">
|
||||
{if $editstyle!=1}
|
||||
<div class="panel-heading panel-default">
|
||||
<h3 class="panel-title">SEO配置</h3>
|
||||
</div>
|
||||
{/if}
|
||||
<div id="defaultLanguage">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<input class="form-control" id="c-s-title" type="text" name="seo[zh-cn][title]" value="{$settings['seo']['zh-cn']['title']}"></input>
|
||||
<input class="form-control" id="c-s-title" type="text" name="seo[zh-cn][title]" value="{$row['seo']['zh-cn']['title']}"></input>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Keywords')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<textarea class="form-control" id="c-s-keywords" name="seo[zh-cn][keywords]">{$settings['seo']['zh-cn']['keywords']}</textarea>
|
||||
<textarea class="form-control" id="c-s-keywords" name="seo[zh-cn][keywords]">{$row['seo']['zh-cn']['keywords']}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-xs-12 col-sm-2">{:__('Description')}:</label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<textarea class="form-control" id="c-s-description" name="seo[zh-cn][description]">{$settings['seo']['zh-cn']['description']}</textarea>
|
||||
<textarea class="form-control" id="c-s-description" name="seo[zh-cn][description]">{$row['seo']['zh-cn']['description']}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="extraLanguage">
|
||||
{foreach name="settings['seo']" item="lang" key="language"}
|
||||
{foreach name="row['seo']" item="lang" key="language"}
|
||||
{notin name="language" value="zh-cn"}
|
||||
<h2>{:__('Lang')} - {:config('site.multilanguages')[$language]}({$language})</h2>
|
||||
<div class="form-group">
|
||||
|
|
@ -99,21 +126,41 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="custom">
|
||||
<dl class="fieldlist" rel="">
|
||||
<dd>
|
||||
<ins>变量名</ins>
|
||||
<ins>变量值</ins>
|
||||
</dd>
|
||||
{foreach name="$settings['custom']" item="vo" key="key"}
|
||||
<dd class="form-inline" data-index="{$key}">
|
||||
<input type="text" name="custom[{$key}][field]" class="form-control" value="{$key}" size="20" />
|
||||
<input type="text" name="custom[{$key}][value]" class="form-control" value="{$vo}" size="50" />
|
||||
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
|
||||
</dd>
|
||||
{/foreach}
|
||||
<dd><a href="javascript:;" class="btn-append btn btn-sm btn-success"><i class="fa fa-plus"></i> {:__('Append')}</a></dd>
|
||||
</dl>
|
||||
<div class="tab-pane fade {if $editstyle!=1}active in{/if}" id="custom">
|
||||
{if $editstyle!=1}
|
||||
<div class="panel-heading panel-default">
|
||||
<h3 class="panel-title">自定义变量</h3>
|
||||
</div>
|
||||
{/if}
|
||||
<dl class=" varlist" rel="">
|
||||
<dd>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">变量名</div>
|
||||
<div class="col-sm-1">类型</div>
|
||||
<div class="col-sm-7">变量值</div>
|
||||
</div>
|
||||
</dd>
|
||||
{foreach name="$row['custom']" item="vo" key="key"}
|
||||
<dd class="form-inline" data-index="{$key}">
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<input type="text" name="custom[{$key}][field]" class="form-control" value="{$key}" size="10" />
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
</div>
|
||||
<div class="col-sm-7 custom-val">
|
||||
<input type="text" name="custom[{$key}][value]" class="form-control" value="{$vo}" />
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</dd>
|
||||
{/foreach}
|
||||
<dd>
|
||||
<a href="javascript:;" class="btn-append btn btn-sm btn-success"><i class="fa fa-plus"></i> {:__('Append')}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -121,7 +168,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group layer-footer">
|
||||
<div class="form-group {if $editstyle==1}layer-footer{else /}normal-footer" style="padding-top:10px;{/if}">
|
||||
<label class="control-label col-xs-12 col-sm-2"></label>
|
||||
<div class="col-xs-12 col-sm-8">
|
||||
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
|
||||
|
|
@ -151,4 +198,26 @@
|
|||
<textarea class="form-control" id="c-s-description" name="seo[<%=lang%>][description]"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script id="appendtpl" type="text/html">
|
||||
<dd class="form-inline" data-index="<%=key%>">
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
<input type="text" name="custom[<%=key%>][field]" class="form-control" value="" size="10" />
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<select class="form-control ctype">
|
||||
<option value="text">文本</option>
|
||||
<option value="textarea">多行文本</option>
|
||||
<option value="file">上传文件</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-7 custom-val">
|
||||
<input type="text" name="custom[<%=key%>][value]" class="form-control" value="" />
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</dd>
|
||||
</script>
|
||||
|
|
@ -31,7 +31,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|||
{field: 'lang', title: __('Lang'), operate:false},
|
||||
{field: 'status', title: __('Status'),searchList: {normal: __('Normal'), hidden: __('Hidden')}, formatter: Table.api.formatter.status},
|
||||
{field: 'createtime', title: __('Createtime'), operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"', formatter: Table.api.formatter.datetime},
|
||||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
|
||||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,formatter: Table.api.formatter.operate}
|
||||
]
|
||||
]
|
||||
});
|
||||
|
|
@ -43,14 +43,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|||
Controller.api.bindevent();
|
||||
},
|
||||
edit: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
config: function(){
|
||||
|
||||
$.validator.config({
|
||||
rules: {
|
||||
domain: function(ele){
|
||||
_value = $.trim(element.value.toString());
|
||||
_value = $.trim(ele.value.toString());
|
||||
if(_value==$('#c-domain-old').val()) return ;
|
||||
if (!_value.match(/^[A-Za-z0-9]+$/)) {
|
||||
return __('Please enter a valid URL');
|
||||
}
|
||||
|
|
@ -75,19 +73,44 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
api: {
|
||||
bindevent: function () {
|
||||
$(document).on("click", ".fieldlist .btn-append", function () {
|
||||
var rel = parseInt($(this).closest("dl").children('dd').length)-2;
|
||||
$(this).closest("dl").attr("rel", rel);
|
||||
$('<dd class="form-inline"><input type="text" name="custom['+ rel + '][field]" class="form-control" value="" size="20" /> <input type="text" name="custom[' + rel + '][value]" class="form-control" value="" size="50" /> <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span></dd>').insertBefore($(this).parent());
|
||||
$(document).on('change', '.ctype',function(){
|
||||
if($(this).val()=='') return false;
|
||||
$tarDiv = $(this).closest('.row').find('.custom-val');
|
||||
nodeName = $tarDiv.children(0).attr('name');
|
||||
switch($(this).val()){
|
||||
case "text":
|
||||
$tarDiv.html('<input type="text" name="'+nodeName+'" class="form-control">')
|
||||
break;
|
||||
case "file":
|
||||
|
||||
var random = $(this).closest('dd').data('index');// Math.floor(Math.random()*(10000-1+1)+1);
|
||||
$tarDiv.html('<input id="c-file-'+random+'" class="form-control upfile" name="'+nodeName+'" type="text" value=""><span><button type="button" id="plupload-f'+random+'" class="btn btn-danger plupload" data-input-id="c-file-'+random+'" data-mimetype="*/*" data-multiple="false"><i class="fa fa-upload"></i>' + __("Upload") + '</button></span><span><button type="button" id="fachoose-f'+random+'" class="btn btn-primary fachoose" data-input-id="c-file-'+random+'" data-mimetype="*/*" data-multiple="false"><i class="fa fa-list"></i>' + __("Choose") + '</button></span><ul class="row list-inline plupload-preview" id="p-image"></ul>');
|
||||
Form.api.bindevent($tarDiv);
|
||||
break;
|
||||
case "textarea":
|
||||
$tarDiv.html('<textarea name="'+nodeName+'" class="form-control" cols="50"></textarea>')
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
$(document).on("click", ".fieldlist dd .btn-remove", function () {
|
||||
var that=this;
|
||||
$(that).parent().remove();
|
||||
return;
|
||||
$(document).on("click", ".varlist .btn-append", function () {
|
||||
var rel = parseInt($(this).closest("dl").children('dd').length)-2;
|
||||
var html = Template('appendtpl', {key: rel});
|
||||
$tar=$(html).insertBefore($(this).parent());
|
||||
Form.api.bindevent($tar);
|
||||
});
|
||||
$(document).on("click", ".varlist dd .btn-remove", function (e) {
|
||||
e.preventDefault();
|
||||
$(this).closest(".form-inline").off();
|
||||
$(this).closest(".form-inline").remove();
|
||||
return false;
|
||||
});
|
||||
|
||||
$(document).on('click', 'input[name*="row[lang]"]', function(e){
|
||||
|
|
@ -108,6 +131,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
Form.api.bindevent($("form[role=form]"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue