consoleItem.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view
  3. class="consoleItem"
  4. :class="['type-' + item.type]"
  5. @longpress.stop="consoleLongpress"
  6. >
  7. <view class="content">
  8. <view
  9. v-for="(row, index) in item.list"
  10. :key="index"
  11. >
  12. <template v-if="isObj(row)">
  13. <objectAnalysis
  14. :data="row"
  15. :width="610"
  16. :canLongpress="false"
  17. @onLongpress="consoleLongpress"
  18. />
  19. </template>
  20. <template v-else>
  21. <view>
  22. <text
  23. class="context"
  24. :class="[getTypeClass(row)]"
  25. >
  26. {{ getText(row) }}
  27. </text>
  28. </view>
  29. </template>
  30. </view>
  31. <view class="msgBar">
  32. <text class="time">{{ item.date }}</text>
  33. <text
  34. class="logType"
  35. :class="'type-' + item.type"
  36. >
  37. {{ item.type }}
  38. </text>
  39. <text class="page">{{ item.page }}</text>
  40. </view>
  41. </view>
  42. <view class="tools">
  43. <view
  44. class="copyBtn"
  45. @click="copyList"
  46. >
  47. <image
  48. src="@/devTools/page/static/copy.png"
  49. class="copyIcon"
  50. />
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import objectAnalysis from "./objectAnalysis.vue";
  57. export default {
  58. components: {
  59. objectAnalysis,
  60. },
  61. props: {
  62. /**
  63. * console单行数据
  64. */
  65. item: {
  66. type: Object,
  67. default() {
  68. return {
  69. list: [],
  70. date: "", // 打印的日期
  71. page: "", // 打印的页面
  72. type: "", // 打印类型
  73. };
  74. },
  75. },
  76. },
  77. methods: {
  78. /**
  79. * 是否为对象类型
  80. */
  81. isObj(data) {
  82. return typeof data == "object" && data != null && data != undefined;
  83. },
  84. /**
  85. * 获取对应的类型样式
  86. */
  87. getTypeClass(obj) {
  88. try {
  89. let type = typeof obj;
  90. if (type == "string") {
  91. if (obj.indexOf("at ") == 0) {
  92. return "t-line";
  93. } else if (obj === undefined || obj == "undefined") {
  94. return "t-undefined";
  95. } else if (obj === null || obj == "null") {
  96. return "t-null";
  97. } else if (obj == "true" || obj == "false") {
  98. return "t-boolean";
  99. } else if (Number.isFinite(Number(obj))) {
  100. return "t-number";
  101. }
  102. }
  103. return "t-" + type;
  104. } catch (error) {}
  105. return "t-string";
  106. },
  107. /**
  108. * 获取数据文字
  109. */
  110. getText(data) {
  111. switch (typeof data) {
  112. case "string":
  113. // return data.replace(/\n/g, "");
  114. return data;
  115. case "boolean":
  116. return data ? "true" : "false";
  117. case "undefined":
  118. return "undefined";
  119. case "function":
  120. return "js:function";
  121. case "symbol":
  122. return "js:symbol";
  123. default:
  124. return data;
  125. }
  126. },
  127. /**
  128. * 复制列表
  129. */
  130. copyList() {
  131. uni.setClipboardData({
  132. data: JSON.stringify(this.item.list),
  133. });
  134. },
  135. /**
  136. * 长按事件
  137. */
  138. consoleLongpress() {
  139. let that = this;
  140. let menu = [
  141. {
  142. text: `复制日志信息`,
  143. click() {
  144. uni.setClipboardData({
  145. data: JSON.stringify(that.item),
  146. });
  147. },
  148. },
  149. {
  150. text: `删除此记录`,
  151. click() {
  152. uni.$emit("devTools_delConsoleItem", that.item);
  153. uni.showToast({
  154. title: "删除成功!",
  155. icon: "success",
  156. });
  157. },
  158. },
  159. ];
  160. uni.showActionSheet({
  161. itemList: menu.map((x) => x.text),
  162. success({ tapIndex }) {
  163. menu[tapIndex].click();
  164. },
  165. });
  166. },
  167. },
  168. };
  169. </script>
  170. <style lang="scss" scoped>
  171. .consoleItem:active {
  172. background-color: rgba(0, 0, 0, 0.03);
  173. }
  174. .consoleItem {
  175. display: flex;
  176. flex-direction: row;
  177. align-items: flex-start;
  178. justify-content: space-between;
  179. width: 750rpx;
  180. padding: 10rpx 20rpx;
  181. border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  182. &.type-warn {
  183. background-color: rgb(255, 251, 229);
  184. }
  185. &.type-error {
  186. background-color: rgb(255, 240, 240);
  187. }
  188. &.type-info {
  189. background-color: rgba(0, 0, 0, 0.02);
  190. }
  191. .content {
  192. width: 610rpx;
  193. display: flex;
  194. flex-direction: column;
  195. .context {
  196. font-size: 20rpx;
  197. color: #333;
  198. line-height: 24rpx;
  199. &.t-number {
  200. color: rgb(8, 66, 160);
  201. }
  202. &.t-boolean {
  203. color: rgb(133, 2, 255);
  204. }
  205. &.t-string {
  206. color: #333;
  207. }
  208. &.t-undefined {
  209. color: rgba(0, 0, 0, 0.2);
  210. }
  211. &.t-null {
  212. color: rgba(0, 0, 0, 0.2);
  213. }
  214. &.t-line {
  215. color: rgba(0, 0, 0, 0.5);
  216. }
  217. }
  218. .msgBar {
  219. display: flex;
  220. flex-direction: row;
  221. margin-top: 4rpx;
  222. .time {
  223. font-size: 16rpx;
  224. color: #888;
  225. /* #ifndef APP-PLUS */
  226. min-width: 90rpx;
  227. /* #endif */
  228. }
  229. .page {
  230. font-size: 16rpx;
  231. color: #888;
  232. margin-left: 20rpx;
  233. }
  234. .logType {
  235. margin-left: 20rpx;
  236. font-size: 16rpx;
  237. padding: 0px 6rpx;
  238. border-radius: 2px;
  239. }
  240. .type-log {
  241. color: #fff;
  242. background-color: #a8abb3;
  243. }
  244. .type-info {
  245. color: #fff;
  246. background-color: #747474;
  247. }
  248. .type-warn {
  249. color: #fff;
  250. background-color: #ff9900;
  251. }
  252. .type-error {
  253. color: #fff;
  254. background-color: #fa3534;
  255. }
  256. }
  257. }
  258. .tools {
  259. width: 100rpx;
  260. display: flex;
  261. flex-direction: row-reverse;
  262. margin-top: 6rpx;
  263. .copy {
  264. font-size: 20rpx;
  265. color: #333;
  266. line-height: 24rpx;
  267. }
  268. .copy:active {
  269. background-color: red;
  270. }
  271. }
  272. }
  273. .copyBtn:active {
  274. background-color: rgba(103, 194, 58, 0.6);
  275. }
  276. .copyBtn {
  277. padding: 5rpx;
  278. border-radius: 999rpx;
  279. overflow: hidden;
  280. background-color: #67c23a;
  281. .copyIcon {
  282. width: 20rpx;
  283. height: 20rpx;
  284. }
  285. }
  286. </style>