1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <title>商品添加</title> <link rel="stylesheet" href="../assets/layui/css/layui.css">
</head> <body> <form class="layui-form column-content-detail">
<div class="layui-tab-content"> <div class="layui-tab-item layui-show"> <div class="layui-form-item"> <label class="layui-form-label">商品标题:</label> <div class="layui-input-block"> <input type="text" name="name" required lay-verify="required" placeholder="请输入商品标题" autocomplete="off" class="layui-input"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label">分类:</label> <div class="layui-input-block"> <select name="categoryId" lay-verify="required"> <option value="">请选择分类</option> <option value="100001">家用电器</option> <option value="100002">数码3C</option> <option value="100003">服装箱包</option> <option value="100004">食品生鲜</option> <option value="100005">酒水饮料</option> </select> </div> </div> <div class="layui-form-item"> <label class="layui-form-label">图像上传:</label> <div class="layui-input-block"> <img id="upload_img" src="../images/default_img.png" width="100" height="100"> <button type="button" class="layui-btn" id="test1"> <i class="layui-icon"></i>上传图片 </button> </div> </div> <div class="layui-form-item layui-form-text"> <label class="layui-form-label">商品介绍:</label> <div class="layui-input-block"> <textarea class="layui-textarea layui-hide" name="detail" lay-verify="detail" id="LAY_demo_editor"></textarea> </div> </div> <input type="hidden" id="mainImage" name="mainImage" required value="default_img.png" class="layui-input"> <input type="hidden" id="status" name="status" value="1" class="layui-input"> <div class="layui-form-item"> <label class="layui-form-label">商品库存:</label> <div class="layui-input-block"> <input type="text" name="stock" required lay-verify="number" placeholder="请输入商品库存" autocomplete="off" class="layui-input"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label">商品价格:</label> <div class="layui-input-block"> <input type="text" name="price" required lay-verify="number" placeholder="请输入商品价格" autocomplete="off" class="layui-input"> </div> </div>
</div> </div>
<div class="layui-form-item" style="padding-left: 10px;"> <div class="layui-input-block"> <button class="layui-btn" lay-submit lay-filter="add_product">立即提交</button> <button id="reset" type="reset" class="layui-btn layui-btn-primary">重置</button> </div> </div> </form> <script src="../js/cos-js-sdk-v5.min.js" type="text/javascript" charset="utf-8"></script> <script src="../js/jquery-1.10.2.js" type="text/javascript" charset="utf-8"></script> <script src="../assets/layui/layui.all.js"></script> <script> layui.use(['form', 'jquery', 'laydate', 'layer', 'laypage', 'element', 'upload', 'layedit'], function() { var form = layui.form, layer = layui.layer, $ = layui.jquery, laypage = layui.laypage, laydate = layui.laydate, layedit = layui.layedit, element = layui.element, upload=layui.upload;
//创建一个编辑器 var editIndex = layedit.build('LAY_demo_editor', { tool: ['strong' //加粗 , 'italic' //斜体 , 'underline' //下划线 , 'del' //删除线 , '|' //分割线 , 'left' //左对齐 , 'center' //居中对齐 , 'right' //右对齐 , 'link' //超链接 , 'unlink' //清除链接 , 'image' //插入图片 ], height: 100 }); var uploadInst = upload.render({ elem: '#test1' //绑定元素 ,url:'../upload/upload_image_cos.do'//后台上传接口 ,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。 layer.msg('上传中',{icon: 16,time:0,shade:0.01}); } ,done: function(res, index, upload){ layer.closeAll('loading'); //status=1代表上传成功 if(res.status == 1){ layer.msg("上传成功",{icon:1}); //do something (比如将res返回的图片链接保存到表单的隐藏域) $('#upload_img').attr('src','https://sr-1251242863.cos.ap-shanghai.myqcloud.com/webdemo/images/'+res.path); $('#mainImage').val(res.path); }
//获取当前触发上传的元素,一般用于 elem 绑定 class 的情况,注意:此乃 layui 2.1.0 新增 var item = this.item; //文件保存失败 //do something } ,error: function(){ layer.closeAll('loading'); //请求异常回调 layer.msg("上传失败,请重试",{icon:2}); } ,size:2048 //文件大小限制 ,number:1 //文件数量限制 ,accept: 'images' //文件类型限制 ,acceptMime: 'image/jpg, image/png' //选择窗口属性 }); }); </script> </body> </html>
|