修复h5
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -111,7 +111,20 @@ function clearSearch() {
|
||||
}
|
||||
|
||||
function preview(content) {
|
||||
const text = (content || '').replace(/<[^>]+>/g, '').replace(/ /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(/ /g, ' ')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/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 {
|
||||
|
||||
Reference in New Issue
Block a user