1549469775 3 years ago
parent
commit
673bbc6117
  1. 2385
      package-lock.json
  2. 3
      src/App.vue
  3. 32
      src/api/_request/interceptors.ts
  4. 11
      src/api/contact/CompanyStruct.ts
  5. 9
      src/api/index.ts
  6. 7
      src/assets/script/request/error.ts
  7. 0
      src/assets/script/request/index.ts
  8. 55
      src/assets/script/request/interceptors.ts
  9. 3
      src/config/index.ts
  10. 0
      src/layout/Layout.vue
  11. 0
      src/layout/SiteContent/SiteContent.vue
  12. 7
      src/layout/SiteHeader/SiteHeader.vue
  13. 0
      src/layout/SiteHeader/style.less
  14. 0
      src/layout/SliderMenu/SliderMenu.vue
  15. 10
      src/main.ts
  16. 12
      src/router/basic/index.ts
  17. 15
      src/router/constant.ts
  18. 7
      tsconfig.json
  19. 3
      vite.config.ts

2385
package-lock.json

File diff suppressed because it is too large

3
src/App.vue

@ -14,5 +14,6 @@ watchEffect(() => {
</template>
<style lang="less">
@import '@/assets/style/common.less';
</style>

32
src/api/_request/interceptors.ts

@ -1,32 +0,0 @@
import type { AxiosInstance, AxiosRequestConfig } from 'axios'
import { userStore } from '@/store/module/user'
export default function createInterceptors(axios: AxiosInstance) {
axios.interceptors.request.use(
function (config: AxiosRequestConfig) {
const store = userStore()
if (config && config.headers&&store.token){
config.headers['token'] = store.token
}
if (config && config.headers && !config!.headers['Content-Type']) {
config.headers['Accept'] = 'application/json';
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
// 在发送请求之前做些什么
return config
},
function (error) {
// 对请求错误做些什么
return Promise.reject(error)
}
)
axios.interceptors.response.use(
function (response) {
return response
},
function (error) {
return Promise.reject(error)
}
)
}

11
src/api/contact/CompanyStruct.ts

@ -1,11 +0,0 @@
import { http } from "@/api/_request"
import { IHttpMethod } from "@/enum"
import { readonly } from "vue"
const api = {
getStruct: (data?: any) => http("/enesoon/organization/v1.0/orgStructure", IHttpMethod.GET, data),
getDepartment: (data?: any) => http("/enesoon/organization/v1.0/orgDepartment", IHttpMethod.GET, data),
getDepartmentEmp: (data?: any) => http("/enesoon/organization/v1.0/departmentEmp", IHttpMethod.GET, data),
}
export default api

9
src/api/index.ts

@ -1,9 +1,8 @@
import { IHttpMethod } from '@/enum'
import { http } from './_request'
import { http } from '$/request'
const api = {
login: (data?: any) => http('/enesoon/login/v1.0/employees', IHttpMethod.GET, data),
export const User = {
// login: (data?: any) => http('/enesoon/login/v1.0/employees', IHttpMethod.GET, data),
login: (data?: any) => http('/api/login', IHttpMethod.GET, data),
getUserProfile: (data?: any) => http('/enesoon/user/v1.0/employees', IHttpMethod.GET, data)
}
export default api

7
src/api/_request/error.ts → src/assets/script/request/error.ts

@ -1,13 +1,14 @@
import { message } from 'ant-design-vue'
import { userStore } from "@/store/module/user"
export default function error(err: any, type: number) {
switch (type) {
case 0:
const store = userStore()
message.error(err?.data?.message?err?.data?.message:"未知错误")
console.log(err?.data?.message?err?.data?.message:"未知错误");
if(err?.data&&err?.data.code === -1){
store.logout(false)
// Token过期逻辑
// store.logout(false)
}
// 响应正确,服务器返回错误
break

0
src/api/_request/index.ts → src/assets/script/request/index.ts

55
src/assets/script/request/interceptors.ts

@ -0,0 +1,55 @@
import type { AxiosInstance, AxiosRequestConfig } from "axios"
import { userStore } from "@/store/module/user"
import checkError from './error'
export default function createInterceptors(axios: AxiosInstance) {
axios.interceptors.request.use(
function (config: AxiosRequestConfig) {
const store = userStore()
if (config && config.headers && store.token) {
config.headers["token"] = store.token
}
if (config && config.headers && !config!.headers["Content-Type"]) {
config.headers["Accept"] = "application/json"
config.headers["Content-Type"] = "application/x-www-form-urlencoded"
}
// 在发送请求之前做些什么
return config
},
function (error) {
// 对请求错误做些什么
return Promise.reject(error)
}
)
axios.interceptors.response.use(
function (response) {
console.log(response);
return Promise.reject(response);
return response
},
function (error) {
const { response } = error
console.log(error);
console.log(response);
if (response) {
// 请求已发出,但是不在2xx的范围
console.log("请求已发出,但是不在2xx的范围");
return Promise.reject(response);
} else {
// 处理断网的情况
// eg:请求超时或断网时,更新state的network状态
// network状态在app.vue中控制着一个全局的断网提示组件的显示隐藏
// 关于断网组件中的刷新重新获取数据,会在断网组件中说明
if (!window.navigator.onLine) {
console.log("网络连接断开");
// store.commit("changeNetwork", false)
} else {
return Promise.reject(error)
}
}
return Promise.reject(error)
}
)
}

3
src/config/index.ts

@ -1 +1,2 @@
export const BASE_URL = "https://enesoon-saas-back-test.cn:8381"
// export const BASE_URL = "https://enesoon-saas-back-test.cn:8381"
export const BASE_URL = ""

0
src/pagesSys/Layout/Layout.vue → src/layout/Layout.vue

0
src/pagesSys/Layout/SiteContent/SiteContent.vue → src/layout/SiteContent/SiteContent.vue

7
src/pagesSys/Layout/SiteHeader/SiteHeader.vue → src/layout/SiteHeader/SiteHeader.vue

@ -1,8 +1,11 @@
<template>
<div>header</div>
<div @click="post">header</div>
</template>
<script lang="ts" setup>
import * as http from "@/api"
async function post(){
await http.User.login()
}
</script>
<style lang="less" scoped>

0
src/pagesSys/Layout/SiteHeader/style.less → src/layout/SiteHeader/style.less

0
src/pagesSys/Layout/SliderMenu/SliderMenu.vue → src/layout/SliderMenu/SliderMenu.vue

10
src/main.ts

@ -6,10 +6,12 @@ import Plugins from "@/plugins"
import Components from "@/components"
import App from "./App.vue"
// import 'virtual:windi.css'
import 'virtual:windi-base.css'
import 'virtual:windi-components.css'
import 'virtual:windi-utilities.css'
import '%/common.less';
// import 'virtual:windi.css';
import 'virtual:windi-base.css';
import 'virtual:windi-components.css';
import 'virtual:windi-utilities.css';
import { setGlobalOptions } from "vue-request"
setGlobalOptions({

12
src/router/basic/index.ts

@ -1,9 +1,7 @@
import {
PAGE_NOT_FOUND_NAME,
LAYOUT,
EXCEPTION_COMPONENT,
LOGIN_COMPONENT,
REDIRECT_NAME,
REDIRECT_COMPONENT,
} from '@/router/constant'
import { RouteRecordRaw } from 'vue-router'
@ -48,12 +46,12 @@ export const LOGIN_ROUTE = {
// 404 on a page
export const PAGE_NOT_FOUND_ROUTE = {
path: '/:path(.*)*',
name: PAGE_NOT_FOUND_NAME,
name: "PageNotFound",
component: LAYOUT,
children: [
{
path: '',
name: PAGE_NOT_FOUND_NAME,
name: "PageNotFound",
component: EXCEPTION_COMPONENT,
meta: {
title: 'ErrorPage',
@ -70,17 +68,17 @@ export const REDIRECT_ROUTE = {
name: 'RedirectTo',
hidden: true,
meta: {
title: REDIRECT_NAME,
title: "Redirect",
hideBreadcrumb: true,
hideSliderMenu: true,
},
children: [
{
path: '/redirect/:path(.*)',
name: REDIRECT_NAME,
name: "Redirect",
component: REDIRECT_COMPONENT,
meta: {
title: REDIRECT_NAME,
title: "Redirect",
hideBreadcrumb: true,
hideSliderMenu: true,
},

15
src/router/constant.ts

@ -1,12 +1,11 @@
export const REDIRECT_NAME = 'Redirect';
export const PARENT_LAYOUT_NAME = 'ParentLayout';
export const PAGE_NOT_FOUND_NAME = 'PageNotFound';
/**
* @description: system pages
*/
export const LOGIN_COMPONENT = () => import("@/pagesSys/Login/Login.vue")
export const EXCEPTION_COMPONENT = () => import("@/pagesSys/Exception/Exception.vue")
export const REDIRECT_COMPONENT = () => import("@/pagesSys/Redirect/Redirect.vue")
export const LOGIN_COMPONENT = () => import('@/pagesSys/Login/Login.vue');
export const EXCEPTION_COMPONENT = () => import('@/pagesSys/Exception/Exception.vue');
export const REDIRECT_COMPONENT = () => import('@/pagesSys/Redirect/Redirect.vue');
/**
* @description: default layout
*/
export const LAYOUT = () => import('@/pagesSys/Layout/Layout.vue');
export const LAYOUT = () => import("@/layout/Layout.vue")

7
tsconfig.json

@ -13,9 +13,10 @@
"lib": ["esnext", "dom"],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@util": ["./src/assets/script/util"],
"#/*": ["./types/*"],
"@/*": ["./src/*"], //
"$/*": ["./src/assets/script/*"], //
"%/*": ["./src/assets/style/*"], //
"#/*": ["./types/*"], //
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "types/**/*.d.ts", "types/**/*.ts", "vite.config.ts"],

3
vite.config.ts

@ -14,7 +14,8 @@ export default ({ mode, command } : { mode: string, command: string}) => {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
alias: {
'@': path.resolve('./src'),
'@util': path.resolve('./src/assets/script/util'),
'$': path.resolve('./src/assets/script'),
'%': path.resolve('./src/assets/style'),
},
},
css: {

Loading…
Cancel
Save