';
$("body").append(s);
// var content = _xy_cms.content_id ? $("#post-" + _xy_cms.content_id + " .entry-summary p").html() : $(this).closest(".kx-item").find(".kx-details").html();
var content = _xy_cms.content_id ? $("#post-" + _xy_cms.content_id).html() : $(this).closest(".kx-item").find(".kx-details").html();
content = cleanArticleContent(content);
var qrcode = "";
var t = $(this).parent().find(".j-share-qrcode");
if (t && t.find('canvas')[0]) {
qrcode = t.find('canvas')[0].toDataURL();
} else {
var _qr = $('
');
$("body").append(_qr);
var link = $(this).data("qrcode") ? $(this).data("qrcode") : locations.href;
_qr.qrcode({
text: link
});
qrcode = _qr.find("canvas")[0].toDataURL();
}
var html = ''
+ '
请长按保存图片,将内容分享给更多好友
'
+ '
'
+ '
'
+ '
'
+ '
'
+ '
' + $(this).data('title') + ''
+ '
'
+ '
'
+ '
'
+ '
' + content + '
'
+ '
______________________________________
'
+ '
'
+ ' '
+ '
'
+ '
'
+ '
'
+ '
';
$(".mobiles-share-wrap").html(html);
setTimeout(function () {
html2canvas(document.querySelector(".mobiles-share-inner"), {
scale: 2,
useCORS: true,
scrollY: 0,
backgroundColor: null
}).then((function (e) {
let a = e.toDataURL("image/png");
$(".mobiles-share-canvas").html('
');
$(".mobiles-share-wrap .top_tips").show();
$(".mobiles-share-inner").css("visibility", "hidden");
}))
}, 300);
}))
.on('click', '.btn-more-comment', (function () {
loadCommentList(this);
}))
.on('click', '.btn-more-reply', (function () {
loadCommentReplyList(this);
}))
.on('member_login_checked', function (e, data) {
// 会员登录了
window.is_login = true;
window.login_user = data;
var myInfoUrl = (_xy_cms.preview ? _xy_cms.api_prefix : _xy_cms.prefix) + 'account/setting';
if (_xy_cms.preview) {
myInfoUrl += '?preview=true&sid=' + _xy_cms.site_id + "&pp=" + _xy_cms.publish_pipe;
}
$(".footer-bar .footer-bar-user a").attr("href", myInfoUrl)
// 会员文章
if (_xy_cms.memberId && _xy_cms.memberId === data.memberId) {
$("#contribute-list .item-content").addClass("item-edit").toArray().forEach(item => {
var cid = $(item).closest("li.item").attr("data-id");
var status = $(item).closest("li.item").attr("data-st");
if (status === '0') {
$(item).find(".item-title a").prepend("
【待审核】 ");
var editLink = (_xy_cms.preview ? _xy_cms.api_prefix : _xy_cms.prefix) + 'account/contribute?cid=' + cid;
if (_xy_cms.preview) {
editLink += '&preview=true&sid=' + _xy_cms.site_id + '&pp=' + _xy_cms.publish_pipe;
}
$(item).prepend('
编辑 ');
$(item).prepend('
删除 ');
}
})
}
// 评论
$("form.comment-form").show();
if ($(".login-user").find("img").length > 0 && data.avatar && data.avatar.length > 0) {
$(".login-user").find("img").attr("src", data.avatar)
}
if ($(".login-user").find("span").length > 0) {
$(".login-user").find("span").html(data.displayName)
}
// 点赞
if ($(".btn-zan1").length > 0) {
checkLike($(".btn-zan1"))
}
// 收藏
if ($(".j-heart1").length > 0) {
checkFavorite($(".j-heart1"))
}
// 关注
var followBtns = $(".check-follow");
if (followBtns.length > 0) {
checkFollow(followBtns);
}
})
.on('member_not_login', function (e, res) {
// 会员未登录
window.is_login = false;
$(".footer-bar .footer-bar-user a").addClass("btn-login")
// 评论
$("div.comment-form").show();
});
deleteMemberContribute = function (ele) {
ele.loading(1);
$.ajax({
type: "post",
url: _xy_cms.api_prefix + "api/account/contribute/delete?cid=" + ele.closest("li.item").attr("data-id"),
headers: getTokenHeaders(),
contentType: "application/json;charset=UTF-8",
dataType: 'json',
success: function (res) {
ele.loading(0);
if (res.code == 200) {
window.locations.reload();
} else {
wpcom_notice({ message: res.msg, type: "error", show: 1500 })
}
},
error: function () {
ele.loading(0);
}
})
}
loadMemberCommentList = function (ele) {
var uid = ele.attr("data-uid")
var params = { type: "cms_content" };
var limit = ele.attr("data-limit");
if (!limit) {
limit = 10;
};
params.limit = limit;
var offset = ele.attr("data-offset");
if (offset) params.offset = offset;
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/comment/user/" + uid,
data: params,
dataType: 'json',
success: function (res) {
if (res.code == 200) {
if (res.data.length == 0) {
ele.addClass("disabled").removeClass('btn-content-more').html("已经到底了");
return;
}
ele.attr("data-offset", res.data[res.data.length - 1].commentId);
res.data.forEach(item => {
var html = '';
ele.parent().parent().find(".comment-list").append(html);
});
if (res.data.length < parseInt(limit)) {
ele.addClass("disabled").removeClass('btn-content-more').html("已经到底了");
} else {
ele.addClass("btn-content-more").remove("disbaled").html('点击加载更多');
}
} else {
wpcom_notice({ message: res.msg, type: "error", show: 1500 })
}
}
})
}
loadContentList = function (ele) {
if (ele.hasClass("disbaled")) {
console.log("All content loaded!")
return;
}
var params = {};
params['sid'] = _xy_cms.site_id;
params['pp'] = _xy_cms.publish_pipe;
if (_xy_cms.preview) params['preview'] = true;
var lv = ele.attr("data-lv");
if (!isBlank(lv)) params['lv'] = lv;
var cid = ele.attr("data-cid");
if (!isBlank(cid)) params['cid'] = cid;
var st = ele.attr("data-st");
if (!isBlank(st)) params['st'] = st;
var ps = ele.attr("data-ps");
if (!isBlank(ps)) {
params['ps'] = ps
} else {
ps = 16;
};
var pn = ele.attr("data-pn");
if (!isBlank(pn)) params['pn'] = pn;
ele.removeClass("btn-content-more").addClass("disabled").html('
正在加载...');
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/cms/content/list",
data: params,
dataType: 'json',
success: function (res) {
if (res.code == 200) {
if (res.data.length == 0) {
ele.addClass("disabled").removeClass('btn-content-more').html("已经到底了");
return;
}
ele.attr("data-pn", isBlank(pn) ? "2" : parseInt(pn) + 1);
res.data.forEach(item => {
var logoSrc = "";
if (item.imagesSrc && item.imagesSrc.length > 0) {
logoSrc = item.imagesSrc[0];
}
var html = '
';
if (!isBlank(logoSrc)) {
html += ''
+ ' '
}
html += ' '
+ '
'
+ ' ';
if (item.topFlag > 0) {
html += ' 置顶 '
}
html += item.title
+ ' '
+ ' '
+ '
'
+ '
' + (item.summary ? item.summary : '') + '
'
+ '
'
+ '
'
+ '
'
+ ' ';
ele.parent().parent().find(".content-list").append(html);
});
if (res.data.length < parseInt(ps)) {
ele.addClass("disabled").removeClass('btn-content-more').html("已经到底了");
} else {
ele.addClass("btn-content-more").remove("disbaled").html('点击加载更多');
}
} else {
wpcom_notice({ message: res.msg, type: "error", show: 1500 })
}
}
})
}
loadKuaiXunList = function (ele) {
if (ele.hasClass("disbaled")) {
console.log("All kuaixun loaded!")
return;
}
var params = {};
params['sid'] = _xy_cms.site_id;
params['pp'] = _xy_cms.publish_pipe;
if (_xy_cms.preview) params['preview'] = true;
var lv = ele.attr("data-lv");
if (!isBlank(lv)) params['lv'] = lv;
var cid = ele.attr("data-cid");
if (!isBlank(cid)) params['cid'] = cid;
var st = ele.attr("data-st");
if (!isBlank(st)) params['st'] = st;
var ps = ele.attr("data-ps");
if (!isBlank(ps)) {
params['ps'] = ps
} else {
ps = 16;
};
var pn = ele.attr("data-pn");
if (!isBlank(pn)) params['pn'] = pn;
var text = ele.attr("data-text");
if (!isBlank(text)) params['text'] = text;
ele.removeClass("btn-kx-more").addClass("disabled").html('
正在加载...');
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/cms/article/list",
data: params,
dataType: 'json',
success: function (res) {
if (res.code == 200) {
if (res.data.length == 0) {
ele.addClass("disabled").removeClass('btn-kx-more').html("已经到底了");
return;
}
ele.attr("data-pn", isBlank(pn) ? "2" : parseInt(pn) + 1);
res.data.forEach(item => {
var pdate = dateFormatCN(item.publishDate, 'date');
var html = "";
if (!_xy_cms.kx_pdate || _xy_cms.kx_pdate !== pdate) {
html += '
' + pdate + '
';
_xy_cms.kx_pdate = pdate
}
html += '
'
+ '
' + dateFormat(item.publishDate, 'time') + ' '
+ '
'
+ '
' + item.title + ' '
+ '
' + item.contentHtml + '
'
+ '
'
+ '
'
+ '
';
var i = $(html)
_wshare.init2(i)
ele.parent().before(i);
});
if (res.data.length < parseInt(ps)) {
ele.addClass("disabled").removeClass('btn-kx-more').html("已经到底了");
} else {
ele.addClass("btn-kx-more").remove("disbaled").html('点击加载更多');
}
} else {
wpcom_notice({ message: res.msg, type: "error", show: 1500 })
}
}
})
}
saveMemberInfo = function () {
var nickName = $("#member-account-form input#nickName").val();
var slogan = $("#member-account-form textarea#slogan").val();
if (isBlank(nickName)) {
wpcom_notice({ message: '昵称不能为空', type: "error", show: 1500 })
return;
}
if (nickName.length > 20) {
wpcom_notice({ message: '昵称不能超过20个字符', type: "error", show: 1500 })
return;
}
if (slogan && slogan.length > 200) {
wpcom_notice({ message: '个人介绍不能超过200个字符', type: "error", show: 1500 })
return;
}
$(".btn-setting-save").loading(1);
$.ajax({
type: "post",
url: _xy_cms.api_prefix + "api/member/info",
headers: getTokenHeaders(),
contentType: "application/json;charset=UTF-8",
data: JSON.stringify({
nickName: nickName,
slogan: slogan,
}),
dataType: 'json',
success: function (res) {
$(".btn-setting-save").loading(0);
if (res.code == 200) {
wpcom_notice({ message: "保存成功", type: "success", show: 1500 })
} else {
wpcom_notice({ message: res.msg, type: "error", show: 1500 })
}
}
})
}
sendSmsCode = function (ele) {
if (_xy_cms.sms_seconds && _xy_cms.sms_seconds > 0) {
return;
}
ele.html("发送中...")
ele.loading(1)
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/sms_code",
headers: getTokenHeaders(),
dataType: 'json',
success: function (res) {
ele.loading(0)
if (res.code == 200) {
wpcom_notice({ message: "发送成功", type: "success", show: 1500 })
ele.html("60秒后重试")
_xy_cms.sms_seconds = 60;
var interval = setInterval(function () {
_xy_cms.sms_seconds--;
ele.html(_xy_cms.sms_seconds + "秒后重试");
if (_xy_cms.sms_seconds 0) {
$(".art-author img.avatar").attr("src", data.contributor.avatarSrc)
}
if (data.contributor.cover && data.contributor.cover.length > 0) {
$(".art-author .profile-cover img").attr("src", data.contributor.cover)
}
if (data.contributor.slogan && data.contributor.slogan.length > 0) {
$(".art-author .author-description").html(data.contributor.slogan)
} else {
$(".art-author .author-description").html("这个家伙很懒,什么都没有留下!")
}
$(".art-author #author-arts b").html(data.contributor.stat.contribute ? data.contributor.stat.contribute : 0);
$(".art-author #author-comments b").html(data.contributor.stat.comment ? data.contributor.stat.comment : 0);
$(".art-author #author-followers b").html(data.contributor.stat.follower ? data.contributor.stat.follower : 0);
$(".art-author .btn-follow").attr("data-user", data.contributorId);
// 关注
if (window.is_login) {
if (window.login_user.memberId == data.contributorId) {
$(".art-author .btn-follow").addClass("disabled");
} else {
checkFollow($(".art-author .btn-follow"))
}
}
}
$("#views-" + contentId).html("阅读 " + data.views)
$(".j-heart1 .data").html(data.favorites)
$(".btn-zan1 .entry-action-num").html(data.likes)
$(".j-comment .data").html(data.comments)
}
}
})
}
loadContentListDynamicDatas = function (eles) {
var contentIds = eles.map((index, item) => {
return $(item).attr("data-id")
});
if (contentIds.length == 0) {
return;
}
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/cms/contentex/data",
dataType: 'json',
data: {
ids: contentIds.toArray().join(",")
},
success: function (res) {
if (res.code == 200) {
eles.toArray().forEach(ele => {
var e = $(ele);
var cid = e.attr("data-id");
var data = res.data.find(item => item.contentId == cid)
if (data) {
e.find(".likes").append(data.likes);
e.find(".views").append(data.views);
if (data.contributor) {
var ulink = (_xy_cms.preview ? _xy_cms.api_prefix : _xy_cms.prefix) + 'account/' + data.contributorId;
if (_xy_cms.preview) {
ulink += "?sid=" + _xy_cms.site_id + "&pp=" + _xy_cms.publish_pipe + "&preview=" + true;
}
var html = '
';
e.find('.item-meta .item-meta-li.author').remove();
e.find(".item-meta").prepend(html)
}
}
})
} else {
eles.toArray().forEach(ele => {
var e = $(ele);
e.find(".likes").append("0");
e.find(".views").append("0");
})
}
}
})
}
// 提交评论
// dataId: 文章内容ID
// content: 评论内容
// replyCommentId: 回复的评论ID
submitComment = function (dataId, content, ele) {
if (!content || content.length == 0) {
wpcom_notice({ message: "请填写评论内容", type: "warning", show: 1500 })
return;
}
ele.loading(1)
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/comment/submit",
headers: getTokenHeaders(),
contentType: "application/json;charset=UTF-8",
data: JSON.stringify({
sourceType: 'cms_content',
sourceId: dataId,
content: content
}),
dataType: 'json',
success: function (res) {
ele.loading(0)
if (res.code == 200) {
if (res.data.auditStatus !== 1) {
wpcom_notice({ message: "提交成功,请耐心等待审核。", type: "success", show: 1500 })
} else {
wpcom_notice({ message: "提交成功。", type: "success", show: 1500 })
}
}
}
})
}
applyReplyForm = function (ele) {
var eleReply = $(ele).parent().parent().next(".comment-respond");
if (eleReply.length > 0) {
eleReply.remove();
return;
}
if ($(".comment-reply").length > 0) {
$(".comment-reply").toArray().forEach(e => $(e).remove())
}
var commentId = $(ele).attr("comment-id");
var contentId = $(ele).attr("data-id");
var replyUid = $(ele).attr("data-uid");
var html = '';
$(ele).parent().parent().after(html);
}
submitReplyComment = function (dataId, commentId, replyUid, content, ele) {
if (!content || content.length == 0) {
wpcom_notice({ message: "请填写评论内容", type: "warning", show: 1500 })
return;
}
if (!commentId || commentId.length == 0) {
submitComment(dataID, content);
return;
}
ele.loading(1)
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/comment/submit",
headers: getTokenHeaders(),
contentType: "application/json;charset=UTF-8",
data: JSON.stringify({
sourceType: 'cms_content',
sourceId: dataId,
commentId: commentId,
replyUid: replyUid,
content: content
}),
dataType: 'json',
success: function (res) {
ele.loading(0)
if (res.code == 200) {
$(".comment-reply").toArray().forEach(e => $(e).remove())
if (res.data.auditStatus !== 1) {
wpcom_notice({ message: "提交成功,请耐心等待审核。", type: "success", show: 1500 })
} else {
wpcom_notice({ message: "提交成功。", type: "success", show: 1500 })
}
}
}
})
}
// 获取评论列表
loadCommentList = function (ele) {
var $el = $(ele);
if ($el.hasClass("disabled")) {
return;
}
var dataId = $el.attr("data-id");
var offset = $el.data("offset") ? $el.data("offset") : 0
$el.loading(1);
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/comment/cms_content/" + dataId,
data: {
offset: offset
},
dataType: 'json',
success: function (res) {
$el.loading(0);
if (res.code == 200 && res.data && res.data.length > 0) {
res.data.forEach(row => {
var html = '';
$(".comments-list").append(html);
$el.data("offset", row.commentId)
});
if (res.data.length 0) {
res.data.forEach(reply => {
var html = '';
$el.before(html);
$el.data("offset", reply.commentId);
});
if (res.data.length < 10) {
$el.remove();
}
} else {
$el.remove();
}
}
})
}
checkFollow = function (eles) {
if (!window.is_login) {
return;
}
var targetUids = eles.toArray().map(item => $(item).attr("data-user"))
if (!targetUids || targetUids.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/member/check_follow",
headers: getTokenHeaders(),
data: {
targetIds: targetUids.join(",")
},
dataType: 'json',
success: function (res) {
if (res.code == 200) {
eles.toArray().forEach(ele => {
if (res.data[$(ele).attr("data-user")]) {
$(ele).removeClass("btn-primary").addClass("followed").html("已关注");
}
})
}
}
})
}
// 关注
followUser = function (ele) {
var uid = ele.attr("data-user");
if (!uid || uid.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
ele.html('
关注');
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/follow",
headers: getTokenHeaders(),
data: {
targetId: uid
},
dataType: 'json',
success: function (res) {
if (res.code == 200) {
ele.removeClass("btn-primary").addClass("followed").html("已关注");
} else {
wpcom_notice({ message: res.msg, type: "warning", show: 1500 })
ele.html('
关注');
}
}
})
}
// 取消关注
cancelFollowUser = function (ele) {
var uid = ele.attr("data-user");
if (!uid || uid.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
ele.html('
已关注');
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/cancel_follow",
headers: getTokenHeaders(),
data: {
targetId: uid
},
dataType: 'json',
success: function (res) {
if (res.code == 200) {
ele.removeClass("followed").addClass("btn-primary").html('
关注');
}
}
})
}
// 是否收藏过指定内容
checkFavorite = function (ele) {
var contentId = ele.attr("data-id");
if (!contentId || contentId.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/member/favorites/check",
dataType: 'json',
headers: getTokenHeaders(),
data: {
dataType: 'cms_content',
dataId: contentId,
},
success: function (res) {
if (res.code == 200 && res.data) {
ele.addClass("stared");
ele.find(".wi").removeClass("wi-star").addClass("wi-star-fill")
}
}
})
}
// 收藏
favoriteContent = function (ele) {
var contentId = ele.attr("data-id");
if (!contentId || contentId.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/favorites",
headers: getTokenHeaders(),
contentType: 'application/json',
data: JSON.stringify({
dataType: 'cms_content',
dataId: contentId,
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
wpcom_notice({ message: "收藏成功", type: "success", show: 1500 })
ele.addClass("stared");
ele.find("span").html(parseInt(ele.find("span").html()) + 1)
ele.find(".wi").removeClass("wi-star").addClass("wi-star-fill")
}
}
})
}
// 取消收藏
cancelFavoriteContent = function (ele) {
var contentId = ele.attr("data-id");
if (!contentId || contentId.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "post",
url: _xy_cms.api_prefix + "api/member/favorites/cancel",
headers: getTokenHeaders(),
contentType: 'application/json',
data: JSON.stringify({
dataType: 'cms_content',
dataId: contentId,
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
wpcom_notice({ message: "取消收藏成功", type: "success", show: 1500 })
ele.removeClass("stared");
ele.find("span").html(parseInt(ele.find("span").html()) - 1)
ele.find(".wi").removeClass("wi-star-fill").addClass("wi-star")
}
}
})
}
// 是否点赞过指定内容
checkLike = function (ele) {
var contentId = ele.attr("data-id");
if (!contentId || contentId.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/member/like/check",
dataType: 'json',
headers: getTokenHeaders(),
data: {
dataType: 'cms_content',
dataId: contentId,
},
success: function (res) {
if (res.code == 200 && res.data) {
ele.addClass("liked");
}
}
})
}
// 点赞
likeContent = function (ele) {
var contentId = ele.attr("data-id");
if (!contentId || contentId.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/like",
headers: getTokenHeaders(),
contentType: 'application/json',
data: JSON.stringify({
dataType: 'cms_content',
dataId: contentId,
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
wpcom_notice({ message: "点赞成功", type: "success", show: 1500 })
ele.addClass("liked")
var eleNum = ele.find(".entry-action-num");
eleNum.html(parseInt(eleNum.html()) + 1)
}
}
})
}
// 取消点赞
cancelLikeContent = function (ele) {
var contentId = ele.attr("data-id");
if (!contentId || contentId.length == 0) {
// wpcom_notice({ message: "no content", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "post",
url: _xy_cms.api_prefix + "api/member/like/cancel",
headers: getTokenHeaders(),
contentType: 'application/json',
data: JSON.stringify({
dataType: 'cms_content',
dataId: contentId,
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
wpcom_notice({ message: "取消点赞成功", type: "success", show: 1500 })
ele.removeClass("liked")
var eleNum = ele.find(".entry-action-num");
eleNum.html(parseInt(eleNum.html()) - 1)
}
}
})
}
// 文章动态数据获取
// 文章详情页作者动态信息
memberInfo = function (ele) {
var memberId = ele.attr("data-id");
if (!memberId || memberId.length == 0) {
// wpcom_notice({ message: "no member", type: "warning", show: 1500 })
return;
}
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/cms/member/" + memberId + "/data",
contentType: 'application/json',
dataType: 'json',
success: function (res) {
if (res.code == 200) {
}
}
});
}
// 登录
memberLogin = function () {
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/login",
contentType: 'application/json',
data: JSON.stringify({
username: $('#login-form input#user_login').val(),
password: $('#login-form input#user_password').val(),
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
$.cookie("Authorization-M", res.data, { expires: 7, path: '/' });
window.locations.reload();
} else {
wpcom_notice({
message: res.msg,
type: "warning",
show: 1500
});
}
}
});
}
// 注册
memberRegister = function () {
var pwd = $('#register-form input#user_pass').val();
if (!pwd || pwd.lenght === 0) {
wpcom_notice({ message: "密码不能为空", type: "warning", show: 1500 });
}
if (pwd !== $('#register-form input#user_pass2').val()) {
wpcom_notice({ message: "两次密码不一致!", type: "warning", show: 1500 });
return;
}
let mode = $('.tab-btn.active').data('mode');
if (mode === 'email') {
var email = $('#register-form input#user_email').val();
if (!validEmail(email)) {
wpcom_notice({ message: "邮箱格式不正确", type: "warning", show: 1500 });
return;
}
var authCode = $('#register-form input#auth_code').val();
if (!authCode || authCode.lenght === 0) {
wpcom_notice({ message: "验证码不能为空", type: "warning", show: 1500 });
}
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/register",
contentType: 'application/json',
headers: {
"uuid": $.cookie("uuid")
},
data: JSON.stringify({
type: "email",
email: email,
password: pwd,
authCode: authCode,
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
$.cookie("Authorization-M", res.data, { expires: 7, path: '/' });
window.locations.reload();
} else {
wpcom_notice({
message: res.msg,
type: "warning",
show: 1500
});
}
}
});
}else if (mode === 'phones') {
// 手机验证码逻辑
console.log($('#register-form input#phones').val())
var phones = $('#register-form input#user_phone').val();
if (!validPhoneNumber(phones)) {
wpcom_notice({ message: "请输入正确的手机号码", type: "warning", show: 1500 });
return;
}
var authCode = $('#register-form input#auth_code').val();
if (!authCode || authCode.lenght === 0) {
wpcom_notice({ message: "验证码不能为空", type: "warning", show: 1500 });
return
}
$.ajax({
type: "POST",
url: _xy_cms.api_prefix + "api/member/register",
contentType: 'application/json',
headers: {
"uuid": $.cookie("uuid")
},
data: JSON.stringify({
type: mode,
phonenumber: phones,
password: pwd,
authCode: authCode,
}),
dataType: 'json',
success: function (res) {
if (res.code == 200) {
$.cookie("Authorization-M", res.data, { expires: 7, path: '/' });
window.locations.reload();
} else {
wpcom_notice({
message: res.msg,
type: "warning",
show: 1500
});
}
}
});
}
}
sendRegisterSmsCode = function (ele) {
if (_xy_cms.sms_seconds && _xy_cms.sms_seconds > 0) {
return;
}
let mode = $('.tab-btn.active').data('mode');
if (mode =='email') {
var email = $('#register-form input#user_email').val();
if (!validEmail(email)) {
wpcom_notice({ message: "请输入正确的邮箱", type: "warning", show: 1500 });
return;
}
ele.html("发送中...")
ele.loading(1)
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/member/register_sms_code",
data: {
email: email
},
dataType: 'json',
success: function (res) {
ele.loading(0)
if (res.code == 200) {
$.cookie("uuid", res.data, { expires: 7, path: '/' });
wpcom_notice({ message: "发送成功", type: "success", show: 1500 })
ele.html("60秒后重试")
_xy_cms.sms_seconds = 60;
var interval = setInterval(function () {
_xy_cms.sms_seconds--;
ele.html(_xy_cms.sms_seconds + "秒后重试");
if (_xy_cms.sms_seconds '
+ '';
$("#header-user-wrap").html(html);
// window.is_login = true
$(document).trigger("member_login_checked", res.data);
} else {
// window.is_login = false
$(document).trigger("member_not_login", res);
}
}
});
}
getToken = function () {
return "Bearer " + $.cookie('Authorization-M');
}
getTokenHeaders = function () {
return { "Authorization-M": getToken() }
}
cleanArticleContent = function (html) {
const nonPTagRegex = /<[^>]*?(?:>(?!<[^>]*?>)[^<]*)*>/g;
const pTagRegex = /
]*?(?:>(?!<\/p[^>]*?>)[^>]*)*>/g;
html = html.replace(nonPTagRegex, '');
html = html.replace(pTagRegex, '
');
return html;
}
validEmail = function (email) {
var reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return reg.test(email)
}
validPhoneNumber = function (phoneNumber) {
var reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/
return reg.test(phoneNumber)
}
generateUUID = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
isBlank = function (value) {
return !value || value.trim().length == 0;
}
loadCaptcha = function () {
var captchaToken = generateUUID();
_xy_cms.captchaToken = captchaToken;
$.ajax({
type: "GET",
url: _xy_cms.api_prefix + "api/member/captcha?token=" + captchaToken,
dataType: 'json',
success: function(res) {
if (res.code == 200) {
$('#captcha_image').attr('src', 'data:image/gif;base64,' + res.data.image);
$('#captcha-wrapper').show();
} else {
_xy_cms.captchaToken = null;
}
},
error: function() {
_xy_cms.captchaToken = null;
}
});
}
dateFormatCN = function (millis, type) {
var date = new Date(parseInt(millis))
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (type === 'date') {
return year + '年' + (month < 10 ? '0' : '') + month + '月' + (day < 10 ? '0' : '') + day + '日';
} else if (type === 'time') {
return (hours < 10 ? '0' : '') + hours + '点' + (minutes < 10 ? '0' : '') + minutes + '分' + (seconds < 10 ? '0' : '') + seconds + '秒';
} else if (type === 'kx') {
return year + '年' + (month < 10 ? '0' : '') + month + '月' + (day < 10 ? '0' : '') + day + '日 ' + (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes;
} else {
return year + '年' + (month < 10 ? '0' : '') + month + '月' + (day < 10 ? '0' : '') + day + '日 ' + (hours < 10 ? '0' : '') + hours + '点' + (minutes < 10 ? '0' : '') + minutes + '分' + (seconds < 10 ? '0' : '') + seconds + '秒';
}
}
dateFormat = function (millis, type) {
var date = new Date(parseInt(millis))
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (type === 'date') {
return year + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day;
} else if (type === 'time') {
return (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
} else {
return year + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day + ' ' + (hours < 10 ? '0' : '') + hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
}
}
// >>>>>>>>初始化<<<<<<<<<
function init() {
// 检查登录
checkLogin();
// 如果有文章列表,需要动态加载文章阅览数和点赞数
var eleContentList = $(".content-list .item");
if (eleContentList.length > 0) {
loadContentListDynamicDatas(eleContentList);
}
// 详情页加载内容动态数据
var article = $(".main article[id|=post]")
if (article.length > 0) {
var contentId = article.attr("id").substring(5)
getContentDynamicData(contentId)
}
// 文章详情页动态加载评论
if ($("ul.comments-list").length > 0) {
$(".btn-more-comment").click()
}
// 快讯列表页定时请求新数据
if ($('.kx-list').lengnth > 0) {
if ($('.kx-list .kx-item').length > 0) {
_xy_cms.kx_pdate = $('.kx-list .kx-item').last().attr("data-pdate");
}
setInterval((function () {
let cid = $(".kx-main-list").attr("data-cid");
let t = $(".kx-main-list .kx-item2").first().attr("data-id");
$.ajax({
url: _xy_cms.api_prefix + 'api/content/newest',
data: {
cid: cid,
id: t
},
method: "GET",
dataType: "json",
success: function (res) {
if (res.code == 200 && parseInt(res.data) > 0) {
$(".kx-main-list .kx-new .new-num").html(res.data).parent().show()
}
}
})
}
), 1e4)
}
// 用户中心-评论
if ($(".btn-user-comment-more").length > 0) {
$(".btn-user-comment-more").click();
}
}
$(document).ready(init)
})(jQuery);
本站内容按公开信息整理,栏目与正文互为入口,便于对照阅读。
评论列表