新增片刻删除提示框、动画;修复异常;深度优化

This commit is contained in:
anian
2026-03-20 00:15:04 +08:00
parent ee5c1a2b5b
commit 5a3544f8df
9 changed files with 520 additions and 174 deletions
+167 -149
View File
@@ -1,13 +1,13 @@
main_content = $('.moment_type_main');
function remove_image_temp(){
if(!$('.image_edit_temp .add_img_box').length > 0){
function remove_image_temp() {
if (!$('.image_edit_temp .add_img_box').length > 0) {
var temp = $('.add_img_box');
$('.image_edit_temp').html(temp);
}
main_content.empty();
}
function back_image_temp(){
function back_image_temp() {
var temp = $('.add_img_box');
main_content.html(temp);
$('.image_edit_temp').empty();
@@ -58,7 +58,7 @@ $('body').on('click', '.edit_content .push_card', function () {
}
});
function card_post(card_url){
function card_post(card_url) {
$.ajax({
type: 'GET',
url: `/apis/api.console.halo.run/v1alpha1/posts?keyword=${card_url}&labelSelector=content.halo.run%2Fdeleted%3Dfalse&page=1&size=20`,
@@ -68,12 +68,12 @@ function card_post(card_url){
success: function (data) {
$('.edit_card_box .edit_content input').val('');
if (data.total > 0) {
if(data.total>1){
if (data.total > 1) {
cocoMessage.error('当前搜索的文章有多个无法选择');
}else{
} else {
var item = data.items[0]
$('.show_card').show();
$('.card_sortble').append(getcard(item.post.metadata.name,item.post.spec.cover,item.post.spec.title,'post'));
$('.card_sortble').append(getcard(item.post.metadata.name, item.post.spec.cover, item.post.spec.title, 'post'));
cocoMessage.success('已生成卡片');
}
@@ -86,7 +86,7 @@ function card_post(card_url){
}
function edit_page(card_url){
function edit_page(card_url) {
$.ajax({
type: 'GET',
url: `/apis/api.console.halo.run/v1alpha1/singlepages?keyword=${card_url}&labelSelector=content.halo.run%2Fdeleted%3Dfalse&page=1&size=20`,
@@ -96,12 +96,12 @@ function edit_page(card_url){
success: function (data) {
$('.edit_card_box .edit_content input').val('');
if (data.total > 0) {
if(data.total>1){
if (data.total > 1) {
cocoMessage.error('当前搜索的页面有多个无法选择');
}else{
} else {
var item = data.items[0]
$('.show_card').show();
$('.card_sortble').append(getcard(item.page.metadata.name,item.page.spec.cover,item.page.spec.title,'page'));
$('.card_sortble').append(getcard(item.page.metadata.name, item.page.spec.cover, item.page.spec.title, 'page'));
cocoMessage.success('已生成卡片');
}
@@ -113,7 +113,7 @@ function edit_page(card_url){
});
}
function getcard(name,cover,title,type){
function getcard(name, cover, title, type) {
return `<div class="moment_card_item" pid="${name}" type="${type}">
<a>
@@ -127,31 +127,25 @@ function getcard(name,cover,title,type){
</div>`
}
$(document).on('click', '.de_card', function() {
var msg = "确认删除此卡片?";
$(document).on('click', '.de_card', function () {
var num = $('.moment_card_item').length;
if (confirm(msg)==true){
$(this).parents('.moment_card_item').remove();
} else {
return false;
}
if(num == 1){
$(this).parents('.moment_card_item').remove();
if (num == 1) {
$(".show_card").hide();
}
});
//图文编辑 返回图文编辑区域
$('body').on('click', '.moment_image_type a', function() {
$('body').on('click', '.moment_image_type a', function () {
back_image_temp();
$('.push_item').attr('type','image');
$('.push_item').attr('type', 'image');
});
//发布音乐--------------------------------------------------------------
$('body').on('click', '.moment_audio_type a', function() {
$('.push_item').attr('type','audio');
$('body').on('click', '.moment_audio_type a', function () {
$('.push_item').attr('type', 'audio');
main_content = $('.moment_type_main');
if($('.add_audio_box').length > 0){
if ($('.add_audio_box').length > 0) {
return false;
}
remove_image_temp();
@@ -180,57 +174,57 @@ $('body').on('click', '.moment_audio_type a', function() {
});
//音乐和视频上传
$(document).on('change','#moment_img_up',function(){
if($('#moment_img_up').val() == '')
$(document).on('change', '#moment_img_up', function () {
if ($('#moment_img_up').val() == '')
return;
var f = this.files[0];
var formData = new FormData();
formData.append('file',f);
formData.append('file', f);
const policyName = Theme.moments.policy_name;
const groupName = Theme.moments.group_name;
policyName && formData.append('policyName',policyName)
groupName && formData.append('groupName',groupName)
policyName && formData.append('policyName', policyName)
groupName && formData.append('groupName', groupName)
$.ajax({
type: "POST",
url: `${Theme.moments.attachments_upload_api}`,
dataType: 'json',
dataType: 'json',
data: formData,
processData : false,
contentType : false,
processData: false,
contentType: false,
beforeSend: function () {
cocoMessage.info('上传中...');
$('.m_media_left i').remove();
$('.m_media_left').append("<div class='up_loading' uk-spinner='ratio: .6'></div>");
var imged = $('.m_media_left img');
if(imged.length > 0){
if (imged.length > 0) {
imged.remove();
}
},
success: function(data){
success: function (data) {
var thum = data.metadata.annotations["storage.halo.run/uri"] || data.metadata.annotations["storage.halo.run/external-link"]
$('.m_media_left .up_loading').remove();
$('.m_media_left').append('<img src="/themes/theme-pix/assets/img/video.png" data="'+thum+'">');
$('.m_media_left').append('<img src="/themes/theme-pix/assets/img/video.png" data="' + thum + '">');
cocoMessage.success('上传成功');
$('input#moment_video_url').val(thum)
}
});
});
$('body').on('click', '.audio_choose a', function() {
$('body').on('click', '.audio_choose a', function () {
var text = '# 请插入封面,歌名以及歌曲外链';
var type = $(this).attr('au_type');
if(type != 'local'){
if (type != 'local') {
var text = '# 请输入歌曲ID';
}
$('.edit_audio_box .tips').text(text);
});
//发布视频--------------------------------------------------------------
$('body').on('click', '.moment_video_type a', function() {
$('.push_item').attr('type','video');
$('body').on('click', '.moment_video_type a', function () {
$('.push_item').attr('type', 'video');
main_content = $('.moment_type_main');
if($('.add_video_box').length > 0){
if ($('.add_video_box').length > 0) {
return false;
}
remove_image_temp();
@@ -265,10 +259,10 @@ $('body').on('click', '.moment_video_type a', function() {
});
$('body').on('click', '.video_choose a', function() {
$('body').on('click', '.video_choose a', function () {
var text = '# 请上传视频或填写视频外链';
var type = $(this).attr('vi_type');
if(type == 'bili'){
if (type == 'bili') {
var text = '# 请输入B站视频bvid';
}
$('.edit_video_box .tips').text(text);
@@ -279,75 +273,91 @@ $('body').on('click', '.video_choose a', function() {
//});
//删除片刻文章
$('body').on('click', '.control_delete_post', function() {
var pid = $(this).parent().attr('pid');
//删除片刻
// 全局变量暂存当前要删除的 ID
window.currentDeletePid = null;
var msg = "确定删除瞬间?";
if (confirm(msg)==true){
$.ajax({
type: 'DELETE',
dataType: 'json',
url: `/apis/${Theme.moments.api}/v1alpha1/moments/`+pid,
contentType: "application/json",
beforeSend: function () {
cocoMessage.info('处理中..');
},
success: function (data) {
cocoMessage.success('删除成功');
setTimeout(()=>{
$(`#post-${pid}`)[0].remove()
},1000)
},
error: function (request) {
if(request.status){
cocoMessage.error('瞬间不存在或已删除');
}else{
cocoMessage.error('删除失败');
}
console.log(request)
},
});
} else {
return false;
}
// 删除片刻文章 - 打开弹窗
$('body').on('click', '.control_delete_post', function () {
window.currentDeletePid = $(this).parent().attr('pid');
openModal('删除确认', '确定删除瞬间?该条数据将被永久移除。', 'red');
});
// 点击取消按钮 - 关闭弹窗
$('body').on('click', '#momentsCancelDeleteBtn', function (e) {
$('#momentsDeleteModal').fadeOut(200);
window.currentDeletePid = null;
});
// 点击确认删除 - 执行 AJAX
$('body').on('click', '#momentsConfirmDeleteBtn', function () {
var pid = window.currentDeletePid;
if (!pid) return;
let closeLoading = cocoMessage.loading('正在删除...');
$('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', true);
$.ajax({
type: 'DELETE',
dataType: 'json',
url: `/apis/${Theme.moments.api}/v1alpha1/moments/` + pid,
contentType: "application/json",
success: function (data) {
$('#momentsDeleteModal').fadeOut(200);
closeLoading?.()
cocoMessage.success('删除成功');
window.currentDeletePid = null;
const $post = $(`#post-${pid}`);
if (!$post.length) return;
$post.addClass('moments-delete-disperse');
setTimeout(() => $post.remove(), 800);
},
error: function (request) {
if (request.status) {
closeLoading?.()
cocoMessage.error('瞬间不存在或已删除');
} else {
closeLoading?.()
cocoMessage.error('删除失败');
}
console.log(request)
$('.moments-btn-cancel, .moments-btn-confirm').prop('disabled', false);
},
});
});
//置顶片刻
$('body').on('click', '.sticky_btn', function() {
$('body').on('click', '.sticky_btn', function () {
var pid = $(this).parent().attr('pid');
var stick = $(this).hasClass('stick');
if(stick){
if (stick) {
var state = 'stick';
} else {
var state = 'unstick';
}
var msg = "确定执行此操作?";
if (confirm(msg)==true){
if (confirm(msg) == true) {
$.ajax({
type: 'POST',
dataType: 'json',
url: Theme.ajaxurl,
data: {
'action':'stick_moment',
pid:pid,
state:state
'action': 'stick_moment',
pid: pid,
state: state
},
beforeSend: function () {
cocoMessage.info('处理中..');
},
success: function (data) {
if(data.state == '1'){
if (data.state == '1') {
cocoMessage.success(data.msg);
if(data.type == 'stick'){
var post_item = $('#post-'+pid+'.moment_item');
if (data.type == 'stick') {
var post_item = $('#post-' + pid + '.moment_item');
post_item.remove();
$('.moment_list').prepend(post_item.prop('outerHTML'));
$('#post-'+pid+'.moment_item').find('.post_footer_meta .right').prepend('<span class="sticky_icon"><i class="ri-fire-line"></i> TOP</span>');
$('#post-'+pid+'.moment_item').find('.post_control').remove();
$('#post-' + pid + '.moment_item').find('.post_footer_meta .right').prepend('<span class="sticky_icon"><i class="ri-fire-line"></i> TOP</span>');
$('#post-' + pid + '.moment_item').find('.post_control').remove();
} else {
$('#post-'+pid+'.moment_item').find('.sticky_icon').remove();
$('#post-' + pid + '.moment_item').find('.sticky_icon').remove();
}
} else {
@@ -362,46 +372,48 @@ $('body').on('click', '.sticky_btn', function() {
});
//编辑片刻
$('body').on('click', '.control_edit_post', function() {
$(".loca_text").empty().attr("state",'0');
$('body').on('click', '.control_edit_post', function () {
$('.push_close, .push_item').prop('disabled', true);
let closeLoading = null;
$(".loca_text").empty().attr("state", '0');
$(".loca_text").attr("uk-tooltip", "title:获取位置; pos: top; offset:2;");
$('.moment_image_type a').click();
$('#topic_content').val('');
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible','PUBLIC');
$(".simi a").children().css({"background":"#e3efe7","color":"#66c187"});
$('.moment_image_type a').click();
$('#topic_content').val('');
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible', 'PUBLIC');
$(".simi a").children().css({ "background": "#e3efe7", "color": "#66c187" });
$('.t_media_item').remove();
$('#moment_audio_api').remove();
var pid = $(this).parent().attr('pid');
$('.push_item').html('<i class="ri-edit-box-line"></i>更新');
$('.push_item').attr('pid',pid).attr('action','update')
$('.push_item').attr('pid', pid).attr('action', 'update')
$.ajax({
type: 'GET',
url: `/apis/${Theme.moments.api}/v1alpha1/moments/`+pid,
url: `/apis/${Theme.moments.api}/v1alpha1/moments/` + pid,
beforeSend: function () {
cocoMessage.info('数据拉取中');
closeLoading = cocoMessage.loading('数据拉取中...');
//$('.t_form').before('<div class="edit_overlay"></div>');
},
success: function (data) {
$('.push_item').attr('version',data.metadata.version)
$('.push_item').attr('owner',data.spec.owner)
$('.push_item').attr('releaseTime',data.spec.releaseTime)
$('.push_item').attr('version', data.metadata.version)
$('.push_item').attr('owner', data.spec.owner)
$('.push_item').attr('releaseTime', data.spec.releaseTime)
//发布状态
if(data.spec.visible == 'PRIVATE'){
$(".simi a").html('<i class="ri-lock-line"></i>').attr('visible','PRIVATE');
$(".simi a").children().css({"background":"#ddd","color":"#c6c6c6"});
if (data.spec.visible == 'PRIVATE') {
$(".simi a").html('<i class="ri-lock-line"></i>').attr('visible', 'PRIVATE');
$(".simi a").children().css({ "background": "#ddd", "color": "#c6c6c6" });
} else {
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible','PUBLIC');
$(".simi a").children().css({"background":"#e3efe7","color":"#66c187"});
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible', 'PUBLIC');
$(".simi a").children().css({ "background": "#e3efe7", "color": "#66c187" });
}
var medium = data.spec.content.medium;
var tags = data.spec.tags
if(medium.length > 0){
if (medium.length > 0) {
var type = medium[0].type;
}
let content = data.spec.content.html;
if(content == null){
if (content == null) {
content = '';
}else{
} else {
// 创建一个新的HTML解析器对象
var parser = new DOMParser();
@@ -423,16 +435,15 @@ $('body').on('click', '.control_edit_post', function() {
}
$('#topic_content').val(content);
if(tags.length > 0){
if (tags.length > 0) {
$('.t_cat_toogle span').text(tags[0]);
}
if(data.metadata.annotations?.mylocal!=null && data.metadata.annotations?.mylocal!='') {
if (data.metadata.annotations?.mylocal != null && data.metadata.annotations?.mylocal != '') {
$('.loca_text').text(data.metadata.annotations?.mylocal);
}
switch(type)
{
switch (type) {
case "PHOTO":
//if(data.moment_data.length > 0){ 文字片刻没有数据
edit_image(data);
@@ -448,35 +459,42 @@ $('body').on('click', '.control_edit_post', function() {
edit_video(data);
break;
}
cocoMessage.success('拉取完成');
closeLoading();
cocoMessage.success('数据拉取完成');
$('.push_close, .push_item').prop('disabled', false);
},
error: function () {
closeLoading();
cocoMessage.error('数据拉取失败');
$('.push_close').prop('disabled', false);
}
});
});
//发布片刻重置
$('body').on('click', '.normal_edit,.center .mobile_edit', function() {
$('.push_item').attr('action','push').html('<i class="ri-send-plane-2-line"></i>发布');
$('body').on('click', '.normal_edit,.center .mobile_edit', function () {
$('.push_item').attr('action', 'push').html('<i class="ri-send-plane-2-line"></i>发布');
$('.moment_image_type a').click();
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible','PUBLIC');
$(".simi a").children().css({"background":"#e3efe7","color":"#66c187"});
$(".simi a").html('<i class="ri-lock-unlock-line"></i>').attr('visible', 'PUBLIC');
$(".simi a").children().css({ "background": "#e3efe7", "color": "#66c187" });
$('#topic_content').val('');
$(".loca_text").empty().attr("state",'0');
$(".loca_text").empty().attr("state", '0');
$('#set_local, [name="set_local"]').val('');
$('.t_media_item').remove();
$('.t_cat_toogle span').text('叽里咕噜');
});
//编辑片刻类型(已兼容图片+视频)------------------------------------------------------------------------------
function edit_image(data){
function edit_image(data) {
var m_data = data.spec.content.medium;
$('.t_media_item').remove();
$('.moment_image_type a').click();
if(m_data && m_data.length > 0){
if (m_data && m_data.length > 0) {
// reverse() 是为了配合 prepend,确保显示顺序与发布时一致
var new_data = [...m_data].reverse();
$.each(new_data, function(index, value) {
var new_data = [...m_data].reverse();
$.each(new_data, function (index, value) {
var src = value.url;
var type = value.originType || ""; // 获取 MIME 类型
var mediaInnerHtml = '';
@@ -484,10 +502,10 @@ function edit_image(data){
// --- 核心逻辑:判定是否为视频 ---
// 1. 检查 MIME 类型是否以 video/ 开头
// 2. 检查文件名后缀是否为常见的视频格式(防止 originType 丢失的情况)
var isVideo = type.startsWith('video/') ||
src.toLowerCase().endsWith('.mp4') ||
src.toLowerCase().endsWith('.webm') ||
src.toLowerCase().endsWith('.mov');
var isVideo = type.startsWith('video/') ||
src.toLowerCase().endsWith('.mp4') ||
src.toLowerCase().endsWith('.webm') ||
src.toLowerCase().endsWith('.mov');
if (isVideo) {
// 如果是视频,使用 video 标签预览
@@ -502,30 +520,30 @@ function edit_image(data){
<a class="topic-img-de"><i class="ri-subtract-line"></i></a>
${mediaInnerHtml}
</div>`;
$(".img_show").prepend(media);
});
}
}
function edit_video(data){
function edit_video(data) {
var m_data = data.spec.content.medium[0];
var type = m_data.originType;
//var url = m_data.url;
$('.moment_video_type a').click();
var add = setInterval(function() {
if(type != 'video/bili'){
var add = setInterval(function () {
if (type != 'video/bili') {
var url = m_data.url;
$('input#moment_video_url').val(url);
if(url !== ''){
if (url !== '') {
$('.m_media_left i').remove();
$('.m_media_left').append('<img src="/themes/theme-pix/assets/img/video.png" data="'+url+'">');
$('.m_media_left').append('<img src="/themes/theme-pix/assets/img/video.png" data="' + url + '">');
}
} else if(type == 'video/bili') {
if($('.video_choose').length > 0){
} else if (type == 'video/bili') {
if ($('.video_choose').length > 0) {
var bvid = m_data.url;
UIkit.switcher('.video_choose').show(1);
$('input#moment_video_bili').val(bvid);
@@ -533,26 +551,26 @@ function edit_video(data){
}
if($('.edit_video_box').length == 1){
if ($('.edit_video_box').length == 1) {
clearInterval(add);
}
}, 100);
}
function edit_audio(data){
function edit_audio(data) {
var m_data = data.spec.content.medium[0];
var type = m_data.originType;
$('.moment_audio_type a').click();
var add = setInterval(function() {
if(type == 'audio/netease' || type == 'audio/tencent' || type == 'audio/kugou' || type == 'audio/kuwo'){
var add = setInterval(function () {
if (type == 'audio/netease' || type == 'audio/tencent' || type == 'audio/kugou' || type == 'audio/kuwo') {
var result = type.substring(type.indexOf("audio/") + 6);
if($('.audio_choose').length > 0){
if ($('.audio_choose').length > 0) {
var n_id = m_data.url;
var index = $('.audio_choose li.'+result+'').index();
var index = $('.audio_choose li.' + result + '').index();
UIkit.switcher('.audio_choose').show(index);
$('.edit_audio_box .tips').text('# 请输入歌曲ID');
$('.'+result+'_audio').append('<input type="text" placeholder="歌曲ID" name="moment_audio_api" id="moment_audio_api" class="required" required="required">');
$('.' + result + '_audio').append('<input type="text" placeholder="歌曲ID" name="moment_audio_api" id="moment_audio_api" class="required" required="required">');
$('input#moment_audio_api').val(n_id);
}
} else {
@@ -562,7 +580,7 @@ function edit_audio(data){
$('.edit_audio_box .tips').text('# 请插入歌曲外链');
$('input#moment_audio_url').val(url);
}
if($('.edit_audio_box').length == 1){
if ($('.edit_audio_box').length == 1) {
clearInterval(add);
}
@@ -574,15 +592,15 @@ function edit_card(data) {
$('.card_sortble .moment_card_item').remove();
$('.moment_card_type a').click();
var pid = data.metadata.name;
var card_list = $("#post-"+pid+"").find('.moment_card_item');
var add = setInterval(function() {
var card_list = $("#post-" + pid + "").find('.moment_card_item');
var add = setInterval(function () {
$('.show_card').show();
$.each(m_data, function(index, value) {
$.each(m_data, function (index, value) {
var srcValue = card_list.eq(index).find('img').attr('src');
var h4Text = card_list.eq(index).find('h4').text();
$('.card_sortble').append(getcard(value.url,srcValue,h4Text,value.originType));
var h4Text = card_list.eq(index).find('h4').text();
$('.card_sortble').append(getcard(value.url, srcValue, h4Text, value.originType));
});
if($('.edit_card_box').length == 1){
if ($('.edit_card_box').length == 1) {
clearInterval(add);
}
}, 100);