Browse Source

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

adam 5 years ago
parent
commit
1b95a25e29
3 changed files with 17 additions and 7 deletions
  1. 5
    3
      lib/helper.js
  2. 2
    1
      package.json
  3. 10
    3
      src/helper.js

+ 5
- 3
lib/helper.js View File

75
     }
75
     }
76
     // 如果不存在对应的表情, 则返回原文
76
     // 如果不存在对应的表情, 则返回原文
77
     // const emoji = emojiObejct[src];
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
     return "[" + src + "]";
84
     return "[" + src + "]";
83
   }).replace(innerUrl, function (a, b) {
85
   }).replace(innerUrl, function (a, b) {

+ 2
- 1
package.json View File

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

+ 10
- 3
src/helper.js View File

72
       }
72
       }
73
       // 如果不存在对应的表情, 则返回原文
73
       // 如果不存在对应的表情, 则返回原文
74
       // const emoji = emojiObejct[src];
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
       return `[${src}]`;
86
       return `[${src}]`;
80
     })
87
     })