tools.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view>
  3. <subTitleBar
  4. :isOpen="isShowSetting"
  5. @click="changeStatus('isShowSetting')"
  6. title="DevTools扩展配置项"
  7. />
  8. <template v-if="isShowSetting">
  9. <!-- #ifdef APP-PLUS || H5 -->
  10. <view class="settingItem">
  11. <view class="settingHead">
  12. <text class="settingTitle">页面自动注入Eruda调试工具</text>
  13. <text class="settingSubtitle">(强大的节点选择等工具;重启APP后生效)</text>
  14. </view>
  15. <switch
  16. :checked="isInjectEruda"
  17. @change="switchChange($event, 'isInjectEruda')"
  18. color="#ff2d55"
  19. />
  20. </view>
  21. <view class="settingItem">
  22. <view class="settingHead">
  23. <text class="settingTitle">页面自动注入vConsole调试工具</text>
  24. <text class="settingSubtitle">(腾讯开源的h5调试工具;重启APP后生效)</text>
  25. </view>
  26. <switch
  27. :checked="isInjectVConsole"
  28. @change="switchChange($event, 'isInjectVConsole')"
  29. color="#ff2d55"
  30. />
  31. </view>
  32. <!-- #endif -->
  33. <!-- #ifdef MP-WEIXIN -->
  34. <view class="settingItem">
  35. <view class="settingHead">
  36. <text class="settingTitle">小程序VConsole开关</text>
  37. <text class="settingSubtitle">设置是否打开调试开关。此开关对正式版也能生效。</text>
  38. </view>
  39. <switch
  40. :checked="isOpenMpDevTag"
  41. @change="switchChange($event, 'isOpenMpDevTag')"
  42. color="#ff2d55"
  43. />
  44. </view>
  45. <!-- #endif -->
  46. </template>
  47. <subTitleBar
  48. :isOpen="isShowBtnPanel"
  49. @click="changeStatus('isShowBtnPanel')"
  50. title="常用工具"
  51. />
  52. <view
  53. v-if="isShowBtnPanel"
  54. class="btnPanel"
  55. >
  56. <!-- #ifdef APP-PLUS || H5 -->
  57. <view
  58. class="btnItem btn-def"
  59. @click="restart"
  60. >
  61. <text class="btnText">重启APP</text>
  62. </view>
  63. <!-- #endif -->
  64. <view
  65. class="btnItem btn-def"
  66. @click="goPage"
  67. >
  68. <text class="btnText">跳转指定页面</text>
  69. </view>
  70. <view
  71. class="btnItem btn-def"
  72. @click="$emit('goOpenRequest')"
  73. >
  74. <text class="btnText">发起网络请求</text>
  75. </view>
  76. <view
  77. class="btnItem btn-def"
  78. @click="delLocalStorage"
  79. >
  80. <text class="btnText">清空localStorage缓存</text>
  81. </view>
  82. </view>
  83. <subTitleBar
  84. :isOpen="isShowDiyTools"
  85. @click="changeStatus('isShowDiyTools')"
  86. title="自定义Tools"
  87. />
  88. <tools
  89. v-if="isShowDiyTools"
  90. ref="tools"
  91. />
  92. </view>
  93. </template>
  94. <script>
  95. import tools from "../../../tools.vue";
  96. import subTitleBar from "../ui/subTitleBar.vue";
  97. export default {
  98. components: {
  99. tools,
  100. subTitleBar,
  101. },
  102. data() {
  103. return {
  104. /**
  105. * 是否显示系统工具栏
  106. */
  107. isShowSetting: false,
  108. /**
  109. * 是否自动注入Eruda
  110. */
  111. isInjectEruda: uni.getStorageSync("devTools_isInjectEruda") == "yes",
  112. /**
  113. * 是否自动注入vConsole
  114. */
  115. isInjectVConsole: uni.getStorageSync("devTools_isInjectVConsole") == "yes",
  116. /**
  117. * 是否显示 用户自定义tools
  118. */
  119. isShowDiyTools: true,
  120. /**
  121. * 是否打开小程序调试工具
  122. */
  123. isOpenMpDevTag: uni.getStorageSync("devTools_isOpenMpDevTag") == "yes",
  124. /**
  125. * 常用工具栏开关
  126. */
  127. isShowBtnPanel: true,
  128. };
  129. },
  130. methods: {
  131. /**
  132. * 更改选中状态
  133. */
  134. changeStatus(key) {
  135. this[key] = !this[key];
  136. },
  137. /**
  138. * 开关选择器改变事件
  139. */
  140. switchChange(e, key) {
  141. let status = e.detail.value;
  142. this[key] = status;
  143. uni.setStorageSync("devTools_" + key, status ? "yes" : "no");
  144. if (key == "isOpenMpDevTag") {
  145. wx.setEnableDebug({
  146. enableDebug: status,
  147. });
  148. }
  149. },
  150. /**
  151. * 重启APP
  152. */
  153. restart() {
  154. // #ifdef APP-PLUS
  155. plus.runtime.restart();
  156. // #endif
  157. // #ifdef H5
  158. location.href = "/";
  159. // #endif
  160. },
  161. /**
  162. * 跳转指定页面
  163. */
  164. goPage() {
  165. uni.$emit("devTools_showRouteDialog");
  166. },
  167. /**
  168. * 清空LocalStorage
  169. */
  170. delLocalStorage() {
  171. uni.showModal({
  172. title: "操作确认",
  173. content: "是否确认清空LocalStorage缓存?",
  174. success(res) {
  175. if (res.confirm) {
  176. // #ifdef APP-PLUS
  177. let keys = plus.storage.getAllKeys();
  178. for (let i = 0; i < keys.length; i++) {
  179. const key = String(keys[i]);
  180. if (key.indexOf("devTools_") == 0) {
  181. continue;
  182. }
  183. uni.removeStorageSync(key);
  184. }
  185. // #endif
  186. // #ifdef H5
  187. for (let i = 0; i < localStorage.length; i++) {
  188. let key = String(localStorage.key(i));
  189. if (key.indexOf("devTools_") == 0) {
  190. continue;
  191. }
  192. setTimeout(() => {
  193. localStorage.removeItem(key);
  194. }, i * 2 + 1);
  195. }
  196. // #endif
  197. // #ifdef MP
  198. let keyList = devCache.get("storage");
  199. if (!keyList) keyList = [];
  200. for (let i = 0; i < keyList.length; i++) {
  201. const key = keyList[i];
  202. if (key.indexOf("devTools_") == 0) {
  203. continue;
  204. }
  205. uni.removeStorageSync(key);
  206. }
  207. // #endif
  208. uni.showToast({
  209. icon: "success",
  210. title: "清空成功!",
  211. });
  212. }
  213. },
  214. });
  215. },
  216. },
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. .padding-sm {
  221. padding: 20rpx;
  222. }
  223. .settingItem:active {
  224. background-color: rgba(0, 0, 0, 0.05);
  225. }
  226. .settingItem {
  227. display: flex;
  228. flex-direction: row;
  229. justify-content: space-between;
  230. align-items: center;
  231. width: 750rpx;
  232. padding: 15rpx 0;
  233. padding-right: 15rpx;
  234. .settingHead {
  235. display: flex;
  236. flex-direction: column;
  237. margin-left: 20rpx;
  238. .settingTitle {
  239. font-size: 24rpx;
  240. line-height: 28rpx;
  241. color: #333;
  242. }
  243. .settingSubtitle {
  244. margin-top: 4rpx;
  245. font-size: 20rpx;
  246. line-height: 26rpx;
  247. color: #777;
  248. }
  249. }
  250. }
  251. .btnPanel {
  252. display: flex;
  253. flex-direction: row;
  254. flex-wrap: wrap;
  255. padding-left: 20rpx;
  256. padding-right: 20rpx;
  257. padding-top: 20rpx;
  258. .btnItem {
  259. margin-right: 20rpx;
  260. margin-bottom: 20rpx;
  261. border-radius: 10rpx;
  262. /* #ifndef APP-PLUS */
  263. min-width: 120rpx;
  264. /* #endif */
  265. height: 60rpx;
  266. border: 1px solid rgba(0, 0, 0, 0.1);
  267. background-color: rgba(0, 0, 0, 0.04);
  268. display: flex;
  269. flex-direction: row;
  270. align-items: center;
  271. justify-content: center;
  272. padding: 0 15rpx;
  273. .btnText {
  274. font-size: 20rpx;
  275. line-height: 30rpx;
  276. color: #333;
  277. }
  278. }
  279. .btn-red:active {
  280. background-color: rgba(255, 45, 85, 0.5);
  281. }
  282. .btn-red {
  283. border: 1px solid rgba(255, 45, 85, 1);
  284. background-color: rgba(255, 45, 85, 1);
  285. .btnText {
  286. color: #fff;
  287. }
  288. }
  289. .btn-def:active {
  290. background-color: rgba(0, 0, 0, 0.1);
  291. }
  292. .btn-def {
  293. border: 1px solid rgba(0, 0, 0, 0.1);
  294. background-color: rgba(0, 0, 0, 0.04);
  295. .btnText {
  296. color: #333;
  297. }
  298. }
  299. }
  300. </style>