sbd-npm 1.2.28 → 1.2.31

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/.npmignore +1 -0
  2. package/package.json +1 -1
  3. package/util.js +100 -66
package/.npmignore ADDED
@@ -0,0 +1 @@
1
+ sbd-npm.md
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.2.28",
3
+ "version": "1.2.31",
4
4
  "description": "Stock Big Data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/util.js CHANGED
@@ -481,6 +481,17 @@ const Util = {
481
481
  return html;
482
482
  },
483
483
 
484
+ /**
485
+ * 美股 LOGO
486
+ * @param code
487
+ * @returns {*}
488
+ */
489
+ us_logo_html: function(code) {
490
+ code = code.toUpperCase();
491
+ let logo_url = "https://storage.googleapis.com/iex/api/logos/" + code + ".png";
492
+ return '<a rel="noopener noreferrer nofollow" href="' + logo_url + '" target="_blank"><img alt="' + code + '" width="20px" src="' + logo_url + '"/><a>';
493
+ },
494
+
484
495
  /**
485
496
  * 随机一股
486
497
  * @param rand_btn_id
@@ -865,6 +876,8 @@ const Util = {
865
876
  head_cols.push({"name": "成交均价", "table_sort": 1});
866
877
  head_cols.push({"name": "股东数", "table_sort": 1});
867
878
  head_cols.push({"name": "备注", "id": "stock_category_remark_title"});
879
+ } else {
880
+ head_cols.unshift({"name": ""});
868
881
  }
869
882
  let table_options = {
870
883
  "element_id": table_id,
@@ -893,17 +906,19 @@ const Util = {
893
906
 
894
907
  render_stock_category_html: function () {
895
908
  if (Util["stock_category_table_id"]) {
896
- let _html = [];
897
- let total_num = 0;
909
+ let _html = [], total_num = 0;
910
+ let is_us = $("#stock_category_remark_title").length === 0 ? 1 : 0;
898
911
  if (Util["stock_category_data"]) {
899
912
  let industry = $("#stock_category_industry").val();
900
913
  let area = $("#stock_category_area").val();
901
- let is_us = $("#stock_category_remark_title").length === 0 ? 1 : 0;
902
914
  Util["stock_category_data"].forEach(function (item) {
903
915
  if (Util.is_industry_area(item, industry, area)) {
904
916
  total_num++;
905
917
  _html.push("<tr>");
906
918
  item["code"] = item["code"].toLowerCase();
919
+ if (is_us === 1) {
920
+ _html.push('<td>', Util.us_logo_html(item["code"]), '</td>');
921
+ }
907
922
  _html = Util.stock_basics_html(_html, item);
908
923
  _html.push("<td id='high_", item["code"], "'>0</td>");
909
924
  _html.push("<td id='low_", item["code"], "'>0</td>");
@@ -921,6 +936,11 @@ const Util = {
921
936
  });
922
937
  }
923
938
  Util.render_table_html(Util["stock_category_table_id"] + "_body", _html);
939
+ if (is_us === 1) {
940
+ $("img").on("error", function () {
941
+ $(this).attr("src", "https://storage.googleapis.com/iex/api/logos/LI.png");
942
+ });
943
+ }
924
944
  $("#" + Util["stock_category_table_id"] + "_body_tips").html('共 <span class="label label-info">' + total_num + '</span> 家');
925
945
  }
926
946
  },
@@ -1450,7 +1470,7 @@ const Util = {
1450
1470
  _html.push('<option value="2">这月</option>');
1451
1471
  _html.push('<option value="3">上一周</option>');
1452
1472
  _html.push('<option value="4">上一月</option>');
1453
- _html.push('<option value="5">今年以来</option>');
1473
+ _html.push('<option value="5">年初至今</option>');
1454
1474
  _html.push('<option value="6">最近7日</option>');
1455
1475
  _html.push('<option value="7">最近30日</option>');
1456
1476
  _html.push('<option value="8">最近60日</option>');
@@ -1499,7 +1519,7 @@ const Util = {
1499
1519
  sd_obj.val(year + "-" + month + "-01");
1500
1520
  ed_obj.val(Util.seconds_to_format(pre_month_end_second, "%Y-%m-%d"));
1501
1521
  break;
1502
- case "5": // 今年以来
1522
+ case "5": // 年初至今
1503
1523
  sd_obj.val(year + "-01-01");
1504
1524
  ed_obj.val(Util.seconds_to_format(midnight_second, "%Y-%m-%d"));
1505
1525
  break;
@@ -1836,70 +1856,84 @@ const Util = {
1836
1856
  }
1837
1857
  }
1838
1858
  $(this).click(function () {
1839
- let table = $(this).parents('table').eq(0);
1840
- let row_arr = table.find('tr:gt(0)').toArray();
1841
- let td_index = $(this).index();
1842
- let get_td_value = function (row) {
1843
- let td_obj = $(row).children('td').eq(td_index);
1844
- if (td_obj.attr("data-val")) {
1845
- return td_obj.attr("data-val");
1846
- } else {
1847
- let td_val = td_obj.text();
1848
- // 2017-12-7 这种时间格式
1849
- if (Util.regexp_date_yyyy_mm_dd(td_val)) {
1850
- return Util.format_to_second(td_val);
1851
- } else {
1852
- // 174.36(+0.79%) 括号里的数字
1853
- let bracket_re = /\(([-+]?\d*\.?\d+|[-+]?\d+|\d+)\%?\)/;
1854
- let match_arr = bracket_re.exec(td_val);
1855
- if ($.isArray(match_arr)) {
1856
- if (match_arr.length >= 2) {
1857
- return match_arr[1];
1858
- }
1859
- return 0;
1860
- } else {
1861
- // 匹配数字
1862
- let digit_re = /([-+]?\d*\.?\d+|[-+]?\d+|\d+)/;
1863
- match_arr = digit_re.exec(td_val);
1864
- if ($.isArray(match_arr) && match_arr[0]) {
1865
- return match_arr[0];
1866
- }
1867
- return Util.filter_chinese(td_val).replace("%", "");
1868
- }
1869
- }
1870
- }
1871
- };
1872
- row_arr.sort(function (row1, row2) {
1873
- let td1_val = get_td_value(row1);
1874
- let td2_val = get_td_value(row2);
1875
- return $.isNumeric(td1_val) && $.isNumeric(td2_val) ? td1_val - td2_val : td1_val.localeCompare(td2_val);
1876
- });
1877
- let sort_cls = "fa-sort-asc";
1878
- this.asc = !this.asc;
1879
- if (!this.asc) {
1880
- row_arr = row_arr.reverse();
1881
- sort_cls = "fa-sort-desc";
1859
+ Util.sort_table_row($(this));
1860
+ });
1861
+ });
1862
+ },
1863
+
1864
+ /**
1865
+ * 对表格每一行排序
1866
+ * @param td_obj 表格里的单元格对象
1867
+ */
1868
+ sort_table_row: function (td_obj) {
1869
+ let table = td_obj.parents('table').eq(0);
1870
+ let row_arr = table.find('tr:gt(0)').toArray();
1871
+ let td_index = td_obj.index();
1872
+ row_arr.sort(function (row1, row2) {
1873
+ let td1_val = Util.get_table_td_value(row1, get_table_td_value);
1874
+ let td2_val = Util.get_table_td_value(row2, get_table_td_value);
1875
+ return $.isNumeric(td1_val) && $.isNumeric(td2_val) ? td1_val - td2_val : td1_val.localeCompare(td2_val);
1876
+ });
1877
+ let sort_cls = "fa-sort-asc";
1878
+ this.asc = !this.asc;
1879
+ if (!this.asc) {
1880
+ row_arr = row_arr.reverse();
1881
+ sort_cls = "fa-sort-desc";
1882
+ }
1883
+ table.children('tbody').empty().html(row_arr);
1884
+ table.find("i").each(function () {
1885
+ if ($(this).hasClass("fa")) {
1886
+ $(this).removeClass("fa-sort-asc");
1887
+ $(this).removeClass("fa-sort-desc");
1888
+ if (!$(this).hasClass("fa-sort")) {
1889
+ $(this).addClass("fa-sort");
1882
1890
  }
1883
- table.children('tbody').empty().html(row_arr);
1884
- table.find("i").each(function () {
1885
- if ($(this).hasClass("fa")) {
1886
- $(this).removeClass("fa-sort-asc");
1887
- $(this).removeClass("fa-sort-desc");
1888
- if (!$(this).hasClass("fa-sort")) {
1889
- $(this).addClass("fa-sort");
1890
- }
1891
- $(this).parent().removeClass("info");
1891
+ $(this).parent().removeClass("info");
1892
+ }
1893
+ });
1894
+ td_obj.find("i").each(function () {
1895
+ if ($(this).hasClass("fa")) {
1896
+ $(this).removeClass("fa-sort");
1897
+ $(this).addClass(sort_cls);
1898
+ }
1899
+ });
1900
+ td_obj.addClass("info");
1901
+ },
1902
+
1903
+ /**
1904
+ * 获取表格的单元格值
1905
+ * @param row
1906
+ * @param td_index
1907
+ */
1908
+ get_table_td_value: function (row, td_index) {
1909
+ let td_obj = $(row).children('td').eq(td_index);
1910
+ if (td_obj.attr("data-val")) {
1911
+ return td_obj.attr("data-val");
1912
+ } else {
1913
+ let td_val = td_obj.text();
1914
+ // 2017-12-7 这种时间格式
1915
+ if (Util.regexp_date_yyyy_mm_dd(td_val)) {
1916
+ return Util.format_to_second(td_val);
1917
+ } else {
1918
+ // 174.36(+0.79%) 括号里的数字
1919
+ let bracket_re = /\(([-+]?\d*\.?\d+|[-+]?\d+|\d+)\%?\)/;
1920
+ let match_arr = bracket_re.exec(td_val);
1921
+ if ($.isArray(match_arr)) {
1922
+ if (match_arr.length >= 2) {
1923
+ return match_arr[1];
1892
1924
  }
1893
- });
1894
- $(this).find("i").each(function () {
1895
- if ($(this).hasClass("fa")) {
1896
- $(this).removeClass("fa-sort");
1897
- $(this).addClass(sort_cls);
1925
+ return 0;
1926
+ } else {
1927
+ // 匹配数字
1928
+ let digit_re = /([-+]?\d*\.?\d+|[-+]?\d+|\d+)/;
1929
+ match_arr = digit_re.exec(td_val);
1930
+ if ($.isArray(match_arr) && match_arr[0]) {
1931
+ return match_arr[0];
1898
1932
  }
1899
- });
1900
- $(this).addClass("info");
1901
- });
1902
- });
1933
+ return Util.filter_chinese(td_val).replace("%", "");
1934
+ }
1935
+ }
1936
+ }
1903
1937
  },
1904
1938
 
1905
1939
  /**