sbd-npm 1.3.6 → 1.3.8

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 +38 -28
  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.6",
3
+ "version": "1.3.8",
4
4
  "description": "Stock Big Data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/stock_basics.js CHANGED
@@ -837,7 +837,9 @@ let Stock = {
837
837
  });
838
838
  },
839
839
 
840
- // 公募持股
840
+ /**
841
+ * 公募持股
842
+ */
841
843
  fetch_public_fund: function () {
842
844
  Util.show_loading();
843
845
  Util.init_table_skeleton({
@@ -887,14 +889,22 @@ let Stock = {
887
889
  _html.push("<td>", item["invest_type"], "</td>");
888
890
  _html.push("<td>", item["administrator"], "</td>");
889
891
  _html.push("<td>", public_date, "</td>");
890
- _html.push("<td>", Util.to_ten_thousand(item["stock_num"], 3), "万</td>");
891
- _html.push("<td>", Util.to_hundred_million(item["market_capital"], 4), "亿</td>");
892
+ _html.push("<td data-val='", item["stock_num"], "' title='", item["stock_num"], "'>", Util.to_unit(item["stock_num"], 3), "股</td>");
893
+ _html.push("<td data-val='", item["market_capital"], "' title='", item["market_capital"], "'>", Util.to_unit(item["market_capital"], 3), "</td>");
892
894
  _html.push("<td><a class='link_cls' data-toggle='modal' data-target='.public_fund_modal' data-val='", item["fund_code"], "'>详细</a></td>");
893
895
  _html.push("</tr>");
894
896
  });
895
897
  Util.render_table_html("public_fund_table_body", _html);
896
898
  total_public_fund = Util.pack_html_link(Util.get_url("trend_fund_hold"), '<span class="label label-info">' + total_public_fund + '</span>');
897
- $("#public_fund_tips").html('共 ' + total_public_fund + ' 家, <span class="label label-info">' + Util.to_hundred_million(total_stock_num, 3) + '</span> 亿股,<span class="label label-info">' + Util.to_hundred_million(total_market_capital, 3) + '</span>亿市值');
899
+ $("#public_fund_tips").html('共 ' + total_public_fund + ' 家, <span class="label label-info">' + Util.to_unit(total_stock_num, 3) + '</span> 股,<span class="label label-info">' + Util.to_unit(total_market_capital, 3) + '</span>市值');
900
+ if (j["date"] && j["date"] > 0) {
901
+ $("#public_fund_title").find("a").each(function() {
902
+ let t_text = $(this).text();
903
+ if (t_text.indexOf("持股详细查询") > -1) {
904
+ $(this).attr("href", "https://data.eastmoney.com/zlsj/detail/" + Util.seconds_to_format(j["date"], "%Y-%m-%d") + "-1-" + Stock["code"] + ".html");
905
+ }
906
+ });
907
+ }
898
908
  if ($("#public_fund_date").length === 0) {
899
909
  Util.post("/stock/" + Stock["code"], {action: "public_fund_date"}, function (j) {
900
910
  let _html = [];
@@ -913,24 +923,24 @@ let Stock = {
913
923
  });
914
924
  },
915
925
 
926
+ /**
927
+ * 公募持股变化
928
+ */
916
929
  fetch_public_fund_change: function () {
917
930
  Stock["pfc_stock_chart"] = Util.show_chart_loading(Stock["pfc_stock_chart"], "pfc_stock_line_canvas");
918
931
  Util.init_table_skeleton({
919
932
  "element_id": "pfc_fund_table",
920
933
  "head_cols": [
921
- {"name": "时间", "table_sort": 1},
922
- {"name": "股价", "table_sort": 1},
923
- {"name": "总持股数(万股)", "table_sort": 1},
934
+ {"name": "时间", "class": "info", "table_sort": 1},
935
+ {"name": "当时股价", "table_sort": 1},
936
+ {"name": "总持股数", "table_sort": 1},
924
937
  {"name": "持仓家数", "table_sort": 1},
938
+ {"name": "持仓市值", "table_sort": 1, "title": "当时股价 * 总持股数"},
925
939
  ]
926
940
  });
927
941
  Util.post("/stock/" + Stock["code"], {action: "public_fund_change"}, function (j) {
928
942
  Stock["pfc_stock_chart"].hideLoading();
929
- let date_data = [];
930
- let fund_num_data = [];
931
- let stock_num_data = [];
932
- let price_data = [];
933
- let _html = [];
943
+ let date_data = [], fund_num_data = [], stock_num_data = [], price_data = [], _html = [];
934
944
  j["data"].forEach(function (item) {
935
945
  let date_format = Util.seconds_to_format(item["date"], "%Y-%m-%d");
936
946
  date_data.push(date_format);
@@ -938,31 +948,31 @@ let Stock = {
938
948
  stock_num_data.push(item["stock_num"]);
939
949
  price_data.push(item["price"]);
940
950
  _html.push("<tr>");
941
- _html.push("<td>", date_format, "</td>");
951
+ _html.push("<td>", Util.pack_html_link("https://data.eastmoney.com/zlsj/detail/" + date_format + "-1-" + Stock["code"] + ".html", date_format), "</td>");
942
952
  _html.push("<td>", item["price"], "</td>");
943
- _html.push("<td>", item["stock_num"], "</td>");
953
+ _html.push("<td data-val='", item["stock_num"], "' title='", item["stock_num"], "'>", Util.to_unit(item["stock_num"], 3), "股</td>");
944
954
  _html.push("<td>", item["fund_num"], "</td>");
955
+ let market_capital = item["price"] * item["stock_num"];
956
+ _html.push("<td data-val='", market_capital, "' title='", market_capital, "'>", Util.to_unit(market_capital, 4), "</td>");
945
957
  _html.push("</tr>");
946
958
  });
947
959
  date_data = date_data.reverse();
948
960
  fund_num_data = fund_num_data.reverse();
949
961
  stock_num_data = stock_num_data.reverse();
950
962
  price_data = price_data.reverse();
951
- 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);
952
964
  Stock["pfc_fund_chart"] = Util.multi_axis_line(Stock["pfc_fund_chart"], "pfc_fund_line_canvas", date_data, '持仓家数', fund_num_data, '股价', price_data);
953
- if (j["cur_stock_num"] && j["cur_stock_num"] > 0 && j["pre_stock_num"] && j["pre_stock_num"] > 0) {
954
- $("#pfc_stock_tips").html("(当前持股数: <b class='text-info'>" + Util.to_unit(j["cur_stock_num"] * 10000, 4) + "</b>, 环比: " + Util.year_price_rate(j["cur_stock_num"], j["pre_stock_num"]) + ")");
955
- }
956
- if (j["cur_fund_num"] && j["cur_fund_num"] > 0 && j["pre_fund_num"] && j["pre_fund_num"] > 0) {
957
- $("#pfc_fund_tips").html("(当前基金数: <b class='text-info'>" + Util.to_unit(j["cur_fund_num"]) + "</b>, 环比: " + Util.year_price_rate(j["cur_fund_num"], j["pre_fund_num"]) + ")");
958
- }
959
- if (j["cfi_id"]) {
960
- $("#pfc_stock_tips").parent().find("a").each(function () {
961
- let url = $(this).attr("href");
962
- if (url && url.indexOf("cfi") !== -1) {
963
- $(this).attr("href", "https://quote.cfi.cn/jjccbd/" + j["cfi_id"] + "/" + Stock["code"] + ".html");
964
- }
965
- });
965
+ if (j["data"].length > 1) {
966
+ let cur_stock_num = j["data"][0]["stock_num"];
967
+ let pre_stock_num = j["data"][1]["stock_num"];
968
+ if (cur_stock_num > 0 && pre_stock_num > 0) {
969
+ $("#pfc_stock_tips").html("(当前持股数: <b class='text-info'>" + Util.to_unit(cur_stock_num, 4) + "</b>, 环比: " + Util.year_price_rate(cur_stock_num, pre_stock_num) + ")");
970
+ }
971
+ let cur_fund_num = j["data"][0]["fund_num"];
972
+ let pre_fund_num = j["data"][1]["fund_num"];
973
+ if (cur_fund_num > 0 && pre_fund_num > 0) {
974
+ $("#pfc_fund_tips").html("(当前基金数: <b class='text-info'>" + cur_fund_num + "</b>, 环比: " + Util.year_price_rate(cur_fund_num, pre_fund_num) + ")");
975
+ }
966
976
  }
967
977
  Util.render_table_html("pfc_fund_table_body", _html);
968
978
  Util.hide_tips();
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