Browse Source

Merge remote-tracking branch 'origin/master'

hanfucheng 4 months ago
parent
commit
9fa1d52c7a

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

@@ -124,27 +124,36 @@
     $(".file-upload").fileinput({
         uploadUrl: ctx + 'common/upload',
         maxFileCount: 5,
-        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/mall/edit.html

@@ -145,7 +145,7 @@
         var initialPreview = val ? val.split(',') : [];
 
         $(this).fileinput({
-            'uploadUrl': ctx + 'common/upload',
+            uploadUrl: ctx + 'common/upload',
             initialPreviewAsData: true,
             initialPreview: initialPreview,
             maxFileCount: 5,
@@ -155,13 +155,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;

+ 2 - 0
qmjszx-business/src/main/java/beilv/shopping/domain/QmjsShoppingMall.java

@@ -39,6 +39,8 @@ public class QmjsShoppingMall extends BaseEntity
     @Excel(name = "商品图片")
     private String goodsImg;
 
+//    private String[] imageUrlsArray;
+
     /** 商品说明 */
     @Excel(name = "商品说明")
     private String goodsDescribe;

+ 8 - 2
qmjszx-business/src/main/java/beilv/shopping/service/impl/QmjsShoppingMallServiceImpl.java

@@ -30,7 +30,14 @@ public class QmjsShoppingMallServiceImpl implements IQmjsShoppingMallService {
      */
     @Override
     public QmjsShoppingMall selectQmjsShoppingMallById(Long id) {
-        return qmjsShoppingMallMapper.selectQmjsShoppingMallById(id);
+
+        QmjsShoppingMall shoppingMall = qmjsShoppingMallMapper.selectQmjsShoppingMallById(id);
+//        if (shoppingMall != null && shoppingMall.getGoodsImg() != null) {
+//            // 将逗号分隔的字符串拆分为数组
+//            String[] imageUrls = shoppingMall.getGoodsImg().split(",");
+//            shoppingMall.setImageUrlsArray(imageUrls);
+//        }
+        return shoppingMall;
     }
 
     /**
@@ -60,7 +67,6 @@ public class QmjsShoppingMallServiceImpl implements IQmjsShoppingMallService {
             }
         }
         return result;
-
     }
 
     /**