parent
fe8bb888e6
commit
0baa3620c1
16 changed files with 1032 additions and 171 deletions
@ -1,4 +1,4 @@ |
||||
# 变量必须以 VITE_ 为前缀才能暴露给外部读取 |
||||
NODE_ENV = 'development' |
||||
VITE_APP_TITLE = '硅谷甄选运营平台' |
||||
VITE_APP_BASE_API = '/dev-api' |
||||
VITE_APP_TITLE = '在线测试平台' |
||||
VITE_APP_BASE_API = '/api' |
@ -1,3 +1,3 @@ |
||||
NODE_ENV = 'production' |
||||
VITE_APP_TITLE = '硅谷甄选运营平台' |
||||
VITE_APP_BASE_API = '/prod-api' |
||||
VITE_APP_TITLE = '在线测试平台' |
||||
VITE_APP_BASE_API = '/api' |
@ -1,4 +1,4 @@ |
||||
# 变量必须以 VITE_ 为前缀才能暴露给外部读取 |
||||
NODE_ENV = 'test' |
||||
VITE_APP_TITLE = '硅谷甄选运营平台' |
||||
VITE_APP_BASE_API = '/test-api' |
||||
VITE_APP_TITLE = '在线测试平台' |
||||
VITE_APP_BASE_API = '/api' |
@ -0,0 +1,70 @@ |
||||
//用户信息数据
|
||||
//createuserList:次函数执行会返回一个数组,数组里面包含两个用户信息
|
||||
function createUserList() { |
||||
return [ |
||||
{ |
||||
userId: 1, |
||||
avatar: |
||||
'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', |
||||
username: 'admin', |
||||
password: '111111', |
||||
desc: '平台管理员', |
||||
roles: ['平台管理员'], |
||||
buttons: ['cuser.detail'], |
||||
routes: ['home'], |
||||
token: 'Admin Token', |
||||
}, |
||||
{ |
||||
userId: 2, |
||||
avatar: |
||||
'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', |
||||
username: 'system', |
||||
password: '111111', |
||||
desc: '系统管理员', |
||||
roles: ['系统管理员'], |
||||
buttons: ['cuser.detail', 'cuser.user'], |
||||
routes: ['home'], |
||||
token: 'System Token', |
||||
}, |
||||
] |
||||
} |
||||
|
||||
export default [ |
||||
// 用户登录接口
|
||||
{ |
||||
url: '/api/user/login',//请求地址
|
||||
method: 'post',//请求方式
|
||||
response: ({ body }) => { |
||||
//获取请求体携带过来的用户名与密码
|
||||
const { username, password } = body; |
||||
//调用获取用户信息函数,用于判断是否有此用户
|
||||
const checkUser = createUserList().find( |
||||
(item) => item.username === username && item.password === password, |
||||
) |
||||
//没有用户返回失败信息
|
||||
if (!checkUser) { |
||||
return { code: 201, data: { message: '账号或者密码不正确' } } |
||||
} |
||||
//如果有返回成功信息
|
||||
const { token } = checkUser |
||||
return { code: 200, data: { token } } |
||||
}, |
||||
}, |
||||
// 获取用户信息
|
||||
{ |
||||
url: '/api/user/info', |
||||
method: 'get', |
||||
response: (request) => { |
||||
//获取请求头携带token
|
||||
const token = request.headers.token; |
||||
//查看用户信息是否包含有次token用户
|
||||
const checkUser = createUserList().find((item) => item.token === token) |
||||
//没有返回失败的信息
|
||||
if (!checkUser) { |
||||
return { code: 201, data: { message: '获取用户信息失败' } } |
||||
} |
||||
//如果有返回成功信息
|
||||
return { code: 200, data: {checkUser} } |
||||
}, |
||||
}, |
||||
] |
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,17 @@ |
||||
<template> |
||||
<div> |
||||
<h1>Svg测试</h1> |
||||
<svg-icon name="home" color="red" width="100px" height="100px"></svg-icon> |
||||
<h1>ces</h1> |
||||
</div> |
||||
</template> |
||||
<script setup lang="ts"> |
||||
import SvgIcon from '@/components/SvgIcon/index.vue' |
||||
import request from "@/utils/request"; |
||||
import {onMounted} from 'vue'; |
||||
import {reqLogin} from "@/api/user"; |
||||
|
||||
onMounted(()=>{ |
||||
reqLogin({username:'admin',password:'111111'}) |
||||
}) |
||||
</script> |
||||
<style scoped lang="scss"> |
||||
h1 { |
||||
color: $h1-color; |
||||
} |
||||
<style scoped> |
||||
|
||||
</style> |
||||
|
@ -0,0 +1,19 @@ |
||||
//统一管理项目相关信息
|
||||
import request from "@/utils/request"; |
||||
import type { |
||||
loginForm, |
||||
loginResponseDate, |
||||
userReponseData, |
||||
} from './type' |
||||
//统一管理接口
|
||||
enum API { |
||||
LOGIN_URL = '/user/login', |
||||
USERINFO_URL = '/user/info', |
||||
// LOGOUT_URL = '/admin/acl/index/logout',
|
||||
} |
||||
//登录接口
|
||||
export const reqLogin = (data: loginForm) => request.post<any,loginResponseDate>(API.LOGIN_URL, data) |
||||
//获取用户信息
|
||||
export const reqUserInfo = () =>request.get<any,userReponseData>(API.USERINFO_URL) |
||||
//退出登录
|
||||
// export const reqLogout = () => request.post<any, any>(API.LOGOUT_URL)
|
@ -0,0 +1,33 @@ |
||||
//登录接口需要携带参数ts类型
|
||||
export interface loginForm{ |
||||
username:string, |
||||
password:string |
||||
} |
||||
|
||||
interface dataType{ |
||||
token:string |
||||
} |
||||
//登录接口返回数据类型
|
||||
export interface loginResponseDate{ |
||||
code:number, |
||||
date:dataType |
||||
} |
||||
//定义服务器返回用户信息相关数据类型
|
||||
interface userInfo{ |
||||
userId:number, |
||||
avatar:string, |
||||
username:string, |
||||
password:string, |
||||
desc:string, |
||||
roles:string[], |
||||
buttons:string[], |
||||
routes:string[], |
||||
token:string |
||||
} |
||||
interface user{ |
||||
checkUser:userInfo |
||||
} |
||||
export interface userReponseData{ |
||||
code:number, |
||||
date:user |
||||
} |
@ -1,9 +1,11 @@ |
||||
<template></template> |
||||
<template> |
||||
|
||||
</template> |
||||
|
||||
<script setup> |
||||
|
||||
<script> |
||||
export default { |
||||
name: 'index', |
||||
} |
||||
</script> |
||||
|
||||
<style scoped></style> |
||||
<style scoped> |
||||
|
||||
</style> |
||||
|
@ -0,0 +1,17 @@ |
||||
//引入项目中全部的全局组件
|
||||
import SvgIcon from './SvgIcon/index.vue' |
||||
import Pagination from'./Pagination/index.vue' |
||||
//全局对象
|
||||
const allGloablComponent={SvgIcon,Pagination }; |
||||
//对外暴露插件对象
|
||||
export default { |
||||
//务必叫做insta1l方法
|
||||
install(app) { |
||||
//注册项目全部的全局组件
|
||||
Object.keys(allGloablComponent).forEach(key => { |
||||
//注册为全局组件
|
||||
|
||||
app.component(key, allGloablComponent[key]); |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
//进行axios二次封装:使用请求与响应拦截器
|
||||
//1:使用请求拦截器,可以在请求拦截器中处理一些业务(开始进度条、请求头携带公共参数)
|
||||
// 2:使用响应拦截器,可以在响应拦截器中处理一些业务(进度条结束、简化服务器返回的数据、处理http网络错误)
|
||||
import axios from "axios"; |
||||
import { ElMessage } from "element-plus"; |
||||
//创建axios实例
|
||||
let request = axios.create({ |
||||
baseURL: import.meta.env.VITE_APP_BASE_API, |
||||
timeout: 5000 |
||||
}) |
||||
//请求拦截器
|
||||
request.interceptors.request.use(config => { |
||||
//config配置对象,headers属性请求头,经常给服务器端携带公共参数
|
||||
return config; |
||||
}); |
||||
//响应拦截器
|
||||
request.interceptors.response.use((response) => { |
||||
return response.data; |
||||
}, (error) => { |
||||
//处理网络错误
|
||||
let msg = ''; |
||||
let status = error.response.status; |
||||
switch (status) { |
||||
case 401: |
||||
msg = "token过期"; |
||||
break; |
||||
case 403: |
||||
msg = '无权访问'; |
||||
break; |
||||
case 404: |
||||
msg = "请求地址错误"; |
||||
break; |
||||
case 500: |
||||
msg = "服务器出现问题"; |
||||
break; |
||||
default: |
||||
msg = "无网络"; |
||||
|
||||
} |
||||
ElMessage({ |
||||
type: 'error', |
||||
message: msg |
||||
}) |
||||
return Promise.reject(error); |
||||
}); |
||||
export default request; |
@ -0,0 +1,44 @@ |
||||
// vite.config.ts
|
||||
import { defineConfig } from "file:///C:/Users/bo/Desktop/vue3_admin_template/project/node_modules/.pnpm/vite@5.4.10_@types+node@22.9.0_sass@1.80.6/node_modules/vite/dist/node/index.js"; |
||||
import { createSvgIconsPlugin } from "file:///C:/Users/bo/Desktop/vue3_admin_template/project/node_modules/.pnpm/vite-plugin-svg-icons@2.0.1_vite@5.4.10_@types+node@22.9.0_sass@1.80.6_/node_modules/vite-plugin-svg-icons/dist/index.mjs"; |
||||
import { viteMockServe } from "file:///C:/Users/bo/Desktop/vue3_admin_template/project/node_modules/.pnpm/vite-plugin-mock@3.0.2_esbuild@0.21.5_mockjs@1.1.0_vite@5.4.10_@types+node@22.9.0_sass@1.80.6_/node_modules/vite-plugin-mock/dist/index.mjs"; |
||||
import vue from "file:///C:/Users/bo/Desktop/vue3_admin_template/project/node_modules/.pnpm/@vitejs+plugin-vue@5.1.4_vite@5.4.10_@types+node@22.9.0_sass@1.80.6__vue@3.5.12_typescript@5.6.3_/node_modules/@vitejs/plugin-vue/dist/index.mjs"; |
||||
import path from "path"; |
||||
var vite_config_default = defineConfig( |
||||
({ command }) => { |
||||
return { |
||||
plugins: [ |
||||
vue(), |
||||
createSvgIconsPlugin({ |
||||
// Specify the icon folder to be cached
|
||||
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")], |
||||
// Specify symbolId format
|
||||
symbolId: "icon-[dir]-[name]" |
||||
}), |
||||
viteMockServe({ |
||||
enable: command === "serve" |
||||
//保证开发阶段可以使用mock接口
|
||||
}) |
||||
], |
||||
resolve: { |
||||
alias: { |
||||
"@": path.resolve("./src") |
||||
// 相对路径别名配置,使用 @ 代替 src
|
||||
} |
||||
}, |
||||
//scss全局变量的配置
|
||||
css: { |
||||
preprocessorOptions: { |
||||
scss: { |
||||
javascriptEnabled: true, |
||||
additionalData: '@import "./src/styles/variable.scss";' |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
); |
||||
export { |
||||
vite_config_default as default |
||||
}; |
||||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCJDOlxcXFxVc2Vyc1xcXFxib1xcXFxEZXNrdG9wXFxcXHZ1ZTNfYWRtaW5fdGVtcGxhdGVcXFxccHJvamVjdFwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZ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