Table.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="table-container">
  3. <v-card elevation="0">
  4. <!-- 表格上功能区 -->
  5. <v-card-title>
  6. <v-container id="dataTableHeader">
  7. <v-row>
  8. <v-col cols="4">
  9. {{ page.name }}
  10. </v-col>
  11. <v-col cols="8">
  12. <v-text-field hide-details single-line label="Local Search" append-icon="mdi-magnify" v-model="table.search"/>
  13. </v-col>
  14. </v-row>
  15. </v-container>
  16. </v-card-title>
  17. <!-- 顶部分页 -->
  18. <div class="mt-2">
  19. <v-row>
  20. <v-col cols="2"></v-col>
  21. <v-col cols="2">
  22. <v-text-field required type="number" label="page" v-model="tempPage" @change="inputPageNum" />
  23. </v-col>
  24. <v-col cols="4">
  25. <v-pagination color="teal" :disabled="table.loading" :length="99" v-model="table.pageNum" @input="generateTableDataAgain"></v-pagination>
  26. </v-col>
  27. </v-row>
  28. </div>
  29. <!-- 表格主体 -->
  30. <v-data-table calculate-widths multi-sort hide-default-footer
  31. :group-by="table.groupBy" :group-desc="table.groupDesc"
  32. :headers="table.headers" :items="table.data" :search="table.search" :loading="table.loading"
  33. :items-per-page="table.pageSize"
  34. :sort-by="table.sortBy" :sort-desc="table.sortDesc">
  35. <!-- 操作区 -->
  36. <template v-slot:item.option="{ item }">
  37. <div>
  38. <v-row>
  39. <v-col cols="5">
  40. <v-btn icon elevation="0" color="red" large @click="deleteByHash(item.hash, item)">
  41. <v-icon>mdi-delete-forever-outline</v-icon>
  42. </v-btn>
  43. </v-col>
  44. </v-row>
  45. </div>
  46. </template>
  47. <!-- Block -->
  48. <template v-slot:item.block="{ item }">
  49. <div>
  50. {{ item.block }}
  51. </div>
  52. </template>
  53. <!-- Hash -->
  54. <template v-slot:item.hash="{ item }">
  55. <v-btn v-if="item.hash.indexOf('0x') !== -1" outlined text target="_blank" @click="httpKit.jumpToExplorer(item.hash, 'tx')">
  56. {{ hashKit.head5(item.hash) + '..' }}
  57. </v-btn>
  58. <v-chip v-else label target="_blank">
  59. {{ hashKit.head5(item.hash) + '..' }}
  60. </v-chip>
  61. </template>
  62. <!-- From -->
  63. <template v-slot:item.from="{ item }">
  64. <v-chip label color="green lighten-3" target="_blank" @click="httpKit.jumpToExplorer(item.from)">
  65. {{ hashKit.headAndEnd2(item.from) }}
  66. </v-chip>
  67. </template>
  68. <!-- to -->
  69. <template v-slot:item.to="{ item }">
  70. <v-chip v-if="!item.toName" label color="indigo lighten-4" @click="httpKit.jumpToExplorer(item.to)">
  71. {{ hashKit.headAndEnd2(item.to) }}
  72. </v-chip>
  73. <v-chip v-else label color="indigo lighten-4" @click="httpKit.jumpToExplorer(item.to)">
  74. {{ item.toName }}
  75. </v-chip>
  76. </template>
  77. <template v-slot:item.type="{ item }">
  78. <div v-if="item.type !== undefined && item.type !== ''">
  79. {{ item.type }}
  80. </div>
  81. <div v-else>
  82. [type]
  83. </div>
  84. </template>
  85. <template v-slot:item.index="{ item }">
  86. <div v-if="item.index !== undefined">
  87. {{ item.index }}
  88. </div>
  89. <div v-else>
  90. [index]
  91. </div>
  92. </template>
  93. <template v-slot:item.status="{ item }">
  94. <div v-if="item.state !== undefined">
  95. {{ item.status }}
  96. </div>
  97. <div v-else>
  98. [status]
  99. </div>
  100. </template>
  101. <template v-slot:item.ping="{ item }">
  102. <div v-if="item.ping !== undefined">
  103. {{ item.ping }}
  104. </div>
  105. <div v-else>
  106. [ping]
  107. </div>
  108. </template>
  109. <template v-slot:item.isMev="{ item }">
  110. <BooleanViewer :value="item.isMev"></BooleanViewer>
  111. </template>
  112. <template v-slot:item.isBot="{ item }">
  113. <BooleanViewer :value="item.isBot"></BooleanViewer>
  114. </template>
  115. <template v-slot:item.maybeBot="{ item }">
  116. <BooleanViewer :value="item.maybeBot"></BooleanViewer>
  117. </template>
  118. <template v-slot:item.timestamp="{ item }">
  119. {{ formatTimeBySixBitTimestamp(item.timestamp) }}
  120. </template>
  121. <template v-slot:item.comment="{ item }">
  122. <div v-if="item.comment">
  123. <span class="memo-span">{{ item.comment }}</span>
  124. </div>
  125. <div v-else>
  126. [comment]
  127. </div>
  128. </template>
  129. <!--tradeInfo-->
  130. <template v-slot:item.transferList="{ item }">
  131. <div v-if="page.name === 'Pending Page'">
  132. <div class="tradeInfoBtn" @click="showTradeInfo(item)">
  133. <v-chip v-for="tokenAddress in item.tokenAddressList" :key='tokenAddress'
  134. :color="item.tokenMap[tokenAddress] ? hashKit.generateColorByHash(tokenAddress) : undefined" class="tokenChip">
  135. {{ item.tokenMap[tokenAddress] ? item.tokenMap[tokenAddress] : '**' + hashKit.headAndEnd2(tokenAddress) }}
  136. </v-chip>
  137. </div>
  138. </div>
  139. <div v-else>
  140. <TradeInfo :item="item"></TradeInfo>
  141. </div>
  142. </template>
  143. </v-data-table>
  144. <!-- 底部分页 -->
  145. <div class="mt-2">
  146. <v-row>
  147. <v-col cols="2"></v-col>
  148. <v-col cols="2">
  149. <v-text-field type="number" required label="page" v-model="tempPage" @change="inputPageNum" />
  150. </v-col>
  151. <v-col cols="4">
  152. <v-pagination :disabled="table.loading" :length="99" v-model="table.pageNum" @input="generateTableDataAgain"></v-pagination>
  153. </v-col>
  154. </v-row>
  155. </div>
  156. </v-card>
  157. <v-dialog v-model="dialog.visible" max-width="800">
  158. <v-card>
  159. <v-card-title>交易详情</v-card-title>
  160. <v-card-text><TradeInfo :item="dialog.data"></TradeInfo></v-card-text>
  161. <v-card-actions>
  162. <v-spacer></v-spacer>
  163. <v-btn
  164. color="primary"
  165. text
  166. @click="dialog.visible = false"
  167. >
  168. 我知道了
  169. </v-btn>
  170. </v-card-actions>
  171. </v-card>
  172. </v-dialog>
  173. </div>
  174. </template>
  175. <script>
  176. import TradeInfo from '@/components/viewer/table/TradeInfoDetails'
  177. import BooleanViewer from '@/components/viewer/table/BooleanViewer'
  178. import HashKit from '@/plugins/kit/HashKit'
  179. import HttpKit from '@/plugins/kit/HttpKit'
  180. import TimeKit from '@/plugins/kit/TimeKit'
  181. export default {
  182. name: 'Table',
  183. components: {BooleanViewer, TradeInfo},
  184. props: ['query', 'page', 'table'],
  185. inject: ['generateTableData'],
  186. data: () => ({
  187. hashKit: HashKit,
  188. httpKit: HttpKit,
  189. timeKit: TimeKit,
  190. dialog: {
  191. data: [],
  192. visible: false
  193. },
  194. tempPage: 1
  195. }),
  196. methods: {
  197. async deleteByHash(hash_code, item) {
  198. if (confirm('要删吗?\n' + hash_code)) {
  199. console.log(JSON.stringify(item))
  200. this.$msgkit.warning('还没有做,别急啊')
  201. // const rst = await EthMev.deleteByHash(hash_code)
  202. //
  203. // if (rst.data.state) {
  204. // this.$msgkit.success(rst.data.msg)
  205. //
  206. // await this.pullData()
  207. // } else {
  208. // this.$msgkit.error(rst.data.msg)
  209. // }
  210. }
  211. },
  212. showTradeInfo(item) {
  213. this.dialog.data = item
  214. this.dialog.visible = true
  215. },
  216. async inputPageNum() {
  217. console.log(typeof this.tempPage, parseInt(this.tempPage))
  218. this.table.pageNum = parseInt(this.tempPage)
  219. await this.generateTableDataAgain()
  220. },
  221. async generateTableDataAgain() {
  222. this.tempPage = this.table.pageNum
  223. this.table.data = []
  224. await this.generateTableData()
  225. },
  226. formatTimeBySixBitTimestamp(sixBitTimestamp) {
  227. let lastThreeBit = (sixBitTimestamp + '').slice(-3)
  228. return this.timeKit.getTime(sixBitTimestamp) + lastThreeBit
  229. }
  230. }
  231. }
  232. </script>
  233. <style scoped>
  234. .table-container {
  235. width: 100%;
  236. }
  237. #dataTableHeader {
  238. max-width: none;
  239. }
  240. .tokenChip {
  241. margin-top: 5px;
  242. margin-left: 5px;
  243. margin-bottom: 5px;
  244. }
  245. .tradeInfoBtn {
  246. padding: 15px !important;
  247. border: grey 2px solid;
  248. }
  249. .tradeInfoBtn:hover {
  250. background: beige;
  251. }
  252. .memo-span {
  253. width: 200px;
  254. display:block;
  255. padding: 10px;
  256. }
  257. </style>