2017-04-29 21:28:09 +08:00
|
|
|
|
/**
|
|
|
|
|
* Created by lifei6671 on 2017/4/29 0029.
|
|
|
|
|
*/
|
2018-08-17 17:33:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开最后选中的节点
|
|
|
|
|
*/
|
|
|
|
|
function openLastSelectedNode() {
|
|
|
|
|
//如果文档树或编辑器没有准备好则不加载文档
|
|
|
|
|
if (window.treeCatalog == null || window.editor == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var $isSelected = false;
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (window.localStorage) {
|
2018-08-17 17:39:03 +08:00
|
|
|
|
var $selectedNodeId = window.sessionStorage.getItem("MinDoc::LastLoadDocument:" + window.book.identify);
|
2019-05-20 17:38:37 +08:00
|
|
|
|
try {
|
|
|
|
|
if ($selectedNodeId) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
//遍历文档树判断是否存在节点
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$.each(window.documentCategory, function (i, n) {
|
|
|
|
|
if (n.id == $selectedNodeId && !$isSelected) {
|
|
|
|
|
var $node = {"id": n.id};
|
2018-08-17 17:33:45 +08:00
|
|
|
|
window.treeCatalog.deselect_all();
|
|
|
|
|
window.treeCatalog.select_node($node);
|
|
|
|
|
$isSelected = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} catch ($ex) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
console.log($ex)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果节点不存在,则默认选中第一个节点
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (!$isSelected && window.documentCategory.length > 0) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
var doc = window.documentCategory[0];
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (doc && doc.id > 0) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
var node = {"id": doc.id};
|
|
|
|
|
$("#sidebar").jstree(true).select_node(node);
|
|
|
|
|
$isSelected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $isSelected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置最后选中的文档
|
|
|
|
|
* @param $node
|
|
|
|
|
*/
|
|
|
|
|
function setLastSelectNode($node) {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (window.localStorage) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
if (typeof $node === "undefined" || !$node) {
|
2018-08-17 17:39:03 +08:00
|
|
|
|
window.sessionStorage.removeItem("MinDoc::LastLoadDocument:" + window.book.identify);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
} else {
|
|
|
|
|
var nodeId = $node.id ? $node.id : $node.node.id;
|
2018-08-17 17:39:03 +08:00
|
|
|
|
window.sessionStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, nodeId);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 21:28:09 +08:00
|
|
|
|
/**
|
|
|
|
|
* 保存排序
|
|
|
|
|
* @param node
|
|
|
|
|
* @param parent
|
|
|
|
|
*/
|
|
|
|
|
function jstree_save(node, parent) {
|
|
|
|
|
|
|
|
|
|
var parentNode = window.treeCatalog.get_node(parent.parent);
|
|
|
|
|
|
|
|
|
|
var nodeData = window.getSiblingSort(parentNode);
|
|
|
|
|
|
|
|
|
|
if (parent.parent !== parent.old_parent) {
|
|
|
|
|
parentNode = window.treeCatalog.get_node(parent.old_parent);
|
|
|
|
|
var newNodeData = window.getSiblingSort(parentNode);
|
|
|
|
|
if (newNodeData.length > 0) {
|
|
|
|
|
nodeData = nodeData.concat(newNodeData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var index = layer.load(1, {
|
|
|
|
|
shade: [0.1, '#fff'] //0.1透明度的白色背景
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
2019-05-20 17:38:37 +08:00
|
|
|
|
url: window.sortURL,
|
|
|
|
|
type: "post",
|
|
|
|
|
data: JSON.stringify(nodeData),
|
|
|
|
|
success: function (res) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
layer.close(index);
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (res.errcode === 0) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
layer.msg("保存排序成功");
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} else {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
layer.msg(res.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建文档
|
|
|
|
|
*/
|
|
|
|
|
function openCreateCatalogDialog($node) {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
var $then = $("#addDocumentModal");
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
|
|
|
|
var doc_id = $node ? $node.id : 0;
|
|
|
|
|
|
|
|
|
|
$then.find("input[name='parent_id']").val(doc_id);
|
2018-08-24 19:16:34 +08:00
|
|
|
|
$then.find("input[name='doc_id']").val('');
|
|
|
|
|
$then.find("input[name='doc_name']").val('');
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
|
|
|
|
$then.modal("show");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理排序
|
|
|
|
|
* @param node
|
|
|
|
|
* @returns {Array}
|
|
|
|
|
*/
|
2019-05-20 17:38:37 +08:00
|
|
|
|
function getSiblingSort(node) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var data = [];
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
for (var key in node.children) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var index = data.length;
|
|
|
|
|
|
|
|
|
|
data[index] = {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
"id": parseInt(node.children[key]),
|
|
|
|
|
"sort": parseInt(key),
|
|
|
|
|
"parent": Number(node.id) ? Number(node.id) : 0
|
2017-04-29 21:28:09 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return data;
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除一个文档
|
|
|
|
|
* @param $node
|
|
|
|
|
*/
|
|
|
|
|
function openDeleteDocumentDialog($node) {
|
|
|
|
|
var index = layer.confirm('你确定要删除该文档吗?', {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
btn: ['确定', '取消'] //按钮
|
|
|
|
|
}, function () {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$.post(window.deleteURL, {"identify": window.book.identify, "doc_id": $node.id}).done(function (res) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
layer.close(index);
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (res.errcode === 0) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
window.treeCatalog.delete_node($node);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
window.documentCategory.remove(function (item) {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
return item.id == $node.id;
|
2018-08-17 17:33:45 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(window.documentCategory)
|
|
|
|
|
setLastSelectNode();
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} else {
|
|
|
|
|
layer.msg("删除失败", {icon: 2})
|
2017-04-29 21:28:09 +08:00
|
|
|
|
}
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
layer.close(index);
|
2019-05-20 17:38:37 +08:00
|
|
|
|
layer.msg("删除失败", {icon: 2})
|
2017-04-29 21:28:09 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打开文档编辑界面
|
|
|
|
|
* @param $node
|
|
|
|
|
*/
|
|
|
|
|
function openEditCatalogDialog($node) {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
var $then = $("#addDocumentModal");
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var doc_id = parseInt($node ? $node.id : 0);
|
|
|
|
|
var text = $node ? $node.text : '';
|
|
|
|
|
var parentId = $node && $node.parent !== '#' ? $node.parent : 0;
|
|
|
|
|
|
2018-08-14 18:17:46 +08:00
|
|
|
|
|
2017-04-29 21:28:09 +08:00
|
|
|
|
$then.find("input[name='doc_id']").val(doc_id);
|
|
|
|
|
$then.find("input[name='parent_id']").val(parentId);
|
|
|
|
|
$then.find("input[name='doc_name']").val(text);
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
var open = $node.a_attr && $node.a_attr.opened ? $node.a_attr.opened : 0;
|
2018-08-14 18:17:46 +08:00
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
|
|
|
|
|
console.log($node)
|
|
|
|
|
$then.find("input[name='is_open'][value='" + open + "']").prop("checked", "checked");
|
|
|
|
|
|
|
|
|
|
for (var index in window.documentCategory) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var item = window.documentCategory[index];
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (item.id === doc_id) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
$then.find("input[name='doc_identify']").val(item.identify);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$then.modal({show: true});
|
2017-04-29 21:28:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将一个节点推送到现有数组中
|
|
|
|
|
* @param $node
|
|
|
|
|
*/
|
|
|
|
|
function pushDocumentCategory($node) {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
for (var index in window.documentCategory) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
var item = window.documentCategory[index];
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (item.id === $node.id) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
|
|
|
|
window.documentCategory[index] = $node;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
window.documentCategory.push($node);
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
|
2017-05-12 19:14:29 +08:00
|
|
|
|
/**
|
|
|
|
|
* 将数据重置到Vue列表中
|
|
|
|
|
* @param $lists
|
|
|
|
|
*/
|
|
|
|
|
function pushVueLists($lists) {
|
|
|
|
|
|
2017-05-13 12:12:37 +08:00
|
|
|
|
window.vueApp.lists = [];
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$.each($lists, function (i, item) {
|
2017-05-12 19:14:29 +08:00
|
|
|
|
window.vueApp.lists.push(item);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
});
|
2017-05-12 19:14:29 +08:00
|
|
|
|
}
|
2017-04-29 21:28:09 +08:00
|
|
|
|
|
2018-01-25 19:18:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* 发布项目
|
|
|
|
|
*/
|
|
|
|
|
function releaseBook() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: window.releaseURL,
|
2019-05-20 17:38:37 +08:00
|
|
|
|
data: {"identify": window.book.identify},
|
2018-01-25 19:18:59 +08:00
|
|
|
|
type: "post",
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.errcode === 0) {
|
|
|
|
|
layer.msg("发布任务已推送到任务队列,稍后将在后台执行。");
|
|
|
|
|
} else {
|
|
|
|
|
layer.msg(res.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
|
2017-04-29 21:28:09 +08:00
|
|
|
|
//实现小提示
|
|
|
|
|
$("[data-toggle='tooltip']").hover(function () {
|
|
|
|
|
var title = $(this).attr('data-title');
|
|
|
|
|
var direction = $(this).attr("data-direction");
|
|
|
|
|
var tips = 3;
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (direction === "top") {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
tips = 1;
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} else if (direction === "right") {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
tips = 2;
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} else if (direction === "bottom") {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
tips = 3;
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} else if (direction === "left") {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
tips = 4;
|
|
|
|
|
}
|
|
|
|
|
index = layer.tips(title, this, {
|
|
|
|
|
tips: tips
|
|
|
|
|
});
|
|
|
|
|
}, function () {
|
|
|
|
|
layer.close(index);
|
|
|
|
|
});
|
|
|
|
|
//弹出创建文档的遮罩层
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$("#btnAddDocument").on("click", function () {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
$("#addDocumentModal").modal("show");
|
|
|
|
|
});
|
|
|
|
|
//用于还原创建文档的遮罩层
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$("#addDocumentModal").on("hidden.bs.modal", function () {
|
|
|
|
|
$(this).find("form").html(window.sessionStorage.getItem("MinDoc::addDocumentModal"));
|
|
|
|
|
var $then = $("#addDocumentModal");
|
2018-08-24 19:16:34 +08:00
|
|
|
|
|
|
|
|
|
$then.find("input[name='parent_id']").val('');
|
|
|
|
|
$then.find("input[name='doc_id']").val('');
|
|
|
|
|
$then.find("input[name='doc_name']").val('');
|
2019-05-20 17:38:37 +08:00
|
|
|
|
}).on("shown.bs.modal", function () {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
$(this).find("input[name='doc_name']").focus();
|
2019-05-20 17:38:37 +08:00
|
|
|
|
}).on("show.bs.modal", function () {
|
|
|
|
|
window.sessionStorage.setItem("MinDoc::addDocumentModal", $(this).find("form").html())
|
2017-04-29 21:28:09 +08:00
|
|
|
|
});
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
function showError($msg, $id) {
|
|
|
|
|
if (!$id) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
$id = "#form-error-message"
|
|
|
|
|
}
|
|
|
|
|
$($id).addClass("error-message").removeClass("success-message").text($msg);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
function showSuccess($msg, $id) {
|
|
|
|
|
if (!$id) {
|
2017-04-29 21:28:09 +08:00
|
|
|
|
$id = "#form-error-message"
|
|
|
|
|
}
|
|
|
|
|
$($id).addClass("success-message").removeClass("error-message").text($msg);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-05-20 15:27:03 +08:00
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
window.documentHistory = function () {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
layer.open({
|
|
|
|
|
type: 2,
|
|
|
|
|
title: '历史版本',
|
|
|
|
|
shadeClose: true,
|
|
|
|
|
shade: 0.8,
|
2019-05-20 17:38:37 +08:00
|
|
|
|
area: ['700px', '80%'],
|
2017-05-25 15:19:17 +08:00
|
|
|
|
content: window.historyURL + "?identify=" + window.book.identify + "&doc_id=" + window.selectNode.id,
|
2019-05-20 17:38:37 +08:00
|
|
|
|
end: function () {
|
|
|
|
|
if (window.SelectedId) {
|
|
|
|
|
var selected = {
|
|
|
|
|
node: {
|
|
|
|
|
id: window.SelectedId
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-05-25 15:19:17 +08:00
|
|
|
|
window.loadDocument(selected);
|
|
|
|
|
window.SelectedId = null;
|
2017-05-20 15:27:03 +08:00
|
|
|
|
}
|
2017-05-25 15:19:17 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
function uploadImage($id, $callback) {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
/** 粘贴上传图片 **/
|
2019-05-20 17:38:37 +08:00
|
|
|
|
document.getElementById($id).addEventListener('paste', function (e) {
|
|
|
|
|
if (e.clipboardData && e.clipboardData.items) {
|
2018-07-24 17:54:24 +08:00
|
|
|
|
var clipboard = e.clipboardData;
|
|
|
|
|
for (var i = 0, len = clipboard.items.length; i < len; i++) {
|
|
|
|
|
if (clipboard.items[i].kind === 'file' || clipboard.items[i].type.indexOf('image') > -1) {
|
|
|
|
|
|
|
|
|
|
var imageFile = clipboard.items[i].getAsFile();
|
|
|
|
|
|
|
|
|
|
var fileName = String((new Date()).valueOf());
|
|
|
|
|
|
|
|
|
|
switch (imageFile.type) {
|
|
|
|
|
case "image/png" :
|
|
|
|
|
fileName += ".png";
|
|
|
|
|
break;
|
|
|
|
|
case "image/jpg" :
|
|
|
|
|
fileName += ".jpg";
|
|
|
|
|
break;
|
|
|
|
|
case "image/jpeg" :
|
|
|
|
|
fileName += ".jpeg";
|
|
|
|
|
break;
|
|
|
|
|
case "image/gif" :
|
|
|
|
|
fileName += ".gif";
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
layer.msg("不支持的图片格式");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var form = new FormData();
|
|
|
|
|
|
|
|
|
|
form.append('editormd-image-file', imageFile, fileName);
|
|
|
|
|
|
|
|
|
|
var layerIndex = 0;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: window.imageUploadURL,
|
|
|
|
|
type: "POST",
|
|
|
|
|
dataType: "json",
|
|
|
|
|
data: form,
|
|
|
|
|
processData: false,
|
|
|
|
|
contentType: false,
|
|
|
|
|
beforeSend: function () {
|
|
|
|
|
layerIndex = $callback('before');
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
layer.close(layerIndex);
|
|
|
|
|
$callback('error');
|
|
|
|
|
layer.msg("图片上传失败");
|
|
|
|
|
},
|
|
|
|
|
success: function (data) {
|
|
|
|
|
layer.close(layerIndex);
|
|
|
|
|
$callback('success', data);
|
|
|
|
|
if (data.errcode !== 0) {
|
|
|
|
|
layer.msg(data.message);
|
|
|
|
|
}
|
2017-06-12 17:58:45 +08:00
|
|
|
|
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
2018-07-24 17:54:24 +08:00
|
|
|
|
});
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-05-20 15:27:03 +08:00
|
|
|
|
|
2018-01-27 13:56:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 初始化代码高亮
|
|
|
|
|
*/
|
|
|
|
|
function initHighlighting() {
|
|
|
|
|
$('pre code,pre.ql-syntax').each(function (i, block) {
|
|
|
|
|
hljs.highlightBlock(block);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
|
2017-05-25 15:19:17 +08:00
|
|
|
|
$(function () {
|
|
|
|
|
window.vueApp = new Vue({
|
2019-05-20 17:38:37 +08:00
|
|
|
|
el: "#attachList",
|
|
|
|
|
data: {
|
|
|
|
|
lists: []
|
2017-05-25 15:19:17 +08:00
|
|
|
|
},
|
2019-05-20 17:38:37 +08:00
|
|
|
|
delimiters: ['${', '}'],
|
|
|
|
|
methods: {
|
|
|
|
|
removeAttach: function ($attach_id) {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
var $this = this;
|
|
|
|
|
var item = $this.lists.filter(function ($item) {
|
|
|
|
|
return $item.attachment_id == $attach_id;
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (item && item[0].hasOwnProperty("state")) {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
$this.lists = $this.lists.filter(function ($item) {
|
|
|
|
|
return $item.attachment_id != $attach_id;
|
|
|
|
|
});
|
|
|
|
|
return;
|
2017-05-20 15:27:03 +08:00
|
|
|
|
}
|
2017-05-25 15:19:17 +08:00
|
|
|
|
$.ajax({
|
2019-05-20 17:38:37 +08:00
|
|
|
|
url: window.removeAttachURL,
|
|
|
|
|
type: "post",
|
|
|
|
|
data: {"attach_id": $attach_id},
|
|
|
|
|
success: function (res) {
|
|
|
|
|
if (res.errcode === 0) {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
$this.lists = $this.lists.filter(function ($item) {
|
|
|
|
|
return $item.attachment_id != $attach_id;
|
|
|
|
|
});
|
2019-05-20 17:38:37 +08:00
|
|
|
|
} else {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
layer.msg(res.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-05-20 15:27:03 +08:00
|
|
|
|
}
|
2017-05-25 15:19:17 +08:00
|
|
|
|
},
|
2019-05-20 17:38:37 +08:00
|
|
|
|
watch: {
|
|
|
|
|
lists: function ($lists) {
|
2017-05-25 15:19:17 +08:00
|
|
|
|
$("#attachInfo").text(" " + $lists.length + " 个附件")
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-20 15:27:03 +08:00
|
|
|
|
});
|
2018-08-17 17:33:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* 启动自动保存,默认30s自动保存一次
|
|
|
|
|
*/
|
2019-05-20 17:38:37 +08:00
|
|
|
|
if (window.book && window.book.auto_save) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
setTimeout(function () {
|
|
|
|
|
setInterval(function () {
|
2019-05-20 17:38:37 +08:00
|
|
|
|
var $then = $("#markdown-save");
|
|
|
|
|
if (!window.saveing && $then.hasClass("change")) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
$then.trigger("click");
|
|
|
|
|
}
|
2019-05-20 17:38:37 +08:00
|
|
|
|
}, 30000);
|
|
|
|
|
}, 30000);
|
2018-08-17 17:33:45 +08:00
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 当离开窗口时存在未保存的文档会提示保存
|
|
|
|
|
*/
|
2019-05-20 17:38:37 +08:00
|
|
|
|
$(window).on("beforeunload", function () {
|
|
|
|
|
if ($("#markdown-save").hasClass("change")) {
|
2018-08-17 17:33:45 +08:00
|
|
|
|
return '您输入的内容尚未保存,确定离开此页面吗?';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2017-05-25 15:19:17 +08:00
|
|
|
|
|