Browse Source

处理上传插件删除某张图片时,同时删除该图片的id,并且重新填入图片id输入框内

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
5e88a21821
  1. 18
      vendor/antgoods/goods/src/controllers/GoodsController.php
  2. 1
      vendor/antgoods/goods/src/models/ars/Goods.php
  3. 26
      vendor/antgoods/goods/src/views/goods/_form.php
  4. 12
      vendor/iron/widgets/Upload.php

18
vendor/antgoods/goods/src/controllers/GoodsController.php

@ -180,6 +180,24 @@ class GoodsController extends Controller
$model->alias = $data['alias']; $model->alias = $data['alias'];
$model->path = $data['path']; $model->path = $data['path'];
$model->save(); $model->save();
return $model->id;
} }
} }
/**
* @return string
* 点击删除按钮时同时删除字符串中的id
*/
public function actionImgIdDel()
{
$alias = Yii::$app->request->get('data')['alias'];
$imgid = Yii::$app->request->get('imgid');
$imgidarr = explode(',', $imgid);
$temfile = TemFile::findOne(['alias' => $alias]);
if ($temfile) {
$imgidarr = array_diff($imgidarr, [$temfile->id]);
}
$imgidstr = implode(',', $imgidarr);
return $imgidstr;
}
} }

1
vendor/antgoods/goods/src/models/ars/Goods.php

@ -44,6 +44,7 @@ use yii\behaviors\TimestampBehavior;
*/ */
class Goods extends \yii\db\ActiveRecord class Goods extends \yii\db\ActiveRecord
{ {
public $imagePath;
//是否删除is_delete //是否删除is_delete
const IS_DELETE_NO = 0;//未删除 const IS_DELETE_NO = 0;//未删除
const IS_DELETE_YES = 1;//已删除 const IS_DELETE_YES = 1;//已删除

26
vendor/antgoods/goods/src/views/goods/_form.php

@ -68,11 +68,33 @@ use antgoods\goods\models\ars\Supplier;
<?= $form->field($model, 'express_template')->textInput() ?> <?= $form->field($model, 'express_template')->textInput() ?>
<?= $form->field($model, 'image')->widget(\iron\widgets\Upload::className(), [
<?= $form->field($model, 'image')->textInput() ?>
<?= $form->field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [
'url' => 'upload', 'url' => 'upload',
'deleteUrl' => 'imageDel', 'deleteUrl' => 'imageDel',
'dragdropWidth'=> 800, 'dragdropWidth'=> 800,
'afterSave' => 'savefile'
'afterSave' => 'savefile',
'successScript' => "
success: function(data)
{
var imageval = $('#goods-image').val();
if(imageval == ''){
$('#goods-image').val(data);
}else{
$('#goods-image').val($('#goods-image').val()+','+data);
}
}
",
'deleteScript' => "
$.ajax({
url: 'img-id-del',
data: {data: data, imgid: $('#goods-image').val()},
success: function(data)
{
$('#goods-image').val(data);
},
});
",
]) ?> ]) ?>
<div class="form-group"> <div class="form-group">

12
vendor/iron/widgets/Upload.php

@ -96,6 +96,16 @@ class Upload extends InputWidget
* 拉拽框大小 * 拉拽框大小
*/ */
public $dragdropWidth; public $dragdropWidth;
/**
* @var javascript
* 图片上传成功回调方法
*/
public $successScript;
/**
* @var
* 删除图片触发方法
*/
public $deleteScript;
/** /**
* @throws NotFoundHttpException * @throws NotFoundHttpException
@ -164,6 +174,7 @@ class Upload extends InputWidget
url: "{$this->afterSave}", url: "{$this->afterSave}",
dataType: "json", dataType: "json",
data: {data: data, fileName: files}, data: {data: data, fileName: files},
{$this->successScript},
}); });
}, },
onLoad:function(obj) onLoad:function(obj)
@ -182,6 +193,7 @@ class Upload extends InputWidget
}); });
}, },
deleteCallback: function (data, pd) { deleteCallback: function (data, pd) {
{$this->deleteScript}
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
$.post("{$this->deleteUrl}", {op: "delete",name: data[i]}, $.post("{$this->deleteUrl}", {op: "delete",name: data[i]},
function (resp,textStatus, jqXHR) { function (resp,textStatus, jqXHR) {

Loading…
Cancel
Save