소스 검색

组件图片增加

ajun 4 년 전
부모
커밋
99454e8ff3

+ 4 - 2
app/Providers/AppServiceProvider.php

@@ -157,6 +157,7 @@ use App\Services\SFDeliveryService;
 use App\Services\JDDeliveryService;
 use App\Services\SFQHDDeliveryService;
 use App\Services\DeliveryService;
+use App\Services\PrintPartImageService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -239,8 +240,8 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('CustomerLogStatusService',CustomerLogStatusService::class);
         app()->singleton('CustomerService',CustomerService::class);
         app()->singleton('DataHandlerService',DataHandlerService::class);
-        app()->singleton('DeliveryService',DeliveryService::class);
         app()->singleton('DeliveryAppointmentService',DeliveryAppointmentService::class);
+        app()->singleton('DeliveryService',DeliveryService::class);
         app()->singleton('DemandProcessService',DemandProcessService::class);
         app()->singleton('DemandService',DemandService::class);
         app()->singleton('DepositoryService',DepositoryService::class);
@@ -314,6 +315,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('PDDDeliveryService',PDDDeliveryService::class);
         app()->singleton('PackageService', PackageService::class);
         app()->singleton('PackageStatisticsService', PackageStatisticsService::class);
+        app()->singleton('PrintPartImageService',PrintPartImageService::class);
         app()->singleton('PrintPartService',PrintPartService::class);
         app()->singleton('PrintService',PrintService::class);
         app()->singleton('PrintTemplateService',PrintTemplateService::class);
@@ -331,9 +333,9 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('RejectedBillService', RejectedBillService::class);
         app()->singleton('RejectedService', RejectedService::class);
         app()->singleton('RoleService',RoleService::class);
-        app()->singleton('SettlementBillsAreaFeeService',SettlementBillsAreaFeeService::class);
         app()->singleton('SFDeliveryService',SFDeliveryService::class);
         app()->singleton('SFQHDDeliveryService',SFQHDDeliveryService::class);
+        app()->singleton('SettlementBillsAreaFeeService',SettlementBillsAreaFeeService::class);
         app()->singleton('ShopService', ShopService::class);
         app()->singleton('StationCacheShelfGridService', StationCacheShelfGridService::class);
         app()->singleton('StationRuleBatchService', StationRuleBatchService::class);

+ 0 - 39
app/Services/PrintPartService.php

@@ -13,45 +13,6 @@ class PrintPartService
     use ServiceAppAop;
     protected $modelClass = PrintPart::class;
 
-    public function getImagePart()
-    {
-        $printPart = PrintPart::query()->firstOrCreate(['name' => "PrintPart-Image"],['value' => json_encode(array(), JSON_UNESCAPED_UNICODE)]);
 
-        $printPart['values'] = json_decode($printPart['value'], JSON_UNESCAPED_UNICODE);
-
-        return $printPart;
-    }
-
-    public function pushImagePart($file,$fileName): array
-    {
-        $tempFile = $file->getRealPath();
-        if (!$file->isValid()) return ['success' => false, 'message' => '未找到上传文件'];
-//        if (!is_uploaded_file($tempFile)) return ['success' => false, 'message' => '获取文件错误'];
-        if ($file->getSize() > 5 * 1024 * 1024) return ['success' => false, 'message' => '文件不能大于5MB'];
-
-        $printPart = $this->getImagePart();
-        $is_exists = false;
-        foreach ($printPart['values'] as $values){
-            if ($values['name'] == $fileName){
-                $is_exists = true;
-                break;
-            }
-        }
-        if ($is_exists) return ['success' => true ,'message' => '文件名重复'];
-
-        $fileSuffix = '.'.$file->getClientOriginalExtension();
-
-        $dirPath = storage_path('app\public\files\print');
-
-        if (!file_exists($dirPath)) {
-            mkdir($dirPath);
-        }
-        $filePath = storage_path('app\public\files\print\\' . $fileName.$fileSuffix);
-        $result = move_uploaded_file($tempFile,$filePath);
-        if (!$result) ['success' => false , 'message' => '图片保存异常'];
-        $values = ['name' => $fileName, 'value' => Storage::url("print/".$fileName.$fileSuffix)];
-        PrintPart::query()->where('id',$printPart['id'])->update(['value' => json_encode($values,JSON_UNESCAPED_UNICODE)]);
-        return ['success' => true , 'data' =>  $this->getImagePart()];
-    }
 
 }

+ 32 - 0
database/migrations/2021_06_28_154631_create_print_part_images_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreatePrintPartImagesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('print_part_images', function (Blueprint $table) {
+            $table->id();
+            $table->string('name')->unique();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('print_part_images');
+    }
+}

+ 34 - 0
resources/views/maintenance/expressPrinting/part/image/_create.blade.php

