TaoLer/public/static/res/mods/user.js

382 lines
10 KiB
JavaScript
Raw Normal View History

2020-01-01 13:17:19 +08:00
/**
@Name: 用户模块
*/
2021-05-26 17:57:00 +08:00
layui.define(['laypage', 'fly', 'element', 'flow', 'imgcom'], function(exports){
2020-01-01 13:17:19 +08:00
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;
2021-05-26 17:57:00 +08:00
var imgcom = layui.imgcom;
2021-05-24 15:05:30 +08:00
var table = layui.table;
2020-01-01 13:17:19 +08:00
var gather = {}, dom = {
mine: $('#LAY_mine')
,mineview: $('.mine-view')
,minemsg: $('#LAY_minemsg')
,infobtn: $('#LAY_btninfo')
};
//我的相关数据
2021-05-24 15:05:30 +08:00
2021-05-24 18:46:16 +08:00
//发贴list
2021-05-24 15:05:30 +08:00
var post = table.render({
elem: '#art-post'
2021-05-24 18:46:16 +08:00
,url: artListUrl
2021-05-24 15:05:30 +08:00
,title: ''
,cols: [[
{type: 'numbers', fixed: 'left'}
2021-05-24 18:46:16 +08:00
,{field: 'title', title: '标题',minWidth: 250 ,templet: '<div><a href="{{d.url}}" target="_blank">{{d.title}}</a></div>'}
,{field: 'status', title: '状态', width: 80}
2021-05-24 15:05:30 +08:00
,{field: 'ctime', title: '时间', width: 120}
,{field: 'datas', title: '数据', width: 120}
,{title: '操作', width: 150, align: 'center', toolbar: '#artTool'}
]]
,text: '对不起,加载出现异常!'
,page: true
});
//收藏list
table.render({
elem: '#coll-post'
2021-05-24 18:46:16 +08:00
,url: collListUrl
2021-05-24 15:05:30 +08:00
,title: ''
,cols: [[
{type: 'numbers', fixed: 'left'}
2021-05-24 18:46:16 +08:00
,{field: 'title', title: '标题',minWidth: 250,templet: '<div><a href="{{d.url}}" target="_blank">{{d.title}}</a></div>'}
2021-05-24 15:05:30 +08:00
,{field: 'auther', title: '作者', width: 120}
2021-05-25 18:17:45 +08:00
,{field: 'status', title: '状态', width: 80}
2021-05-24 15:05:30 +08:00
,{field: 'ctime', title: '时间', width: 120}
,{title: '取消', width: 80, align: 'center', toolbar: '#collTool'}
]]
,text: '对不起,加载出现异常!'
,page: true
});
//监听行工具事件
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');
});
}
});
2020-01-01 13:17:19 +08:00
//显示当前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'
2021-05-26 17:57:00 +08:00
,accept: 'images'
,acceptMime: 'image/*'
,exts: 'jpg|png|gif|bmp|jpeg'
2020-04-24 15:07:26 +08:00
,url: uploadHeadImg
2021-05-26 17:57:00 +08:00
,size: 10240
,auto: false
,choose: function (obj) { //选择文件后的回调
imgcom.uploads(obj);
}
2020-01-01 13:17:19 +08:00
,before: function(){
avatarAdd.find('.loading').show();
}
,done: function(res){
if(res.status == 0){
2020-04-24 15:07:26 +08:00
$.post(userSet, {
2020-01-01 13:17:19 +08:00
avatar: res.url
}, function(res){
location.reload();
});
} else {
layer.msg(res.msg, {icon: 5});
}
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){ }}'
,'<tr>'
,'<td><a href="/u/{{ item.uid }}" target="_blank" style="color: #01AAED;">{{ item.uid }}</a></td>'
,'<td>{{ item.authProduct }}</td>'
,'<td>¥{{ item.rmb }}</td>'
,'<td>{{ item.create_time }}</td>'
,'</tr>'
,'{{# }); }}'].join('');
var effectView = function(res){
var html = laytpl(effectTpl).render(res);
$('#LAY_coop_effect').html(html);
$('#LAY_effect_count').html('你共有 <strong style="color: #FF5722;">'+ (res.count||0) +'</strong> 笔合作授权订单');
};
var effectShow = function(page){
fly.json('/cooperation/effect', {
page: page||1
}, function(res){
effectView(res);
laypage.render({
elem: 'LAY_effect_page'
,count: res.count
,curr: page
,jump: function(e, first){
if(!first){
effectShow(e.curr);
}
}
});
});
};
effectShow();
}
//提交成功后刷新
fly.form['set-mine'] = function(data, required){
layer.msg('修改成功', {
icon: 1
,time: 1000
,shade: 0.1
}, function(){
location.reload();
});
}
//帐号绑定
$('.acc-unbind').on('click', function(){
var othis = $(this), type = othis.attr('type');
layer.confirm('整的要解绑'+ ({
qq_id: 'QQ'
,weibo_id: '微博'
})[type] + '吗?', {icon: 5}, function(){
fly.json('/api/unbind', {
type: type
}, function(res){
if(res.status === 0){
layer.alert('已成功解绑。', {
icon: 1
,end: function(){
location.reload();
}
});
} else {
layer.msg(res.msg);
}
});
});
});
2021-05-16 15:39:22 +08:00
//手机设备的简单适配
2021-07-22 10:48:06 +08:00
var treeMobileUser = $('.site-tree-mobile-user')
,shadeMobileUser = $('.site-mobile-shade-user')
2021-05-16 15:39:22 +08:00
2021-07-22 10:48:06 +08:00
treeMobileUser.on('click', function(){
2021-05-16 15:39:22 +08:00
$('body').addClass('site-mobile');
});
2021-07-22 10:48:06 +08:00
shadeMobileUser.on('click', function(){
2021-05-16 15:39:22 +08:00
$('body').removeClass('site-mobile');
});
2020-11-30 17:13:55 +08:00
//我的消息
gather.minemsg = function(){
var delAll = $('#LAY_delallmsg')
,tpl = '{{# var len = d.rows.length;\
2020-01-01 13:17:19 +08:00
if(len === 0){ }}\
<div class="fly-none">您暂时没有最新消息</div>\
{{# } else { }}\
<ul class="mine-msg">\
{{# for(var i = 0; i < len; i++){ }}\
<li data-id="{{d.rows[i].id}}">\
2020-03-31 23:01:00 +08:00
{{# if(d.rows[i].type == 1){ }}\
2020-11-30 17:13:55 +08:00
<blockquote class="layui-elem-quote"><a href= "'+ userNameJump +'?username={{ d.rows[i].name}}" target="_blank"><cite>{{ d.rows[i].name}}</cite></a><a class="sys-title" id-data="{{ d.rows[i].id}}" href="javascript:;"><cite>{{ d.rows[i].title}}</cite></a> <span class="float:right">{{ d.rows[i].read}}</span></blockquote>\
{{# } }}\
{{# if(d.rows[i].type == 2){ }}\
2020-04-30 18:35:46 +08:00
<blockquote class="layui-elem-quote"><a href= "'+ userNameJump +'?username={{ d.rows[i].name}}" target="_blank"><cite>{{ d.rows[i].name}}</cite></a><a target="_blank" class="art-title" id-data="{{ d.rows[i].id}}" href="{{ d.rows[i].link}}"><cite>{{ d.rows[i].title}}</cite></a> <span class="float:right">{{ d.rows[i].read}}</span></blockquote>\
2020-11-30 17:13:55 +08:00
{{# } }}\
{{# if(d.rows[i].type == 0){ }}\
2020-03-31 23:01:00 +08:00
<blockquote class="layui-elem-quote">系统消息<a class="sys-title" id-data="{{ d.rows[i].id}}" href="javascript:;"><cite>{{ d.rows[i].title}}</cite></a> <span class="float:right">{{ d.rows[i].read}}</span></blockquote>\
{{# } }}\
2020-01-01 13:17:19 +08:00
<p><span>{{d.rows[i].time}}</span><a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-danger fly-delete"></a></p>\
</li>\
{{# } }}\
</ul>\
{{# } }}'
2020-11-30 17:13:55 +08:00
,delEnd = function(clear){
if(clear || dom.minemsg.find('.mine-msg li').length === 0){
dom.minemsg.html('<div class="fly-none">您暂时没有最新消息</div>');
}
}
2020-01-01 13:17:19 +08:00
2020-04-22 18:37:53 +08:00
fly.json(messageFind, {}, function(res){
2020-01-01 13:17:19 +08:00
var html = laytpl(tpl).render(res);
dom.minemsg.html(html);
if(res.rows.length > 0){
delAll.removeClass('layui-hide');
2020-03-28 21:48:35 +08:00
} else {
delAll.addClass('layui-hide');
}
2020-01-01 13:17:19 +08:00
});
2020-03-28 21:48:35 +08:00
2020-01-01 13:17:19 +08:00
//阅读后删除
dom.minemsg.on('click', '.mine-msg li .fly-delete', function(){
var othis = $(this).parents('li'), id = othis.data('id');
2020-04-22 18:37:53 +08:00
fly.json(messageRemove, {
2020-01-01 13:17:19 +08:00
id: id
}, function(res){
if(res.status === 0){
othis.remove();
delEnd();
}
});
});
//删除全部
$('#LAY_delallmsg').on('click', function(){
var othis = $(this);
layer.confirm('确定清空吗?', function(index){
2020-04-22 18:37:53 +08:00
fly.json(messageRemove, {
2020-03-28 21:48:35 +08:00
id: true
2020-01-01 13:17:19 +08:00
}, function(res){
if(res.status === 0){
layer.close(index);
othis.addClass('layui-hide');
delEnd(true);
}
});
});
});
};
dom.minemsg[0] && gather.minemsg();
exports('user', null);
});