ajun 5 лет назад
Родитель
Сommit
a01cf5ed1e

+ 1 - 1
app/Demand.php

@@ -63,7 +63,7 @@ class Demand extends Model
      */
     public function saveFile($fileName,$fileSuffix)
     {
-        return UploadFile::query()->create(['table_name' => $this->getTable(), 'table_id' => $this['id'], 'url' => '/files/issue'.$fileName, 'type' => $fileSuffix]);
+        return UploadFile::query()->create(['table_name' => $this->getTable(), 'table_id' => $this['id'], 'url' => '/files/issue/'.$fileName, 'type' => $fileSuffix]);
     }
 
     /**

+ 25 - 4
app/Http/Controllers/DemandController.php

@@ -7,6 +7,7 @@ use App\Components\AsyncResponse;
 use App\Filters\DemandFilters;
 use App\Http\Requests\Demand\DemandRequest;
 use App\Services\DemandService;
+use App\UploadFile;
 use Illuminate\Http\Request;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Contracts\View\Factory;
@@ -60,9 +61,7 @@ class DemandController extends Controller
      */
     public function updateApi(DemandRequest $request)
     {
-        // 编辑权限
-        $this->gate('需求管理-问题-编辑');
-        $demand = Demand::query()->find($request['id'])->first();
+        $demand = Demand::query()->where('id',$request['id'])->first();
 
         if($demand['initiator'] != Auth::user()['id'])
             $this->error('非当前需求创建人不可修改');
@@ -82,7 +81,8 @@ class DemandController extends Controller
      */
     public function uploadFileApi(DemandRequest $request, DemandService $service)
     {
-        $demand = Demand::query()->find($request['id'])->first();
+        /** @var Demand $demand */
+        $demand = Demand::query()->where('id',$request['id'])->first();
 
         $service->saveUPLoadFile($demand, $request->file('file'));
 
@@ -91,6 +91,27 @@ class DemandController extends Controller
         $this->success($demand);
     }
 
+    /**
+     * @param DemandRequest $request
+     */
+    public function destroyFileApi(DemandRequest $request)
+    {
+        /** @var Demand $demand */
+        $demand = Demand::query()->where('id',$request['id'])->first();
+
+        /** @var UploadFile $uploadFile */
+        $uploadFile = $demand->uploadFile();
+
+        try {
+            $bool = $uploadFile->delete();
+            if($bool)$this->success();
+            $this->error('删除出现异常');
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
+
+    }
+
 
     /**
      * 删除需求

+ 21 - 6
app/Services/DemandService.php

@@ -6,6 +6,7 @@ use App\Traits\ServiceAppAop;
 use App\Demand;
 use Illuminate\Http\UploadedFile;
 use Illuminate\Support\Facades\Auth;
+use Intervention\Image\Facades\Image;
 use Ramsey\Uuid\Uuid;
 
 class DemandService
@@ -28,7 +29,7 @@ class DemandService
         if (!$file) return ['success' => false, 'message' => '上传图片不得为空'];
         if (!$file->isValid()) return ['success' => false, 'message' => '找不到上传图片'];
         if (!is_uploaded_file($tmpFile)) return ['success' => false, 'message' => '文件错误'];
-        if ($file->getSize() > 10 * 1024 * 1024) return ['success' => false, 'message' => '文件不能大于10MB'];
+        if ($file->getSize() > 5 * 1024 * 1024) return ['success' => false, 'message' => '文件不能大于10MB'];
         $fileSuffix = $file->getClientOriginalExtension();
 
         $dirPath = storage_path('app\public\files\issue');
@@ -36,13 +37,27 @@ class DemandService
             mkdir($dirPath);
         }
 
-        $fileName = date('ymd') . '-' . Uuid::uuid1(). '-issue.'.$fileSuffix ;
-        $filePath = storage_path('app\public\files\issue\\' . $fileName);
-        $result = move_uploaded_file($tmpFile, $filePath);
+        $fileName = date('ymd') . '-' . Uuid::uuid1();
 
-        if (!$result) return ['success' => false, 'message' => '文件上传失败'];
+        $thumbnailName = storage_path('app\public\files\issue\\' . $fileName . '-thumbnail.' . $fileSuffix);
+        $commonName = storage_path('app\public\files\issue\\' . $fileName . '-common.' . $fileSuffix);
+        $bulkyName = storage_path('app\public\files\issue\\' . $fileName . '-bulky.' . $fileSuffix);
+
+        $result = move_uploaded_file($tmpFile, $bulkyName);
+
+        if ($result == false) return ['success' => false, 'data' => '文件上传失败'];
+
+        $img = Image::make($bulkyName);
+
+        if ($img->height() > $img->width()) {
+            $img->heighten(250)->save($commonName);
+        } else {
+            $img->widen(250)->save($commonName);
+        }
+        $img->heighten(28)->save($thumbnailName);
 
         $upLoadFile = $demand->saveFile($fileName, $fileSuffix);
+
         if (!$upLoadFile) return ['success' => false, 'message' => '文件上传失败'];
 
         return ['success' => true, 'data' => $demand];
@@ -80,7 +95,7 @@ class DemandService
         if ($demand['status'] != 0)
             return ['success' => false, 'message' => '任务已被认领'];
 
-        $bool = $demand->update(['handler' => $handler,'status' => 1]);
+        $bool = $demand->update(['handler' => $handler, 'status' => 1]);
         if ($bool) {
             $demand->loadMissing('initiator', 'handle', 'uploadFile', 'processes');
             return ['success' => true, 'data' => $demand];

+ 43 - 24
resources/views/maintenance/demand/_table.blade.php

@@ -4,7 +4,7 @@
         <th rowspan="2">序号</th>
         <th rowspan="2">类型</th>
         <th rowspan="2">需求描述</th>
-        <th colspan="3" rowspan="1">过程</th>
+        <th rowspan="1">过程</th>
         <th rowspan="2">附件</th>
         <th rowspan="2">发起人</th>
         <th rowspan="2">处理人</th>
@@ -12,10 +12,16 @@
         <th rowspan="2">状态</th>
         <th rowspan="2">操作</th>
     </tr>
-    <tr class="thead-light">
-        <th>说明</th>
-        <th>经手人</th>
-        <th>时间</th>
+    <tr >
+        <td class="p-0">
+            <table class="table m-0 p-0">
+                <td>说明</td>
+                <td>经手人</td>
+                <td>时间</td>
+            </table>
+        </td>
+{{--        <th>经手人</th>--}}
+{{--        <th>时间</th>--}}
     </tr>
     </thead>
     <tbody>
@@ -24,26 +30,39 @@
             :class="selectTr===i+1?'focusing' : ''">
             <td>@{{ i+1 }}</td>
             <td>@{{ demand.type }}</td>
-            <td>@{{ demand.description }}</td>
-            <template v-for="(process,index) in demand.processes">
-                <td>@{{ process.explain }}</td>
-                <td>@{{ process.processor ? process.processor.name : '' }}</td>
-                <td>@{{ process.created_at }}</td>
-            </template>
-            <template>
-                <td></td>
-                <td></td>
-                <td></td>
-            </template>
+            <td class="">
+                <textarea class="form-control" rows="2" cols="15" :value="demand.description" @change="updateDemand(demand,'description',$event)"></textarea>
+            </td>
+            <td class="text-left" @mouseenter="alert(demand.showAddDiv) " @mouseleave="demand.showAddDiv = false">
+                <button class="btn btn-primary position-absolute" v-if="demand['showAddDiv']" style="margin-top: -40px;" @click="toggleAddDiv('addDiv_'+i)">新</button>
+                <div>
+                    <div :id="'addDiv_'+i" class="form-inline float-right">
+                        <label for="">
+                            <input type="text" class="form-control col-10" @keydown.enter="addProcees(demand,$event)">
+                            <button class="btn btn-sm btn-primary ml-1">添加</button>
+                        </label>
+                    </div>
+                    <template v-if="demand['processes'].length > 0 ">
+                        <table>
+                            <template v-for="(process,process_i) in demand['processes']">
+                                <tr  class="text-center" @mouseenter="process['status'] = true" @mouseleave="process['status'] = false">
+                                    <td>@{{ process.explain }}</td>
+                                    <td>@{{ process.processor ? process.processor.name : '' }}</td>
+                                    <td>@{{ process.created_at }}</td>
+                                    <td>
+                                        <button type="button" v-show="process['status']" @click="deleteProccess(demand,process_i)" class="btn btn-sm btn-outline-danger">删</button>
+                                    </td>
+                                </tr>
+                            </template>
+                        </table>
+                    </template>
+                </div>
+            </td>
             <td>
-                {{-- 附件 --}}
-                <template v-if="demand.uploadFile">
-                    附件
-                </template>
-                <template v-else>
-                    <button type="button" class="btn btn-outline-secondary" @click="showUploadDiv(demand,i)">上传文件
-                    </button>
-                </template>
+                <div class="text-center" @mouseleave="removeCommonImg('imgBulky_'+demand.id)" @mouseenter="commonImg('img_'+demand.id,demand,i)">
+                    <img v-if="demand['upload_file']" :id="'img_'+demand.id" :data-src="demand['upload_file']['url']" src="{{url('icon/img404-thumbnail.jpg')}}" alt="">
+                    <button v-else type="button" class="btn btn-outline-secondary" @click="showUploadDiv(demand,i)">上传文件</button>
+                </div>
             </td>
             <td>@{{ demand.initiator ? demand.initiator.name : '' }}</td>
             <td>@{{ demand.handle ? demand.handle.name : '' }}</td>

+ 150 - 63
resources/views/maintenance/demand/index.blade.php

@@ -20,167 +20,254 @@
     <script src="{{mix('js/queryForm/queryForm.js')}}"></script>
 
     <script>
-        new Vue({
+        let demand_vue = new Vue({
             el: '#list',
             data: {
                 demands: {!! $demands->toJson() !!}['data'],
                 status: [
-                    {name: 0, value: '未处理'}, {name: 1, value: '处理中'} ,{name: 2, value: '已处理'},
+                    {name: 0, value: '未处理'}, {name: 1, value: '处理中'}, {name: 2, value: '已处理'},
                 ],
                 types: [
                     {name: 0, value: '需求'}, {name: 1, value: '问题'}
                 ],
                 selectTr: null,
-                uploadError:null,
-                selectDemand:null,
-                selectIndex:null,
+                uploadError: null,
+                selectDemand: null,
+                selectIndex: null,
+                imgs: '',
             },
             created() {
                 let that = this;
-                this.demands.forEach(function (item,index,self){
-                    self[index]['status'] = that.status[item['status']]['value'] ?? '';
-                    self[index]['type'] = that.types[item['type']]['value']  ?? '';
+                this.demands.forEach(function (item, index, self) {
+                    that.initDemand(self[index]);
                 });
             },
-            mounted(){
+            mounted() {
+                this.imgs = Array.from(document.getElementById('list').querySelectorAll('img'));
+                this.lazy();
+                if (this.imgs && this.imgs.length > 0) {
+                    window.addEventListener('scroll', this.lazy)
+                }
                 $('#list').removeClass('d-none');
                 let data = [
                     [
-                        {name:'created_at_start',type:'time',tip:'创建开始时间'},
-                        {name:'created_at_end',type:'time',tip:'创建结束时间'},
-                        {name:'type',type:'select',data:this.types,placeholder:'类型'},
+                        {name: 'created_at_start', type: 'time', tip: '创建开始时间'},
+                        {name: 'created_at_end', type: 'time', tip: '创建结束时间'},
+                        {name: 'type', type: 'select', data: this.types, placeholder: '类型'},
                     ]
                 ];
-                let form=new query({
-                    el:"#form_div",
-                    condition:data,
+                let form = new query({
+                    el: "#form_div",
+                    condition: data,
                 });
                 form.init();
             },
             methods: {
-                initDemand(demand){
+                initDemand(demand) {
                     demand['status'] = this.status[demand['status']]['value'] ?? '';
-                    demand['type'] = this.types[demand['type']]['value']  ?? '';
+                    demand['type'] = this.types[demand['type']]['value'] ?? '';
+                    demand.showAddDiv= false;
+                    if (demand['upload_file']) this.setImgUrl(demand['upload_file']);
+                    if(demand['processes']){
+                        demand['processes'].forEach(function(item,index,self){
+                            self[index]['status'] = false;
+                        });
+
+                    }
+                },
+                setImgUrl(uploadFile) {
+                    let url = '{{url('/storage/')}}';
+                    let urlPath = uploadFile['url'];
+                    let type = uploadFile.type;
+                    uploadFile['url'] = url + urlPath + '-thumbnail.' + type;
+                    uploadFile['bulkyUrl'] = url + urlPath + '-bulky.' + type;
+                    uploadFile['commonUrl'] = url + urlPath + '-thumbnail.' + type;
                 },
                 /** 完结需求 */
-                finishDemand(demand){
+                finishDemand(demand) {
                     let url = '{{url('apiLocal/demand/finish')}}';
                     window.tempTip.setDuration(3000);
-                    window.axios.post(url,{id:demand['id']}).then(res=>{
-                        if(res.data.success){
+                    window.axios.post(url, {id: demand['id']}).then(res => {
+                        if (res.data.success) {
                             window.tempTip.showSuccess('需求完结成功');
                             demand.status = '已处理'
-                            return ;
+                            return;
                         }
-                        window.tempTip.show('需求完结失败'+res.data.data);
-                    }).catch(err=>{
-                        window.tempTip.show('需求完结异常'+err);
+                        window.tempTip.show('需求完结失败' + res.data.data);
+                    }).catch(err => {
+                        window.tempTip.show('需求完结异常' + err);
                     });
                 },
                 /** 删除 */
-                destroyDemand(demand,index){
-                    if(!confirm('确定要删除当前需求吗?')){return ;}
+                destroyDemand(demand, index) {
+                    if (!confirm('确定要删除当前需求吗?')) {
+                        return;
+                    }
 
-                    let url = '{{url('apiLocal/demand/destroy?id=')}}'+demand['id'];
+                    let url = '{{url('apiLocal/demand/destroy?id=')}}' + demand['id'];
 
                     window.tempTip.setDuration(3000);
-                    window.axios.delete(url).then(res=>{
-                        if(res.data.success){
+                    window.axios.delete(url).then(res => {
+                        if (res.data.success) {
                             window.tempTip.showSuccess('删除成功!');
-                            this.$delete(this.demands,index);
-                            return ;
+                            this.$delete(this.demands, index);
+                            return;
                         }
                         window.tempTip.show(res.data.data);
-                    }).catch(err=>{
-                        window.tempTip.show('删除出现异常'+err);
+                    }).catch(err => {
+                        window.tempTip.show('删除出现异常' + err);
                     });
                 },
                 /** 添加处理过程 */
-                addProcess(demand,$e){
+                addProcess(demand, $e) {
                     let url = '{{url('apiLocal/demand/process/store')}}';
-                    let data = {'demand_id':demand['id'],'explain':$($e.target).val()};
+                    let data = {'demand_id': demand['id'], 'explain': $($e.target).val()};
 
                     window.tempTip.setDuration(3000);
-                    window.axios.post(url,data).then(res=>{
-                        if(res.data.success){
+                    window.axios.post(url, data).then(res => {
+                        if (res.data.success) {
                             demand['processes'].unshfit(res.data.data);
                             this.$forceUpdate();
 
                             window.tempTip.showSuccess('添加处理过程成功')
-                            return ;
+                            return;
                         }
                         window.tempTip.show('添加处理过程失败')
-                    }).catch(err=>{
-                        window.tempTip.show('添加处理过程异常:'+err);
+                    }).catch(err => {
+                        window.tempTip.show('添加处理过程异常:' + err);
                     })
 
                 },
                 /** 文件上传 */
-                uploadFile(){
+                uploadFile() {
                     let fileInput = document.querySelector('#upLoadFile-input');
                     let url = '{{url('apiLocal/demand/uploadFile')}}';
 
                     let formData = new FormData();
-                    formData.append('id',this.selectDemand);
+                    formData.append('id', this.selectDemand);
                     let file = fileInput.files[0];
-                    formData.append('file',file);
+                    formData.append('file', file);
 
                     window.tempTip.setDuration(3000);
-                    window.axios.post(url,formData).then(res=>{
-                        if(res.data.success){
+                    window.tempTip.setIndex(1999);
+                    window.axios.post(url, formData, {
+                        'Content-Type': 'multipart/form-data'
+                    }).then(res => {
+                        if (res.data.success) {
                             this.initDemand(res.data.data);
-                            this.$set(this.demands,this.selectIndex,res.data.data);
+                            this.$set(this.demands, this.selectIndex, res.data.data);
                             $('#uploadFile').modal('hide');
                             window.tempTip.showSuccess('文件上传成功');
                             return;
                         }
                         window.tempTip.show('文件上传失败');
-                    }).catch(err=>{
-                        window.tempTip.show('文件上传异常:'+err);
+                    }).catch(err => {
+                        window.tempTip.show('文件上传异常:' + err);
                     });
                 },
                 /** 修改需求描述 */
-                updateDemand(demand,column,$e){
+                updateDemand(demand, column, $e) {
                     let url = '{{url('apiLocal/demand/update')}}';
-                    let data = {'id':demand['id']};
+                    let data = {'id': demand['id']};
                     let value = $($e.target).val();
                     data[column] = value;
 
                     window.tempTip.setDuration(3000);
-                    window.axios.post(url,data).then(res=>{
-                        if(res.data.success){
+                    window.axios.post(url, data).then(res => {
+                        if (res.data.success) {
                             demand[column] = value;
                             this.$forceUpdate();
                             window.tempTip.showSuccess('修改需求成功');
                             return;
                         }
                         window.tempTip.show(res.data.data);
-                    }).catch(err=>{
-                        window.tempTip.show('修改需求描述异常:'+err);
+                    }).catch(err => {
+                        window.tempTip.show('修改需求描述异常:' + err);
                     });
                 },
                 /** 问题认领 */
-                claimDemand(demand,index){
+                claimDemand(demand, index) {
                     console.log(demand);
                     let url = '{{url('apiLocal/demand/claim')}}';
                     window.tempTip.setDuration(3000);
-                    window.axios.post(url,{id:demand['id']}).then(res=>{
-                        if(res.data.success){
+                    window.axios.post(url, {id: demand['id']}).then(res => {
+                        if (res.data.success) {
                             this.initDemand(res.data.data);
-                            this.$set(this.demands,index,res.data.data);
+                            this.$set(this.demands, index, res.data.data);
                             window.tempTip.showSuccess('认领成功!');
-                            return ;
+                            return;
                         }
-                        if(res.data.errors)window.tempTip.show(res.data.errors);
+                        if (res.data.errors) window.tempTip.show(res.data.errors);
                         else window.tempTip.show(res.data.data);
-                    }).catch(err=>{
-                        window.tempTip.show('认领出现异常'+err);
+                    }).catch(err => {
+                        window.tempTip.show('认领出现异常' + err);
                     });
                 },
-                showUploadDiv(demand,index){
+                showUploadDiv(demand, index) {
                     this.selectDemand = demand['id'];
                     this.selectIndex = index;
                     $('#uploadFile').modal('show');
+                },
+
+                lazy() {
+                    //可视区域高度
+                    let height = window.innerHeight;
+                    //滚动区域高度
+                    let scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;
+                    let _this = this;
+                    this.imgs.forEach(function (img, i) {
+                        if ((height + scrollHeight) > $('#' + img.getAttribute('id')).offset().top && img.getAttribute('data-src')) {
+                            let temp = new Image();
+                            temp.src = img.getAttribute('data-src');
+                            temp.onload = function () {
+                                img.src = img.getAttribute('data-src');
+                                _this.$delete(_this.imgs, i);
+                            }
+                        }
+                    });
+                },
+                removeCommonImg(id) {
+                    $('#' + id).remove();
+                },
+                commonImg(id, demand,index) {
+                    if (!demand['upload_file']) return;
+                    let bulkyUrl = demand['upload_file']['bulkyUrl'];
+                    let commonUrl = demand['upload_file']['commonUrl'];
+                    $('#' + id).after(
+                        "<div id=\"imgBulky_" + demand['id'] + "\" style='position: absolute;padding-top: 2px;z-index: 99'>" +
+                        "<div style='position:absolute'>" +
+                            "<div >" +
+                            "<a target='_blank' href='" + bulkyUrl + "'>" +
+                                "<img src='" + commonUrl + "'" + "style='position: relative;left:-50px;' >" +
+                            "</a>" +
+                            "</div>" +
+                                "<button type='button' class='btn btn-sm btn-danger' onclick='demand_vue.btnDeleteImg(this,"+index+")' value='" + id + "' style='position: relative;float: right;margin-right: 51px;margin-top: -30px;' >删除</button>" +
+                        "</div>" +
+                        "</div>");
+                },
+                btnDeleteImg(e,index) {
+                    let idStr = $(e).val()
+                    let id = idStr.substr(idStr.indexOf('_') + 1)
+                    if (!confirm('确定要删除所选图片吗?')) return;
+                    this.destroyImg(id,index);
+                },
+                destroyImg(id,index) {
+                    let url = '{{url('apiLocal/demand/destroyFile/?id=')}}'+id;
+                    window.tempTip.setDuration(3000);
+                    window.axios.delete(url).then(res=>{
+                        if(res.data.success){
+                            window.tempTip.showSuccess('附件删除成功!');
+                            this.$delete(this.demands[index],['upload_file']);
+                            this.$forceUpdate();
+                            return ;
+                        }
+                        window.tempTip.show('附件删除异常:'+res.data.data);
+                    }).catch(err=>{
+                        window.tempTip.show(err);
+                    });
+                },
+                toggleAddDiv(id){
+
                 }
             }
         });

+ 1 - 0
routes/apiLocal.php

@@ -162,6 +162,7 @@ Route::group(['prefix'=>'demand'],function(){
     Route::post('update','DemandController@updateApi')->name('demand.updateApi');
     Route::post('uploadFile','DemandController@uploadFileApi')->name('demand.uploadFileApi');
     Route::delete('destroy','DemandController@destroyApi')->name('demand.destroyApi');
+    Route::delete('destroyFile','DemandController@destroyFileApi')->name('demand.destroyFileApi');
     Route::post('finish','DemandController@finishApi')->name('demand.finishApi');
     Route::post('claim','DemandController@claimApi')->name('demand.claimApi');
     Route::group(['prefix'=>'process'],function (){