routeDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view>
  3. <view
  4. class="routeDialogMask"
  5. v-if="isShow"
  6. :style="{
  7. height: height + 'px',
  8. }"
  9. @click.stop
  10. >
  11. <view
  12. class="routeDialog"
  13. @click.stop
  14. >
  15. <view>
  16. <text class="title">跳转至指定页面</text>
  17. </view>
  18. <textarea
  19. v-model="path"
  20. type="text"
  21. placeholder="请输入..."
  22. class="textarea"
  23. />
  24. <view class="btnGroup">
  25. <view
  26. class="btnItem left"
  27. @click="hide"
  28. >
  29. <text class="btnText">取消</text>
  30. </view>
  31. <view
  32. class="btnItem right"
  33. @click="goPath"
  34. >
  35. <text class="btnText">跳转</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. /**
  47. * 是否展示
  48. */
  49. isShow: false,
  50. /**
  51. * 输入框的值
  52. */
  53. path: "",
  54. /**
  55. * 屏幕高度
  56. */
  57. height: uni.getSystemInfoSync().windowHeight,
  58. };
  59. },
  60. mounted() {
  61. let that = this;
  62. /**
  63. * 使用uni.$on打开弹窗
  64. */
  65. uni.$on("devTools_showRouteDialog", (path) => {
  66. that.path = path ? path : "";
  67. that.isShow = true;
  68. });
  69. },
  70. beforeDestroy() {
  71. uni.$off("devTools_showRouteDialog");
  72. },
  73. methods: {
  74. /**
  75. * 关闭弹窗
  76. */
  77. hide() {
  78. this.isShow = false;
  79. },
  80. /**
  81. * 执行跳转
  82. */
  83. goPath() {
  84. let that = this;
  85. let path = String(that.path);
  86. path = path.replace(/[\r\n\s]+/g, "");
  87. if (path.substring(0, 1) !== "/") {
  88. return uni.showToast({
  89. title: "页面路径需以“/”开头!",
  90. icon: "none",
  91. });
  92. }
  93. if (path.length < 2) {
  94. return uni.showToast({
  95. title: "请输入正确的路径!",
  96. icon: "none",
  97. });
  98. }
  99. uni.navigateTo({
  100. url: path,
  101. });
  102. },
  103. },
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. .routeDialogMask {
  108. display: flex;
  109. flex-direction: column;
  110. align-items: center;
  111. justify-content: center;
  112. background-color: rgba(0, 0, 0, 0.3);
  113. width: 750rpx;
  114. flex: 1;
  115. /* #ifndef APP-PLUS */
  116. height: 100vh;
  117. backdrop-filter: blur(1px);
  118. /* #endif */
  119. position: fixed;
  120. left: 0;
  121. top: 0;
  122. z-index: 999;
  123. .routeDialog {
  124. display: flex;
  125. flex-direction: column;
  126. align-items: center;
  127. justify-content: center;
  128. width: 690rpx;
  129. background-color: #fff;
  130. border-radius: 20rpx;
  131. padding: 20rpx;
  132. .title {
  133. font-size: 28rpx;
  134. line-height: 28rpx;
  135. color: #333;
  136. /* #ifndef APP-PLUS */
  137. word-wrap: break-word;
  138. max-width: 600rpx;
  139. /* #endif */
  140. /* #ifdef APP-PLUS */
  141. width: 600rpx;
  142. /* #endif */
  143. }
  144. .textarea {
  145. margin-top: 20rpx;
  146. margin-bottom: 20rpx;
  147. width: 640rpx;
  148. /* #ifndef APP-PLUS */
  149. min-height: 200rpx;
  150. max-height: 750rpx;
  151. /* #endif */
  152. background-color: rgba(0, 0, 0, 0.02);
  153. padding: 10rpx;
  154. }
  155. .btnGroup {
  156. display: flex;
  157. flex-direction: row;
  158. width: 640rpx;
  159. justify-content: space-between;
  160. .btnItem {
  161. height: 64rpx;
  162. border-radius: 10rpx;
  163. display: flex;
  164. flex-direction: row;
  165. align-items: center;
  166. justify-content: center;
  167. .btnText {
  168. font-size: 24rpx;
  169. color: #fff;
  170. }
  171. &.left {
  172. width: 160rpx;
  173. background-color: #8799a3;
  174. }
  175. &.right {
  176. width: 450rpx;
  177. background-color: #3cbb45;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. </style>