sbd-npm 1.3.7 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/stock_basics.js +27 -33
  3. package/util.js +24 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "Stock Big Data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/stock_basics.js CHANGED
@@ -960,7 +960,7 @@ let Stock = {
960
960
  fund_num_data = fund_num_data.reverse();
961
961
  stock_num_data = stock_num_data.reverse();
962
962
  price_data = price_data.reverse();
963
- Stock["pfc_stock_chart"] = Util.multi_axis_line(Stock["pfc_stock_chart"], "pfc_stock_line_canvas", date_data, '总持股数(万股)', stock_num_data, '股价', price_data);
963
+ Stock["pfc_stock_chart"] = Util.multi_axis_line(Stock["pfc_stock_chart"], "pfc_stock_line_canvas", date_data, '总持股数', stock_num_data, '股价', price_data);
964
964
  Stock["pfc_fund_chart"] = Util.multi_axis_line(Stock["pfc_fund_chart"], "pfc_fund_line_canvas", date_data, '持仓家数', fund_num_data, '股价', price_data);
965
965
  if (j["data"].length > 1) {
966
966
  let cur_stock_num = j["data"][0]["stock_num"];
@@ -1104,11 +1104,9 @@ let Stock = {
1104
1104
  },
1105
1105
 
1106
1106
  fetch_margin: function () {
1107
- let is_summary = Stock["rzye_chart"] ? 0 : 1;
1108
1107
  Stock["rzye_chart"] = Util.show_chart_loading(Stock["rzye_chart"], "rzye_line_canvas");
1109
1108
  let payload = {
1110
1109
  action: "margin",
1111
- is_summary: is_summary,
1112
1110
  date_type: $("#margin_date_type").val(),
1113
1111
  start_date: $("#margin_start_date").val(),
1114
1112
  end_date: $("#margin_end_date").val()
@@ -1127,7 +1125,7 @@ let Stock = {
1127
1125
  price_data.push(item["price"]);
1128
1126
  });
1129
1127
  let margin_summary = "";
1130
- if (is_summary === 1 && j["latest"].length > 0) {
1128
+ if (j["latest"].length > 0) {
1131
1129
  if (j["latest"].length === 1) {
1132
1130
  margin_summary = " 最新(" + Util.seconds_to_format(j["latest"][0]["date"], "%Y-%m-%d") + "): " + Util.to_unit(j["latest"][0]["rzye"], 3);
1133
1131
  } else if (j["latest"].length === 2) {
@@ -1143,7 +1141,7 @@ let Stock = {
1143
1141
  margin_summary = " 最新(" + Util.seconds_to_format(d1["date"], "%Y-%m-%d") + "): " + Util.to_unit(d1["rzye"], 3) + dist_tips;
1144
1142
  }
1145
1143
  }
1146
- margin_summary = Util.pack_html_link(j["url"], "[" + Stock.name + "融资余额(单位:亿)]") + margin_summary + ' 最高: ' + Util.to_unit(rzye_high, 3) + ' 最低: ' + Util.to_unit(rzye_low, 3);
1144
+ margin_summary = Util.pack_html_link(j["url"], "[" + Stock.name + "]融资余额(单位:亿)") + margin_summary + ' 最高: ' + Util.to_unit(rzye_high, 3) + ' 最低: ' + Util.to_unit(rzye_low, 3);
1147
1145
  if (j["high"] && j["high"]["date"] && j["high"]["date"] > 0) {
1148
1146
  margin_summary += ' 历史最高: ' + Util.to_unit(j["high"]["rzye"], 3) + '(' + Util.seconds_to_format(j["high"]["date"], "%Y-%m-%d") + ')';
1149
1147
  }
@@ -1168,11 +1166,9 @@ let Stock = {
1168
1166
  },
1169
1167
 
1170
1168
  fetch_hkex_holding: function () {
1171
- let is_summary = Stock.hkex_holding_chart ? 0 : 1;
1172
1169
  Stock["hkex_holding_chart"] = Util.show_chart_loading(Stock["hkex_holding_chart"], "hkex_holding_line_canvas");
1173
1170
  let payload = {
1174
1171
  action: "hkex_holding",
1175
- is_summary: is_summary,
1176
1172
  date_type: $("#hkex_holding_date_type").val(),
1177
1173
  start_date: $("#hkex_start_date").val(),
1178
1174
  end_date: $("#hkex_end_date").val()
@@ -1187,35 +1183,33 @@ let Stock = {
1187
1183
  volume_data.push(item["volume"]);
1188
1184
  price_data.push(item["price"]);
1189
1185
  });
1190
- if (is_summary === 1) {
1191
- let hhs_obj = $("#hkex_holding_summary");
1192
- let hkex_holding_summary = "[" + Util.pack_html_link(j["url"], hhs_obj.text()) + "]";
1193
- if (j["latest"].length > 0) {
1194
- let circulation_stock = $("#circulation_stock").attr("data-val");
1195
- let latest_html = "";
1196
- if (j["latest"].length === 1) {
1197
- let holding_num = Util.to_hundred_million(j["latest"][0]["volume"], 3);
1198
- let holding_rate = Math.round((holding_num / circulation_stock) * 10000) / 100;
1199
- latest_html = "最新(" + Util.seconds_to_format(j["latest"][0]["date"], "%Y-%m-%d") + "): " + holding_num + "亿股, 占 <b>" + holding_rate + "%</b> 流通股, ";
1200
- } else if (j["latest"].length === 2) {
1201
- let d1 = j["latest"][0];
1202
- let d2 = j["latest"][1];
1203
- let difference = d1["volume"] - d2["volume"];
1204
- let dist_tips = "";
1205
- if (difference > 0) {
1206
- dist_tips = "(<b title='" + Util.strip_html(Util.to_unit(d2["volume"])) + "股' style='color: #a94442;'>+" + Util.strip_html(Util.to_unit(difference)) + "股</b>)";
1207
- } else if (difference < 0) {
1208
- dist_tips = "(<b title='" + Util.strip_html(Util.to_unit(d2["volume"])) + "股' style='color: #3c763d;'>" + Util.strip_html(Util.to_unit(difference)) + "股</b>)";
1209
- }
1210
- let holding_num = Util.to_hundred_million(d1["volume"]);
1211
- let holding_rate = Math.round((holding_num / circulation_stock) * 10000) / 100;
1212
- latest_html = "最新(" + Util.seconds_to_format(d1["date"], "%Y-%m-%d") + "): " + holding_num + "亿股" + dist_tips + ", 占 <b>" + holding_rate + "%</b> 流通股, ";
1186
+ let hhs_obj = $("#hkex_holding_summary");
1187
+ let hkex_holding_summary = "[" + Util.pack_html_link(j["url"], hhs_obj.text()) + "]";
1188
+ if (j["latest"].length > 0) {
1189
+ let circulation_stock = $("#circulation_stock").attr("data-val");
1190
+ let latest_html = "";
1191
+ if (j["latest"].length === 1) {
1192
+ let holding_num = Util.to_hundred_million(j["latest"][0]["volume"], 3);
1193
+ let holding_rate = Math.round((holding_num / circulation_stock) * 10000) / 100;
1194
+ latest_html = "最新(" + Util.seconds_to_format(j["latest"][0]["date"], "%Y-%m-%d") + "): " + holding_num + "亿股, 占 <b>" + holding_rate + "%</b> 流通股, ";
1195
+ } else if (j["latest"].length === 2) {
1196
+ let d1 = j["latest"][0];
1197
+ let d2 = j["latest"][1];
1198
+ let difference = d1["volume"] - d2["volume"];
1199
+ let dist_tips = "";
1200
+ if (difference > 0) {
1201
+ dist_tips = "(<b title='" + Util.strip_html(Util.to_unit(d2["volume"])) + "股' style='color: #a94442;'>+" + Util.strip_html(Util.to_unit(difference)) + "股</b>)";
1202
+ } else if (difference < 0) {
1203
+ dist_tips = "(<b title='" + Util.strip_html(Util.to_unit(d2["volume"])) + "股' style='color: #3c763d;'>" + Util.strip_html(Util.to_unit(difference)) + "股</b>)";
1213
1204
  }
1214
- hkex_holding_summary += (latest_html + ' 最高: ' + Util.to_unit(j["high"]["volume"]) + '股(' + Util.seconds_to_format(j["high"]["date"], "%Y-%m-%d") +
1215
- ') 最低: ' + Util.to_unit(j["low"]["volume"]) + '股(' + Util.seconds_to_format(j["low"]["date"], "%Y-%m-%d") + ')');
1205
+ let holding_num = Util.to_hundred_million(d1["volume"]);
1206
+ let holding_rate = Math.round((holding_num / circulation_stock) * 10000) / 100;
1207
+ latest_html = "最新(" + Util.seconds_to_format(d1["date"], "%Y-%m-%d") + "): " + holding_num + "亿股" + dist_tips + ", 占 <b>" + holding_rate + "%</b> 流通股, ";
1216
1208
  }
1217
- hhs_obj.html(hkex_holding_summary);
1209
+ hkex_holding_summary += (latest_html + ' 最高: ' + Util.to_unit(j["high"]["volume"]) + '股(' + Util.seconds_to_format(j["high"]["date"], "%Y-%m-%d") +
1210
+ ') 最低: ' + Util.to_unit(j["low"]["volume"]) + '股(' + Util.seconds_to_format(j["low"]["date"], "%Y-%m-%d") + ')');
1218
1211
  }
1212
+ hhs_obj.html(hkex_holding_summary);
1219
1213
  Stock["hkex_holding_chart"] = Util.multi_axis_line(Stock["hkex_holding_chart"], "hkex_holding_line_canvas", date_data, '持股数', volume_data, '股价', price_data);
1220
1214
  let flow_data = [];
1221
1215
  date_data = [];
package/util.js CHANGED
@@ -27,7 +27,7 @@ const Util = {
27
27
  interval_timer: null,
28
28
  stock_timer_id: 0,
29
29
  is_init: 0,
30
- is_load: 0,
30
+ is_load: false,
31
31
  // 1年的天数
32
32
  one_year_day: 365,
33
33
  // 一天的秒数
@@ -183,12 +183,30 @@ const Util = {
183
183
 
184
184
  /**
185
185
  * https://api.jquery.com/jquery.ajax/
186
+ * $.ajax 方法参数:
187
+ * url:要请求的服务器 URL
188
+ * type:HTTP 请求类型,如 "GET"、"POST"等,默认为 "GET"
189
+ * data:发送到服务器的数据,可以是字符串或对象
190
+ * dataType:预期从服务器返回的数据类型,如 "json"、"text"、"xml"、"html"等
191
+ * success:成功时的回调函数
192
+ * error:请求失败时的回调函数
193
+ * beforeSend:在发送请求之前调用的函数,用于设置自定义 HTTP 头信息等操作
194
+ * timeout:设置请求超时时间(默认为 0,即表示没有超时限制)。如果在指定的时间内未收到响应,则触发错误回调
195
+ * async:设置请求是否异步,默认为 true
196
+ * cache:设置是否缓存请求结果,默认为 true。如果设置为 false,则会在 URL 上添加一个时间戳来禁用缓存
197
+ * contentType:设置发送数据的格式,默认为 "application/x-www-form-urlencoded"。如果要发送 JSON 数据,则需要将此值设置为 "application/json"
198
+ * context:设置回调函数的上下文对象,即回调函数中 this 关键字的指向
199
+ * crossDomain:设置是否允许跨域请求。默认情况下,jQuery 会自动判断当前域名与请求域名是否相同,如果不同则会使用 JSONP 方式进行跨域请求
200
+ * headers:设置要发送的自定义 HTTP 头信息
201
+ * jsonp:设置 JSONP 请求的回调参数名
202
+ * jsonpCallback:设置 JSONP 回调函数的名称
186
203
  * @param url
187
204
  * @param payload
188
205
  * @param callback 回调函数
189
206
  * @param data_type json | text
190
207
  */
191
208
  post: function (url, payload, callback, data_type = "json") {
209
+ Util.is_load = true;
192
210
  $.ajax({
193
211
  url: url,
194
212
  headers: {
@@ -198,12 +216,16 @@ const Util = {
198
216
  type: 'POST',
199
217
  dataType: data_type,
200
218
  data: payload,
201
- success: callback,
219
+ success: function(data) {
220
+ callback(data);
221
+ Util.is_load = false;
222
+ },
202
223
  error: function (jqXHR, textStatus, errorThrown) {
203
224
  Util.hide_tips();
204
225
  let msg = "[" + textStatus + "] " + errorThrown;
205
226
  Util.show_tips(msg, 0, "alert-danger");
206
227
  }
228
+ //timeout: 5000
207
229
  })
208
230
  },
209
231