附件支持多站点

pull/41/head
devlike 2018-02-09 23:47:54 +08:00
parent 3c6c284bd5
commit 2808709fd3
10 changed files with 66 additions and 35 deletions

View File

@ -38,6 +38,7 @@ class Attachment extends Backend
$list = $this->model $list = $this->model
->where($where) ->where($where)
->with('sites')
->order($sort, $order) ->order($sort, $order)
->limit($offset, $limit) ->limit($offset, $limit)
->select(); ->select();
@ -52,6 +53,7 @@ class Attachment extends Backend
return json($result); return json($result);
} }
$this->assignconfig('show_sitename', $this->auth->isSuperAdmin());
return $this->view->fetch(); return $this->view->fetch();
} }
@ -64,6 +66,8 @@ class Attachment extends Backend
{ {
return $this->index(); return $this->index();
} }
$siteId = $this->request->param("site_id");
$this->assignconfig('site_id',$siteId);
return $this->view->fetch(); return $this->view->fetch();
} }

View File

@ -218,6 +218,7 @@ class Sites extends Backend
$row['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom,true) : null; $row['custom'] = !empty($row->config->custom) ? json_decode($row->config->custom,true) : null;
$this->view->assign("row", $row); $this->view->assign("row", $row);
$this->view->assign('editstyle', $this->auth->isSuperAdmin()?'1':'0'); $this->view->assign('editstyle', $this->auth->isSuperAdmin()?'1':'0');
$this->assignconfig('site_id',$row->id);
$this->view->assign('multilanguage', Seven::build_langs('row[lang]', $row['lang'], ['type'=>'checkbox'])); $this->view->assign('multilanguage', Seven::build_langs('row[lang]', $row['lang'], ['type'=>'checkbox']));
return $this->view->fetch(); return $this->view->fetch();
} }

View File

@ -0,0 +1,9 @@
<?php
namespace app\admin\model;
class SitesConfig extends \app\common\model\SitesConfig
{
}

View File

