- You’ve successfully created a project with
- Vite +
- Vue 3. What's next?
-
-
-
-
-
diff --git a/src/components/TheWelcome.vue b/src/components/TheWelcome.vue
deleted file mode 100644
index 49d8f73..0000000
--- a/src/components/TheWelcome.vue
+++ /dev/null
@@ -1,88 +0,0 @@
-
-
-
-
-
-
-
- Documentation
-
- Vue’s
- official documentation
- provides you with all information you need to get started.
-
-
-
-
-
-
- Tooling
-
- This project is served and bundled with
- Vite. The
- recommended IDE setup is
- VSCode +
- Volar. If
- you need to test your components and web pages, check out
- Cypress and
- Cypress Component Testing.
-
-
-
- More instructions are available in README.md.
-
-
-
-
-
-
- Ecosystem
-
- Get official tools and libraries for your project:
- Pinia,
- Vue Router,
- Vue Test Utils, and
- Vue Dev Tools. If
- you need more resources, we suggest paying
- Awesome Vue
- a visit.
-
-
-
-
-
-
- Community
-
- Got stuck? Ask your question on
- Vue Land, our official
- Discord server, or
- StackOverflow. You should also subscribe to
- our mailing list and follow
- the official
- @vuejs
- twitter account for latest news in the Vue world.
-
-
-
-
-
-
- Support Vue
-
- As an independent project, Vue relies on community backing for its sustainability. You can help
- us by
- becoming a sponsor.
-
-
diff --git a/src/components/WelcomeItem.vue b/src/components/WelcomeItem.vue
deleted file mode 100644
index 6d7086a..0000000
--- a/src/components/WelcomeItem.vue
+++ /dev/null
@@ -1,87 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/config/config.ts b/src/config/config.ts
new file mode 100644
index 0000000..aae1976
--- /dev/null
+++ b/src/config/config.ts
@@ -0,0 +1,5 @@
+export const baseUrl = import.meta.env.MODE === 'development' ? '/api' : '/api/v1'
+
+export const imageUrl = import.meta.env.MODE === 'development' ? '/img_url' : ''
+
+export const app_code:string = 'user-busniss-center'
\ No newline at end of file
diff --git a/src/main.ts b/src/main.ts
index 5dcad83..320f8ee 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,14 +1,19 @@
-import './assets/main.css'
-
+// import './assets/main.css'
+import { setupStore } from './stores/store'
+import Antd from "ant-design-vue"
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
-import router from './router'
+import router from './router/router'
+import {setupRouter} from './router/router'
const app = createApp(App)
app.use(createPinia())
app.use(router)
-
+app.use(Antd)
+setupStore(app)
+setupRouter(app)
+await router.isReady()
app.mount('#app')
diff --git a/src/router/guard/guard.ts b/src/router/guard/guard.ts
new file mode 100644
index 0000000..ecff9f0
--- /dev/null
+++ b/src/router/guard/guard.ts
@@ -0,0 +1,43 @@
+import { getToken } from "@/utils/auth";
+import type { Route } from "ant-design-vue/es/breadcrumb/Breadcrumb";
+import type { Router } from "vue-router";
+import {user} from '@/api/user/api'
+import type {IUser} from '@/api/user/model'
+import type { IMenu } from "@/api/application/menu";
+import {useUserStore} from "@/stores/modules/user"
+
+const whiteList = ["/login"]
+
+export function createRouterGuard(router:Router){
+ router.beforeEach(async (to,from,next) =>{
+ if (getToken()){
+ // 获取菜单,构建router和menu
+ const userInfo = await user({})
+ if (userInfo){
+ //
+ const userStore = useUserStore()
+ if (userInfo.data.menus){
+ // 构建菜单
+ // 构建路由
+ userStore.menus = userInfo.data.menus
+ createRouter(router,userInfo.data.menus)
+ }
+ }
+ }else{
+ // 没有token跳转到登陆
+ if (whiteList.indexOf(to.path) !== -1){
+ next()
+ }else{
+ // todo 调用登出接口,删除store等内容
+
+ }
+ }
+ })
+}
+
+function createRouter(router:Router,menus:IMenu[]){
+ // todo 创建路由
+ menus.forEach((menu) =>{
+ router.addRoute()
+ })
+}
diff --git a/src/router/index.ts b/src/router/index.ts
deleted file mode 100644
index a49ae50..0000000
--- a/src/router/index.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { createRouter, createWebHistory } from 'vue-router'
-import HomeView from '../views/HomeView.vue'
-
-const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes: [
- {
- path: '/',
- name: 'home',
- component: HomeView
- },
- {
- path: '/about',
- name: 'about',
- // route level code-splitting
- // this generates a separate chunk (About.[hash].js) for this route
- // which is lazy-loaded when the route is visited.
- component: () => import('../views/AboutView.vue')
- }
- ]
-})
-
-export default router
diff --git a/src/router/router.ts b/src/router/router.ts
new file mode 100644
index 0000000..335d704
--- /dev/null
+++ b/src/router/router.ts
@@ -0,0 +1,79 @@
+import { createRouter, createWebHistory } from 'vue-router'
+import type { RouteRecordRaw } from "vue-router"
+import type {App} from "vue"
+
+const routers: RouteRecordRaw[] = [
+ // {
+ // path: '/',
+ // name: 'home',
+ // component: () => import('../views/home/home.vue')
+ // },
+ {
+ path: '/login',
+ name: 'login',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('../views/login/index.vue')
+ },
+ {
+ path: '/user',
+ name: 'user',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('../views/user/user.vue')
+ },
+ {
+ path: '/organization',
+ name: 'organization',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('../views/organization/organization.vue')
+ },
+ {
+ path: '/role',
+ name: 'role',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('../views/role/role.vue')
+ },
+ {
+ path: '/application',
+ name: 'application',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('../views/application/application.vue'),
+ children:[
+ {
+ path:'menu',
+ name:'menu',
+ component:() => import('../views/application/menu/menu.vue'),
+ }
+
+ ]
+ },
+ {
+ path: '/application',
+ name: 'application',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('../views/application/application.vue')
+ },
+ ]
+
+const router = createRouter({
+ history:createWebHistory('/'),
+ routes:routers,
+ scrollBehavior: () => ({ left: 0, top: 0 }),
+})
+
+export const setupRouter = (app:App) => {
+ app.use(router)
+}
+
+export default router
diff --git a/src/stores/counter.ts b/src/stores/counter.ts
deleted file mode 100644
index b6757ba..0000000
--- a/src/stores/counter.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { ref, computed } from 'vue'
-import { defineStore } from 'pinia'
-
-export const useCounterStore = defineStore('counter', () => {
- const count = ref(0)
- const doubleCount = computed(() => count.value * 2)
- function increment() {
- count.value++
- }
-
- return { count, doubleCount, increment }
-})
diff --git a/src/stores/modules/app.ts b/src/stores/modules/app.ts
new file mode 100644
index 0000000..0871b64
--- /dev/null
+++ b/src/stores/modules/app.ts
@@ -0,0 +1,23 @@
+import { defineStore } from "pinia";
+
+interface appStore{
+ loading:boolean
+ name:string
+}
+
+export const useAppStore = defineStore("user",{
+ state: () :appStore =>{
+ return {
+ loading:false,
+ name:"用户中心"
+ }
+ },
+
+ getters:{
+
+ },
+
+ actions:{
+
+ }
+})
\ No newline at end of file
diff --git a/src/stores/modules/user.ts b/src/stores/modules/user.ts
new file mode 100644
index 0000000..eb1ebb9
--- /dev/null
+++ b/src/stores/modules/user.ts
@@ -0,0 +1,65 @@
+import { defineStore } from "pinia";
+import type { IUser } from "@/api/user/model"
+import type { ItemType } from 'ant-design-vue';
+import {ref} from 'vue'
+
+interface userInfo {
+ id: number
+ account: string
+ name: string
+}
+
+interface UserStore {
+ info: userInfo
+ menus:any
+ roles: []
+ orgs: []
+}
+
+export const useUserStore = defineStore("user", {
+ state: (): UserStore => {
+ return {
+ info: {
+ id: 0,
+ account: "",
+ name: ""
+ },
+ menus: ref(getMenus()),
+ roles: [],
+ orgs: [],
+ }
+ },
+
+ getters: {
+
+ },
+
+ actions: {
+
+ }
+})
+
+const getMenus = ():ItemType[] => {
+ return [
+ // {
+ // key:"/",
+ // label:"首页",
+ // },
+ {
+ key:"/user",
+ label:"用户",
+ },
+ {
+ key:"/organization",
+ label:"组织",
+ },
+ {
+ key:"/role",
+ label:"角色",
+ },
+ {
+ key:"/application",
+ label:"应用",
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/stores/store.ts b/src/stores/store.ts
new file mode 100644
index 0000000..e88f2b9
--- /dev/null
+++ b/src/stores/store.ts
@@ -0,0 +1,10 @@
+import type {App} from 'vue'
+import { createPinia } from 'pinia'
+
+const store = createPinia()
+
+export function setupStore(app:App){
+ app.use(store)
+}
+
+export {store}
\ No newline at end of file
diff --git a/src/types/global.d.ts b/src/types/global.d.ts
new file mode 100644
index 0000000..08eec7c
--- /dev/null
+++ b/src/types/global.d.ts
@@ -0,0 +1,8 @@
+interface Response{
+ data:T;
+ result:boolean;
+ code:number;
+ msg:string;
+ }
+
+type RES = Promise>
\ No newline at end of file
diff --git a/src/utils/auth.ts b/src/utils/auth.ts
new file mode 100644
index 0000000..4506417
--- /dev/null
+++ b/src/utils/auth.ts
@@ -0,0 +1,35 @@
+import Cookies from "js-cookie"
+
+const tokenKey = "token"
+const userIdKey = "id"
+const userAccountKey = "account"
+const pwdKey = "pwd"
+const setOption = {expires:7}
+
+export function getToken(){
+ return Cookies.get(tokenKey)
+}
+
+export function setToken(token: string) {
+ return Cookies.set(tokenKey, token)
+}
+
+export function removeToken() {
+ return Cookies.remove(tokenKey)
+}
+
+export const getAccount = ():string | undefined => {return Cookies.get(userAccountKey)}
+export const setAccount = (account:string) => {Cookies.set(userAccountKey,account,setOption)}
+
+export const getUserId = ():number | undefined => {
+ const id = Cookies.get(userIdKey);
+ if (id){
+ return Number(id)
+ }
+}
+
+export const setUserId = (id:number) => {Cookies.set(userIdKey,String(id),setOption)}
+
+export const getPwd = ():string | undefined => {return Cookies.get(pwdKey)}
+
+export const setPwd = (pwd:string) => {Cookies.set(pwdKey,pwd,setOption)}
\ No newline at end of file
diff --git a/src/utils/http.ts b/src/utils/http.ts
new file mode 100644
index 0000000..71c6cd0
--- /dev/null
+++ b/src/utils/http.ts
@@ -0,0 +1,53 @@
+import axios from "axios"
+import { message as Message } from "ant-design-vue"
+import { removeToken } from "@/utils/auth"
+import { useRouter } from "vue-router";
+
+const router = useRouter()
+
+const instance = axios.create({
+ baseURL:'/user_center',
+ timeout:5000,
+})
+
+instance.interceptors.request.use(
+ (config) => config,
+ (err) => Promise.reject(err)
+)
+
+instance.interceptors.response.use(
+ (response) =>{
+ let message = ''
+ const data = response.data as Response;
+ if (!data.result){
+ message = data.msg
+ Message.error(message)
+ }else {
+ if (data.code === 400){
+ message = "400 bad request"
+ Message.error(message)
+ }else if (data.code === 401){
+ // 没有权限则删除token,跳转登陆页面
+ removeToken()
+ router.push("/login")
+ }else if (data.code === 403){
+ message = "权限错误"
+ Message.error(message)
+ }else if (data.code === 500){
+ message = "内部错误"
+ Message.error(message)
+ }else if (data.code === 200){
+ return response.data
+ }else{
+ message = "请求错误,错误码: " + response.data.code
+ Message.error(message)
+ }
+ }
+ },
+ (err) =>{
+ Message.error( "请求失败,错误信息: "+ err.message)
+ Promise.reject(err)
+ }
+)
+
+export default instance;
diff --git a/src/views/AboutView.vue b/src/views/AboutView.vue
deleted file mode 100644
index 756ad2a..0000000
--- a/src/views/AboutView.vue
+++ /dev/null
@@ -1,15 +0,0 @@
-
-