Browse Source

style: 统一代码缩进为2个空格,提升代码可读性

此次提交主要将代码中的缩进统一调整为2个空格,替换原有的4个空格或Tab缩进。这一改动不影响代码功能,但有助于提升代码的一致性和可读性。
feat/icon
npmrun 3 weeks ago
parent
commit
b6964f5fbe
  1. 17
      resources/fuck.html
  2. 1
      src/main/modules/api/readme.md
  3. 1
      src/main/modules/api/test.ts
  4. 1175
      src/renderer/auto-imports.d.ts
  5. 17
      src/renderer/index.html
  6. 14
      src/renderer/src/App.vue
  7. 3
      src/renderer/src/assets/libs/scrollbot.ts
  8. 212
      src/renderer/src/components/AdjustLine.vue
  9. 75
      src/renderer/src/components/CodeEditor/code-editor.vue
  10. 42
      src/renderer/src/components/NavBar.vue
  11. 4
      src/renderer/src/components/Versions.vue
  12. 6
      src/renderer/src/layouts/default.vue
  13. 4
      src/renderer/src/pages/_ui/App.vue
  14. 232
      src/renderer/src/pages/_ui/Browser.vue
  15. 46
      src/renderer/src/pages/about/index.vue
  16. 86
      src/renderer/src/pages/browser.vue
  17. 8
      src/renderer/src/pages/index.vue
  18. 1
      src/types/global.d.ts
  19. 4
      推荐.md

17
resources/fuck.html

@ -1,11 +1,12 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title> <title>Document</title>
</head> </head>
<body> <body>
前往 <a href="https://baidu.com" target="_blank">百度</a> 前往
</body> <a href="https://baidu.com" target="_blank">百度</a>
</body>
</html> </html>

1
src/main/modules/api/readme.md

@ -1,4 +1,3 @@
## 资源 ## 资源
- https://juejin.cn/post/7311619723317657611#heading-6 - https://juejin.cn/post/7311619723317657611#heading-6

1
src/main/modules/api/test.ts

@ -69,4 +69,3 @@
// }; // };
// ses.protocol.interceptBufferProtocol("https", interceptHandler); // ses.protocol.interceptBufferProtocol("https", interceptHandler);

1175
src/renderer/auto-imports.d.ts

File diff suppressed because it is too large

17
src/renderer/index.html

@ -1,17 +1,19 @@
<!doctype html> <!doctype html>
<html> <html>
<head>
<head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Electron</title> <title>Electron</title>
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' api: 'unsafe-inline'; <meta
http-equiv="Content-Security-Policy"
content="default-src 'self' api: 'unsafe-inline';
script-src 'self' api:; script-src 'self' api:;
style-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';
img-src 'self' data: *;" /> img-src 'self' data: *;"
</head> />
</head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<noscript> <noscript>
<style> <style>
@ -21,6 +23,5 @@
</style> </style>
</noscript> </noscript>
<script type="module" src="/src/main.ts"></script> <script type="module" src="/src/main.ts"></script>
</body> </body>
</html> </html>

14
src/renderer/src/App.vue

@ -14,17 +14,17 @@
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.slide-fade-enter-active { .slide-fade-enter-active {
transition: all 0.2s ease-out; transition: all 0.2s ease-out;
} }
.slide-fade-leave-active { .slide-fade-leave-active {
transition: all 0.2s cubic-bezier(1, 0.5, 0.8, 1); transition: all 0.2s cubic-bezier(1, 0.5, 0.8, 1);
} }
.slide-fade-enter-from, .slide-fade-enter-from,
.slide-fade-leave-to { .slide-fade-leave-to {
transform: translateX(20px); transform: translateX(20px);
opacity: 0; opacity: 0;
} }
</style> </style>

3
src/renderer/src/assets/libs/scrollbot.ts