@ -22,6 +22,11 @@ class Attachment extends Model
} }
} }
public function sites()
{
return $this->belongsTo('Sites', 'site_id','id')->field('id,name');
}
public function setUploadtimeAttr($value) public function setUploadtimeAttr($value)
{ {
return strtotime($value); return strtotime($value);

View File

@ -16,9 +16,15 @@ class TakeAttach
if ($params instanceof \think\Model) { if ($params instanceof \think\Model) {
if(\think\Session::has('user_site_id')) { if(\think\Session::has('user_site_id')) {
$params->site_id = \think\Session::get('user_site_id'); $params->site_id = \think\Session::get('user_site_id');
$params->canDelete = 1;
$params->save(); $params->save();
return; return;
} }
if(request()->param('siteid')) {
$params->site_id = request()->param('siteid');
$params->canDelete = 1;
$params->save();
}
} }
//del //del
elseif ($params instanceof \think\Controller) { elseif ($params instanceof \think\Controller) {

View File

@ -24,9 +24,14 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
[ [
{field: 'state', checkbox: true, }, {field: 'state', checkbox: true, },
{field: 'id', title: __('Id')}, {field: 'id', title: __('Id')},
{field: 'site_id', title: __('Site_id'), visible:Config.show_sitename,
formatter: function (value, row, index) {
return row.sites==null?'':'<a href="javascript:;" class="searchit" data-field="site_id" data-value="' + row.site_id + '">' + row.sites.name + '</a>';
}
},
{field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb}, {field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb},
{field: 'url', title: __('Url'), formatter: function(value,row,index){ {field: 'url', title: __('Url'), formatter: function(value,row,index){
return '<a href="' + value + '" title="'+value+'" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a>'; return '<a href="' + Fast.api.cdnurl(value) + '" title="'+Fast.api.cdnurl(value)+'" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a>';
}}, }},
{field: 'imagewidth', title: __('Imagewidth')}, {field: 'imagewidth', title: __('Imagewidth')},
{field: 'imageheight', title: __('Imageheight')}, {field: 'imageheight', title: __('Imageheight')},
@ -57,6 +62,17 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefin
// 初始化表格 // 初始化表格
table.bootstrapTable({ table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url, url: $.fn.bootstrapTable.defaults.extend.index_url,
queryParams:function (params) {
if(Config.site_id!=null){
return {
sort: params.sort,
order: params.order,
filter: JSON.stringify({site_id: Config.site_id}),
op: JSON.stringify({site_id: '='}),
offset: params.offset,
limit: params.limit,
};}
},
sortName: 'id', sortName: 'id',
columns: [ columns: [
[ [

View File

@ -189,22 +189,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
$(document).on("change", "select[name='row[site_id]']", function () { $(document).on("change", "select[name='row[site_id]']", function () {
siteid=$(this).val(); siteid=$(this).val();
/* $('.plupload').data("siteid", siteid);
$("#c-channel_id option:selected").prop("selected", false); $('.fachoose').data("siteid", siteid);
$("#c-channel_id option").addClass("hide");
$("#c-channel_id option[data-siteid='" + $(that).val() + "']").removeClass("hide");
try{
$("#c-channel_id").selectpicker("refresh");
}catch(e){}
$('#c-channel_id').trigger('change');
Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": $(that).val()}}, function (data) {
$("#language_choose").html(data.html);
Form.api.bindevent($("#language_choose"));
return false;
});
*/
$pid = $('#c-channel_id'); $pid = $('#c-channel_id');
@ -212,7 +198,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
if(ret.code=="1"){ if(ret.code=="1"){
$pid.empty(); $pid.empty();
$.each(ret.data.list, function(i,k){ $.each(ret.data.list, function(i,k){
$pid.append("<option value='" + ret.data.list[i].id + "' "+(ret.data.list[i].disabled==1?'disabled':'')+">"+ ret.data.list[i].name + "</option>"); $pid.append("<option data-model='"+ret.data.list[i].model+"' value='" + ret.data.list[i].id + "' "+(ret.data.list[i].disabled==1?'disabled':'')+">"+ ret.data.list[i].name + "</option>");
}); });
$pid.selectpicker("refresh"); $pid.selectpicker("refresh");
$pid.trigger('change'); $pid.trigger('change');
@ -222,18 +208,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
return false; return false;
}); });
/*
var ml = $('option:selected', this).data('lang');
if(ml==undefined) {
$('input[name="row[lang]"]').prop('disabled', false).closest('label').show();
return false;
}
$('input[name="row[lang]"]').prop('disabled', true).closest('label').hide();
$.each(ml.split(','), function(key,value){
$('input[name="row[lang]"][value="'+value+'"]').prop('disabled', false).closest('label').show();
});
*/
}); });
$(document).on("change", "select[name='row[channel_id]']", function () { $(document).on("change", "select[name='row[channel_id]']", function () {
@ -242,15 +216,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
Fast.api.ajax({url: 'posts/archives/get_model_fields', data: {model: model}}, function (data) { Fast.api.ajax({url: 'posts/archives/get_model_fields', data: {model: model}}, function (data) {
$("#extra").html(data.html); $("#extra").html(data.html);
Form.api.bindevent($("#extra")); Form.api.bindevent($("#extra"));
$('#extra .plupload').data("siteid", $("select[name='row[site_id]']").val());
$('#extra .fachoose').data("siteid", $("select[name='row[site_id]']").val());
return false; return false;
}); });
} }
$('input[name="row[type]"]').val(model); $('input[name="row[type]"]').val(model);
}); });
Controller.edit(); //$("select[name='row[site_id]']").trigger('change');
//if($('#c-site_id').size()>0) $('#c-site_id').trigger('change'); $('.plupload').data("siteid", $("select[name='row[site_id]']").val());
$('.fachoose').data("siteid", $("select[name='row[site_id]']").val());
$("select[name='row[channel_id]']").trigger('change'); $("select[name='row[channel_id]']").trigger('change');
Controller.edit();
}, },
edit: function () { edit: function () {
$("form").data("validator-options", {ignore: ':hidden'}); $("form").data("validator-options", {ignore: ':hidden'});
@ -285,7 +264,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
appendHtml += '<span><button type="button" id="fachoose-' + objID + '" class="btn btn-primary fachoose" data-input-id="pa-' + objID + '" data-attach-id="pa-' + objID + 'i' + '" data-title-id="pa-' + objID + 't'+ '" data-mimetype="*/*" data-multiple="false"><i class="fa fa-list"></i> ' + __('Choose') + '</button></span> '; appendHtml += '<span><button type="button" id="fachoose-' + objID + '" class="btn btn-primary fachoose" data-input-id="pa-' + objID + '" data-attach-id="pa-' + objID + 'i' + '" data-title-id="pa-' + objID + 't'+ '" data-mimetype="*/*" data-multiple="false"><i class="fa fa-list"></i> ' + __('Choose') + '</button></span> ';
appendHtml += '<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span></dd>'; appendHtml += '<span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span></dd>';
$(appendHtml).insertBefore($(this).parent()); $(appendHtml).insertBefore($(this).parent());
Controller.api.bindevent(); Form.api.bindevent($(this).closest("dl"));
}); });
$(document).on("click", ".fieldlist dd .btn-remove", function () { $(document).on("click", ".fieldlist dd .btn-remove", function () {
var rel = parseInt($(this).closest("dl").attr("rel")); var rel = parseInt($(this).closest("dl").attr("rel"));

View File

@ -116,6 +116,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
$(document).on("change", "select[name='row[site_id]']", function () { $(document).on("change", "select[name='row[site_id]']", function () {
siteid=$(this).val(); siteid=$(this).val();
$('.plupload').data("siteid", siteid);
$('.fachoose').data("siteid", siteid);
//$("#c-pid option:first").prop("selected", true); //$("#c-pid option:first").prop("selected", true);
//$("#c-pid option").addClass("hide"); //$("#c-pid option").addClass("hide");
//$("#c-pid option[data-siteid='" + $(that).val() + "']").removeClass("hide"); //$("#c-pid option[data-siteid='" + $(that).val() + "']").removeClass("hide");
@ -147,6 +149,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
}); });
$("select[name='row[model]']").trigger("change"); $("select[name='row[model]']").trigger("change");
$("select[name='row[site_id]']").trigger("change");
$("input[name='row[type]']:checked").trigger("click"); $("input[name='row[type]']:checked").trigger("click");
Form.api.bindevent($("form[role=form]")); Form.api.bindevent($("form[role=form]"));

View File

@ -64,14 +64,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
api: { api: {
bindevent: function () { bindevent: function () {
$(document).on("change", "#c-site_id", function () { $(document).on("change", "#c-site_id", function () {
that=this; siteid=$(this).val();
Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": $(that).val()}}, function (r,data) { $('.plupload').data("siteid", siteid);
$('.fachoose').data("siteid", siteid);
Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": siteid}}, function (r,data) {
$("#language_choose").html(data.html); $("#language_choose").html(data.html);
Form.api.bindevent($("#language_choose")); Form.api.bindevent($("#language_choose"));
return false; return false;
}); });
}); });
$('.plupload').data("siteid", $("#c-site_id").val());
$('.fachoose').data("siteid", $("#c-site_id").val());
Form.api.bindevent($("form[role=form]")); Form.api.bindevent($("form[role=form]"));
} }
} }

View File

@ -91,6 +91,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
var random = $(this).closest('dd').data('index');// Math.floor(Math.random()*(10000-1+1)+1); 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>'); $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); Form.api.bindevent($tarDiv);
$('.plupload').data("siteid", Config.site_id);
$('.fachoose').data("siteid", Config.site_id);
break; break;
case "textarea": case "textarea":
$tarDiv.html('<textarea name="'+nodeName+'" class="form-control" cols="50"></textarea>') $tarDiv.html('<textarea name="'+nodeName+'" class="form-control" cols="50"></textarea>')