From f3d4db769ba9b51b799d981511a710fd443d0e08 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 21 四月 2025 12:18:03 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/components/editor/index.jsx |  104 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 96 insertions(+), 8 deletions(-)

diff --git a/src/components/editor/index.jsx b/src/components/editor/index.jsx
index 58bfb60..a9e96de 100644
--- a/src/components/editor/index.jsx
+++ b/src/components/editor/index.jsx
@@ -1,38 +1,126 @@
-import React, {Component} from 'react'
+import React, { Component } from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
+import BraftEditor from 'braft-editor'
 import 'braft-editor/dist/index.css'
 import 'braft-extensions/dist/table.css'
-import BraftEditor from 'braft-editor'
 import Table from 'braft-extensions/dist/table'
 
+import Api from '@/api'
 import './index.scss'
 
 BraftEditor.use(Table())
 
 class NormalEditor extends Component {
   static propTpyes = {
-    card: PropTypes.object,  // 鏉$爜璁剧疆
-    value: PropTypes.any,    // 鏉$爜鍊�
+    config: PropTypes.object,
+    onChange: PropTypes.func
+  }
+
+  state = {
+    editorState: '',
+    encryption: 'false'
+  }
+
+  UNSAFE_componentWillMount () {
+    const { config, defaultValue } = this.props
+    let initVal = null
+    let encryption = 'false'
+
+    if (config && config.initval) {
+      initVal = config.initval
+    } else if (defaultValue) {
+      initVal = defaultValue
+    }
+
+    if (config && config.encryption === 'true') {
+      encryption = 'true'
+      if (initVal) {
+        try {
+          initVal = window.decodeURIComponent(window.atob(initVal))
+        } catch (e) {
+          initVal = this.props['data-__meta'].initialValue || null
+        }
+      }
+    }
+    
+    this.setState({
+      editorState: BraftEditor.createEditorState(initVal),
+      encryption
+    })
   }
 
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.props), fromJS(nextProps))
   }
 
-  handleEditorChange = () => {
+  handleEditorChange = (editorState) => {
+    const { encryption } = this.state
 
+    this.setState({ editorState })
+    if (this.props.onChange) {
+      let val = editorState.toHTML()
+      if (encryption === 'true') {
+        try {
+          val = window.btoa(window.encodeURIComponent(val))
+        } catch (e) {
+          val = editorState.toHTML()
+        }
+      }
+      this.props.onChange(val)
+    }
   }
 
-  submitContent = () => {
+  handleUpload(param) {
+    let form = new FormData()
 
+    form.append('file', param.file)
+
+    Api.getFileUpload(form).then(res => {
+      if (res.status) {
+        if (res.urlPath) {
+          param.success({
+            url: res.urlPath
+          })
+        } else {
+          param.error({
+            url: '涓婁紶澶辫触锛�'
+          })
+        }
+      } else {
+        param.error({
+          url: '涓婁紶澶辫触锛�'
+        })
+      }
+    })
   }
 
   render() {
+    const { config } = this.props
+    const { editorState } = this.state
+
+    let style = null
+    if (config && config.contHeidht) {
+      style = {'--editor-height': config.contHeidht < 100 ? config.contHeidht + 'vh' : config.contHeidht + 'px'}
+    }
 
     return (
-      <div className="normal-braft-editor">
-        <BraftEditor value={'<p></p>'} onChange={this.handleEditorChange} onSave={this.submitContent}/>
+      <div className="normal-braft-editor" style={style}>
+        <BraftEditor
+          value={editorState}
+          onChange={this.handleEditorChange}
+          media={{
+            uploadFn: (param) => {
+              this.handleUpload(param)
+            },
+            validate: () => {
+              return true
+            },
+            onInsert: () => {
+
+            }
+          }}
+        />
       </div>
     )
   }

--
Gitblit v1.8.0