Przeglądaj źródła

Merge branch 'zzd' of ssh://was.baoshi56.com:10022/var/git/bswas

LD 5 lat temu
rodzic
commit
c9c49aa003

+ 15 - 4
app/Http/Controllers/WaybillController.php

@@ -33,6 +33,7 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Facades\Validator;
 use Intervention\Image\Facades\Image;
 use Ramsey\Uuid\Uuid;
@@ -529,19 +530,24 @@ class WaybillController extends Controller
     public function batchUploadImages()
     {
         $this->gate("运输管理-图片上传");
+        ini_set('max_execution_time',1000);
+        ini_set('memory_limit','100M');
         $images = request("images");
         $errors = [];
         $number = [];
         $mapping = [];
         $type = ["jpg","png","gif","jfif","pjpeg","jpeg","webp"];
         foreach ($images as $index => $image){
-            $suffix = $image->getClientOriginalExtension();
-            $name = $image->getClientOriginalName();
+            $arr = explode(".",$image["name"]);
+            $suffix = $arr[count($arr)-1];
+            unset($arr[count($arr)-1]);
+            $name = implode(".",$arr);
             if (array_search(strtolower($suffix),$type) === false){
                 $errors[] = "“".$name."”格式错误";
                 unset($images[$index]);
                 continue;
             }
+            $images[$index]["suffix"] = $suffix;
             $num = trim(rtrim($name,".".$suffix));
             $number[] = $num;
             $mapping[$num] = $index;
@@ -555,11 +561,16 @@ class WaybillController extends Controller
         foreach ($waybills as $waybill){
             $image = $images[$mapping[$waybill->source_bill]];
             $fileName = date('ymd').'-'.Uuid::uuid1();
-            $suffix = $image->getClientOriginalExtension();
+            $suffix = $image["suffix"];
+
             $thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$suffix);
             $commonName=storage_path('app/public/files/'.$fileName.'-common.'.$suffix);
             $bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$suffix);
-            move_uploaded_file ($image->getRealPath() ,$bulkyName);
+
+            preg_match('/^(data:\s*image\/(\w+);base64,)/',$image["src"],$res);
+            $base64_img=base64_decode(str_replace($res[1],'', $image["src"]));
+            Storage::put('public/files/'.$fileName.'-bulky.'.$suffix,$base64_img);
+
             $img=Image::make($bulkyName);
             if ($img->height() > $img->width())
                 $img->heighten(250)->save($commonName);

+ 1 - 1
app/UploadFile.php

@@ -11,6 +11,6 @@ class UploadFile extends Model
     use ModelLogChanging;
 
     protected $fillable=[
-        'table_name','table_id','url','type',"name"
+        'table_name','table_id','url','type',"file_name"
     ];
 }

+ 8 - 8
resources/views/waybill/_batchUploadImg.blade.php

@@ -24,21 +24,21 @@
                             </div>
                         </div>
                         <div class="col-3 border border-2 rounded" v-for="(img,i) in images">
-                            <div class="w-100 h4 m-1" style="height: 10%;">
-                                <span class="text-danger font-weight-bold pull-right" style="cursor: pointer;" @click="delTempImg(i)"> &times;</span>
+                            <div class="w-100 row m-1 h-25">
+                                <div class="text-center small col-9">
+                                    <span class="text-wrap">@{{ img.name }}(<span class="text-info">@{{ img.size | size }}</span>)</span>
+                                </div>
+                                <span class="col-3 h4 cursor-pointer text-danger font-weight-bold h-25" @click="delTempImg(i)"> &times;</span>
                             </div>
-                            <div class="w-100 m-0 text-center" style="height: 60%">
-                                <img class="img-fluid" :src="img.src" alt="img.name">
-                            </div>
-                            <div class="w-100 text-center small" style="height: 25%;margin-top: 5%">
-                                <span class="text-wrap">@{{ img.name }}(<span class="text-info">@{{ img.size | size }}</span>)</span>
+                            <div class="w-100 m-0 text-center h-50 overflow-hidden">
+                                <img class="img-fluid" :src="img.src" alt="img.name"/>
                             </div>
                         </div>
                     </div>
                 </div>
             </div>
             <div class="modal-footer">
-                <button class="btn btn-info text-white mr-1" @click="selectedFile()" v-if="images.length>1">
+                <button class="btn btn-info text-white mr-1" @click="selectedFile()" v-if="images.length>0">
                     <span class="fa fa-image"></span>
                     继续添加</button>
                 <button class="btn btn-success" @click="batchUploadImages()">开始上传</button>

+ 51 - 48
resources/views/waybill/index.blade.php

@@ -680,10 +680,10 @@
                                 if (waybill.waybill_number===waybill_number){
                                     waybill.url=response.data.data.url;
                                     waybill.suffix=response.data.data.type;
-                                    setTimeout(function () {
+                                    /*setTimeout(function () {
                                         _this.imgs.push(document.getElementById('img_'+waybill.id));
                                         _this.lazy();
-                                    },1);
+                                    },1);*/
                                     tempTip.setDuration(3000);
                                     tempTip.showSuccess("上传成功!");
                                     return true;
@@ -1003,9 +1003,33 @@
                 uploadFiles(event){
                     let images = event.target.files;
                     for(let i=0;i<images.length;i++){
-                        images[i]['src'] = window.URL.createObjectURL(images[i]);
-                        this.images.push(images[i]);
-                        this.size += images[i].size;
+                        let MAX_HEIGHT = 1000;
+                        let image = new Image();
+                        image.onload = ()=>{
+                            let canvas = document.createElement("canvas");
+                            if (image.height > MAX_HEIGHT && image.height >= image.width) {
+                                image.width *= MAX_HEIGHT / image.height;
+                                image.height = MAX_HEIGHT;
+                            }
+                            if (image.width > MAX_HEIGHT && image.width > image.height) {
+                                image.height *= MAX_HEIGHT / image.width;
+                                image.width = MAX_HEIGHT;
+                            }
+                            let ctx = canvas.getContext("2d");
+                            ctx.clearRect(0, 0, canvas.width, canvas.height);
+                            canvas.width = image.width;
+                            canvas.height = image.height;
+                            ctx.drawImage(image, 0, 0, image.width, image.height);
+                            let src = canvas.toDataURL("image/jpeg");
+                            let size = src.length;
+                            this.images.push({
+                                src :  src,
+                                name : images[i]["name"],
+                                size : size,
+                            });
+                            this.size += size;
+                        };
+                        image.src = window.URL.createObjectURL(images[i]);
                     }
                 },
                 //删除图片
@@ -1019,52 +1043,31 @@
                         window.tempTip.show("未选择图片");
                         return;
                     }
-                    if (this.size > 10485760){
-                        window.tempTip.show("上传图片超出10MB,请分开上传");
+                    if (this.size > 104857600){
+                        window.tempTip.show("上传图片超出100MB,请分开上传");
                         return;
                     }
-                    let formData = new FormData();
-                    this.images.forEach(image=>{
-                        formData.append("images[]",image);
-                    });
-                    window.tempTip.setIndex(1099);
-                    window.tempTip.setDuration(9999);
-                    window.tempTip.waitingTip("上传中,请稍等......");
-                    window.axios.post('{{url('waybill/batchUploadImages')}}',formData,{
-                        'Content-Type':'multipart/form-data'
-                    }).then(res=>{
-                        if (res.data.success){
-                            let result = res.data.data.data;
-                            let errors = res.data.data.errors;
-                            if (errors.length>0)this.batchUploadError =  errors;
-                            result.forEach(r=>{
-                                this.waybills.some(waybill=> {
-                                    if (waybill.id==r.id){
-                                        waybill.url="/storage"+r.upload_file.url;
-                                        waybill.suffix=r.upload_file.type;
-                                        setTimeout(()=> {
-                                            this.imgs.push(document.getElementById('img_'+waybill.id));
-                                            this.lazy();
-                                        },1);
-                                        return true;
-                                    }
-                                });
-                                this.size = 0;
+                    window.tempTip.postBasicRequest('{{url('waybill/batchUploadImages')}}',{images:this.images},res=>{
+                        let result = res.data;
+                        let errors = res.errors;
+                        if (errors.length>0)this.batchUploadError =  errors;
+                        result.forEach(r=>{
+                            this.waybills.some(waybill=> {
+                                if (waybill.id==r.id){
+                                    waybill.url="/storage"+r.upload_file.url;
+                                    waybill.suffix=r.upload_file.type;
+                                    /*setTimeout(()=> {
+                                        this.imgs.push(document.getElementById('img_'+waybill.id));
+                                        this.lazy();
+                                    },1);*/
+                                    return true;
+                                }
                             });
-                            this.$forceUpdate();
-                            window.tempTip.cancelWaitingTip();
-                            window.tempTip.setDuration(2000);
-                            window.tempTip.showSuccess("上传成功!");
-                            return;
-                        }
-                        window.tempTip.cancelWaitingTip();
-                        window.tempTip.setDuration(3000);
-                        window.tempTip.show(res.data.data);
-                    }).catch(err=>{
-                        window.tempTip.cancelWaitingTip();
-                        window.tempTip.setDuration(3000);
-                        window.tempTip.show('网络错误:'+err);
-                    });
+                            this.size = 0;
+                        });
+                        this.$forceUpdate();
+                        return "上传成功";
+                    },true);
                 },
             },
             filters:{