sbd-npm 1.3.11 → 1.3.13

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 (2) hide show
  1. package/package.json +1 -1
  2. package/util.js +57 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sbd-npm",
3
- "version": "1.3.11",
3
+ "version": "1.3.13",
4
4
  "description": "Stock Big Data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/util.js CHANGED
@@ -82,6 +82,7 @@ const Util = {
82
82
  window.open(Util.array_rand(url_arr), "_blank");
83
83
  }
84
84
  });
85
+ $("#save_page_content").click(Util.save_page_content_image);
85
86
 
86
87
  $('#stock').keyup(function () {
87
88
  let st_obj = $("#search-tips");
@@ -181,6 +182,48 @@ const Util = {
181
182
  return url;
182
183
  },
183
184
 
185
+ /**
186
+ * 当前页面内容保存为图片
187
+ */
188
+ save_page_content_image: function() {
189
+ if (!Util.is_load) {
190
+ Util.is_load = true;
191
+ Util.show_loading();
192
+ // 获取要截取的HTML元素
193
+ let element = document.getElementById('page_content');
194
+ // 创建canvas元素
195
+ let canvas = document.createElement("canvas");
196
+ canvas.width = element.offsetWidth;
197
+ canvas.height = element.offsetHeight;
198
+ // 将html元素渲染到canvas上
199
+ html2canvas(element).then((canvas) => {
200
+ // 获取Canvas上下文对象
201
+ //let ctx = canvas.getContext('2d');
202
+ // 添加水印
203
+ //ctx.font = '30px Arial';
204
+ //ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
205
+ //let text = 'Stock Big Data';
206
+ //let textSize = ctx.measureText(text);
207
+ //let centerX = (canvas.width - textSize.width) / 2;
208
+ //let centerY = canvas.height / 2;
209
+ //ctx.fillText(text, centerX, centerY);
210
+
211
+ // 创建一个新的图像对象
212
+ let img = new Image();
213
+ // 设置图像的源为canvas中的内容
214
+ img.src = canvas.toDataURL("image/png");
215
+ // 创建一个下载链接并模拟点击
216
+ let link = document.createElement("a");
217
+ link.download = "sbd_page_content_" + Util.now() + ".png";
218
+ link.href = img.src;
219
+ link.click();
220
+
221
+ Util.is_load = false;
222
+ Util.hide_tips();
223
+ });
224
+ }
225
+ },
226
+
184
227
  /**
185
228
  * https://api.jquery.com/jquery.ajax/
186
229
  * $.ajax 方法参数:
@@ -632,13 +675,22 @@ const Util = {
632
675
  return prefix === "6";
633
676
  },
634
677
 
678
+ /**
679
+ * 是否A股股票
680
+ * @param code
681
+ * @returns {boolean}
682
+ */
683
+ is_cn: function (code) {
684
+ return /^\d{6}$/.test(code);
685
+ },
686
+
635
687
  /**
636
688
  * 是否港股
637
689
  * @param code
638
690
  * @returns {boolean}
639
691
  */
640
692
  is_hk: function (code) {
641
- return code.length === 5;
693
+ return /^\d{5}$/.test(code);
642
694
  },
643
695
 
644
696
  /**
@@ -1097,8 +1149,7 @@ const Util = {
1097
1149
  Util.init_modal_skeleton(component_id, modal_content_html);
1098
1150
  let component_obj = $('#' + component_id);
1099
1151
  component_obj.on('shown.bs.modal', function (e) {
1100
- let obj = e.relatedTarget;
1101
- let fund_code = $(obj).attr("data-val");
1152
+ let fund_code = $(e.relatedTarget).attr("data-val");
1102
1153
  Util.fetch_public_fund_detail(fund_code, component_id);
1103
1154
  });
1104
1155
  component_obj.on('hidden.bs.modal', function () {
@@ -1335,8 +1386,7 @@ const Util = {
1335
1386
  });
1336
1387
  let component_obj = $('#' + component_id);
1337
1388
  component_obj.on('shown.bs.modal', function (e) { // 此事件在模态框已经显示出来触发
1338
- let obj = e.relatedTarget;
1339
- let currency = $(obj).attr("data-code");
1389
+ let currency = $(e.relatedTarget).attr("data-code");
1340
1390
  Util.set_table_loading(component_id + "_body_body");
1341
1391
  if ($("#currency_modal_start_date").length <= 0) {
1342
1392
  Util.init_range_date("currency_modal_start_end_date", Util, "render_currency_modal", 60);
@@ -1428,8 +1478,7 @@ const Util = {
1428
1478
  });
1429
1479
  let component_obj = $('#' + component_id);
1430
1480
  component_obj.on('shown.bs.modal', function (e) { // 此事件在模态框已经显示出来触发
1431
- let obj = e.relatedTarget;
1432
- let coin = $(obj).attr("data-coin");
1481
+ let coin = $(e.relatedTarget).attr("data-coin");
1433
1482
  Util.set_table_loading(component_id + "_body_body");
1434
1483
  if ($("#" + component_id + "_start_date").length <= 0) {
1435
1484
  Util.init_range_date(component_id + "_start_end_date", Util, "render_btc_modal", 60);
@@ -2657,9 +2706,7 @@ const Util = {
2657
2706
  * @returns {string}
2658
2707
  */
2659
2708
  digit_compare_trend: function (digit, previous_digit) {
2660
- let cls = "";
2661
- let trend_ratio = "(0)";
2662
- let ratio_val = 0;
2709
+ let cls = "", trend_ratio = "(0)", ratio_val = 0;
2663
2710
  if (digit > 0 && previous_digit > 0) {
2664
2711
  if (digit > previous_digit) {
2665
2712
  cls = "text-danger";