Yansen 5 years ago
parent
commit
dc103533a1
3 changed files with 67 additions and 59 deletions
  1. 1
    1
      config/config.js
  2. 13
    0
      config/routes.js
  3. 53
    58
      src/components/Wangedit/Wangedit.jsx

+ 1
- 1
config/config.js View File

134
   proxy: {
134
   proxy: {
135
     '/api': {
135
     '/api': {
136
       // target: 'https://dev.fangdeal.cn',
136
       // target: 'https://dev.fangdeal.cn',
137
-      target: 'http://192.168.0.195:8080/',
137
+      target: 'http://127.0.0.1:8080/',
138
       changeOrigin: true,
138
       changeOrigin: true,
139
       // pathRewrite: { '^/server': '' },
139
       // pathRewrite: { '^/server': '' },
140
     },
140
     },

+ 13
- 0
config/routes.js View File

211
             ],
211
             ],
212
           },
212
           },
213
 
213
 
214
+          {
215
+            path: '/officenews',
216
+            name: '资讯管理',
217
+            component: '../layouts/BlankLayout',
218
+            routes: [
219
+              {
220
+                path: '/officenews',
221
+                name: '资讯管理',
222
+                component: './resource/openScreen',
223
+              },
224
+            ],
225
+          },
226
+
214
           {
227
           {
215
             component: './404',
228
             component: './404',
216
           },
229
           },

+ 53
- 58
src/components/Wangedit/Wangedit.jsx View File

11
     super(props, context);
11
     super(props, context);
12
     this.state = {
12
     this.state = {
13
       html: undefined,
13
       html: undefined,
14
-      contenteditable: props.contenteditable == false ? false : true
15
-    }
14
+      contenteditable: props.contenteditable == false ? false : true,
15
+    };
16
     this.editor = undefined;
16
     this.editor = undefined;
17
   }
17
   }
18
 
18
 
