Skip to content

Commit 1dd53f3

Browse files
author
zhongzhenlong
committed
finished
1 parent be8e54a commit 1dd53f3

File tree

16 files changed

+682
-158
lines changed

16 files changed

+682
-158
lines changed

config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
port: 9000,
2828
autoOpenBrowser: false,
2929
assetsSubDirectory: 'static',
30-
assetsPublicPath: '',
30+
assetsPublicPath: '/',
3131
proxyTable: {
3232
// http://localhost:9000/api/menuList => http://localhost:3000/menuList
3333
'/api': {

src/axios.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/common/axios.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import axios from "axios";
2+
import qs from "qs";
3+
import auth from "../auth";
4+
import { getBaseUrl } from "../common/utils";
5+
import { MessageBox } from "element-ui";
6+
7+
// axios 配置
8+
axios.defaults.timeout = 5000;
9+
//axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
10+
//axios.defaults.baseURL = 'http://localhost:8008';
11+
axios.defaults.baseURL = getBaseUrl(window.location.href);
12+
axios.defaults.headers.common[ 'authUid' ] = auth.getUid();
13+
axios.defaults.headers.common[ 'authSid' ] = auth.getSid();
14+
15+
//POST传参序列化
16+
axios.interceptors.request.use((config) => {
17+
if (config.method === 'post') {
18+
config.data = qs.stringify(config.data);
19+
}
20+
return config;
21+
}, (error) => {
22+
return Promise.reject(error);
23+
});
24+
25+
//返回状态判断
26+
axios.interceptors.response.use(
27+
response => {
28+
if (response.data && response.data.code) {
29+
if (response.data.code === '2001') {
30+
auth.logout()
31+
}
32+
}
33+
return response;
34+
},
35+
error => {
36+
if (error.response) {
37+
//全局ajax错误信息提示
38+
//MessageBox({type:"error",message:error.response.data,title:"温馨提示",});
39+
}
40+
//return Promise.reject(error);
41+
});
42+
43+
export function fetch (url, config = { method: 'get' }) {
44+
return axios.request({ ...config, url })
45+
// return new Promise((resolve, reject) => {
46+
// axios.request({ ...config, url })
47+
// .then(response => {
48+
// resolve(response.data);
49+
// }, err => {
50+
// reject(err);
51+
// })
52+
// .catch((error) => {
53+
// reject(error)
54+
// })
55+
// })
56+
}
57+
58+
export default axios

src/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import Vue from "vue";
33
import frame from "./frame.vue";
44
import router from "./router";
55
import store from "./store";
6-
import axios from "./axios";
6+
import axios from "./common/axios";
77
import filters from "./filters";
88
import VueProgressBar from "vue-progressbar";
99
import Element from "element-ui";
1010
// import 'element-ui/lib/theme-default/index.css';
1111
// import "./css/theme/index.css";
1212
import ImpPanel from "./components/panel.vue";
1313

14+
Vue.prototype.$http = axios
15+
Vue.axios = axios
16+
Vue.http = axios;
1417
Vue.use(axios);
1518

1619
Vue.use(Element);

src/pages/layout/header.vue

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
</div>
1818
<el-dropdown-menu>
1919
<ul class="message-list">
20-
<li v-for="item in list"><!-- start message -->
20+
<li v-for="(item,index) in list"><!-- start message -->
2121
<router-link :to="{path:'/sys/message',query:{id:item.id}}">
22-
<p>{{item.title}}</p>
22+
<p>{{index + 1}}. {{item.title}}</p>
2323
</router-link>
2424
</li>
2525
</ul>
@@ -58,6 +58,8 @@
5858
import types from "../../store/mutation-types"
5959
import * as api from "../../api"
6060
import auth from '../../auth'
61+
import * as sysApi from '../../services/sys'
62+
6163
export default {
6264
data(){
6365
return {
@@ -120,22 +122,13 @@
120122
}
121123
this.count = 0;
122124
this.list = [];
123-
this.$http.get(api.MSG_TOP_TEN)
125+
sysApi.msgList()
124126
.then(res => {
125-
if (res.data && res.data.length>0){
126-
this.count = res.data.length;
127-
this.list = res.data;
127+
if (res && res.length>0){
128+
this.count = res.length;
129+
this.list = res;
128130
}
129131
})
130-
.catch(err=>{
131-
this.list = [{"id":"640000201501165883","type":0,"code":107,"timeLine":"2013031613","message":"阶期查音音南这认式给自来走事。手进全线引其质行族导深些。","title":"作几点内部重压示现或采候器日","createTime":"426050337874","senderName":"Hall","senderPic":"http://dummyimage.com/100x100/f2799f/757575.png&text=H"},
132-
{"id":"15000019760303327X","type":1,"code":109,"timeLine":"1994030718","message":"听飞叫例感给其团南织主作什。","title":"府铁些以眼铁南单行办其被眼线","createTime":"612808881585","senderName":"Hall","senderPic":"http://dummyimage.com/100x100/79c3f2/757575.png&text=H"},
133-
{"id":"530000198607165793","type":1,"code":106,"timeLine":"1990122503","message":"于学认气感很效效引需说报党。调应各近思常市美许自毛完容矿日增。","title":"整近律马造起米农员济解题自例识个","createTime":"234654265042","senderName":"Rodriguez","senderPic":"http://dummyimage.com/100x100/e6f279/757575.png&text=R"},
134-
{"id":"320000200905032842","type":1,"code":103,"timeLine":"1980062104","message":"除年命却积同部去断权议党低二易过。","title":"消问料品把精是器话","createTime":"1194108860623","senderName":"Lewis","senderPic":"http://dummyimage.com/100x100/da79f2/757575.png&text=L"},
135-
{"id":"210000198109172937","type":1,"code":104,"timeLine":"1993041210","message":"具都主部确特次取圆派不儿日和难力。","title":"导结计市色通证确高想","createTime":"374284498307","senderName":"Hernandez","senderPic":"http://dummyimage.com/100x100/79f2b7/757575.png&text=H"},
136-
{"id":"410000200402164212","type":1,"code":108,"timeLine":"2015123015","message":"青矿地级质还进眼件每产它整区土容斯消。","title":"治龙工必近思空例东应","createTime":"626036503938","senderName":"Martinez","senderPic":"http://dummyimage.com/100x100/f29479/757575.png&text=M"}]
137-
this.count = this.list.length;
138-
})
139132
},
140133
mounted() {
141134
// document.addEventListener('click', this.autoHide, false)
@@ -159,7 +152,7 @@
159152
position: fixed;
160153
min-width: 100%;
161154
box-shadow: 0 2px 3px hsla(0, 0%, 7%, .1), 0 0 0 1px hsla(0, 0%, 7%, .1);
162-
z-index: 9999;
155+
z-index: 1999;
163156
animation-name: slideInDown;
164157
animation-fill-mode: both;
165158
color: #48576a;

src/pages/login.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import types from '../store/mutation-types'
5050
import * as api from "../api"
5151
import auth from '../auth'
52+
import * as sysApi from '../services/sys'
5253
import {mapGetters, mapActions, mapMutations} from 'vuex'
5354
5455
export default {
@@ -74,10 +75,8 @@
7475
if (this.$route.query && this.$route.query != null && this.$route.query.redirect && this.$route.query.redirect != null) {
7576
redirectUrl = this.$route.query.redirect;
7677
}
77-
this.$http.post(api.LOGIN, this.form).then(res => {
78-
this.loginSuccess({...res.data,redirectUrl})
79-
}).catch(error=>{
80-
this.loginSuccess({user: {name: "管理员"}, redirectUrl, sid: '1234567890',})
78+
sysApi.login(this.form).then(res => {
79+
this.loginSuccess({...res,redirectUrl})
8180
})
8281
},
8382
loginSuccess({sid,user,redirectUrl}){

src/pages/register.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
·
3131
<script>
3232
import * as types from '../store/mutation-types'
33-
import api from '../axios'
3433
export default {
3534
name: 'login',
3635
data() {
@@ -100,7 +99,7 @@
10099
this.$refs[formName].validate((valid) => {
101100
if (valid) {
102101
let opt = this.registerValidateForm;
103-
api.userRegister(opt).then(({
102+
this.$http.post(opt).then(({
104103
data
105104
}) => {
106105
if (data.success) {

0 commit comments

Comments
 (0)