@tnotesjs/core 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +84 -84
  2. package/dist/vitepress/config/index.js +2 -3
  3. package/package.json +1 -1
  4. package/types/config.ts +61 -61
  5. package/types/index.ts +11 -11
  6. package/types/note.ts +33 -33
  7. package/vitepress/assets/icons/icon__check.svg +3 -3
  8. package/vitepress/assets/icons/icon__clipboard.svg +7 -7
  9. package/vitepress/assets/icons/icon__close.svg +1 -1
  10. package/vitepress/assets/icons/icon__collapse.svg +1 -1
  11. package/vitepress/assets/icons/icon__confirm.svg +1 -1
  12. package/vitepress/assets/icons/icon__copy.svg +4 -4
  13. package/vitepress/assets/icons/icon__focus.svg +1 -1
  14. package/vitepress/assets/icons/icon__fold.svg +3 -3
  15. package/vitepress/assets/icons/icon__folder.svg +1 -1
  16. package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
  17. package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
  18. package/vitepress/assets/icons/icon__github.svg +3 -3
  19. package/vitepress/assets/icons/icon__mindmap.svg +1 -1
  20. package/vitepress/assets/icons/icon__next.svg +1 -1
  21. package/vitepress/assets/icons/icon__number_gray.svg +1 -1
  22. package/vitepress/assets/icons/icon__number_purple.svg +1 -1
  23. package/vitepress/assets/icons/icon__prev.svg +1 -1
  24. package/vitepress/assets/icons/icon__restore.svg +1 -1
  25. package/vitepress/assets/icons/icon__rotate.svg +4 -4
  26. package/vitepress/assets/icons/icon__search.svg +1 -1
  27. package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
  28. package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
  29. package/vitepress/assets/icons/icon__totop.svg +5 -5
  30. package/vitepress/assets/icons/icon__vscode.svg +5 -5
  31. package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
  32. package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
  33. package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
  34. package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
  35. package/vitepress/assets/icons/index.ts +38 -38
  36. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
  37. package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -373
  38. package/vitepress/components/CodeBlockFullscreen/index.ts +115 -115
  39. package/vitepress/components/CodeBlockFullscreen/styles.css +64 -64
  40. package/vitepress/components/Discussions/Discussions.module.scss +32 -32
  41. package/vitepress/components/Discussions/Discussions.vue +211 -211
  42. package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
  43. package/vitepress/components/EnWordList/EnWordList.vue +543 -543
  44. package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
  45. package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
  46. package/vitepress/components/Footprints/Footprints.module.scss +93 -93
  47. package/vitepress/components/Footprints/Footprints.vue +377 -377
  48. package/vitepress/components/Layout/AboutModal.module.scss +233 -233
  49. package/vitepress/components/Layout/AboutModal.vue +105 -105
  50. package/vitepress/components/Layout/AboutPanel.vue +266 -266
  51. package/vitepress/components/Layout/ContentCollapse.vue +603 -603
  52. package/vitepress/components/Layout/CustomSidebar.vue +605 -605
  53. package/vitepress/components/Layout/DocBeforeControls.vue +149 -139
  54. package/vitepress/components/Layout/DocFooter.vue +233 -233
  55. package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
  56. package/vitepress/components/Layout/ImagePreview.vue +281 -281
  57. package/vitepress/components/Layout/Layout.module.scss +661 -661
  58. package/vitepress/components/Layout/Layout.vue +542 -542
  59. package/vitepress/components/Layout/NoteStatus.vue +140 -140
  60. package/vitepress/components/Layout/SidebarItems.vue +263 -263
  61. package/vitepress/components/Layout/SidebarNavBefore.vue +92 -92
  62. package/vitepress/components/Layout/Swiper.vue +167 -167
  63. package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
  64. package/vitepress/components/Layout/ToggleFullContent.vue +34 -34
  65. package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
  66. package/vitepress/components/Layout/ToggleSidebar.vue +35 -35
  67. package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
  68. package/vitepress/components/Layout/composables/useNoteConfig.ts +121 -121
  69. package/vitepress/components/Layout/composables/useNoteSave.ts +173 -173
  70. package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
  71. package/vitepress/components/Layout/composables/useRedirect.ts +110 -110
  72. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
  73. package/vitepress/components/Layout/homeReadme.data.ts +124 -124
  74. package/vitepress/components/LoadingPage/LoadingPage.vue +192 -192
  75. package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
  76. package/vitepress/components/MarkMap/MarkMap.vue +404 -404
  77. package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
  78. package/vitepress/components/Mermaid/Mermaid.vue +364 -364
  79. package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
  80. package/vitepress/components/NotesTable/NotesTable.vue +98 -98
  81. package/vitepress/components/NotesTable/README.md +67 -67
  82. package/vitepress/components/Settings/Settings.module.scss +433 -433
  83. package/vitepress/components/Settings/Settings.vue +306 -306
  84. package/vitepress/components/SidebarCard/MindMapView.vue +483 -483
  85. package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
  86. package/vitepress/components/SidebarCard/SidebarCard.vue +948 -948
  87. package/vitepress/components/Tooltip/Tooltip.vue +70 -70
  88. package/vitepress/components/constants.ts +91 -91
  89. package/vitepress/components/notesConfig.data.ts +73 -73
  90. package/vitepress/components/sidebar.data.ts +59 -59
  91. package/vitepress/components/tnotes-config.data.ts +21 -21
  92. package/vitepress/components/utils.ts +26 -26
  93. package/vitepress/config/index.ts +160 -148
  94. package/vitepress/configs/constants.ts +26 -26
  95. package/vitepress/configs/head.config.ts +25 -25
  96. package/vitepress/configs/index.ts +9 -9
  97. package/vitepress/configs/markdown-it.d.ts +23 -23
  98. package/vitepress/configs/markdown.config.ts +366 -366
  99. package/vitepress/configs/theme.config.ts +108 -108
  100. package/vitepress/plugins/buildProgressPlugin.ts +470 -470
  101. package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
  102. package/vitepress/plugins/renameNotePlugin.ts +60 -60
  103. package/vitepress/plugins/updateConfigPlugin.ts +63 -63
  104. package/vitepress/theme/index.ts +95 -95
  105. package/vitepress/theme/styles/base.scss +50 -50
  106. package/vitepress/theme/styles/components/404.scss +31 -31
  107. package/vitepress/theme/styles/components/collapse.scss +175 -175
  108. package/vitepress/theme/styles/components/markmap.scss +101 -101
  109. package/vitepress/theme/styles/components/swiper.scss +255 -255
  110. package/vitepress/theme/styles/index.scss +25 -25
  111. package/vitepress/theme/styles/layout.scss +62 -62
  112. package/vitepress/theme/styles/utilities.scss +39 -39
  113. package/vitepress/theme/styles/vitepress-override.scss +25 -25
