瀏覽代碼

2. 接入项目列表
3. 接入 token 认证
4. 接入退出登录

YunaiV 2 年之前
父節點
當前提交
5b9b16d0ec

+ 2 - 2
src/api/axios.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)
     }
 

+ 1 - 1
src/api/path/project.api.ts

@@ -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()

+ 13 - 12
src/api/path/project.d.ts

@@ -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
-}
+}

+ 1 - 1
src/api/path/system.api.ts

@@ -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()

+ 3 - 3
src/enums/httpEnum.ts

@@ -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,

+ 2 - 2
src/utils/router.ts

@@ -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
-}
+}

+ 87 - 1
src/utils/utils.ts

@@ -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
+}

+ 6 - 3
src/views/login/index.vue

@@ -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,

+ 8 - 8
src/views/project/index.vue

@@ -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>

+ 11 - 10
src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts

@@ -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(() => {