From 30ce4b8a3df1749084ad8ef1d6adb58104bf3e92 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Sun, 4 Apr 2021 22:25:18 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E5=AD=90=E7=BA=A7=E5=8D=9A=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog.html | 10 +- excel.html | 10 +- mind.html | 10 +- .../elements/em-blog-left-sidebar.html | 55 ++++++++++- .../elements/em-blog-left-sidebar.js | 94 +++++++++++++++---- .../elements/em-blog-left-sidebar.less | 29 +++++- src/resources/elements/em-blog-tpl-select.js | 11 ++- src/resources/elements/em-blog-write.js | 4 +- 8 files changed, 182 insertions(+), 41 deletions(-) diff --git a/blog.html b/blog.html index 5a71129..79bab4a 100644 --- a/blog.html +++ b/blog.html @@ -626,6 +626,7 @@ var content = $('#edit').froalaEditor('html.get', true); var spaceId = url('?spaceId'); var dirId = url('?dirId'); + var pid = url('?pid'); if (!title || !$.trim(title)) { toastr && toastr.error('博文标题不能为空!'); @@ -639,8 +640,8 @@ if (blog == null) { - if (spaceId) { // 基于空间或者目录创建博文场景 - createBlog(spaceId, dirId); + if (spaceId || pid) { // 基于空间或者目录创建博文场景 + createBlog(spaceId, dirId, pid); } else { $.get('/admin/space/listMy', function (data) { if (data.success) { @@ -727,7 +728,7 @@ } }); - function createBlog(spaceId, dirId) { + function createBlog(spaceId, dirId, pid) { var title = $('#title').val(); var content = $('#edit').froalaEditor('html.get', true); @@ -744,7 +745,7 @@ if (blog == null) { - if (!spaceId) { + if (!spaceId && !pid) { $.modal.close(); @@ -766,6 +767,7 @@ spaceId: spaceId ? spaceId : $('#saveFrm select[name="space"]').val(), dirId: dirId ? dirId : (spaceId ? '' : $('#saveFrm select[name="dir"]') .val()), // 如果只是基于空间,目录设置为空 + pid: pid ? pid : '', title: title, content: content, editor: 'Html', diff --git a/excel.html b/excel.html index 4b8c28d..bc5f8d6 100644 --- a/excel.html +++ b/excel.html @@ -276,6 +276,7 @@ var cid = url('?cid'); var spaceId = url('?spaceId'); var dirId = url('?dirId'); + var pid = url('?pid'); var readonly = typeof url('?readonly') !== 'undefined'; !readonly && $('#editor').removeClass('readonly'); @@ -578,8 +579,8 @@ if (blog == null) { - if (spaceId) { - createBlog(spaceId, dirId); + if (spaceId || pid) { + createBlog(spaceId, dirId, pid); } else { $.get('/admin/space/listMy', function (data) { if (data.success) { @@ -657,7 +658,7 @@ }); } - function createBlog(spaceId, dirId) { + function createBlog(spaceId, dirId, pid) { var title = $('#title').val(); var content = JSON.stringify(excel.getData()); @@ -673,7 +674,7 @@ if (blog == null) { - if (!spaceId) { + if (!spaceId && !pid) { $.modal.close(); localStorage && localStorage.setItem('tms-blog-html-space', $( @@ -690,6 +691,7 @@ '/page/index.html', spaceId: spaceId ? spaceId : $('#saveFrm select[name="space"]').val(), dirId: dirId ? dirId : (spaceId ? '' : $('#saveFrm select[name="dir"]').val()), + pid: pid ? pid : '', title: title, content: content, editor: 'Excel', diff --git a/mind.html b/mind.html index afd6881..c50700c 100644 --- a/mind.html +++ b/mind.html @@ -251,6 +251,7 @@ var cid = url('?cid'); var spaceId = url('?spaceId'); var dirId = url('?dirId'); + var pid = url('?pid'); var readonly = typeof url('?readonly') !== 'undefined'; !readonly && $('#editor').removeClass('readonly'); @@ -569,8 +570,8 @@ if (blog == null) { - if (spaceId) { - createBlog(spaceId, dirId) + if (spaceId || pid) { + createBlog(spaceId, dirId, pid) } else { $.get('/admin/space/listMy', function (data) { if (data.success) { @@ -648,7 +649,7 @@ }); } - function createBlog(spaceId, dirId) { + function createBlog(spaceId, dirId, pid) { var title = $('#title').val(); mind.cancelFocus(); @@ -666,7 +667,7 @@ if (blog == null) { - if (!spaceId) { + if (!spaceId && !pid) { $.modal.close(); localStorage && localStorage.setItem('tms-blog-html-space', $( @@ -683,6 +684,7 @@ '/page/index.html', spaceId: spaceId ? spaceId : $('#saveFrm select[name="space"]').val(), dirId: dirId ? dirId : (spaceId ? '' : $('#saveFrm select[name="dir"]').val()), + pid: pid ? pid : '', title: title, content: content, editor: 'Mind', diff --git a/src/resources/elements/em-blog-left-sidebar.html b/src/resources/elements/em-blog-left-sidebar.html index 2bc3b1f..0c1273f 100644 --- a/src/resources/elements/em-blog-left-sidebar.html +++ b/src/resources/elements/em-blog-left-sidebar.html @@ -156,7 +156,8 @@ 思维导图
- + 基于模板 @@ -238,11 +239,59 @@
- - + + + ${item.title} +
+ +
+
diff --git a/src/resources/elements/em-blog-left-sidebar.js b/src/resources/elements/em-blog-left-sidebar.js index 60bb144..c9fc71a 100644 --- a/src/resources/elements/em-blog-left-sidebar.js +++ b/src/resources/elements/em-blog-left-sidebar.js @@ -2,7 +2,7 @@ import { bindable, containerless } from 'aurelia-framework'; - +import _ from 'lodash'; @containerless export class EmBlogLeftSidebar { @@ -42,7 +42,16 @@ export class EmBlogLeftSidebar { constructor() { this.subscribe = ea.subscribe(nsCons.EVENT_BLOG_CHANGED, (payload) => { if (payload.action == 'created') { - this.blogs = [payload.blog, ...this.blogs]; + + if (payload.blog.pid) { + let blog = this._fixBlog(this.blogs, payload.blog.pid); + if (blog) { + blog._childs = blog._childs ? [payload.blog, ...blog._childs] : [payload.blog]; + } + } else { + this.blogs = [payload.blog, ...this.blogs]; + } + nsCtx.blogId = payload.blog.id; this.calcTree(); _.delay(() => this._scrollTo(payload.blog.id), 1000); @@ -53,6 +62,7 @@ export class EmBlogLeftSidebar { let blog = _.find(this.blogs, { id: payload.blog.id }); + if (!blog) return; if (!payload.blog.dir) blog.dir = null; _.extend(blog, payload.blog); // 同步更新收藏博文 @@ -91,9 +101,10 @@ export class EmBlogLeftSidebar { } }); this.subscribe2 = ea.subscribe(nsCons.EVENT_BLOG_SWITCH, (payload) => { - this.blog = _.find(this.blogs, { - id: +nsCtx.blogId - }); + // this.blog = _.find(this.blogs, { + // id: +nsCtx.blogId + // }); + this.blog = this._fixBlog(this.blogs, +nsCtx.blogId); payload.anchor && this.calcTree(); // TODO 这里存在bug,拖拽后重新计划目录,博文目录定位错乱,原因不明??? // payload.anchor && this.refresh(); // TODO 这里存在bug,拖拽后重新计划目录,博文目录定位错乱,原因不明??? this.blog && _.delay(() => this._scrollTo(this.blog.id), 1000); @@ -118,6 +129,22 @@ export class EmBlogLeftSidebar { }); } + _fixBlog(blogs, bid) { + let _blog = null; + _.each(blogs, blog => { + if (blog.id == bid) { + _blog = blog; + return false; + } + _blog = this._fixBlog(blog._childs, bid); + if (_blog) { + return false; + } + }); + + return _blog; + } + /** * 当数据绑定引擎从视图解除绑定时被调用 */ @@ -567,9 +594,22 @@ export class EmBlogLeftSidebar { this._recentOpenHandle(data.data); this.blogs = data.data; - this.blog = _.find(this.blogs, { - id: +nsCtx.blogId - }); + + this.blog = this._fixBlog(this.blogs, +nsCtx.blogId); + + if (!this.blog) { + $.get('/admin/blog/get', { + id: nsCtx.blogId + }, (data) => { + if (data.success) { + this.blog = data.data; + this.blog._openTime = new Date().getTime() + } else { + toastr.error(data.data, "获取博文失败!"); + } + }); + } + } }); } @@ -744,34 +784,52 @@ export class EmBlogLeftSidebar { this.folded && $(this.leftBarRef).css('left', -$(this.leftBarRef).width()); } - createHandler(space, dir) { + createHandler(space, dir, blog) { if (!nsCtx.isModaalOpening) { nsCtx.newBlogSpace = space; nsCtx.newBlogDir = dir; - // console.log(nsCtx.newBlogSpace); + nsCtx.newBlogBlog = blog; $('a[href="#modaal-blog-write"]').click(); } } - createHtmlHandler(space, dir) { - $('.em-blog-write-html > iframe').attr('src', this.baseRes + 'blog.html' + '?_=' + new Date().getTime() + '&spaceId=' + (space ? space.id : '') + '&dirId=' + (dir ? dir.id : '')); + createHtmlHandler(space, dir, blog) { + $('.em-blog-write-html > iframe').attr('src', this.baseRes + 'blog.html' + '?_=' + new Date().getTime() + '&spaceId=' + (space ? space.id : '') + '&dirId=' + (dir ? dir.id : '') + '&pid=' + (blog ? blog.id : '')); $('a[href="#modaal-blog-write-html"]').click(); return false; } - createMindHandler(space, dir) { - $('.em-blog-write-mind > iframe').attr('src', this.baseRes + 'mind.html' + '?_=' + new Date().getTime() + '&spaceId=' + (space ? space.id : '') + '&dirId=' + (dir ? dir.id : '')); + createMindHandler(space, dir, blog) { + $('.em-blog-write-mind > iframe').attr('src', this.baseRes + 'mind.html' + '?_=' + new Date().getTime() + '&spaceId=' + (space ? space.id : '') + '&dirId=' + (dir ? dir.id : '') + '&pid=' + (blog ? blog.id : '')); $('a[href="#modaal-blog-write-mind"]').click(); return false; } - createExcelHandler(space, dir) { - $('.em-blog-write-excel > iframe').attr('src', this.baseRes + 'excel.html' + '?_=' + new Date().getTime() + '&spaceId=' + (space ? space.id : '') + '&dirId=' + (dir ? dir.id : '')); + createExcelHandler(space, dir, blog) { + $('.em-blog-write-excel > iframe').attr('src', this.baseRes + 'excel.html' + '?_=' + new Date().getTime() + '&spaceId=' + (space ? space.id : '') + '&dirId=' + (dir ? dir.id : '') + '&pid=' + (blog ? blog.id : '')); $('a[href="#modaal-blog-write-excel"]').click(); return false; } - selectTplHandler(space, dir) { - this.blogTplSelectMd.show(space, dir); + selectTplHandler(space, dir, blog) { + this.blogTplSelectMd.show(space, dir, blog); + } + + loadChildBlogs(blog) { + + if (!blog.hasChild) return; + + blog._open = !blog._open; + if (blog._open) { + $.get('/admin/blog/list/by/pid', { + pid: blog.id + }, (data) => { + if (data.success) { + blog._childs = data.data; + } else { + toastr.error(data.data); + } + }); + } } } diff --git a/src/resources/elements/em-blog-left-sidebar.less b/src/resources/elements/em-blog-left-sidebar.less index 451a1be..83fd743 100644 --- a/src/resources/elements/em-blog-left-sidebar.less +++ b/src/resources/elements/em-blog-left-sidebar.less @@ -52,7 +52,7 @@ display: none; position: absolute; right: 0; - top: -2px; + top: 3px; } } >.item { @@ -86,7 +86,7 @@ display: none; position: absolute; right: 0; - top: -2px; + top: 3px; } } .ui.bulleted.list { @@ -139,8 +139,8 @@ color: #999; } &.active { - font-weight: bold; >a { + font-weight: bold; color: black; } } @@ -148,6 +148,29 @@ // box-shadow: 0px 0px 2px -1px #5791cb; background-color: rgba(232, 224, 224, 0.5); } + .actions { + position: absolute; + top: 3px; + right: 0; + } + >.list { + .item{ + padding-top: 5px; + padding-bottom: 5px;; + > a { + display: block; + } + &.active { + font-weight: bold; + >a { + color: black; + } + } + &:hover { + background-color: rgba(232, 224, 224, 1); + } + } + } } } height: e("calc(100% - 40px)")!important; diff --git a/src/resources/elements/em-blog-tpl-select.js b/src/resources/elements/em-blog-tpl-select.js index f2d1d36..beb0971 100644 --- a/src/resources/elements/em-blog-tpl-select.js +++ b/src/resources/elements/em-blog-tpl-select.js @@ -40,16 +40,18 @@ export class EmBlogTplSelect { unbind() { this.space = null; this.dir = null; + this.blog = null; } approveHandler(modal) { } - show(space, dir) { + show(space, dir, blog) { this.space = space; this.dir = dir; + this.blog = blog; this.emModal.show({ hideOnApprove: true, @@ -59,17 +61,18 @@ export class EmBlogTplSelect { createHandler(item) { if (item.editor == 'Html') { - $('.em-blog-write-html > iframe').attr('src', utils.getResourceBase() + 'blog.html?id=' + item.id + '©' + '&_=' + new Date().getTime() + '&spaceId=' + (this.space ? this.space.id : '') + '&dirId=' + (this.dir ? this.dir.id : '')); + $('.em-blog-write-html > iframe').attr('src', utils.getResourceBase() + 'blog.html?id=' + item.id + '©' + '&_=' + new Date().getTime() + '&spaceId=' + (this.space ? this.space.id : '') + '&dirId=' + (this.dir ? this.dir.id : '') + '&pid=' + (this.blog ? this.blog.id : '')); $('a[href="#modaal-blog-write-html"]').click(); } else if (item.editor == 'Mind') { - $('.em-blog-write-mind > iframe').attr('src', utils.getResourceBase() + 'mind.html?id=' + item.id + '©' + '&_=' + new Date().getTime() + '&spaceId=' + (this.space ? this.space.id : '') + '&dirId=' + (this.dir ? this.dir.id : '')); + $('.em-blog-write-mind > iframe').attr('src', utils.getResourceBase() + 'mind.html?id=' + item.id + '©' + '&_=' + new Date().getTime() + '&spaceId=' + (this.space ? this.space.id : '') + '&dirId=' + (this.dir ? this.dir.id : '') + (this.blog ? this.blog.id : '')); $('a[href="#modaal-blog-write-mind"]').click(); } else if (item.editor == 'Excel') { - $('.em-blog-write-excel > iframe').attr('src', utils.getResourceBase() + 'excel.html?id=' + item.id + '©' + '&_=' + new Date().getTime() + '&spaceId=' + (this.space ? this.space.id : '') + '&dirId=' + (this.this.dir ? this.dir.id : '')); + $('.em-blog-write-excel > iframe').attr('src', utils.getResourceBase() + 'excel.html?id=' + item.id + '©' + '&_=' + new Date().getTime() + '&spaceId=' + (this.space ? this.space.id : '') + '&dirId=' + (this.this.dir ? this.dir.id : '') + (this.blog ? this.blog.id : '')); $('a[href="#modaal-blog-write-excel"]').click(); } else if (!nsCtx.isModaalOpening) { nsCtx.newBlogSpace = this.space; nsCtx.newBlogDir = this.dir; + nsCtx.newBlogBlog = this.blog; ea.publish(nsCons.EVENT_BLOG_ACTION, { action: 'copy', id: item.id diff --git a/src/resources/elements/em-blog-write.js b/src/resources/elements/em-blog-write.js index f85cf76..234af66 100644 --- a/src/resources/elements/em-blog-write.js +++ b/src/resources/elements/em-blog-write.js @@ -99,6 +99,7 @@ export class EmBlogWrite { nsCtx.isModaalOpening = false; nsCtx.newBlogSpace = null; nsCtx.newBlogDir = null; + nsCtx.newBlogBlog = null; if (this.stompClient) { this.stompClient.disconnect(() => { @@ -767,7 +768,7 @@ export class EmBlogWrite { } if (!this.blog) { - if (event.ctrlKey || nsCtx.newBlogSpace) { + if (event.ctrlKey || nsCtx.newBlogSpace || nsCtx.newBlogBlog) { // 给消息体增加uuid nsCtx.b_uuid = nsCtx.b_uuid || utils.uuid(); $.post(`/admin/blog/create`, { @@ -777,6 +778,7 @@ export class EmBlogWrite { content: content, spaceId: nsCtx.newBlogSpace ? nsCtx.newBlogSpace.id : '', dirId: nsCtx.newBlogDir ? nsCtx.newBlogDir.id : '', + pid: nsCtx.newBlogBlog ? nsCtx.newBlogBlog.id : '', privated: false, uuid: nsCtx.b_uuid, contentHtml: utils.md2html(content, true) -- Gitee From d9aca522158f0d35e0a528c44aac8b4746215b99 Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Mon, 5 Apr 2021 08:40:00 +0800 Subject: [PATCH 02/25] ... --- .../elements/em-blog-left-sidebar.html | 2 +- .../elements/em-blog-left-sidebar.js | 151 +++++++++++------- 2 files changed, 97 insertions(+), 56 deletions(-) diff --git a/src/resources/elements/em-blog-left-sidebar.html b/src/resources/elements/em-blog-left-sidebar.html index 0c1273f..3f56cdd 100644 --- a/src/resources/elements/em-blog-left-sidebar.html +++ b/src/resources/elements/em-blog-left-sidebar.html @@ -237,7 +237,7 @@
+ show.bind="!item._hidden && !item.pid" class="item blog-item ${item.id == blog.id ? 'active' : ''}"> diff --git a/src/resources/elements/em-blog-left-sidebar.js b/src/resources/elements/em-blog-left-sidebar.js index c9fc71a..ffa71b2 100644 --- a/src/resources/elements/em-blog-left-sidebar.js +++ b/src/resources/elements/em-blog-left-sidebar.js @@ -44,10 +44,11 @@ export class EmBlogLeftSidebar { if (payload.action == 'created') { if (payload.blog.pid) { - let blog = this._fixBlog(this.blogs, payload.blog.pid); - if (blog) { - blog._childs = blog._childs ? [payload.blog, ...blog._childs] : [payload.blog]; - } + this._fixBlogSync(payload.blog.pid).then(blog => { + if (blog) { + blog._childs = blog._childs ? [payload.blog, ...blog._childs] : [payload.blog]; + } + }); } else { this.blogs = [payload.blog, ...this.blogs]; } @@ -101,10 +102,7 @@ export class EmBlogLeftSidebar { } }); this.subscribe2 = ea.subscribe(nsCons.EVENT_BLOG_SWITCH, (payload) => { - // this.blog = _.find(this.blogs, { - // id: +nsCtx.blogId - // }); - this.blog = this._fixBlog(this.blogs, +nsCtx.blogId); + this._fixBlogSync(+nsCtx.blogId).then(b => this.blog = b); payload.anchor && this.calcTree(); // TODO 这里存在bug,拖拽后重新计划目录,博文目录定位错乱,原因不明??? // payload.anchor && this.refresh(); // TODO 这里存在bug,拖拽后重新计划目录,博文目录定位错乱,原因不明??? this.blog && _.delay(() => this._scrollTo(this.blog.id), 1000); @@ -129,22 +127,6 @@ export class EmBlogLeftSidebar { }); } - _fixBlog(blogs, bid) { - let _blog = null; - _.each(blogs, blog => { - if (blog.id == bid) { - _blog = blog; - return false; - } - _blog = this._fixBlog(blog._childs, bid); - if (_blog) { - return false; - } - }); - - return _blog; - } - /** * 当数据绑定引擎从视图解除绑定时被调用 */ @@ -449,14 +431,12 @@ export class EmBlogLeftSidebar { localStorage.setItem(`tms-blog-recent-open`, JSON.stringify(recentOpenBlogs)); - let b = _.find(this.blogs, { - id: blog.id + this._getBlogs(blog.id).then(blog2 => { + if (blog2) { + blog2._openTime = blog._openTime; + bs.signal('sg-recent-open-refresh'); + } }); - if (b) { - b._openTime = blog._openTime; - bs.signal('sg-recent-open-refresh'); - } - } } @@ -467,15 +447,14 @@ export class EmBlogLeftSidebar { let recentOpenBlogs = JSON.parse(robs); _.each(recentOpenBlogs, b => { - let blog = _.find(blogs, { - id: b.id + this._getBlogs(b.id).then(blog => { + if (blog) { + blog._openTime = b.openTime; + } else { + // TODO 如果不存在(可能被删除了) + b._deleted = true; + } }); - if (blog) { - blog._openTime = b.openTime; - } else { - // TODO 如果不存在(可能被删除了) - b._deleted = true; - } }); } @@ -586,29 +565,91 @@ export class EmBlogLeftSidebar { dir.open = !dir.open; } + _fixBlog(blogs, bid) { + + let _blog = null; + _.each(blogs, blog => { + if (blog.id == bid) { + _blog = blog; + return false; + } + _blog = this._fixBlog(blog._childs, bid); + if (_blog) { + return false; + } + }); + + return _blog; + } + + async _fixBlogSync(id) { + + this.blogs = this.blogs ? this.blogs : []; + + let blog = this._fixBlog(this.blogs, id); + + if (blog) return blog; + + await this._getBlogs(id).then(b => { + if (b) { + blog = b; + } + }); + + return blog; + } + + async _getBlog(id) { + let blog = null; + await $.get('/admin/blog/get', { + id: id + }, (data) => { + if (data.success) { + blog = data.data; + } else { + toastr.error(data.data, "获取博文失败!"); + } + }); + + return blog; + } + + async _getBlogs(id) { + this.blogs = this.blogs ? this.blogs : []; + let blog = _.find(this.blogs, { + id: id + }); + if (blog) return blog; + + await $.get('/admin/blog/get', { + id: id + }, (data) => { + if (data.success) { + blog = _.find(this.blogs, { + id: id + }); + if (!blog) { + blog = data.data; + this.blogs.push(blog); + } + } else { + toastr.error(data.data, "获取博文失败!"); + } + }); + + return blog; + } + getBlogTree() { return $.get('/admin/blog/listMy', (data) => { if (data.success) { - // 最近打开博文处理 - this._recentOpenHandle(data.data); - this.blogs = data.data; - this.blog = this._fixBlog(this.blogs, +nsCtx.blogId); + // 最近打开博文处理 + this._recentOpenHandle(data.data); - if (!this.blog) { - $.get('/admin/blog/get', { - id: nsCtx.blogId - }, (data) => { - if (data.success) { - this.blog = data.data; - this.blog._openTime = new Date().getTime() - } else { - toastr.error(data.data, "获取博文失败!"); - } - }); - } + this._fixBlogSync(+nsCtx.blogId).then(b => this.blog = b); } }); -- Gitee From 7fca3e2688f85b7b8413af564dfd00f34506532d Mon Sep 17 00:00:00 2001 From: xiweicheng Date: Mon, 5 Apr 2021 12:32:55 +0800 Subject: [PATCH 03/25] ... --- .../elements/em-blog-left-sidebar.html | 6 +- .../elements/em-blog-left-sidebar.js | 189 +++++++++++++----- 2 files changed, 143 insertions(+), 52 deletions(-) diff --git a/src/resources/elements/em-blog-left-sidebar.html b/src/resources/elements/em-blog-left-sidebar.html index 3f56cdd..ed8edba 100644 --- a/src/resources/elements/em-blog-left-sidebar.html +++ b/src/resources/elements/em-blog-left-sidebar.html @@ -63,7 +63,8 @@ ${spaceRecent.name}
-