19
-  render() {
20
-    return (
21
-      <div ref="editorElem" style={{ textAlign: 'left' }}>
22
-      </div>
23
-    );
24
-  }
25
-
26
   componentDidMount() {
19
   componentDidMount() {
27
-    const elem = this.refs.editorElem
28
-    this.editor = new E(elem)
20
+    const elem = this.refs.editorElem;
21
+    this.editor = new E(elem);
29
     // 使用 onchange 函数监听内容的变化
22
     // 使用 onchange 函数监听内容的变化
30
     this.editor.customConfig.onchange = html => {
23
     this.editor.customConfig.onchange = html => {
31
-      this.setState({ html })
24
+      this.setState({ html });
32
 
25
 
33
       if (typeof this.props.onChange === 'function') {
26
       if (typeof this.props.onChange === 'function') {
34
-        this.props.onChange(html)
27
+        this.props.onChange(html);
35
       }
28
       }
36
-    }
37
-    this.editor.customConfig.zIndex = 100
38
-    this.editor.customConfig.uploadImgMaxLength = 1
39
-    this.editor.customConfig.customUploadImg = function (files, insert) {
40
-      if (!files.length) return
41
-      
42
-      const data = new FormData()
43
-      data.append('file', files[0])
29
+    };
30
+    this.editor.customConfig.zIndex = 100;
31
+    this.editor.customConfig.uploadImgMaxLength = 1;
32
+    this.editor.customConfig.customUploadImg = function(files, insert) {
33
+      if (!files.length) return;
44
 
34
 
45
-      fetch(apis.image.upload)({data}).then(insert)
46
-    }
35
+      const data = new FormData();
36
+      data.append('file', files[0]);
37
+
38
+      fetch(apis.image.upload)({ data }).then(insert);
39
+    };
47
     this.editor.customConfig.menus = [
40
     this.editor.customConfig.menus = [
48
-      'head',  // 标题
49
-      'bold',  // 粗体
50
-      'fontSize',  // 字号
51
-      'fontName',  // 字体
52
-      'italic',  // 斜体
53
-      'underline',  // 下划线
54
-      'strikeThrough',  // 删除线
55
-      'foreColor',  // 文字颜色
56
-      'backColor',  // 背景颜色
57
-      'list',  // 列表
58
-      'justify',  // 对齐方式
59
-      'quote',  // 引用
60
-      'image',  // 插入图片
61
-      'undo',  // 撤销
62
-      'redo'  // 重复
63
-    ]
64
-    
41
+      'head', // 标题
42
+      'bold', // 粗体
43
+      'fontSize', // 字号
44
+      'fontName', // 字体
45
+      'italic', // 斜体
46
+      'underline', // 下划线
47
+      'strikeThrough', // 删除线
48
+      'foreColor', // 文字颜色
49
+      'backColor', // 背景颜色
50
+      'list', // 列表
51
+      'justify', // 对齐方式
52
+      'quote', // 引用
53
+      'image', // 插入图片
54
+      'undo', // 撤销
55
+      'redo', // 重复
56
+    ];
57
+
65
     // 过滤 word 字符
58
     // 过滤 word 字符
66
-    this.editor.customConfig.pasteFilterStyle = false
59
+    this.editor.customConfig.pasteFilterStyle = false;
67
     this.editor.customConfig.pasteTextHandle = function(content) {
60
     this.editor.customConfig.pasteTextHandle = function(content) {
68
       const regs = [
61
       const regs = [
69
-        /<!--\[if [\s\S]*?endif\]-->/ig,
70
-        /<[a-zA-Z0-9]+\:[^>]+>[^>]*<\/[a-zA-Z0-9]+\:[^>]+>/ig,
71
-        /<[a-zA-Z0-9]+\:[^>]+\/>/ig,
72
-        /<style>[\s\S]*?<\/style>/ig,
73
-      ]
62
+        /<!--\[if [\s\S]*?endif\]-->/gi,
63
+        /<[a-zA-Z0-9]+\:[^>]+>[^>]*<\/[a-zA-Z0-9]+\:[^>]+>/gi,
64
+        /<[a-zA-Z0-9]+\:[^>]+\/>/gi,
65
+        /<style>[\s\S]*?<\/style>/gi,
66
+        new RegExp('\u2029', 'ig'), // 替换word分隔符 序号 8233
67
+      ];
74
 
68
 
75
-      return regs.reduce((acc, reg) => {
76
-        return acc.replace(reg, '')
77
-      }, content)
78
-    }
69
+      return regs.reduce((acc, reg) => acc.replace(reg, ''), content);
70
+    };
79
 
71
 
80
-    this.editor.create()
81
-    this.editor.$textElem.attr('contenteditable',this.state.contenteditable);
82
-    this.editor.customConfig.uploadImgShowBase64 = true
83
-    this.editor.txt.html(this.props.value)
72
+    this.editor.create();
73
+    this.editor.$textElem.attr('contenteditable', this.state.contenteditable);
74
+    this.editor.customConfig.uploadImgShowBase64 = true;
75
+    this.editor.txt.html(this.props.value);
84
   }
76
   }
85
 
77
 
86
   componentDidUpdate(props, state) {
78
   componentDidUpdate(props, state) {
87
     if (this.props.value && !state.html) {
79
     if (this.props.value && !state.html) {
88
       if (this.editor) {
80
       if (this.editor) {
89
-        this.editor.txt.html(this.props.value)
81
+        this.editor.txt.html(this.props.value);
90
       }
82
       }
91
     }
83
     }
92
   }
84
   }
100
    * @memberof Wangedit
92
    * @memberof Wangedit
101
    */
93
    */
102
   shouldComponentUpdate(nextProps) {
94
   shouldComponentUpdate(nextProps) {
103
-    return nextProps.value !== this.editor.txt.html()
95
+    return nextProps.value !== this.editor.txt.html();
104
   }
96
   }
105
-}
106
 
97
 
107
-export default Wangedit
98
+  render() {
99
+    return <div ref="editorElem" style={{ textAlign: 'left' }}></div>;
100
+  }
101
+}
108
 
102
 
103
+export default Wangedit;