You've already forked SmartisanNote.Remake
新增 离线web应用发布流程;
移除了便签详情页; 优化了若干逻辑; 新增 移动端、IOS兼容处理;
This commit is contained in:
@@ -488,6 +488,68 @@ const insertTodoList = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 插入图片
|
||||
const insertImage = () => {
|
||||
// 创建文件输入元素
|
||||
const fileInput = document.createElement('input')
|
||||
fileInput.type = 'file'
|
||||
fileInput.accept = 'image/*'
|
||||
fileInput.style.display = 'none'
|
||||
|
||||
// 添加到文档中
|
||||
document.body.appendChild(fileInput)
|
||||
|
||||
// 监听文件选择事件
|
||||
fileInput.addEventListener('change', function (event) {
|
||||
const file = event.target.files[0]
|
||||
if (file && file.type.startsWith('image/')) {
|
||||
// 创建FileReader读取文件
|
||||
const reader = new FileReader()
|
||||
reader.onload = function (e) {
|
||||
// 获取图片数据URL
|
||||
const imageDataUrl = e.target.result
|
||||
|
||||
// 获取当前选区
|
||||
const selection = window.getSelection()
|
||||
if (selection.rangeCount > 0) {
|
||||
const range = selection.getRangeAt(0)
|
||||
|
||||
// 创建图片元素
|
||||
const img = document.createElement('img')
|
||||
img.src = imageDataUrl
|
||||
img.className = 'editor-image'
|
||||
img.style.maxWidth = '100%'
|
||||
img.style.height = 'auto'
|
||||
img.style.display = 'block'
|
||||
img.style.margin = '0 auto'
|
||||
|
||||
// 插入图片到当前光标位置
|
||||
range.insertNode(img)
|
||||
|
||||
// 添加换行
|
||||
const br = document.createElement('br')
|
||||
img.parentNode.insertBefore(br, img.nextSibling)
|
||||
|
||||
// 触发输入事件更新内容
|
||||
handleInput()
|
||||
|
||||
// 重新聚焦到编辑器
|
||||
if (editorRef.value) {
|
||||
editorRef.value.focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
}
|
||||
|
||||
// 清理文件输入元素
|
||||
document.body.removeChild(fileInput)
|
||||
})
|
||||
|
||||
// 触发文件选择对话框
|
||||
fileInput.click()
|
||||
}
|
||||
|
||||
// 处理输入事件
|
||||
const handleInput = () => {
|
||||
if (editorRef.value) {
|
||||
@@ -878,6 +940,13 @@ defineExpose({
|
||||
line-height: var(--editor-line-height, 1.6);
|
||||
}
|
||||
|
||||
.editor-content img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* 待办事项样式 */
|
||||
:deep(.todo-container) {
|
||||
display: flex;
|
||||
@@ -903,3 +972,71 @@ defineExpose({
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// 插入图片
|
||||
const insertImage = () => {
|
||||
// 创建文件输入元素
|
||||
const fileInput = document.createElement('input')
|
||||
fileInput.type = 'file'
|
||||
fileInput.accept = 'image/*'
|
||||
fileInput.style.display = 'none'
|
||||
|
||||
// 添加到文档中
|
||||
document.body.appendChild(fileInput)
|
||||
|
||||
// 监听文件选择事件
|
||||
fileInput.addEventListener('change', function (event) {
|
||||
const file = event.target.files[0]
|
||||
if (file && file.type.startsWith('image/')) {
|
||||
// 创建FileReader读取文件
|
||||
const reader = new FileReader()
|
||||
reader.onload = function (e) {
|
||||
// 获取图片数据URL
|
||||
const imageDataUrl = e.target.result
|
||||
|
||||
// 获取当前选区
|
||||
const selection = window.getSelection()
|
||||
if (selection.rangeCount > 0) {
|
||||
const range = selection.getRangeAt(0)
|
||||
|
||||
// 创建图片元素
|
||||
const img = document.createElement('img')
|
||||
img.src = imageDataUrl
|
||||
img.className = 'editor-image'
|
||||
img.style.maxWidth = '100%'
|
||||
img.style.height = 'auto'
|
||||
img.style.display = 'block'
|
||||
img.style.margin = '0 auto'
|
||||
|
||||
// 插入图片到当前光标位置
|
||||
range.insertNode(img)
|
||||
|
||||
// 添加换行
|
||||
const br = document.createElement('br')
|
||||
img.parentNode.insertBefore(br, img.nextSibling)
|
||||
|
||||
// 触发输入事件更新内容
|
||||
handleInput()
|
||||
|
||||
// 重新聚焦到编辑器
|
||||
if (editorRef.value) {
|
||||
editorRef.value.focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
}
|
||||
|
||||
// 清理文件输入元素
|
||||
document.body.removeChild(fileInput)
|
||||
})
|
||||
|
||||
// 触发文件选择对话框
|
||||
fileInput.click()
|
||||
}
|
||||
|
||||
export default {
|
||||
insertImage
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user