1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
|
<template>
<div class="page-block">
<header-cps></header-cps>
<div class="block-info-wrap">
<div class="container">
<search></search>
<div class="bui-dlist">
<div class="block-item-des">
<strong class="bui-dlist-tit">账号
<span class="space-des"></span>
</strong>
<div class="bui-dlist-det">{{account}}</div>
</div>
<div class="block-item-des">
<strong class="bui-dlist-tit">余额
<span class="space-des"></span>
</strong>
<div class="bui-dlist-det">{{balance | toCZRVal}} CZR</div>
</div>
</div>
<div class="account-content">
<h2 class="transfer-tit">交易记录</h2>
<div class="transfer-log" v-loading="loadingSwitch">
<template v-for="item in accountInfo.currentTxList">
<div v-if="item.to == accountInfo.address">
<router-link class="transfer-item plus-assets" :to="'/block/'+ item.hash">
<div class="transfer-info">
<p class="by-address">{{item.from}}</p>
<p class="transfer-time">{{item.exec_timestamp |toDate }}</p>
</div>
<div class="transfer-assets">
<div class="assets">+ {{item.amount | toCZRVal }} CZR</div>
</div>
</router-link>
</div>
<div v-if="item.from == accountInfo.address">
<router-link class="transfer-item less-assets " :to="'/block/'+ item.hash">
<div class="transfer-info">
<p class="by-address">{{item.to}}</p>
<p class="transfer-time">{{item.exec_timestamp |toDate }}</p>
</div>
<div class="transfer-assets">
<div class="assets">- {{item.amount | toCZRVal }} CZR</div>
</div>
</router-link>
</div>
</template>
<div class="pagin-wrap b-flex b-flex-justify" v-if="accountInfo.tx_list.length>=pagingSwitch.limit">
<el-button :disabled="pagingSwitch.beforeDisabled" @click="beforeList" class="before-btn">上一页</el-button>
<el-button :disabled="pagingSwitch.nextDisabled" @click="nextList" class="next-btn">下一页</el-button>
</div>
</div>
<!-- No transaction record -->
<div v-if="accountInfo.tx_list.length==0" class="no-transfer-log">
<i class="el-icon-document iconfont"></i>
<p class="no-list">暂无交易记录</p>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import HeaderCps from "@/components/Header/Header";
import Search from "@/components/Search/Search";
let self = null;
export default {
name: "Block",
components: {
HeaderCps,
Search
},
data() {
return {
account: this.$route.params.id,
balance: 0,
pagingSwitch: {
limit: 10,
beforeDisabled: true,
nextDisabled: false
},
accountInfo: {
address: this.$route.params.id,
tx_list: [],
currentTxList: []
},
transactionInfo: null,
loadingSwitch: true,
txStatus: "-",
lastBlockHash: ""
};
},
created() {
self = this;
this.initDatabase();
this.initTransactionInfo();
self.getTxList();
},
methods: {
initTransactionInfo() {
this.transactionInfo = {
hash: "", //哈希值
from: "",
to: "",
amount: "",
previous: "",
parents: "",
witness_list: "",
witness_list_block: "",
last_summary: "",
last_summary_block: "",
data: "",
exec_timestamp: "",
signature: ""
};
},
initDatabase() {
var self = this;
self.$czr.request
.accountBalance(self.account)
.then(function(data) {
return data;
})
.then(function(data) {
self.balance = data.balance;
});
},
// 列表
//get List
getTxList() {
self.$czr.request
.blockList(
self.accountInfo.address,
self.pagingSwitch.limit,
self.lastBlockHash
)
.then(function(data) {
if (data.error) {
self.$message({
message: data.error,
type: "error"
});
self.loadingSwitch = false;
return;
}
data = !!data ? data : { list: [] };
self.loadingSwitch = false;
if (data.list.length > 0) {
self.accountInfo.currentTxList = data.list;
data.list.forEach(element => {
self.accountInfo.tx_list.push(element);
});
}
//是否有下页
if (data.list.length < self.pagingSwitch.limit) {
self.pagingSwitch.nextDisabled = true;
} else {
self.pagingSwitch.nextDisabled = false;
self.lastBlockHash =
data.list[data.list.length - 1].hash; //需要拿新的HASH,准备下次请求
}
});
},
getNextList() {
/*
currentTxList最后一个hash是否 等于 tx_list 最后一个hash;
- 等于 需要获取
- 不等 从tx_list中获取
*/
var _currentTxList = self.accountInfo.currentTxList;
var currentTxListHashBlock =
_currentTxList[_currentTxList.length - 1].hash;
var _txList = self.accountInfo.tx_list;
var lastTxListHashBlock = _txList[_txList.length - 1].hash;
if (currentTxListHashBlock == lastTxListHashBlock) {
//获取
self.lastBlockHash = lastTxListHashBlock;
self.getTxList();
} else {
//不获取
//先把当前的哈希,替换为下一个hash
var startHash = currentTxListHashBlock;
var tempAry = [];
var ele;
for (var j = 0; j < _txList.length; j++) {
ele = _txList[j];
var _isSet = ele.hash == startHash;
var _isGoOn = tempAry.length < self.pagingSwitch.limit;
if (_isSet && _isGoOn) {
//如果是最后一个item,就不要循环了
if (
_txList[j].hash == _txList[_txList.length - 1].hash
) {
self.pagingSwitch.nextDisabled = true; //释放 后翻
break;
}
startHash = _txList[j + 1].hash;
tempAry.push(_txList[j + 1]);
}
}
// _txList.forEach ((ele, index) => {
// var _isSet = ele.hash == startHash;
// var _isGoOn = tempAry.length < self.pagingSwitch.limit;
// if (_isSet && _isGoOn) {
// startHash = _txList[index + 1].hash;
// tempAry.push(_txList[index + 1]);
// }
// //如果是最后一个item,就不要循环了
// if(_txList[_txList.length-1]==startHash){
// return;
// }
// });
self.loadingSwitch = false;
self.accountInfo.currentTxList = tempAry;
self.lastBlockHash = tempAry[tempAry.length - 1].hash;
}
},
getBeforeList() {
//TODO 从 tx_list 中取一些值给currentTxLList
/*
1.当前有 lastBlockHash 开始循环找
2.可以取值,并且可以继续,则取值
- 取值同时,设置l astBlockHash 为前一个Hash,如果是第一个item了,则astBlockHash 为""
= 开始 > 结束 返回
= 开始 > 中间 返回
*/
var localList = self.accountInfo.tx_list;
var targetAry = [];
if (self.lastBlockHash) {
//当前list最后数据的hashBlock 就是当前hash;这时候需要换,换成上一页最后一个hash;
var _currentTxList = self.accountInfo.currentTxList;
var currentTxListHashBlock =
_currentTxList[_currentTxList.length - 1].hash;
if (self.lastBlockHash == currentTxListHashBlock) {
//当前 lastBlockHash 在 tx_list 中的索引
var currentIndexInTxLixt = 0;
localList.forEach((ele, index) => {
if (ele.hash == self.lastBlockHash) {
currentIndexInTxLixt = index;
}
});
var currentTxLeng = self.accountInfo.currentTxList.length;
var lessNum =
self.pagingSwitch.limit > currentTxLeng
? currentTxLeng
: self.pagingSwitch.limit;
var targetIndex = currentIndexInTxLixt - lessNum;
if (targetIndex < 0) {
self.pagingSwitch.beforeDisabled = true;
self.loadingSwitch = false;
return;
}
// var targetIndex = currentIndexInTxLixt - self.pagingSwitch.limit;
self.lastBlockHash = localList[targetIndex].hash;
}
//如果有lastBlockHash
for (var i = localList.length - 1; i >= 0; i--) {
//如果当前Hash 等于 循环的哈希,开始取值
var isSet = localList[i].hash == self.lastBlockHash; //是否取值
var isGoOn = targetAry.length < self.pagingSwitch.limit; //是否继续取值
if (isSet && isGoOn) {
targetAry.unshift(localList[i]);
self.lastBlockHash = i > 0 ? localList[i - 1].hash : "";
if (i == 0) {
self.pagingSwitch.beforeDisabled = true;
}
}
//如果数据读取完毕,不需要循环
if (!isGoOn) {
break;
}
}
}
if (targetAry.length > 0) {
self.accountInfo.currentTxList = targetAry;
} else {
//不能上翻
self.pagingSwitch.beforeDisabled = true;
}
self.loadingSwitch = false;
},
nextList() {
self.loadingSwitch = true;
self.getNextList();
self.pagingSwitch.beforeDisabled = false; //释放 前翻
},
beforeList() {
self.loadingSwitch = true;
self.getBeforeList();
self.pagingSwitch.nextDisabled = false; //释放 后翻
}
},
filters: {
toCZRVal: function(val) {
let tempVal = self.$czr.utils.fromWei(val, "czr");
return tempVal; //TODO Keep 4 decimal places
},
toDate: function(val) {
if (val == "0" || !val) {
return "-";
}
let newDate = new Date();
newDate.setTime(val * 1000);
let addZero = function(val) {
return val < 10 ? "0" + val : val;
};
return (
newDate.getFullYear() +
" / " +
addZero(newDate.getMonth() + 1) +
" / " +
addZero(newDate.getDate()) +
" " +
addZero(newDate.getHours()) +
":" +
addZero(newDate.getMinutes()) +
":" +
addZero(newDate.getSeconds())
);
}
}
};
</script>
<style scoped>
.page-block {
width: 100%;
position: relative;
}
#header {
color: #fff;
background: #5a59a0;
}
.block-info-wrap {
position: relative;
width: 100%;
margin: 0 auto;
color: black;
text-align: left;
padding-top: 20px;
padding-bottom: 80px;
}
.block-item-des {
padding: 10px 0;
border-bottom: 1px dashed #f6f6f6;
}
@media (max-width: 1199px) {
.bui-dlist {
color: #3f3f3f;
font-size: 16px;
line-height: 2.4;
}
.block-item-des {
display: block;
}
.bui-dlist-tit {
display: block;
width: 100%; /* 默认值, 具体根据视觉可改 */
margin: 0;
text-align: left;
}
.bui-dlist-det {
display: block;
color: #5f5f5f;
text-align: left;
margin: 0;
table-layout: fixed;
word-break: break-all;
overflow: hidden;
}
}
@media (min-width: 1200px) {
.bui-dlist {
color: #3f3f3f;
font-size: 16px;
line-height: 2.4;
margin-top: 20px;
border-top: 1px dashed #f6f6f6;
}
.block-item-des {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.bui-dlist-tit {
float: left;
width: 20%; /* 默认值, 具体根据视觉可改 */
text-align: right;
margin: 0;
}
.bui-dlist-det {
float: left;
color: #5f5f5f;
width: 80%; /* 默认值,具体根据视觉可改 */
text-align: left;
margin: 0;
table-layout: fixed;
word-break: break-all;
overflow: hidden;
}
}
.txt-warning {
color: #e6a23c;
}
.txt-info {
color: #909399;
}
.txt-success {
color: #67c23a;
}
.txt-danger {
color: #f56c6c;
}
.bui-dlist-tit .space-des {
display: inline-block;
width: 10px;
}
/* 记录 */
.account-content {
text-align: left;
margin-top: 40px;
}
.account-content .transfer-tit {
font-size: 18px;
font-weight: 400;
}
/* Transaction Record */
.account-content .no-transfer-log {
text-align: center;
color: #9b9b9b;
}
.account-content .no-transfer-log .iconfont {
font-size: 128px;
}
.account-content .transfer-log {
padding: 22px 0;
}
.transfer-log .transfer-item {
background-color: #fff;
padding: 10px 0;
cursor: pointer;
border-bottom: 1px dashed #f0f0f0;
-webkit-user-select: none;
}
.transfer-log .transfer-item:hover {
text-decoration: none;
background-color: #f5f5f5;
}
@media (max-width: 1199px) {
.transfer-log .transfer-item {
display: block;
}
.transfer-time {
padding: 10px 0;
}
}
@media (min-width: 1200px) {
.transfer-log .transfer-item {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.account-content .transfer-log .transfer-info {
width: 800px;
padding-left: 10px;
text-align: left;
}
.transfer-log .transfer-assets .assets {
font-size: 18px;
height: 42px;
line-height: 42px;
width: 300px;
text-align: right;
}
}
.transfer-log .icon-wrap {
width: 42px;
height: 42px;
border-radius: 50%;
}
.transfer-log .icon-wrap .icon-transfer {
color: #fff;
position: relative;
left: 11px;
top: 4px;
font-size: 20px;
}
.transfer-log .plus-assets .icon-wrap {
background-color: rgba(0, 128, 0, 0.555);
}
.transfer-log .less-assets .icon-wrap {
background-color: rgba(255, 153, 0, 0.555);
}
.transfer-log .by-address {
width: 100%;
color: #9a9c9d;
table-layout: fixed;
word-break: break-all;
overflow: hidden;
color: rgb(54, 54, 54);
}
.transfer-log .transfer-time {
color: rgb(161, 161, 161);
}
.plus-assets .assets {
color: green;
}
.less-assets .assets {
color: rgb(255, 51, 0);
}
.iconfont {
font-size: 18px;
color: #bfbef8;
}
.no-list {
padding-top: 20px;
}
.pagin-wrap {
padding: 15px 0;
}
</style>
|