From e2b79ce57d8d922ee3614011c07893c359968930 Mon Sep 17 00:00:00 2001 From: James-chok <305580798@qq.com> Date: Mon, 7 Aug 2023 15:08:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(stock):=20=E7=8A=B6=E6=80=81=E6=A0=8F?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=B8=AF=E8=82=A1=E6=98=BE=E7=A4=BA=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/explorer/stockService.ts | 14 ++++++++------ yarn.lock | 5 +++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ca73088b..23cfcff5 100644 --- a/package.json +++ b/package.json @@ -764,6 +764,7 @@ "iconv-lite": "^0.6.2", "lodash.clonedeep": "^4.5.0", "lodash.throttle": "^4.1.1", + "moment": "^2.29.4", "public-ip": "^4.0.3", "ws": "^7.4.1" }, diff --git a/src/explorer/stockService.ts b/src/explorer/stockService.ts index 22e1e7af..6557ca9f 100644 --- a/src/explorer/stockService.ts +++ b/src/explorer/stockService.ts @@ -6,6 +6,7 @@ import { LeekTreeItem } from '../shared/leekTreeItem'; import { executeStocksRemind } from '../shared/remindNotification'; import { calcFixedPriceNumber, events, formatNumber, randHeader, sortData } from '../shared/utils'; import { LeekService } from './leekService'; +import moment = require('moment'); export default class StockService extends LeekService { public stockList: Array = []; @@ -37,9 +38,9 @@ export default class StockService extends LeekService { // 兼容2.1-2.5版本中以大写开头及cnf_开头的期货代码 const transFuture = (code: string) => { - if(/^[A-Z]+/.test(code)){ + if (/^[A-Z]+/.test(code)) { return code.replace(/^[A-Z]+/, (it: string) => `nf_${it}`); - } else if(/cnf_/.test(code)){ + } else if (/cnf_/.test(code)) { return code.replace('cnf_', 'nf_'); } return code; @@ -211,7 +212,7 @@ export default class StockService extends LeekService { 新浪接口对于商品期货的 昨收盘返回 0.0,导致无法计算【昨收盘涨跌幅】,只能计算【结算涨跌幅】。 使用期货的结算价对应 股票通用的 【昨收盘 yestclose】字段以方便计算涨跌幅的显示。 */ - let yestclose = params[8 + 2]; + let yestclose = params[8 + 2]; let volume = params[8 + 6]; // 成交量 //股指期货 const stockIndexFuture = /nf_IC/.test(code) // 中证500 @@ -223,7 +224,7 @@ export default class StockService extends LeekService { || /nf_T\d+/.test(code) // 十债 || /nf_TL/.test(code) // 三十年国债 ; - if(stockIndexFuture){ + if (stockIndexFuture) { // 0 开盘 1 最高 2 最低 3 收盘 // ['5372.000', '5585.000', '5343.000', '5581.600', // 4 成交量 6 持仓量 @@ -413,6 +414,7 @@ export default class StockService extends LeekService { volume: formatNumber(quote.volume || 0, 2), amount: formatNumber(quote.amount || 0, 2), percent: '', + time: `${moment(quote.time).format('YYYY-MM-DD HH:mm:ss')}`, }; hkStockCount += 1; if (stockItem) { @@ -495,9 +497,9 @@ export default class StockService extends LeekService { let market = arr[1]; code = code.toUpperCase(); // 国内交易所 - if(market === '85' || market === '88'){ + if (market === '85' || market === '88') { code = 'nf_' + code; - }else if(market === '86'){ + } else if (market === '86') { // 海外交易所 code = 'hf_' + code; } diff --git a/yarn.lock b/yarn.lock index b7a4d724..7dbf3e4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2713,6 +2713,11 @@ modify-values@^1.0.0: resolved "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022" integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw== +moment@^2.29.4: + version "2.29.4" + resolved "https://registry.npmmirror.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" + integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== + ms@2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"