返回Lay框架后台......登陆

Lay框架后台文件上传

天腾²⁰¹⁹2019-05-17 13:01:57282

<!DOCTYPE html>    

<html>    

<head>    

<title></title>    

<link rel="stylesheet" type="text/css" href="/plugins/layui/css/layui.css">    

<script type="text/javascript" src="/plugins/layui/layui.js"></script>    

<script type="text/javascript" src="/plugins/ueditor/ueditor.config.js"></script>    

<script type="text/javascript" src="/plugins/ueditor/ueditor.all.min.js"></script>    

</head>    

<body style="padding: 10px;">    

<div class="layui-form layui-form-pane">    

<input type="hidden" name="aid" value="0">    

<input type="hidden" name="_token" value="SzyCdEnF8Bay8ThQ8wAumP9Bnn6J1oYVOG4wHDot">    

<div class="layui-form-item">    

<label class="layui-form-label">文章标题</label>    

<div class="layui-input-block">    

<input type="text" name="title" class="layui-input" value="">    

</div>    

</div>    


<div class="layui-form-item">    

<label class="layui-form-label">文章分类</label>    

<div class="layui-input-inline">    

<select id="cid">    

<option value="0"></option>    

<option value="1" >行业应用</option>    

<option value="2" >技术服务</option>    

<option value="3" >新闻动态</option>    

<option value="4" >关于我们</option>    

<option value="7" >产品列表</option>    

</select>    

</div>    

<div class="layui-input-inline">    

<input type="checkbox" name="status" title="发布" >    

</div>    

</div>    


<div class="layui-form-item">    

<label class="layui-form-label">关键字</label>    

<div class="layui-input-block">    

<input type="text" name="keywords" class="layui-input" value="">    

</div>    

</div>    


<div class="layui-form-item">    

<label class="layui-form-label">文章描述</label>    

<div class="layui-input-block">    

<input type="text" name="descs" class="layui-input" value="">    

</div>    

</div>    


<div class="layui-form-item">    

<button type="button" class="layui-btn layui-btn-sm" id="btn_logo"><i class="layui-icon">&#xe67c;</i>上传图片</button>    

<img src="" style="height: 30px;" id="img_logo">    

<span style="color: gray;font-size: 12px;">最大1M,格式:jpg,png,gif;尺寸:500×500</span>    

</div>    


<div class="layui-form-item">    

<script id="article" name="content" type="text/plain">    

</script>    

</div>    


<div class="layui-form-item">    

<button class="layui-btn" onclick="save()">提交</button>    

</div>    

</div>    

</body>    

</html>    

<script type="text/javascript">    

layui.use(['layer','form','upload'],function(){    

layer = layui.layer;    

form = layui.form;    

$ = layui.jquery;    

var upload = layui.upload;    

//执行实例    

var uploadInst = upload.render({    

elem: '#btn_logo' //绑定元素    

,url: '/admins/files/upload_img' //上传接口    

,data: {_token: $('input[name="_token"]').val()}    

,done: function(res){    

$('#img_logo').attr('src',res.data.src);    

}    

,error: function(){    

alert('上传失败');    

}    

});    


ue = UE.getEditor('article');    

});    


function save(){    

var data = new Object();    

data._token = $('input[name="_token"]').val();    

data.aid = $('input[name="aid"]').val();    

data.title = $.trim($('input[name="title"]').val());    

data.cid = $('#cid').val();    

data.status = $('input[name="status"]').is(':checked')?1:0;    

data.keywords = $.trim($('input[name="keywords"]').val());    

data.descs = $.trim($('input[name="descs"]').val());    

data.img_logo = $('#img_logo').attr('src');    

data.article =  ue.getContent();    

// 判断标题是否为空    


$.post('/admins/article/save',data,function(res){    

if(res.code>0){    

layer.msg(res.msg,{icon:2});    

}else{    

layer.msg(res.msg,{icon:1});    

setTimeout(function(){parent.window.location.reload();},1000);    

}    

},'json');    

}    

</script>    



最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送