jsRunnerItem.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="jsRunnerItem">
  3. <view class="codeInput">
  4. <image
  5. src="@/devTools/page/static/fold.png"
  6. class="fold-left"
  7. />
  8. <view class="codeView">
  9. <text class="codeText">{{ item.code }}</text>
  10. </view>
  11. </view>
  12. <view class="codeResult">
  13. <image
  14. src="@/devTools/page/static/fold.png"
  15. class="fold-right"
  16. />
  17. <view class="codeResultView">
  18. <template v-if="item.isEnd">
  19. <template v-if="isObj(item.result)">
  20. <objectAnalysis
  21. :data="item.result"
  22. :showObjProto="true"
  23. :width="610"
  24. :canLongpress="false"
  25. />
  26. </template>
  27. <template v-else>
  28. <view>
  29. <text
  30. class="context"
  31. :class="[getTypeClass(item.result)]"
  32. selectable
  33. >
  34. {{ getText(item.result) }}
  35. </text>
  36. </view>
  37. </template>
  38. </template>
  39. <text
  40. v-else
  41. class="loadingOutput"
  42. >
  43. ...
  44. </text>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import objectAnalysis from "./objectAnalysis.vue";
  51. export default {
  52. components: {
  53. objectAnalysis,
  54. },
  55. props: {
  56. /**
  57. * 单行数据
  58. */
  59. item: {
  60. type: Object,
  61. default() {
  62. return {
  63. id: "",
  64. code: "",
  65. result: "",
  66. isEnd: false,
  67. };
  68. },
  69. },
  70. },
  71. methods: {
  72. /**
  73. * 是否为对象类型
  74. */
  75. isObj(data) {
  76. return typeof data == "object" && data != null && data != undefined;
  77. },
  78. /**
  79. * 获取对应的类型样式
  80. */
  81. getTypeClass(obj) {
  82. try {
  83. let type = typeof obj;
  84. if (type == "string") {
  85. if (obj.indexOf("at ") == 0) {
  86. return "t-line";
  87. } else if (obj === undefined || obj == "undefined") {
  88. return "t-undefined";
  89. } else if (obj === null || obj == "null") {
  90. return "t-null";
  91. } else if (obj == "true" || obj == "false") {
  92. return "t-boolean";
  93. } else if (Number.isFinite(Number(obj))) {
  94. return "t-number";
  95. }
  96. } else if (type == "function") {
  97. return "t-function";
  98. }
  99. return "t-" + type;
  100. } catch (error) {}
  101. return "t-string";
  102. },
  103. /**
  104. * 获取数据文字
  105. */
  106. getText(data) {
  107. if (data === null) {
  108. return "null";
  109. }
  110. switch (typeof data) {
  111. case "string":
  112. // return data.replace(/\n/g, "");
  113. return data;
  114. case "boolean":
  115. return data ? "true" : "false";
  116. case "undefined":
  117. return "undefined";
  118. case "function":
  119. return data.toString();
  120. case "symbol":
  121. return "js:symbol";
  122. default:
  123. return data;
  124. }
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .jsRunnerItem:active {
  131. // background-color: rgba(0, 0, 0, 0.03);
  132. }
  133. .jsRunnerItem {
  134. display: flex;
  135. flex-direction: column;
  136. width: 750rpx;
  137. padding: 10rpx 20rpx;
  138. border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  139. .codeInput {
  140. width: 710rpx;
  141. display: flex;
  142. flex-direction: row;
  143. margin-bottom: 10rpx;
  144. .codeView {
  145. margin-left: 10rpx;
  146. width: 670rpx;
  147. display: flex;
  148. flex-direction: column;
  149. .codeText {
  150. font-size: 20rpx;
  151. color: #777;
  152. line-height: 26rpx;
  153. }
  154. }
  155. }
  156. .codeResult {
  157. width: 710rpx;
  158. display: flex;
  159. flex-direction: row;
  160. border-top: 1px solid rgba(0, 0, 0, 0.02);
  161. padding-top: 10rpx;
  162. .codeResultView {
  163. margin-left: 10rpx;
  164. width: 670rpx;
  165. display: flex;
  166. flex-direction: column;
  167. .loadingOutput {
  168. font-size: 20rpx;
  169. color: rgba(0, 0, 0, 0.1);
  170. line-height: 26rpx;
  171. }
  172. .context {
  173. font-size: 20rpx;
  174. color: rgb(227, 54, 46);
  175. line-height: 26rpx;
  176. &.t-number {
  177. color: rgb(8, 66, 160);
  178. }
  179. &.t-boolean {
  180. color: rgb(133, 2, 255);
  181. }
  182. &.t-string {
  183. color: rgb(227, 54, 46);
  184. }
  185. &.t-undefined {
  186. color: rgba(0, 0, 0, 0.2);
  187. }
  188. &.t-null {
  189. color: rgba(0, 0, 0, 0.2);
  190. }
  191. &.t-line {
  192. color: rgba(0, 0, 0, 0.5);
  193. }
  194. &.t-function {
  195. color: rgb(121, 38, 117);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. .fold-left {
  202. transform: rotate(90deg);
  203. width: 24rpx;
  204. height: 24rpx;
  205. }
  206. .fold-right {
  207. transform: rotate(-90deg);
  208. width: 24rpx;
  209. height: 24rpx;
  210. }
  211. </style>