Skip to content
Merged
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
57 changes: 26 additions & 31 deletions src/utils/tools/console-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ export const formatConsoleValue = (
}
break
}
case "Object": {
consoleValue = {
...consoleValue,
...recordLengthLimit,
name: value?.constructor?.name,
attrs: getObjEntries(value),
}
break
}
case "Map": {
consoleValue = {
...consoleValue,
Expand Down Expand Up @@ -126,44 +117,43 @@ export const formatConsoleValue = (
}
break
}
case "Window": {
consoleValue = {
type: "string",
value: "该类型数据暂不支持展示,请在浏览器控制台查看~",
}
break
}
case "console": {
const attrs = Reflect.ownKeys(value).map((key: string | symbol) => {
const newValue = key === "memory"
? {
// @ts-expect-error: memory exist
jsHeapSizeLimit: console.memory?.jsHeapSizeLimit,
// @ts-expect-error: memory exist
totalJSHeapSize: console.memory?.totalJSHeapSize,
// @ts-expect-error: memory exist
usedJSHeapSize: console.memory?.usedJSHeapSize,
}
: value[key]
return { key: String(key), value: newValue }
})
consoleValue = {
...consoleValue,
...recordLengthLimit,
attrs,
type: "Object",
name: value?.constructor?.name,
attrs: Object.keys(value).map((key) => {
const newValue = key === "memory"
? {
// @ts-expect-error: memory exist
jsHeapSizeLimit: console.memory?.jsHeapSizeLimit,
// @ts-expect-error: memory exist
totalJSHeapSize: console.memory?.totalJSHeapSize,
// @ts-expect-error: memory exist
usedJSHeapSize: console.memory?.usedJSHeapSize,
}
: value[key]
return { key, value: newValue }
}),
size: attrs.length,
}
break
}
default: {
if (isElement(value)) {
const attrs = Array
.from((value as HTMLElement).attributes)
.map((item) => ({ key: item.name, value: item.value }))
consoleValue = {
...consoleValue,
...listLengthLimit,
attrs,
type: "Element",
value: value.toString(),
name: (value as HTMLElement).nodeName.toLowerCase(),
attrs: Array.from((value as HTMLElement).attributes).map((item) => ({ key: item.name, value: item.value })),
size: attrs.length,
suffix: [
(value as HTMLElement).id ? `#${(value as HTMLElement).id}` : "",
(value as HTMLElement).classList?.length
Expand All @@ -172,12 +162,17 @@ export const formatConsoleValue = (
].join(""),
}
} else {
const attrs = Reflect.ownKeys(value).map((key: string | symbol) => ({
key: String(key),
value: value[key],
}))
consoleValue = {
...consoleValue,
...recordLengthLimit,
attrs,
type: "Object",
name: value?.constructor?.name,
attrs: getObjEntries(value),
size: attrs.length,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div @click="handleClickFold">
<slot></slot>
</div>
<div v-show="modelValue">
<div v-if="modelValue">
<slot name="content"></slot>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
class="console-item pl-xs pr-xxl p-y-xs font-xxs flex"
class="console-item pl-xs pr-xxl p-y-xs font-xxs flex over-hidden over-x-auto common-scrollbar"
:class="[`console-${logInfo.type}`]">
<!-- icon -->
<div class="inline-flex flex-center mr-xs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div v-else-if="type === 'Array'">
<!-- ▶ (6) [{...}, 1, "123", true, ƒ, Array(0)] -->
<span v-if="simple">Array({{ size }})</span>
<console-fold v-else v-model="isFold">
<console-fold v-else v-model="isUnfold">
<template #default>
<span v-if="size">({{ size }}) </span>
<span>[</span>
Expand All @@ -43,7 +43,7 @@
</div>
<div v-else-if="type === 'Object'">
<span v-if="simple">{{ name === 'Object' ? "{...}" : name }}</span>
<console-fold v-else v-model="isFold">
<console-fold v-else v-model="isUnfold">
<template #default>
<span v-if="name">{{ name === 'Object' ? "" : name }} </span>
<span>{</span>
Expand All @@ -60,7 +60,7 @@
</template>
<template #content>
<template v-for="(item, index) in attrs" :key="item.key">
<div v-if="index < maxLength">
<div class="flex" v-if="index < maxLength">
<span class="console-attribute-name">{{ item.key }}</span>
<span>:&nbsp;</span>
<console-value v-bind="unfoldListData[index]"></console-value>
Expand All @@ -85,7 +85,7 @@
<span>{{ toStringTag }}</span>
<span v-if="size">({{ size }})</span>
</template>
<console-fold v-else v-model="isFold">
<console-fold v-else v-model="isUnfold">
<template #default>
<span>{{ toStringTag }}</span>
<span v-if="size">({{ size }})</span>
Expand Down Expand Up @@ -119,7 +119,7 @@
<span>{{ toStringTag }}</span>
<span v-if="size">({{ size }})</span>
</template>
<console-fold v-else v-model="isFold">
<console-fold v-else v-model="isUnfold">
<!-- ▶ Set(9) {{…}, Array(0), 3, 4, 5, …} -->
<template #default>
<span>{{ toStringTag }}</span>
Expand Down Expand Up @@ -154,7 +154,7 @@
<span>{{ toStringTag }}</span>
<span v-if="size">({{ size }})</span>
</template>
<console-fold v-else v-model="isFold">
<console-fold v-else v-model="isUnfold">
<template #default>
<span>{{ toStringTag }}</span>
<span v-if="size">({{ size }})</span>
Expand Down Expand Up @@ -200,7 +200,7 @@
<script setup lang="ts">
import { IConsoleValueMapData, IProps } from "./console-value"
import ConsoleFold from "../console-fold/console-fold.vue"
import { ref } from "vue"
import { ref, watch } from "vue"
import { formatConsoleValue } from "@utils/tools/console-value"
import { IConsoleValue } from "@type/console"
import { basicTypes } from "@utils/tools"
Expand All @@ -210,8 +210,8 @@ const props = withDefaults(defineProps<IProps>(), {
maxLength: Infinity,
simple: false,
})
const isFold = ref<boolean>(false)

const isUnfold = ref<boolean>(false)
const hasInitUnfoldData = ref<boolean>(false)
/** 展示的数据(缩起) */
const foldListData: IConsoleValue[] = []
/** 展示的数据(展开) */
Expand All @@ -220,67 +220,79 @@ const unfoldListData: IConsoleValue[] = []
const foldMapData: IConsoleValueMapData[] = []
/** 展示的键值对数据(展开) */
const unfoldMapData: IConsoleValueMapData[] = []
// eslint-disable-next-line max-lines-per-function
const setFoldData = () => {
const { type, value, attrs = [], minLength, maxLength, size = 0 } = props

watch(isUnfold, (newState) => {
if (hasInitUnfoldData.value || !newState) { return }
setUnfoldData()
hasInitUnfoldData.value = true
})

const setUnfoldData = () => {
const { type, value, attrs = [], maxLength, size = 0 } = props
const loopTime = Math.min(size, maxLength)
switch(type) {
case "Array": {
const loopTime = Math.min(size, maxLength)
case "Array":
case "NodeList": {
for (let i = 0; i < loopTime; i ++) {
const result = formatConsoleValue(value[i])
if (i < minLength) {
foldListData.push(result)
}
unfoldListData.push(result)
}
break
}
case "Object": {
const loopTime = Math.min(attrs.length, maxLength)
case "Object":
case "Set":
case "WeakSet": {
for (let i = 0; i < loopTime; i ++) {
const result = formatConsoleValue(attrs[i].value)
if (i < minLength) {
foldListData.push(result)
}
unfoldListData.push(result)
}
break
}
case "Map":
case "WeakMap": {
const loopTime = Math.min(attrs.length, maxLength)
for (let i = 0; i < loopTime; i ++) {
const result = {
key: formatConsoleValue(attrs[i].key),
value: formatConsoleValue(attrs[i].value),
}
if (i < minLength) {
foldMapData.push(result)
}
unfoldMapData.push(result)
}
break
}
default: {}
}
}

// eslint-disable-next-line max-lines-per-function
const setFoldData = () => {
const { type, value, attrs = [], minLength, size = 0 } = props
const loopTime = Math.min(size, minLength)
switch(type) {
case "Array":
case "NodeList": {
for (let i = 0; i < loopTime; i ++) {
const result = formatConsoleValue(value[i])
foldListData.push(result)
}
break
}
case "Object":
case "Set":
case "WeakSet": {
const loopTime = Math.min(attrs.length, maxLength)
for (let i = 0; i < loopTime; i ++) {
const result = formatConsoleValue(attrs[i].value)
if (i < minLength) {
foldListData.push(result)
}
unfoldListData.push(result)
foldListData.push(result)
}
break
}
case "NodeList": {
const loopTime = Math.min(value.length, maxLength)
case "Map":
case "WeakMap": {
for (let i = 0; i < loopTime; i ++) {
const result = formatConsoleValue(value[i])
if (i < minLength) {
foldListData.push(result)
const result = {
key: formatConsoleValue(attrs[i].key),
value: formatConsoleValue(attrs[i].value),
}
unfoldListData.push(result)
foldMapData.push(result)
}
break
}
Expand Down
9 changes: 6 additions & 3 deletions src/views/instance/instance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<editor-wrapper></editor-wrapper>
</div>
<!--结果-->
<div class="flex" :style="{ width: `${isShowResult ? modulesSize.resultWidth : 0}px` }">
<div class="flex" :style="{ width: `${resultWidth}px` }">
<div class="resize-line fill-h">
<!--分割线-->
<split-line
Expand All @@ -17,7 +17,7 @@
@mousedown.prevent="handleResizeEditorAndResult"
></split-line>
</div>
<div class="flex-1">
<div :style="{ width: `calc(${resultWidth - resizeLineWidth}px)` }">
<result></result>
</div>
</div>
Expand All @@ -41,7 +41,7 @@ import UpdateLogsModal from "@views/components/modals/update-logs-modal/update-l
import SplitLine from "@components/split-line/split-line.vue"
import Result from "@views/components/result/result.vue"
import { SplitDirection } from "@type/editor"
import { onMounted, watch, onUnmounted } from "vue"
import { computed, onMounted, watch } from "vue"
import { getModulesHeight, getModulesWidth } from "./instance"
import { useLayoutStore } from "@store/layout"
import useWindowResize from "@hooks/use-window-resize"
Expand Down Expand Up @@ -124,6 +124,9 @@ const handleResizeEditorAndResult = (e: MouseEvent): void => {
})
}

const resizeLineWidth = 1
const resultWidth = computed(() => isShowResult ? modulesSize.resultWidth - resizeLineWidth : 0)

onBeforeRouteLeave(() => {
if (import.meta.env.PROD) {
if (!window.confirm("你所做的更改可能未保存。")) {
Expand Down
8 changes: 7 additions & 1 deletion tests/console.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck

console.log(123)
console.log("string")
console.log(true)
Expand Down Expand Up @@ -36,4 +39,7 @@ console.log(window)
console.log(console)
console.log("Find me at http://www.example.com and also at http://stackoverflow.com")
// eslint-disable-next-line max-len
console.log("https://play.vuejs.org/#eNp9kUFLAzEQhf/KmMsq1C61nsq2oFJQDyoqeMmlbKfb1GwSkkktLPvfnaS09iCFHDLvvRm+YTpx59xwG1FMRBVqrxxBQIpuJo1qnfUEHXhcQQ8rb1soOFpII01tTSBoQwPT5F8Wj6i1hS/r9fKiuJKmKvfjeBAXhK3TC0KuAKr1aNZ1ubnvq5KrrCrjIsH2urVL1FMp2JcCSjar8qR/dDPmJwaCAkOsVDPcBGuYv0tTpKht65RG/+pIMaQUE8hO8hbM+POcNfIRBwe9XmP9/Y++CbukSfHmMaDfohRHjxa+Qdrb848X3PH/aPIOUXP6jPmOweqYGPex+2iWjH2Sy7RP+QrKNJ9hviM04bBUAk3JPuel4Ms8nFn9D3c8vM190vSi/wUJTKhh")
console.log("https://play.vuejs.org/#eNp9kUFLAzEQhf/KmMsq1C61nsq2oFJQDyoqeMmlbKfb1GwSkkktLPvfnaS09iCFHDLvvRm+YTpx59xwG1FMRBVqrxxBQIpuJo1qnfUEHXhcQQ8rb1soOFpII01tTSBoQwPT5F8Wj6i1hS/r9fKiuJKmKvfjeBAXhK3TC0KuAKr1aNZ1ubnvq5KrrCrjIsH2urVL1FMp2JcCSjar8qR/dDPmJwaCAkOsVDPcBGuYv0tTpKht65RG/+pIMaQUE8hO8hbM+POcNfIRBwe9XmP9/Y++CbukSfHmMaDfohRHjxa+Qdrb848X3PH/aPIOUXP6jPmOweqYGPex+2iWjH2Sy7RP+QrKNJ9hviM04bBUAk3JPuel4Ms8nFn9D3c8vM190vSi/wUJTKhh")
const circle = {}
circle.circle = circle
console.log(circle)