/** @Name: 用户模块 */ layui.define(['laypage', 'fly', 'element', 'flow', 'imgcom'], function(exports){ var $ = layui.jquery; var layer = layui.layer; var util = layui.util; var laytpl = layui.laytpl; var form = layui.form; var laypage = layui.laypage; var fly = layui.fly; var flow = layui.flow; var element = layui.element; var upload = layui.upload; var imgcom = layui.imgcom; var table = layui.table; var gather = {}, dom = { mine: $('#LAY_mine') ,mineview: $('.mine-view') ,minemsg: $('#LAY_minemsg') ,infobtn: $('#LAY_btninfo') }; //我的相关数据 //发贴list var post = table.render({ elem: '#art-post' ,url: artListUrl ,toolbar: '#toolbarPost' ,title: '' ,cols: [[ {type: 'checkbox', fixed: 'left'}, {type: 'numbers', fixed: 'left', title: '序号'} ,{field: 'title', title: '标题',minWidth: 250 ,templet: '
'} ,{field: 'pv', title:'浏览 ', fieldTitle: 'pv', hide: 0, width:100, expandedMode: 'tips', edit: 'text'} ,{field: 'status', title: '状态', width: 80} ,{field: 'ctime', title: '发布时间', width: 160} ,{field: 'utime', title: '更新时间', width:160} ,{field: 'datas', title: '数据', width: 80} ,{title: '操作', width: 150, align: 'center', toolbar: '#artTool'} ]] ,text: '对不起,加载出现异常!' ,page: true }); // 工具栏事件 table.on('toolbar(art-post)', function(obj){ var id = obj.config.id; var checkStatus = table.checkStatus(id); var othis = lay(this); switch(obj.event){ case 'getCheckData': var data = checkStatus.data; // layer.alert(layui.util.escape(JSON.stringify(data))); $.post(updateTime,{"data":data},function(res){ if(res.code === 0){ layer.msg(res.msg,{icon:6,time:2000}); table.reload('art-post') } else { layer.open({title:'刷新失败',content:res.msg,icon:5,adim:6}) } } ); break; case 'getData': var getData = table.getData(id); console.log(getData); layer.alert(layui.util.escape(JSON.stringify(getData))); break; case 'LAYTABLE_TIPS': layer.alert('自定义工具栏图标按钮'); break; }; return false }); //收藏list table.render({ elem: '#coll-post' ,url: collListUrl ,title: '' ,cols: [[ {type: 'numbers', fixed: 'left'} ,{field: 'title', title: '标题',minWidth: 250,templet: ''} ,{field: 'auther', title: '作者', width: 120} ,{field: 'status', title: '状态', width: 80} ,{field: 'ctime', title: '时间', width: 120} ,{title: '取消', width: 80, align: 'center', toolbar: '#collTool'} ]] ,text: '对不起,加载出现异常!' ,page: true }); // 单元格编辑事件 table.on('edit(art-post)', function(obj){ var field = obj.field; // 得到字段 var value = obj.value; // 得到修改后的值 var data = obj.data; // 得到所在行所有键值 // 值的校验 if(field === 'email'){ if(!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(obj.value)){ layer.tips('输入的邮箱格式不正确,请重新编辑', this, {tips: 1}); return obj.reedit(); // 重新编辑 -- v2.8.0 新增 } } // 编辑后续操作,如提交更新请求,以完成真实的数据更新 $.ajax({ type: "post", url: pvEdit, data: data, dataType: 'json', success: (res) => { if(res.code === 0) { layer.msg(res.msg, {icon: 1}); } else { layer.msg(res.msg, {icon: 2}); return false; } } }) // … // 其他更新操作 var update = {}; update[field] = value; obj.update(update); }); //监听行工具事件 table.on('tool(art-post)', function(obj){ var data = obj.data; var id = data.id; if(obj.event === 'del'){ layer.confirm('确定删除吗?',{ title:'删除文章', icon:3 },function(index){ layer.close(index); $.post(atrDelUrl,{"id":id},function(data){ if(data.code == 0){ layer.msg(data.msg,{icon:6,time:2000}); } else { layer.open({title:'删除失败',content:data.msg,icon:5,adim:6}) } } ); table.reload('art-post'); }); } else if(obj.event === 'edit'){//编辑 $.post(artEditUrl,{"id":id},function(){ location.href = artEditUrl + '?id=' + id; }); } }); //监听行工具事件 table.on('tool(coll-post)', function(obj){ var id = obj.data.id; if(obj.event === 'del'){ layer.confirm('确定取消收藏?',{ title:'取消收藏', icon:3 },function(index){ layer.close(index); $.post(collDelUrl,{"id":id},function(data){ if(data.code == 0){ layer.msg(data.msg,{ icon:6, time:2000 }); } else { layer.open({ title:'取消失败', content:data.msg, icon:5, adim:6 }) } } ); table.reload('coll-post'); }); } }); //显示当前tab if(location.hash){ element.tabChange('user', location.hash.replace(/^#/, '')); } element.on('tab(user)', function(){ var othis = $(this), layid = othis.attr('lay-id'); if(layid){ location.hash = layid; } }); /* //根据ip获取城市 if($('#L_city').val() === ''){ $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(){ $('#L_city').val(remote_ip_info.city||''); }); } */ //上传图片 if($('.upload-img')[0]){ layui.use('upload', function(upload){ var avatarAdd = $('.avatar-add'); upload.render({ elem: '.upload-img' ,accept: 'images' ,acceptMime: 'image/*' ,exts: 'jpg|png|gif|bmp|jpeg' ,url: uploadHeadImg ,size: 10240 ,auto: false ,choose: function (obj) { //选择文件后的回调 imgcom.uploads(obj); } ,before: function(){ avatarAdd.find('.loading').show(); } ,done: function(res){ if(res.code == 0){ layer.msg(res.msg, { icon: 6, time: 2000 },function(){ location.reload(); }); } else { layer.open({ content: data.msg, icon: 5, adim: 6 }); } avatarAdd.find('.loading').hide(); } ,error: function(){ avatarAdd.find('.loading').hide(); } }); }); } //合作平台 if($('#LAY_coop')[0]){ //资源上传 $('#LAY_coop .uploadRes').each(function(index, item){ var othis = $(this); upload.render({ elem: item ,url: '/api/upload/cooperation/?filename='+ othis.data('filename') ,accept: 'file' ,exts: 'zip' ,size: 30*1024 ,before: function(){ layer.msg('正在上传', { icon: 16 ,time: -1 ,shade: 0.7 }); } ,done: function(res){ if(res.code == 0){ layer.msg(res.msg, {icon: 6}) } else { layer.msg(res.msg) } } }); }); //成效展示 var effectTpl = ['{{# layui.each(d.data, function(index, item){ }}' ,'{{ d.rows[i].name}}给您发了站内信{{ d.rows[i].title}} {{ d.rows[i].read}}\ {{# } }}\ {{# if(d.rows[i].type == 2){ }}\
{{ d.rows[i].name}}回答了您的帖子{{ d.rows[i].title}} {{ d.rows[i].read}}\ {{# } }}\ {{# if(d.rows[i].type == 0){ }}\
系统消息:{{ d.rows[i].title}} {{ d.rows[i].read}}\ {{# } }}\
{{d.rows[i].time}}删除
\