Skip to content

Commit 672f8ff

Browse files
committed
feat: 学术子模块条目结构升级为自定义模块格式,新增 CollapsibleItemEditor 复用组件,示例数据要点化
1 parent 35bb4df commit 672f8ff

8 files changed

Lines changed: 873 additions & 533 deletions

File tree

‎src/App.vue‎

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import CvEditor from './components/CvEditor.vue';
55
import { defaultData } from './defaultData';
66
import type { CvData } from './types';
77
import { useLocale } from './composables/useLocale';
8-
98
const cvData = ref<CvData>(defaultData);
109
const activeTab = ref('personal');
1110
const lastSaved = ref<Date | null>(null);
@@ -43,6 +42,8 @@ onMounted(() => {
4342
}
4443
}
4544
startAutoSave();
45+
// 点击外部关闭数据下拉菜单
46+
document.addEventListener('click', closeDataMenu);
4647
// 监听预览 wrapper 尺寸变化(分页变化、数据变化都会触发),同步外层占位高度
4748
nextTick(() => {
4849
if (previewZoomRef.value) {
@@ -58,6 +59,7 @@ watch(previewScale, () => updateOuterH());
5859
onUnmounted(() => {
5960
if (autoSaveInterval) clearInterval(autoSaveInterval);
6061
if (resizeObserver) resizeObserver.disconnect();
62+
document.removeEventListener('click', closeDataMenu);
6163
});
6264
6365
let autoSaveInterval: number | null = null;
@@ -143,6 +145,25 @@ const handleImportJson = (event: Event) => {
143145
reader.readAsText(file);
144146
};
145147
148+
// 加载示例数据(覆盖当前数据,需确认)
149+
const handleLoadSample = () => {
150+
if (!confirm(t('loadSampleConfirm'))) return;
151+
// 深拷贝避免默认数据对象被响应式修改污染
152+
cvData.value = JSON.parse(JSON.stringify(defaultData));
153+
};
154+
155+
// 数据操作下拉菜单
156+
const showDataMenu = ref(false);
157+
const toggleDataMenu = () => { showDataMenu.value = !showDataMenu.value; };
158+
const closeDataMenu = () => { showDataMenu.value = false; };
159+
const handleImportClick = () => {
160+
closeDataMenu();
161+
const input = document.getElementById('import-json') as HTMLInputElement | null;
162+
input?.click();
163+
};
164+
const handleExportClick = () => { closeDataMenu(); handleExportJson(); };
165+
const handleSampleClick = () => { closeDataMenu(); handleLoadSample(); };
166+
146167
</script>
147168

148169
<template>
@@ -210,26 +231,45 @@ const handleImportJson = (event: Event) => {
210231
<!-- Editor Pane -->
211232
<aside
212233
class="w-[450px] md:w-[500px] min-w-[350px] border-r border-slate-200 bg-white flex flex-col z-10 shrink-0 no-print shadow-sm h-full relative">
213-
<div class="h-14 border-b border-slate-200 bg-white flex justify-between items-center px-4 shrink-0">
214-
<h2 class="text-sm font-bold text-slate-700 capitalize w-20"><i
234+
<div class="h-14 border-b border-slate-200 bg-white flex justify-between items-center px-4 shrink-0 gap-3">
235+
<h2 class="text-sm font-bold text-slate-700 capitalize min-w-0 truncate"><i
215236
class="fa-solid fa-pen-to-square text-[#01a3a4] mr-1.5 hidden sm:inline"></i> {{ activeTab }}</h2>
216237
<div class="flex items-center gap-2">
217238
<input type="file" id="import-json" accept=".json" class="hidden" @change="handleImportJson" />
218-
<label for="import-json"
219-
class="px-2 py-1.5 text-[11px] font-semibold text-slate-600 rounded bg-slate-100 hover:bg-slate-200 transition-colors shadow-sm cursor-pointer whitespace-nowrap">
220-
<i class="fa-solid fa-file-import mr-1"></i> <span class="hidden sm:inline">Import JSON</span>
221-
</label>
222-
<button @click="handleExportJson"
223-
class="px-2 py-1.5 text-[11px] font-semibold text-slate-600 rounded bg-slate-100 hover:bg-slate-200 transition-colors shadow-sm whitespace-nowrap">
224-
<i class="fa-solid fa-file-export mr-1"></i> <span class="hidden sm:inline">Export JSON</span>
225-
</button>
239+
<!-- 数据操作下拉菜单(Import / Export / Sample) -->
240+
<div class="relative">
241+
<button @click.stop="toggleDataMenu"
242+
class="px-2 py-1.5 text-[11px] font-semibold text-slate-600 rounded bg-slate-100 hover:bg-slate-200 transition-colors shadow-sm whitespace-nowrap flex items-center gap-1"
243+
:class="{ 'bg-slate-200': showDataMenu }"
244+
:title="t('dataOpsHint')">
245+
<i class="fa-solid fa-database"></i> <span class="hidden sm:inline">{{ t('dataOps') }}</span>
246+
<i class="fa-solid fa-chevron-down text-[8px] ml-0.5"></i>
247+
</button>
248+
<div v-if="showDataMenu"
249+
class="absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg py-1 min-w-[140px] z-50">
250+
<button @click.stop="handleImportClick"
251+
class="w-full text-left px-3 py-1.5 text-[11px] text-slate-600 hover:bg-slate-50 hover:text-[#01a3a4] flex items-center gap-2">
252+
<i class="fa-solid fa-file-import w-3"></i> {{ t('importJson') }}
253+
</button>
254+
<button @click.stop="handleExportClick"
255+
class="w-full text-left px-3 py-1.5 text-[11px] text-slate-600 hover:bg-slate-50 hover:text-[#01a3a4] flex items-center gap-2">
256+
<i class="fa-solid fa-file-export w-3"></i> {{ t('exportJson') }}
257+
</button>
258+
<div class="border-t border-slate-100 my-1"></div>
259+
<button @click.stop="handleSampleClick"
260+
class="w-full text-left px-3 py-1.5 text-[11px] text-slate-600 hover:bg-slate-50 hover:text-[#01a3a4] flex items-center gap-2"
261+
:title="t('loadSampleHint')">
262+
<i class="fa-solid fa-flask-vial w-3"></i> {{ t('loadSample') }}
263+
</button>
264+
</div>
265+
</div>
226266
<button @click="handlePrint"
227267
class="px-2 py-1.5 text-[11px] font-semibold text-white rounded bg-[#01a3a4] hover:bg-[#01a3a4]/90 transition-colors shadow-sm whitespace-nowrap border border-[#01a3a4]">
228268
<i class="fa-solid fa-file-pdf mr-1"></i> <span class="hidden sm:inline">PDF</span>
229269
</button>
230270
<button @click="handleSave"
231271
class="px-2 py-1.5 text-[11px] font-semibold text-white rounded bg-green-600 hover:bg-green-700 transition-colors shadow-sm whitespace-nowrap border border-green-600">
232-
<i class="fa-solid fa-save mr-1"></i> <span class="hidden sm:inline">Save</span>
272+
<i class="fa-solid fa-save mr-1"></i> <span class="hidden sm:inline">{{ t('save') }}</span>
233273
</button>
234274
</div>
235275
</div>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<script setup lang="ts">
2+
import LineNumberedTextarea from './LineNumberedTextarea.vue';
3+
import type { CustomItem } from '../types';
4+
import { useLocale } from '../composables/useLocale';
5+
6+
const { t } = useLocale();
7+
8+
const props = defineProps<{
9+
item: CustomItem;
10+
list: CustomItem[];
11+
index: number;
12+
}>();
13+
14+
// 上移 / 下移
15+
const moveItem = (direction: number) => {
16+
const newIdx = props.index + direction;
17+
if (newIdx < 0 || newIdx >= props.list.length) return;
18+
[props.list[props.index], props.list[newIdx]] = [props.list[newIdx], props.list[props.index]];
19+
};
20+
</script>
21+
22+
<template>
23+
<div class="p-3 border border-slate-200 bg-slate-50/50 rounded relative group">
24+
<!-- Collapsible header -->
25+
<div class="flex items-center justify-between gap-2">
26+
<div class="flex-1 font-bold text-xs text-slate-700 cursor-pointer flex items-center min-w-0"
27+
@click="item._collapsed = !item._collapsed">
28+
<i class="fa-solid fa-chevron-right mr-1 transition-transform inline-block shrink-0"
29+
:class="{ 'rotate-90': !item._collapsed }"></i>
30+
<span class="truncate">{{ item.title || t('untitledItem') }}</span>
31+
</div>
32+
<div class="flex items-center gap-1 shrink-0">
33+
<button @click.stop="moveItem(-1)" :disabled="index === 0"
34+
class="w-6 h-6 rounded bg-white hover:bg-slate-100 border border-slate-200 text-slate-500 disabled:opacity-30 disabled:hover:bg-white shadow-sm flex items-center justify-center"><i
35+
class="fa-solid fa-arrow-up text-[10px]"></i></button>
36+
<button @click.stop="moveItem(1)" :disabled="index === list.length - 1"
37+
class="w-6 h-6 rounded bg-white hover:bg-slate-100 border border-slate-200 text-slate-500 disabled:opacity-30 disabled:hover:bg-white shadow-sm flex items-center justify-center"><i
38+
class="fa-solid fa-arrow-down text-[10px]"></i></button>
39+
<button @click.stop="list.splice(index, 1)"
40+
class="w-6 h-6 rounded bg-white hover:bg-red-50 border border-slate-200 text-slate-400 hover:text-red-500 hover:border-red-200 shadow-sm ml-1 flex items-center justify-center"><i
41+
class="fa-solid fa-trash text-[10px]"></i></button>
42+
</div>
43+
</div>
44+
45+
<!-- Collapsible body -->
46+
<div v-show="!item._collapsed" class="mt-3 pt-3 border-t border-slate-200">
47+
<div class="grid grid-cols-2 gap-3 mb-2">
48+
<div class="col-span-2"><label class="block text-[10px] text-slate-500 font-bold mb-1">{{
49+
t('itemTitle') }}</label><input v-model="item.title" :placeholder="t('projectName')"
50+
class="w-full font-medium text-xs border border-slate-200 rounded p-1.5 outline-none focus:border-[#01a3a4] bg-white">
51+
</div>
52+
<div><label class="block text-[10px] text-slate-500 font-bold mb-1">{{ t('subtitle')
53+
}}</label><input v-model="item.subtitle"
54+
class="w-full text-xs border border-slate-200 rounded p-1.5 outline-none focus:border-[#01a3a4] bg-white">
55+
</div>
56+
<div><label class="block text-[10px] text-slate-500 font-bold mb-1">{{ t('date') }}</label><input
57+
v-model="item.dateStr"
58+
class="w-full text-xs border border-slate-200 rounded p-1.5 outline-none focus:border-[#01a3a4] bg-white">
59+
</div>
60+
<div><label class="block text-[10px] text-slate-500 font-bold mb-1">{{ t('location')
61+
}}</label><input v-model="item.location"
62+
class="w-full text-xs border border-slate-200 rounded p-1.5 outline-none focus:border-[#01a3a4] bg-white">
63+
</div>
64+
<div class="col-span-2">
65+
<label class="block text-[10px] text-slate-500 font-bold mb-1">{{ t('description') }}</label>
66+
<LineNumberedTextarea v-model="item.description" :rows="2" />
67+
</div>
68+
</div>
69+
<div class="mt-2 border-t border-slate-200 pt-2">
70+
<div class="flex items-center justify-between mb-1">
71+
<label class="block text-[10px] text-slate-500 font-bold">
72+
{{ t('bulletPoints') }} <span class="font-normal">{{ t('bulletPointsHint') }}</span>
73+
</label>
74+
<div class="inline-flex border border-slate-200 rounded overflow-hidden text-[10px]">
75+
<button type="button" @click="item.bulletListType = 'unordered'"
76+
:class="item.bulletListType !== 'ordered' ? 'bg-[#01a3a4] text-white' : 'bg-white text-slate-500 hover:bg-slate-50'"
77+
class="px-2 py-0.5 transition-colors" :title="t('unorderedList')">
78+
<i class="fa-solid fa-list-ul"></i>
79+
</button>
80+
<button type="button" @click="item.bulletListType = 'ordered'"
81+
:class="item.bulletListType === 'ordered' ? 'bg-[#01a3a4] text-white' : 'bg-white text-slate-500 hover:bg-slate-50'"
82+
class="px-2 py-0.5 transition-colors border-l border-slate-200" :title="t('orderedList')">
83+
<i class="fa-solid fa-list-ol"></i>
84+
</button>
85+
</div>
86+
</div>
87+
<LineNumberedTextarea :model-value="item.bullets?.join('\n')"
88+
@update:model-value="(v: string) => item.bullets = v.split('\n').map(s => s.trim()).filter(s => s)"
89+
:rows="3" />
90+
</div>
91+
</div>
92+
</div>
93+
</template>

0 commit comments

Comments
 (0)