123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- // API基础URL
- const API_BASE_URL = 'http://localhost:3000/api';
- // 岗位相关API
- const JobAPI = {
- // 获取所有岗位
- getAllJobs: async () => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs`);
- if (!response.ok) throw new Error('获取岗位列表失败');
- return await response.json();
- } catch (error) {
- console.error('获取岗位列表错误:', error);
- return [];
- }
- },
-
- // 获取单个岗位详情
- getJobById: async (id) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs/${id}`);
- if (!response.ok) throw new Error('获取岗位详情失败');
- return await response.json();
- } catch (error) {
- console.error('获取岗位详情错误:', error);
- return null;
- }
- },
-
- // 创建新岗位
- createJob: async (jobData) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(jobData)
- });
- if (!response.ok) throw new Error('创建岗位失败');
- return await response.json();
- } catch (error) {
- console.error('创建岗位错误:', error);
- throw error;
- }
- },
-
- // 更新岗位
- updateJob: async (id, jobData) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs/${id}`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(jobData)
- });
- if (!response.ok) throw new Error('更新岗位失败');
- return await response.json();
- } catch (error) {
- console.error('更新岗位错误:', error);
- throw error;
- }
- },
-
- // 删除岗位
- deleteJob: async (id) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs/${id}`, {
- method: 'DELETE'
- });
- if (!response.ok) throw new Error('删除岗位失败');
- return await response.json();
- } catch (error) {
- console.error('删除岗位错误:', error);
- throw error;
- }
- },
-
- // 启动智能筛选
- startScreening: async (id) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs/${id}/screen`, {
- method: 'POST'
- });
- if (!response.ok) throw new Error('启动筛选失败');
- return await response.json();
- } catch (error) {
- console.error('启动筛选错误:', error);
- throw error;
- }
- },
-
- // 获取岗位候选人列表
- getJobCandidates: async (id) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs/${id}/candidates`);
- if (!response.ok) throw new Error('获取候选人列表失败');
- return await response.json();
- } catch (error) {
- console.error('获取候选人列表错误:', error);
- return { candidates: [] };
- }
- },
-
- // 发布草稿岗位
- publishDraft: async (id) => {
- try {
- const response = await fetch(`${API_BASE_URL}/jobs/${id}/publish`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({})
- });
- if (!response.ok) throw new Error('发布岗位失败');
- return await response.json();
- } catch (error) {
- console.error('发布岗位错误:', error);
- throw error;
- }
- }
- };
- // 候选人相关API
- const CandidateAPI = {
- // 获取所有候选人
- getAllCandidates: async () => {
- try {
- const response = await fetch(`${API_BASE_URL}/candidates`);
- if (!response.ok) throw new Error('获取候选人列表失败');
- return await response.json();
- } catch (error) {
- console.error('获取候选人列表错误:', error);
- return [];
- }
- },
-
- // 获取单个候选人详情
- getCandidateDetails: async (id) => {
- try {
- const response = await fetch(`${API_BASE_URL}/candidates/${id}`);
- if (!response.ok) throw new Error('获取候选人详情失败');
- return await response.json();
- } catch (error) {
- console.error('获取候选人详情错误:', error);
- return null;
- }
- },
-
- // 更新候选人状态
- updateCandidateStatus: async (id, status) => {
- try {
- const response = await fetch(`${API_BASE_URL}/candidates/${id}/status`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({ status })
- });
- if (!response.ok) throw new Error('更新候选人状态失败');
- return await response.json();
- } catch (error) {
- console.error('更新候选人状态错误:', error);
- throw error;
- }
- },
-
- // 添加候选人
- addCandidate: async (candidateData) => {
- try {
- const response = await fetch(`${API_BASE_URL}/candidates`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(candidateData)
- });
- if (!response.ok) throw new Error('添加候选人失败');
- return await response.json();
- } catch (error) {
- console.error('添加候选人错误:', error);
- throw error;
- }
- }
- };
- // 统计数据相关API
- const StatisticsAPI = {
- // 获取招聘总览统计
- getOverviewStats: async () => {
- try {
- const response = await fetch(`${API_BASE_URL}/statistics/overview`);
- if (!response.ok) throw new Error('获取招聘总览统计失败');
- return await response.json();
- } catch (error) {
- console.error('获取招聘总览统计错误:', error);
- return {
- totalJobs: 0,
- totalCandidates: 0,
- pendingResumes: 0,
- passedResumes: 0
- };
- }
- },
-
- // 获取部门招聘统计
- getDepartmentStats: async () => {
- try {
- const response = await fetch(`${API_BASE_URL}/statistics/departments`);
- if (!response.ok) throw new Error('获取部门招聘统计失败');
- return await response.json();
- } catch (error) {
- console.error('获取部门招聘统计错误:', error);
- return [];
- }
- },
-
- // 获取筛选效率统计
- getScreeningEfficiencyStats: async () => {
- try {
- const response = await fetch(`${API_BASE_URL}/statistics/screening-efficiency`);
- if (!response.ok) throw new Error('获取筛选效率统计失败');
- return await response.json();
- } catch (error) {
- console.error('获取筛选效率统计错误:', error);
- return [];
- }
- },
-
- // 获取候选人评分分布
- getScoreDistribution: async () => {
- try {
- const response = await fetch(`${API_BASE_URL}/statistics/score-distribution`);
- if (!response.ok) throw new Error('获取候选人评分分布失败');
- return await response.json();
- } catch (error) {
- console.error('获取候选人评分分布错误:', error);
- return [];
- }
- }
- };
- // 导出API
- const API = {
- Job: JobAPI,
- Candidate: CandidateAPI,
- Statistics: StatisticsAPI
- };
- // 全局挂载API
- window.API = API;
|