ajun 4 lat temu
rodzic
commit
193b5b2fa4

+ 2 - 2
app/Http/Controllers/PrintController.php

@@ -24,9 +24,9 @@ class PrintController extends Controller
         return ['success' => true,'data' => $result];
     }
 
-    public function uploadApi(Request $request)
+    public function uploadPrintDataApi(Request $request,PrintService  $service)
     {
-        dd($request->input());
+        return $service->processingPrintData($request['printData']);
     }
 
 

+ 4 - 0
app/PrintTemplate.php

@@ -11,4 +11,8 @@ class PrintTemplate extends Model
     use ModelLogChanging;
 
     protected $fillable = ['name','value'];
+
+    protected $casts = [
+        'value' => 'array'
+    ];
 }

+ 25 - 0
app/Services/PrintService.php

@@ -4,10 +4,14 @@ namespace App\Services;
 
 use App\OracleDocOrderDeliveryInfo;
 use App\OracleDOCOrderHeader;
+use App\PrintTemplate;
 use App\Traits\ModelSearchWay;
 use App\Traits\ServiceAppAop;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Storage;
+use Intervention\Image\Facades\Image;
 
 class PrintService
 {
@@ -87,4 +91,25 @@ class PrintService
         }
         return $data ?? [];
     }
+
+    public function processingPrintData(array $params)
+    {
+        foreach ($params as $param) {
+//            $owner_id = $param['owner_id'];
+//            $logistic_id = $param['logistic_id'];
+            $img_base64_code = $param['base64'];
+            $img =  Image::make($img_base64_code);
+            $printTemplate = PrintTemplate::query()->where('name','123')->first();
+            $img = $this->convertPrintImage($img,$printTemplate);
+            return $img->response("jpg");
+        }
+    }
+
+    public function convertPrintImage($image,$printTemplate,$order_package = null)
+    {
+        foreach ($printTemplate->value as $item) {
+
+        }
+        return $image;
+    }
 }

+ 45 - 25
resources/views/maintenance/expressPrinting/print/template.blade.php

@@ -14,17 +14,7 @@
                 <button @click="getPrintRequest">获取</button>
                 <button @click="pushGoPrintData">打印</button>
                 <button @click="resetGoWebsocket">recon</button>
-                <input type="file" id="uploadInput">
-{{--                <template v-for="image in printImage">--}}
-{{--                    <div class="print-div">--}}
-{{--                        <template v-if="image.type === 'image'">--}}
-{{--                            <img :src="image.uri" class="print-image">--}}
-{{--                        </template>--}}
-{{--                        <template v-else-if="image.type === 'pdf'">--}}
-{{--                            <embed :src="image.uri" type="application/pdf" width="100%" height="100%" class="print-pdf">--}}
-{{--                        </template>--}}
-{{--                    </div>--}}
-{{--                </template>--}}
+                <button @click="uploadPrintData">上传</button>
             </div>
             <div class="alert-success" v-if="goWebSocketStatus">
                 链接成功
@@ -35,6 +25,9 @@
             <div class="card-footer">
                 <canvas id="canvas-div" class="d-none"></canvas>
             </div>
+            <div>
+                <img src="" alt="" id="img">
+            </div>
         </div>
     </div>
 @endsection
@@ -47,9 +40,10 @@
             data: {
                 data: [],
                 goWebSocketPath: "ws://127.0.0.1:11101/msg",
-                goWebSocket:null,
-                goWebSocketStatus:false,
-                printData:[]
+                goWebSocket: null,
+                goWebSocketStatus: false,
+                printData: [],
+                uploadData:[]
             },
             created() {
 
@@ -58,22 +52,23 @@
                 this.getGoWebSocket();
             },
             methods: {
-                getGoWebSocket(){
-                    if(this.goWebSocket)return this.goWebSocket;
+                getGoWebSocket() {
+                    if (this.goWebSocket) return this.goWebSocket;
                     this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
+                    this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
                     return this.goWebSocket;
                 },
-                closeGoWebSocket(){
+                closeGoWebSocket() {
                     this.goWebSocket.close();
                 },
                 getPrintRequest() {
                     let self = this;
                     let url = '{{url('apiLocal/maintenance/print/getData')}}'
-                    window.axios.post(url).then(res => {
+                    window.axios.get(url).then(res => {
                         res.data.data.forEach(function (item) {
                             self.printData.push({
-                                type:"CAINIAO",
-                                data:JSON.stringify(self.getPreviewRequest(item,null))
+                                type: "CAINIAO",
+                                data: JSON.stringify(self.getPreviewRequest(item, null))
                             });
                         });
                         this.$forceUpdate();
@@ -82,14 +77,31 @@
                         console.log(err);
                     });
                 },
-                pushGoPrintData(){
+                pushGoPrintData() {
                     let self = this;
-                    this.printData.forEach(function(item){
-                        let json =  JSON.stringify(item);
+                    this.printData.forEach(function (item) {
+                        let json = JSON.stringify(item);
                         self.getGoWebSocket().send(json);
                     })
                 },
-                getPreviewRequest(item,taskId){
+                receiveGoWebSocketMessage(meg) {
+                    console.log("receiveGoWebSocketMessage");
+                    let params = JSON.parse(meg.data)
+                    if(params.success ==="false"){
+                        alert(params.message)
+                    }else if (params.success ==="true"){
+                        let imgBase64 = params.data;
+                        let base64String = "data:image/gif;base64," + imgBase64;
+                        document.getElementById("img").setAttribute("src",base64String)
+                        // js/base64图片 base64String
+                        this.uploadData.push({
+                            'base64':base64String
+                        })
+                        console.log(this.uploadData);
+                        this.$forceUpdate()
+                    }
+                },
+                getPreviewRequest(item, taskId) {
                     return {
                         cmd: "print",
                         requestID: "123458976",
@@ -114,8 +126,16 @@
                         }
                     };
                 },
-                resetGoWebsocket(){
+                resetGoWebsocket() {
                     this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
+                    this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
+                },
+                uploadPrintData(){
+                    let url = "{{url("apiLocal/maintenance/print/uploadPrintData")}}";
+                    let data = {printData:this.uploadData}
+                    window.axios.post(url,data).then(res=>{
+                    }).then(err=>{
+                    })
                 }
             }
         });

+ 2 - 2
routes/apiLocal.php

@@ -118,8 +118,8 @@ Route::group(['prefix'=>'maintenance'],function (){
         Route::post('getOwners','OwnerController@getOwners');
     });
     Route::group(['prefix' => 'print'],function(){
-        Route::post('getData','PrintController@getPrintDataApi');
-        Route::post('upload','PrintController@uploadApi');
+        Route::get('getData','PrintController@getPrintDataApi');
+        Route::post('uploadPrintData','PrintController@uploadPrintDataApi');
     });
     Route::group(['prefix'=>'expressPrinting'],function (){
         Route::group(['prefix'=>'part'],function(){