Browse Source

将上传插件中加载慢的js文件改为本地加载,开发修改商品操作时加载图片的方法,修改删除图片时触发的回调方法,改为适用于创建和修改的删除回调方法

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
3ca69b16c2
  1. 20
      backend/logic/file/FileManager.php
  2. 38
      vendor/antgoods/goods/src/controllers/GoodsController.php
  3. 1
      vendor/antgoods/goods/src/logic/goods/GoodsManager.php
  4. 7
      vendor/antgoods/goods/src/views/goods/_form.php
  5. 2
      vendor/iron/assets/upload/js/jquery-file-upload.min.js
  6. 1
      vendor/iron/web/UploadAsset.php
  7. 1
      vendor/iron/widgets/Upload.php

20
backend/logic/file/FileManager.php

@ -26,28 +26,18 @@ class FileManager
/** /**
* @param $array * @param $array
* @param $value * @param $value
* @param int $key
* @return int * @return int
* 查看$extension数组中是否存在文件类型,不存在则返回-1 * 查看$extension数组中是否存在文件类型,不存在则返回-1
*/ */
public function searchType($array,$value, $key=-1){
foreach($array as $k=>$row){
if(!is_array($row)){
if($row == $value){
if($key != -1) {
public function searchType($array, $keyword, $key=-1){
foreach($array as $key => $value){
foreach ($value as $k => $v) {
if($v == $keyword){
return $key; return $key;
}else{
return -1;
}
}
}else{
$r = self::searchType($row,$value, $k);
if($r != -1){
return $r;
} }
} }
} }
return -1;
return false;
} }
/** /**

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

@ -104,6 +104,7 @@ class GoodsController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$model->imageId = $model->image;
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect('index'); return $this->redirect('index');
@ -183,7 +184,7 @@ class GoodsController extends Controller
$model->name = $file_name; $model->name = $file_name;
$file_manager = new \backend\logic\file\FileManager(); $file_manager = new \backend\logic\file\FileManager();
$type = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); $type = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']);
if ($type != -1) {
if ($type) {
$model->type = $type; $model->type = $type;
} }
$model->alias = $data['alias']; $model->alias = $data['alias'];
@ -200,18 +201,49 @@ class GoodsController extends Controller
public function actionImgIdDel() public function actionImgIdDel()
{ {
//判断该类是否存在 //判断该类是否存在
if(!class_exists('\common\models\ars\TemFile')){
if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){
return ''; return '';
} }
$alias = Yii::$app->request->get('data')['alias'];
$img_id = Yii::$app->request->get('imgid'); $img_id = Yii::$app->request->get('imgid');
$img_id_arr = explode(',', $img_id); $img_id_arr = explode(',', $img_id);
if(isset(Yii::$app->request->get('data')['alias'])) {
$alias = Yii::$app->request->get('data')['alias'];
$tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); $tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]);
if ($tem_file) { if ($tem_file) {
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); $img_id_arr = array_diff($img_id_arr, [$tem_file->id]);
} }
}else{
foreach (Yii::$app->request->get() as $key => $value) {
$tem_file = \common\models\ars\File::findOne(['alias' => $value]);
if ($tem_file) {
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]);
}
}
}
$img_id_str = implode(',', $img_id_arr); $img_id_str = implode(',', $img_id_arr);
return $img_id_str; return $img_id_str;
} }
public function actionImageFile()
{
//判断该类是否存在
if(!class_exists('\common\models\ars\File')){
return false;
}
$file_id_str = Yii::$app->request->get('fileidstr');
$file_id_arr = explode(',', $file_id_str);
$data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all();
if($data) {
$res = array();
$i = 0;
foreach ($data as $key => $value) {
$res[$i]['name'] = $value->alias;
$res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path;
$res[$i]['size'] = filesize($value->path);
}
}
return json_encode($res);
}
} }

1
vendor/antgoods/goods/src/logic/goods/GoodsManager.php

@ -15,6 +15,7 @@ class GoodsManager
*/ */
public function saveFile($fileIdStr, $goodsModel, $filetype = 1) public function saveFile($fileIdStr, $goodsModel, $filetype = 1)
{ {
//判断类名是否存在
if(!class_exists('\backend\logic\file\FileManager') || !class_exists('\common\models\ars\File')) { if(!class_exists('\backend\logic\file\FileManager') || !class_exists('\common\models\ars\File')) {
return false; return false;
} }

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

@ -68,7 +68,7 @@ use antgoods\goods\models\ars\Supplier;
<?= $form->field($model, 'express_template')->textInput() ?> <?= $form->field($model, 'express_template')->textInput() ?>
<?= $form->field($model, 'imageId')->hiddenInput()->label('') ?>
<?= $form->field($model, 'imageId')->textInput()->label('') ?>
<?= $form->field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [ <?= $form->field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [
'url' => 'upload', 'url' => 'upload',
'deleteUrl' => 'imageDel', 'deleteUrl' => 'imageDel',
@ -87,15 +87,20 @@ use antgoods\goods\models\ars\Supplier;
} }
", ",
'deleteScript' => " 'deleteScript' => "
console.log(data);
$.ajax({ $.ajax({
url: 'img-id-del', url: 'img-id-del',
data: {data: data, imgid: $('#goods-imageid').val()}, data: {data: data, imgid: $('#goods-imageid').val()},
success: function(data) success: function(data)
{ {
console.log(data);
$('#goods-imageid').val(data); $('#goods-imageid').val(data);
}, },
}); });
", ",
'previewConfig' => [
'url' => 'image-file?fileidstr='.$model->imageId,
],
])->label('图片') ?> ])->label('图片') ?>
<div class="form-group"> <div class="form-group">

2
vendor/iron/assets/upload/js/jquery-file-upload.min.js
File diff suppressed because it is too large
View File

1
vendor/iron/web/UploadAsset.php

@ -39,6 +39,7 @@ class UploadAsset extends AssetBundle {
]; ];
public $js = [ public $js = [
'js/jquery-file-upload.min.js', 'js/jquery-file-upload.min.js',
'js/jquery-form.js',
]; ];
public $depends = [ public $depends = [
'yii\web\JqueryAsset' 'yii\web\JqueryAsset'

1
vendor/iron/widgets/Upload.php

@ -224,6 +224,7 @@ class Upload extends InputWidget
} }
pd.statusbar.hide(); //You choice. pd.statusbar.hide(); //You choice.
}, },
}); });
SCRIPT; SCRIPT;
$view->registerJs($js); $view->registerJs($js);

Loading…
Cancel
Save