diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000000000000000000000000000000000000..9028b8cb05120426f1a2b67ae506f84fab963fda
--- /dev/null
+++ b/.env.development
@@ -0,0 +1 @@
+VITE_APP_API=http://localhost:3003/
\ No newline at end of file
diff --git a/.env.production b/.env.production
new file mode 100644
index 0000000000000000000000000000000000000000..9028b8cb05120426f1a2b67ae506f84fab963fda
--- /dev/null
+++ b/.env.production
@@ -0,0 +1 @@
+VITE_APP_API=http://localhost:3003/
\ No newline at end of file
diff --git a/.eslintrc.js b/.eslintrc.js
index 03c538de4b5eb60bcbe52714460f101a4aa947f7..d6c23e3e74db271e21379b65854d3f73d69f8146 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -5,7 +5,12 @@ module.exports = {
node: true,
es2021: true
},
- extends: ["plugin:vue/vue3-recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
+ extends: [
+ "plugin:vue/vue3-recommended",
+ "plugin:@typescript-eslint/recommended",
+ "prettier",
+ "plugin:prettier/recommended"
+ ],
parserOptions: {
ecmaVersion: 13,
parser: "@typescript-eslint/parser",
diff --git a/package.json b/package.json
index 88cd755e0517a7f6b763a2ab53136e15de438eff..77a54a79087361af0fab93fca21dcc682c325c8c 100644
--- a/package.json
+++ b/package.json
@@ -9,6 +9,7 @@
"lint": "eslint \"src/**/*.{vue,ts}\" --fix"
},
"dependencies": {
+ "axios": "^0.26.1",
"element-plus": "^2.1.4",
"pinia": "^2.0.13",
"vue": "^3.2.25",
@@ -16,6 +17,7 @@
},
"devDependencies": {
"@types/node": "^17.0.23",
+ "@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"@vitejs/plugin-vue": "^2.3.0",
@@ -24,6 +26,7 @@
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-vue": "^8.5.0",
"prettier": "2.4.1",
+ "qs": "^6.10.3",
"sass": "^1.49.11",
"typescript": "^4.5.4",
"unplugin-auto-import": "^0.6.9",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e6ef6ca8bed6e09cb01b458fcf1bfa04466dd9fa..a8b78a37bb659cfffb6a38c2b77f649049ac16cd 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2,9 +2,11 @@ lockfileVersion: 5.3
specifiers:
'@types/node': ^17.0.23
+ '@types/qs': ^6.9.7
'@typescript-eslint/eslint-plugin': ^5.17.0
'@typescript-eslint/parser': ^5.17.0
'@vitejs/plugin-vue': ^2.3.0
+ axios: ^0.26.1
element-plus: ^2.1.4
eslint: ^7.32.0
eslint-config-prettier: ^8.5.0
@@ -12,6 +14,7 @@ specifiers:
eslint-plugin-vue: ^8.5.0
pinia: ^2.0.13
prettier: 2.4.1
+ qs: ^6.10.3
sass: ^1.49.11
typescript: ^4.5.4
unplugin-auto-import: ^0.6.9
@@ -25,6 +28,7 @@ specifiers:
vue-tsc: ^0.29.8
dependencies:
+ axios: registry.npmmirror.com/axios/0.26.1
element-plus: registry.npmmirror.com/element-plus/2.1.8_vue@3.2.31
pinia: registry.npmmirror.com/pinia/2.0.13_typescript@4.6.3+vue@3.2.31
vue: registry.npmmirror.com/vue/3.2.31
@@ -32,6 +36,7 @@ dependencies:
devDependencies:
'@types/node': registry.npmmirror.com/@types/node/17.0.23
+ '@types/qs': registry.npmmirror.com/@types/qs/6.9.7
'@typescript-eslint/eslint-plugin': registry.npmmirror.com/@typescript-eslint/eslint-plugin/5.17.0_6da5f837f6da21a8347f2aaca31a901b
'@typescript-eslint/parser': registry.npmmirror.com/@typescript-eslint/parser/5.17.0_eslint@7.32.0+typescript@4.6.3
'@vitejs/plugin-vue': registry.npmmirror.com/@vitejs/plugin-vue/2.3.1_vite@2.9.1+vue@3.2.31
@@ -40,6 +45,7 @@ devDependencies:
eslint-plugin-prettier: registry.npmmirror.com/eslint-plugin-prettier/3.4.1_180f37bdf0df965baf264f9cfe7a5521
eslint-plugin-vue: registry.npmmirror.com/eslint-plugin-vue/8.5.0_eslint@7.32.0
prettier: registry.npmmirror.com/prettier/2.4.1
+ qs: registry.npmmirror.com/qs/6.10.3
sass: registry.npmmirror.com/sass/1.49.11
typescript: registry.npmmirror.com/typescript/4.6.3
unplugin-auto-import: registry.npmmirror.com/unplugin-auto-import/0.6.9_vite@2.9.1
@@ -260,6 +266,12 @@ packages:
version: 17.0.23
dev: true
+ registry.npmmirror.com/@types/qs/6.9.7:
+ resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/qs/-/qs-6.9.7.tgz}
+ name: '@types/qs'
+ version: 6.9.7
+ dev: true
+
registry.npmmirror.com/@typescript-eslint/eslint-plugin/5.17.0_6da5f837f6da21a8347f2aaca31a901b:
resolution: {integrity: sha512-qVstvQilEd89HJk3qcbKt/zZrfBZ+9h2ynpAGlWjWiizA7m/MtLT9RoX6gjtpE500vfIg8jogAkDzdCxbsFASQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.17.0.tgz}
id: registry.npmmirror.com/@typescript-eslint/eslint-plugin/5.17.0
@@ -787,6 +799,16 @@ packages:
version: 4.0.7
dev: false
+ registry.npmmirror.com/axios/0.26.1:
+ resolution: {integrity: sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/axios/-/axios-0.26.1.tgz}
+ name: axios
+ version: 0.26.1
+ dependencies:
+ follow-redirects: registry.npmmirror.com/follow-redirects/1.14.9
+ transitivePeerDependencies:
+ - debug
+ dev: false
+
registry.npmmirror.com/babel-walk/3.0.0-canary-5:
resolution: {integrity: sha512-GAwkz0AihzY5bkwIY5QDR+LvsRQgB/B+1foMPvi0FZPMl5fjD7ICiznUiBdLYMH1QYe6vqu4gWYytZOccLouFw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/babel-walk/-/babel-walk-3.0.0-canary-5.tgz}
name: babel-walk
@@ -1694,6 +1716,18 @@ packages:
version: 3.2.5
dev: true
+ registry.npmmirror.com/follow-redirects/1.14.9:
+ resolution: {integrity: sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.14.9.tgz}
+ name: follow-redirects
+ version: 1.14.9
+ engines: {node: '>=4.0'}
+ peerDependencies:
+ debug: '*'
+ peerDependenciesMeta:
+ debug:
+ optional: true
+ dev: false
+
registry.npmmirror.com/fs.realpath/1.0.0:
resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz}
name: fs.realpath
@@ -2204,6 +2238,12 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
+ registry.npmmirror.com/object-inspect/1.12.0:
+ resolution: {integrity: sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/object-inspect/-/object-inspect-1.12.0.tgz}
+ name: object-inspect
+ version: 1.12.0
+ dev: true
+
registry.npmmirror.com/once/1.4.0:
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/once/-/once-1.4.0.tgz}
name: once
@@ -2466,6 +2506,15 @@ packages:
engines: {node: '>=6'}
dev: true
+ registry.npmmirror.com/qs/6.10.3:
+ resolution: {integrity: sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/qs/-/qs-6.10.3.tgz}
+ name: qs
+ version: 6.10.3
+ engines: {node: '>=0.6'}
+ dependencies:
+ side-channel: registry.npmmirror.com/side-channel/1.0.4
+ dev: true
+
registry.npmmirror.com/queue-microtask/1.2.3:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz}
name: queue-microtask
@@ -2602,6 +2651,16 @@ packages:
engines: {node: '>=8'}
dev: true
+ registry.npmmirror.com/side-channel/1.0.4:
+ resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/side-channel/-/side-channel-1.0.4.tgz}
+ name: side-channel
+ version: 1.0.4
+ dependencies:
+ call-bind: registry.npmmirror.com/call-bind/1.0.2
+ get-intrinsic: registry.npmmirror.com/get-intrinsic/1.1.1
+ object-inspect: registry.npmmirror.com/object-inspect/1.12.0
+ dev: true
+
registry.npmmirror.com/slash/3.0.0:
resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/slash/-/slash-3.0.0.tgz}
name: slash
diff --git a/src/Login.vue b/src/Login.vue
new file mode 100644
index 0000000000000000000000000000000000000000..8fa56d1c62e16fd49b90e420703129c34db3791e
--- /dev/null
+++ b/src/Login.vue
@@ -0,0 +1,13 @@
+
+
+
+ login
+
+
+
diff --git a/src/api/index.ts b/src/api/index.ts
new file mode 100644
index 0000000000000000000000000000000000000000..13bea305d41d8d72383c76439131d8e16076f3f6
--- /dev/null
+++ b/src/api/index.ts
@@ -0,0 +1,5 @@
+import * as user from "./user";
+
+export default {
+ user
+};
diff --git a/src/api/user.ts b/src/api/user.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b35c7b91d92709ad466d223f39d222bf29ec6092
--- /dev/null
+++ b/src/api/user.ts
@@ -0,0 +1,10 @@
+import service from "@/utils/request";
+import { IObject } from "@/types/interface";
+
+export const login = (data: IObject) => {
+ return service({
+ url: "/api/login",
+ method: "post",
+ data
+ });
+};
diff --git a/src/router/index.ts b/src/router/index.ts
index 73acf0c0dcb160872b6f70a339aacebf251ce9f9..6cffb6958694f04b4dc47be2803fbdd92c64f35e 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -4,6 +4,10 @@ const routes: Array = [
{
path: "/",
component: () => import("@/Home.vue")
+ },
+ {
+ path: "/login",
+ component: () => import("@/Login.vue")
}
];
diff --git a/src/types/interface.ts b/src/types/interface.ts
new file mode 100644
index 0000000000000000000000000000000000000000..093f9568edf39e8f991de2741867a9e1a48aa0fd
--- /dev/null
+++ b/src/types/interface.ts
@@ -0,0 +1,3 @@
+export interface IObject {
+ [key: string]: any;
+}
diff --git a/src/utils/request.ts b/src/utils/request.ts
new file mode 100644
index 0000000000000000000000000000000000000000..34aa16a8b4770c7fca54b8b0dd8185ae80d3e3f9
--- /dev/null
+++ b/src/utils/request.ts
@@ -0,0 +1,57 @@
+import axios from "axios";
+import qs from "qs";
+import { IObject } from "@/types/interface";
+import { ElMessage } from "element-plus";
+
+const baseURL = import.meta.env.VITE_APP_API?.toString();
+
+const service = axios.create({
+ baseURL: baseURL,
+ timeout: 60 * 1000,
+ withCredentials: true
+});
+
+service.interceptors.request.use(
+ (config: IObject) => {
+ const token = localStorage.getItem("Token");
+ config.headers["token"] = token;
+
+ // get请求传递数组
+ if (config.method?.toUpperCase() === "GET") {
+ config.paramsSerializer = function (params: unknown) {
+ return qs.stringify(params, { arrayFormat: "comma" });
+ };
+ }
+
+ // post请求数组传string
+ if (config.method?.toUpperCase() === "POST") {
+ config.data = qs.stringify(config.data);
+ }
+
+ return config;
+ },
+ (error) => {
+ // 请求错误
+ return Promise.reject(error);
+ }
+);
+
+service.interceptors.response.use(
+ (response) => {
+ const res = response.data as IObject;
+ if (res.code && res.code !== 0) {
+ // token过期处理
+ if (res.code === 401 || res.code === 4001) {
+ // return redirectLogin();
+ }
+ return ElMessage(`请求失败,${res.msg}`);
+ } else {
+ return res;
+ }
+ },
+ (error) => {
+ console.log(error);
+ }
+);
+
+export default service;
diff --git a/tsconfig.json b/tsconfig.json
index bcc4abda4c57f07c6bb73283dfa0aeb23d8b4a27..1ee3170a64cfcf2546aa584141307d26b2f20a11 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -11,7 +11,11 @@
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
- "skipLibCheck": true
+ "skipLibCheck": true,
+ "baseUrl": "./",
+ "paths": {
+ "@/*": ["src/*"]
+ }
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
diff --git a/vite.config.ts b/vite.config.ts
index 747810b173a75c86416ebbd8f7c9edaa71ef86d7..b6d6906cd9ebc8c0b94fb2711a07b7d38bd7274c 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,11 +1,11 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
-import eslint from 'vite-plugin-eslint';
+import eslint from "vite-plugin-eslint";
import tsconfigPaths from "vite-tsconfig-paths";
-import AutoImport from 'unplugin-auto-import/vite'
-import Components from 'unplugin-vue-components/vite'
-import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
+import AutoImport from "unplugin-auto-import/vite";
+import Components from "unplugin-vue-components/vite";
+import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default defineConfig({
@@ -15,14 +15,14 @@ export default defineConfig({
eslint({
cache: false,
fix: false,
- include: ["src/**/*.ts", "src/**/*.vue"],
+ include: ["src/**/*.ts", "src/**/*.vue"]
}),
AutoImport({
- resolvers: [ElementPlusResolver()],
+ resolvers: [ElementPlusResolver()]
}),
Components({
- resolvers: [ElementPlusResolver()],
- }),
+ resolvers: [ElementPlusResolver()]
+ })
],
resolve: {
alias: {
@@ -33,14 +33,14 @@ export default defineConfig({
chunkSizeWarningLimit: 1024,
rollupOptions: {
output: {
- chunkFileNames: 'static/js/[name]-[hash].js',
- entryFileNames: 'static/js/[name]-[hash].js',
- assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
+ chunkFileNames: "static/js/[name]-[hash].js",
+ entryFileNames: "static/js/[name]-[hash].js",
+ assetFileNames: "static/[ext]/[name]-[hash].[ext]",
manualChunks: {
elementPlus: ["element-plus"],
vue: ["vue"],
vueRouter: ["vue-router"]
- },
+ }
// manualChunks(id) {
// // 将pinia的全局库实例打包进vendor,避免和页面一起打包造成资源重复引入
// if (id.includes(path.resolve(__dirname, '/src/store/index.ts'))) {
@@ -49,5 +49,5 @@ export default defineConfig({
// }
}
}
- },
+ }
});