2020-01-01 13:17:19 +08:00
|
|
|
|
/**
|
2021-05-21 19:49:21 +08:00
|
|
|
|
TaoLer社区修改 www.aieok.com
|
2020-01-01 13:17:19 +08:00
|
|
|
|
@Name: Fly社区主入口
|
2024-04-14 12:08:53 +08:00
|
|
|
|
2024-4.7
|
2020-01-01 13:17:19 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2024-04-14 12:08:53 +08:00
|
|
|
|
layui.define(['layer', 'form', 'util'], function(exports){
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
var $ = layui.jquery
|
|
|
|
|
,layer = layui.layer
|
|
|
|
|
,form = layui.form
|
|
|
|
|
,util = layui.util
|
|
|
|
|
,device = layui.device()
|
2021-06-07 17:53:24 +08:00
|
|
|
|
var uid = layui.cache.user.uid;
|
2022-08-02 21:13:36 +08:00
|
|
|
|
var login = $('.fly-nav-user').attr('userlogin');
|
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
//阻止IE7以下访问
|
|
|
|
|
if(device.ie && device.ie < 8){
|
|
|
|
|
layer.alert('如果您非得使用 IE 浏览器访问Fly社区,那么请使用 IE8+');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layui.focusInsert = function(obj, str){
|
|
|
|
|
var result, val = obj.value;
|
|
|
|
|
obj.focus();
|
|
|
|
|
if(document.selection){ //ie
|
|
|
|
|
result = document.selection.createRange();
|
|
|
|
|
document.selection.empty();
|
|
|
|
|
result.text = str;
|
|
|
|
|
} else {
|
|
|
|
|
result = [val.substring(0, obj.selectionStart), str, val.substr(obj.selectionEnd)];
|
|
|
|
|
obj.focus();
|
|
|
|
|
obj.value = result.join('');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//数字前置补零
|
|
|
|
|
layui.laytpl.digit = function(num, length, end){
|
|
|
|
|
var str = '';
|
|
|
|
|
num = String(num);
|
|
|
|
|
length = length || 2;
|
|
|
|
|
for(var i = num.length; i < length; i++){
|
|
|
|
|
str += '0';
|
|
|
|
|
}
|
|
|
|
|
return num < Math.pow(10, length) ? str + (num|0) : num;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var fly = {
|
2024-04-01 10:17:53 +08:00
|
|
|
|
dir: layui.cache.host + 'static/res/mods/' //模块路径
|
2020-01-01 13:17:19 +08:00
|
|
|
|
//Ajax
|
|
|
|
|
,json: function(url, data, success, options){
|
|
|
|
|
var that = this, type = typeof data === 'function';
|
|
|
|
|
|
|
|
|
|
if(type){
|
|
|
|
|
options = success
|
|
|
|
|
success = data;
|
|
|
|
|
data = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
|
|
return $.ajax({
|
|
|
|
|
type: options.type || 'post',
|
|
|
|
|
dataType: options.dataType || 'json',
|
|
|
|
|
data: data,
|
|
|
|
|
url: url,
|
|
|
|
|
success: function(res){
|
|
|
|
|
if(res.status === 0) {
|
|
|
|
|
success && success(res);
|
|
|
|
|
} else {
|
|
|
|
|
layer.msg(res.msg || res.code, {shift: 6});
|
|
|
|
|
options.error && options.error();
|
|
|
|
|
}
|
|
|
|
|
}, error: function(e){
|
|
|
|
|
layer.msg('请求异常,请重试', {shift: 6});
|
|
|
|
|
options.error && options.error(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//计算字符长度
|
|
|
|
|
,charLen: function(val){
|
|
|
|
|
var arr = val.split(''), len = 0;
|
|
|
|
|
for(var i = 0; i < val.length ; i++){
|
|
|
|
|
arr[i].charCodeAt(0) < 299 ? len++ : len += 2;
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
,form: {}
|
|
|
|
|
|
2024-04-14 12:08:53 +08:00
|
|
|
|
//简易编辑器 -移除 -2024/4/7
|
2022-08-02 18:49:40 +08:00
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
//新消息通知
|
|
|
|
|
,newmsg: function(){
|
|
|
|
|
var elemUser = $('.fly-nav-user');
|
2024-04-14 12:08:53 +08:00
|
|
|
|
var messageNums = elemUser.attr('msg-url');
|
|
|
|
|
var messageRead = elemUser.attr('readMsg-url');
|
2022-08-02 21:13:36 +08:00
|
|
|
|
if(uid != -1 && elemUser[0]){
|
2020-04-22 18:37:53 +08:00
|
|
|
|
fly.json(messageNums, {
|
2020-01-01 13:17:19 +08:00
|
|
|
|
_: new Date().getTime()
|
|
|
|
|
}, function(res){
|
|
|
|
|
if(res.status === 0 && res.count > 0){
|
|
|
|
|
var msg = $('<a class="fly-nav-msg" href="javascript:;">'+ res.count +'</a>');
|
|
|
|
|
elemUser.append(msg);
|
|
|
|
|
msg.on('click', function(){
|
2020-04-22 18:37:53 +08:00
|
|
|
|
fly.json(messageRead, {}, function(res){
|
2020-01-01 13:17:19 +08:00
|
|
|
|
if(res.status === 0){
|
2022-08-02 21:13:36 +08:00
|
|
|
|
location.href = res.url;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
layer.tips('你有 '+ res.count +' 条未读消息', msg, {
|
|
|
|
|
tips: 3
|
|
|
|
|
,tipsMore: true
|
|
|
|
|
,fixed: true
|
|
|
|
|
});
|
|
|
|
|
msg.on('mouseenter', function(){
|
|
|
|
|
layer.closeAll('tips');
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return arguments.callee;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//手机绑定弹窗
|
|
|
|
|
,setPhoneNotice: function(){
|
|
|
|
|
layer.open({
|
|
|
|
|
type: 1
|
|
|
|
|
,id: 'LAY_Notice_add'
|
|
|
|
|
,title: '手机号绑定通知'
|
|
|
|
|
,content: '<div class="layui-text" style="padding: 20px;">您需要绑定手机号后,才可进行发帖/回帖等操作。</div>'
|
|
|
|
|
,btnAlign: 'c'
|
|
|
|
|
,btn: ['立即绑定', '朕偏不!']
|
|
|
|
|
,yes: function(){
|
|
|
|
|
location.href = '/user/set'
|
|
|
|
|
}
|
|
|
|
|
,btn2: function(){
|
|
|
|
|
layer.msg('少年,我看好你!');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//邮箱激活提示
|
|
|
|
|
,setEmailNotice: function(){
|
|
|
|
|
layer.open({
|
|
|
|
|
type: 1
|
|
|
|
|
,id: 'LAY_Notice_add'
|
|
|
|
|
,title: '邮箱激活通知'
|
|
|
|
|
,content: '<div class="layui-text" style="padding: 20px;">您需要激活邮箱后,才可进行发帖/回帖等操作。</div>'
|
|
|
|
|
,btnAlign: 'c'
|
|
|
|
|
,btn: ['前往激活', '朕偏不!']
|
|
|
|
|
,yes: function(){
|
|
|
|
|
location.href = '/user/set'
|
|
|
|
|
}
|
|
|
|
|
,btn2: function(){
|
|
|
|
|
layer.msg('少年,我看好你!');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-02 18:49:40 +08:00
|
|
|
|
};
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
//加载扩展模块
|
2022-09-23 10:59:41 +08:00
|
|
|
|
// layui.config({
|
|
|
|
|
// base: fly.dir
|
|
|
|
|
// }).extend({
|
|
|
|
|
// im: 'im'
|
|
|
|
|
// ,face: 'face'
|
|
|
|
|
// });
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
//头像
|
|
|
|
|
if(device.android || device.ios){
|
|
|
|
|
$('#LAY_header_avatar').on('click', function(){
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//刷新图形验证码
|
2021-05-22 18:33:26 +08:00
|
|
|
|
$('body').on('click', '#captcha111', function(){
|
|
|
|
|
var othis = $(this);
|
|
|
|
|
othis.attr('src', othis.attr('src')+'?'+ new Date().getTime());
|
|
|
|
|
//console.log(othis.attr('src'));
|
2020-01-01 13:17:19 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//签到
|
2022-08-02 18:49:40 +08:00
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//活跃榜
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
//相册
|
|
|
|
|
if($(window).width() > 750){
|
|
|
|
|
layer.photos({
|
|
|
|
|
photos: '.photos'
|
|
|
|
|
,zIndex: 9999999999
|
|
|
|
|
,anim: -1
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$('body').on('click', '.photos img', function(){
|
|
|
|
|
window.open(this.src);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//搜索
|
2022-08-02 21:13:36 +08:00
|
|
|
|
$('.fly-search').on('click', function(data){
|
|
|
|
|
var searchUrl = $('.fly-search').attr('data-url');
|
|
|
|
|
var forms = '<form action='+ searchUrl + '>';
|
2020-01-01 13:17:19 +08:00
|
|
|
|
layer.open({
|
|
|
|
|
type: 1
|
|
|
|
|
,title: false
|
|
|
|
|
,closeBtn: false
|
2022-08-02 21:13:36 +08:00
|
|
|
|
,shade: [0.1, '#fff']
|
2020-01-01 13:17:19 +08:00
|
|
|
|
,shadeClose: true
|
|
|
|
|
,maxWidth: 10000
|
|
|
|
|
,skin: 'fly-layer-search'
|
2022-08-02 21:13:36 +08:00
|
|
|
|
,content: [forms
|
2020-01-01 13:17:19 +08:00
|
|
|
|
,'<input autocomplete="off" placeholder="搜索内容,回车跳转" type="text" name="keywords">'
|
|
|
|
|
,'</form>'].join('')
|
|
|
|
|
,success: function(layero){
|
|
|
|
|
var input = layero.find('input');
|
|
|
|
|
input.focus();
|
|
|
|
|
|
|
|
|
|
layero.find('form').submit(function(){
|
|
|
|
|
var val = input.val();
|
|
|
|
|
if(val.replace(/\s/g, '') === ''){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
input.val();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
2021-07-22 10:48:06 +08:00
|
|
|
|
|
|
|
|
|
//移动端搜索
|
|
|
|
|
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
//新消息通知
|
|
|
|
|
fly.newmsg();
|
|
|
|
|
|
|
|
|
|
//发送激活邮件
|
|
|
|
|
fly.activate = function(email){
|
2021-08-07 15:50:50 +08:00
|
|
|
|
fly.json(actvateEmaiUrl, {"email":email}, function(res){
|
2020-01-01 13:17:19 +08:00
|
|
|
|
if(res.status === 0){
|
|
|
|
|
layer.alert('已成功将激活链接发送到了您的邮箱,接受可能会稍有延迟,请注意查收。', {
|
|
|
|
|
icon: 1
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
$('#LAY-activate').on('click', function(){
|
|
|
|
|
fly.activate($(this).attr('email'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//点击@
|
|
|
|
|
$('body').on('click', '.fly-aite', function(){
|
|
|
|
|
var othis = $(this), text = othis.text();
|
|
|
|
|
if(othis.attr('href') !== 'javascript:;'){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
text = text.replace(/^@|([\s\S]+?)/g, '');
|
|
|
|
|
othis.attr({
|
2021-06-17 14:25:48 +08:00
|
|
|
|
href: jumpUrl + '?name=' + text
|
2020-01-01 13:17:19 +08:00
|
|
|
|
,target: '_blank'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//表单提交
|
|
|
|
|
form.on('submit(*)', function(data){
|
|
|
|
|
var action = $(data.form).attr('action'), button = $(data.elem);
|
|
|
|
|
fly.json(action, data.field, function(res){
|
|
|
|
|
var end = function(){
|
|
|
|
|
if(res.action){
|
|
|
|
|
location.href = res.action;
|
|
|
|
|
} else {
|
|
|
|
|
fly.form[action||button.attr('key')](data.field, data.form);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if(res.status == 0){
|
|
|
|
|
button.attr('alert') ? layer.alert(res.msg, {
|
|
|
|
|
icon: 1,
|
|
|
|
|
time: 10*1000,
|
|
|
|
|
end: end
|
|
|
|
|
}) : end();
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
//return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//加载特定模块
|
|
|
|
|
if(layui.cache.page && layui.cache.page !== 'index'){
|
|
|
|
|
var extend = {};
|
|
|
|
|
extend[layui.cache.page] = layui.cache.page;
|
|
|
|
|
layui.extend(extend);
|
|
|
|
|
layui.use(layui.cache.page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//加载IM
|
|
|
|
|
if(!device.android && !device.ios){
|
|
|
|
|
//layui.use('im');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//加载编辑器
|
2024-04-14 12:08:53 +08:00
|
|
|
|
|
2021-05-24 15:05:30 +08:00
|
|
|
|
|
2022-08-02 21:13:36 +08:00
|
|
|
|
//手机设备的简单适配 用户中心底部左侧栏导航
|
2020-01-01 13:17:19 +08:00
|
|
|
|
var treeMobile = $('.site-tree-mobile')
|
|
|
|
|
,shadeMobile = $('.site-mobile-shade')
|
|
|
|
|
|
|
|
|
|
treeMobile.on('click', function(){
|
|
|
|
|
$('body').addClass('site-mobile');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
shadeMobile.on('click', function(){
|
|
|
|
|
$('body').removeClass('site-mobile');
|
|
|
|
|
});
|
2021-05-16 15:39:22 +08:00
|
|
|
|
|
2021-07-22 10:48:06 +08:00
|
|
|
|
//手机设备的简单适配 头部左侧栏导航
|
|
|
|
|
var treeMobileTop = $('.site-tree-mobile-top')
|
|
|
|
|
,shadeMobileTop = $('.site-mobile-shade-top')
|
|
|
|
|
|
|
|
|
|
treeMobileTop.on('click', function(){
|
|
|
|
|
$('body').addClass('site-mobile');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
shadeMobileTop.on('click', function(){
|
|
|
|
|
$('body').removeClass('site-mobile');
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-16 15:39:22 +08:00
|
|
|
|
//导航窗口scroll
|
|
|
|
|
;!function(){
|
|
|
|
|
var main = $('.site-menu'), scroll = function(){
|
|
|
|
|
var stop = $(window).scrollTop();
|
|
|
|
|
|
|
|
|
|
if($(window).width() <= 992) return;
|
2022-09-23 11:03:10 +08:00
|
|
|
|
var bottom = $('.footer').offset().top - $(window).height();
|
2021-05-16 15:39:22 +08:00
|
|
|
|
|
|
|
|
|
if(stop > 60){ //211
|
|
|
|
|
if(!main.hasClass('site-fix')){
|
|
|
|
|
main.addClass('site-fix').css({
|
|
|
|
|
width: main.parent().width()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
if(main.hasClass('site-fix')){
|
|
|
|
|
main.removeClass('site-fix').css({
|
|
|
|
|
width: 'auto'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
stop = null;
|
|
|
|
|
};
|
|
|
|
|
scroll();
|
|
|
|
|
$(window).on('scroll', scroll);
|
|
|
|
|
}();
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
//获取统计数据
|
|
|
|
|
$('.fly-handles').each(function(){
|
|
|
|
|
var othis = $(this);
|
|
|
|
|
$.get('/api/handle?alias='+ othis.data('alias'), function(res){
|
|
|
|
|
othis.html('(下载量:'+ res.number +')');
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//添加文章
|
|
|
|
|
$('#add_post').click(function() {
|
|
|
|
|
if (layui.cache.user.uid !== -1) {
|
|
|
|
|
loading = layer.load(2, {
|
|
|
|
|
shade: [0.2, '#000']
|
2022-08-02 18:49:40 +08:00
|
|
|
|
});
|
|
|
|
|
location.href = articleAdd;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
layer.msg('请先登陆',{
|
|
|
|
|
icon:5,
|
|
|
|
|
time:2000
|
|
|
|
|
},function () {
|
2020-04-24 15:07:26 +08:00
|
|
|
|
location.href = login;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//退出登录
|
|
|
|
|
$('.logi_logout').click(function() {
|
|
|
|
|
loading = layer.load(2, {
|
|
|
|
|
shade: [0.2, '#000']
|
|
|
|
|
});
|
|
|
|
|
var url = $(this).data('url');
|
|
|
|
|
$.getJSON(url, function(data) {
|
|
|
|
|
if (data.code == 200) {
|
|
|
|
|
layer.close(loading);
|
|
|
|
|
layer.msg(data.msg, { icon: 1, time: 1000 }, function() {
|
2021-08-03 17:33:48 +08:00
|
|
|
|
location.href = data.url;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
layer.close(loading);
|
|
|
|
|
layer.msg(data.msg, { icon: 2, anim: 6, time: 1000 });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-11-02 15:41:31 +08:00
|
|
|
|
|
2021-07-22 10:48:06 +08:00
|
|
|
|
//pc端监听多语言切换
|
2020-11-02 21:54:26 +08:00
|
|
|
|
$('#language').on('change',function(){
|
|
|
|
|
var data = $(this).val();
|
|
|
|
|
$.post(langUrl,{language:data},function(res){
|
|
|
|
|
if(res.code == 0){
|
|
|
|
|
location.reload();
|
|
|
|
|
}
|
2020-11-02 15:41:31 +08:00
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2022-08-02 21:13:36 +08:00
|
|
|
|
|
2021-07-22 10:48:06 +08:00
|
|
|
|
//移动端左侧栏监听多语言切换
|
|
|
|
|
$('#language1').on('change',function(){
|
|
|
|
|
var data = $(this).val();
|
|
|
|
|
$.post(langUrl,{language:data},function(res){
|
|
|
|
|
if(res.code == 0){
|
|
|
|
|
location.reload();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2020-01-01 13:17:19 +08:00
|
|
|
|
|
|
|
|
|
//固定Bar
|
|
|
|
|
util.fixbar({
|
|
|
|
|
bar1: ''
|
|
|
|
|
,bgcolor: '#009688'
|
2022-11-18 10:31:44 +08:00
|
|
|
|
,css: {right: 10, bottom: 50}
|
2020-01-01 13:17:19 +08:00
|
|
|
|
,click: function(type){
|
2020-11-02 15:41:31 +08:00
|
|
|
|
//添加文章
|
2020-01-01 13:17:19 +08:00
|
|
|
|
if(type === 'bar1'){
|
|
|
|
|
//slayer.msg('打开 index.js,开启发表新帖的路径');
|
2020-04-24 15:07:26 +08:00
|
|
|
|
location.href = articleAdd;
|
2020-01-01 13:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
exports('fly', fly);
|
|
|
|
|
});
|
|
|
|
|
|