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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* eslint-disable class-methods-use-this */
import _axios, { get, put, _delete } from '@/lin/plugin/axios'
 
// 我们通过 class 这样的语法糖使模型这个概念更加具象化,其优点:耦合性低、可维护性。
class ProjectInfo {
  // constructor() {}
 
  // 类中的方法可以代表一个用户行为
  async createProjectInfo(data) {
    return _axios({
      method: 'post',
      url: 'v1/projectInfo',
      data,
    })
  }
 
  // 在这里通过 async await 语法糖让代码同步执行
  // 1. await 一定要搭配 async 来使用
  // 2. await 后面跟的是一个 Promise 对象
  async getProjectInfo(id) {
    const res = await get(`v1/projectInfo/${id}`)
    return res
  }
 
  async getProjectInfoDetail(id) {
    const res = await get(`v1/projectInfo/detail/${id}`)
    return res
  }
 
  async editProjectInfo(id, info) {
    const res = await put(`v1/projectInfo/${id}`, info)
    return res
  }
 
  async deleteProjectInfo(id) {
    const res = await _delete(`v1/projectInfo/${id}`)
    return res
  }
 
  async getProjectInfoList(params) {
    return _axios({
      method: 'get',
      url: 'v1/projectInfo/list',
      // params:{keyword:keyword},
      params,
      handleError: true,
    })
  }
 
  // async getProjectInfoPage(params) {
  //   return _axios({
  //     method: 'get',
  //     url: 'v1/projectInfo/page',
  //     // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
  //     params,
  //     handleError: true,
  //   })
  // }
  async getProjectInfoPage(data) {
    return _axios({
      method: 'post',
      url: 'v1/projectInfo/page',
      // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
      data,
      handleError: true,
    })
  }
 
  async getProjectInfoReportList(data) {
    return _axios({
      method: 'post',
      url: 'v1/projectInfo/report/list',
      // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
      data,
      handleError: true,
    })
  }
 
  // async exportProjectInfoList(data) {
  //   return _axios({
  //     method: 'post',
  //     url: 'v1/projectInfo/report/list/export',
  //     // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
  //     data,
  //     responseType: 'blob', // 关键点:告诉浏览器这是一份二进制流
  //     handleError: true,
  //   })
  // }
 
  async exportProjectInfoList(data) {
    try {
      const response = await _axios({
        method: 'post',
        url: 'v1/projectInfo/report/list/export',
        data,
        responseType: 'blob', // 确保返回二进制数据
        handleError: true,
      });
 
      // 判断返回数据类型
      if (response && response.data) {
        const contentDisposition = response.headers['content-disposition'];
 
        // 从 Content-Disposition 头部中提取文件名并进行 URL 解码
        let fileName = '项目报表.xlsx'; // 默认文件名
        if (contentDisposition) {
          // 使用正则匹配文件名(支持 UTF-8 编码格式)
          const matches = contentDisposition.match(/filename\*?=UTF-8''([^;]+)/);
          if (matches && matches[1]) {
            // 解码并处理文件名
            fileName = decodeURIComponent(matches[1]);
          }
        }
 
        // 创建一个 Blob 对象,传入文件的二进制数据
        const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
 
        // 创建一个临时的下载链接
        const link = document.createElement('a');
        link.href = URL.createObjectURL(blob); // 生成对象 URL
        link.download = fileName;  // 设置下载文件名
        link.click();  // 触发下载
      }
    } catch (error) {
      console.error('文件下载失败', error);
    }
  }
 
 
 
 
 
  async getProjectStatistics(params) {
    return _axios({
      method: 'get',
      url: 'v1/projectInfo/hourStatistics',
      // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
      params,
      handleError: true,
    })
  }
 
  async getProjectStatisticsUnconfirm(params) {
    return _axios({
      method: 'get',
      url: 'v1/projectInfo/all/hourStatistics',
      // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
      params,
      handleError: true,
    })
  }
 
  // 项目立项
  async editProjectSetUp(id, info) {
    const res = await put(`v1/projectInfo/projectSetUp/${id}`, info)
    return res
  }
 
  // 项目启动
  async editProjectInfoStart(id, info) {
    const res = await put(`v1/projectInfo/projectStart/${id}`, info)
    return res
  }
 
  // 项目完成
  async editProjectInfoComplete(id, info) {
    const res = await put(`v1/projectInfo/projectComplete/${id}`, info)
    return res
  }
 
  // 项目完成
  async editProjectInfoTermination(id, info) {
    const res = await put(`v1/projectInfo/projectTermination/${id}`, info)
    return res
  }
 
  // 项目完成
  async editProjectHours(id, info) {
    const res = await put(`v1/projectInfo/projectHours/${id}`, info)
    return res
  }
 
  getProjectBoard(params) {
    return _axios({
      method: 'post',
      url: 'v1/projectInfo/board',
      // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
      data: params,
      handleError: true,
    })
  }
 
  editProjectProBusDate(id, info) {
    const res = put(`v1/projectInfo/projectProBusDate/${id}`, info)
    return res
  }
 
  /**
   *
   * @param {*} params
   * @returns
   */
  getProjectBoardByMonth(params) {
    return _axios({
      method: 'post',
      url: 'v1/projectInfo/board/month',
      // params:{keyword:queryForm.keyword.value,status:queryForm.status.value,stage:queryForm.stage.value,type:queryForm.type.value},
      data: params,
      handleError: true,
    })
  }
}
 
export default new ProjectInfo()