KaysonCui 5 years ago
parent
commit
075db6f7fc
1 changed files with 23 additions and 5 deletions
  1. 23 5
      front/src/services/Tools.js

+ 23 - 5
front/src/services/Tools.js

@@ -84,14 +84,14 @@ export function loadScript(url, callback) {
   script.async = true;
   script.defer = true;
   if (script.readyState) {
-    script.onreadystatechange = function () {
+    script.onreadystatechange = function() {
       if (script.readyState === 'loaded' || script.readyState === 'complete') {
         script.onreadystatechange = null;
         if (callback) callback();
       }
     };
   } else {
-    script.onload = function () {
+    script.onload = function() {
       if (callback) callback();
     };
   }
@@ -333,7 +333,7 @@ export function bindSearch(targetList, field, Component, listFunc, render, def,
   });
   const key = `lastFetchId${field}${index}`;
   if (!Component[key]) Component[key] = 0;
-  const searchFunc = (data) => {
+  const searchFunc = data => {
     Component[key] += 1;
     const fetchId = Component[key];
     Component.setState({ fetching: true });
@@ -378,7 +378,7 @@ export function generateSearch(field, prop, Component, listFunc, render, def, no
     filterOption: false,
     notFoundContent: notFound,
   };
-  const searchFunc = (data) => {
+  const searchFunc = data => {
     Component[key] += 1;
     const fetchId = Component[key];
     Component.setState({ fetching: true });
@@ -393,7 +393,7 @@ export function generateSearch(field, prop, Component, listFunc, render, def, no
       Component.setState({ [field]: prop, fetching: false });
     });
   };
-  item.onSearch = (keyword) => {
+  item.onSearch = keyword => {
     searchFunc({ page: 1, number: 5, keyword });
   };
   item = Object.assign(prop || {}, item);
@@ -409,3 +409,21 @@ export function generateSearch(field, prop, Component, listFunc, render, def, no
   }
   Component.setState({ [field]: prop });
 }
+
+export function getHtmlText(text) {
+  text = text.replace(new RegExp(/\r\n/, 'g'), '\r').replace(new RegExp(/\n/, 'g'), '\r');
+  let html = '';
+  text.split('\r').forEach(item => {
+    item.split(' ').forEach(t => {
+      html += `<i uuid="${uuid(4)}">${t}</i>`;
+    });
+    html += '<br/>';
+  });
+  return html;
+}
+
+export function getSimpleText(html) {
+  let text = html.replace(new RegExp('<br/>', 'g'), '\n\r');
+  text = text.replace(new RegExp('<.+?>', 'g'), '');
+  return text;
+}