parent
90a4ce5fd3
commit
c9f437c3ee
@ -0,0 +1,3 @@
|
||||
NODE_ENV = 'development'
|
||||
VUE_APP_URL = ''
|
||||
VUE_APP_CDN = ''
|
@ -0,0 +1,3 @@
|
||||
NODE_ENV = 'production'
|
||||
VUE_APP_URL = ''
|
||||
VUE_APP_CDN = ''
|
File diff suppressed because it is too large
Load Diff
@ -1,32 +1,31 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<div id="nav">
|
||||
<router-link to="/">Home</router-link> |
|
||||
<router-link to="/about">About</router-link>
|
||||
</div>
|
||||
<router-view/>
|
||||
<router-view></router-view>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
#app {
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-align: center;
|
||||
color: #2c3e50;
|
||||
<script>
|
||||
export default {
|
||||
// mounted () {
|
||||
// // 关闭浏览器窗口的时候清空浏览器缓存在localStorage的数据
|
||||
// window.onbeforeunload = function (e) {
|
||||
// var storage = window.localStorage
|
||||
// storage.clear()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
</script>
|
||||
|
||||
#nav {
|
||||
padding: 30px;
|
||||
<style >
|
||||
#app{
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#nav a {
|
||||
font-weight: bold;
|
||||
color: #2c3e50;
|
||||
*{
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#nav a.router-link-exact-active {
|
||||
color: #42b983;
|
||||
html,body{
|
||||
margin: 0px;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
@ -0,0 +1,38 @@
|
||||
import { GetAxios } from '@/utils/request'
|
||||
import router from '../router'
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 全局前置守卫
|
||||
if (to.path === '/about' || to.path === '/register') {
|
||||
next()
|
||||
} else {
|
||||
// 验证token
|
||||
if (localStorage.getItem('manage-token') !== null) {
|
||||
next()
|
||||
} else {
|
||||
next({
|
||||
path: '/about'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
export const axios = GetAxios((config) => {
|
||||
// 在发送请求之前做些什么
|
||||
config.headers['device-type'] = 'web'
|
||||
config.headers['manage-token'] = localStorage.getItem('manage-token')
|
||||
return config
|
||||
}, process.env.VUE_APP_URL, response => {
|
||||
if (response.status === 200) {
|
||||
if (response.headers['content-type'].indexOf('application/json') !== -1) {
|
||||
if (response.data.code === 10000) {
|
||||
// 登录失败 跳转到登陆页面
|
||||
// 跳转到登录页
|
||||
router.push({ path: 'about' })
|
||||
} else {
|
||||
return response.data
|
||||
}
|
||||
} else {
|
||||
// 文件流
|
||||
}
|
||||
}
|
||||
return response.data
|
||||
})
|
@ -0,0 +1,10 @@
|
||||
import { axios } from './auth'
|
||||
|
||||
// 项目列表
|
||||
export const login = (params) => {
|
||||
return axios({
|
||||
url: '/login',
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
export const imagePath = process.env.VUE_APP_URL + '/file/image'
|
||||
export const filePath = process.env.VUE_APP_URL + '/file/file'
|
||||
export const cdnImage = (imagePath) => { return imagePath === '' ? '' : process.env.VUE_APP_CDN + imagePath }
|
||||
export const upHeaders = () => {
|
||||
return {
|
||||
'device-type': 'web',
|
||||
'manage-token': localStorage.getItem('manage-token')
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* 接口统一集成模块
|
||||
*/
|
||||
import * as file from './file'
|
||||
import * as basic from './basic'
|
||||
|
||||
// 默认全部导出
|
||||
export const api = {
|
||||
basic,
|
||||
file
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
/*
|
||||
Write your variables here. All available variables can be
|
||||
found in element-ui/packages/theme-chalk/src/common/var.scss.
|
||||
For example, to overwrite the theme color:
|
||||
*/
|
||||
$--color-primary: teal;
|
||||
|
||||
/* icon font path, required */
|
||||
$--font-path: '~element-ui/lib/theme-chalk/fonts';
|
||||
|
||||
@import "~element-ui/packages/theme-chalk/src/index";
|
@ -0,0 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import Element from 'element-ui'
|
||||
import '@/assets/css/element-variables.scss'
|
||||
|
||||
Vue.use(Element)
|
@ -0,0 +1,29 @@
|
||||
import { api } from '@/api'
|
||||
|
||||
export const utils = {
|
||||
api: api,
|
||||
formatDate: (time, fmt) => {
|
||||
if (time > 0) {
|
||||
const date = new Date(time * 1000)
|
||||
if (/(y+)/.test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
|
||||
}
|
||||
const o = {
|
||||
'M+': date.getMonth() + 1,
|
||||
'd+': date.getDate(),
|
||||
'h+': date.getHours(),
|
||||
'm+': date.getMinutes(),
|
||||
's+': date.getSeconds()
|
||||
}
|
||||
for (const k in o) {
|
||||
if (new RegExp(`(${k})`).test(fmt)) {
|
||||
const str = o[k] + ''
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : ('00' + str).substr(str.length))
|
||||
}
|
||||
}
|
||||
return fmt
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import axios from 'axios'
|
||||
export const GetAxios = (config, baseUrl, toResponse) => {
|
||||
const instance = axios.create({
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
instance.defaults.baseURL = baseUrl
|
||||
instance.defaults.withCredentials = true
|
||||
|
||||
// 添加请求拦截器
|
||||
instance.interceptors.request.use(config, function (error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// 添加响应拦截器
|
||||
instance.interceptors.response.use(function (response) {
|
||||
// 对响应数据做点什么
|
||||
// console.log(response)
|
||||
return toResponse(response)
|
||||
}, function (error) {
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(error)
|
||||
})
|
||||
return instance
|
||||
}
|
@ -1,5 +1,20 @@
|
||||
<template>
|
||||
<div class="about">
|
||||
<h1>This is an about page</h1>
|
||||
<h1>{{msg}}</h1>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { api } from '@/api'
|
||||
export default ({
|
||||
data () {
|
||||
return {
|
||||
msg: ''
|
||||
}
|
||||
},
|
||||
created () {
|
||||
api.basic.login({ userName: 'admin', password: '123456' }).then(res => {
|
||||
console.log(res)
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in new issue