diff --git a/src/api/task.ts b/src/api/task.ts index e69de29..340cd78 100644 --- a/src/api/task.ts +++ b/src/api/task.ts @@ -0,0 +1,27 @@ +import request from "../utils/request"; + + +//城市列表 +export function cityList(data:any) { + return request({ + url: '/sys/city/list', + method: 'get', + params:data + }) +} +//轮播 +export function bannerList(data:any) { + return request({ + url: '/home/banner/list', + method: 'get', + params:data + }) +} +//职位类型 +export function positionTypeList(data:any) { + return request({ + url: '/position/positionTypeApi', + method: 'get', + params:data + }) +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 186e17e..ea5b93d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,15 +5,19 @@ import App from './App.vue' import store from "./store/index.ts"; import router from "./router"; import './utils/rem' -import { Button,NavBar,Tabbar,TabbarItem,Checkbox,Toast,Icon } from "vant"; +import { Button,NavBar,Tabbar,TabbarItem,Checkbox,Toast,Icon ,Popup , Swipe, SwipeItem} from "vant"; const app = createApp(App) app.use(Button) app.use(NavBar) app.use(Tabbar) app.use(TabbarItem) app.use(Checkbox) +app.use(Popup) app.use(Toast) app.use(Icon) +app.use(Swipe) +app.use(SwipeItem) + app.use(store) app.use(router) app.mount('#app') diff --git a/src/router/index.ts b/src/router/index.ts index e0c33d9..c0436c5 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,4 +1,7 @@ -import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"; +import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"; +import { userStore } from "../store/user"; +import store from '../store/index'; +import { mapGamepadToXbox360Controller } from "@vueuse/core"; const routes: Array = [ //login { @@ -141,4 +144,18 @@ const router = createRouter({ routes }) +//路由守卫 + +router.beforeEach((to, from, next) => { + const store = userStore() + if (store.token) { + next() + } else { + if (to.path === '/login' || to.path === '/login/serviceAgree' || to.path == '/login/privacyPolicy') { + next() + } else { + next('/login') + } + } +}) export default router \ No newline at end of file diff --git a/src/store/index.ts b/src/store/index.ts index 3298a15..89715ab 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,4 +1,4 @@ import { createPinia } from "pinia"; -const store = createPinia +const store = createPinia(); export default store \ No newline at end of file diff --git a/src/store/task.ts b/src/store/task.ts new file mode 100644 index 0000000..683d96f --- /dev/null +++ b/src/store/task.ts @@ -0,0 +1,27 @@ +import { defineStore } from 'pinia' +import { bannerList, positionTypeList } from '../api/task'; + export const taskStore = defineStore({ + id: 'task', + state: () => { + return { + cityList: [], + cityValue: localStorage.getItem('city') || '北京', + bannerList: [], + positionList:[] + } + }, + actions: { + setCityValue(value: string){ + this.cityValue = value + }, + setCityList(data: any){ + this.cityList=data + }, + setBannerList(data: any) { + this.bannerList=data + }, + setPositionList(data: any) { + this.positionList=data + } + } + }) \ No newline at end of file diff --git a/src/store/user.ts b/src/store/user.ts new file mode 100644 index 0000000..6da2942 --- /dev/null +++ b/src/store/user.ts @@ -0,0 +1,23 @@ +import { defineStore } from 'pinia' + export const userStore = defineStore({ + id: 'user', + state: () => { + return { + token: localStorage.getItem('token') || '', + role: localStorage.getItem('role') || '1', + userInfo: {} + } + }, + actions: { + setRole(type: string){ + this.role = type + }, + setUserInfo(data: any){ + this.userInfo = data.user_info + this.token = data.token + this.role = data.user_info.role || '1' + localStorage.setItem('token',this.token) + localStorage.setItem('role',this.role) + }, + } + }) \ No newline at end of file diff --git a/src/utils/request.ts b/src/utils/request.ts index 28ea68d..73c59af 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -9,8 +9,8 @@ service.interceptors.request.use( config=>{ const token = window.localStorage.getItem('token') if (token) { - config.params = { - 'token':token + config.headers = { + 'x-access-token':token } } return config diff --git a/src/view/login/index.vue b/src/view/login/index.vue index c932492..7a64428 100644 --- a/src/view/login/index.vue +++ b/src/view/login/index.vue @@ -2,7 +2,10 @@ import { ref,reactive } from "vue"; import {useRoute,useRouter} from 'vue-router' import { getCode,login } from '@/api/user' + import {userStore} from "@/store/user"; import { showToast } from 'vant' + const store=userStore() + interface Istate{ checked:boolean; accounts:string; @@ -41,6 +44,7 @@ state.code=res.code } } + const router = useRouter() const loginSubmit=async ()=>{ if(!state.code){ showToast('请输入验证码') @@ -55,15 +59,27 @@ code:state.code }) if(res.errCode===200){ - + //d登录成功之后需要把登录返回的数据存到store中 + store.setUserInfo(res.data) + if(store.role=='1'){ + router.push('/task') + } + if(store.role=='2'){ + router.push('/talent') + } + + }else{ + showToast(res.msg) } } - + const onClickLeft=()=>{ + history.back() + }