Prechádzať zdrojové kódy

修改banner和文创品牌的edit画面,显示图片

baolei 6 mesiacov pred
rodič
commit
12e7a38d17

+ 50 - 2
08.src/Xingxi/xingxi-admin/src/main/resources/templates/business/banner/edit.html

@@ -5,13 +5,16 @@
 </head>
 <body class="white-bg">
     <div class="wrapper wrapper-content animated fadeInRight ibox-content">
-        <form class="form-horizontal m" id="form-banner-edit" th:object="${tBanner}">
+        <form class="form-horizontal m" id="form-banner-edit" th:object="${banner}">
             <input name="bannerId" th:field="*{bannerId}" type="hidden">
             <div class="col-xs-12">
                 <div class="form-group">
                     <label class="col-sm-3 control-label">banner图地址:</label>
                     <div class="col-sm-8">
-                        <input name="bannerUrl" th:field="*{bannerUrl}" class="form-control" type="text">
+<!--                        <input name="bannerUrl" th:field="*{bannerUrl}" class="form-control" type="text">-->
+                        <img id="bannerImg" width="30%" height="30%" th:src="*{bannerUrl}">
+                        <input type="file" class="form-control" name="bannerImgUrl" id="bannerImgUrl" accept="image/*"/>
+                        <input type="hidden" class="form-control" name="bannerUrl" id="bannerUrl" th:field="*{bannerUrl}" />
                     </div>
                 </div>
             </div>
@@ -52,6 +55,51 @@
     <th:block th:include="include :: footer" />
     <script th:inline="javascript">
         var prefix = ctx + "system/banner";
+
+        $('#bannerImgUrl').change(function () {
+            var fileSize = this.files[0].size;
+            fileSize = Math.round(fileSize/1024*100)/100;
+
+            if(fileSize>2048){
+                layer.msg('上传文件不得大于2M,请重新上传。', {time: 3000, icon:6});
+                return false;
+            }
+
+            if (!/image\/\w+/.test(this.files[0].type)) {
+                layer.msg('上传的不是图片文件,请重新上传。', {time: 3000, icon:6});
+                return false;
+            }
+
+            if ($(this).val()) {
+                var formdata = new FormData();
+                formdata.append("imageFile", this.files[0]);
+                $.ajax({
+                    url: ctx + "common/upload/file/image",
+                    data: formdata,
+                    type: "post",
+                    processData: false,
+                    contentType: false,
+                    beforeSend: function () {
+                        $.modal.loading("正在处理中,请稍后...");
+                        $.modal.disable();
+                    },
+                    success: function (result) {
+                        if (result.code === web_status.SUCCESS) {
+                            $('#bannerImg').attr('src', result.imageUrl);
+                            $('#bannerUrl').val(result.imageUrl);
+                            $.modal.alertSuccess(result.msg)
+                        } else if (result.code === web_status.WARNING) {
+                            $.modal.alertWarning(result.msg)
+                        } else {
+                            $.modal.alertError(result.msg);
+                        }
+                        $.modal.closeLoading();
+                        $.modal.enable();
+                    }
+                })
+            }
+        });
+
         $("#form-banner-edit").validate({
             focusCleanup: true
         });

+ 2 - 2
08.src/Xingxi/xingxi-admin/src/main/resources/templates/master/ipInfo/edit.html

@@ -19,9 +19,9 @@
                 <div class="form-group">
                     <label class="col-sm-3 control-label">ip图片:</label>
                     <div class="col-sm-8">
-                        <img id="ipUrlImg" width="30%" height="30%">
+                        <img id="ipUrlImg" width="30%" height="30%" th:src="*{ipUrl}">
                         <input type="file" class="form-control" name="ipInfoUrl" id="ipInfoUrl" accept="image/*"/>
-                        <input type="hidden" lass="form-control" name="ipUrl" id="ipUrl" />
+                        <input type="hidden" lass="form-control" name="ipUrl" id="ipUrl" th:src="*{ipUrl}"/>
                     </div>
                 </div>
             </div>