diff --git a/CHANGELOG.md b/CHANGELOG.md index a46cead..a5104c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ 范围|描述|commitId --|--|-- plugin | 插件解析机制完善 | 0f5a27d + project title | 项目标题修改; 切换角色移除script | 5c20017 role | 切换角色的逻辑修正完善 | 4ae534f task任务逻辑完善 | 减少初始global及regular的不必要请求 | bd4bd38 - | 上下滑动加载定期任务 | 4090d89 diff --git a/src/components/Plugin/Plugin.vue b/src/components/Plugin/Plugin.vue index 1a238d8..328cb98 100644 --- a/src/components/Plugin/Plugin.vue +++ b/src/components/Plugin/Plugin.vue @@ -68,11 +68,13 @@ export default { if (!data || !data.id) return; const reg = /data-root=["|']?(\w+)["|']?/gi; // console.log(data.html); + let uuid = ''; + // FIXME: 没有兼容只有js 没有html的情况 if (data.html) { // 查有没有data-root=“xxx” 有的话 将xxx替换为 pluginTaskId if (reg.test(data.html)) { - const uuid = RegExp.$1; + uuid = RegExp.$1; // console.log('uuid: ', uuid, `p${this.pluginTaskId}`); const str = data.html.replaceAll(uuid, `p${this.pluginTaskId}`); @@ -80,34 +82,38 @@ export default { } else { this.pluginContent = data.html; } + + const str = data.js.replaceAll(uuid, `p${this.pluginTaskId}`); + this.handleDom(str); } // console.log(this.pluginContent); - if (data.js) { - if (reg.test(data.js)) { - const uuid = RegExp.$1; - const str = data.js.replaceAll(uuid, `p${this.pluginTaskId}`); - this.handleDom(str); - } else { - this.handleDom(data.js); - } - } + // if (data.js) { + // if (reg.test(data.js)) { + // const uuid = RegExp.$1; + // const str = data.js.replaceAll(uuid, `p${this.pluginTaskId}`); + // this.handleDom(str); + // } else { + // this.handleDom(data.js); + // } + // } }, // 创建script dom handleDom(js) { - const { pluginId } = this; + const { pluginTaskId } = this; let domList = Array.from(document.getElementsByTagName('script')); - const index = domList.findIndex(item => item.id === `p${pluginId}`); - if (js && index === -1) { - const scriptDom = document.createElement('script'); - scriptDom.id = `p${pluginId}`; - scriptDom.setAttribute('data-type', 'plugin'); - scriptDom.innerHTML = js; - this.$nextTick(() => { - document.body.append(scriptDom); - }); + const index = domList.findIndex(item => item.id === `p${pluginTaskId}`); + if (index >= 0) { + document.body.removeChild(document.getElementById(`p${pluginTaskId}`)); } + const scriptDom = document.createElement('script'); + scriptDom.id = `p${pluginTaskId}`; + scriptDom.setAttribute('data-type', 'plugin'); + scriptDom.innerHTML = js; + this.$nextTick(() => { + document.body.append(scriptDom); + }); }, }, }; diff --git a/src/components/Roles/Roles.vue b/src/components/Roles/Roles.vue index 3dc6811..d2d1183 100644 --- a/src/components/Roles/Roles.vue +++ b/src/components/Roles/Roles.vue @@ -97,18 +97,19 @@ export default { try { // 清除多余的script this.clearPluginScript(); - - this.setRoleId(id); - //改变index 即手动点击切换 我在此时将当前元素赋值给左边距 实现自动滚动 - this.setCurrentRole(index); - // 清空定期任务数据 - this.setTasks(); - // 清空日常任务的数据 - this.setPermanents([]); - this.setDailyTasks([]); - // 到顶的标志复位 - // 到底的标志复位 - this.clearEndFlag(); + this.$nextTick(() => { + this.setRoleId(id); + //改变index 即手动点击切换 我在此时将当前元素赋值给左边距 实现自动滚动 + this.setCurrentRole(index); + // 清空定期任务数据 + this.setTasks(); + // 清空日常任务的数据 + this.setPermanents([]); + this.setDailyTasks([]); + // 到顶的标志复位 + // 到底的标志复位 + this.clearEndFlag(); + }); } catch (error) { console.log('role.vue changeRole error: ', error); } @@ -117,10 +118,14 @@ export default { // 清除插件script clearPluginScript() { console.log('clearPluginScript: '); + try { + const scripts = document.querySelectorAll('script[data-type=plugin]'); - const scripts = document.querySelectorAll('script[data-type=plugin]'); - for (let i = 0; i < scripts.length; i++) { - document.body.removeChild(scripts[i]); + for (let i = 0; i < scripts.length; i++) { + document.body.removeChild(scripts[i]); + } + } catch (error) { + console.log('clearPluginScript error: ', error); } }, diff --git a/src/components/TimeLine/TimeLine.vue b/src/components/TimeLine/TimeLine.vue index 65b0c4f..92c593f 100644 --- a/src/components/TimeLine/TimeLine.vue +++ b/src/components/TimeLine/TimeLine.vue @@ -23,7 +23,7 @@