Table.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 + ' block: ' + query.tx.block }}
  10. </v-col>
  11. <v-col cols="8">
  12. <v-text-field hide-details single-line label="Local Search" append-icon="mdi-magnify"
  13. v-model="table.search"/>
  14. </v-col>
  15. </v-row>
  16. </v-container>
  17. </v-card-title>
  18. <!-- 顶部分页 -->
  19. <div class="mt-2">
  20. <v-row>
  21. <v-col cols="2"></v-col>
  22. <v-col cols="2">
  23. <v-text-field required type="number" label="page" v-model="tempPage" @change="inputPageNum"/>
  24. </v-col>
  25. <v-col cols="4">
  26. <v-pagination color="teal" :disabled="table.loading" :length="table.pageLength" v-model="table.pageNum"
  27. @input="generateTableDataAgain"></v-pagination>
  28. </v-col>
  29. </v-row>
  30. </div>
  31. <!-- 表格主体 -->
  32. <v-data-table calculate-widths multi-sort hide-default-footer
  33. class="history-table"
  34. @current-items="currentItems"
  35. @input="input"
  36. @item-selected="itemSelected"
  37. @item-expanded="itemExpanded"
  38. @page-count="pageCount"
  39. @pagination="pagination"
  40. @toggle-select-all="toggleSelectAll"
  41. @update:expanded="updateExpanded"
  42. @update:group-by="updateGroupBy"
  43. @update:group-desc="updateGroupEesc"
  44. @update:items-per-page="updateItemsPerPage"
  45. @update:multi-sort="updateMultiSort"
  46. @update:must-sort="updateMustSort"
  47. @update:options="updateOptions"
  48. @update:page="updatePage"
  49. @update:sort-by="updateSortBy"
  50. @update:sort-desc="updateSortDesc"
  51. @toggle="toggle"
  52. @dblclick:row="dblclickRow"
  53. :headers="table.headers" :items="table.data" :search="table.search" :loading="table.loading"
  54. :items-per-page="table.pageSize"
  55. :sort-by="table.sortBy" :sort-desc="table.sortDesc">
  56. <!-- 操作区 -->
  57. <template v-slot:item.option="{ item }">
  58. <div>
  59. <v-row>
  60. <v-col cols="5">
  61. <v-btn large icon elevation="0" color="primary" @click="editItem(item)">
  62. <v-icon>mdi-table-edit</v-icon>
  63. </v-btn>
  64. </v-col>
  65. </v-row>
  66. </div>
  67. </template>
  68. <!-- block -->
  69. <template v-slot:item.block="{ item }">
  70. <div>
  71. {{ item.block }}
  72. </div>
  73. </template>
  74. <!-- Hash -->
  75. <template v-slot:item.hash="{ item }">
  76. <v-btn v-if="item.hash.indexOf('0x') !== -1" outlined text target="_blank"
  77. @click="httpKit.jumpToExplorer(item.hash, 'tx')">
  78. {{ hashKit.head5(item.hash) + '..' }}
  79. </v-btn>
  80. <v-chip v-else label target="_blank">
  81. {{ hashKit.head5(item.hash) + '..' }}
  82. </v-chip>
  83. </template>
  84. <!-- From -->
  85. <template v-slot:item.from="{ item }">
  86. <v-chip v-if="!item.fromName" label color="indigo lighten-3" @click="httpKit.jumpToExplorer(item.to)">
  87. {{ hashKit.headAndEnd2(item.from) }}
  88. </v-chip>
  89. <v-chip v-else label color="green lighten-3" target="_blank" @click="httpKit.jumpToExplorer(item.from)">
  90. {{ item.fromName }}
  91. </v-chip>
  92. </template>
  93. <!-- to -->
  94. <template v-slot:item.to="{ item }">
  95. <v-chip v-if="!item.toName" label color="indigo lighten-4" @click="httpKit.jumpToExplorer(item.to)">
  96. {{ hashKit.headAndEnd2(item.to) }}
  97. </v-chip>
  98. <v-chip v-else label color="indigo lighten-4" @click="httpKit.jumpToExplorer(item.to)">
  99. {{ item.toName }}
  100. </v-chip>
  101. </template>
  102. <template v-slot:item.gasPrice="{ item }">
  103. <div v-if="item.gasPrice != -1 && item.gasPrice !== undefined">
  104. {{ item.gasPrice }}
  105. </div>
  106. <div v-else>
  107. [gasPrice]
  108. </div>
  109. </template>
  110. <template v-slot:item.type="{ item }">
  111. <div v-if="item.type !== '' && item.type !== undefined">
  112. {{ item.type }}
  113. </div>
  114. <div v-else>
  115. [type]
  116. </div>
  117. </template>
  118. <template v-slot:item.index="{ item }">
  119. <div v-if="item.index !== '' && item.index !== undefined">
  120. {{ item.index }}
  121. </div>
  122. <div v-else>
  123. [index]
  124. </div>
  125. </template>
  126. <template v-slot:item.status="{ item }">
  127. <div v-if="item.status !== '' && item.status !== undefined">
  128. {{ item.status }}
  129. </div>
  130. <div v-else>
  131. [status]
  132. </div>
  133. </template>
  134. <template v-slot:item.ping="{ item }">
  135. <div v-if="item.ping !== undefined">
  136. {{ item.ping }}
  137. </div>
  138. <div v-else>
  139. [ping]
  140. </div>
  141. </template>
  142. <template v-slot:item.isMev="{ item }">
  143. <BooleanViewer :value="item.isMev"></BooleanViewer>
  144. </template>
  145. <template v-slot:item.isBot="{ item }">
  146. <BooleanViewer :value="item.isBot"></BooleanViewer>
  147. </template>
  148. <template v-slot:item.maybeBot="{ item }">
  149. <BooleanViewer :value="item.maybeBot"></BooleanViewer>
  150. </template>
  151. <template v-slot:item.timestamp="{ item }">
  152. {{ formatTimeBySixBitTimestamp(item.timestamp) }}
  153. </template>
  154. <template v-slot:item.comment="{ item }">
  155. <div v-if="item.comment">
  156. <span class="memo-span">{{ item.comment }}</span>
  157. </div>
  158. <div v-else>
  159. [comment]
  160. </div>
  161. </template>
  162. <!--tradeInfo-->
  163. <template v-slot:item.transferList="{ item }">
  164. <div v-if="page.name === 'History Page'">
  165. <div class="tradeInfoBtn" @click="showTradeInfo(item)">
  166. <v-chip v-for="trade in item.transferList"
  167. label class="ma-2 tradeLabel" style="max-width: 100px;">
  168. {{
  169. (trade.tokenSymbol === undefined ? ('**' + hashKit.headAndEnd2(trade.token)) : (trade.tokenSymbol === '' ? '[no name]' : trade.tokenSymbol))
  170. }}
  171. </v-chip>
  172. </div>
  173. </div>
  174. <div v-else>
  175. <TradeInfo :item="item"></TradeInfo>
  176. </div>
  177. </template>
  178. </v-data-table>
  179. <!-- 底部分页 -->
  180. <div class="mt-2">
  181. <v-row>
  182. <v-col cols="2"></v-col>
  183. <v-col cols="2">
  184. <v-text-field type="number" required label="page" v-model="tempPage" @change="inputPageNum"/>
  185. </v-col>
  186. <v-col cols="4">
  187. <v-pagination :disabled="table.loading" :length="table.pageLength" v-model="table.pageNum"
  188. @input="generateTableDataAgain"></v-pagination>
  189. </v-col>
  190. </v-row>
  191. </div>
  192. </v-card>
  193. <!-- 展示transfer的详情 -->
  194. <v-dialog v-model="transferDetailsDialog.visible" max-width="800">
  195. <v-card elevation="0">
  196. <v-card-title>交易详情</v-card-title>
  197. <v-card-text>
  198. <TradeInfo :item="transferDetailsDialog.data"></TradeInfo>
  199. </v-card-text>
  200. <v-card-actions>
  201. <v-spacer></v-spacer>
  202. <v-btn text color="primary" @click="transferDetailsDialog.visible = false">我知道了</v-btn>
  203. </v-card-actions>
  204. </v-card>
  205. </v-dialog>
  206. <!-- 编辑框 -->
  207. <v-dialog v-model="editDialog.visible" max-width="1200">
  208. <v-card elevation="0">
  209. <v-card-title>编辑详情</v-card-title>
  210. <v-card-text>
  211. <v-row>
  212. <v-col cols="12">
  213. <v-text-field disabled label="hash" v-model="editDialog.item.hash"></v-text-field>
  214. </v-col>
  215. </v-row>
  216. <v-row>
  217. <v-col cols="12">
  218. <v-text-field label="comment" v-model="editDialog.item.comment"></v-text-field>
  219. </v-col>
  220. </v-row>
  221. <v-row>
  222. <v-col cols="6">
  223. <v-text-field disabled label="from" v-model="editDialog.item.from"></v-text-field>
  224. </v-col>
  225. <v-col cols="6">
  226. <v-text-field label="fromName" v-model="editDialog.item.fromName"></v-text-field>
  227. </v-col>
  228. </v-row>
  229. <v-row>
  230. <v-col cols="6">
  231. <v-text-field disabled label="to" v-model="editDialog.item.to"></v-text-field>
  232. </v-col>
  233. <v-col cols="6">
  234. <v-text-field label="toName" v-model="editDialog.item.toName"></v-text-field>
  235. </v-col>
  236. </v-row>
  237. </v-card-text>
  238. <v-card-actions>
  239. <v-spacer></v-spacer>
  240. <v-btn text color="primary" @click="updateAdapter">提交编辑</v-btn>
  241. </v-card-actions>
  242. </v-card>
  243. </v-dialog>
  244. </div>
  245. </template>
  246. <script>
  247. import TradeInfo from '@/components/viewer/newhistory/table/TradeInfoDetails'
  248. import BooleanViewer from '@/components/viewer/newhistory/table/BooleanViewer'
  249. import HashKit from '@/plugins/kit/HashKit'
  250. import HttpKit from '@/plugins/kit/HttpKit'
  251. import TimeKit from '@/plugins/kit/TimeKit'
  252. import AddressModel from "@/plugins/model/AddressModel";
  253. import jquery from 'jquery'
  254. export default {
  255. name: 'Table',
  256. components: {BooleanViewer, TradeInfo},
  257. props: ['query', 'page', 'table', 'tx'],
  258. inject: ['packQuery'],
  259. data: () => ({
  260. hashKit: HashKit,
  261. httpKit: HttpKit,
  262. timeKit: TimeKit,
  263. transferDetailsDialog: {
  264. data: [],
  265. visible: false
  266. },
  267. editDialog: {
  268. item: {},
  269. visible: false
  270. },
  271. tempPage: 1,
  272. addressModel: undefined,
  273. dblclickRowUrl: "https://tools.blocksec.com/tx/eth/",
  274. }),
  275. methods: {
  276. async deleteByHash(hash_code, item) {
  277. if (confirm('要删吗?\n' + hash_code)) {
  278. // console.log(JSON.stringify(item))
  279. this.$msgkit.warning('还没有做,别急啊')
  280. // const rst = await EthMev.deleteByHash(hash_code)
  281. //
  282. // if (rst.data.state) {
  283. // this.$msgkit.success(rst.data.msg)
  284. //
  285. // await this.pullData()
  286. // } else {
  287. // this.$msgkit.error(rst.data.msg)
  288. // }
  289. }
  290. },
  291. async updateAdapter() {
  292. this.createAddressModel()
  293. const updateItem = this.editDialog.item
  294. const txBaseItem = {
  295. hash: updateItem.hash,
  296. comment: updateItem.comment
  297. }
  298. const fromAddrBaseItem = {
  299. hash: updateItem.from,
  300. name: updateItem.fromName
  301. }
  302. const toAddrBaseItem = {
  303. hash: updateItem.to,
  304. name: updateItem.toName
  305. }
  306. const rst1 = await this.tx.updateTxBaseModel(txBaseItem)
  307. const rst2 = await this.addressModel.updateAddressBaseModel(fromAddrBaseItem)
  308. const rst3 = await this.addressModel.updateAddressBaseModel(toAddrBaseItem)
  309. if (rst1.state && rst2.state && rst3.state) {
  310. this.$msgkit.success('更新成功')
  311. this.editDialog.visible = false
  312. } else {
  313. this.$msgkit.error(`rst1: ${rst1.msg}, rst2: ${rst2.msg}, rst3: ${rst3.msg}`)
  314. }
  315. },
  316. showTradeInfo(item) {
  317. console.log(">>", item)
  318. this.transferDetailsDialog.data = item
  319. this.transferDetailsDialog.visible = true
  320. },
  321. async inputPageNum() {
  322. this.table.pageNum = parseInt(this.tempPage)
  323. await this.generateTableDataAgain()
  324. },
  325. async generateTableDataAgain() {
  326. this.tempPage = this.table.pageNum
  327. this.table.data = []
  328. await this.packQuery()
  329. },
  330. formatTimeBySixBitTimestamp(sixBitTimestamp) {
  331. let lastThreeBit = (sixBitTimestamp + '').slice(-3)
  332. return this.timeKit.getTime(sixBitTimestamp) + lastThreeBit
  333. },
  334. editItem(item) {
  335. this.editDialog.item = item
  336. this.editDialog.visible = true
  337. },
  338. createAddressModel() {
  339. if (!this.addressModel) this.addressModel = new AddressModel(this.tx.chainId, AddressModel.MODULES.unknown)
  340. },
  341. currentItems(val) {
  342. // console.log("currentItems:", val)
  343. },
  344. input(val) {
  345. // console.log("input:", val)
  346. },
  347. itemSelected(val) {
  348. // console.log("itemSelected:", val)
  349. },
  350. pageCount(val) {
  351. // console.log("pageCount:", val)
  352. },
  353. pagination(val) {
  354. // console.log("pagination:", val)
  355. },
  356. toggleSelectAll(val) {
  357. // console.log("toggleSelectAll:", val)
  358. },
  359. updateExpanded(val) {
  360. // console.log("updateExpanded:", val)
  361. },
  362. updateGroupBy(val) {
  363. // console.log("updateGroupBy:", val)
  364. },
  365. updateGroupEesc(val) {
  366. // console.log("updateGroupEesc:", val)
  367. },
  368. updateItemsPerPage(val) {
  369. // console.log("updateItemsPerPage:", val)
  370. },
  371. updateMultiSort(val) {
  372. // console.log("updateMultiSort:", val)
  373. },
  374. updateMustSort(val) {
  375. // console.log("updateMustSort:", val)
  376. },
  377. updateOptions(val) {
  378. // console.log("updateOptions:", val)
  379. },
  380. updatePage(val) {
  381. // console.log("updatePage:", val)
  382. },
  383. updateSortBy(val) {
  384. // console.log("updateSortBy:", val)
  385. },
  386. updateSortDesc(val) {
  387. // console.log("updateSortDesc:", val)
  388. },
  389. itemExpanded(item, val) {
  390. // console.log("itemExpanded:", item, val)
  391. },
  392. toggle(val) {
  393. // console.log("toggle:", val)
  394. },
  395. dblclickRow(event, value) {
  396. // console.log("dblclickRow:", event, value)
  397. },
  398. },
  399. async mounted() {
  400. // let vm = new Vue({
  401. // el: "td.text-start",
  402. // click: () => {
  403. // console.log('点击')
  404. // }
  405. // });
  406. // $("td.text-start").on("click",this,function (){
  407. // console.log('点击')
  408. // });
  409. }
  410. }
  411. </script>
  412. <style scoped>
  413. .table-container {
  414. width: 100%;
  415. }
  416. #dataTableHeader {
  417. max-width: none;
  418. }
  419. .tokenChip {
  420. margin-top: 5px;
  421. margin-left: 5px;
  422. margin-bottom: 5px;
  423. }
  424. .tradeInfoBtn {
  425. padding: 15px !important;
  426. border: grey 2px solid;
  427. }
  428. .tradeInfoBtn:hover {
  429. background: beige;
  430. }
  431. .memo-span {
  432. width: 200px;
  433. display: block;
  434. padding: 10px;
  435. }
  436. </style>