|
@@ -65,6 +65,29 @@
|
|
|
<!-- 引入Quill库 -->
|
|
|
<script src="//cdn.quilljs.com/1.3.6/quill.js"></script>
|
|
|
<script>
|
|
|
+ function isSharePage() {
|
|
|
+ // 有share_id参数,没有id参数
|
|
|
+ return getQueryString("share_id") && !getQueryString("id");
|
|
|
+ }
|
|
|
+
|
|
|
+ function getShareId() {
|
|
|
+ return getQueryString("share_id").split("#")[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ function setContent(content) {
|
|
|
+ document.getElementById("editor").innerHTML = content;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDataByShareId(id) {
|
|
|
+ let res = requestUtil.sync("https://web_history.tianyunperfect.cn/content/selectByShareId?id=" + id, "get");
|
|
|
+ if (res.code === 200) {
|
|
|
+ if (res.res.length > 0) {
|
|
|
+ setContent(res.res[0].content)
|
|
|
+ sharePageSet();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取当前时间戳 减去 2024年1月1日的时间戳
|
|
|
let timestamp = getTimeStamp();
|
|
|
|
|
@@ -72,15 +95,22 @@
|
|
|
// 获取编辑器内容
|
|
|
if (id) {
|
|
|
let res = requestUtil.sync("https://web_history.tianyunperfect.cn/content/select?id=" + id, "get");
|
|
|
- if (res.code == 200) {
|
|
|
+ if (res.code === 200) {
|
|
|
if (res.res.length > 0) {
|
|
|
- document.getElementById("editor").innerHTML = res.res[0].content;
|
|
|
+ setContent(res.res[0].content);
|
|
|
showTextOnTopRight("✅");
|
|
|
+
|
|
|
+ if (isSharePage()) {
|
|
|
+ sharePageSet();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } else if (isSharePage()) {
|
|
|
+ getDataByShareId(getShareId())
|
|
|
} else {
|
|
|
+ let share_id = timestamp * 10000 + Math.floor(Math.random() * 10000 + 1);
|
|
|
// 重定向
|
|
|
- location.href = requestUtil.buildUrl(location.href, {"id": timestamp})
|
|
|
+ location.href = requestUtil.buildUrl(location.href, {"id": timestamp, share_id: share_id})
|
|
|
}
|
|
|
|
|
|
const quill = new Quill('#editor', {
|
|
@@ -100,12 +130,17 @@
|
|
|
console.log(content);
|
|
|
}
|
|
|
|
|
|
+ function sharePageSet() {
|
|
|
+ showTextOnTopRight("分享页面,只读");
|
|
|
+ }
|
|
|
+
|
|
|
function sysncContent() {
|
|
|
let content = quill.root.innerHTML;
|
|
|
let res = requestUtil.sync("https://web_history.tianyunperfect.cn/content/updateOrInsert", "post", {
|
|
|
"id": id,
|
|
|
"type": "html",
|
|
|
- "content": content
|
|
|
+ "content": content,
|
|
|
+ "share_id": getShareId()
|
|
|
});
|
|
|
if (res.code == 200) {
|
|
|
console.log("同步成功");
|
|
@@ -121,6 +156,10 @@
|
|
|
// source - 表示触发变化的原因,如'user'(用户输入)或'silent'(编程方式修改)
|
|
|
|
|
|
// 在这里执行你想要的操作,比如更新数据或执行其他逻辑
|
|
|
+ if (isSharePage()) {
|
|
|
+ sharePageSet();
|
|
|
+ return;
|
|
|
+ }
|
|
|
console.log("内容发生变化");
|
|
|
showTextOnTopRight("待同步");
|
|
|
// 防抖 1秒内同步一次
|