首次提交
This commit is contained in:
22
cdtestplant/src/api/dashboard.ts
Normal file
22
cdtestplant/src/api/dashboard.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import axios from 'axios'
|
||||
import type { TableData } from '@arco-design/web-vue/es/table/interface'
|
||||
|
||||
export interface ContentDataRecord {
|
||||
x: string
|
||||
y: number
|
||||
}
|
||||
|
||||
export function queryContentData() {
|
||||
return axios.get<ContentDataRecord[]>('/api/content-data')
|
||||
}
|
||||
|
||||
export interface PopularRecord {
|
||||
key: number
|
||||
clickNumber: string
|
||||
title: string
|
||||
increases: number
|
||||
}
|
||||
|
||||
export function queryPopularList(params: { type: string }) {
|
||||
return axios.get<TableData[]>('/api/popular/list', { params })
|
||||
}
|
||||
74
cdtestplant/src/api/interceptor.ts
Normal file
74
cdtestplant/src/api/interceptor.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import axios from 'axios'
|
||||
import type { AxiosRequestConfig, AxiosResponse } from 'axios'
|
||||
import { Message, Modal } from '@arco-design/web-vue'
|
||||
import { useUserStore } from '@/store'
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
export interface HttpResponse<T = unknown> {
|
||||
status: number
|
||||
msg: string
|
||||
code: number
|
||||
data: T
|
||||
}
|
||||
|
||||
if (import.meta.env.VITE_API_BASE_URL) {
|
||||
axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL
|
||||
}
|
||||
|
||||
// 添加请求拦截器
|
||||
axios.interceptors.request.use(
|
||||
(config: AxiosRequestConfig) => {
|
||||
// 让每个请求携带令牌
|
||||
// 使用JWT token
|
||||
// 授权是一个自定义header密钥
|
||||
// 获取localStorage中token,如果有token,头没有则加上
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
if (!config.headers) {
|
||||
config.headers = {}
|
||||
}
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
// 做点什么
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
// 添加响应拦截器
|
||||
axios.interceptors.response.use(
|
||||
(response: AxiosResponse<HttpResponse>) => {
|
||||
const res = response.data
|
||||
// 如果自定义代码不是20000,则判断为错误
|
||||
if (res.code !== 20000) {
|
||||
Message.error({
|
||||
content: res.msg || 'Error',
|
||||
duration: 5 * 1000,
|
||||
})
|
||||
// 50008: 非法令牌;50012:其他客户端登录;50014:令牌过期
|
||||
if ([50008, 50012, 50014].includes(res.code) && response.config.url !== '/api/user/info') {
|
||||
Modal.error({
|
||||
title: 'Confirm logout',
|
||||
content: '您已注销,您可以取消以留在此页面,也可以重新登录',
|
||||
okText: 'Re-Login',
|
||||
async onOk() {
|
||||
const userStore = useUserStore()
|
||||
|
||||
await userStore.logout()
|
||||
window.location.reload()
|
||||
},
|
||||
})
|
||||
}
|
||||
return Promise.reject(new Error(res.msg || 'Error'))
|
||||
}
|
||||
return res
|
||||
},
|
||||
(error) => {
|
||||
Message.error({
|
||||
content: error.msg || '请求错误',
|
||||
duration: 5 * 1000,
|
||||
})
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
38
cdtestplant/src/api/message.ts
Normal file
38
cdtestplant/src/api/message.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export interface MessageRecord {
|
||||
id: number
|
||||
type: string
|
||||
title: string
|
||||
subTitle: string
|
||||
avatar?: string
|
||||
content: string
|
||||
time: string
|
||||
status: 0 | 1
|
||||
messageType?: number
|
||||
}
|
||||
export type MessageListType = MessageRecord[]
|
||||
|
||||
export function queryMessageList() {
|
||||
return axios.post<MessageListType>('/api/message/list')
|
||||
}
|
||||
|
||||
interface MessageStatus {
|
||||
ids: number[]
|
||||
}
|
||||
|
||||
export function setMessageStatus(data: MessageStatus) {
|
||||
return axios.post<MessageListType>('/api/message/read', data)
|
||||
}
|
||||
|
||||
export interface ChatRecord {
|
||||
id: number
|
||||
username: string
|
||||
content: string
|
||||
time: string
|
||||
isCollect: boolean
|
||||
}
|
||||
|
||||
export function queryChatList() {
|
||||
return axios.post<ChatRecord[]>('/api/chat/list')
|
||||
}
|
||||
27
cdtestplant/src/api/user.ts
Normal file
27
cdtestplant/src/api/user.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import axios from 'axios'
|
||||
import type { RouteRecordNormalized } from 'vue-router'
|
||||
import { UserState } from '@/store/modules/user/types'
|
||||
|
||||
export interface LoginData {
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface LoginRes {
|
||||
token: string
|
||||
}
|
||||
export function login(data: LoginData) {
|
||||
return axios.post<LoginRes>('/api/user/login', data)
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
return axios.post<LoginRes>('/api/user/logout')
|
||||
}
|
||||
|
||||
export function getUserInfo() {
|
||||
return axios.post<UserState>('/api/user/info')
|
||||
}
|
||||
|
||||
export function getMenuList() {
|
||||
return axios.post<RouteRecordNormalized[]>('/api/user/menu')
|
||||
}
|
||||
27
cdtestplant/src/api/userAbout.ts
Normal file
27
cdtestplant/src/api/userAbout.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import axios from 'axios'
|
||||
import qs from 'query-string'
|
||||
|
||||
export interface PolicyParams {
|
||||
current: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
// 请求用户列表接口
|
||||
export function getUserList(params: PolicyParams) {
|
||||
return axios.get<any>('/api/user/list', {
|
||||
params,
|
||||
paramsSerializer: (obj) => {
|
||||
return qs.stringify(obj)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 请求用户列表删除接口
|
||||
export function deleteUserList(data: any) {
|
||||
return axios.post<any>('/api/user/delete', data)
|
||||
}
|
||||
|
||||
// 全条件搜索接口
|
||||
export function getUserListAll(data: any) {
|
||||
return axios.post<any>('/api/user/all', data)
|
||||
}
|
||||
Reference in New Issue
Block a user