2 Commits a1da4813d9 ... 5aef6354e9

Author SHA1 Message Date
  KaysonCui 5aef6354e9 Merge branch 'master' of https://git.proginn.com/zaixianjiaoyu/sourcecode 5 years ago
  KaysonCui 075db6f7fc fix 5 years ago
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];
     targetList[index].loading = true;
@@ -381,7 +381,7 @@ export function generateSearch(field, props, Component, listFunc, render, def, n
     notFoundContent: notFound,
   };
   item = Object.assign(props || {}, item);
-  const searchFunc = (data) => {
+  const searchFunc = data => {
     Component[key] += 1;
     const fetchId = Component[key];
     item.loading = true;
@@ -398,7 +398,7 @@ export function generateSearch(field, props, Component, listFunc, render, def, n
       Component.setState({ [field]: item, fetching: false });
     });
   };
-  item.onSearch = (keyword) => {
+  item.onSearch = keyword => {
     searchFunc({ page: 1, number: 5, keyword });
   };
   if (def) {
@@ -412,3 +412,21 @@ export function generateSearch(field, props, Component, listFunc, render, def, n
   }
   Component.setState({ [field]: item });
 }
+
+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;
+}