Skip to content

Commit cf853d4

Browse files
committed
feat: v1.2.1 布局优化
1 parent 5e20595 commit cf853d4

File tree

6 files changed

+74
-44
lines changed

6 files changed

+74
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
显示名称:代码编辑器
66

7-
版本:1.2.0
7+
版本:1.2.1
88

99
发布者:Flex_7746
1010

app/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
appname=code.editor
2-
version=1.2.0
2+
version=1.2.1
33
desc=`<div>VS Code 同源库,支持多种编码文件的操作,更有语法高亮、代码补全。</div>
44
<div>text、txt、js、ts、html、htm、css、scss、less、json、md、py、java、c、cpp、cc、cxx、go、rs、php、rb、sh、sql、xml、yaml、yml、vue 后缀文件直接双击文件或右键选择代码编辑器打开。</div><div>非上述后缀文件,右键【详细信息】-【复制原始路径】,点击桌面图标访问后粘贴路径打开。</div>
55
<div>提示:编辑用户目录中的文件需【系统设置】-【应用】-【代码编辑器】进行文件夹授权,应用文件夹中目录下可直接编辑;</div><div>提示:移动端暂未做 UI 适配,访问可能布局错乱;访问二进制文件将显示乱码,请谨慎操作。</div>`

code.editor.fpk

-360 Bytes
Binary file not shown.

