2. 接入项目列表

3. 接入 token 认证
4. 接入退出登录
master
YunaiV 3 years ago
parent 7ad120e2a3
commit 5b9b16d0ec
  1. 4
      src/api/axios.ts
  2. 2
      src/api/path/project.api.ts
  3. 25
      src/api/path/project.d.ts
  4. 2
      src/api/path/system.api.ts
  5. 6
      src/enums/httpEnum.ts
  6. 4
      src/utils/router.ts
  7. 88
      src/utils/utils.ts
  8. 9
      src/views/login/index.vue
  9. 16
      src/views/project/index.vue
  10. 21
      src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts

@ -42,7 +42,7 @@ axiosInstance.interceptors.request.use(
const userInfo = info[SystemStoreEnum.USER_INFO]
config.headers = {
...config.headers,
[userInfo[SystemStoreUserInfoEnum.TOKEN_NAME] || 'token']: userInfo[SystemStoreUserInfoEnum.USER_TOKEN] || ''
[userInfo[SystemStoreUserInfoEnum.TOKEN_NAME] || 'token']: 'Bearer ' + userInfo[SystemStoreUserInfoEnum.USER_TOKEN] || ''
}
return config
},
@ -63,7 +63,7 @@ axiosInstance.interceptors.response.use(
if (code === undefined || code === null) return Promise.resolve(res)
// 成功
if (code === ResultEnum.SUCCESS || code === ResultEnum.DATA_SUCCESS) {
if (code === ResultEnum.SUCCESS) {
return Promise.resolve(res.data)
}

@ -6,7 +6,7 @@ import { ProjectItem, ProjectDetail } from './project'
// * 项目列表
export const projectListApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.GET)<ProjectItem[]>(`${ModuleTypeEnum.PROJECT}/list`, data)
const res = await http(RequestHttpEnum.GET)<any>(`${ModuleTypeEnum.PROJECT}/my-page`, data)
return res
} catch {
httpErrorHandle()

@ -6,29 +6,30 @@ export type ProjectItem = {
/**
*
*/
projectName: string
name: string
/**
* :\
* -1: 未发布\
* 1: 已发布
* :
*
* 0 -
* 1 -
*/
state: number
status: number
/**
*
*/
createTime: string
createTime: number
/**
* url
* URL
*/
indexImage: string
picUrl: string
/**
* id
*
*/
createUserId: string
creator: string
/**
*
*/
remarks: string
remark: string
}
export interface ProjectDetail extends ProjectItem {
@ -36,4 +37,4 @@ export interface ProjectDetail extends ProjectItem {
*
*/
content: string
}
}

@ -17,7 +17,7 @@ export const loginApi = async (data: object) => {
// * 登出
export const logoutApi = async () => {
try {
const res = await http(RequestHttpEnum.GET)(`${ModuleTypeEnum.SYSTEM}/logout`)
const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.SYSTEM}/auth/logout`)
return res
} catch (err) {
httpErrorHandle()

@ -2,13 +2,13 @@
export enum ModuleTypeEnum {
// SYSTEM = 'sys',
SYSTEM = 'system',
PROJECT = 'project',
PROJECT = 'report/go-view/project',
}
// 请求结果集
export enum ResultEnum {
DATA_SUCCESS = 0,
SUCCESS = 200,
// DATA_SUCCESS = 0,
SUCCESS = 0,
SERVER_ERROR = 500,
SERVER_FORBIDDEN = 403,
NOT_FOUND = 404,

@ -203,11 +203,11 @@ export const loginCheck = () => {
/**
* *
* @returns
* @returns
*/
export const previewPath = (id?: string | number) => {
const { origin, pathname } = document.location
const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href')
const previewPath = `${origin}${pathname}${path}/${id || fetchRouteParamsLocation()}`
return previewPath
}
}

@ -317,4 +317,90 @@ export const JSONParse = (data: string) => {
*/
export const setTitle = (title?: string) => {
title && (document.title = title)
}
}
/**
*
* @param date new Date()
* @param format
* @description format `YYYY-mm、YYYY-mm-dd`
* @description format "YYYY-mm-dd HH:MM:SS QQQQ"
* @description format "YYYY-mm-dd HH:MM:SS WWW"
* @description format "YYYY-mm-dd HH:MM:SS ZZZ"
* @description format + + "YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ"
* @returns
*/
export function formatDate(date: Date, format: string): string {
const we = date.getDay() // 星期
const z = getWeek(date) // 周
const qut = Math.floor((date.getMonth() + 3) / 3).toString() // 季度
const opt: { [key: string]: string } = {
'Y+': date.getFullYear().toString(), // 年
'm+': (date.getMonth() + 1).toString(), // 月(月份从0开始,要+1)
'd+': date.getDate().toString(), // 日
'H+': date.getHours().toString(), // 时
'M+': date.getMinutes().toString(), // 分
'S+': date.getSeconds().toString(), // 秒
'q+': qut // 季度
}
// 中文数字 (星期)
const week: { [key: string]: string } = {
'0': '日',
'1': '一',
'2': '二',
'3': '三',
'4': '四',
'5': '五',
'6': '六'
}
// 中文数字(季度)
const quarter: { [key: string]: string } = {
'1': '一',
'2': '二',
'3': '三',
'4': '四'
}
if (/(W+)/.test(format))
format = format.replace(
RegExp.$1,
RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '星期' + week[we] : '周' + week[we]) : week[we]
)
if (/(Q+)/.test(format))
format = format.replace(
RegExp.$1,
RegExp.$1.length == 4 ? '第' + quarter[qut] + '季度' : quarter[qut]
)
if (/(Z+)/.test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 3 ? '第' + z + '周' : z + '')
for (const k in opt) {
const r = new RegExp('(' + k + ')').exec(format)
// 若输入的长度不为1,则前面补零
if (r)
format = format.replace(
r[1],
RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0')
)
}
return format
}
/**
*
* @param dateTime
* @returns
*/
export function getWeek(dateTime: Date): number {
const temptTime = new Date(dateTime.getTime())
// 周几
const weekday = temptTime.getDay() || 7
// 周1+5天=周六
temptTime.setDate(temptTime.getDate() - weekday + 1 + 5)
let firstDay = new Date(temptTime.getFullYear(), 0, 1)
const dayOfWeek = firstDay.getDay()
let spendDay = 1
if (dayOfWeek != 0) spendDay = 7 - dayOfWeek + 1
firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay)
const d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000)
const result = Math.ceil(d / 7)
return result
}

@ -209,15 +209,18 @@ const handleSubmit = async (e: Event) => {
password
})
if(loginRes && loginRes.data) {
// Token
const tokenValue = loginRes.data.accessToken
const tokenName = 'Authorization'
//
const id = loginRes.data.userId
const token = loginRes.data.accessToken
const username = '芋道源码'
const nickname = '芋道源码'
// pinia
systemStore.setItem(SystemStoreEnum.USER_INFO, {
[SystemStoreUserInfoEnum.USER_TOKEN]: token,
[SystemStoreUserInfoEnum.TOKEN_NAME]: '',
[SystemStoreUserInfoEnum.USER_TOKEN]: tokenValue,
[SystemStoreUserInfoEnum.TOKEN_NAME]: tokenName,
[SystemStoreUserInfoEnum.USER_ID]: id,
[SystemStoreUserInfoEnum.USER_NAME]: username,
[SystemStoreUserInfoEnum.NICK_NAME]: nickname,

@ -27,16 +27,16 @@
import { ProjectLayoutSider } from './layout/components/ProjectLayoutSider'
import { LayoutHeaderPro } from '@/layout/components/LayoutHeaderPro'
import { LayoutTransitionMain } from '@/layout/components/LayoutTransitionMain/index'
import { goDialog } from '@/utils'
// import { goDialog } from '@/utils'
//
goDialog({
message: '不要在官方后端上发布任何私密数据,任何人都看得到并进行删除!!!!',
isMaskClosable: true,
closeNegativeText: true,
transformOrigin: 'center',
onPositiveCallback: () => {}
})
// goDialog({
// message: '',
// isMaskClosable: true,
// closeNegativeText: true,
// transformOrigin: 'center',
// onPositiveCallback: () => {}
// })
</script>
<style lang="scss" scoped>

@ -1,9 +1,10 @@
import { ref, reactive } from 'vue'
import { goDialog, httpErrorHandle } from '@/utils'
import { formatDate, goDialog, httpErrorHandle } from '@/utils'
import { DialogEnum } from '@/enums/pluginEnum'
import { projectListApi, deleteProjectApi, changeProjectReleaseApi } from '@/api/path'
import { Chartype, ChartList } from '../../../index.d'
import { ResultEnum } from '@/enums/httpEnum'
import { ProjectItem } from "@/api/path/project";
// 数据初始化
export const useDataListInit = () => {
@ -28,17 +29,17 @@ export const useDataListInit = () => {
limit: paginat.limit
})
if (res && res.data) {
const { count } = res as any // 这里的count与data平级,不在Response结构中
paginat.count = count
list.value = res.data.map(e => {
const { id, projectName, state, createTime, indexImage, createUserId } = e
paginat.count = res.data.count
const projects = res.data.list as ProjectItem[]
list.value = projects.map(e => {
const { id, name, status, createTime, picUrl, creator } = e
return {
id: id,
title: projectName,
createId: createUserId,
time: createTime,
image: indexImage,
release: state !== -1
title: name,
createId: creator,
time: formatDate(new Date(createTime), 'YYY-mm-dd HH:MM:SS'),
image: picUrl,
release: status === 0
}
})
setTimeout(() => {

Loading…
Cancel
Save