Commit 73749bb9 authored by ZhuChunYang's avatar ZhuChunYang

update

parent 79f8ca6d
......@@ -137,15 +137,18 @@ class ApplicationController extends BaseController
if(Yii::$app->request->isAjax){
$id = Yii::$app->request->get('id');
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$data = [];
$applicate = CoinApplication::getApplicate($id);
if($applicate){
$data = CoinImage::getItemsByImageIds($applicate->image_ids);
}else{
$data = ['code' => 0,'data' => []];
}
return $data;
}else{
$id = Yii::$app->request->get('id');
if($id){
$applicate = CoinApplication::getApplicate($id);
if($applicate){
$this->layout = false;
return $this->render('image-index',['applicate' => $applicate]);
}else{
$this->error('id参数不合法', Yii::$app->request->getReferrer());
......@@ -157,4 +160,31 @@ class ApplicationController extends BaseController
}
}
public function actionAddImage()
{
if(Yii::$app->request->isPost){
Yii::$app->response->format = 'json';
$id = Yii::$app->request->post('applicate_id',0);
$image_id = Yii::$app->request->post('image',0);
if($id && $image_id){
$coin_applicate_form = new CoinApplicationForm();
return $coin_applicate_form->addImage($id,$image_id);
}else{
return ['code' => 1,'msg'=> '图片添加失败'];
}
}
}
public function actionDeleteImage()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id');
$applicate_id = Yii::$app->request->get('applicate_id');
if ($id && $applicate_id) {
$coin_applicateion_form = new CoinApplicationForm();
return $coin_applicateion_form->delImage($id,$applicate_id);
}
return ['code' => 1, 'msg' => 'failed'];
}
}
\ No newline at end of file
......@@ -190,5 +190,45 @@ class CoinApplicationForm extends BaseForm
}
}
public function addImage($id,$image_id)
{
$coin_applicate = CoinApplication::getApplicate($id);
if($coin_applicate){
$image_ids = $coin_applicate->image_ids;
if($image_ids){
$image_items = explode(',',$image_ids);
array_push($image_items,$image_id);
$image_ids = implode(",",$image_items);
}else{
$image_ids = $image_id;
}
$coin_applicate->image_ids = $image_ids;
$coin_applicate->save();
return ['code' => 0,'msg' => '图片添加成功'];
}else{
return ['code' => 1,'msg' => '应用不存在'];
}
}
public function delImage($image_id,$id)
{
$coin_applicate = CoinApplication::getApplicate($id);
if($coin_applicate){
$image_ids = $coin_applicate->image_ids;
$image_items = explode(',',$image_ids);
$image_items = array_diff($image_items,[$image_id]);
if($image_items){
$image_ids = implode(",",$image_items);
}else{
$image_ids = '';
}
$coin_applicate->image_ids = $image_ids;
$coin_applicate->save();
return ['code' => 0,'msg' => '图片删除成功'];
}else{
return ['code' => 1,'msg' => '应用不存在'];
}
}
}
\ No newline at end of file
......@@ -5,3 +5,154 @@
* Date: 2018/10/17
* Time: 16:27
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<h4>所属应用---<?= $applicate->name ?></h4>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md1">
<button class="layui-btn layui-btn-default" id="add">添加应用图片</button>
</div>
</div>
<div class="layui-col-md10">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<div class="layui-row add" style="display: none;padding: 5px;" id="_form">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form" action="javascript:void(0)" id="form1" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input id="applicate_id" name="applicate_id" type="hidden" value="<?= $applicate->id ?>">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="image1">
</div>
<input type="hidden" name="image" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
</form>
</div>
</div>
<script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
var form = layui.form;
form.render();
var table = layui.table;
var applicate_id = $("#applicate_id").val();
table.render({
elem: '#table1',
url: '/admin/application/image-index?id='+applicate_id,
cols: [[
{
field: 'id',
title: '图片ID'
},
{
field: 'image_url',
title: '图片链接',
templet: function(d){
return "<a href='"+d.image_url+"' target='_blank'>"+d.image_url+"</a>";
}
},
{
title: '操作',
templet: '#operationTpl',
width: 300
},
]],
});
table.on('tool(table1)', function(obj) {
var data = obj.data;
var event = obj.event;
if (event === 'del') {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/application/delete-image', {id: data.id,applicate_id:applicate_id}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table1',{
page:{curr:1}
});
}
});
});
}
});
$('#add').click(function () {
var index = layer.open({
title: '添加图片',
area: '800px',
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
success: function() {
clearForm();
},
btn1: function() {
$.post('/admin/application/add-image', $("#form1").serialize(), function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
table.reload('table1', {
page: {
curr: 1
}
});
}
});
},
btn2: function() {
layer.close(index);
clearForm();
$("#_form").css('display', 'none');
},
cancel: function() {
layer.close(index);
clearForm();
$("#_form").css('display', 'none');
}
});
})
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf},
done: function (res) {
if(res.code == 0){
$("input[name='image']").val(res.data.image_id);
$("#image1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
function clearForm(){
form.val("form1", {
image: '',
});
$("#image1").attr('src', '');
}
</script>
\ No newline at end of file
......@@ -222,6 +222,4 @@
});
}
});
</script>
\ No newline at end of file
......@@ -38,4 +38,19 @@ class CoinImage extends BaseActiveRecord
return self::find()->where(['id' => $id])->asArray()->one();
}
public static function getItemsByImageIds($image_ids)
{
if($image_ids){
$idItems = explode(',',$image_ids);
$data = self::find()->where(['in','id',$idItems])->asArray()->all();
foreach ($data as &$value){
$value['image_url'] = $value['base_url'].$value['file_url'];
}
return ['code' => 0,'data' => $data];
}else{
return ['code' => 0,'data' => []];
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment