Sfoglia il codice sorgente

fix:修正部分极端情况导致的解析表情报错问题;更改测试端口

adam 5 anni fa
parent
commit
1b95a25e29
3 ha cambiato i file con 17 aggiunte e 7 eliminazioni
  1. 5
    3
      lib/helper.js
  2. 2
    1
      package.json
  3. 10
    3
      src/helper.js

+ 5
- 3
lib/helper.js Vedi File

@@ -75,9 +75,11 @@ function renderContent(content, onClick) {
75 75
     }
76 76
     // 如果不存在对应的表情, 则返回原文
77 77
     // const emoji = emojiObejct[src];
78
-    var emoji = JSON.parse(sessionStorage.getItem("emojiMap"))[src];
79
-    if (emoji) {
80
-      return "<img class=\"comment-emoji\" src=\"" + emoji + "\" alt=\"" + emoji.title + "\" style=\"width:28px\"/>";
78
+    if(sessionStorage.getItem("emojiMap") && JSON.parse(sessionStorage.getItem("emojiMap"))){
79
+      var emoji = JSON.parse(sessionStorage.getItem("emojiMap"))[src];
80
+      if (emoji) {
81
+        return "<img class=\"comment-emoji\" src=\"" + emoji + "\" alt=\"" + emoji.title + "\" style=\"width:28px\"/>";
82
+      }
81 83
     }
82 84
     return "[" + src + "]";
83 85
   }).replace(innerUrl, function (a, b) {

+ 2
- 1
package.json Vedi File

@@ -35,13 +35,14 @@
35 35
   "scripts": {
36 36
     "precommit": "lint-staged",
37 37
     "prettier": "prettier --single-quote --trailing-comma=es5 --write 'src/**/*.{js,jsx,json,css,less}'",
38
-    "start": "react-app-rewired start",
38
+    "start": "cross-env PORT=3001 react-app-rewired start",
39 39
     "build": "react-app-rewired build",
40 40
     "test": "react-app-rewired test --env=jsdom",
41 41
     "eject": "react-scripts eject",
42 42
     "lib": "babel ./src --out-dir ./lib --source-maps --copy-files"
43 43
   },
44 44
   "devDependencies": {
45
+    "cross-env": "^5.2.0",
45 46
     "babel-cli": "^6.26.0",
46 47
     "babel-plugin-import": "^1.8.0",
47 48
     "babel-plugin-transform-object-rest-spread": "^6.26.0",

+ 10
- 3
src/helper.js Vedi File

@@ -72,9 +72,16 @@ export function renderContent(content, onClick) {
72 72
       }
73 73
       // 如果不存在对应的表情, 则返回原文
74 74
       // const emoji = emojiObejct[src];
75
-      const emoji = JSON.parse(sessionStorage.getItem("emojiMap"))[src];
76
-      if (emoji) {
77
-        return `<img class="comment-emoji" src="${emoji}" alt="${emoji.title}" style="width:28px"/>`;
75
+      if (
76
+        sessionStorage.getItem("emojiMap") &&
77
+        JSON.parse(sessionStorage.getItem("emojiMap"))
78
+      ) {
79
+        const emoji = JSON.parse(sessionStorage.getItem("emojiMap"))[src];
80
+        if (emoji) {
81
+          return `<img class="comment-emoji" src="${emoji}" alt="${
82
+            emoji.title
83
+          }" style="width:28px"/>`;
84
+        }
78 85
       }
79 86
       return `[${src}]`;
80 87
     })