Browse Source
feat(stock): 实现股票行情接口和动态刷新功能
feat(stock): 实现股票行情接口和动态刷新功能
- 新增 StockController 类,提供股票行情数据接口 - 在前端实现股票信息的定时刷新,支持局部更新 - 更新投资页面和页脚组件,整合股票信息展示,添加数据属性以支持动态更新 - 移除冗余的定时刷新脚本,优化代码结构master
4 changed files with 134 additions and 97 deletions
-
35app/controller/frontend/StockController.php
-
84public/themes/dist_static/static/js/common.js
-
48public/themes/website/1/zh/demo/components/footer.html
-
64public/themes/website/1/zh/demo/investment.html
@ -0,0 +1,35 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
|
|||
namespace app\controller\frontend; |
|||
|
|||
/** |
|||
* 股票行情接口(供页脚 / 投资者关系局部刷新) |
|||
*/ |
|||
class StockController extends BaseController |
|||
{ |
|||
public function quote(): \think\response\Json |
|||
{ |
|||
$code = (string)$this->request->param('code', '603933'); |
|||
if (!preg_match('/^\d{6}$/', $code)) { |
|||
$code = '603933'; |
|||
} |
|||
|
|||
$stock = getStockInfo($code); |
|||
$change = (string)($stock['change'] ?? '--'); |
|||
$color = ''; |
|||
if ($change !== '--' && $change !== '') { |
|||
if ($change[0] === '+') { |
|||
$color = '#ef4335'; |
|||
} elseif ($change[0] === '-') { |
|||
$color = '#00b894'; |
|||
} |
|||
} |
|||
|
|||
$stock['color'] = $color; |
|||
$market = $code[0] === '6' ? 'sh' : 'sz'; |
|||
$stock['chart'] = "https://image.sinajs.cn/newchart/min/n/{$market}{$code}.gif"; |
|||
|
|||
return jsonReturn(0, 'success', $stock); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue