首次提交

This commit is contained in:
2023-06-04 20:01:58 +08:00
parent 00c64c53bb
commit 587f078d21
560 changed files with 106725 additions and 0 deletions

View 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 })
}

View 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)
}
)

View 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')
}

View 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')
}

View 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)
}