errorItem.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view
  3. class="errorItem"
  4. :class="['type-' + item.type]"
  5. @longpress.stop="errorLongpress"
  6. >
  7. <view class="content">
  8. <view
  9. v-for="(row, index) in [item.m, item.tr]"
  10. :key="index"
  11. >
  12. <template v-if="isObj(row)">
  13. <objectAnalysis
  14. :data="row"
  15. :width="610"
  16. :canLongpress="false"
  17. @onLongpress="errorLongpress"
  18. />
  19. </template>
  20. <template v-else>
  21. <view>
  22. <text class="context">{{ getText(row) }}</text>
  23. </view>
  24. </template>
  25. </view>
  26. <view class="msgBar">
  27. <text class="time">{{ item.date }}</text>
  28. <text
  29. class="logType"
  30. :class="['type-' + item.type]"
  31. >
  32. {{ getType(item.type) }}
  33. </text>
  34. <text class="page">{{ item.p }}</text>
  35. </view>
  36. </view>
  37. <view class="tools">
  38. <view
  39. class="copyBtn"
  40. @click="copyList"
  41. >
  42. <image
  43. src="@/devTools/page/static/copy.png"
  44. class="copyIcon"
  45. />
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import devCache from "../../../core/libs/devCache";
  52. import objectAnalysis from "./objectAnalysis.vue";
  53. export default {
  54. components: {
  55. objectAnalysis,
  56. },
  57. props: {
  58. /**
  59. * console单行数据
  60. */
  61. item: {
  62. type: Object,
  63. default() {
  64. return {
  65. m: "",
  66. tr: "",
  67. date: "", // 打印的日期
  68. p: "", // 打印的页面
  69. type: "", // 打印类型
  70. };
  71. },
  72. },
  73. },
  74. methods: {
  75. /**
  76. * 是否为对象类型
  77. */
  78. isObj(data) {
  79. return typeof data == "object";
  80. },
  81. /**
  82. * 获取数据文字
  83. */
  84. getText(data) {
  85. switch (typeof data) {
  86. case "string":
  87. return data;
  88. case "boolean":
  89. return data ? "true" : "false";
  90. case "undefined":
  91. return "undefined";
  92. case "function":
  93. return "js:function";
  94. case "symbol":
  95. return "js:symbol";
  96. default:
  97. return data;
  98. }
  99. },
  100. /**
  101. * 复制列表
  102. */
  103. copyList() {
  104. let that = this;
  105. uni.setClipboardData({
  106. data: JSON.stringify([that.item.m, that.item.tr]),
  107. });
  108. },
  109. /**
  110. * 获取类型
  111. */
  112. getType(type) {
  113. let t = {
  114. ve: "vue error",
  115. vw: "vue warn",
  116. oe: "App.vue onError",
  117. n: "unknown",
  118. };
  119. return t[type];
  120. },
  121. /**
  122. * 长按事件
  123. */
  124. errorLongpress() {
  125. let that = this;
  126. let menu = [
  127. {
  128. text: `复制日志信息`,
  129. click() {
  130. uni.setClipboardData({
  131. data: JSON.stringify(that.item),
  132. });
  133. },
  134. },
  135. {
  136. text: `删除此记录`,
  137. click() {
  138. uni.$emit("devTools_delError", that.item);
  139. let logs = devCache.get("errorReport");
  140. if (!logs) logs = [];
  141. let i = logs.findIndex(
  142. (x) =>
  143. x.type == that.item.type &&
  144. x.t == that.item.t &&
  145. x.m == that.item.m &&
  146. x.tr == that.item.tr &&
  147. x.p == that.item.p
  148. );
  149. if (i != -1) {
  150. logs.splice(i, 1);
  151. devCache.set("errorReport", logs);
  152. }
  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. .errorItem:active {
  172. background-color: rgba(0, 0, 0, 0.03);
  173. }
  174. .errorItem {
  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-vw {
  183. background-color: rgb(255, 251, 229);
  184. }
  185. &.type-ve {
  186. background-color: rgb(255, 240, 240);
  187. }
  188. &.type-oe {
  189. background-color: rgb(255, 240, 240);
  190. }
  191. .content {
  192. width: 670rpx;
  193. display: flex;
  194. flex-direction: column;
  195. .context {
  196. font-size: 20rpx;
  197. color: #333;
  198. line-height: 24rpx;
  199. }
  200. .msgBar {
  201. display: flex;
  202. flex-direction: row;
  203. flex-wrap: wrap;
  204. .time {
  205. font-size: 16rpx;
  206. color: #888;
  207. /* #ifndef APP-PLUS */
  208. min-width: 90rpx;
  209. /* #endif */
  210. }
  211. .page {
  212. font-size: 16rpx;
  213. color: #888;
  214. margin-left: 20rpx;
  215. lines: 1;
  216. overflow: hidden;
  217. /* #ifndef APP-PLUS */
  218. max-width: 450rpx;
  219. white-space: nowrap;
  220. /* #endif */
  221. /* #ifdef APP-PLUS */
  222. width: 450rpx;
  223. /* #endif */
  224. text-overflow: ellipsis;
  225. }
  226. .logType {
  227. margin-left: 20rpx;
  228. font-size: 16rpx;
  229. padding: 0px 6rpx;
  230. border-radius: 2px;
  231. }
  232. .type-ve {
  233. color: #fff;
  234. background-color: #fd0add;
  235. }
  236. .type-n {
  237. color: #fff;
  238. background-color: #82848a;
  239. }
  240. .type-vw {
  241. color: #fff;
  242. background-color: #ff9900;
  243. }
  244. .type-oe {
  245. color: #fff;
  246. background-color: #ff0000;
  247. }
  248. }
  249. }
  250. .tools {
  251. width: 40rpx;
  252. display: flex;
  253. flex-direction: row-reverse;
  254. margin-top: 6rpx;
  255. .copy {
  256. font-size: 20rpx;
  257. color: #333;
  258. line-height: 24rpx;
  259. }
  260. .copy:active {
  261. background-color: red;
  262. }
  263. }
  264. }
  265. .copyBtn:active {
  266. background-color: rgba(103, 194, 58, 0.6);
  267. }
  268. .copyBtn {
  269. padding: 5rpx;
  270. border-radius: 999rpx;
  271. overflow: hidden;
  272. background-color: #67c23a;
  273. .copyIcon {
  274. width: 20rpx;
  275. height: 20rpx;
  276. }
  277. }
  278. </style>