tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import _axios, { get } from '@/lin/plugin/axios'
 
class Log {
 
  name = null
 
  start = null
 
  end = null
 
  keyword = null
 
  relationId=null
 
  constructor({
    uPage = 0,
    uCount = 5,
 
    lPage = 0,
    lCount = 10,
 
    sPage = 0,
    sCount = 10,
  }) {
    if (uPage === 0) {
      this.uPage = uPage
    }
    if (uCount) {
      this.uCount = uCount
    }
    if (lPage === 0) {
      this.lPage = lPage
    }
    if (lCount) {
      this.lCount = lCount
    }
    if (sPage === 0) {
      this.sPage = sPage
    }
    if (sCount) {
      this.sCount = sCount
    }
  }
 
  async increaseUpage() {
    this.uPage += 1
  }
 
  async increaseLpage() {
    this.lPage += 1
  }
 
  increaseSpage() {
    this.sPage += 1
  }
 
  init() {
    this.lPage = 0
    this.uPage = 0
    this.sPage = 0
  }
 
  setBaseInfo(name, start, end) {
    this.name = name
    this.start = start
    this.end = end
  }
 
  setBaseInfo2(relationId, start, end) {
    this.relationId = relationId
    this.start = start
    this.end = end
  }
 
  setKeyword(keyword) {
    this.keyword = keyword
  }
 
  async addTestLog() {
    const log = await get('cms/test/info')
    return log
  }
 
  /**
   * 查询已经被记录过日志的用户(分页)
   * @param {number} count 每页个数
   * @param {number} page 第几页
   */
  async getLoggedUsers({ count, page }) {
    const users = await get('cms/log/users', {
      count: count || this.uCount,
      page: page || this.uPage,
    })
    return users
  }
 
  /**
   * 查询日志信息(分页)
   * @param {number} count 每页个数
   * @param {number} page 第几页
   * @param {number} name 用户昵称
   * @param {number} start 起始时间 # 2018-11-01 09:39:35
   * @param {number} end 结束时间
   */
  async getLogs({ count, page, name, start, end, next = false }) {
    if (!next) {
      this.setBaseInfo(name, start, end)
    }
    if (page === 0) {
      this.lPage = 0
    }
    const res = await _axios({
      url: 'cms/log',
      params: {
        count: count || this.lCount,
        page: page || this.lPage,
        name: name || this.name,
        start: start || this.start,
        end: end || this.end,
      },
      handleError: true,
    })
    return res
  }
 
  /**
   * 所搜日志信息(分页)
   * @param {number} count 每页个数
   * @param {number} page 第几页
   * @param {number} keyword 搜索关键词
   * @param {number} name 用户昵称
   * @param {number} start 起始时间 # 2018-11-01 09:39:35
   * @param {number} end 结束时间
   */
  async searchLogs({ count, page, keyword, name, start, end, next = false }) {
    if (!next) {
      this.setBaseInfo(name, start, end)
      this.setKeyword(keyword)
    }
    if (page === 0) {
      this.sPage = 0
    }
    try {
      const res = await get('cms/log/search', {
        count: count || this.sCount,
        page: page || this.sPage,
        keyword: keyword || this.keyword,
        name: name || this.name,
        start: start || this.start,
        end: end || this.end,
      })
      return res
    } catch (error) {
      console.log(error)
    }
  }
 
  async moreUserPage() {
    await this.increaseUpage()
    return this.getLoggedUsers({})
  }
 
  async moreLogPage() {
    await this.increaseLpage()
    return this.getLogs({ next: true })
  }
 
  async moreSearchPage() {
    this.increaseSpage()
    return this.searchLogs({ next: true })
  }
 
  async relationLogs({ count, page, keyword, relationId, start, end, next = false }) {
    if (!next) {
      this.setBaseInfo2(relationId, start, end)
      this.setKeyword(keyword)
    }
    if (page === 0) {
      this.sPage = 0
    }
    try {
      const res = await get(`cms/log/relation_log/${relationId}`, {
        count: count || this.sCount,
        page: page || this.sPage,
        keyword: keyword || this.keyword,
        relationId: relationId || this.relationId,
        start: start || this.start,
        end: end || this.end,
      })
      return res
    } catch (error) {
      console.log(error)
    }
  }
 
}
 
export default new Log({})