Commit 52d5adeb46ba50b227a85f5bf1f823005290486f

Authored by Adam
Exists in master

Merge branch 'master' into 'master'

Master

See merge request !5
... ... @@ -44,7 +44,7 @@ export default [{ // user login
44 44 url: '/yp/user/login',
45 45 type: 'post',
46 46 response: config => {
47   - console.log('config-------->', config.body);
  47 + console.log('config-----111--->', config.body);
48 48 const {
49 49 username,
50 50 password
... ... @@ -63,9 +63,10 @@ export default [{ // user login
63 63 }
64 64 }
65 65 } else {
  66 + console.log('passwordpasswordpassword', username, password);
66 67 return {
67 68 code: 60204,
68   - message: 'Account and password are incorrect.'
  69 + message: 'Account and password are incorrect///.'
69 70 }
70 71 }
71 72 }
... ...
... ... @@ -4,12 +4,12 @@ import request from '@/utils/request'
4 4 export function login(data) {
5 5 console.log('login.1111...', data)
6 6 return request({
7   - // url: '/yp/user/login',
8   - url: '/yp.user.login.php',
  7 + url: '/yp/user/login',
  8 + // url: '/yp.user.login.php',
9 9 method: 'post',
10   - headers: {
11   - 'Content-type': 'application/x-www-form-urlencoded'
12   - },
  10 + // headers: {
  11 + // 'Content-type': 'application/x-www-form-urlencoded'
  12 + // },
13 13 data,
14 14 // responseType: 'text/plain',
15 15 // onDownloadProgress: false,
... ... @@ -22,10 +22,15 @@ export function getInfo(token) {
22 22 console.log('getInfo....', token)
23 23 return request({
24 24 url: '/yp/user/info',
  25 + // url: '/yp.user.info.php',
25 26 method: 'get',
26 27 params: {
27 28 token
28 29 }
  30 + // ,
  31 + // headers: {
  32 + // 'Content-type': 'application/x-www-form-urlencoded'
  33 + // },
29 34 })
30 35 }
31 36  
... ... @@ -44,7 +49,7 @@ export function add(token) {
44 49 console.log('addUser....', token)
45 50 return request({
46 51 url: '/yp/user/add',
47   - method: 'get',
  52 + method: 'post',
48 53 params: {
49 54 token
50 55 }
... ... @@ -55,17 +60,18 @@ export function modi(token) {
55 60 console.log('modiUser....', token)
56 61 return request({
57 62 url: '/yp/user/modi',
58   - method: 'get',
  63 + method: 'post',
59 64 params: {
60 65 token
61 66 }
62 67 })
63 68 }
64 69  
65   -export function logout() {
66   - console.log('logout....')
  70 +export function logout(token) {
  71 + console.log('logout....', token)
67 72 return request({
68 73 url: '/yp/user/logout',
69   - method: 'post'
  74 + // url: '/yp.user.logout.php',
  75 + method: 'post',
70 76 })
71 77 }
... ...
src/store/modules/app.js
1 1 import Cookies from 'js-cookie'
2 2  
  3 +//state
3 4 const state = {
4 5 sidebar: {
5 6 opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
... ... @@ -8,6 +9,7 @@ const state = {
8 9 device: 'desktop'
9 10 }
10 11  
  12 +//mutations
11 13 const mutations = {
12 14 TOGGLE_SIDEBAR: state => {
13 15 state.sidebar.opened = !state.sidebar.opened
... ... @@ -28,6 +30,7 @@ const mutations = {
28 30 }
29 31 }
30 32  
  33 +//actions
31 34 const actions = {
32 35 toggleSideBar({ commit }) {
33 36 commit('TOGGLE_SIDEBAR')
... ...
src/store/modules/user.js
1   -import { login, logout, getInfo } from '@/api/user'
2   -import { getToken, setToken, removeToken } from '@/utils/auth'
3   -import { resetRouter } from '@/router'
  1 +import {
  2 + login,
  3 + logout,
  4 + getInfo
  5 +} from '@/api/user'
  6 +import {
  7 + getToken,
  8 + setToken,
  9 + removeToken
  10 +} from '@/utils/auth'
  11 +import {
  12 + resetRouter
  13 +} from '@/router'
4 14  
5 15 const getDefaultState = () => {
6 16 return {
... ... @@ -33,30 +43,46 @@ const mutations = {
33 43  
34 44 const actions = {
35 45 // user login
36   - login({ commit }, userInfo) {
37   - const { username, password } = userInfo
  46 + login({
  47 + commit
  48 + }, userInfo) {
  49 + const {
  50 + username,
  51 + password
  52 + } = userInfo
38 53 return new Promise((resolve, reject) => {
39   - login({ username: username.trim(), password: password }).then(response => {
40   - const { data } = response
41   - console.log('action------->login------->处理', data);
42   - commit('SET_TOKEN', data.token)
43   - setToken(data.token)
  54 + login({
  55 + username: username.trim(),
  56 + password: password
  57 + }).then(response => {
  58 + console.log('返回的数据-- step 3------>', response);
  59 + // const { token, name, id, password } = response
  60 + const {token,name} = response
  61 + console.log('返回的数据-- step 4------>', response);
  62 + commit('SET_TOKEN', token)
  63 + setToken(token)
44 64 resolve()
45 65 }).catch(error => {
  66 + console.log('返回的数据-- step 4.1------>', error);
46 67 reject(error)
47 68 })
48 69 })
49 70 },
50 71  
51 72 // get user info
52   - getInfo({ commit, state }) {
  73 + getInfo({
  74 + commit,
  75 + state
  76 + }) {
53 77 return new Promise((resolve, reject) => {
54 78 getInfo(state.token).then(response => {
55   - const { data } = response
56   - if (!data) {
  79 + console.log('返回的数据-- step 5------>', state);
  80 + console.log('返回的数据-- step 5.1------>', response);
  81 + const {avatar,id,name,password,roles,token} = response
  82 + if (!roles) {
57 83 reject('Verification failed, please Login again.')
58 84 }
59   - const { roles, name, avatar } = data
  85 + console.error('返回的数据-- step 5.2------>', response);
60 86 // roles must be a non-empty array
61 87 if (!roles || roles.length <= 0) {
62 88 reject('getInfo: roles must be a non-null array!')
... ... @@ -64,15 +90,19 @@ const actions = {
64 90 commit('SET_ROLES', roles)
65 91 commit('SET_NAME', name)
66 92 commit('SET_AVATAR', avatar)
67   - resolve(data)
  93 + resolve(response)
68 94 }).catch(error => {
  95 + console.log('返回的数据-- step 5.3------>', error);
69 96 reject(error)
70 97 })
71 98 })
72 99 },
73 100  
74 101 // user logout
75   - logout({ commit, state }) {
  102 + logout({
  103 + commit,
  104 + state
  105 + }) {
76 106 return new Promise((resolve, reject) => {
77 107 logout(state.token).then(() => {
78 108 removeToken() // must remove token first
... ... @@ -86,7 +116,9 @@ const actions = {
86 116 },
87 117  
88 118 // remove token
89   - resetToken({ commit }) {
  119 + resetToken({
  120 + commit
  121 + }) {
90 122 return new Promise(resolve => {
91 123 removeToken() // must remove token first
92 124 commit('RESET_STATE')
... ... @@ -101,4 +133,3 @@ export default {
101 133 mutations,
102 134 actions
103 135 }
104   -
... ...
src/utils/request.js
... ... @@ -15,9 +15,9 @@ const service = axios.create({
15 15 baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
16 16 // withCredentials: true, // send cookies when cross-domain requests
17 17 timeout: 5000, // request timeout
18   - headers: {
19   - 'Content-Type': 'application/x-www-form-urlencoded'
20   - }
  18 + // headers: {
  19 + // 'Content-Type': 'application/x-www-form-urlencoded'
  20 + // }
21 21 })
22 22  
23 23 // request interceptor
... ... @@ -32,7 +32,7 @@ service.interceptors.request.use(
32 32 // ['X-Token'] is a custom headers key
33 33 // please modify it according to the actual situation
34 34 config.headers['X-Token'] = getToken();
35   - config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
  35 + // config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
36 36 // var token = getToken()
37 37 // Object.assign(config.headers, { 'token': token })
38 38 }
... ... @@ -41,7 +41,7 @@ service.interceptors.request.use(
41 41 error => {
42 42 // console.log('do something with request error')
43 43 // do something with request error
44   - console.error(error) // for debug
  44 + console.error('出现错误。在use里。======>', error) // for debug
45 45 return Promise.reject(error)
46 46 }
47 47 )
... ... @@ -61,7 +61,7 @@ service.interceptors.response.use(
61 61 */
62 62 response => {
63 63 const res = response.data
64   - console.log('返回的数据-------->', res);
  64 + console.log('返回的数据-- step 1------>', res);
65 65 /**
66 66 * 下面的注释为通过response自定义code来标示请求状态,当code返回如下情况为权限有问题,登出并返回到登录页
67 67 * 如通过xmlhttprequest 状态码标识 逻辑可写在下面error中
... ... @@ -93,17 +93,18 @@ service.interceptors.response.use(
93 93 return Promise.reject(new Error(res.message || 'Error'))
94 94 } else {
95 95 // const token = res.data.token;
96   - console.log('进入20000号判断-------->', res);
97   - return res;
  96 + console.log('进入20000号判断- step 2------->', res.data);
  97 + const data = res.data;
  98 + return data;
98 99 }
99 100 },
100 101 error => {
101   - console.error('===============发生错误!!!!!===============' + error) // for debug
102   - Message({
103   - message: error.message,
104   - type: 'error',
105   - duration: 5 * 1000
106   - })
  102 + console.error('===============发生错误!!!!!===============' + error.message); // for debug
  103 + // Message({
  104 + // message: error.message,
  105 + // type: 'error',
  106 + // duration: 5 * 1000
  107 + // })
107 108 return Promise.reject(error)
108 109 }
109 110 )
... ...
... ... @@ -36,6 +36,7 @@ module.exports = {
36 36 warnings: false,
37 37 errors: true
38 38 },
  39 + //线下API测试时,可以去掉这个Mock数据。
39 40 before: require('./mock/mock-server.js')
40 41 },
41 42 configureWebpack: {
... ...