소스 검색

修改图片上传

lchao 4 달 전
부모
커밋
00d5db6ae5

+ 17 - 8
qmjszx-admin/src/main/resources/templates/system/site/add.html

@@ -60,7 +60,7 @@
                 <div class="col-sm-8">
                     <input type="hidden" name="cover">
                     <div class="file-loading">
-                        <input class="form-control file-upload" id="cover" name="file" type="file" multiple>
+                        <input class="form-control file-upload" id="cover" name="file" type="file" >
                     </div>
                 </div>
             </div>
@@ -101,27 +101,36 @@
     $(".file-upload").fileinput({
         uploadUrl: ctx + 'common/upload',
         maxFileCount: 1,
-        allowedFileExtensions:['jpg','png'],
+        allowedFileExtensions: ['jpg', 'png'],
         maxFileSize: 10240,
         multiple: true,
     }).on('fileuploaded', function (event, data, previewId, index) {
         var inputName = event.currentTarget.id;
         var existingValue = $("input[name='" + inputName + "']").val();
-        var newValue = data.response.url;
+        var fullUrl = data.response.url; // 获取完整的URL
+        var urlObject = new URL(fullUrl);
+        var relativePath = urlObject.pathname; // 获取路径部分
+        // var newBaseUrl = "http://192.168.4.27"; // 新的基URL
+        var newBaseUrl = "http://localhost"; // 新的基URL
+        var absoluteUrl = newBaseUrl + relativePath; // 拼接完整的URL
 
         // 如果已经存在值,则在后面加上逗号分隔的新值
         if (existingValue) {
-            $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
+            $("input[name='" + inputName + "']").val(existingValue + ',' + absoluteUrl);
         } else {
-            $("input[name='" + inputName + "']").val(newValue);
+            $("input[name='" + inputName + "']").val(absoluteUrl);
         }
-    }).on('fileremoved', function (event, id, index) {
+    }).on('fileremoved', function (event, key, jqXHR, pd) {
         var inputName = event.currentTarget.id;
         var existingValue = $("input[name='" + inputName + "']").val();
         var fileUrls = existingValue.split(',');
 
-        // 移除对应的文件路径
-        fileUrls.splice(index, 1);
+        // 假设key是文件的key或者index,需要找到对应的URL并移除
+        // 这里假设key是文件的index
+        var index = key;
+        if (fileUrls[index]) {
+            fileUrls.splice(index, 1);
+        }
 
         // 重新拼接文件路径
         $("input[name='" + inputName + "']").val(fileUrls.join(','));

+ 9 - 4
qmjszx-admin/src/main/resources/templates/system/site/edit.html

@@ -112,7 +112,7 @@
         var initialPreview = val ? val.split(',') : [];
 
         $(this).fileinput({
-            'uploadUrl': ctx + 'common/upload',
+            uploadUrl: ctx + 'common/upload',
             initialPreviewAsData: true,
             initialPreview: initialPreview,
             maxFileCount: 1,
@@ -122,13 +122,18 @@
         }).on('fileuploaded', function (event, data, previewId, index) {
             var inputName = event.currentTarget.id;
             var existingValue = $("input[name='" + inputName + "']").val();
-            var newValue = data.response.url;
+            var fullUrl = data.response.url; // 获取完整的URL
+            var urlObject = new URL(fullUrl);
+            var relativePath = urlObject.pathname; // 获取路径部分
+            // var newBaseUrl = "http://192.168.4.27"; // 新的基URL
+            var newBaseUrl = "http://localhost"; // 新的基URL
+            var absoluteUrl = newBaseUrl + relativePath; // 拼接完整的URL
 
             // 如果已经存在值,则在后面加上逗号分隔的新值
             if (existingValue) {
-                $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
+                $("input[name='" + inputName + "']").val(existingValue + ',' + absoluteUrl);
             } else {
-                $("input[name='" + inputName + "']").val(newValue);
+                $("input[name='" + inputName + "']").val(absoluteUrl);
             }
         }).on('fileremoved', function (event, id, index) {
             var inputName = event.currentTarget.id;

+ 16 - 7
qmjszx-admin/src/main/resources/templates/system/venue/add.html

@@ -93,27 +93,36 @@
         $(".file-upload").fileinput({
             uploadUrl: ctx + 'common/upload',
             maxFileCount: 1,
-            allowedFileExtensions:['jpg','png'],
+            allowedFileExtensions: ['jpg', 'png'],
             maxFileSize: 10240,
             multiple: true,
         }).on('fileuploaded', function (event, data, previewId, index) {
             var inputName = event.currentTarget.id;
             var existingValue = $("input[name='" + inputName + "']").val();
-            var newValue = data.response.url;
+            var fullUrl = data.response.url; // 获取完整的URL
+            var urlObject = new URL(fullUrl);
+            var relativePath = urlObject.pathname; // 获取路径部分
+            // var newBaseUrl = "http://192.168.4.27"; // 新的基URL
+            var newBaseUrl = "http://localhost"; // 新的基URL
+            var absoluteUrl = newBaseUrl + relativePath; // 拼接完整的URL
 
             // 如果已经存在值,则在后面加上逗号分隔的新值
             if (existingValue) {
-                $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
+                $("input[name='" + inputName + "']").val(existingValue + ',' + absoluteUrl);
             } else {
-                $("input[name='" + inputName + "']").val(newValue);
+                $("input[name='" + inputName + "']").val(absoluteUrl);
             }
-        }).on('fileremoved', function (event, id, index) {
+        }).on('fileremoved', function (event, key, jqXHR, pd) {
             var inputName = event.currentTarget.id;
             var existingValue = $("input[name='" + inputName + "']").val();
             var fileUrls = existingValue.split(',');
 
-            // 移除对应的文件路径
-            fileUrls.splice(index, 1);
+            // 假设key是文件的key或者index,需要找到对应的URL并移除
+            // 这里假设key是文件的index
+            var index = key;
+            if (fileUrls[index]) {
+                fileUrls.splice(index, 1);
+            }
 
             // 重新拼接文件路径
             $("input[name='" + inputName + "']").val(fileUrls.join(','));

+ 9 - 4
qmjszx-admin/src/main/resources/templates/system/venue/edit.html

@@ -100,7 +100,7 @@
         var initialPreview = val ? val.split(',') : [];
 
         $(this).fileinput({
-            'uploadUrl': ctx + 'common/upload',
+            uploadUrl: ctx + 'common/upload',
             initialPreviewAsData: true,
             initialPreview: initialPreview,
             maxFileCount: 1,
@@ -110,13 +110,18 @@
         }).on('fileuploaded', function (event, data, previewId, index) {
             var inputName = event.currentTarget.id;
             var existingValue = $("input[name='" + inputName + "']").val();
-            var newValue = data.response.url;
+            var fullUrl = data.response.url; // 获取完整的URL
+            var urlObject = new URL(fullUrl);
+            var relativePath = urlObject.pathname; // 获取路径部分
+            // var newBaseUrl = "http://192.168.4.27"; // 新的基URL
+            var newBaseUrl = "http://localhost"; // 新的基URL
+            var absoluteUrl = newBaseUrl + relativePath; // 拼接完整的URL
 
             // 如果已经存在值,则在后面加上逗号分隔的新值
             if (existingValue) {
-                $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
+                $("input[name='" + inputName + "']").val(existingValue + ',' + absoluteUrl);
             } else {
-                $("input[name='" + inputName + "']").val(newValue);
+                $("input[name='" + inputName + "']").val(absoluteUrl);
             }
         }).on('fileremoved', function (event, id, index) {
             var inputName = event.currentTarget.id;