up
This commit is contained in:
@@ -16,6 +16,26 @@ use think\facade\View;
|
||||
class Crawler extends BaseController
|
||||
{
|
||||
protected $middleware = [Auth::class];
|
||||
|
||||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
// 对于API方法,直接设置响应头
|
||||
$action = $this->request->action(true);
|
||||
$apiActions = ['getUserConfig', 'saveUserConfig', 'getDsdmOptions', 'getZwdmList', 'getPositionInfo', 'batchGetPositionInfo', 'fetchAllPositions'];
|
||||
|
||||
if (in_array($action, $apiActions)) {
|
||||
// 设置JSON响应头并禁用视图渲染
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
// 禁用视图自动输出
|
||||
$this->app->view->config('auto_render', false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示爬虫工具首页
|
||||
*/
|
||||
@@ -41,9 +61,6 @@ class Crawler extends BaseController
|
||||
*/
|
||||
public function getUserConfig()
|
||||
{
|
||||
// 强制返回JSON,设置响应头
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
try {
|
||||
$username = Session::get('username', '');
|
||||
|
||||
@@ -75,9 +92,6 @@ class Crawler extends BaseController
|
||||
*/
|
||||
public function saveUserConfig()
|
||||
{
|
||||
// 强制返回JSON,设置响应头
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
try {
|
||||
$username = Session::get('username', '');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user