Browse Source

JSON工具中判断mock工具是否安装,如果安装了就直接打开,没安装就跳转到安装页面

zxlie 3 months ago
parent
commit
9518726ad3
2 changed files with 21 additions and 1 deletions
  1. 1 1
      apps/json-format/index.html
  2. 20 0
      apps/json-format/index.js

+ 1 - 1
apps/json-format/index.html

@@ -16,7 +16,7 @@
                             <img src="../static/img/fe-16.png" alt="fehelper"/> FeHelper</a>:JSON格式化
                             <img src="../static/img/fe-16.png" alt="fehelper"/> FeHelper</a>:JSON格式化
                         <span class="x-xdemo" ref="demoLink1" @click="setDemo">示例1:JSON片段</span>
                         <span class="x-xdemo" ref="demoLink1" @click="setDemo">示例1:JSON片段</span>
                         <a class="x-xdemo" href="http://t.weather.sojson.com/api/weather/city/101030100" target="_blank">示例2:在线JSON</a>
                         <a class="x-xdemo" href="http://t.weather.sojson.com/api/weather/city/101030100" target="_blank">示例2:在线JSON</a>
-                        <a class="x-xdemo" href="/options/index.html?query=数据Mock工具" target="_blank" class="fh-tip-link">获取更多Mock数据</a>
+                        <a class="x-xdemo" href="/options/index.html?query=数据Mock工具" target="_blank" class="fh-tip-link" @click="jumpToMockDataTool($event)">获取更多Mock数据</a>
 
 
                         <span id="layoutBar">
                         <span id="layoutBar">
                             <button id="btnLeftRight" ref="btnLeftRight" class="selected" @click="changeLayout('left-right')">左右布局</button><button id="btnUpDown" ref="btnUpDown" @click="changeLayout('up-down')">上下布局</button>
                             <button id="btnLeftRight" ref="btnLeftRight" class="selected" @click="changeLayout('left-right')">左右布局</button><button id="btnUpDown" ref="btnUpDown" @click="changeLayout('up-down')">上下布局</button>

+ 20 - 0
apps/json-format/index.js

@@ -716,6 +716,26 @@ new Vue({
             }
             }
             
             
             return 'jsonpath_' + filename;
             return 'jsonpath_' + filename;
+        },
+
+        jumpToMockDataTool: function(event) {
+            event.preventDefault();
+            // 1. 先判断mock-data工具是否已安装
+            // 方案:直接读取chrome.storage.local,判断DYNAMIC_TOOL:mock-data是否存在
+            if (typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local) {
+                chrome.storage.local.get('DYNAMIC_TOOL:mock-data', result => {
+                    if (result && result['DYNAMIC_TOOL:mock-data']) {
+                        // 已安装,直接打开mock-data工具
+                        window.open('/mock-data/index.html', '_blank');
+                    } else {
+                        // 未安装,跳转到原href
+                        window.open('/options/index.html?query=数据Mock工具', '_blank');
+                    }
+                });
+            } else {
+                // 兜底:如果无法访问chrome.storage,直接跳原href
+                window.open('/options/index.html?query=数据Mock工具', '_blank');
+            }
         }
         }
     }
     }
 });
 });