浏览代码

Signed-off-by: sgq <sgq@sugangqiang>

sgq 2 年之前
父节点
当前提交
084143f1c0

+ 12 - 12
app/common/api/UploadApi.php

@@ -10,13 +10,13 @@ namespace app\common\api;
 class UploadApi {
 
     protected $fileSize = 5 * 1024 * 1024;
-    protected $fileExt = "jpg,png,gif,pdf";
-    protected $fileMime = "image/jpg,image/png,image/gif,application/pdf";
+    protected $fileExt = "jpg,png,gif,pdf,xls,xlsx";
+    protected $fileMime = "image/jpg,image/png,image/gif,application/pdf,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
 
     public function __construct($config = []) {
-        $this->fileSize = $config["maxSize"] ?: $this->fileSize;
-        $this->fileExt = $config["fileExt"] ?: $this->fileExt;
-        $this->fileMime = $config["fileMime"] ?: $this->fileMime;
+        $this->fileSize = isset($config["maxSize"]) ? $config["maxSize"] : $this->fileSize;
+        $this->fileExt = isset($config["fileExt"]) ? $config["fileExt"] : $this->fileExt;
+        $this->fileMime = isset($config["fileMime"]) ? $config["fileMime"] : $this->fileMime;
     }
 
     /**
@@ -24,13 +24,13 @@ class UploadApi {
      * @param type $files
      * @return type
      */
-    public function uploadList($files) {
+    public function uploadList($files, $path = "uploadfiles") {
         try {
-            validate(['image' => 'fileSize:' . $this->maxSize . '|fileExt:' . $this->fileExt . '|fileMime:' . $this->fileMime])
+            validate(['image' => ["sileSize" => $this->fileSize, "fileExt" => $this->fileExt, "fileMime" => $this->fileMime]])
                     ->check($files);
             $savename = [];
             foreach ($files as $file) {
-                $savename[] = \think\facade\Filesystem::disk("public")->putFile('topic', $file);
+                $savename[] = \think\facade\Filesystem::disk("public")->putFile($path, $file);
             }
             return $savename;
         } catch (\think\exception\ValidateException $e) {
@@ -43,11 +43,11 @@ class UploadApi {
      * @param type $file
      * @return type
      */
-    public function uploadOne($file) {
+    public function uploadOne($file, $path = "uploadfiles") {
         try {
-            validate(['image' => 'fileSize:' . $this->maxSize . '|fileExt:' . $this->fileExt . '|fileMime:' . $this->fileMime])
-                    ->check($file);
-            $savename = \think\facade\Filesystem::disk("public")->putFile('topic', $file);
+            validate(['image' => ["sileSize" => $this->fileSize, "fileExt" => $this->fileExt, "fileMime" => $this->fileMime]])
+                    ->check(["file" => $file]);
+            $savename = \think\facade\Filesystem::disk("public")->putFile($path, $file);
             return $savename;
         } catch (\think\exception\ValidateException $e) {
             echo $e->getMessage();

+ 7 - 0
app/enterprise/controller/Talent.php

@@ -26,4 +26,11 @@ class Talent extends EnterpriseController {
         return view("", ["year" => date("Y"), "enterprise" => $enterprise_info]);
     }
 
+    public function addTalentFile() {
+        $file = $this->request->file("fileUrl");
+        $upload = new \app\common\api\UploadApi();
+        $res = $upload->uploadOne($file);
+        var_dump($res);exit();
+    }
+
 }

+ 1 - 1
app/enterprise/view/talent/add.html

@@ -294,7 +294,7 @@
                                             </thead>
                                         </table>
                                         <label style="padding-top: 15px;color: red">*请根据上传的附件材料,编辑好相应的文件夹名称</label>
-                                        <form id="uploadForm" action="/api/talentInfo/addTalentFile" method="post" class="form-horizontal" enctype="multipart/form-data" target="hiddenIframe" style="display: none">
+                                        <form id="uploadForm" action="/enterprise/talent/addTalentFile" method="post" class="form-horizontal" enctype="multipart/form-data" target="hiddenIframe" style="display: none">
                                             <input type='hidden' id="fileId" name="fileId" >
                                             <input type='file' id="upload_file" name="fileUrl" style='display: none'>
                                             <input type='hidden' id="mainId" name="mainId" >

+ 4 - 4
public/static/modular/gate/talentInfo/talentInfo_info.js

@@ -565,8 +565,8 @@ TalentInfoInfoDlg.validId = function () {
 }
 //选择附件并显示附件名
 TalentInfoInfoDlg.checkFile = function (content, state, fileTypeId, fileId) {
-    if (!TalentInfoInfoDlg.validateIsEdit())
-        return;
+    //if (!TalentInfoInfoDlg.validateIsEdit())
+        //return;
     $("#upload_file ").unbind("change");
     $("#upload_file ").change(function () {
         TalentInfoInfoDlg.upload(fileTypeId, fileId);
@@ -577,12 +577,12 @@ TalentInfoInfoDlg.checkFile = function (content, state, fileTypeId, fileId) {
 //上传附件
 TalentInfoInfoDlg.upload = function (fileTypeId, fileId) {
     var id = $("#id").val();
-    if (id == null || id == '') {
+    /*if (id == null || id == '') {
         Feng.info("请先添加基本信息并保存后再试");
         return;
     }
     if (!TalentInfoInfoDlg.validateIsEdit())
-        return;
+        return;*/
     if (fileId != null && fileId != 'null') {
         $("#fileId").val(fileId)
     } else {