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,
|
latest_real_order_index: -1,
|
hidden_canceled: true,
|
//隐藏撤单
|
hidden_cancel: true,
|
hidden_little_money: true,
|
hidden_sell: 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: []
|
},
|
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;
|
});
|
|
setInterval(function() {
|
if (is_trade_time()) {
|
app.get_delegated_buy_code_infos();
|
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;
|
}
|
}
|
});
|
},
|
refresh_l_cancel_data: function(type_) {
|
// 刷新L撤
|
if (app.code == "000000") {
|
alert("没有获取到代码")
|
return;
|
}
|
http_util.get_l2_l_cancel_datas(app.code, app.operate_index, 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);
|
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透明度的白色背景
|
});
|
|
http_util.get_l2_datas(app.code, function(res) {
|
layer.close(index);
|
console.log("获取到L2数据:", res)
|
res = JSON.parse(res);
|
if (res.code == 0) {
|
var real_order_index = -1;
|
var buy_singles = [];
|
res.data.data.forEach(function(e) {
|
if (e[1] != null) {
|
if (e[1][0] == 3) {
|
//真实下单位置
|
real_order_index = 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)
|
});
|
console.log("最近真实下单位置:", real_order_index);
|
app.latest_real_order_index = real_order_index;
|
app.l2_datas = res.data.data;
|
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;
|
}
|
});
|
app.delegated_buy_code_infos = result.data.delegates;
|
app.account_available_money = result.data.account_available_money;
|
app.reset_l2_height();
|
|
} else {
|
console.log("已挂买单错误:", result.msg);
|
app.delegated_buy_code_infos = [];
|
}
|
});
|
},
|
|
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 - 370 - 66 * 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 = [];
|
},
|
get_last_trade_day_reasons: function(code) {
|
http_util.get_last_trade_day_reasons(code, function(res) {
|
res = JSON.parse(res);
|
console.log("返回内容", res);
|
if (res.code == 0) {
|
app.same_reason_codes = res.data;
|
} else {
|
app.same_reason_codes = null;
|
}
|
});
|
},
|
|
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;
|
},
|
|
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.get_last_trade_day_reasons(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.hidden_canceled && (item[2][6].indexOf('买撤') >= 0 || (item[2][8] != null &&
|
item[2][8].indexOf("-") > 0))) {
|
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]) < 50 && item[2][0] != app
|
.latest_real_order_index) {
|
return false;
|
}
|
|
return true;
|
},
|
get_score_data: function(code, name, callback) {
|
console.log("获取分数数据:", code, name);
|
http_util.get_score_data(code, name, 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);
|
}
|
},
|
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 = []
|
}
|
});
|
}
|
}
|
})
|
|
|
|
});
|