From ae1d1cf70a9221aa548c2f645e79cfe548953d43 Mon Sep 17 00:00:00 2001 From: wkj <278599135@.com> Date: Mon, 15 Dec 2025 18:18:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B0=E5=BB=BAarticle=E6=97=B6=20?= =?UTF-8?q?=EF=BC=8C=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6extraFile=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1entityId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/article/editor/index.js | 25 +-- .../article/editor/locales/zh-CN.json | 2 +- es/components/article/editor/web.d.ts | 2 - es/components/article/editor/web.js | 188 +++++++++--------- es/components/article/upsert/web.js | 16 +- es/data/i18n.js | 2 +- lib/data/i18n.js | 2 +- src/components/article/editor/index.ts | 25 +-- .../article/editor/locales/zh-CN.json | 2 +- src/components/article/editor/web.tsx | 91 +++------ src/components/article/upsert/web.tsx | 51 ++--- src/data/i18n.ts | 2 +- 12 files changed, 176 insertions(+), 232 deletions(-) diff --git a/es/components/article/editor/index.js b/es/components/article/editor/index.js index 58615062e..25c3c6609 100644 --- a/es/components/article/editor/index.js +++ b/es/components/article/editor/index.js @@ -21,7 +21,6 @@ export default OakComponent({ data: { editor: null, html: '', - contentTip: false, }, properties: { articleMenuId: '', @@ -40,15 +39,14 @@ export default OakComponent({ next.editor.setHtml(next.content); } }, - oakId(prev, next) { - if (prev.oakId !== next.oakId) { - const { editor } = this.state; - if (editor == null) - return; - editor.destroy(); - this.setEditor(null); - } - }, + // oakId(prev, next) { + // if (prev.oakId !== next.oakId) { + // const { editor } = this.state; + // if (editor == null) return; + // editor.destroy(); + // this.setEditor(null); + // } + // }, name(prev, next) { if (prev.name !== next.name) { window.document.title = next.name ?? ''; @@ -58,7 +56,7 @@ export default OakComponent({ lifetimes: { async ready() { const { oakId, articleMenuId } = this.props; - if (!oakId) { + if (this.isCreation()) { if (articleMenuId) { this.update({ articleMenuId, @@ -89,11 +87,6 @@ export default OakComponent({ editor, }); }, - clearContentTip() { - this.setState({ - contentTip: false, - }); - }, async check() { if (this.state.name && this.state.name.length > 0 && diff --git a/es/components/article/editor/locales/zh-CN.json b/es/components/article/editor/locales/zh-CN.json index e13c7cd88..c67c10ea2 100644 --- a/es/components/article/editor/locales/zh-CN.json +++ b/es/components/article/editor/locales/zh-CN.json @@ -7,7 +7,7 @@ "name": "请输入文章标题", "content": "请输入文章内容..." }, - "chcek": { + "check": { "no name": "请填写文章标题!", "no content": "请填写文章内容!" } diff --git a/es/components/article/editor/web.d.ts b/es/components/article/editor/web.d.ts index 238443893..5377e7ec8 100644 --- a/es/components/article/editor/web.d.ts +++ b/es/components/article/editor/web.d.ts @@ -8,7 +8,6 @@ export default function Render(props: WebComponentProps void; check: () => void; uploadFile: (extraFile: EntityDict['extraFile']['CreateOperationData'], file: File) => Promise; - clearContentTip: () => void; gotoPreview: (content?: string, title?: string) => void; }>): React.JSX.Element; diff --git a/es/components/article/editor/web.js b/es/components/article/editor/web.js index 0fa32dbf6..ac4c64b8d 100644 --- a/es/components/article/editor/web.js +++ b/es/components/article/editor/web.js @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { Alert, Button, Space, Input, } from "antd"; +import { Button, Space, Input, } from "antd"; import "@wangeditor/editor/dist/css/style.css"; // 引入 css import { Editor, Toolbar } from "@wangeditor/editor-for-react"; import { SlateNode } from "@wangeditor/editor"; @@ -30,7 +30,7 @@ function customCheckImageFn(src, alt, url) { } export default function Render(props) { const { methods, data } = props; - const { t, setEditor, check, uploadFile, update, setHtml, gotoPreview, clearContentTip, } = methods; + const { t, setMessage, setEditor, check, uploadFile, update, setHtml, gotoPreview, } = methods; const { oakId, oakFullpath, id, name, content, editor, origin, tocPosition = 'none', highlightBgColor, scrollId, tocWidth, tocHeight, height = 600, tocClosed = false, execuable, activeColor, html, oakLoading, oakExecuting, } = data; const [articleId, setArticleId] = useState(''); const [toc, setToc] = useState([]); @@ -80,7 +80,6 @@ export default function Render(props) {
- {data.contentTip && ( clearContentTip()}/>)}
{ if (e.target.value.trim() && e.target.value.trim() !== '') { @@ -89,102 +88,107 @@ export default function Render(props) { else { update({ name: null }); } - }} value={data.name ?? ''} placeholder={t('placeholder.name')} size="large" maxLength={32} - // suffix={`${(data.name || "").length}/32`} - showCount className={Style.titleInput}/> + }} value={data.name ?? ''} placeholder={t('placeholder.name')} size="large" maxLength={32} showCount className={Style.titleInput}/>
- { - setHtml(editor.getHtml()); - const headers = editor.getElemsByTypePrefix("header"); - const tocItems = headers.map((header) => { - const text = SlateNode.string(header); - const { id, type } = header; - return { - text, - level: parseInt(type.substring(6)), - id, - }; - }); - setToc([...tocItems]); - }} style={{ - minHeight: '100%', - }} mode="default"/> + }} onCreated={setEditor} onChange={(editor) => { + setHtml(editor.getHtml()); + const headers = editor.getElemsByTypePrefix("header"); + const tocItems = headers.map((header) => { + const text = SlateNode.string(header); + const { id, type } = header; + return { + text, + level: parseInt(type.substring(6)), + id, + }; + }); + setToc([...tocItems]); + }} style={{ + minHeight: '100%', + }} mode="default"/>}
- {tocPosition === "right" ? () : null} + {tocPosition === "right" ? () : null} ); } diff --git a/es/components/article/upsert/web.js b/es/components/article/upsert/web.js index 26a9bbcca..7105cb5a2 100644 --- a/es/components/article/upsert/web.js +++ b/es/components/article/upsert/web.js @@ -30,7 +30,7 @@ function customCheckImageFn(src, alt, url) { } export default function Render(props) { const { methods, data } = props; - const { t, setEditor, check, uploadFile, update, setHtml, gotoPreview, clearContentTip, } = methods; + const { t, setMessage, setEditor, check, uploadFile, update, setHtml, gotoPreview, clearContentTip, } = methods; const { oakId, oakFullpath, id, content, editor, origin, tocPosition = 'none', highlightBgColor, activeColor, scrollId, tocWidth, tocHeight, height = 600, html, oakLoading, oakExecuting, } = data; const [articleId, setArticleId] = useState(''); const [toc, setToc] = useState([]); @@ -98,7 +98,12 @@ export default function Render(props) { // 最后插入图片 insertFn(url, extraFile.filename); } - catch (err) { } + catch (err) { + setMessage({ + type: "error", + content: err.message, + }); + } }, }, uploadVideo: { @@ -130,7 +135,12 @@ export default function Render(props) { insertFn(url, url + "?vframe/jpg/offset/0"); } - catch (err) { } + catch (err) { + setMessage({ + type: "error", + content: err.message, + }); + } }, }, }, diff --git a/es/data/i18n.js b/es/data/i18n.js index b4101a8ae..b81208923 100644 --- a/es/data/i18n.js +++ b/es/data/i18n.js @@ -68,7 +68,7 @@ const i18ns = [ "name": "请输入文章标题", "content": "请输入文章内容..." }, - "chcek": { + "check": { "no name": "请填写文章标题!", "no content": "请填写文章内容!" } diff --git a/lib/data/i18n.js b/lib/data/i18n.js index 3874df6db..92e3bfee8 100644 --- a/lib/data/i18n.js +++ b/lib/data/i18n.js @@ -70,7 +70,7 @@ const i18ns = [ "name": "请输入文章标题", "content": "请输入文章内容..." }, - "chcek": { + "check": { "no name": "请填写文章标题!", "no content": "请填写文章内容!" } diff --git a/src/components/article/editor/index.ts b/src/components/article/editor/index.ts index ec38db4be..d8b700fc7 100644 --- a/src/components/article/editor/index.ts +++ b/src/components/article/editor/index.ts @@ -1,6 +1,5 @@ import { IDomEditor } from '@wangeditor/editor'; import { EntityDict } from '../../../oak-app-domain'; -import { OakRowInconsistencyException } from 'oak-domain/lib/types'; export default OakComponent({ entity: 'article', @@ -25,7 +24,6 @@ export default OakComponent({ data: { editor: null as IDomEditor | null, html: '', - contentTip: false, }, properties: { articleMenuId: '', @@ -44,14 +42,14 @@ export default OakComponent({ next.editor.setHtml(next.content); } }, - oakId(prev, next) { - if (prev.oakId !== next.oakId) { - const { editor } = this.state; - if (editor == null) return; - editor.destroy(); - this.setEditor(null); - } - }, + // oakId(prev, next) { + // if (prev.oakId !== next.oakId) { + // const { editor } = this.state; + // if (editor == null) return; + // editor.destroy(); + // this.setEditor(null); + // } + // }, name(prev, next) { if (prev.name !== next.name) { window.document.title = next.name ?? ''; @@ -61,7 +59,7 @@ export default OakComponent({ lifetimes: { async ready() { const { oakId, articleMenuId } = this.props; - if (!oakId) { + if (this.isCreation()) { if (articleMenuId) { this.update({ articleMenuId, @@ -98,11 +96,6 @@ export default OakComponent({ editor, }); }, - clearContentTip() { - this.setState({ - contentTip: false, - }); - }, async check() { if ( this.state.name && diff --git a/src/components/article/editor/locales/zh-CN.json b/src/components/article/editor/locales/zh-CN.json index d9b02432a..7654b4f05 100644 --- a/src/components/article/editor/locales/zh-CN.json +++ b/src/components/article/editor/locales/zh-CN.json @@ -7,7 +7,7 @@ "name": "请输入文章标题", "content": "请输入文章内容..." }, - "chcek": { + "check": { "no name": "请填写文章标题!", "no content": "请填写文章内容!" } diff --git a/src/components/article/editor/web.tsx b/src/components/article/editor/web.tsx index d398d3b9f..3b8eed020 100644 --- a/src/components/article/editor/web.tsx +++ b/src/components/article/editor/web.tsx @@ -56,7 +56,6 @@ export default function Render( editor: any; content?: string; origin?: null | EntityDict['extraFile']['Schema']['origin']; - contentTip: boolean; articleMenuId: string; oakId: string; tocPosition: 'none' | 'left' | 'right'; @@ -78,7 +77,6 @@ export default function Render( extraFile: EntityDict['extraFile']['CreateOperationData'], file: File ) => Promise; - clearContentTip: () => void; gotoPreview: (content?: string, title?: string) => void; } > @@ -86,13 +84,13 @@ export default function Render( const { methods, data } = props; const { t, + setMessage, setEditor, check, uploadFile, update, setHtml, gotoPreview, - clearContentTip, } = methods; const { oakId, @@ -194,14 +192,6 @@ export default function Render( [Style.editorExternalContainer]: !!scrollId, })} > - {data.contentTip && ( - clearContentTip()} - /> - )}
{ @@ -215,13 +205,12 @@ export default function Render( placeholder={t('placeholder.name')} size="large" maxLength={32} - // suffix={`${(data.name || "").length}/32`} showCount className={Style.titleInput} />
- + />}
@@ -369,7 +329,6 @@ export default function Render( showToc={showToc} tocPosition="right" setShowToc={setShowToc} - // highlightBgColor={highlightBgColor} activeColor={activeColor} scrollId={containerId} tocWidth={tocWidth} diff --git a/src/components/article/upsert/web.tsx b/src/components/article/upsert/web.tsx index 90abe62ad..fed1f8170 100644 --- a/src/components/article/upsert/web.tsx +++ b/src/components/article/upsert/web.tsx @@ -84,6 +84,7 @@ export default function Render( const { methods, data } = props; const { t, + setMessage, setEditor, check, uploadFile, @@ -198,21 +199,9 @@ export default function Render( ) { // TS 语法 // file 即选中的文件 - const { name, size, type } = - file; - const extension = - name.substring( - name.lastIndexOf( - "." - ) + 1 - ); - const filename = - name.substring( - 0, - name.lastIndexOf( - "." - ) - ); + const { name, size, type } = file; + const extension = name.substring(name.lastIndexOf(".") + 1); + const filename = name.substring(0, name.lastIndexOf(".")); const extraFile = { entity: "article", entityId: oakId || articleId, @@ -240,7 +229,12 @@ export default function Render( url, extraFile.filename ); - } catch (err) { } + } catch (err: any) { + setMessage({ + type: "error", + content: err.message, + }) + } }, }, uploadVideo: { @@ -251,21 +245,9 @@ export default function Render( ) { // TS 语法 // file 即选中的文件 - const { name, size, type } = - file; - const extension = - name.substring( - name.lastIndexOf( - "." - ) + 1 - ); - const filename = - name.substring( - 0, - name.lastIndexOf( - "." - ) - ); + const { name, size, type } = file; + const extension = name.substring(name.lastIndexOf(".") + 1); + const filename = name.substring(0, name.lastIndexOf(".")); const extraFile = { entity: "article", entityId: oakId || articleId, @@ -294,7 +276,12 @@ export default function Render( url + "?vframe/jpg/offset/0" ); - } catch (err) { } + } catch (err: any) { + setMessage({ + type: "error", + content: err.message, + }) + } }, }, }, diff --git a/src/data/i18n.ts b/src/data/i18n.ts index 8107b8633..41d112d58 100644 --- a/src/data/i18n.ts +++ b/src/data/i18n.ts @@ -70,7 +70,7 @@ const i18ns: I18n[] = [ "name": "请输入文章标题", "content": "请输入文章内容..." }, - "chcek": { + "check": { "no name": "请填写文章标题!", "no content": "请填写文章内容!" }