-
-
我的
+
+
+
+
+
+
+
+
{{ merInfo.mer_name }}
+
{{ merInfo.service_phone }}
+
+
+
+
+
+
+
+ 退出登录
+
+
+
+
+
\ No newline at end of file
+.el-dropdown{
+ border: none;
+}
+
diff --git a/src/main.ts b/src/main.ts
index ffce009..d3d447f 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -6,15 +6,17 @@ import 'element-plus/dist/index.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
-
+import { createPinia } from 'pinia'
const app = createApp(App)
// 注册图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
+const pinia = createPinia();
app.use(router)
+app.use(pinia)
app.use(ElementPlus, {
locale: zhCn,
})
diff --git a/src/router/index.js b/src/router/index.js
index d95a990..d5fd278 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,5 +1,8 @@
import { createRouter, createWebHistory } from 'vue-router';
import layout from '@/layout/index.vue';
+import { useUserStore } from '@/store/user.js';
+
+
const routes = [
{
path: '/',
@@ -14,6 +17,11 @@ const routes = [
}
]
},
+ {
+ path: '/login',
+ name: 'login',
+ component: () => import('@/views/login/index.vue'),
+ },
];
const router = createRouter({
@@ -21,4 +29,16 @@ const router = createRouter({
routes
});
+// 全局前置守卫
+router.beforeEach((to, from, next) => {
+ const userStore = useUserStore();
+
+ // 如果用户访问的不是登录页面,并且未登录,则重定向到登录页面
+ if (to.name !== 'login' && !userStore.Token) {
+ next({ name: 'login' });
+ } else {
+ next(); // 放行
+ }
+});
+
export default router;
\ No newline at end of file
diff --git a/src/store/user.js b/src/store/user.js
new file mode 100644
index 0000000..931a5ee
--- /dev/null
+++ b/src/store/user.js
@@ -0,0 +1,24 @@
+import { defineStore } from "pinia"
+import { ref } from "vue"
+
+export const useUserStore = defineStore('user', () => {
+ const userInfo = ref(JSON.parse(localStorage.getItem('userInfo') || '{}'));
+
+ const Token = ref(localStorage.getItem('Token'));
+
+ const setUserInfo = (e)=>{
+ userInfo.value = e;
+ localStorage.setItem('userInfo',JSON.stringify(e));
+ }
+ const setToken = (e)=>{
+ Token.value = e;
+ localStorage.setItem('Token',e);
+ }
+
+ return {
+ userInfo,
+ Token,
+ setUserInfo,
+ setToken
+ }
+})
\ No newline at end of file
diff --git a/src/utils/axios.js b/src/utils/axios.js
new file mode 100644
index 0000000..ba6cfca
--- /dev/null
+++ b/src/utils/axios.js
@@ -0,0 +1,39 @@
+import axios from "axios";
+
+const request = axios.create({
+ baseURL: import.meta.env.VITE_BASE_URL + '/api',
+ timeout: 5000
+})
+
+// 请求拦截器
+request.interceptors.request.use(
+ config => {
+ // 在发送请求之前做些什么,例如添加token、修改请求头等
+ const token = localStorage.getItem('Token');
+ if (token) {
+ config.headers['X-Token'] = 'Bearer ' + token;
+ }
+
+ return config;
+ },
+ error => {
+ // 处理请求错误
+ console.error(error);
+ return Promise.reject(error);
+ }
+);
+
+// 响应拦截器
+request.interceptors.response.use(
+ response => {
+ // 对响应数据做些什么,例如解析数据、统一处理错误等
+ return response.data;
+ },
+ error => {
+ // 处理响应错误
+ console.error(error);
+ return Promise.reject(error);
+ }
+);
+
+export default request;
\ No newline at end of file
diff --git a/src/views/home/component/order.vue b/src/views/home/component/order.vue
index 34fd65b..9f77838 100644
--- a/src/views/home/component/order.vue
+++ b/src/views/home/component/order.vue
@@ -1,4 +1,25 @@
@@ -7,10 +28,24 @@
- 订单列表
+
+
+
+
+
+
很不错的商品名称很不错的商品名称很不错的商品名称很不错的商品名称
+
删除
+
+
设备规格
+
+
+