diff --git a/zyplayer-doc-ui/wiki-ui/.env.development b/zyplayer-doc-ui/wiki-ui/.env.development index 58e9a01d..fb7181ed 100644 --- a/zyplayer-doc-ui/wiki-ui/.env.development +++ b/zyplayer-doc-ui/wiki-ui/.env.development @@ -2,8 +2,8 @@ ENV = 'development' # base api -VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage' -# VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage' +# VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage' +VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage' VUE_CLI_BABEL_TRANSPILE_MODULES = true diff --git a/zyplayer-doc-ui/wiki-ui/src/common/lib/HtmlUtil.js b/zyplayer-doc-ui/wiki-ui/src/common/lib/HtmlUtil.js new file mode 100644 index 00000000..be3d63e3 --- /dev/null +++ b/zyplayer-doc-ui/wiki-ui/src/common/lib/HtmlUtil.js @@ -0,0 +1,115 @@ + +export default { + /** + * 生成目录树 + * ======================================================== + * 说明:代码修改至 yaohaixiao 的 autoc.js + * 项目 gitee 地址:https://gitee.com/yaohaixiao/AutocJS + * ======================================================== + */ + createNavigationHeading() { + let headArr = []; + let headNodeArr = document.querySelector('.wiki-page-content').querySelectorAll('h1,h2,h3,h4,h5,h6'); + if (headNodeArr.length <= 0) { + return []; + } + headNodeArr.forEach(node => { + headArr.push({ + node: node, + level: parseInt(node.tagName.replace(/[h]/i, ''), 10) + }); + }); + let chapters = [] + let previous = 1 + let level = 0 + headArr.forEach((heading, i) => { + let current = heading.level + let pid = -1 + // 当前标题的(标题标签)序号 > 前一个标题的序号:两个相连的标题是父标题 -> 子标题关系; + // h2 (前一个标题) + // h3 (当前标题) + if (current > previous) { + level += 1 + // 第一层级的 pid 是 -1 + if (level === 1) { + pid = -1 + } else { + pid = i - 1 + } + } + // 当前标题的(标题标签)序号 = 前一个标题的序号 + // h2 (前一个标题) + // h2 (当前标题) + // 当前标题的(标题标签)序号 < 前一个标题的序号,并且当前标题序号 > 当前的级别 + // h2 + // h4 (前一个标题) + // h3 (当前标题:这种情况我们还是任务 h3 是 h2 的下一级章节) + else if (current === previous || (current < previous && current > level)) { + // H1 的层级肯定是 1 + if (current === 1) { + level = 1 + pid = -1 + } else { + pid = chapters[i - 1].pid + } + } else if (current <= level) { + // H1 的层级肯定是 1 + if (current === 1) { + level = 1 + } else { + level = level - (previous - current) + + if (level <= 1) { + level = 1 + } + } + // 第一级的标题 + if (level === 1) { + pid = -1 + } else { + // 虽然看上去差点,不过能工作啊 + pid = this.generatePid(chapters, previous - current, i) + } + } + previous = current + chapters.push({ + id: i, + pid: pid, + level: level, + node: heading.node, + text: this.stripTags(this.trim(heading.node.innerHTML)) + }); + }) + console.log(chapters); + return chapters; + }, + trim: (str) => { + return str.replace(/^\s+/g, '').replace(/\s+$/g, '') + }, + stripTags: (str) => { + return str.replace(/<\/?[^>]+(>|$)/g, '') + }, + generatePid(chapters, differ, index) { + let pid + // 最大只有 5 级的差距 + switch (differ) { + case 2: + pid = chapters[chapters[chapters[index - 1].pid].pid].pid + break + case 3: + pid = chapters[chapters[chapters[chapters[index - 1].pid].pid].pid].pid + break + case 4: + pid = chapters[chapters[chapters[chapters[chapters[index - 1].pid].pid].pid].pid].pid + break + case 5: + pid = chapters[chapters[chapters[chapters[chapters[chapters[index - 1].pid].pid].pid].pid].pid].pid + break + default: + pid = chapters[chapters[index - 1].pid].pid + break + } + return pid + }, +} + diff --git a/zyplayer-doc-ui/wiki-ui/src/common/lib/UnitUtil.js b/zyplayer-doc-ui/wiki-ui/src/common/lib/UnitUtil.js new file mode 100644 index 00000000..9e191e48 --- /dev/null +++ b/zyplayer-doc-ui/wiki-ui/src/common/lib/UnitUtil.js @@ -0,0 +1,26 @@ + +export default { + computeFileSize(fileSize) { + if (!fileSize) { + return '-'; + } + let size = ""; + if (fileSize < 0.1 * 1024) { + size = fileSize.toFixed(2) + "B" + } else if (fileSize < 0.1 * 1024 * 1024) { + size = (fileSize / 1024).toFixed(2) + "KB" + } else if (fileSize < 0.1 * 1024 * 1024 * 1024) { + size = (fileSize / (1024 * 1024)).toFixed(2) + "MB" + } else { + size = (fileSize / (1024 * 1024 * 1024)).toFixed(2) + "GB" + } + let sizeStr = size + ""; + let index = sizeStr.indexOf("."); + let dou = sizeStr.substr(index + 1, 2); + if (dou == "00") { + return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2) + } + return size; + }, +} + diff --git a/zyplayer-doc-ui/wiki-ui/src/common/lib/common.js b/zyplayer-doc-ui/wiki-ui/src/common/lib/common.js deleted file mode 100644 index cb0685fa..00000000 --- a/zyplayer-doc-ui/wiki-ui/src/common/lib/common.js +++ /dev/null @@ -1,90 +0,0 @@ -import vue from '../../main' - -export default { - data: { - accessToken: '', - }, - setAccessToken: function (token) { - this.data.accessToken = token; - }, - getAccessToken: function () { - if (!this.data.accessToken) { - var arr, reg = new RegExp("(^| )accessToken=([^;]*)(;|$)"); - if (arr = document.cookie.match(reg)) { - this.data.accessToken = unescape(arr[2]); - } - } - return this.data.accessToken; - }, - validateResult: function (res) { - return new Promise(function (resolve, reject) { - if (!!res.message) { - vue.$message('请求错误:' + res.message); - } else if (res.data.errCode == 400) { - vue.$message('请先登录'); - var href = encodeURIComponent(window.location.href); - window.location = process.env.VUE_APP_BASE_API + "#/user/login?redirect=" + href; - } else if (res.data.errCode == 402) { - vue.$router.push("/common/noAuth"); - } else if (res.data.errCode !== 200) { - vue.$message(res.data.errMsg || "未知错误"); - } else { - resolve(res.data); - } - }); - }, - /** - * 返回不为空的字符串,为空返回def - */ - getNotEmptyStr(str, def) { - if (isEmpty(str)) { - return isEmpty(def) ? "" : def; - } - return str; - }, - /** - * 是否是空对象 - * @param obj - * @returns - */ - isEmptyObject(obj) { - return isEmpty(obj) || $.isEmptyObject(obj); - }, - /** - * 是否是空字符串 - * @param str - * @returns - */ - isEmpty(str) { - return (str == "" || str == null || str == undefined); - }, - /** - * 是否不是空字符串 - * @param str - * @returns - */ - isNotEmpty(str) { - return !isEmpty(str); - }, - /** - * param 将要转为URL参数字符串的对象 - * key URL参数字符串的前缀 - * encode true/false 是否进行URL编码,默认为true - * return URL参数字符串 - */ - objUrlEncode(param, key, encode) { - if (param == null) return ''; - var paramStr = ''; - var t = typeof (param); - if (t == 'string' || t == 'number' || t == 'boolean') { - paramStr += '&' + key + '=' + ((encode == null || encode) ? encodeURIComponent(param) : param); - } else { - for (var i in param) { - var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i); - paramStr += urlEncode(param[i], k, encode); - } - } - return paramStr; - } -} - diff --git a/zyplayer-doc-ui/wiki-ui/src/components/layouts/GlobalLayout.vue b/zyplayer-doc-ui/wiki-ui/src/components/layouts/GlobalLayout.vue index 38804c09..0d756278 100644 --- a/zyplayer-doc-ui/wiki-ui/src/components/layouts/GlobalLayout.vue +++ b/zyplayer-doc-ui/wiki-ui/src/components/layouts/GlobalLayout.vue @@ -1,7 +1,7 @@