@@ -0,0 +1,34 @@
+<div class="modal " id="imageModal" tabindex="-1">
+    <div class="modal-dialog modal-lg modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title text-center" v-if="isCreated">图片编辑</h5>
+                <h5 class="modal-title text-center" v-else>图片编辑</h5>
+                <button type="button" class="close" data-dismiss="modal">
+                    <span>&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form class="form">
+                    <div class="form-group row">
+                        <label for="image-name" class="col-sm-3 col-form-label text-right">name</label>
+                        <div class="col-sm-9 form-inline">
+                            <input type="text" id="image-name" class="form-control col-9" v-model="editItem.name" placeholder="图片名"></input>
+                        </div>
+                    </div>
+
+                    <div class="form-group row">
+                        <label for="image-file" class="col-sm-3 col-form-label text-right">所属图片</label>
+                        <div class="col-sm-9 form-inline">
+                            <input type="file" id="image-file" class="form-control col-9" ref="image"></input>
+                        </div>
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
+                <button type="button" class="btn btn-primary" @click="save">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 24 - 0
resources/views/maintenance/expressPrinting/part/image/_table.blade.php

@@ -0,0 +1,24 @@
+<table class="table table-striped table-sm table-hover" id="table">
+    <thead>
+    <tr>
+        <td>序号</td>
+        <td>名称</td>
+        <td>图片</td>
+        <td>操作</td>
+    </tr>
+    </thead>
+    <tbody>
+    <tr v-for="(item,i) in  images" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
+        <td>@{{ i+1 }}</td>
+        <td></td>
+        <td></td>
+        <td></td>
+        <td></td>
+        <td>
+            <button class="btn btn-sm btn-primary" @click="edit(printer,i)">编辑</button>
+            <button class="btn btn-sm btn-danger " style="opacity: 0.9" @click="destroy(printer,i)">删除</button>
+        </td>
+    </tr>
+    </tbody>
+</table>
+{{ $printPartImages->links()}}

+ 92 - 0
resources/views/maintenance/expressPrinting/part/image/index.blade.php

@@ -0,0 +1,92 @@
+@extends("layouts.app")
+@section("title","图片")
+
+@section("content")
+    <div class="container-fluid d-noe" id="list">
+        <div class="card">
+
+            @include('maintenance.expressPrinting.print.image._create')
+            <div class="card-body">
+                <div class="row pull-left m-1">
+                    <button class="btn btn-outline-info mb-1 mr-3" @click="showCreatedModel"><span
+                            class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增
+                    </button>
+                </div>
+                @include('maintenance.expressPrinting.print.image._table')
+            </div>
+        </div>
+    </div>
+@endsection
+
+@section('lastScript')
+    <script>
+        let list = new Vue({
+            el:'list',
+            data:{
+                images:{!! $printPartImages->toJson() !!}['data'],
+                selectTr:null,
+                isCreated:null,
+                editItem:{},
+                index:null,
+            },
+            mounted(){
+                $("#list").removeClass("d-none");
+            },
+            methods:{
+                showCreatedModel(){
+                    this.isCreated = true;
+                    $("#imageModal").modal("show");
+                },
+                edit(){
+                    this.isCreated = false;
+                    $("#imageModal").modal("show");
+                },
+                save(){
+                    let url = '{{url("apiLocal/maintenance/expressPrinting/part/image/saveFile")}}';
+                    let data = new FormData();
+                    data.set("name",this.editItem.name);
+                    let file= this.$refs.image.files[0];
+                    data.set("file",file);
+                    if (!this.isCreated)  {
+                        url = '{{url("apiLocal/maintenance/expressPrinting/part/image/update")}}'
+                        data.set("id",this.);
+                    };
+
+                    window.tempTip.setIndex(2000);
+                    window.axios.post(url,data,{
+                        'Content-Type': 'multipart/form-data'
+                    }).then(res=>{
+                        if(res.data.success){
+                            window.tempTip.showSuccess("文件保存成功");
+                            if (this.isCreated){
+                                this.images.unshift(res.data.data);
+                            } else {
+                                this.$set(this.images,index,res.data.data);
+                            }
+                            this.$forceUpdate();
+                            $('#imageModal').modal('hide');
+                            return
+                        }
+                        window.tempTip.show(res.data.message);
+                    }).catch(err=>{
+                        window.tempTip.show(err)
+                    });
+                },
+                destroy(id,index){
+                    let url = '{{url("apiLocal/maintenance/expressPrinting/part/image/destroy")}}'+"?id"+id;
+                    window.axios.delete(url).then(res=>{
+                        if(res.data.success){
+                            window.tempTip.showSuccess("文件删除成功");
+                            this.$delete(this.images,index)
+                            this.$forceUpdate()
+                            return
+                        }
+                        window.tempTip.show(res.data.message);
+                    }).catch(err=>{
+                        window.tempTip.show(err)
+                    });
+                }
+            }
+        })
+    </script>
+@endsection

+ 6 - 0
routes/apiLocal.php

@@ -133,7 +133,13 @@ Route::group(['prefix'=>'maintenance'],function (){
             Route::post('printTemplate','PrintPartController@printTemplateApi');
             Route::get('imagePart','PrintPartController@getImagesPartApi');
             Route::post('pushImage','PrintPartController@pushImagesPartApi');
+            Route::group(['prefix'=>'image'],function(){
+                Route::post('saveFile','PrintPartImageController@saveFileApi');
+                Route::post('update','PrintPartImageController@updateFileApi');
+                Route::delete('{id}','PrintPartImageController@updateFileApi');
+            });
         });
+
         Route::group(['prefix'=>'template'],function(){
             Route::post('create','PrintTemplateController@storeApi');
             Route::post('destroy','PrintTemplateController@destroyApi');