# Vue use axios 项目 api 封装

  • src\api\home.js
// src\api\home.js
import Axios from 'axios';
import qs from 'qs';
import moment from 'moment';

// get
export function getContactInfo({ clue_id }) {
  return Axios({
    url: '/api/contact_info/',
    method: 'get',
    params: {
      clue_id, // 同 与 参
    },
  });
}

// 获取用户列表
export function getUsersList({
  pageNo,
  pageCount,
  searchType,
  searchValue,
  sortField,
  sortOrder,
  userStatus,
  status,
  ...
}) {
  return Axios({
    url: '/api/user/search/',
    method: 'get',
    params: {
      page_no: pageNo, // 名同 则只写 pageNo 即可
      page_count: pageCount,
      need_total_count: true,
      user_status:
        (Array.isArray(userStatus) && userStatus.join(',')) ||
        userStatus,
      sort_field: sortField,
      sort_asc: sortOrder === 'asc' ? true : false,
      status: (Array.isArray(status) && status.join(',')) || status,
    },
  });
}

// 获得用户信息
export function getUserDetailInfoApi({ userId }) {
  return Axios({
    url: '/api/oa/user/detail_info/',
    method: 'get',
    params: {
      user_id: userId,
    },
  });
}


// post
export function assignUsersApi({ 
  users,
  teacher
}) {
  return Axios({
    url: '',
    method: 'post',
    data: qs.stringify({
      clue_id: Array.isArray(users) ? JSON.stringify(users) : users,
      ct_key: teacher,
    }),
  });
}


//获取现在时间;
export function getNowTime() {
  var date = new Date();
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? '0' + m : m;
  var d = date.getDate();
  d = d < 10 ? '0' + d : d;
  var h = date.getHours();
  h = h < 10 ? '0' + h : h;
  var minute = date.getMinutes();
  minute = minute < 10 ? '0' + minute : minute;
  var second = date.getSeconds();
  second = second < 10 ? '0' + second : second;
  return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}
//获取昨天时间
export function getYesterdayTime() {
  return [
    moment()
      .subtract(1, 'days')
      .startOf('day')
      .valueOf(),
    moment()
      .subtract(1, 'days')
      .endOf('day')
      .valueOf(),
  ];
}
//获取近30天时间
export function get30DayTime() {
  return [
    moment()
      .subtract(30, 'day')
      .valueOf(),
    moment().valueOf(),
  ];
}
//获取今天时间
export function getTodayTime() {
  return [
    moment()
      .startOf('day')
      .valueOf(),
    moment()
      .endOf('day')
      .valueOf(),
  ];
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123