@ -205,8 +205,7 @@ class Scrollbot {
this.scrollBar.style.top = `${this.pC}%` this.scrollBar.style.top = `${this.pC}%`
this.inP.scrollTop = this.inP.scrollTop =
((parseFloat(this.scrollBar.style.top) - ((parseFloat(this.scrollBar.style.top) -
((this.sbHeight - parseFloat(this.sB.height)) * this.inP.scrollTop) / ((this.sbHeight - parseFloat(this.sB.height)) * this.inP.scrollTop) / (this.inP.scrollHeight - this.inP.clientHeight)) *
(this.inP.scrollHeight - this.inP.clientHeight)) *
this.inP.scrollHeight) / this.inP.scrollHeight) /
100 100
} else if (this.pC < 0 && parseFloat(this.scrollBar.style.top) > 0) { } else if (this.pC < 0 && parseFloat(this.scrollBar.style.top) > 0) {

212
src/renderer/src/components/AdjustLine.vue

@ -10,16 +10,16 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { nextTick, onMounted, ref, watch, computed, onBeforeUnmount, onErrorCaptured } from "vue" import { nextTick, onMounted, ref, watch, computed, onBeforeUnmount, onErrorCaptured } from "vue"
import { useDebounceFn } from "@vueuse/core" import { useDebounceFn } from "@vueuse/core"
const adjustLineEL = ref<HTMLElement>() const adjustLineEL = ref<HTMLElement>()
// //
type Direction = "left" | "right" | "top" | "bottom" type Direction = "left" | "right" | "top" | "bottom"
// Props // Props
interface AdjustLineProps { interface AdjustLineProps {
/** /**
* 所在方向 'left' | 'right' | 'top' | 'bottom' * 所在方向 'left' | 'right' | 'top' | 'bottom'
*/ */
@ -40,66 +40,66 @@ interface AdjustLineProps {
maxSize?: number maxSize?: number
defaultSize?: number defaultSize?: number
onChange?: (size: number) => void onChange?: (size: number) => void
} }
const props = withDefaults(defineProps<AdjustLineProps>(), { const props = withDefaults(defineProps<AdjustLineProps>(), {
direction: "right", direction: "right",
minSize: 100, minSize: 100,
maxSize: 800, maxSize: 800,
}) })
// //
const emit = defineEmits<{ const emit = defineEmits<{
(e: "resize", size: number): void (e: "resize", size: number): void
(e: "resizeStart"): void (e: "resizeStart"): void
(e: "resizeEnd", size: number): void (e: "resizeEnd", size: number): void
}>() }>()
let curTarget: HTMLElement | undefined | null let curTarget: HTMLElement | undefined | null
const isDragging = ref(false) const isDragging = ref(false)
const currentSize = ref(props.defaultSize || 0) const currentSize = ref(props.defaultSize || 0)
// 使computed // 使computed
const isHorizontal = computed(() => props.direction === "left" || props.direction === "right") const isHorizontal = computed(() => props.direction === "left" || props.direction === "right")
// // 使computed // // 使computed
// const cursorStyle = computed(() => (isHorizontal.value ? "ew-resize" : "ns-resize")) // const cursorStyle = computed(() => (isHorizontal.value ? "ew-resize" : "ns-resize"))
// // localStorage // // localStorage
// const storageKey = computed(() => `adjust-line-${props.mid}`) // const storageKey = computed(() => `adjust-line-${props.mid}`)
// function saveSize(size: number) { // function saveSize(size: number) {
// if (props.mid) { // if (props.mid) {
// try { // try {
// localStorage.setItem(storageKey.value, String(size)) // localStorage.setItem(storageKey.value, String(size))
// } catch (error) { // } catch (error) {
// console.warn("Failed to save size to localStorage:", error) // console.warn("Failed to save size to localStorage:", error)
// } // }
// } // }
// } // }
// function loadSavedSize(): number | null { // function loadSavedSize(): number | null {
// if (props.mid) { // if (props.mid) {
// try { // try {
// const saved = localStorage.getItem(storageKey.value) // const saved = localStorage.getItem(storageKey.value)
// return saved ? Number(saved) : null // return saved ? Number(saved) : null
// } catch (error) { // } catch (error) {
// console.warn("Failed to load size from localStorage:", error) // console.warn("Failed to load size from localStorage:", error)
// return null // return null
// } // }
// } // }
// return null // return null
// } // }
// 使resize // 使resize
const emitResize = useDebounceFn((size: number) => { const emitResize = useDebounceFn((size: number) => {
emit("resize", size) emit("resize", size)
}, 16) }, 16)
// 使ResizeObserver // 使ResizeObserver
let observer: ResizeObserver | null = null let observer: ResizeObserver | null = null
const observeResize = () => { const observeResize = () => {
if (!adjustLineEL.value) return if (!adjustLineEL.value) return
observer = new ResizeObserver(() => { observer = new ResizeObserver(() => {
@ -111,13 +111,13 @@ const observeResize = () => {
}) })
observer.observe(adjustLineEL.value) observer.observe(adjustLineEL.value)
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
observer && observer.disconnect() observer && observer.disconnect()
}) })
onMounted(async () => { onMounted(async () => {
await nextTick() await nextTick()
if (!props.target) { if (!props.target) {
curTarget = adjustLineEL.value?.parentElement curTarget = adjustLineEL.value?.parentElement
@ -137,9 +137,9 @@ onMounted(async () => {
}, },
) )
observeResize() observeResize()
}) })
function handle(target: HTMLElement) { function handle(target: HTMLElement) {
if (!adjustLineEL.value) return if (!adjustLineEL.value) return
const nextContainer = target const nextContainer = target
const el = adjustLineEL.value const el = adjustLineEL.value
@ -316,49 +316,49 @@ function handle(target: HTMLElement) {
} }
} }
} }
} }
// function handleDrag(e: MouseEvent, target: HTMLElement) { // function handleDrag(e: MouseEvent, target: HTMLElement) {
// const startPos = isHorizontal.value ? e.clientX : e.clientY // const startPos = isHorizontal.value ? e.clientX : e.clientY
// const startSize = isHorizontal.value ? target.clientWidth : target.clientHeight // const startSize = isHorizontal.value ? target.clientWidth : target.clientHeight
// const handleMouseMove = (e: MouseEvent) => { // const handleMouseMove = (e: MouseEvent) => {
// const currentPos = isHorizontal.value ? e.clientX : e.clientY // const currentPos = isHorizontal.value ? e.clientX : e.clientY
// const diff = props.direction === "right" || props.direction === "bottom" ? startPos - currentPos : currentPos - startPos // const diff = props.direction === "right" || props.direction === "bottom" ? startPos - currentPos : currentPos - startPos
// let newSize = startSize - diff // let newSize = startSize - diff
// // // //
// newSize = Math.max(props.minSize, Math.min(props.maxSize, newSize)) // newSize = Math.max(props.minSize, Math.min(props.maxSize, newSize))
// // // //
// if (isHorizontal.value) { // if (isHorizontal.value) {
// target.style.width = `${newSize}px` // target.style.width = `${newSize}px`
// } else { // } else {
// target.style.height = `${newSize}px` // target.style.height = `${newSize}px`
// } // }
// currentSize.value = newSize // currentSize.value = newSize
// emit("resize", newSize) // emit("resize", newSize)
// } // }
// const handleMouseUp = () => { // const handleMouseUp = () => {
// document.removeEventListener("mousemove", handleMouseMove) // document.removeEventListener("mousemove", handleMouseMove)
// document.removeEventListener("mouseup", handleMouseUp) // document.removeEventListener("mouseup", handleMouseUp)
// document.body.style.userSelect = "" // document.body.style.userSelect = ""
// isDragging.value = false // isDragging.value = false
// saveSize(currentSize.value) // saveSize(currentSize.value)
// emit("resizeEnd", currentSize.value) // emit("resizeEnd", currentSize.value)
// } // }
// document.addEventListener("mousemove", handleMouseMove) // document.addEventListener("mousemove", handleMouseMove)
// document.addEventListener("mouseup", handleMouseUp) // document.addEventListener("mouseup", handleMouseUp)
// document.body.style.userSelect = "none" // document.body.style.userSelect = "none"
// isDragging.value = true // isDragging.value = true
// emit("resizeStart") // emit("resizeStart")
// } // }
const debug = { const debug = {
log: (...args: any[]) => { log: (...args: any[]) => {
if (process.env.NODE_ENV === "development") { if (process.env.NODE_ENV === "development") {
console.log("[AdjustLine]", ...args) console.log("[AdjustLine]", ...args)
@ -367,23 +367,23 @@ const debug = {
error: (...args: any[]) => { error: (...args: any[]) => {
console.error("[AdjustLine]", ...args) console.error("[AdjustLine]", ...args)
}, },
} }
function handleError(error: Error, context: string) { function handleError(error: Error, context: string) {
debug.error(`Error in ${context}:`, error) debug.error(`Error in ${context}:`, error)
// //
} }
// //
onErrorCaptured((err, instance, info) => { onErrorCaptured((err, instance, info) => {
handleError(err as Error, info) handleError(err as Error, info)
console.log(instance); console.log(instance)
return false return false
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.adjust-line { .adjust-line {
position: absolute; position: absolute;
z-index: 999; z-index: 999;
@ -511,5 +511,5 @@ onErrorCaptured((err, instance, info) => {
background-color: #666; background-color: #666;
} }
} }
} }
</style> </style>

75
src/renderer/src/components/CodeEditor/code-editor.vue

@ -1,13 +1,13 @@
<script lang="ts" setup> <script lang="ts" setup>
import { judgeFile } from "./utils" import { judgeFile } from "./utils"
import { monaco } from "./monaco" import { monaco } from "./monaco"
import { computed, getCurrentScope, onBeforeUnmount, onMounted, onScopeDispose, ref, watch } from "vue" import { computed, getCurrentScope, onBeforeUnmount, onMounted, onScopeDispose, ref, watch } from "vue"
import DefaultLogo from "./120x120.png" import DefaultLogo from "./120x120.png"
import { PlaceholderContentWidget } from "./PlaceholderContentWidget" import { PlaceholderContentWidget } from "./PlaceholderContentWidget"
const editorRef = ref<HTMLDivElement>() const editorRef = ref<HTMLDivElement>()
let editor: monaco.editor.IStandaloneCodeEditor | null = null let editor: monaco.editor.IStandaloneCodeEditor | null = null
let placeholderWidget: PlaceholderContentWidget | null = null let placeholderWidget: PlaceholderContentWidget | null = null
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
modelValue?: string modelValue?: string
name?: string name?: string
@ -24,13 +24,13 @@ const props = withDefaults(
modelValue: "", modelValue: "",
name: "", name: "",
}, },
) )
const emit = defineEmits<{ const emit = defineEmits<{
(e: "update:modelValue", code: string): void (e: "update:modelValue", code: string): void
(e: "change", code: string): void (e: "change", code: string): void
(e: "cursor:position", position: [number, number]): void (e: "cursor:position", position: [number, number]): void
}>() }>()
defineExpose({ defineExpose({
scrollTop() { scrollTop() {
editor?.setScrollTop(0) editor?.setScrollTop(0)
}, },
@ -82,10 +82,10 @@ defineExpose({
editor.setValue(content) editor.setValue(content)
} }
}, },
}) })
let isInnerChange = false let isInnerChange = false
function updateModel(name: string, content: string) { function updateModel(name: string, content: string) {
if (editor) { if (editor) {
const oldModel = editor.getModel() // const oldModel = editor.getModel() //
const file = judgeFile(name) const file = judgeFile(name)
@ -105,14 +105,14 @@ function updateModel(name: string, content: string) {
} }
editor.setModel(model) editor.setModel(model)
} }
} }
function resizeLayout() { function resizeLayout() {
if (editor) { if (editor) {
editor.layout() editor.layout()
} }
} }
onMounted(() => { onMounted(() => {
if (editorRef.value && !editor) { if (editorRef.value && !editor) {
editor = monaco.editor.create(editorRef.value, { editor = monaco.editor.create(editorRef.value, {
theme: "vs-light", theme: "vs-light",
@ -185,14 +185,13 @@ onMounted(() => {
} }
}, },
) )
})
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
console.log(newModule);
}) })
} if (import.meta.hot) {
onBeforeUnmount(() => { import.meta.hot.accept(newModule => {
console.log(newModule)
})
}
onBeforeUnmount(() => {
if (editorRef.value) { if (editorRef.value) {
editorRef.value.removeEventListener("resize", resizeLayout) editorRef.value.removeEventListener("resize", resizeLayout)
} }
@ -204,8 +203,8 @@ onBeforeUnmount(() => {
editor.dispose() editor.dispose()
editor = null editor = null
} }
}) })
const style = computed(() => { const style = computed(() => {
if (props.logo && props.logoType === "bg") { if (props.logo && props.logoType === "bg") {
return { return {
backgroundImage: `url(${props.logo})`, backgroundImage: `url(${props.logo})`,
@ -215,14 +214,14 @@ const style = computed(() => {
} }
} }
return {} return {}
}) })
const getLogo = computed(() => { const getLogo = computed(() => {
if (props.logo) return props.logo if (props.logo) return props.logo
return DefaultLogo return DefaultLogo
}) })
function useResizeObserver(callback: ResizeObserverCallback) { function useResizeObserver(callback: ResizeObserverCallback) {
const isSupported = window && "ResizeObserver" in window const isSupported = window && "ResizeObserver" in window
let observer: ResizeObserver | undefined let observer: ResizeObserver | undefined
const cleanup = () => { const cleanup = () => {
@ -256,12 +255,12 @@ function useResizeObserver(callback: ResizeObserverCallback) {
tryOnScopeDispose(() => { tryOnScopeDispose(() => {
stop() stop()
}) })
} }
useResizeObserver(() => { useResizeObserver(() => {
if (editor) { if (editor) {
editor.layout() editor.layout()
} }
}) })
</script> </script>
<template> <template>
@ -274,7 +273,7 @@ useResizeObserver(() => {
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.monaco-wrapper { .monaco-wrapper {
height: 100%; height: 100%;
position: relative; position: relative;
@ -296,5 +295,5 @@ useResizeObserver(() => {
@apply absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2; @apply absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2;
} }
} }
} }
</style> </style>

42
src/renderer/src/components/NavBar.vue

@ -39,33 +39,33 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import icon from "@res/icon.png" import icon from "@res/icon.png"
import config from "config" import config from "config"
import { PopupMenu } from "@/bridge/PopupMenu" import { PopupMenu } from "@/bridge/PopupMenu"
import { usePlatForm } from "common/usePlatform" import { usePlatForm } from "common/usePlatform"
const { PlatForm } = usePlatForm() const { PlatForm } = usePlatForm()
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
const isFullScreen = ref(false) const isFullScreen = ref(false)
onBeforeMount(async () => { onBeforeMount(async () => {
isFullScreen.value = await PlatForm.isFullScreen() isFullScreen.value = await PlatForm.isFullScreen()
}) })
const isHome = computed(() => { const isHome = computed(() => {
if (route.fullPath === "/") { if (route.fullPath === "/") {
return true return true
} }
return false return false
}) })
function back() { function back() {
router.push("/") router.push("/")
} }
const { t } = useI18n() const { t } = useI18n()
const onClickMenu = e => { const onClickMenu = e => {
const menu = new PopupMenu([ const menu = new PopupMenu([
{ {
label: isFullScreen.value ? t("qu-xiao-quan-ping") : t("quan-ping"), label: isFullScreen.value ? t("qu-xiao-quan-ping") : t("quan-ping"),
@ -83,20 +83,20 @@ const onClickMenu = e => {
]) ])
const obj = e.target.getBoundingClientRect() const obj = e.target.getBoundingClientRect()
menu.show({ x: ~~obj.x, y: ~~(obj.y + obj.height) }) menu.show({ x: ~~obj.x, y: ~~(obj.y + obj.height) })
} }
const onClickAbout = () => { const onClickAbout = () => {
PlatForm.showAbout() PlatForm.showAbout()
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.list { .list {
@apply: flex gap="5px"; @apply: flex gap="5px";
-webkit-app-region: no-drag; -webkit-app-region: no-drag;
.item { .item {
@apply: text-sm px-2 hover:rounded-md hover:bg-gray-2 hover:cursor-pointer text="hover:hover"; @apply: text-sm px-2 hover:rounded-md hover:bg-gray-2 hover:cursor-pointer text="hover:hover";
} }
} }
</style> </style>

4
src/renderer/src/components/Versions.vue

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { reactive } from "vue" import { reactive } from "vue"
const versions = reactive({ ...window.electron.process.versions }) const versions = reactive({ ...window.electron.process.versions })
</script> </script>
<template> <template>

6
src/renderer/src/layouts/default.vue

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import Simplebar from "simplebar-vue" import Simplebar from "simplebar-vue"
</script> </script>
<template> <template>
@ -9,7 +9,7 @@ import Simplebar from "simplebar-vue"
</template> </template>
<style scoped> <style scoped>
:deep(.simplebar-content) { :deep(.simplebar-content) {
height: 100%; height: 100%;
} }
</style> </style>

4
src/renderer/src/pages/_ui/App.vue

@ -1,8 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
defineOptions({ defineOptions({
title: "观山", title: "观山",
bg: "ty", bg: "ty",
}) })
</script> </script>
<template> <template>

232
src/renderer/src/pages/_ui/Browser.vue

@ -1,46 +1,46 @@
<script setup lang="ts"> <script setup lang="ts">
import { onBeforeMount, onBeforeUnmount, onMounted, ref, useTemplateRef, nextTick } from "vue" import { onBeforeMount, onBeforeUnmount, onMounted, ref, useTemplateRef, nextTick } from "vue"
import { PopupMenu } from "@/bridge/PopupMenu" import { PopupMenu } from "@/bridge/PopupMenu"
defineOptions({ defineOptions({
title: "浏览器", title: "浏览器",
index: 2, index: 2,
bg: "bg", bg: "bg",
}) })
// const PlaceHolderRef = useTemplateRef("PlaceHolder") // const PlaceHolderRef = useTemplateRef("PlaceHolder")
// function OnResize() { // function OnResize() {
// const el = PlaceHolderRef.value // const el = PlaceHolderRef.value
// if (el) { // if (el) {
// const rect = el.getBoundingClientRect().toJSON() // const rect = el.getBoundingClientRect().toJSON()
// console.log(rect) // console.log(rect)
// api.call("TabsCommand.bindElement", rect) // api.call("TabsCommand.bindElement", rect)
// } // }
// } // }
// onMounted(OnResize) // onMounted(OnResize)
// window.addEventListener("resize", OnResize) // window.addEventListener("resize", OnResize)
// onBeforeUnmount(() => { // onBeforeUnmount(() => {
// window.removeEventListener("resize", OnResize) // window.removeEventListener("resize", OnResize)
// }) // })
const PlaceHolder = useTemplateRef("PlaceHolder") const PlaceHolder = useTemplateRef("PlaceHolder")
const { stop } = useResizeObserver(PlaceHolder, () => { const { stop } = useResizeObserver(PlaceHolder, () => {
const el = PlaceHolder.value const el = PlaceHolder.value
if (el) { if (el) {
const rect = el.getBoundingClientRect().toJSON() const rect = el.getBoundingClientRect().toJSON()
api.call("TabsCommand.bindElement", rect) api.call("TabsCommand.bindElement", rect)
} }
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
stop() stop()
api.call("TabsCommand.closeAll") api.call("TabsCommand.closeAll")
}) })
const list = ref<any[]>([]) const list = ref<any[]>([])
const curUrl = ref<any>("") const curUrl = ref<any>("")
const curIndex = ref<any>(-1) const curIndex = ref<any>(-1)
const listener = (_, v) => { const listener = (_, v) => {
list.value = v list.value = v
const el = v.find(v => v.isActive) const el = v.find(v => v.isActive)
curIndex.value = v.findIndex(v => v.isActive) curIndex.value = v.findIndex(v => v.isActive)
@ -49,32 +49,32 @@ const listener = (_, v) => {
} else { } else {
curUrl.value = "" curUrl.value = ""
} }
} }
if (import.meta.hot) { if (import.meta.hot) {
api.off("main:TabsCommand.update", listener) api.off("main:TabsCommand.update", listener)
} }
api.on("main:TabsCommand.update", listener) api.on("main:TabsCommand.update", listener)
onMounted(() => { onMounted(() => {
api.call("TabsCommand.sync") api.call("TabsCommand.sync")
}) })
onBeforeMount(async () => { onBeforeMount(async () => {
list.value = await fetch("api://fuck/TabsService/getAllTabs").then(async res => await res.json()) list.value = await fetch("api://fuck/TabsService/getAllTabs").then(async res => await res.json())
}) })
// const url = ref("") // const url = ref("")
// async function addTab() { // async function addTab() {
// if (!url.value) url.value = "about:blank" // if (!url.value) url.value = "about:blank"
// await fetch("api://fuck/TabsService/add", { // await fetch("api://fuck/TabsService/add", {
// method: "POST", // method: "POST",
// body: JSON.stringify({ url: url.value }), // body: JSON.stringify({ url: url.value }),
// }) // })
// url.value = "" // url.value = ""
// onClick() // onClick()
// } // }
function handleTabContextMenu(_, index) { function handleTabContextMenu(_, index) {
const menu = new PopupMenu([ const menu = new PopupMenu([
{ {
label: "右侧关闭", label: "右侧关闭",
@ -95,9 +95,9 @@ function handleTabContextMenu(_, index) {
}, },
]) ])
menu.show() menu.show()
} }
function scrollTabIntoView(index: number) { function scrollTabIntoView(index: number) {
nextTick(() => { nextTick(() => {
const tabList = document.querySelector(".tab-list") const tabList = document.querySelector(".tab-list")
const tabItems = tabList?.querySelectorAll(".tab-item") const tabItems = tabList?.querySelectorAll(".tab-item")
@ -105,14 +105,14 @@ function scrollTabIntoView(index: number) {
tabItems[index].scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" }) tabItems[index].scrollIntoView({ behavior: "smooth", block: "nearest", inline: "nearest" })
} }
}) })
} }
async function changeTab(_, index) { async function changeTab(_, index) {
await api.call("TabsCommand.setActive", index) await api.call("TabsCommand.setActive", index)
scrollTabIntoView(index) scrollTabIntoView(index)
} }
function addTabInput() { function addTabInput() {
if (curUrl.value) { if (curUrl.value) {
if (curIndex.value !== undefined && curIndex.value >= 0) { if (curIndex.value !== undefined && curIndex.value >= 0) {
api.call("TabsCommand.nagivate", curIndex.value, curUrl.value) api.call("TabsCommand.nagivate", curIndex.value, curUrl.value)
@ -120,22 +120,22 @@ function addTabInput() {
api.call("TabsCommand.add", curUrl.value) api.call("TabsCommand.add", curUrl.value)
} }
} }
} }
async function addTab() { async function addTab() {
await api.call("TabsCommand.add", "about:blank") await api.call("TabsCommand.add", "about:blank")
scrollTabIntoView(list.value.length - 1) scrollTabIntoView(list.value.length - 1)
} }
async function closeTab(_, index) { async function closeTab(_, index) {
await fetch("api://fuck/TabsService/closeTab", { await fetch("api://fuck/TabsService/closeTab", {
method: "POST", method: "POST",
body: JSON.stringify({ active: index }), body: JSON.stringify({ active: index }),
}) })
onClick() onClick()
} }
const onClick = async () => { const onClick = async () => {
list.value = await api.call("TabsCommand.getAllTabs") list.value = await api.call("TabsCommand.getAllTabs")
// list.value = await fetch("api://fuck/TabsService/getAllTabs").then(async res => await res.json()) // list.value = await fetch("api://fuck/TabsService/getAllTabs").then(async res => await res.json())
// fetch("api://fuck/BasicService/showAbout").then(async res => console.log(await res.json())) // fetch("api://fuck/BasicService/showAbout").then(async res => console.log(await res.json()))
@ -143,11 +143,11 @@ const onClick = async () => {
// method: "POST", // method: "POST",
// body: JSON.stringify({ a: "234" }), // body: JSON.stringify({ a: "234" }),
// }).then(async res => console.log(await res.json())) // }).then(async res => console.log(await res.json()))
} }
function onClickDevTool() { function onClickDevTool() {
fetch("api://fuck/BasicService/openTabDevtool") fetch("api://fuck/BasicService/openTabDevtool")
} }
</script> </script>
<template> <template>
@ -213,15 +213,15 @@ function onClickDevTool() {
</template> </template>
<style scoped> <style scoped>
.tab-container { .tab-container {
background: var(--tab-bar-bg, #f3f3f3); background: var(--tab-bar-bg, #f3f3f3);
border-bottom: none; border-bottom: none;
padding-top: 4px; padding-top: 4px;
height: auto; height: auto;
min-height: 80px; min-height: 80px;
} }
.tab-list-container { .tab-list-container {
position: relative; position: relative;
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
@ -230,9 +230,9 @@ function onClickDevTool() {
margin-bottom: 0; margin-bottom: 0;
width: 100%; width: 100%;
overflow: auto; overflow: auto;
} }
.tab-list { .tab-list {
height: 32px; height: 32px;
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
@ -247,9 +247,9 @@ function onClickDevTool() {
&::-webkit-scrollbar { &::-webkit-scrollbar {
display: none; /* Chrome, Safari and Opera */ display: none; /* Chrome, Safari and Opera */
} }
} }
.tab-item { .tab-item {
position: relative; position: relative;
min-width: 160px; min-width: 160px;
max-width: 240px; max-width: 240px;
@ -263,9 +263,9 @@ function onClickDevTool() {
align-items: center; align-items: center;
flex-shrink: 0; /* 防止标签被压缩 */ flex-shrink: 0; /* 防止标签被压缩 */
cursor: pointer; cursor: pointer;
} }
.tab-item::after { .tab-item::after {
content: ""; content: "";
position: absolute; position: absolute;
right: 0; right: 0;
@ -274,20 +274,20 @@ function onClickDevTool() {
width: 1px; width: 1px;
background: var(--tab-separator-color, #bdc1c6); background: var(--tab-separator-color, #bdc1c6);
opacity: 0.3; opacity: 0.3;
} }
.tab-item:hover { .tab-item:hover {
background: var(--tab-hover-bg, #e9ebee); background: var(--tab-hover-bg, #e9ebee);
} }
.tab-item.active { .tab-item.active {
background: var(--tab-active-bg, #fff); background: var(--tab-active-bg, #fff);
z-index: 2; z-index: 2;
height: 32px; height: 32px;
margin-bottom: -1px; margin-bottom: -1px;
} }
.tab-item.active::before { .tab-item.active::before {
content: ""; content: "";
position: absolute; position: absolute;
left: 0; left: 0;
@ -296,34 +296,34 @@ function onClickDevTool() {
height: 2px; height: 2px;
background: var(--primary-color, #1a73e8); background: var(--primary-color, #1a73e8);
border-radius: 2px 2px 0 0; border-radius: 2px 2px 0 0;
} }
.tab-content { .tab-content {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 0 8px; padding: 0 8px;
height: 100%; height: 100%;
gap: 6px; gap: 6px;
width: 100%; width: 100%;
} }
.tab-icon { .tab-icon {
width: 16px; width: 16px;
height: 16px; height: 16px;
flex-shrink: 0; flex-shrink: 0;
border-radius: 3px; border-radius: 3px;
} }
.tab-icon-placeholder { .tab-icon-placeholder {
width: 16px; width: 16px;
height: 16px; height: 16px;
background: #bdc1c6; background: #bdc1c6;
border-radius: 50%; border-radius: 50%;
flex-shrink: 0; flex-shrink: 0;
opacity: 0.7; opacity: 0.7;
} }
.tab-title { .tab-title {
flex: 1; flex: 1;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
@ -332,13 +332,13 @@ function onClickDevTool() {
color: var(--text-color, #5f6368); color: var(--text-color, #5f6368);
line-height: 1.2; line-height: 1.2;
padding-right: 4px; padding-right: 4px;
} }
.tab-item.active .tab-title { .tab-item.active .tab-title {
color: var(--active-text-color, #202124); color: var(--active-text-color, #202124);
} }
.tab-close { .tab-close {
width: 16px; width: 16px;
height: 16px; height: 16px;
display: flex; display: flex;
@ -349,27 +349,27 @@ function onClickDevTool() {
opacity: 0; opacity: 0;
transition: opacity 0.15s ease; transition: opacity 0.15s ease;
flex-shrink: 0; flex-shrink: 0;
} }
.tab-item:hover .tab-close { .tab-item:hover .tab-close {
opacity: 0.6; opacity: 0.6;
} }
.tab-close:hover { .tab-close:hover {
background: var(--close-hover-bg, rgba(0, 0, 0, 0.08)); background: var(--close-hover-bg, rgba(0, 0, 0, 0.08));
opacity: 1; opacity: 1;
} }
.new-tab-button-container { .new-tab-button-container {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 40px; width: 40px;
height: 32px; height: 32px;
background: var(--tab-bar-bg); background: var(--tab-bar-bg);
} }
.new-tab-button { .new-tab-button {
width: 32px; width: 32px;
height: 32px; height: 32px;
display: flex; display: flex;
@ -381,14 +381,14 @@ function onClickDevTool() {
cursor: pointer; cursor: pointer;
opacity: 0.8; opacity: 0.8;
background: transparent; background: transparent;
} }
.new-tab-button:hover { .new-tab-button:hover {
background: var(--tab-hover-bg, rgba(0, 0, 0, 0.06)); background: var(--tab-hover-bg, rgba(0, 0, 0, 0.06));
opacity: 1; opacity: 1;
} }
.address-bar { .address-bar {
padding: 8px 12px; padding: 8px 12px;
margin: 0; margin: 0;
background: var(--address-bar-bg, #fff); background: var(--address-bar-bg, #fff);
@ -397,9 +397,9 @@ function onClickDevTool() {
gap: 8px; gap: 8px;
width: 100%; width: 100%;
border-top: 1px solid var(--tab-separator-color, rgba(0, 0, 0, 0.1)); border-top: 1px solid var(--tab-separator-color, rgba(0, 0, 0, 0.1));
} }
.url-input-container { .url-input-container {
flex: 1; flex: 1;
height: 36px; height: 36px;
background: var(--input-bg, #f1f3f4); background: var(--input-bg, #f1f3f4);
@ -409,9 +409,9 @@ function onClickDevTool() {
align-items: center; align-items: center;
margin: 0; margin: 0;
min-width: 0; min-width: 0;
} }
.url-input { .url-input {
width: 100%; width: 100%;
height: 100%; height: 100%;
border: none; border: none;
@ -419,9 +419,9 @@ function onClickDevTool() {
outline: none; outline: none;
font-size: 14px; font-size: 14px;
color: var(--text-color, #333); color: var(--text-color, #333);
} }
.action-button { .action-button {
flex-shrink: 0; flex-shrink: 0;
height: 36px; height: 36px;
padding: 0 16px; padding: 0 16px;
@ -432,14 +432,14 @@ function onClickDevTool() {
font-size: 14px; font-size: 14px;
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
} }
.action-button:hover { .action-button:hover {
background: var(--button-hover-bg, #f1f3f4); background: var(--button-hover-bg, #f1f3f4);
} }
/* 修改CSS变量 */ /* 修改CSS变量 */
:root { :root {
--tab-bar-bg: #f1f3f4; --tab-bar-bg: #f1f3f4;
--tab-bg: rgba(32, 33, 36, 0.1); --tab-bg: rgba(32, 33, 36, 0.1);
--tab-hover-bg: rgba(32, 33, 36, 0.08); --tab-hover-bg: rgba(32, 33, 36, 0.08);
@ -451,9 +451,9 @@ function onClickDevTool() {
--close-hover-bg: rgba(0, 0, 0, 0.08); --close-hover-bg: rgba(0, 0, 0, 0.08);
--primary-color: #1a73e8; --primary-color: #1a73e8;
--new-tab-shadow: 0 -8px 12px -6px rgba(0, 0, 0, 0.1); --new-tab-shadow: 0 -8px 12px -6px rgba(0, 0, 0, 0.1);
} }
[data-theme="dark"] { [data-theme="dark"] {
--tab-bar-bg: #202124; --tab-bar-bg: #202124;
--tab-bg: rgba(255, 255, 255, 0.1); --tab-bg: rgba(255, 255, 255, 0.1);
--tab-hover-bg: rgba(255, 255, 255, 0.08); --tab-hover-bg: rgba(255, 255, 255, 0.08);
@ -465,5 +465,5 @@ function onClickDevTool() {
--close-hover-bg: rgba(255, 255, 255, 0.08); --close-hover-bg: rgba(255, 255, 255, 0.08);
--primary-color: #8ab4f8; --primary-color: #8ab4f8;
--new-tab-shadow: 0 -8px 12px -6px rgba(0, 0, 0, 0.3); --new-tab-shadow: 0 -8px 12px -6px rgba(0, 0, 0, 0.3);
} }
</style> </style>

46
src/renderer/src/pages/about/index.vue

@ -1,33 +1,33 @@
<script setup lang="ts"> <script setup lang="ts">
definePage({ definePage({
name: "about", name: "about",
meta: { meta: {
title: "听雨", title: "听雨",
bg: "gs", bg: "gs",
}, },
}) })
// const activeTab = ref(0) // const activeTab = ref(0)
// const TopMenu = computed<any[]>(() => { // const TopMenu = computed<any[]>(() => {
// return [ // return [
// { key: 0, title: "sada", url: "/setting" }, // { key: 0, title: "sada", url: "/setting" },
// { key: 1, title: "sdas", url: "/setting/editor" }, // { key: 1, title: "sdas", url: "/setting/editor" },
// { key: 2, title: "asdas", url: "/setting/update" }, // { key: 2, title: "asdas", url: "/setting/update" },
// ] // ]
// }) // })
// const route = useRoute() // const route = useRoute()
// watch( // watch(
// () => route, // () => route,
// route => { // route => {
// for (let i = 0; i < TopMenu.value.length; i++) { // for (let i = 0; i < TopMenu.value.length; i++) {
// const element = TopMenu.value[i] // const element = TopMenu.value[i]
// if (route.path.startsWith(element.url)) { // if (route.path.startsWith(element.url)) {
// activeTab.value = element.key // activeTab.value = element.key
// } // }
// } // }
// }, // },
// { immediate: true }, // { immediate: true },
// ) // )
</script> </script>
<template> <template>
<div> <div>

86
src/renderer/src/pages/browser.vue

@ -1,10 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import Simplebar from "simplebar-vue" import Simplebar from "simplebar-vue"
import { getAssetsFile } from "@/utils" import { getAssetsFile } from "@/utils"
const allModules: Record<string, any> = import.meta.glob("./_ui/**/*.vue", { eager: true }) const allModules: Record<string, any> = import.meta.glob("./_ui/**/*.vue", { eager: true })
let allApp: any[] = [] let allApp: any[] = []
Object.keys(allModules).forEach(key => { Object.keys(allModules).forEach(key => {
// let [, p] = key.match("./_ui/(.*?).vue")! // let [, p] = key.match("./_ui/(.*?).vue")!
// p = p.replace(/\.vue$/, "") // p = p.replace(/\.vue$/, "")
const m = allModules[key]?.default || allModules[key] const m = allModules[key]?.default || allModules[key]
@ -14,47 +14,47 @@ Object.keys(allModules).forEach(key => {
_sort: m.index ?? 0, _sort: m.index ?? 0,
comp: m, comp: m,
}) })
}) })
allApp = allApp.sort((a, b) => (a.index - b.index <= 0 ? 1 : -1)) allApp = allApp.sort((a, b) => (a.index - b.index <= 0 ? 1 : -1))
const active = ref(0) const active = ref(0)
// const allApp = [ // const allApp = [
// { label: "", comp: defineAsyncComponent(() => import("./_ui/Browser.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/Browser.vue")) },
// { label: "", bg: "gs", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", bg: "gs", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", bg: "ty", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", bg: "ty", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "访", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "访", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) }, // { label: "", comp: defineAsyncComponent(() => import("./_ui/App.vue")) },
// ] // ]
const activeBg = computed(() => { const activeBg = computed(() => {
if (active.value === undefined) return "" if (active.value === undefined) return ""
const value = allApp[active.value]?.bg const value = allApp[active.value]?.bg
return value ? getAssetsFile(`@/assets/images/home/${value}.png`) : "" return value ? getAssetsFile(`@/assets/images/home/${value}.png`) : ""
}) })
function onClick(index: number) { function onClick(index: number) {
active.value = index active.value = index
} }
</script> </script>
<template> <template>
@ -90,7 +90,7 @@ function onClick(index: number) {
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.content { .content {
.bg { .bg {
position: absolute; position: absolute;
left: 0; left: 0;
@ -105,8 +105,8 @@ function onClick(index: number) {
// blur(4px) // blur(4px)
filter: brightness(1); filter: brightness(1);
} }
} }
.item { .item {
position: relative; position: relative;
&::before { &::before {
content: ""; content: "";
@ -139,5 +139,5 @@ function onClick(index: number) {
.text { .text {
transition-duration: 300ms; transition-duration: 300ms;
} }
} }
</style> </style>

8
src/renderer/src/pages/index.vue

@ -1,14 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
definePage({ definePage({
meta: { meta: {
home: true, home: true,
}, },
}) })
const state = reactive({ const state = reactive({
content: "", content: "",
name: "aaa.ts", name: "aaa.ts",
}) })
</script> </script>
<template> <template>

1
src/types/global.d.ts

@ -1,4 +1,3 @@
type Api = { type Api = {
call: (command: string, ...args: any[]) => Promise<any> call: (command: string, ...args: any[]) => Promise<any>
callLong: (command: string, ...args: any[]) => Promise<any> callLong: (command: string, ...args: any[]) => Promise<any>

4
推荐.md

@ -1,15 +1,11 @@
插件化: 插件化:
https://rubickcenter.github.io/docs/core/index.html#%E5%9F%BA%E4%BA%8E-browserview-%E5%AE%9E%E7%8E%B0%E6%8F%92%E4%BB%B6%E5%8C%96%E8%83%BD%E5%8A%9B https://rubickcenter.github.io/docs/core/index.html#%E5%9F%BA%E4%BA%8E-browserview-%E5%AE%9E%E7%8E%B0%E6%8F%92%E4%BB%B6%E5%8C%96%E8%83%BD%E5%8A%9B
electron+vue虚拟桌面开发遇坑之透明窗口鼠标穿透 electron+vue虚拟桌面开发遇坑之透明窗口鼠标穿透
https://blog.csdn.net/weixin_42421494/article/details/102800491 https://blog.csdn.net/weixin_42421494/article/details/102800491
截图 截图
https://zhuanlan.zhihu.com/p/46043613?from_voters_page=true https://zhuanlan.zhihu.com/p/46043613?from_voters_page=true

Loading…
Cancel
Save