frontend/components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare module 'vue' {
1414
export interface GlobalComponents {
1515
ElButton: typeof import('element-plus/es')['ElButton']
1616
ElDialog: typeof import('element-plus/es')['ElDialog']
17+
ElIcon: typeof import('element-plus/es')['ElIcon']
1718
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
1819
ElOption: typeof import('element-plus/es')['ElOption']
1920
ElSelect: typeof import('element-plus/es')['ElSelect']
@@ -29,6 +30,7 @@ declare module 'vue' {
2930
declare global {
3031
const ElButton: typeof import('element-plus/es')['ElButton']
3132
const ElDialog: typeof import('element-plus/es')['ElDialog']
33+
const ElIcon: typeof import('element-plus/es')['ElIcon']
3234
const ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
3335
const ElOption: typeof import('element-plus/es')['ElOption']
3436
const ElSelect: typeof import('element-plus/es')['ElSelect']

frontend/src/App.vue

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
<template>
2-
<el-tabs
3-
class="view"
4-
v-model="active"
5-
type="card"
6-
addable
7-
:closable="view.length > 1"
8-
@edit="viewEdit"
9-
>
10-
<el-tab-pane v-for="item in view" :key="item.path" :name="item.path">
2+
<el-tabs class="view" v-model="active" type="card" closable @tab-remove="remove">
3+
<el-tab-pane v-for="(item, i) in view" :key="item.path" :name="i">
114
<template #label>
125
<el-tooltip :content="item.path">
13-
<div class="label" :class="item.diff ? 'diff' : ''">{{ item.path.split('/').pop() }}</div>
6+
<div>{{ item.path.split('/').pop() }}</div>
147
</el-tooltip>
8+
9+
<div v-show="item.diff" class="diff"></div>
1510
</template>
1611

1712
<MonacoEditor
13+
ref="editorRef"
1814
:path="item.path"
1915
:like="like"
2016
@like="() => (open = !open)"
2117
@diff="(v) => (item.diff = v)"
2218
/>
2319
</el-tab-pane>
20+
21+
<el-tab-pane :name="-1" disabled>
22+
<template #label>
23+
<div class="add" @click="add()">
24+
<el-icon><Plus /></el-icon>
25+
</div>
26+
</template>
27+
</el-tab-pane>
2428
</el-tabs>
2529

30+
<el-button
31+
size="small"
32+
class="save"
33+
v-bind="view?.[active]?.diff ? { type: 'primary' } : { disabled: true }"
34+
@click="editorRef?.[active]?.save"
35+
>
36+
保存
37+
</el-button>
38+
2639
<el-dialog v-model="open" title="偏好设置" width="300">
2740
<div class="like-dialog">
2841
<div class="item">
@@ -67,6 +80,9 @@
6780
</template>
6881

6982
<script setup lang="ts">
83+
import { ref } from 'vue'
84+
import { Plus } from '@element-plus/icons-vue'
85+
7086
import MonacoEditor from './components/MonacoEditor.vue'
7187
7288
import { THEME_OPTIONS } from '@/utils/option'
@@ -77,13 +93,7 @@ import usePath from '@/hooks/usePath'
7793
const { open, like, resetLike } = useLike()
7894
const { view, active, add, remove } = usePath()
7995
80-
const viewEdit = (v: string, action: 'remove' | 'add') => {
81-
if (action === 'add') {
82-
add()
83-
} else {
84-
remove(v)
85-
}
86-
}
96+
const editorRef = ref<any[]>([])
8797
</script>
8898

8999
<style lang="scss">
@@ -104,25 +114,38 @@ body,
104114
margin: 0;
105115
106116
.el-tabs__nav {
107-
border-top: none;
108117
border-radius: 0;
109118
110119
.el-tabs__item {
111-
.label {
112-
&::after {
113-
content: '';
114-
display: inline-block;
115-
width: 8px;
116-
height: 8px;
117-
border-radius: 50%;
118-
margin-left: 4px;
120+
position: relative;
121+
display: flex;
122+
align-items: center;
123+
gap: 6px;
124+
125+
&.is-disabled {
126+
> .add {
127+
position: absolute;
128+
left: 0;
129+
top: 0;
130+
width: 100%;
131+
height: 100%;
132+
display: flex;
133+
align-items: center;
134+
justify-content: center;
135+
cursor: pointer;
136+
pointer-events: all;
119137
}
138+
}
120139
121-
&.diff {
122-
&::after {
123-
background-color: var(--el-text-color-placeholder);
124-
}
125-
}
140+
.diff {
141+
width: 6px;
142+
height: 6px;
143+
border-radius: 50%;
144+
background-color: var(--el-text-color-placeholder);
145+
}
146+
147+
> * {
148+
margin: 0;
126149
}
127150
}
128151
}
@@ -144,6 +167,12 @@ body,
144167
}
145168
}
146169
}
170+
171+
> .save {
172+
position: absolute;
173+
right: 8px;
174+
top: 8px;
175+
}
147176
}
148177
149178
.like-dialog {

frontend/src/hooks/usePath.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { onMounted, reactive, ref } from 'vue'
33

44
export default function usePath() {
55
const view = reactive<{ path: string; diff: boolean }[]>([])
6-
const active = ref('')
6+
const active = ref(0)
77

88
onMounted(async () => {
99
const query = new URLSearchParams(window.location.search).get('path') || ''
1010
if (query) {
1111
view.push({ path: query, diff: false })
12-
active.value = query
1312
} else {
1413
add(true)
1514
}
@@ -33,18 +32,16 @@ export default function usePath() {
3332
.catch(() => '')
3433

3534
if (value) {
36-
const item = view.find((i) => i.path === value)
37-
if (item) {
38-
active.value = item.path
35+
const index = view.findIndex((i) => i.path === value)
36+
if (index > -1) {
37+
active.value = index
3938
} else {
40-
view.push({ path: value, diff: false })
41-
active.value = value
39+
active.value = view.push({ path: value, diff: false }) - 1
4240
}
4341
}
4442
}
4543

46-
const remove = async (path: string) => {
47-
const index = view.findIndex((i) => i.path === path)
44+
const remove = async (index: number) => {
4845
const item = view[index]
4946
if (item) {
5047
if (item.diff) {
@@ -59,8 +56,10 @@ export default function usePath() {
5956
}
6057
}
6158

62-
if (active.value === item.path) {
63-
active.value = (view[index + 1] || view[index - 1])?.path || ''
59+
if (index === active.value) {
60+
active.value += view[index + 1] ? 0 : -1
61+
} else if (index < active.value) {
62+
active.value--
6463
}
6564

6665
view.splice(index, 1)

0 commit comments

Comments
 (0)