mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-09 12:32:48 +08:00
feat(phone-image): add save button and state management
This commit is contained in:
@@ -1260,6 +1260,48 @@ var PhoneImageEngine = (function () {
|
|||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存排版配置到服务端(不生成图片)
|
||||||
|
* @param {number} postId 文章ID
|
||||||
|
* @param {Object} saveConfig 配置信息 {size, fontSize, watermark, content_html}
|
||||||
|
* @param {string} url 保存接口URL
|
||||||
|
* @returns {Promise} jQuery Deferred, resolves with {output_id}
|
||||||
|
*/
|
||||||
|
function saveConfig(postId, saveConfig, url) {
|
||||||
|
var deferred = $.Deferred();
|
||||||
|
|
||||||
|
var payload = {
|
||||||
|
post_id: postId,
|
||||||
|
output_type: 'phone_image',
|
||||||
|
config: {
|
||||||
|
size: saveConfig.size || config.size,
|
||||||
|
fontSize: saveConfig.fontSize || config.fontSize,
|
||||||
|
watermark: saveConfig.watermark || config.watermark,
|
||||||
|
pageAlignments: config.pageAlignments || {}
|
||||||
|
},
|
||||||
|
content_html: saveConfig.content_html || postData.content_html
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url || '',
|
||||||
|
type: 'POST',
|
||||||
|
data: JSON.stringify(payload),
|
||||||
|
contentType: 'application/json',
|
||||||
|
success: function (result) {
|
||||||
|
if (result.code === 0) {
|
||||||
|
deferred.resolve(result.data || {});
|
||||||
|
} else {
|
||||||
|
deferred.reject(result.msg || '保存失败');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (xhr) {
|
||||||
|
deferred.reject('网络错误: ' + xhr.statusText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将生成的canvas数组显示为缩略图
|
* 将生成的canvas数组显示为缩略图
|
||||||
* @param {Array} canvases canvas对象数组
|
* @param {Array} canvases canvas对象数组
|
||||||
@@ -1382,6 +1424,7 @@ var PhoneImageEngine = (function () {
|
|||||||
render: render,
|
render: render,
|
||||||
generateImages: generateImages,
|
generateImages: generateImages,
|
||||||
saveImages: saveImages,
|
saveImages: saveImages,
|
||||||
|
saveConfig: saveConfig,
|
||||||
showGeneratedThumbnails: showGeneratedThumbnails,
|
showGeneratedThumbnails: showGeneratedThumbnails,
|
||||||
switchSize: switchSize,
|
switchSize: switchSize,
|
||||||
getConfig: getConfig,
|
getConfig: getConfig,
|
||||||
|
|||||||
@@ -141,6 +141,8 @@
|
|||||||
|
|
||||||
<!-- 操作按钮 -->
|
<!-- 操作按钮 -->
|
||||||
<div class="action-btns">
|
<div class="action-btns">
|
||||||
|
<button type="button" class="layui-btn layui-btn-normal" id="btn-save"><i
|
||||||
|
class="layui-icon layui-icon-ok"></i> 保存</button>
|
||||||
<button type="button" class="layui-btn layui-btn-normal" id="btn-generate"><i
|
<button type="button" class="layui-btn layui-btn-normal" id="btn-generate"><i
|
||||||
class="layui-icon layui-icon-picture"></i> 生成并保存</button>
|
class="layui-icon layui-icon-picture"></i> 生成并保存</button>
|
||||||
<button type="button" class="layui-btn layui-btn-warm" id="btn-download"><i
|
<button type="button" class="layui-btn layui-btn-warm" id="btn-download"><i
|
||||||
@@ -174,6 +176,7 @@
|
|||||||
|
|
||||||
var lastOutputId = null;
|
var lastOutputId = null;
|
||||||
var downloadBaseUrl = '{:url("post/downloadPostOutputZip", ["id" => 0])}';
|
var downloadBaseUrl = '{:url("post/downloadPostOutputZip", ["id" => 0])}';
|
||||||
|
var saveConfigUrl = '{:url("post/savePostOutputConfig")}';
|
||||||
|
|
||||||
var postData = {
|
var postData = {
|
||||||
postId: {$post.id},
|
postId: {$post.id},
|
||||||
@@ -233,6 +236,27 @@
|
|||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存配置(不生成图片)
|
||||||
|
$('#btn-save').click(function () {
|
||||||
|
var btn = $(this);
|
||||||
|
btn.prop('disabled', true);
|
||||||
|
layer.msg('保存中...');
|
||||||
|
|
||||||
|
PhoneImageEngine.saveConfig(postData.postId, {
|
||||||
|
size: $('[name="size"]').val(),
|
||||||
|
fontSize: parseInt($('[name="fontSize"]').val()) || 14,
|
||||||
|
watermark: $('[name="watermark"]').val(),
|
||||||
|
content_html: $('#post-content-html').html()
|
||||||
|
}, saveConfigUrl).then(function (data) {
|
||||||
|
if (data.output_id) lastOutputId = data.output_id;
|
||||||
|
layer.msg('保存成功');
|
||||||
|
}).catch(function (err) {
|
||||||
|
layer.msg('保存失败: ' + err);
|
||||||
|
}).always(function () {
|
||||||
|
setTimeout(function () { btn.prop('disabled', false); }, 2000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 生成并保存
|
// 生成并保存
|
||||||
$('#btn-generate').click(function () {
|
$('#btn-generate').click(function () {
|
||||||
var btn = $(this);
|
var btn = $(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user