瀏覽代碼

Merge branch 'master' of https://git.dev.advichcloud.com/feixiang/xinkeaboard

feix0518 1 周之前
父節點
當前提交
eb5751d80f

+ 15 - 1
xinkeaboard-seller/src/components/SldEditFormCom/SldEditFormCom.js

@@ -2,6 +2,7 @@ import React, { Component, Fragment } from 'react';
 import { Form, Select, Input,InputNumber,DatePicker,TreeSelect,Cascader,Checkbox,Radio } from 'antd';
 import { Form, Select, Input,InputNumber,DatePicker,TreeSelect,Cascader,Checkbox,Radio } from 'antd';
 import global from '@/global.less';
 import global from '@/global.less';
 import { sldInputAfterAddons, } from '@/utils/utils';
 import { sldInputAfterAddons, } from '@/utils/utils';
+import { emojiRegex } from "@/utils/regex";
 import styles from './SldEditFormCom.less';
 import styles from './SldEditFormCom.less';
 const FormItem = Form.Item;
 const FormItem = Form.Item;
 const { RangePicker } = DatePicker;
 const { RangePicker } = DatePicker;
@@ -43,13 +44,26 @@ export default  class SldEditFormCom extends Component {
     	  //普通输入框
     	  //普通输入框
       item_width  = item_width!=undefined?item_width:'auto'
       item_width  = item_width!=undefined?item_width:'auto'
 			if(val.type == 'input'){
 			if(val.type == 'input'){
+        // 统一规则定义
+        const unifyInputRules = [
+          {
+            validator: (_, value, callback) => {
+              const hasEmoji = emojiRegex.test(value);
+              if (hasEmoji) {
+                callback('不支持输入表情符号');
+              } else {
+                callback();
+              }
+            },
+          },
+        ];
 				return (<FormItem
 				return (<FormItem
 							key={index}
 							key={index}
 							label={val.label}
 							label={val.label}
 							extra={val.extra}
 							extra={val.extra}
               style={{width:val.width!=undefined?val.width+80:250}}
               style={{width:val.width!=undefined?val.width+80:250}}
 						>
 						>
-							{getFieldDecorator(val.name,{initialValue:val.initialValue,rules: val.rules})(
+							{getFieldDecorator(val.name,{initialValue:val.initialValue,rules: [...(val.rules || []), ...unifyInputRules]})(
 								<Input maxLength={val.maxLength!=undefined&&val.maxLength?val.maxLength:99999999} className={styles.item}  disabled={val.disable} placeholder={val.placeholder}/>
 								<Input maxLength={val.maxLength!=undefined&&val.maxLength?val.maxLength:99999999} className={styles.item}  disabled={val.disable} placeholder={val.placeholder}/>
 							)}
 							)}
 						</FormItem>
 						</FormItem>

+ 15 - 1
xinkeaboard-seller/src/components/SldTableRowThree/index.js

@@ -8,6 +8,7 @@ import {
 import global from '@/global.less';
 import global from '@/global.less';
 import styles from './index.less';
 import styles from './index.less';
 import { sldInputAfterAddons, sldBeforeUpload,input_limit_length ,sldComLanguage,getLocalStorageStingVal} from '@/utils/utils';
 import { sldInputAfterAddons, sldBeforeUpload,input_limit_length ,sldComLanguage,getLocalStorageStingVal} from '@/utils/utils';
+import { emojiRegex } from "@/utils/regex";
 import { Scrollbars } from 'react-custom-scrollbars';
 import { Scrollbars } from 'react-custom-scrollbars';
 import StandardTable from '@/components/StandardTable';
 import StandardTable from '@/components/StandardTable';
 
 
@@ -80,12 +81,25 @@ export default class SldTableRowTwo extends PureComponent {
       </div>
       </div>
     );
     );
     if (val.type == 'input') {
     if (val.type == 'input') {
+      // 统一规则定义
+      const unifyInputRules = [
+        {
+          validator: (_, value, callback) => {
+            const hasEmoji = emojiRegex.test(value);
+            if (hasEmoji) {
+              callback('不支持输入表情符号');
+            } else {
+              callback();
+            }
+          },
+        },
+      ];
       return (<FormItem
       return (<FormItem
           key={index}
           key={index}
           extra={val.extra}
           extra={val.extra}
           style={{width: `${val.ipwidth != undefined ? val.ipwidth : 80}%`}}
           style={{width: `${val.ipwidth != undefined ? val.ipwidth : 80}%`}}
         >
         >
-          {getFieldDecorator(val.name, { initialValue: val.initialValue, rules: val.rules })(
+          {getFieldDecorator(val.name, { initialValue: val.initialValue, rules: [...(val.rules || []), ...unifyInputRules] })(
             <Input maxLength={val.maxLength!=undefined&&val.maxLength?val.maxLength:input_limit_length} disabled={val.disable != undefined ? val.disable : false} className={styles.item}
             <Input maxLength={val.maxLength!=undefined&&val.maxLength?val.maxLength:input_limit_length} disabled={val.disable != undefined ? val.disable : false} className={styles.item}
                    placeholder={val.placeholder}/>,
                    placeholder={val.placeholder}/>,
           )}
           )}

+ 15 - 1
xinkeaboard-seller/src/components/SldTableRowTwo/index.js

@@ -32,6 +32,7 @@ import {
   sldComLanguage,
   sldComLanguage,
   sldBeforeMoreUpload,
   sldBeforeMoreUpload,
 } from '@/utils/utils';
 } from '@/utils/utils';
+import { emojiRegex } from "@/utils/regex";
 import {reserveInfoLimitType} from '@/utils/util_data';
 import {reserveInfoLimitType} from '@/utils/util_data';
 import ALibbSvg from '@/components/ALibbSvg';
 import ALibbSvg from '@/components/ALibbSvg';
 
 
@@ -130,12 +131,25 @@ export default class SldTableRowTwo extends PureComponent {
       </div>
       </div>
     );
     );
     if (val.type == 'input') {
     if (val.type == 'input') {
+      // 统一规则定义
+      const unifyInputRules = [
+        {
+          validator: (_, value, callback) => {
+            const hasEmoji = emojiRegex.test(value);
+            if (hasEmoji) {
+              callback('不支持输入表情符号');
+            } else {
+              callback();
+            }
+          },
+        },
+      ];
       return (<FormItem
       return (<FormItem
           key={index}
           key={index}
           extra={val.extra}
           extra={val.extra}
           style={{ width: '80%' }}
           style={{ width: '80%' }}
         >
         >
-          {getFieldDecorator(val.name, { initialValue: val.initialValue, rules: val.rules })(
+          {getFieldDecorator(val.name, { initialValue: val.initialValue, rules: [...(val.rules || []), ...unifyInputRules] })(
             <Input maxLength={val.maxLength != undefined ? val.maxLength : 250}
             <Input maxLength={val.maxLength != undefined ? val.maxLength : 250}
                    disabled={val.disable != undefined ? val.disable : false} className={styles.item}
                    disabled={val.disable != undefined ? val.disable : false} className={styles.item}
                    placeholder={val.placeholder}
                    placeholder={val.placeholder}

+ 61 - 18
xinkeaboard-seller/src/components/SldUEditor/index.js

@@ -1,11 +1,12 @@
-import React, { PureComponent, Fragment } from 'react';
-import {apiUrl} from '@/utils/sldconfig.js';
+import React, { PureComponent, Fragment } from "react";
+import { apiUrl } from "@/utils/sldconfig.js";
+import { emojiRegex } from "@/utils/regex";
+import { message } from "antd";
 
 
 export default class SldUEditor extends PureComponent {
 export default class SldUEditor extends PureComponent {
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
-    this.state = {
-    };
+    this.state = {};
   }
   }
 
 
   componentDidMount() {
   componentDidMount() {
@@ -13,38 +14,80 @@ export default class SldUEditor extends PureComponent {
   }
   }
 
 
   componentWillReceiveProps(nextProps, nextContext) {
   componentWillReceiveProps(nextProps, nextContext) {
-    if(nextProps.getContentFlag&&!this.props.getContentFlag){
+    if (nextProps.getContentFlag && !this.props.getContentFlag) {
       let con = UE.getEditor(nextProps.id).getContent();
       let con = UE.getEditor(nextProps.id).getContent();
       this.props.getEditorContent(con);
       this.props.getEditorContent(con);
     }
     }
   }
   }
 
 
   componentWillUnmount() {
   componentWillUnmount() {
-    UE.delEditor(this.props.id)
+    UE.delEditor(this.props.id);
   }
   }
 
 
   initEditor = () => {
   initEditor = () => {
-    const {id,initEditorContent} = this.props;
+    const { id, initEditorContent } = this.props;
     console.info();
     console.info();
-    const ueEditor = UE.getEditor(id,{
-      serverUrl: `${apiUrl}v3/oss/ueditor/upload?configPath=config.json&storeId=`+localStorage.getItem('storeId'),
+    const ueEditor = UE.getEditor(id, {
+      serverUrl:
+        `${apiUrl}v3/oss/ueditor/upload?configPath=config.json&storeId=` +
+        localStorage.getItem("storeId"),
     });
     });
-    ueEditor.ready((editor)=>{
-      if(!editor){
+    ueEditor.ready((editor) => {
+      if (!editor) {
         UE.delEditor(id);
         UE.delEditor(id);
         this.initEditor();
         this.initEditor();
-      }else{
+      } else {
         if (initEditorContent) {
         if (initEditorContent) {
           UE.getEditor(id).setContent(initEditorContent);
           UE.getEditor(id).setContent(initEditorContent);
         }
         }
+
+        // 监听输入内容变化
+        ueEditor.addListener("contentChange", () => {
+          const content = ueEditor.getContentTxt(); // 纯文本
+          if (this.hasEmoji(content)) {
+            message.warn("监测到输入表情符号,已自动去除");
+            ueEditor.body.innerHTML = ueEditor.body.innerHTML.replace(
+              emojiRegex,
+              ""
+            );
+            ueEditor.focus();
+            const range = ueEditor.selection.getRange();
+            const body = ueEditor.body;
+
+            // 找到最后一个文本节点或者元素节点
+            let lastNode = body.lastChild;
+
+            // 如果最后一个是元素节点,尝试找到它的最后一个文本节点
+            function getLastTextNode(node) {
+              if (node.nodeType === 3) return node; // 文本节点
+              if (!node.hasChildNodes()) return null;
+              return getLastTextNode(node.lastChild);
+            }
+
+            const lastTextNode = getLastTextNode(lastNode) || lastNode;
+
+            // 如果找到文本节点,光标放在文本末尾
+            if (lastTextNode && lastTextNode.nodeType === 3) {
+              range.setStart(lastTextNode, lastTextNode.nodeValue.length);
+            } else {
+              // 否则放在最后元素后面
+              range.setStartAfter(lastNode);
+            }
+
+            range.collapse(true);
+            range.select();
+          }
+        });
       }
       }
-    })
-  }
+    });
+  };
+
+  hasEmoji = (str) => {
+    return emojiRegex.test(str);
+  };
 
 
   render() {
   render() {
-    const {id} = this.props
-    return(
-      <div id={id} name="content" type="text/plain"></div>
-    )
+    const { id } = this.props;
+    return <div id={id} name="content" type="text/plain" />;
   }
   }
 }
 }

+ 12 - 0
xinkeaboard-seller/src/utils/regex.js

@@ -0,0 +1,12 @@
+export const emojiRegex = new RegExp(
+  [
+    "[\u{1F600}-\u{1F64F}]", // 😀-🙏 表情
+    "[\u{1F300}-\u{1F5FF}]", // 🌐-🗿 符号&象形文字
+    "[\u{1F680}-\u{1F6FF}]", // 🚀-🛺 交通工具
+    "[\u{2600}-\u{26FF}]", // ☀-⛿ 杂项符号
+    "[\u{2700}-\u{27BF}]", // ✀-➿ 装饰符号
+    "[\u{1F900}-\u{1F9FF}]", // 🤰-🦿 补充符号
+    "[\u{1FA70}-\u{1FAFF}]", // 🪀-🪿 扩展符号
+  ].join("|"),
+  "gu"
+);