This commit is contained in:
Lau-Laptop\Lau 2023-11-06 10:23:48 +08:00
commit 426fbf3b44
19 changed files with 4154 additions and 0 deletions

8
.env.development Normal file
View File

@ -0,0 +1,8 @@
VITE_USER_NODE_ENV = development
VITE_APP_TITLE = ENV TITLE
VITE_API_URL = /api

3
.env.production Normal file
View File

@ -0,0 +1,3 @@
VITE_USER_NODE_ENV = production
VITE_API_URL = /api

24
.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

15
favicon.svg Normal file
View File

@ -0,0 +1,15 @@
<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
<defs>
<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
<stop stop-color="#41D1FF"/>
<stop offset="1" stop-color="#BD34FE"/>
</linearGradient>
<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
<stop stop-color="#FFEA83"/>
<stop offset="0.0833333" stop-color="#FFDD35"/>
<stop offset="1" stop-color="#FFA800"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

13
index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="zh-hans">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>asd</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

3799
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

23
package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "vite2vue2",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.6.0",
"element-ui": "^2.15.14",
"vue": "^2.7.15",
"vue-router": "^3.5.2",
"vue-template-compiler": "^2.7.15",
"vuex": "^3.6.2"
},
"devDependencies": {
"sass": "^1.69.5",
"vite": "^2.8.0",
"vite-plugin-vue2": "^1.9.3"
}
}

3
public/test.json Normal file
View File

@ -0,0 +1,3 @@
{
"name":"test"
}

5
src/App.vue Normal file
View File

@ -0,0 +1,5 @@
<template>
<div>
<router-view></router-view>
</div>
</template>

15
src/api/login.js Normal file
View File

@ -0,0 +1,15 @@
import http from '../utils/http'
/**
* @param {object} data -登录信息
* @param {string} data.account -账号
* @param {string} data.password -密码
* @return {Promise} -返回登录结果
*/
export const login = (data) => {
return http({
method: 'post',
url: '/login',
data: data
})
}

15
src/main.js Normal file
View File

@ -0,0 +1,15 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')

14
src/router/index.js Normal file
View File

@ -0,0 +1,14 @@
import VueRouter from 'vue-router'
import Vue from 'vue'
import routes from './routes.js'
// 使用VueRouter
Vue.use(VueRouter)
const router = new VueRouter({
mode: 'hash',
base: './',
routes
})
export default router

23
src/router/routes.js Normal file
View File

@ -0,0 +1,23 @@
import HomeView from '@/views/HomeView.vue'
const routes = [
{
name: 'index',
path: '/',
meta: {
permission: 1
},
component: HomeView
},
{
name: 'about',
path: '/about',
meta: {
permission: 1
},
component: () => import('@/views/AboutView.vue')
},
]
export default routes

12
src/store/index.js Normal file
View File

@ -0,0 +1,12 @@
import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
Vue.use(Vuex) // 使用Vuex
export default new Vuex.Store({
modules: {
user
}
})

17
src/store/modules/user.js Normal file
View File

@ -0,0 +1,17 @@
const user = {
state: {
account: '23',
username: '',
role: ''
},
mutation: {
},
action: {
}
}
export default user

62
src/utils/http.js Normal file
View File

@ -0,0 +1,62 @@
import axios from "axios"
import { Message, Notification } from "element-ui"
const token = 'testToken'
const API_URL = import.meta.env.VITE_API_URL
console.log(API_URL)
const http = axios.create({
baseURL: API_URL,
timeout: 30000,
headers: {
"Content-Type": "application/json"
},
withCredentials: false,
})
// http.defaults.headers.common["Authorization"] = `Bearer ${token}`
// 请求拦截
http.interceptors.request.use(
config => {
config.headers.Authorization = `Bearer ${token}`
console.log(config)
return config
},
error => {
console.log(error)
}
)
// 响应拦截
http.interceptors.response.use(
response => {
let code = response.data.code
if (code === 400) {
Message({
type: 'warning',
message: '当前用户无权限访问此接口',
duration: 2000
})
}else if(code === 500){
Message({
type: 'error',
message: '当前用户无权限访问此接口',
duration: 2000
})
}
return response.data
},
error => {
console.log(error)
if (error.code === 'ERR_BAD_REQUEST') {
Notification.error({
title: error.response.status,
message: error.response.statusText,
duration: 2000,
})
}
}
)
export default http

30
src/views/AboutView.vue Normal file
View File

@ -0,0 +1,30 @@
<template>
<div class="home">
关于
</div>
</template>
<script>
export default {
name: 'AboutView',
components: {},
props: {
},
data() {
return {
};
},
computed: {
info() {
}
},
methods: {
}
}
</script>
<style lang='scss' scoped></style>

48
src/views/HomeView.vue Normal file
View File

@ -0,0 +1,48 @@
<template>
<div class="home">
首页
<div>
{{ info }}
</div>
</div>
</template>
<script>
import { login } from '@/api/login'
import http from '@/utils/http'
export default {
name: 'HomeView',
components: {},
props: {
},
data() {
return {
};
},
computed: {
info() {
console.log(this.$store.state.user.account)
return this.$store.state.user.account
}
},
methods: {
async handleLogin() {
const res = await login({
account: 'admin',
password: 'admin123'
})
console.log(res)
},
},
mounted() {
this.handleLogin()
http.get('/test.json').then(res => {
console.log(res)
})
},
}
</script>
<style lang='scss' scoped></style>

25
vite.config.js Normal file
View File

@ -0,0 +1,25 @@
import { defineConfig, loadEnv } from 'vite' // 动态配置函数
import { createVuePlugin } from 'vite-plugin-vue2'
import { resolve } from 'path'
export default () => {
return defineConfig({
base: './',
plugins: [
createVuePlugin()
],
server: {
open: true, //自动打开浏览器
port: 3001, //端口号
},
resolve: {
// 别名
alias: [
{
find: '@',
replacement: '/src'
}
]
}
})
}