@@ -1,377 +1,377 @@
1
- <script setup>
2
- import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
3
-
4
- // ----------------------------------------------------------
5
- // #region - 图片处理
6
- // ----------------------------------------------------------
7
- /**
8
- * 获取图片容器的 DOM 引用
9
- */
10
- const imageContainer = ref(null)
11
-
12
- /**
13
- * 动态存储图片路径的列表
14
- */
15
- const images = ref([])
16
-
17
- /**
18
- * 控制 modal 显示
19
- */
20
- const isModalVisible = ref(false)
21
-
22
- /**
23
- * 当前预览的图片索引
24
- */
25
- const currentIndex = ref(0)
26
- const currentImage = computed(() => images.value[currentIndex.value])
27
-
28
- /**
29
- * 唯一标识符,用于区分不同的组件实例。
30
- * 解决被多次复用的时候,直接操作 DOM 的相关逻辑出现 bug。
31
- */
32
- const instanceId = Math.random().toString(36).substr(2, 9)
33
-
34
- /**
35
- * 打开模态框
36
- * @param index 需要展示的图片的索引
37
- */
38
- const openModal = (index) => {
39
- currentIndex.value = index
40
- isModalVisible.value = true
41
- }
42
- /**
43
- * 关闭模态框
44
- */
45
- const closeModal = () => (isModalVisible.value = false)
46
- /**
47
- * 键盘事件处理
48
- * @param event 事件对象
49
- */
50
- const handleKeyDown = (event) => {
51
- if (!isModalVisible.value) return
52
- switch (event.key) {
53
- case 'ArrowLeft':
54
- if (currentIndex.value > 0) currentIndex.value -= 1
55
- break
56
- case 'ArrowRight':
57
- if (currentIndex.value < images.value.length - 1) currentIndex.value += 1
58
- break
59
- case 'Escape':
60
- closeModal()
61
- break
62
- }
63
- }
64
- /**
65
- * 手指按下的初始 X 坐标
66
- */
67
- let touchStartX = 0
68
- /**
69
- * 手指抬起的最终 X 坐标
70
- */
71
- let touchEndX = 0
72
-
73
- /**
74
- * 处理触摸开始事件
75
- * @param event 事件对象
76
- */
77
- const handleTouchStart = (event) => {
78
- event.preventDefault() // 阻止默认行为
79
- touchStartX = event.touches[0].clientX // 记录手指按下的初始位置
80
- // console.log(`Touch start at: ${touchStartX}`);
81
- }
82
-
83
- /**
84
- * 处理触摸移动事件
85
- * @param event 事件对象
86
- */
87
- const handleTouchMove = (event) => {
88
- event.preventDefault() // 阻止默认行为
89
- const currentX = event.touches[0].clientX
90
- const moveDistance = currentX - touchStartX
91
-
92
- // 可选:添加视觉反馈(例如轻微移动图片的位置)
93
- // console.log(`Move distance: ${moveDistance}`);
94
- }
95
-
96
- /**
97
- * 处理触摸结束事件
98
- * - 向右滑动:切换到上一张图片
99
- * - 向左滑动:切换到下一张图片
100
- */
101
- const handleTouchEnd = () => {
102
- const swipeThreshold = 50 // 滑动阈值,单位为像素
103
- const swipeDistance = touchEndX - touchStartX // 计算滑动距离
104
- console.log(`Touch end at: ${touchEndX}, Distance: ${swipeDistance}`)
105
-
106
- if (swipeDistance > swipeThreshold && currentIndex.value > 0) {
107
- currentIndex.value--
108
- } else if (
109
- swipeDistance < -swipeThreshold &&
110
- currentIndex.value < images.value.length - 1
111
- ) {
112
- currentIndex.value++
113
- }
114
- }
115
- /**
116
- * 鼠标按下的初始 X 坐标
117
- */
118
- let mouseStartX = 0
119
- /**
120
- * 处理鼠标按下事件
121
- * @param event 事件对象
122
- */
123
- const handleMouseDown = (event) => {
124
- event.preventDefault()
125
- mouseStartX = event.clientX // 记录鼠标按下的初始位置
126
- window.addEventListener('mousemove', handleMouseMove)
127
- window.addEventListener('mouseup', handleMouseUp)
128
- }
129
- /**
130
- * 处理鼠标移动事件
131
- * @param event 事件对象
132
- */
133
- const handleMouseMove = (event) => {
134
- event.preventDefault()
135
- const currentX = event.clientX
136
- const moveDistance = currentX - mouseStartX
137
- // 可以在这里添加一些视觉反馈,比如轻微移动图片的位置
138
- // console.log(`Move distance: ${moveDistance}`);
139
- }
140
- /**
141
- * 处理鼠标松开事件
142
- */
143
- const handleMouseUp = () => {
144
- const swipeThreshold = 50 // 滑动阈值,单位为像素
145
- const modalContent = document.querySelector('.__dynamic__modal-content')
146
- if (!modalContent) return
147
-
148
- // 使用鼠标松开时的位置
149
- const currentX = event.clientX // 直接从事件对象中获取
150
- const moveDistance = currentX - mouseStartX
151
-
152
- if (moveDistance > swipeThreshold && currentIndex.value > 0) {
153
- currentIndex.value-- // 向右滑动,切换到上一张图片
154
- } else if (
155
- moveDistance < -swipeThreshold &&
156
- currentIndex.value < images.value.length - 1
157
- ) {
158
- currentIndex.value++ // 向左滑动,切换到下一张图片
159
- }
160
-
161
- // 清理变量和事件监听器
162
- mouseStartX = 0
163
- window.removeEventListener('mousemove', handleMouseMove)
164
- window.removeEventListener('mouseup', handleMouseUp)
165
- }
166
-
167
- onMounted(() => {
168
- const imgElements = imageContainer.value.querySelectorAll('img')
169
- images.value = Array.from(imgElements).map((img) => img.src)
170
-
171
- // 添加键盘事件监听器
172
- window.addEventListener('keydown', handleKeyDown)
173
-
174
- // 添加触摸事件监听器
175
- const modalContent = document.querySelector(
176
- `.__dynamic__modal-content-${instanceId}`
177
- )
178
- if (modalContent) {
179
- modalContent.addEventListener('touchstart', handleTouchStart)
180
- modalContent.addEventListener('touchmove', handleTouchMove) // 绑定 touchmove 事件
181
- modalContent.addEventListener('touchend', (event) => {
182
- touchEndX = event.changedTouches[0].clientX // 记录手指抬起的最终位置
183
- handleTouchEnd()
184
- })
185
-
186
- // 添加鼠标事件监听器
187
- modalContent.addEventListener('mousedown', handleMouseDown)
188
- }
189
- })
190
-
191
- onBeforeUnmount(() => {
192
- window.removeEventListener('keydown', handleKeyDown)
193
-
194
- // 移除触摸事件监听器
195
- const modalContent = document.querySelector(
196
- `.__dynamic__modal-content-${instanceId}`
197
- )
198
- if (modalContent) {
199
- modalContent.removeEventListener('touchstart', handleTouchStart)
200
- modalContent.removeEventListener('touchmove', handleTouchMove) // 移除 touchmove 事件
201
- modalContent.removeEventListener('touchend', handleTouchEnd)
202
- modalContent.removeEventListener('mousedown', handleMouseDown)
203
- }
204
- })
205
- // ----------------------------------------------------------
206
- // #endregion - 图片处理
207
- // ----------------------------------------------------------
208
-
209
- // ----------------------------------------------------------
210
- // #region - 文案处理
211
- // ----------------------------------------------------------
212
-
213
- /**
214
- * 文本容器的 DOM 引用
215
- */
216
- const textContainer = ref(null)
217
-
218
- /**
219
- * 控制文本是否折叠
220
- */
221
- const isCollapsed = ref(true)
222
-
223
- /**
224
- * 是否需要显示“全文”按钮
225
- */
226
- const isExpandable = ref(false)
227
-
228
- /**
229
- * 计算一级子元素数量并判断是否需要折叠
230
- * 1. 获取所有一级子元素
231
- * 2. 如果一级子元素数量大于 2,则可以展开
232
- */
233
- const checkChildElementCount = () => {
234
- if (textContainer.value) {
235
- const childElements = textContainer.value.children
236
- isExpandable.value = childElements.length > 2
237
- }
238
- }
239
-
240
- /**
241
- * 切换折叠/展开状态
242
- */
243
- const toggleCollapse = () => {
244
- isCollapsed.value = !isCollapsed.value
245
- }
246
-
247
- /**
248
- * 在 DOM 渲染后再做计算
249
- */
250
- onMounted(() => {
251
- nextTick(checkChildElementCount)
252
- })
253
- // ----------------------------------------------------------
254
- // #endregion - 文案处理
255
- // ----------------------------------------------------------
256
-
257
- // ----------------------------------------------------------
258
- // #region - 时间信息处理
259
- // ----------------------------------------------------------
260
- const props = defineProps({
261
- times: {
262
- type: Array,
263
- default: () => [],
264
- validator: (value) => {
265
- // 验证数组长度和内容类型
266
- return (
267
- value.length >= 2 &&
268
- value.length <= 6 &&
269
- value.every((item, index) => {
270
- if (index === 0) return typeof item === 'number' && item >= 0 // 年
271
- if (index === 1)
272
- return typeof item === 'number' && item >= 1 && item <= 12 // 月
273
- if (index === 2)
274
- return typeof item === 'number' && item >= 1 && item <= 31 // 日
275
- if (index === 3)
276
- return typeof item === 'number' && item >= 0 && item <= 23 // 小时
277
- if (index === 4)
278
- return typeof item === 'number' && item >= 0 && item <= 59 // 分钟
279
- if (index === 5)
280
- return typeof item === 'number' && item >= 0 && item <= 59 // 秒
281
- return false
282
- })
283
- )
284
- },
285
- },
286
- })
287
-
288
- const formattedTime = computed(() => {
289
- if (props.times.length < 2) return ''
290
-
291
- const [year, month, day, hour, minute, second] = props.times
292
-
293
- // 格式化年月日
294
- const datePart = `${String(year).padStart(4, '0')}-${String(month).padStart(
295
- 2,
296
- '0'
297
- )}`
298
- const dayPart = day !== undefined ? `-${String(day).padStart(2, '0')}` : ''
299
-
300
- // 格式化时分秒
301
- let timePart = ''
302
- if (hour !== undefined && minute !== undefined && second !== undefined) {
303
- timePart = ` ${String(hour).padStart(2, '0')}:${String(minute).padStart(
304
- 2,
305
- '0'
306
- )}:${String(second).padStart(2, '0')}`
307
- } else if (hour !== undefined && minute !== undefined) {
308
- timePart = ` ${String(hour).padStart(2, '0')}:${String(minute).padStart(
309
- 2,
310
- '0'
311
- )}`
312
- }
313
-
314
- // 👣 天数
315
- let daysSinceBirthday = ''
316
- if (day !== undefined) {
317
- // 确保时间部分为 00:00:00,避免时区和时间部分的影响
318
- const birthday = new Date(Date.UTC(1999, 5, 29)) // 注意:月份从 0 开始计数
319
- const currentDate = new Date(Date.UTC(year, month - 1, day)) // 同样使用 UTC 时间
320
- const diffInMilliseconds = currentDate - birthday
321
- const diffInDays =
322
- Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24)) + 1
323
- daysSinceBirthday = `👣 ${diffInDays} | `
324
- }
325
-
326
- return daysSinceBirthday + datePart + dayPart + timePart
327
- })
328
- // ----------------------------------------------------------
329
- // #endregion - 时间信息处理
330
- // ----------------------------------------------------------
331
- </script>
332
-
333
- <template>
334
- <div :class="$style.textContainer">
335
- <div
336
- :class="[$style.textContent, { [$style.collapsed]: isCollapsed }]"
337
- ref="textContainer"
338
- >
339
- <slot name="text-area"></slot>
340
- </div>
341
- <button
342
- v-if="isExpandable"
343
- :class="$style.toggleButton"
344
- @click="toggleCollapse"
345
- >
346
- {{ isCollapsed ? '全文' : '收起' }}
347
- </button>
348
- </div>
349
-
350
- <div :class="$style.imageContainer" ref="imageContainer">
351
- <slot
352
- name="image-list"
353
- :openModal="openModal"
354
- :closeModal="closeModal"
355
- :currentImage="currentImage"
356
- :isModalVisible="isModalVisible"
357
- ></slot>
358
- </div>
359
- <div :class="$style.modal" v-show="isModalVisible" @click.self="closeModal">
360
- <span :class="$style.close" @click="closeModal">&times;</span>
361
- <img
362
- :class="[$style.modalContent, `__dynamic__modal-content-${instanceId}`]"
363
- :src="currentImage"
364
- alt="Preview"
365
- @mousedown="handleMouseDown"
366
- />
367
- </div>
368
-
369
- <div :class="$style.timeContainer">
370
- <p>{{ formattedTime }}</p>
371
- </div>
372
- <div :class="$style.otherInfoContainer">
373
- <slot name="other-info"></slot>
374
- </div>
375
- </template>
376
-
377
- <style module src="./Footprints.module.scss"></style>
1
+ <script setup>
2
+ import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
3
+
4
+ // ----------------------------------------------------------
5
+ // #region - 图片处理
6
+ // ----------------------------------------------------------
7
+ /**
8
+ * 获取图片容器的 DOM 引用
9
+ */
10
+ const imageContainer = ref(null)
11
+
12
+ /**
13
+ * 动态存储图片路径的列表
14
+ */
15
+ const images = ref([])
16
+
17
+ /**
18
+ * 控制 modal 显示
19
+ */
20
+ const isModalVisible = ref(false)
21
+
22
+ /**
23
+ * 当前预览的图片索引
24
+ */
25
+ const currentIndex = ref(0)
26
+ const currentImage = computed(() => images.value[currentIndex.value])
27
+
28
+ /**
29
+ * 唯一标识符,用于区分不同的组件实例。
30
+ * 解决被多次复用的时候,直接操作 DOM 的相关逻辑出现 bug。
31
+ */
32
+ const instanceId = Math.random().toString(36).substr(2, 9)
33
+
34
+ /**
35
+ * 打开模态框
36
+ * @param index 需要展示的图片的索引
37
+ */
38
+ const openModal = (index) => {
39
+ currentIndex.value = index
40
+ isModalVisible.value = true
41
+ }
42
+ /**
43
+ * 关闭模态框
44
+ */
45
+ const closeModal = () => (isModalVisible.value = false)
46
+ /**
47
+ * 键盘事件处理
48
+ * @param event 事件对象
49
+ */
50
+ const handleKeyDown = (event) => {
51
+ if (!isModalVisible.value) return
52
+ switch (event.key) {
53
+ case 'ArrowLeft':
54
+ if (currentIndex.value > 0) currentIndex.value -= 1
55
+ break
56
+ case 'ArrowRight':
57
+ if (currentIndex.value < images.value.length - 1) currentIndex.value += 1
58
+ break
59
+ case 'Escape':
60
+ closeModal()
61
+ break
62
+ }
63
+ }
64
+ /**
65
+ * 手指按下的初始 X 坐标
66
+ */
67
+ let touchStartX = 0
68
+ /**
69
+ * 手指抬起的最终 X 坐标
70
+ */
71
+ let touchEndX = 0
72
+
73
+ /**
74
+ * 处理触摸开始事件
75
+ * @param event 事件对象
76
+ */
77
+ const handleTouchStart = (event) => {
78
+ event.preventDefault() // 阻止默认行为
79
+ touchStartX = event.touches[0].clientX // 记录手指按下的初始位置
80
+ // console.log(`Touch start at: ${touchStartX}`);
81
+ }
82
+
83
+ /**
84
+ * 处理触摸移动事件
85
+ * @param event 事件对象
86
+ */
87
+ const handleTouchMove = (event) => {
88
+ event.preventDefault() // 阻止默认行为
89
+ const currentX = event.touches[0].clientX
90
+ const moveDistance = currentX - touchStartX
91
+
92
+ // 可选:添加视觉反馈(例如轻微移动图片的位置)
93
+ // console.log(`Move distance: ${moveDistance}`);
94
+ }
95
+
96
+ /**
97
+ * 处理触摸结束事件
98
+ * - 向右滑动:切换到上一张图片
99
+ * - 向左滑动:切换到下一张图片
100
+ */
101
+ const handleTouchEnd = () => {
102
+ const swipeThreshold = 50 // 滑动阈值,单位为像素
103
+ const swipeDistance = touchEndX - touchStartX // 计算滑动距离
104
+ console.log(`Touch end at: ${touchEndX}, Distance: ${swipeDistance}`)
105
+
106
+ if (swipeDistance > swipeThreshold && currentIndex.value > 0) {
107
+ currentIndex.value--
108
+ } else if (
109
+ swipeDistance < -swipeThreshold &&
110
+ currentIndex.value < images.value.length - 1
111
+ ) {
112
+ currentIndex.value++
113
+ }
114
+ }
115
+ /**
116
+ * 鼠标按下的初始 X 坐标
117
+ */
118
+ let mouseStartX = 0
119
+ /**
120
+ * 处理鼠标按下事件
121
+ * @param event 事件对象
122
+ */
123
+ const handleMouseDown = (event) => {
124
+ event.preventDefault()
125
+ mouseStartX = event.clientX // 记录鼠标按下的初始位置
126
+ window.addEventListener('mousemove', handleMouseMove)
127
+ window.addEventListener('mouseup', handleMouseUp)
128
+ }
129
+ /**
130
+ * 处理鼠标移动事件
131
+ * @param event 事件对象
132
+ */
133
+ const handleMouseMove = (event) => {
134
+ event.preventDefault()
135
+ const currentX = event.clientX
136
+ const moveDistance = currentX - mouseStartX
137
+ // 可以在这里添加一些视觉反馈,比如轻微移动图片的位置
138
+ // console.log(`Move distance: ${moveDistance}`);
139
+ }
140
+ /**
141
+ * 处理鼠标松开事件
142
+ */
143
+ const handleMouseUp = () => {
144
+ const swipeThreshold = 50 // 滑动阈值,单位为像素
145
+ const modalContent = document.querySelector('.__dynamic__modal-content')
146
+ if (!modalContent) return
147
+
148
+ // 使用鼠标松开时的位置
149
+ const currentX = event.clientX // 直接从事件对象中获取
150
+ const moveDistance = currentX - mouseStartX
151
+
152
+ if (moveDistance > swipeThreshold && currentIndex.value > 0) {
153
+ currentIndex.value-- // 向右滑动,切换到上一张图片
154
+ } else if (
155
+ moveDistance < -swipeThreshold &&
156
+ currentIndex.value < images.value.length - 1
157
+ ) {
158
+ currentIndex.value++ // 向左滑动,切换到下一张图片
159
+ }
160
+
161
+ // 清理变量和事件监听器
162
+ mouseStartX = 0
163
+ window.removeEventListener('mousemove', handleMouseMove)
164
+ window.removeEventListener('mouseup', handleMouseUp)
165
+ }
166
+
167
+ onMounted(() => {
168
+ const imgElements = imageContainer.value.querySelectorAll('img')
169
+ images.value = Array.from(imgElements).map((img) => img.src)
170
+
171
+ // 添加键盘事件监听器
172
+ window.addEventListener('keydown', handleKeyDown)
173
+
174
+ // 添加触摸事件监听器
175
+ const modalContent = document.querySelector(
176
+ `.__dynamic__modal-content-${instanceId}`
177
+ )
178
+ if (modalContent) {
179
+ modalContent.addEventListener('touchstart', handleTouchStart)
180
+ modalContent.addEventListener('touchmove', handleTouchMove) // 绑定 touchmove 事件
181
+ modalContent.addEventListener('touchend', (event) => {
182
+ touchEndX = event.changedTouches[0].clientX // 记录手指抬起的最终位置
183
+ handleTouchEnd()
184
+ })
185
+
186
+ // 添加鼠标事件监听器
187
+ modalContent.addEventListener('mousedown', handleMouseDown)
188
+ }
189
+ })
190
+
191
+ onBeforeUnmount(() => {
192
+ window.removeEventListener('keydown', handleKeyDown)
193
+
194
+ // 移除触摸事件监听器
195
+ const modalContent = document.querySelector(
196
+ `.__dynamic__modal-content-${instanceId}`
197
+ )
198
+ if (modalContent) {
199
+ modalContent.removeEventListener('touchstart', handleTouchStart)
200
+ modalContent.removeEventListener('touchmove', handleTouchMove) // 移除 touchmove 事件
201
+ modalContent.removeEventListener('touchend', handleTouchEnd)
202
+ modalContent.removeEventListener('mousedown', handleMouseDown)
203
+ }
204
+ })
205
+ // ----------------------------------------------------------
206
+ // #endregion - 图片处理
207
+ // ----------------------------------------------------------
208
+
209
+ // ----------------------------------------------------------
210
+ // #region - 文案处理
211
+ // ----------------------------------------------------------
212
+
213
+ /**
214
+ * 文本容器的 DOM 引用
215
+ */
216
+ const textContainer = ref(null)
217
+
218
+ /**
219
+ * 控制文本是否折叠
220
+ */
221
+ const isCollapsed = ref(true)
222
+
223
+ /**
224
+ * 是否需要显示“全文”按钮
225
+ */
226
+ const isExpandable = ref(false)
227
+
228
+ /**
229
+ * 计算一级子元素数量并判断是否需要折叠
230
+ * 1. 获取所有一级子元素
231
+ * 2. 如果一级子元素数量大于 2,则可以展开
232
+ */
233
+ const checkChildElementCount = () => {
234
+ if (textContainer.value) {
235
+ const childElements = textContainer.value.children
236
+ isExpandable.value = childElements.length > 2
237
+ }
238
+ }
239
+
240
+ /**
241
+ * 切换折叠/展开状态
242
+ */
243
+ const toggleCollapse = () => {
244
+ isCollapsed.value = !isCollapsed.value
245
+ }
246
+
247
+ /**
248
+ * 在 DOM 渲染后再做计算
249
+ */
250
+ onMounted(() => {
251
+ nextTick(checkChildElementCount)
252
+ })
253
+ // ----------------------------------------------------------
254
+ // #endregion - 文案处理
255
+ // ----------------------------------------------------------
256
+
257
+ // ----------------------------------------------------------
258
+ // #region - 时间信息处理
259
+ // ----------------------------------------------------------
260
+ const props = defineProps({
261
+ times: {
262
+ type: Array,
263
+ default: () => [],
264
+ validator: (value) => {
265
+ // 验证数组长度和内容类型
266
+ return (
267
+ value.length >= 2 &&
268
+ value.length <= 6 &&
269
+ value.every((item, index) => {
270
+ if (index === 0) return typeof item === 'number' && item >= 0 // 年
271
+ if (index === 1)
272
+ return typeof item === 'number' && item >= 1 && item <= 12 // 月
273
+ if (index === 2)
274
+ return typeof item === 'number' && item >= 1 && item <= 31 // 日
275
+ if (index === 3)
276
+ return typeof item === 'number' && item >= 0 && item <= 23 // 小时
277
+ if (index === 4)
278
+ return typeof item === 'number' && item >= 0 && item <= 59 // 分钟
279
+ if (index === 5)
280
+ return typeof item === 'number' && item >= 0 && item <= 59 // 秒
281
+ return false
282
+ })
283
+ )
284
+ },
285
+ },
286
+ })
287
+
288
+ const formattedTime = computed(() => {
289
+ if (props.times.length < 2) return ''
290
+
291
+ const [year, month, day, hour, minute, second] = props.times
292
+
293
+ // 格式化年月日
294
+ const datePart = `${String(year).padStart(4, '0')}-${String(month).padStart(
295
+ 2,
296
+ '0'
297
+ )}`
298
+ const dayPart = day !== undefined ? `-${String(day).padStart(2, '0')}` : ''
299
+
300
+ // 格式化时分秒
301
+ let timePart = ''
302
+ if (hour !== undefined && minute !== undefined && second !== undefined) {
303
+ timePart = ` ${String(hour).padStart(2, '0')}:${String(minute).padStart(
304
+ 2,
305
+ '0'
306
+ )}:${String(second).padStart(2, '0')}`
307
+ } else if (hour !== undefined && minute !== undefined) {
308
+ timePart = ` ${String(hour).padStart(2, '0')}:${String(minute).padStart(
309
+ 2,
310
+ '0'
311
+ )}`
312
+ }
313
+
314
+ // 👣 天数
315
+ let daysSinceBirthday = ''
316
+ if (day !== undefined) {
317
+ // 确保时间部分为 00:00:00,避免时区和时间部分的影响
318
+ const birthday = new Date(Date.UTC(1999, 5, 29)) // 注意:月份从 0 开始计数
319
+ const currentDate = new Date(Date.UTC(year, month - 1, day)) // 同样使用 UTC 时间
320
+ const diffInMilliseconds = currentDate - birthday
321
+ const diffInDays =
322
+ Math.floor(diffInMilliseconds / (1000 * 60 * 60 * 24)) + 1
323
+ daysSinceBirthday = `👣 ${diffInDays} | `
324
+ }
325
+
326
+ return daysSinceBirthday + datePart + dayPart + timePart
327
+ })
328
+ // ----------------------------------------------------------
329
+ // #endregion - 时间信息处理
330
+ // ----------------------------------------------------------
331
+ </script>
332
+
333
+ <template>
334
+ <div :class="$style.textContainer">
335
+ <div
336
+ :class="[$style.textContent, { [$style.collapsed]: isCollapsed }]"
337
+ ref="textContainer"
338
+ >
339
+ <slot name="text-area"></slot>
340
+ </div>
341
+ <button
342
+ v-if="isExpandable"
343
+ :class="$style.toggleButton"
344
+ @click="toggleCollapse"
345
+ >
346
+ {{ isCollapsed ? '全文' : '收起' }}
347
+ </button>
348
+ </div>
349
+
350
+ <div :class="$style.imageContainer" ref="imageContainer">
351
+ <slot
352
+ name="image-list"
353
+ :openModal="openModal"
354
+ :closeModal="closeModal"
355
+ :currentImage="currentImage"
356
+ :isModalVisible="isModalVisible"
357
+ ></slot>
358
+ </div>
359
+ <div :class="$style.modal" v-show="isModalVisible" @click.self="closeModal">
360
+ <span :class="$style.close" @click="closeModal">&times;</span>
361
+ <img
362
+ :class="[$style.modalContent, `__dynamic__modal-content-${instanceId}`]"
363
+ :src="currentImage"
364
+ alt="Preview"
365
+ @mousedown="handleMouseDown"
366
+ />
367
+ </div>
368
+
369
+ <div :class="$style.timeContainer">
370
+ <p>{{ formattedTime }}</p>
371
+ </div>
372
+ <div :class="$style.otherInfoContainer">
373
+ <slot name="other-info"></slot>
374
+ </div>
375
+ </template>
376
+
377
+ <style module src="./Footprints.module.scss"></style>