Browse Source

上传图片

gzb
guozhongbo 1 year ago
parent
commit
93f49f190a
2 changed files with 79 additions and 58 deletions
  1. 77
    56
      sections/service.html
  2. 2
    2
      utils/index.js

+ 77
- 56
sections/service.html View File

69
       }
69
       }
70
       #uploadFile {
70
       #uploadFile {
71
         display: inline-block;
71
         display: inline-block;
72
-        width: 100px;
73
-        height: 100px;
72
+      }
73
+      .upimg {
74
+        width: 180px;
75
+        height: 180px;
76
+        border: 1px solid #ccc;
77
+        margin-bottom: 10px;
78
+      }
79
+      .upimg img {
80
+        width: 100%;
81
+        height: 100%;
74
       }
82
       }
75
     </style>
83
     </style>
76
   </head>
84
   </head>
203
                   />
211
                   />
204
                 </div>
212
                 </div>
205
               </div>
213
               </div>
214
+              <div class="form-group">
215
+                <label for="scorderInput" class="col-sm-2 control-label"
216
+                  >排序</label
217
+                >
218
+                <div class="col-sm-10">
219
+                  <input
220
+                    type="number"
221
+                    class="form-control"
222
+                    id="scorderInput"
223
+                    name="scorder"
224
+                    placeholder="请输入排序"
225
+                  />
226
+                </div>
227
+              </div>
206
               <div class="form-group">
228
               <div class="form-group">
207
                 <label for="loginnameInput" class="col-sm-2 control-label"
229
                 <label for="loginnameInput" class="col-sm-2 control-label"
208
                   >上传图片</label
230
                   >上传图片</label
209
                 >
231
                 >
210
                 <div class="col-sm-10">
232
                 <div class="col-sm-10">
233
+                  <div class="upimg addimg"></div>
211
                   <input type="file" id="uploadFile" />
234
                   <input type="file" id="uploadFile" />
212
                 </div>
235
                 </div>
213
               </div>
236
               </div>
214
             </form>
237
             </form>
215
           </div>
238
           </div>
216
           <div class="modal-footer">
239
           <div class="modal-footer">
217
-            <div type="button" class="btn btn-default" data-dismiss="modal">
240
+            <div
241
+              type="button"
242
+              class="btn btn-default add_cancel"
243
+              data-dismiss="modal"
244
+            >
218
               取消
245
               取消
219
             </div>
246
             </div>
220
             <div type="button" class="btn btn-primary add_save">确定</div>
247
             <div type="button" class="btn btn-primary add_save">确定</div>
247
             <form class="form-horizontal" id="userModifyForm">
274
             <form class="form-horizontal" id="userModifyForm">
248
               <div class="form-group">
275
               <div class="form-group">
249
                 <label for="m_scnameInput" class="col-sm-2 control-label"
276
                 <label for="m_scnameInput" class="col-sm-2 control-label"
250
-                  >用户姓名</label
277
+                  >服务名称</label
251
                 >
278
                 >
252
                 <div class="col-sm-10">
279
                 <div class="col-sm-10">
253
                   <input
280
                   <input
255
                     class="form-control"
282
                     class="form-control"
256
                     id="m_scnameInput"
283
                     id="m_scnameInput"
257
                     name="scname"
284
                     name="scname"
258
-                    placeholder="请输入用户姓名"
285
+                    placeholder="请输入服务名称"
259
                   />
286
                   />
260
                 </div>
287
                 </div>
261
               </div>
288
               </div>
304
             </form>
331
             </form>
305
           </div>
332
           </div>
306
           <div class="modal-footer">
333
           <div class="modal-footer">
307
-            <div type="button" class="btn btn-default" data-dismiss="modal">
334
+            <div
335
+              type="button"
336
+              class="btn btn-default mo_cancel"
337
+              data-dismiss="modal"
338
+            >
308
               取消
339
               取消
309
             </div>
340
             </div>
310
             <div type="button" class="btn btn-primary modify_save">确定</div>
341
             <div type="button" class="btn btn-primary modify_save">确定</div>
335
           </div>
366
           </div>
336
           <div class="modal-body">确定删除选中信息?</div>
367
           <div class="modal-body">确定删除选中信息?</div>
337
           <div class="modal-footer">
368
           <div class="modal-footer">
338
-            <div type="button" class="btn btn-default" data-dismiss="modal">
369
+            <div
370
+              type="button"
371
+              class="btn btn-default del_cancel"
372
+              data-dismiss="modal"
373
+            >
339
               取消
374
               取消
340
             </div>
375
             </div>
341
             <div type="button" class="btn btn-primary del_save">保存</div>
376
             <div type="button" class="btn btn-primary del_save">保存</div>
373
           ltype: Number($.getQueryletiable("ltype")) || 1,
408
           ltype: Number($.getQueryletiable("ltype")) || 1,
374
           scname: $.getQueryletiable("scname") || "",
409
           scname: $.getQueryletiable("scname") || "",
375
           total: 0,
410
           total: 0,
376
-          list: []
411
+          list: [],
412
+          scpic: "",
413
+          scorder: 0,
414
+          createid: 0
377
         };
415
         };
378
         //默认中英文单选框 1
416
         //默认中英文单选框 1
379
         $('.header_left input:radio[name="user_radio"]').each(function (
417
         $('.header_left input:radio[name="user_radio"]').each(function (
403
               if (data.code === 0) {
441
               if (data.code === 0) {
404
                 Search.total = data.obj.total;
442
                 Search.total = data.obj.total;
405
                 Search.list = data.obj.list;
443
                 Search.list = data.obj.list;
444
+                Search.scorder = data.obj.total;
406
                 console.log(Search);
445
                 console.log(Search);
407
                 setTableHtml();
446
                 setTableHtml();
408
                 setPageList();
447
                 setPageList();
556
         //添加弹窗
595
         //添加弹窗
557
         $(".user_main .header_box .user_add_btn").click(function () {
596
         $(".user_main .header_box .user_add_btn").click(function () {
558
           $("#userAddModal").modal("show");
597
           $("#userAddModal").modal("show");
598
+          Search.scorder++;
599
+          $("#scorderInput").val(Search.scorder);
559
         });
600
         });
560
         //获取图片地址
601
         //获取图片地址
561
         $("#uploadFile").on("change", function () {
602
         $("#uploadFile").on("change", function () {
571
             alert("图片太大,不能超过10M!");
612
             alert("图片太大,不能超过10M!");
572
             return false;
613
             return false;
573
           }
614
           }
574
-          var formData = new FormData();
575
-          formData.append("file", file);
576
-          formData.append("savefolder", "servicecase");
577
-          console.log(formData);
615
+          const form = new FormData();
616
+          form.append("file", file);
617
+          form.append("savefolder", "servicecase");
578
           $.ajax({
618
           $.ajax({
579
             type: "POST",
619
             type: "POST",
580
             url: $.baseUrl + "file/upload",
620
             url: $.baseUrl + "file/upload",
581
-            dataType: "json",
582
-            contentType: "application/json; charset=utf-8",
583
-            data: JSON.stringify(formData),
621
+            contentType: false,
622
+            processData: false,
623
+            data: form,
584
             success: function (data) {
624
             success: function (data) {
585
               if (data.code === 0) {
625
               if (data.code === 0) {
586
-                console.log(data);
626
+                Search.scpic = data.obj;
627
+                $(".addimg").html("<img src='" + $.showImageUrl + scpic + "'>");
587
               } else {
628
               } else {
588
                 alert(data.msg);
629
                 alert(data.msg);
589
               }
630
               }
590
             }
631
             }
591
           });
632
           });
592
         });
633
         });
593
-
634
+        //添加 取消add_cancel
635
+        $(".add_cancel").on("click", function () {
636
+          console.log(1);
637
+        });
594
         //确定添加
638
         //确定添加
595
         $("#userAddModal .add_save").on("click", function () {
639
         $("#userAddModal .add_save").on("click", function () {
596
           // 添加表单验证
640
           // 添加表单验证
607
               scname: {
651
               scname: {
608
                 validators: {
652
                 validators: {
609
                   notEmpty: {
653
                   notEmpty: {
610
-                    message: "请输入用户姓名"
654
+                    message: "请输入服务名称"
611
                   }
655
                   }
612
                 }
656
                 }
613
               },
657
               },
614
-              loginname: {
658
+              scorder: {
615
                 validators: {
659
                 validators: {
616
                   notEmpty: {
660
                   notEmpty: {
617
-                    message: "请输入登录账号"
618
-                  },
619
-                  stringLength: {
620
-                    //长度限制
621
-                    min: 4,
622
-                    max: 18,
623
-                    message: "登录账号长度必须在4~18个字符之间"
624
-                  }
625
-                }
626
-              },
627
-              loginpwd: {
628
-                validators: {
629
-                  notEmpty: {
630
-                    message: "请输入登录密码"
631
-                  },
632
-                  stringLength: {
633
-                    //长度限制
634
-                    min: 6,
635
-                    max: 16,
636
-                    message: "登录密码长度必须在6~16个字符之间"
637
-                  }
638
-                }
639
-              },
640
-              userphone: {
641
-                validators: {
642
-                  // notEmpty: {
643
-                  //   message: "请输入手机号",
644
-                  // },
645
-                  regexp: {
646
-                    regexp: /^1\d{10}$/,
647
-                    message: "请输入正确的11位手机号"
661
+                    message: "请输入排序"
648
                   }
662
                   }
649
                 }
663
                 }
650
               }
664
               }
654
           $("#UserAddForm").data("bootstrapValidator").validate();
668
           $("#UserAddForm").data("bootstrapValidator").validate();
655
           //校验表单是否通过
669
           //校验表单是否通过
656
           let flag = $("#UserAddForm").data("bootstrapValidator").isValid();
670
           let flag = $("#UserAddForm").data("bootstrapValidator").isValid();
671
+          if (!Search.scpic) {
672
+            //请上传图片
673
+            alert("请上传图片!");
674
+            return;
675
+          }
657
           if (flag) {
676
           if (flag) {
658
-            let _url = $.baseUrl + "user/save";
677
+            let _url = $.baseUrl + "sc/save";
659
             $.ajax({
678
             $.ajax({
660
               type: "POST",
679
               type: "POST",
661
               url: _url,
680
               url: _url,
662
               dataType: "json",
681
               dataType: "json",
663
               contentType: "application/json; charset=utf-8",
682
               contentType: "application/json; charset=utf-8",
664
               data: JSON.stringify({
683
               data: JSON.stringify({
665
-                scname: $("#UserAddForm #scnameInput").val(),
666
-                loginname: $("#UserAddForm #loginnameInput").val(),
667
-                loginpwd: $("#UserAddForm #loginpwdInput").val(),
684
+                scname: Search.scname,
685
+                scpic: Search.scpic,
686
+                ltype: Search.ltype,
668
                 createid: $.userInfo.userid,
687
                 createid: $.userInfo.userid,
669
-                userphone: $("#UserAddForm #userphoneInput").val()
688
+                scorder: Search.scorder
670
               }),
689
               }),
671
               success: function (data) {
690
               success: function (data) {
672
                 if (data.code === 0) {
691
                 if (data.code === 0) {
673
                   window.location.href =
692
                   window.location.href =
674
-                    "/index.html?page=1&ltype=" +
693
+                    "/sections/service.html?page=" +
694
+                    Search.page +
695
+                    "&ltype=" +
675
                     Search.ltype +
696
                     Search.ltype +
676
                     "&scname=" +
697
                     "&scname=" +
677
                     Search.scname;
698
                     Search.scname;

+ 2
- 2
utils/index.js View File

16
     return year + "-" + month + "-" + day;
16
     return year + "-" + month + "-" + day;
17
   },
17
   },
18
   // 秒时间转换为yyyy-MM-dd HH:mm:ss
18
   // 秒时间转换为yyyy-MM-dd HH:mm:ss
19
-  dateFormat: function(unixtimestamp) {
19
+  dateFormat: function (unixtimestamp) {
20
     unixtimestamp = new Date(unixtimestamp * 1000);
20
     unixtimestamp = new Date(unixtimestamp * 1000);
21
     let year = 1900 + unixtimestamp.getYear();
21
     let year = 1900 + unixtimestamp.getYear();
22
     let month = "0" + (unixtimestamp.getMonth() + 1);
22
     let month = "0" + (unixtimestamp.getMonth() + 1);
39
     );
39
     );
40
   },
40
   },
41
   // 读取url参数
41
   // 读取url参数
42
-  getQueryletiable: function(letiable) {
42
+  getQueryletiable: function (letiable) {
43
     let query = window.location.search.substring(1);
43
     let query = window.location.search.substring(1);
44
     query = decodeURI(query);
44
     query = decodeURI(query);
45
     let lets = query.split("&");
45
     let lets = query.split("&");

Loading…
Cancel
Save