Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 优化元素查看 #1091

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Web/packages/core/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const store = new Store({
mcHostWaitFetchRequestQueue:[],
mcHostWaitFetchResponseQueue:[],
isNative:false,
activeNodeKey: null,
}
})

Expand Down Expand Up @@ -51,6 +52,10 @@ export function toggleElement(element){
store.state.highlightElement = element;
}

export function activeNodeTree(key){
store.state.activeNodeKey = key;
}

export function addIndependPlugin(plugin){
// Unique Container
let index = store.state.independPlugins.findIndex(ele => {
Expand Down
14 changes: 14 additions & 0 deletions Web/packages/web/src/plugins/element/elementContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import ElementDetails from './elementDetails.vue';
import ElementSnippet from './elementSnippet.vue';
// import MutationObserver from 'mutation-observer';
import { guid, $bus } from '../../assets/util';
import { debounce } from "../../assets/util";
import { toggleElement } from '@dokit/web-core';
export default {
components: {
Expand All @@ -58,7 +59,11 @@ export default {
active: 0,
};
},
created() {
this.watchWindowSize = debounce(this.watchWindowSize, 300);
},
mounted() {
window.addEventListener("resize", this.watchWindowSize);
this.node = this.getNode(document.documentElement);
this.observer = new MutationObserver((mutations) => {
for (let i = 0; i < mutations.length; i++) {
Expand All @@ -82,6 +87,7 @@ export default {
},
},
destroyed() {
window.removeEventListener("resize", this.watchWindowSize);
this.observer.disconnect();
},
watch: {
Expand Down Expand Up @@ -324,6 +330,14 @@ export default {
return attrStyle;
}
},
watchWindowSize() {
this.node = this.getNode(document.documentElement);
this.oldElement = this.highlightElement
toggleElement(null);
this.$nextTick(() => {
toggleElement(this.oldElement);
});
}
},
};
</script>
Expand Down
39 changes: 29 additions & 10 deletions Web/packages/web/src/plugins/element/elementTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
unfold ? 'dk-toggle' : '',
]"
>
<span class="dkelm-node" @click="unfoldDetail">
<span class="dkelm-node" :class="[isActived ? 'actived' : '']" @click="unfoldDetail">
&lt;{{ node.tagName.toLowerCase() }}
<i class="dkelm-k" v-if="node.className || node.attributes.length">
<span v-for="(item, index) in node.attributes" :key="index">
Expand All @@ -33,7 +33,7 @@
<ElementTree :node="child" :parentIsUnfold="unfold"></ElementTree>
</div>
</template>
<span class="dkelm-node" v-if="!isNullEndTag(node.tagName)"
<span class="dkelm-node" :class="[isActived ? 'actived' : '']" @click="unfoldDetail" v-if="!isNullEndTag(node.tagName)"
>&lt;/{{ node.tagName.toLowerCase() }}&gt;</span
>
</div>
Expand All @@ -46,6 +46,7 @@
<script>
import ElementTree from "./elementTree.vue";
import { $bus } from "../../assets/util";
import { activeNodeTree } from '@dokit/web-core';
export default {
name: "ElementTree",
components: {
Expand Down Expand Up @@ -82,6 +83,21 @@ export default {
immediate: true,
}
},
computed:{
canFold() {
return this.node?.childNodes.length > 0;
},
isActived() {
console.log(this.activeNodeKey)
return this.activeNodeKey === this.node?.key
},
state() {
return this.$store.state;
},
activeNodeKey() {
return this.state.activeNodeKey;
},
},
created() {
if (this?.node?.tagName === "HTML") {
$bus.on(this.node.key, this.refresh);
Expand Down Expand Up @@ -110,14 +126,9 @@ export default {
return names.indexOf(tagName) > -1 ? true : false;
},
unfoldDetail() {
this.canFold()&&(this.unfold = !this.unfold);
},
canFold() {
if (this.node.childNodes.length > 0) {
return true;
}
return false;
},
this.canFold&&(this.unfold = !this.unfold);
activeNodeTree(this.node.key)
},
_trim(str) {
return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
},
Expand All @@ -129,6 +140,11 @@ export default {
.element-tree-container {
font-size: 16px;
position: relative;
&.can-unfold{
&>.dkelm-l>.dkelm-node {
cursor: pointer;
}
}
.dkelm-l {
padding-left: 8px;
position: relative;
Expand Down Expand Up @@ -158,6 +174,9 @@ export default {
}
.dkelm-node {
color: #183691;
&.actived{
background: rgba(0, 0, 0, 0.1);
}
}
.dkelm-k {
color: #0086b3;
Expand Down