This commit is contained in:
2026-08-15 22:16:58 +08:00
parent a344aaedf3
commit aed71d237d
15 changed files with 13296 additions and 306 deletions
+10 -33
View File
@@ -15,14 +15,11 @@
<view class="field content-field">
<text class="field-label">内容</text>
<editor
id="noteEditor"
class="note-editor"
:placeholder="'记录你的想法...'"
:value="form.content"
@ready="onEditorReady"
@input="onEditorInput"
/>
<NoteRichEditor
v-model="form.content"
class="note-editor"
placeholder="记录你的想法..."
/>
</view>
<view class="switch-row" @tap="form.pinned = !form.pinned">
@@ -52,10 +49,10 @@ import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getNote, createNote, updateNote, deleteNote } from '@/api/note.js'
import { formatDate } from '@/utils/date.js'
import NoteRichEditor from '@/components/NoteRichEditor.vue'
const noteId = ref('')
const saving = ref(false)
const editorCtx = ref(null)
const form = reactive({
title: '',
content: '',
@@ -65,21 +62,6 @@ const meta = reactive({
updatedAt: 0
})
function onEditorReady() {
uni.createSelectorQuery().select('#noteEditor').context((res) => {
if (res && res.context) {
editorCtx.value = res.context
if (form.content) {
editorCtx.value.setContents({ html: form.content })
}
}
}).exec()
}
function onEditorInput(e) {
form.content = e.detail.html || ''
}
onLoad(async (query) => {
if (query?.id) {
noteId.value = query.id
@@ -102,9 +84,6 @@ async function loadNote(id) {
form.content = note.content
form.pinned = !!note.pinned
meta.updatedAt = note.updatedAt
if (editorCtx.value && note.content) {
editorCtx.value.setContents({ html: note.content })
}
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
@@ -218,13 +197,11 @@ function onDelete() {
width: 100%;
flex: 1;
min-height: 0;
padding: 20rpx;
font-size: 28rpx;
color: $color-text;
box-sizing: border-box;
overflow-y: auto;
background: $color-bg-page;
border-radius: $radius-md;
overflow: hidden;
background: #f5f7fa;
border-radius: 12rpx;
padding: 20rpx;
}
.placeholder {
+23 -2
View File
@@ -111,7 +111,20 @@ function clearSearch() {
}
function preview(content) {
const text = (content || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/\s+/g, ' ').trim()
if (!content) return '暂无内容'
let html = content
.replace(/<\/t[dh]>/gi, ' ')
.replace(/<\/tr>/gi, ' ')
.replace(/<\/p>/gi, ' ')
.replace(/<br\s*\/?>/gi, ' ')
const text = html
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/\s+/g, ' ')
.trim()
if (!text) return '暂无内容'
return text.length > 60 ? `${text.slice(0, 60)}...` : text
}
@@ -220,6 +233,7 @@ function onDelete(item) {
@include card;
padding: 28rpx 24rpx;
margin-bottom: 20rpx;
overflow: hidden;
&:active {
opacity: 0.92;
@@ -267,11 +281,18 @@ function onDelete(item) {
}
.note-preview {
display: block;
display: -webkit-box;
width: 100%;
overflow: hidden;
font-size: 26rpx;
color: $color-text-secondary;
line-height: 1.6;
margin-bottom: 20rpx;
word-break: break-all;
overflow-wrap: anywhere;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
}
.note-actions {