瀏覽代碼

修改问题模块 图片上传和定位当前页面的权限

ajun 4 年之前
父節點
當前提交
51cf9c5139

+ 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/'.$fileName, 'type' => $fileSuffix]);
     }
 
     /**

+ 0 - 1
app/Http/Controllers/DemandController.php

@@ -32,7 +32,6 @@ class DemandController extends Controller
         if(!isset($user))return redirect('/');
 
         $demands = Demand::query()->with(['initiator', 'handle', 'uploadFile', 'processes.user'])->filter($filters)->orderByDesc('demands.id')->paginate($request['paginate'] ?? 50);
-
         return view('demand.search.index', compact('demands'));
     }
 

+ 2 - 0
app/Http/Controllers/TestController.php

@@ -53,6 +53,7 @@ use App\ProcurementDeliverie;
 use App\ProcurementQuotation;
 use App\ProcurementTotalBill;
 use App\RejectedBillItem;
+use App\Services\AuthorityService;
 use App\Services\BatchService;
 use App\Services\CacheService;
 use App\Services\CacheShelfService;
@@ -67,6 +68,7 @@ use App\Services\InventoryCompareService;
 use App\Services\LogisticService;
 use App\Services\LogisticZopService;
 use App\Services\LogService;
+use App\Services\MenuService;
 use App\Services\NewOrderCountingRecordService;
 use App\Services\OracleDocAsnHerderService;
 use App\Services\OracleDOCOrderHeaderService;

+ 11 - 4
app/Services/DemandService.php

@@ -32,16 +32,23 @@ class DemandService
         if ($file->getSize() > 5 * 1024 * 1024) return ['success' => false, 'message' => '文件不能大于5MB'];
         $fileSuffix = $file->getClientOriginalExtension();
 
-        $dirPath = storage_path('app\public\files\issue');
+        if (!in_array($fileSuffix,[ 'gif','image','jpeg','jpg','png','svg']))
+            return ['success' => false , 'message' => '文件格式应该为gif,image,jpeg,jpg,png,svg格式'];
+
+        $path = ['app','public','files'];
+
+        $path = join(DIRECTORY_SEPARATOR,$path);
+
+        $dirPath = storage_path($path);
         if (!file_exists($dirPath)) {
             mkdir($dirPath);
         }
 
         $fileName = date('ymd') . '-' . Uuid::uuid1();
 
-        $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);
+        $thumbnailName = storage_path('app/public/files/' . $fileName . '-thumbnail.' . $fileSuffix);
+        $commonName = storage_path('app/public/files/' . $fileName . '-common.' . $fileSuffix);
+        $bulkyName = storage_path('app/public/files/' . $fileName . '-bulky.' . $fileSuffix);
 
         $result = move_uploaded_file($tmpFile, $bulkyName);
 

+ 1 - 0
app/Services/MenuService.php

@@ -98,6 +98,7 @@ class MenuService
             foreach ($authorities as $j=>$authority){
                 if ($menu["name"] == $authority["name"]){
                     $mapping[$menu["id"]] = $authority["id"];
+                    $menus[$index]["authId"] = $authority["id"];
                     $mark = true;
                     $authorities[$j]["mark"] = true;
                     if ($authority["child"])$menus[$index]["child"] = array_values($this->formatMenu($menu["child"],$authority["child"],$mapping));

+ 3 - 2
resources/views/demand/_create.blade.php

@@ -34,10 +34,10 @@
                             <select name="add-demand-auth" id="add-demand-auth" class="form-control col-sm-7"
                                     v-model="addDemand.authority_id"
                                     :class="demandErrors.authority_id?'is-invalid':''"
-                                    @focus="demandErrors.authority_id!==null ? demandErrors.authority_id=null:''">
+                                    >
                                 <option v-for="(authority,index) in authoritiesFilter" :value="authority.id">@{{ authority.alias_name }}</option>
                             </select>
-                            <input type="text" class="form-control col-sm-3 ml-1" id="add-demand-auth-filter" @input="filterAuth($event)"
+                            <input type="text" class="form-control col-sm-3 ml-1" id="add-demand-auth-filter" v-model="filterAuthority"
                                    placeholder="输入权限进行删选">
                             <div class="invalid-feedback" v-if="demandErrors.authority_id">
                                 @{{ demandErrors.authority_id[0] }}
@@ -80,6 +80,7 @@
                         <label for="add-demand-file" class="col-sm-2 col-form-label text-right">上传文件</label>
                         <div class="col-sm-10 form-inline">
                             <input type="file" name="name" id="add-demand-file-create" class="form-control-file col-sm-10"
+                                   accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"
                                    placeholder="输入配置名称"
                                    :class="demandErrors.file?'is-invalid':''"
                                    @focus="demandErrors.file!==null ? demandErrors.file=null:''">

+ 20 - 21
resources/views/demand/_createjs.blade.php

@@ -4,9 +4,11 @@
         el: "#demand-div",
         data: {
             types: [{name:'0',value:'需求'},{name:'1',value:'问题'}],
-            addDemand: {},
             authorities: [],
-            authoritiesFilter: [],
+            addDemand: {
+                authority_id:null
+            },
+            filterAuthority: null,
             demandErrors: {},
             ratio:{
                 unClaimCount:null,
@@ -14,43 +16,40 @@
             }
         },
         created() {
-            this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
             this.getAuthority();
             this.setUnClaimDemandRatio();
             $('#demand-div').removeClass('d-none');
         },
         mounted() {
         },
-        methods: {
-            /** 筛选 */
-            filterAuth($e) {
-                let value = $($e.target).val();
+        computed: {
+            authoritiesFilter:function(){
                 let authorities = JSON.parse(JSON.stringify(this.authorities));
-                if (value === null) {
-                    this.authoritiesFilter = authorities;
-                    return;
+                if (!this.filterAuthority) {
+                    this.$set(this.addDemand,'authority_id',lastAuthority);
+                    return authorities;
                 }
-                this.authoritiesFilter = authorities.filter(function (item) {
-                    return item['name'].includes(value);
+                let self = this;
+                let authoritiesFilter = authorities.filter(function(item){
+                    return  item['name'].includes(self.filterAuthority);
                 });
-                if(this.authoritiesFilter.length > 0)
-                    this.addDemand.authority_id = this.authoritiesFilter[0]['id'];
+                if (authoritiesFilter.length >0 && authoritiesFilter.length < authorities.length){
+                    this.addDemand.authority_id =authoritiesFilter[0]['id']
+                }
+                this.$forceUpdate()
+                return authoritiesFilter;
             },
+        },
+        methods: {
             /** 创建 */
             showAddDemand() {
                 this.addDemand = {};
-                this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
                 $('#add-demand-auth-filter').val('');
                 $('#add-demand').modal('show')
-                if(this.authoritiesFilter.length === 0){
-                    if(this.authorities.length !==0)this.authoritiesFilter = JSON.parse(JSON.stringify(this.authorities));
-                    else this.getAuthority();
-                }
             },
             /** 创建 */
             createDemand() {
                 let url = '{{url('apiLocal/demand/store')}}';
-
                 window.tempTip.setIndex(1999);
                 window.tempTip.setDuration(3000);
 
@@ -80,7 +79,7 @@
                 window.axios.get(url).then(res=>{
                     if(res.data.success){
                         this.authorities = res.data.data;
-                        this.authoritiesFilter = res.data.data;
+                        this.filterAuthority = null;
                         this.$forceUpdate();
                     }
                 }).catch(err=>{

+ 3 - 0
resources/views/layouts/app.blade.php

@@ -44,6 +44,7 @@
     let baseUrl = "{{url('')}}";
     let currentUri = window.location.href.slice(baseUrl.length+1);
     let relativeUrl = currentUri.split(/[/?]/);
+    let lastAuthority;
     (function () {
         if ("{{\Illuminate\Support\Facades\Auth::id()}}")createMenu();
     }());
@@ -62,10 +63,12 @@
                     else continue;
                 }
                 dom.appendChild(createChildElement(type,menus[i],isEquals));
+                if (isEquals)lastAuthority = menus[i].authId;
                 if (isEquals && menus[i].child && menus[i].child.length>0)createMenu(type+1,menus[i].child);
             }
         });
     }
+
     function createBeforeMenu(type) {
         let dom = undefined;
         let ul = undefined;