u
This commit is contained in:
1 parent
07e0001b87
commit
46cbb2f50d
543 files changed
+32576
-4231
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import type { AuthCodeSendParams, AuthCodeSendResult, AuthCodeVerifyParams, AuthCodeVerifyResult } from '@/types/auth/code'
|
||||
import { httpPostJson } from '@/request/utils'
|
||||
|
||||
export function authCodeSendApi(params: AuthCodeSendParams) {
|
||||
return httpPostJson<AuthCodeSendResult>(`/auth/code/send`, params)
|
||||
}
|
||||
|
||||
export function authCodeVerifyApi(params: AuthCodeVerifyParams) {
|
||||
return httpPostJson<AuthCodeVerifyResult>(`/auth/code/verify`, params)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { ForgetApiParams, LoginApiResult, LoginEmailCodeApiParams, LoginPasswordApiParams, RegisterApiParams } from '@/types/auth/index'
|
||||
import { httpPostJson } from '@/request/utils'
|
||||
|
||||
export function registerApi(params: RegisterApiParams) {
|
||||
return httpPostJson<void>('/auth/identity/register', params)
|
||||
}
|
||||
|
||||
export function loginByPasswordApi(params: LoginPasswordApiParams) {
|
||||
return httpPostJson<LoginApiResult>('/auth/identity/login/password', params)
|
||||
}
|
||||
|
||||
export function loginByEmailCodeApi(params: LoginEmailCodeApiParams) {
|
||||
return httpPostJson<LoginApiResult>('/auth/identity/login/emailCode', params)
|
||||
}
|
||||
|
||||
export function forgetApi(params: ForgetApiParams) {
|
||||
return httpPostJson<void>('/auth/identity/forget', params)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { AddFileParams, GetAliyunKeyResult } from '@/types/base'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
export function getAliyunKeyApi() {
|
||||
return httpGet<GetAliyunKeyResult>(`/base/file/getAliyunKey`)
|
||||
}
|
||||
|
||||
export function addFileApi(params: AddFileParams) {
|
||||
return httpPostJson<void>(`/base/file/add`, params)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { Area, Company, CompanyDetail, Industry, QueryCompanyParams, RecommendCompany, RecommendHotCompany, UpdateCompanyParams } from '@/types/company'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
export function getRecommendCompanyApi() {
|
||||
return httpGet<RecommendCompany[]>('/company/recommend')
|
||||
}
|
||||
|
||||
export function getRecommendHotCompanyApi() {
|
||||
return httpGet<RecommendHotCompany[]>('/company/recommend/hot')
|
||||
}
|
||||
|
||||
export function queryCompanyApi(params: QueryCompanyParams) {
|
||||
return httpPostJson<BasePageResult<Company>>('/company/query', params)
|
||||
}
|
||||
|
||||
export function getCompanyDetailApi(id: number) {
|
||||
return httpGet<CompanyDetail>(`/company/detail/${id}`)
|
||||
}
|
||||
|
||||
export function updateCompanyApi(params: UpdateCompanyParams) {
|
||||
return httpPostJson<void>(`/company/update`, params)
|
||||
}
|
||||
|
||||
export function listAreasApi() {
|
||||
return httpGet<Area[]>('/company/area')
|
||||
}
|
||||
|
||||
export function listIndustriesApi() {
|
||||
return httpGet<Industry[]>('/company/industry')
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { AddCompanyUserParams, ChatCompanyUser, CompanyUser, CompanyUserProfile, DeleteCompanyUserParams, QueryCompanyUserParams, UpdateCompanyUserParams } from '@/types/company/user'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
export function queryCompanyUserApi(params: QueryCompanyUserParams) {
|
||||
return httpPostJson<BasePageResult<CompanyUser>>('/company/user/query', params)
|
||||
}
|
||||
export function addCompanyUserApi(params: AddCompanyUserParams) {
|
||||
return httpPostJson<void>('/company/user/add', params)
|
||||
}
|
||||
export function updateCompanyUserApi(params: UpdateCompanyUserParams) {
|
||||
return httpPostJson<void>('/company/user/update', params)
|
||||
}
|
||||
export function deleteCompanyUserApi(params: DeleteCompanyUserParams) {
|
||||
return httpPostJson<void>('/company/user/delete', params)
|
||||
}
|
||||
|
||||
export function listChatCompanyUsersApi(companyId: number) {
|
||||
return httpGet<ChatCompanyUser[]>(`/company/user/chat/${companyId}`)
|
||||
}
|
||||
|
||||
export function getCompanyUserProfileApi(userId: number) {
|
||||
return httpGet<CompanyUserProfile>(`/company/user/profile/${userId}`)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { CreateFriendParams, ImFriend, ImFriendProfile, ImGroup, ImGroupMessage, ImGroupProfile, ImGroupUser, ImPrivateMessage, QueryFriendParams, QueryGroupMessageParams, QueryGroupParams, QueryGroupUserParams, QueryPrivateMessageParams, UpdateGroupUnreadParams, UpdatePrivateUnreadParams } from '@/types/im'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
export function createFriendApi(params: CreateFriendParams) {
|
||||
return httpPostJson<void>(`/im/friend/create`, params)
|
||||
}
|
||||
|
||||
export function queryFriendApi(params: QueryFriendParams) {
|
||||
return httpPostJson<BasePageResult<ImFriend>>('/im/friend/query', params)
|
||||
}
|
||||
|
||||
export function queryGroupApi(params: QueryGroupParams) {
|
||||
return httpPostJson<BasePageResult<ImGroup>>('/im/group/query', params)
|
||||
}
|
||||
|
||||
export function queryPrivateMessageApi(params: QueryPrivateMessageParams) {
|
||||
return httpPostJson<ImPrivateMessage[]>('/im/friend/message/query', params)
|
||||
}
|
||||
export function queryGroupMessageApi(params: QueryGroupMessageParams) {
|
||||
return httpPostJson<ImGroupMessage[]>('/im/group/message/query', params)
|
||||
}
|
||||
|
||||
export function updateGroupUnreadApi(params: UpdateGroupUnreadParams) {
|
||||
return httpPostJson<void>('/im/group/update/unread', params)
|
||||
}
|
||||
|
||||
export function updatePrivateUnreadApi(params: UpdatePrivateUnreadParams) {
|
||||
return httpPostJson<void>('/im/private/update/unread', params)
|
||||
}
|
||||
|
||||
export function queryGroupUserApi(params: QueryGroupUserParams) {
|
||||
return httpPostJson<ImGroupUser[]>('/im/group/user/query', params)
|
||||
}
|
||||
|
||||
export function getFriendProfileApi(friendId: number) {
|
||||
return httpGet<ImFriendProfile>(`/im/friend/${friendId}`)
|
||||
}
|
||||
|
||||
export function getGroupProfileApi(groupId: number) {
|
||||
return httpGet<ImGroupProfile>(`/im/group/${groupId}`)
|
||||
}
|
||||
|
||||
export function getUnreadCountApi() {
|
||||
return httpGet<number>('/im/unreadCount')
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { DashboardData } from '@/types/post'
|
||||
import type {
|
||||
CreatePostParams,
|
||||
Post,
|
||||
PostEditorForm,
|
||||
QueryPostParams,
|
||||
UpdatePostParams,
|
||||
UpdatePostStatusParams,
|
||||
} from '@/types/post/editor'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
// ===== 编辑端 API =====
|
||||
export function createPostApi(params: CreatePostParams) {
|
||||
return httpPostJson<PostEditorForm>('/post/editor/create', params)
|
||||
}
|
||||
|
||||
export function updatePostApi(params: UpdatePostParams) {
|
||||
return httpPostJson<PostEditorForm>('/post/editor/update', params)
|
||||
}
|
||||
|
||||
export function updatePostStatusApi(params: UpdatePostStatusParams) {
|
||||
return httpPostJson<PostEditorForm>('/post/editor/update/status', params)
|
||||
}
|
||||
|
||||
export function queryEditorPostsApi(params: QueryPostParams) {
|
||||
return httpPostJson<BasePageResult<Post>>('/post/editor/query', params)
|
||||
}
|
||||
|
||||
export function getEditorPostApi(id: number) {
|
||||
return httpGet<PostEditorForm>(`/post/editor/${id}`)
|
||||
}
|
||||
|
||||
export function deletePostApi(postId: number) {
|
||||
return httpPostJson<void>(`/post/editor/delete/${postId}`)
|
||||
}
|
||||
|
||||
export function getEditorDashboardApi() {
|
||||
return httpGet<DashboardData>(`/post/editor/dashboard`)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { CreatePostCommentParams, CreatePostCommentResult, PostAuthorProfile, PostComment, PostTag, PublicPost, PublicPostDetail, QueryPublicPostParams } from '@/types/post'
|
||||
import { httpGet, httpPostJson } from '@/request/utils'
|
||||
|
||||
// ===== 公共接口 =====
|
||||
export function listPostTagApi() {
|
||||
return httpGet<PostTag[]>('/post/tag')
|
||||
}
|
||||
|
||||
export function queryPublicPostApi(params: QueryPublicPostParams) {
|
||||
return httpPostJson<BasePageResult<PublicPost>>('/post/query', params)
|
||||
}
|
||||
|
||||
export function getPublicPostDetailApi(id: number) {
|
||||
return httpGet<PublicPostDetail>(`/post/${id}`)
|
||||
}
|
||||
|
||||
export function getAuthorProfileByPostId(id: number) {
|
||||
return httpGet<PostAuthorProfile>(`/post/author/${id}`)
|
||||
}
|
||||
|
||||
export function createPostCommentApi(params: CreatePostCommentParams) {
|
||||
return httpPostJson<CreatePostCommentResult>(`/post/comment/create`, params)
|
||||
}
|
||||
|
||||
export function listPostCommentApi(id: number) {
|
||||
return httpGet<PostComment[]>(`/post/comment/${id}`)
|
||||
}
|
||||
|
||||
export function deletePostCommentApi(id: number) {
|
||||
return httpPostJson<void>(`/post/comment/delete/${id}`)
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import type { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { router } from '@/router/index'
|
||||
import { useUserStore } from '@/store/user'
|
||||
|
||||
function buildBaseUrl() {
|
||||
const mode = import.meta.env.MODE
|
||||
const isProxy = import.meta.env.VITE_APP_PROXY === 'Y'
|
||||
const proxyPrefix = import.meta.env.VITE_APP_PROXY_PREFIX || '/api'
|
||||
const baseURL = import.meta.env.VITE_SERVER_BASEURL
|
||||
|
||||
if (mode === 'prod' && isProxy) {
|
||||
if (isProxy) {
|
||||
return proxyPrefix
|
||||
}
|
||||
else {
|
||||
return baseURL
|
||||
}
|
||||
}
|
||||
|
||||
// 开发环境
|
||||
if (isProxy) {
|
||||
return proxyPrefix
|
||||
}
|
||||
|
||||
return baseURL
|
||||
}
|
||||
|
||||
const axiosInstance: AxiosInstance = axios.create({
|
||||
baseURL: buildBaseUrl(),
|
||||
timeout: 0,
|
||||
})
|
||||
|
||||
const NoFreePaths = [
|
||||
'/imMessage/**',
|
||||
'/file/**',
|
||||
'/company/getPrivateDetail',
|
||||
]
|
||||
|
||||
// 请求拦截器
|
||||
axiosInstance.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
// const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const path = config.url || ''
|
||||
|
||||
const needAuth = matchPaths(path, NoFreePaths)
|
||||
|
||||
if (needAuth) {
|
||||
if (!userStore.isLogined) {
|
||||
userStore.clear()
|
||||
router.push('/login')
|
||||
return Promise.reject(new Error('尚未登录,请先登录!'))
|
||||
}
|
||||
}
|
||||
|
||||
config.headers.Authorization = `Bearer ${userStore.token}`
|
||||
config.headers['X-Company-Id'] = userStore.company.id
|
||||
config.headers['X-User-Id'] = userStore.user.id
|
||||
|
||||
return config
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
console.log('===ReqError===')
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
axiosInstance.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
// 判断响应是否为文件下载类型
|
||||
const isDownload = isDownloadResponse(response.headers)
|
||||
if (isDownload) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response.status !== 200) {
|
||||
return Promise.reject(new Error('系统异常'))
|
||||
}
|
||||
|
||||
const resData = response.data as ResponseData<any>
|
||||
|
||||
if (resData.code === 401) {
|
||||
router.push('/auth/login')
|
||||
return Promise.resolve(response.data)
|
||||
}
|
||||
else if (resData.code === 404) {
|
||||
router.push('/error/404')
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
else if (resData.data === 500) {
|
||||
ElMessage.error('系统异常,请稍后再试')
|
||||
return Promise.resolve(response.data)
|
||||
}
|
||||
else {
|
||||
resData.isSuccess = resData.code === 200
|
||||
return Promise.resolve(response.data)
|
||||
}
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
console.log(error)
|
||||
|
||||
if (error.status === 500) {
|
||||
router.push('/error/500')
|
||||
}
|
||||
|
||||
if (error.status === 404) {
|
||||
router.push('/error/404')
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
function matchPaths(path: string, patterns: string[]): boolean {
|
||||
return patterns.some((pattern) => {
|
||||
const regex = new RegExp(
|
||||
`${pattern
|
||||
.replace(/\/\*\*/g, '(/.*)?')
|
||||
.replace(/\/\*/g, '(/[^/]*)?')
|
||||
.replace(/\./g, '\\.')}$`,
|
||||
)
|
||||
return regex.test(path)
|
||||
})
|
||||
}
|
||||
|
||||
function isDownloadResponse(headers: any): boolean {
|
||||
const contentType = headers['content-type']
|
||||
return /application\/(?:octet-stream|force-download|pdf|vnd.ms-excel|msexcel|OCTET-STREAM)/.test(contentType || '')
|
||||
}
|
||||
|
||||
export default axiosInstance
|
||||
@@ -0,0 +1,21 @@
|
||||
import axiosInstance from './index'
|
||||
|
||||
export function httpGet<T>(url: string, params?: Record<string, any>): Promise<ResponseData<T>> {
|
||||
return axiosInstance.get(url, { params })
|
||||
}
|
||||
|
||||
export function httpPostJson<T>(url: string, data?: Record<string, any>): Promise<ResponseData<T>> {
|
||||
return axiosInstance.post(url, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function httpPostForm<T>(url: string, data?: any): Promise<ResponseData<T>> {
|
||||
return axiosInstance.post(url, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user