Browse Source

feat: 权限接口实现

feature/three
guoapeng 3 months ago
parent
commit
6ad52ff5a9
  1. 2
      server/index.js
  2. 22
      server/routes/auth.js
  3. 2
      src/hooks/useApiData.ts
  4. 6
      src/views/login/index.vue

2
server/index.js

@ -1,5 +1,6 @@
// const express = require('express')
import express from 'express'
import { authRoutes } from './routes/auth.js'
import { debugRoutes } from './routes/debug.js'
import { initWebSocketServer } from './utils/websocket.js'
@ -16,3 +17,4 @@ initWebSocketServer()
// 注册路由模块
debugRoutes(app)
authRoutes(app)

22
server/routes/auth.js

@ -0,0 +1,22 @@
const baseUrl = '/api/auth'
export const authRoutes = (app) => {
app.post(`${baseUrl}/login`, (req, res) => {
// const { username, password } = req.body
const mockResponse = {
code: '0',
msg: '成功',
data: {
id: 1,
createTime: '2025-04-27 07:44:01',
updateTime: '2025-04-27 07:44:01',
username: 'admin',
nickname: 'Admin',
password: null,
role: 'ADMIN',
deleted: 'DISABLE',
fixedUser: 'ENABLE',
},
}
res.json(mockResponse)
})
}

2
src/hooks/useApiData.ts

@ -4,7 +4,7 @@ import { ref } from 'vue'
export default function useApiData(url: string, params?: any, init?: boolean) {
const data = ref(null)
const loading = ref(false)
const error = ref(null)
const error = ref()
const fetchData = async () => {
loading.value = true
error.value = null

6
src/views/login/index.vue

@ -1,4 +1,5 @@
<script setup lang="ts">
import { login } from 'apis/login'
import { setToken } from 'libs/token'
import { useSystemStore } from 'stores/systemStore'
import { onBeforeUnmount, onMounted, ref } from 'vue'
@ -21,6 +22,11 @@ const startProgress = () => {
setToken('111')
useSystemStore().updateSystemUser({ username: '管理员' })
router.push('/')
login({ username: 'admin', password: '12345' }).then((res) => {
setToken('111')
useSystemStore().updateSystemUser({ username: res.username })
router.push('/')
})
}
}, 100)
}

Loading…
Cancel
Save