diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..a4cdf13 --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +# VITE_BASE_URL = 'http://192.168.1.24:8324' +VITE_BASE_URL = 'https://crmeb-test.shop.lihaink.cn' \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..b3d7815 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_BASE_URL = '' \ No newline at end of file diff --git a/index.html b/index.html index dde16aa..de6b245 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - Vite + Vue + TS + 里海收银系统
diff --git a/src/api/store.js b/src/api/store.js new file mode 100644 index 0000000..61037b1 --- /dev/null +++ b/src/api/store.js @@ -0,0 +1,8 @@ +import request from '@/utils/axios.js' + +/** + * @description 商品列表 + */ +export function storeListApi(id, data) { + return request.get(`server/${30}/product/lst`, { params: data }) +} \ No newline at end of file diff --git a/src/api/user.js b/src/api/user.js new file mode 100644 index 0000000..4197980 --- /dev/null +++ b/src/api/user.js @@ -0,0 +1,28 @@ +import request from '@/utils/axios.js' + +/** + * @description 验证码 + */ +export function captchaApi() { + return request.get(`captcha`) +} +/** + * @description 登录 + */ +export function login(data) { + return request.post(`auth/login`, data) +} + +/** + * @description 信息 + */ +export function info(data) { + return request.get(`user`, data) +} + +/** + * @description 退出登录 + */ +export function logout() { + return request.post(`logout`) +} diff --git a/src/layout/myHeader.vue b/src/layout/myHeader.vue index 8772496..6ff53b5 100644 --- a/src/layout/myHeader.vue +++ b/src/layout/myHeader.vue @@ -1,33 +1,98 @@ - \ 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 @@
- +
- 订单列表 + +
+ +
+
+
很不错的商品名称很不错的商品名称很不错的商品名称很不错的商品名称
+
删除
+
+
设备规格
+
+
¥100
+
+
+
+