admin
2025-06-10 568c763084b926a6f2d632b7ac65b9ec8280752f
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
document.addEventListener("DOMContentLoaded", function() {
    //把对象赋值到JS中
    try {
        new QWebChannel(qt.webChannelTransport, function(channel) {
            window.pyjs = channel.objects.Bridge;
            console.log("回调成功");
        });
    } catch (e) {
 
    }
});
var app;
$(function() {
    function is_trade_time() {
        var nowdate = new Date();
        h = nowdate.getHours();
        m = nowdate.getMinutes();
        total_m = h * 60 + m;
        if ((total_m >= (9 * 60 + 25) && total_m <= (11 * 60 + 30)) || (total_m >= 13 * 60 && total_m <= 15 *
                60)) {
            return true;
        } else {
            return false;
        }
    }
 
    new VConsole();
    app = new Vue({
        el: "#app",
        data: {
            element: null,
            code: "000000",
            code_name: "测试代码",
            account_available_money: 0,
            origin_code: null,
            trade_data: {},
            trade_record: {
                open_limit_up: "",
                records: []
            },
            same_reason_codes: null,
            initiative_buy_codes: null,
            passive_buy_codes: null,
            data_type: 0,
            trade_progress_index: -1,
            trade_progress_percent: 0,
            real_order_indexes: new Array(),
            hidden_canceled: true,
            //隐藏撤单
            hidden_cancel: true,
            hidden_little_money: true,
            hidden_sell: true,
            // 不隐藏已撤大单
            not_hidden_canceled_big_money:true,
            l2_datas: [],
            l2_colors_class: ["color-single-start", "color-single-exec", "color-cancel",
                "color-real-order"
            ],
            kpl_code_info: null,
            l_up_cancel_indexes: [],
            l_down_cancel_indexes: [],
            h_cancel_indexes: [],
            buy_single_indexes: [],
            l2_code_name: '',
            operate_index: -1,
            // 已经委托的买代码信息
            delegated_buy_code_infos: [],
            layui_element: null,
            l2_cant_buy_reasons: [],
            latest_cancel_orders: [],
            l2_min_volume:'',
            l2_max_volume:'',
            kpl_open_limit_up_count_rank:[],
            // 大单买卖数量
            big_buy_order_count:0,
            big_sell_order_count:0,
            // 过滤的索引
            filter_indexes:[],
            // 费用数据
            commission_data:{"total_commission":0, "month_commission":0},
            // L2数据结束索引
            l2_end_index:null
            
        },
        watch: {
            delegated_buy_code_infos: function() {
                if (app.layui_element) {
                    setTimeout(() => {
                        app.layui_element.render();
                    })
                }
            }
        },
        mounted: function() {
            layui.use('element', function() {
                var element = layui.element;
                app.layui_element = element;
            });
            
            layui.use('laydate', function(){
              var laydate = layui.laydate;
              
              //执行一个laydate实例
              laydate.render({
                elem: '#date' ,//指定元素
                type: 'date',
                position:'abolute'
              });
            });
 
            setInterval(function() {
                if (is_trade_time()) {
                    app.get_latest_cancel_orders();
                }
            }, 1000 * 3);
 
            layui.use(function() {
                app.element = layui.element;
            });
 
        },
        methods: {
            change_data_type: function(type) {
                // if (app.data_type == type) {
                //     return;
                // }
                // app.data_type = type;
                // window.scrollTo(0,0);
                app.element.tabChange('test-handle', type);
            },
            refresh_trade_progress: function() {
                if (app.code == "000000") {
                    alert("没有获取到代码")
                    return;
                }
                http_util.get_trade_progress(app.code, function(res) {
                    res = JSON.parse(res);
                    if (res.code == 0) {
                        console.log("成交进度", res.data);
                        if (!res.data.is_default) {
                            app.trade_progress_index = res.data.trade_progress;
                            
                            app.trade_progress_percent = res.data.percent;
                        }
                    }
                });
            },
            refresh_l_cancel_data: function(type_) {
                // 刷新L撤
                if (app.code == "000000") {
                    alert("没有获取到代码")
                    return;
                }
                var date = $("#date").val();
                
                http_util.get_l2_l_cancel_datas(app.code, app.operate_index, date, function(res) {
                    console.log("L撤结果", res);
                    res = JSON.parse(res);
                    if (res.code == 0) {
                        if (type_ == 0) {
                            app.l_up_cancel_indexes = res.data.up;
                        } else {
                            app.l_down_cancel_indexes = res.data.down;
                        }
                    }
                });
            },
            refresh_h_cancel_data: function() {
                // 刷新h撤
                if (app.code == "000000") {
                    alert("没有获取到代码")
                    return;
                }
                http_util.get_l2_h_cancel_datas(app.code, app.operate_index, function(res) {
                    res = JSON.parse(res);
                    console.log("H撤數據",res)
                    if (res.code == 0) {
                        app.h_cancel_indexes = res.data;
                    }
                });
            },
            refresh_l2_data: function() {
                if (app.code == "000000") {
                    alert("没有获取到代码")
                    return;
                }
 
                var index = layer.load(1, {
                    shade: [0.1, '#fff'], //0.1透明度的白色背景
                    shadeClose:true
                });
                
                var date = $("#date").val();
 
                http_util.get_l2_datas(app.code, date, app.l2_end_index, function(res) {
                    layer.close(index);
                    res = JSON.parse(res);
                    if (res.code == 0) {
                        var real_order_indexes = new Array();
                        var buy_singles = [];
                        var big_buy_order=0;
                        var big_sell_order=0;
                        res.data.data.delegates.forEach(function(e) {
                            if (e[1] != null) {
                                if (e[1][0] == 3) {
                                    //真实下单位置
                                    real_order_indexes.push(e[2][0])
                                } else if (e[1][0] == 0) {
                                    // 信号位置
                                    buy_singles.push(e[2][0])
                                }
                                e[1] = app.l2_colors_class[e[1][0]]
                            } else {
                                e[1] = '';
                            }
                            e[2][3] = e[2][3].slice(0, e[2][3].length - 1)
                             
                            if(parseFloat(e[2][3])>=299&&e[2][6]=='买T'&&e[2][8]&&e[2][8].indexOf(":")>=0&&e[2][8].indexOf("-")<0&&e[2][8].indexOf("成交")<0){
                                // 大单数量
                                big_buy_order+=1;
                            }
                            
                            if(e[2][5] == 6){
                                console.log("小单:", e)
                            }
                            
                        });
                        res.data.data.transactions.forEach(function(e) {
                            if(parseFloat(e[2][3])>=299){
                                // 大单数量
                                big_sell_order+=1;
                            }
                            
                        });
                        
                        app.big_buy_order_count = big_buy_order;
                        app.big_sell_order_count = big_sell_order;
                        
                        console.log("大单信息:","买:"+big_buy_order,"卖:"+big_sell_order);
                        
                        console.log("最近真实下单位置:", real_order_indexes);
                        app.real_order_indexes = real_order_indexes;
                        app.l2_datas = res.data.data;
                        
                        console.log("第1条L2数据:", res.data.data[0])
                        
                        // console.log("L2数据:", app.l2_datas);
                        var code_name = res.data.code_name;
                        var code_ = res.data.code;
                        app.l2_code_name = code_ + " " + code_name;
                        // 清除成交进度,L撤, H撤
                        app.trade_progress_index = -1;
                        app.l_up_cancel_indexes = [];
                        app.l_down_cancel_indexes = [];
                        app.h_cancel_indexes = [];
                        app.buy_single_indexes = buy_singles;
                    } else {
                        alert(res.msg);
                    }
                });
 
            },
            get_delegated_buy_code_infos: function() {
                // 获取数据
                http_util.get_delegated_buy_code_infos(function(result) {
                    if (result.code == 0) {
                        console.log("已挂买单数据:", result.data);
                        result.data.delegates.forEach(function(e) {
                            if (e.total_num > 0) {
                                e.percent = e.finish_num * 100 / e.total_num;
                            } else {
                                e.percent = 0;
                            }
                        });
                        
                        result.data.delegates.forEach(function(e){
                            if(e.buy1_money.indexOf("万")&&parseFloat(e.buy1_money.substring(0,e.buy1_money.indexOf("万")))<2000){
                                //封单2000w以下提醒
                                e.buy1_money_warning =  1;
                            }else{
                                e.buy1_money_warning =  0; 
                            }
                        });
                        
                        
                        app.delegated_buy_code_infos = result.data.delegates;
                        app.account_available_money = result.data.account_available_money;
                        app.reset_l2_height();
 
                    }
                });
            },
 
            get_latest_cancel_orders: function() {
                http_util.get_latest_cancel_orders(function(res) {
                    res = JSON.parse(res);
                    console.log("最近的撤单", res);
                    if (res.code == 0) {
                        app.latest_cancel_orders = res.data;
                        app.reset_l2_height();
                    }
                });
 
            },
 
            reset_l2_height: function() {
                var height = document.documentElement.clientHeight;
                console.log("屏幕:", height);
                $(".l2-content").eq(0).css("height", (height - 390 - 76 * app
                        .delegated_buy_code_infos.length - 24 * app.latest_cancel_orders.length
                        ) + "px");
            },
            clear_cancel_mark: function() {
                //清除撤单标记
                app.l_up_cancel_indexes = [];
                app.l_down_cancel_indexes = [];
                app.h_cancel_indexes = [];
            },
 
            hidden_canceled_check: function(e) {
 
                app.hidden_canceled = e.currentTarget.checked;
            },
 
            hidden_cancel_check: function(e) {
 
                app.hidden_cancel = e.currentTarget.checked;
            },
 
            hidden_sell_check: function(e) {
                app.hidden_sell = e.currentTarget.checked;
            },
 
            hidden_little_money_check: function(e) {
                app.hidden_little_money = e.currentTarget.checked;
            },
            
            hidden_canceled_big_money_check: function(e) {
                app.not_hidden_canceled_big_money = e.currentTarget.checked;
            },
 
            select_row: function(index) {
                console.log("点击事件", index);
                if (app.buy_single_indexes.includes(index)) {
                    app.operate_index = index;
                } else {
                    app.operate_index = -1;
                }
            },
            show_operate: function(event, index) {
                console.log("位置", event.clientX, event.clientY);
            },
            set_trade_info: function(code, code_name, trade_data, trade_record, initiative_buy_codes,
                passive_buy_codes) {
                try {
                    console.log("交易数据", trade_data)
                    console.log("交易记录数据", trade_record)
                    app.code = code;
                    app.code_name = code_name;
                    if (trade_data) {
                        console.log("交易数据类型", typeof trade_data)
                        try {
                            // trade_data = trade_data.replace("/\n/g", "  ")
                            // var trade_data = JSON.parse(trade_data);
                            app.trade_data = trade_data
                        } catch (e) {
                            console.log(e)
                        }
                        console.log("----有交易数据")
                    } else {
                        app.trade_data = {
                            "star": {
                                "desc": "----",
                                "count": 0
                            },
                            "safe_count": {
                                "base": 0,
                                "now": 0
                            },
                            "m_val": {
                                "base": 0,
                                "now": 0
                            },
                            "big_num": {
                                "base": 0,
                                "now": 0
                            },
                            "trade_progress": [{
                                "time": "00:00:00",
                                "num": 0,
                                "money": 0
                            }],
                            "trade_state": {
                                "order": false,
                                "desc": "未交易"
                            }
                        };
                    }
                    if (trade_record) {
                        console.log("----有交易记录")
                        app.trade_record = trade_record;
                    } else {
                        console.log("----无交易记录")
                        app.trade_record = null;
                    }
                } catch (ee) {
                    console.log("处理出错")
                    console.log(e)
                }
                app.get_l2_cant_buy_reasons(code);
            },
            show_more_records: function(items) {
                var str_ = ""
                items.forEach(function(item) {
                    str_ += item;
                    str_ += "\n";
                });
                alert(str_);
            },
            set_real_place_order_index: function() {
                // 设置真实下单位
                if (app.code) {
                    layer.prompt({
                        formType: 0,
                        value: '',
                        title: '设置真实下单位-' + app.code,
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function(value, index, elem) {
                        try {
                            if (isNaN(value)) {
                                layer.msg("请输入数字");
                                return;
                            } else {
                                http_util.set_real_place_order_index(app.code, parseInt(
                                    value), function(res) {
                                    // 获取到结果
                                    console.log(res);
                                    if (res.code != 0) {
                                        layer.msg(res.msg, {
                                            icon: 5
                                        });
                                    } else {
                                        layer.msg("设置成功", {
                                            icon: 1
                                        });
                                    }
                                })
                            }
                        } catch (e) {}
                        layer.close(index);
                    });
 
                    //set_real_place_order_index
 
                } else {
                    layer.msg("请先加载数据");
                }
 
            },
            need_show: function(item) {
                
                if(app.filter_indexes.length>0){
                    if(app.filter_indexes.indexOf(item[2][0])>=0)
                    {
                         return true;
                    }else{
                        return false;
                    }
                }
                
                
                if(app.real_order_indexes.includes( item[2][0])){
                    return true;
                }
                
                
                
                if (app.hidden_canceled && (item[2][6].indexOf('买撤') >= 0 || (item[2][8] != null &&
                        item[2][8].indexOf("-") > 0))) {
                    if(!app.not_hidden_canceled_big_money){
                        // 隐藏已撤大单
                        return false;
                    }else{
                        // 不隐藏已撤大单
                        if(parseFloat(item[2][3])<299)
                        {
                             return false;
                        }
                    }
                }
 
                if (app.hidden_sell && item[2][6].indexOf('卖') >= 0) {
                    return false;
                }
                
 
                if (app.hidden_cancel && (item[2][6].indexOf('买撤') >= 0)) {
                    return false;
                }
                if (app.hidden_little_money && parseFloat(item[2][3]) < 5) {
                    return false;
                }
                
                if(app.l2_min_volume!=null&&!isNaN(app.l2_min_volume)&&parseInt(app.l2_min_volume) > parseInt(item[2][5])){
                    return false;
                }
                
                if(app.l2_max_volume!=null&&!isNaN(app.l2_max_volume)&&parseInt(app.l2_max_volume) < parseInt(item[2][5])){
                    return false;
                }
                
                
 
                return true;
            },
            get_score_data: function(code, name, callback) {
                console.log("获取分数数据:", code, name);
                var date = $("#date").val();
                http_util.get_score_data(code, name,date, function(res) {
                    res = JSON.parse(res)
                    console.log("分数请求结果:", res)
                    if (res.code == 0) {
                        console.log("获取分数", res)
                        app.code = res.data.code
                        app.code_name = res.data.code_name
                        if (res.data.score_data) {
                            app.score_data = res.data.score_data;
                        } else {
                            app.score_data = app.default_score_data;
                        }
                        if (res.data.trade_data) {
                            app.trade_data = {
                                order: res.data.trade_data.trade_state.order
                            }
                        } else {
                            res.data.trade_data = {
                                order: false
                            };
                            app.trade_data = res.data.trade_data
                        }
                        app.kpl_code_info = res.data.kpl_code_info;
                        //通知副屏改变内容
                        app.set_trade_info(app.code, app.code_name,
                            res.data.trade_data,
                            res.data.trade_record,
                            res.data.initiative_buy_codes,
                            res.data.passive_buy_codes);
 
                        if (callback) {
                            callback()
                        }
                    }
                });
            },
            set_target_code: function(code) {
                console.log("设置目标代码", code);
                app.origin_code = code;
                app.code_name = code;
            },
            load_data: function(refresh_l2) {
                if (app.origin_code) {
                    app.get_score_data(app.origin_code, null, function(e) {
                        // if (refresh_l2) {
                        //     app.refresh_l2_data();
                        // }
                    });
                    
                    app.get_l2_cant_buy_reasons(app.origin_code);
                    http_util.get_open_limit_up_count_rank(null,function(res){
                        res = JSON.parse(res);
                        if(res.code ==0){
                            app.kpl_open_limit_up_count_rank = res.data;
                        }
                    });
                }
            },
            cancel_order: function(code) {
                http_util.cancel_order(code, function(res) {
                    layer.msg("撤单成功");
                });
            },
 
            view_details: function(code, need_l2) {
                pyjs.add_code_to_ths(code);
                // 设置目标代码
                app.set_target_code(code);
                // 将目标票传递到首页
                pyjs.set_target_code(code);
                if (need_l2) {
                    // 点击选择L2选项
                    app.change_data_type(1);
                    app.load_data(true);
                } else {
                    app.change_data_type(0);
                    app.load_data(false);
                }
            },
 
            get_l2_cant_buy_reasons: function(code) {
                http_util.get_l2_cant_buy_reasons(code, function(res) {
                    res = JSON.parse(res);
                    if (res.code == 0) {
                        app.l2_cant_buy_reasons = res.data;
                    } else {
                        app.l2_cant_buy_reasons = []
                    }
                });
            },
            screen_l2_data:function(code){
                // 筛选l2数据
                layer.open({
                    title: 'L2数据筛选',
                    type: 1,
                    content: $("#l2_screen"),
                });
                
                
            },
            l2_screen_click:function(){
                
                // L2筛选
                if(!isNaN($("#min-volume").val())){
                    app.l2_min_volume=$("#min-volume").val();
                }else{
                    app.l2_min_volume=null;
                }
                
                if(!isNaN($("#max-volume").val())){
                    app.l2_max_volume=$("#max-volume").val();
                }else{
                    app.l2_max_volume=null;
                }
                
                
                if(!isNaN($("#end-index").val())){
                    app.l2_end_index=$("#end-index").val();
                }else{
                    app.l2_end_index=null;
                }
                
                watch_indexes_str = $("#watch_indexes").val();
                if(watch_indexes_str!=null&&watch_indexes_str.length>0){
                    var final_indexes=[];
                    var indexes = watch_indexes_str.split(",");
                    indexes.forEach(function(e){
                      final_indexes.push(parseInt(e));
                    });
                    app.filter_indexes = final_indexes;
                    console.log("选中索引:",final_indexes);
                }else{
                    app.filter_indexes =[];
                }
                layer.msg("设置成功")
                
 
            },
            fordbidden_buy:function(code){
                // 加入黑名单
                 http_util.do_action_for_code(code,null,0,function(res){
                     if(res.code!=0){
                         layer.msg(res.msg);
                     }
                 });
            },
            get_account_commission_detail:function(){
                
                 http_util.get_account_commission_detail(function(res){
                    
                     res = JSON.parse(res);
                      console.log(res);
                     if(res.code!=0){
                         layer.msg(res.msg);
                     }else{
                         let commission_data ={};
                         // commission_data.commission = =res.data.commission;
                         commission_data.delegates =res.data.delegates ;
                         commission_data.deals =res.data.deals;
                        var total_money = 0;
                         for(let k in commission_data.delegates){
                             total_money -=commission_data.delegates[k]["money"];
                         }
                         for(let k in commission_data.deals){
                             total_money +=commission_data.deals[k]["money"];
                         }
                         commission_data.total_commission = total_money.toFixed(2);
                         commission_data.commission = res.data.commission;
                          commission_data.month_commission = res.data.month_commission;
                         console.log(commission_data)
                         app.commission_data = commission_data;
                     }
                 });
            }
        }
    })
 
 
 
});