Commit 80c27c51 by liangjianmin

js

parent db4449d6
import axios from 'axios';
import qs from 'qs';
import Util from "../tool";
/**
......@@ -25,14 +26,20 @@ switch (envs) {
NODE_ENVS = '/';
break;
}
export const http = (method, url, param) => {
param = param && typeof param === 'object' ? param : {};
let token = Util.getCookie('token') || '';
const config = {
url: `${NODE_ENVS}${url}`,
method: method,
transformRequest: [function (param) {
return qs.stringify(param);
}]
}],
headers: {
'Authorization': 'Bearer ' + token
}
};
// post请求时需要设定Content-Type
......
......@@ -6,6 +6,7 @@ import directive from './directive'
import {http} from './ajax/index.js';
import axios from 'axios'
import {Message} from 'element-ui';
import Util from "./tool";
//本地环境开启提示信息
Vue.config.productionTip = false;
......@@ -14,6 +15,7 @@ Vue.config.productionTip = false;
import '@/assets/css/public/common.min.css'
import '@/assets/css/font/iconfont.css'
//加载过滤器
Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));
......@@ -57,7 +59,6 @@ router.afterEach((to, from, next) => {
}
});
axios.interceptors.response.use(res => {
return res;
}, error => {
......@@ -65,10 +66,25 @@ axios.interceptors.response.use(res => {
return Promise.reject(new Error(error))
})
//挂载到VUE原型上封装后的http请求
Vue.prototype.$http = http;
//路由页面回跳处理 mate里面参数 back:true 开启登录态回跳
router.beforeEach((to, from, next) => {
http('get', "/api/user/getuserinfo", {
}).then(data => {
let res = data.data;
if (res.err_code === 101) {
window.location.href = '/#/login'
}
}).catch(err => {
console.log(err.message);
})
next();
});
new Vue({
router,
render: (h) => h(App),
......
export default {
sayHellow(){
alert("hello")
return true;
/**
* 设置cookie
* @param name
* @param value
* @param iDay
*/
setCookie: function (name, value, time, domain) {
domain = domain ? ";domain=" + domain : "";
var Days = time;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString() + ";path=/" + domain;
return true;
},
/**
* 获取cookie
* @param name
* @returns {*}
*/
getCookie: function (name) {
var strCookie = document.cookie;
var arrCookie = strCookie.split("; ");
for (var i = 0; i < arrCookie.length; i++) {
var arr = arrCookie[i].split("=");
if (name == arr[0]) {
return arr[1];
}
}
return null;
},
/**
* 删除cookie
* @param name
*/
delCookie: function (name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
}
......@@ -180,12 +180,11 @@
<li class="row rowCenter verCenter">本月</li>
<li class="row rowCenter verCenter">全年</li>
</ul>
<el-form-item label="更新日期">
<el-date-picker v-model="date" type="daterange" range-separator="至" start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</el-form-item>
<el-form>
<el-form-item label="更新日期">
<el-date-picker v-model="date" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
</el-form-item>
</el-form>
</div>
</div>
<div class="wrap row">
......@@ -207,12 +206,13 @@
import * as echarts from 'echarts';
import {
Button,
Form,
FormItem,
Message,
DatePicker
} from 'element-ui';
Vue.use(Button).use(DatePicker);
Vue.use(Form).use(FormItem).use(DatePicker);
export default {
name: "index",
......@@ -223,7 +223,6 @@
},
watch: {},
created() {
},
mounted() {
var myChart = echarts.init(document.getElementById('echarts_box'));
......
......@@ -51,6 +51,7 @@
<script>
import Vue from 'vue';
import {Loading, Message} from 'element-ui';
import Util from "../../tool";
export default {
name: "index",
......@@ -90,7 +91,6 @@
},
created() {
this.updateCp();
Message('2121');
},
computed: {},
methods: {
......@@ -129,7 +129,7 @@
background: 'rgba(0, 0, 0, 0)'
});
this.$http('post', "/auth/login1", {
this.$http('post', "/auth/login", {
mobile: this.form.mobile,
password: this.form.password,
captcha: this.form.captcha,
......@@ -138,9 +138,11 @@
loadingInstance.close();
let res = data.data;
if (res.err_code === 0) {
Util.setCookie("token", res.data.api_token, 1);
window.location.href = '/';
} else {
Message(res.err_msg);
this.updateCp();
}
}).catch(err => {
loadingInstance.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment