This commit is contained in:
杨志
2026-01-21 09:07:10 +08:00
parent e5396f5f83
commit 35f9f6f31f
5 changed files with 292 additions and 1 deletions

View File

@@ -6,6 +6,8 @@ namespace app\controller;
use app\BaseController;
use app\middleware\Auth;
use app\service\CrawlerService;
use app\service\UserConfigService;
use think\facade\Session;
use think\facade\View;
/**
@@ -19,8 +21,77 @@ class Crawler extends BaseController
*/
public function index()
{
// 获取当前用户的配置
$username = Session::get('username', '');
$config = [];
if ($username) {
$configService = new UserConfigService();
$config = $configService->getUserConfig($username);
}
// 将配置传递给视图
View::assign('userConfig', $config);
return View::fetch();
}
/**
* 获取用户配置
*/
public function getUserConfig()
{
header('Content-Type: application/json; charset=utf-8');
$username = Session::get('username', '');
if (empty($username)) {
return json([
'code' => 0,
'msg' => '未登录',
]);
}
$configService = new UserConfigService();
$config = $configService->getUserConfig($username);
return json([
'code' => 1,
'data' => $config,
'msg' => '获取成功',
]);
}
/**
* 保存用户配置
*/
public function saveUserConfig()
{
header('Content-Type: application/json; charset=utf-8');
$username = Session::get('username', '');
if (empty($username)) {
return json([
'code' => 0,
'msg' => '未登录',
]);
}
$config = [
'jsessionid1' => $this->request->param('jsessionid1', ''),
'jsessionid2' => $this->request->param('jsessionid2', ''),
'serverid' => $this->request->param('serverid', ''),
'examid' => $this->request->param('examid', ''),
'bmid' => $this->request->param('bmid', ''),
'userid' => $this->request->param('userid', ''),
];
$configService = new UserConfigService();
$result = $configService->saveUserConfig($username, $config);
return json($result);
}
/**
* 获取地区选项从网页HTML中提取