123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <!DOCTYPE html>
- <html class="x-admin-sm">
-
- <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,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
- <link rel="shortcut icon" href="../favicon.ico">
- <link rel="bookmark" href="../favicon.ico">
- <link rel="stylesheet" href="../css/font.css">
- <link rel="stylesheet" href="../css/xadmin.css">
- <link rel="stylesheet" href="../layui/css/layui.css">
- <script type="text/javascript" src="../layui/layui.js" charset="utf-8"></script>
- <script type="text/javascript" src="../js/xadmin.js"></script>
- <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
- <!--[if lt IE 9]>
- <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
- <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
- <![endif]--></head>
-
- <body>
- <div class="layui-fluid">
- <div class="layui-row">
- <form class="layui-form">
- <div class="layui-form-item">
- <label class="layui-form-label">
- <span class="x-red">*</span>图片</label>
- <div class="layui-input-inline">
- <div class="layui-upload">
- <button type="button" class="layui-btn" id="test1">上传图片</button>
- <div class="layui-upload-list">
- <img {{if gt .id 0 }}
- src="{{.Date.T_img}}"
- {{end}} style="max-height: 100px;height: 100px" class="layui-upload-img" id="demo1">
- <p id="demoText"></p>
- </div>
- </div>
- </div>
- </div>
- <div class="layui-form-item">
- <label for="T_name" class="layui-form-label">
- <span class="x-red">*</span>名称</label>
- <div class="layui-input-inline">
- <input {{if gt .id 0 }}
- value="{{.Date.Id}}"
- {{end}} type="text" id="T_name" name="T_name" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">
- <span class="x-red">*</span>分类</label>
- <div class="layui-input-inline">
- <select lay-filter="T_class" id="T_class" name="T_class" class="valid" >
- {{range $index, $elem := .Class_List}}
- <option value="{{$elem.Id}}" {{if gt $.id 0 }}
- {{if eq $.Date.T_class $elem.Id }}
- selected
- {{end}}
- {{end}}
- >{{$elem.T_name}}</option>
- {{end}}
- </select>
- </div>
- </div>
- <div class="layui-form-item">
- <label for="T_int" class="layui-form-label">
- <span class="x-red">*</span>数字</label>
- <div class="layui-input-inline">
- <input {{if gt .id 0 }}
- value="{{.Date.T_int}}"
- {{end}} type="text" id="T_int" name="T_int" placeholder="¥" autocomplete="off" class="layui-input">
- </div>
- <div class="layui-form-mid layui-word-aux">
- <span class="x-red">*</span>
- </div>
- </div>
- <div class="layui-form-item layui-form-text">
- <label for="T_text" class="layui-form-label">描述</label>
- <div class="layui-input-block">
- <textarea class="layui-textarea" id="T_text" style="display: none" >
- {{if gt .id 0 }}
- {{.Date.T_text}}
- {{end}}
- </textarea>
- </div>
- </div>
- <div class="layui-form-item" style="text-align: center;margin-top: 20px">
- <!-- <label for="L_repass" class="layui-form-label"></label>-->
- <button class="layui-btn layui-btn-normal" lay-filter="add" lay-submit="">提交</button></div>
- </form>
- </div>
- </div>
- <script>
- layui.use(['form', 'layer',"layedit"],
- function() {
- $ = layui.jquery;
- var form = layui.form,
- layer = layui.layer;
- var layedit = layui.layedit
- layedit.set({
- uploadImage: {
- url: '/UpFile' //接口url
- }
- });
- //构建一个默认的编辑器
- var index = layedit.build('T_text', {
- height: 580 //设置编辑器高度,
- });
- //监听提交
- form.on('submit(add)',
- function(data) {
- console.log("=== submit(add) ==");
- console.log(data);
- $.ajax({
- type: 'POST',
- url: 'List_Post',//发送请求
- data: {
- id:"{{.id}}",
- T_name:data.field.T_name,
- T_class:data.field.T_class,
- T_int:data.field.T_int,
- T_img:T_img,
- T_text:layedit.getContent(index),
- },
- success: function(result) {
- console.log(result)
- if(result.Code == 200){
- layer.msg("操作成功", {
- icon: 1,
- time: 2000
- });
- }else {
- layer.msg("错误:"+result.Msg, {
- icon: 2,
- time: 2000
- });
- }
- //
- //关闭当前frame
- parent.layer.close(parent.layer.getFrameIndex(window.name));
- parent.location.reload();
- form.render('select');
- // return false;
- }
- });
- return false;
- });
- });
- </script>
- <script>
- T_img = "{{.Date.T_img}}"
- layui.use('upload', function(){
- var $ = layui.jquery
- ,upload = layui.upload;
- //普通图片上传
- var uploadInst = upload.render({
- elem: '#test1'
- ,url: '/UpFile' //改成您自己的上传接口
- ,before: function(obj){
- //预读本地文件示例,不支持ie8
- obj.preview(function(index, file, result){
- $('#demo1').attr('src', result); //图片链接(base64)
- });
- }
- ,done: function(res){
- console.log(res)
- //如果上传失败
- if(res.code != 0){
- return layer.msg('上传失败');
- }
- T_img = res.data.src
- console.log(T_img)
- //上传成功
- }
- ,error: function(){
- console.log("error")
- //演示失败状态,并实现重传
- var demoText = $('#demoText');
- demoText.html('<span style="color: #ff5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
- demoText.find('.demo-reload').on('click', function(){
- uploadInst.upload();
- });
- }
- });
- //绑定原始文件域
- upload.render({
- elem: '#test20'
- ,url: 'https://httpbin.org/post' //改成您自己的上传接口
- ,done: function(res){
- layer.msg('上传成功');
- console.log(res)
- }
- });
- });
- </script>
- </body>
- </html>
|