register.ts
4.69 KB
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
import http from '@/http/HttpClient'
import BaseResponse from '@/model/BaseResponse'
import axios, { AxiosResponse } from 'axios'
// 这里将API方法统一管理
export default class HomeApi {
// 注册接口
static register(params : object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.post('login/register', params, {})
.then((res) => {
return res
})
}
// 登录 接口
static login(params : object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.post('login/login', params, {})
.then((res) => {
return res
})
}
// 登录 接口 type:phonenumber register login
static getCode(params : object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.post('login/sendSms', params, {})
.then((res) => {
return res
})
}
// 获取服务条款
static getNotice(params : object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.get('common/getNotice', {params})
.then((res) => {
return res
})
}
// 获取用户信息
static getUserInfo() : Promise<AxiosResponse<any, any>> {
return http
.server()
.get('login/getInfo')
.then((res) => {
return res
})
}
// 提交审核
static submitSign(params : object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.post('sign/save', params, {})
.then((res) => {
return res
})
}
// 获取认证信息
static getSignInfo() : Promise<AxiosResponse<any, any>> {
return http
.server()
.get('sign/getSignInfo', {} )
.then((res) => {
return res
})
}
// 获取省市信息
static getHarbourAreaTree() : Promise<AxiosResponse<any, any>> {
return http
.server()
.get('common/harbourAreaTree', { })
.then((res) => {
return res
})
}
// 获取邀请码
static getFollowCode(params: object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.post('common/createTempTicket', params, {})
.then((res) => {
return res
})
}
// 获取消息详情
static getNoticeDetail(params: object) : Promise<AxiosResponse<any, any>> {
return http
.server()
.get('common/getOfficialMsg', {params})
.then((res) => {
return res
})
}
// 上传图片 sensitiveType: 文件敏感类型:false-无敏感信息,true-有敏感信息
static async upload(params : Array<string>) {
let res = await uploadFiles(params)
let result = res.filter((item) => item != '')
return Promise.resolve(result)
}
}
function uploadFiles(files : Array<string>) {
const compressedImages = files.map((item) => {
return uploadFile(item)
})
return Promise.all(compressedImages)
}
function uploadFile(file) {
return new Promise((resolve) => {
if (file.endsWith('.mp4')) {
var filename = 'text.mp4'
var array = file.valueOf().split('/')
if (array.length > 0) {
filename = array[array.length - 1]
}
let headers = {
'Content-Disposition': 'attachment;filename=' + filename,
}
const baseURL = http.getBaseURL() + 'common/upload'
const token = wx.getStorageSync('token') || ""
headers['Authorization'] = token
wx.uploadFile({
url: baseURL,
filePath: file,
name: 'file',
timeout: 120000,
header: headers,
success: (res) => {
console.log('上传返回res', res)
const string = res.data
// console.log('上传返回string',string)
const data = JSON.parse(string)
console.log('上传返回data', data)
if (data.code === 200) {
resolve(data.msg)
} else {
console.log('上传失败1')
resolve('')
}
},
fail: (error) => {
console.log('上传失败', error)
resolve('')
}
})
} else {
wx.getImageInfo({
src: file,
success: (info) => {
var filename = 'text.png'
var array = info.path.valueOf().split('/')
if (array.length > 0) {
filename = array[array.length - 1]
}
console.log('filename', filename)
let headers = {
'Content-Disposition': 'attachment;filename=' + filename,
}
const baseURL = http.getBaseURL() + 'common/upload'
const token = wx.getStorageSync('token') || ""
headers['Authorization'] = token
wx.uploadFile({
url: baseURL,
filePath: info.path,
name: 'file',
header: headers,
success: (res) => {
const string = res.data
// console.log('上传返回string',string)
const data = JSON.parse(string)
// console.log('上传返回data', data)
if (data.code === 200) {
resolve(data.msg)
} else {
resolve('')
}
},
fail: (error) => {
console.log(error)
resolve('')
}
})
},
fail: (error) => {
console.log(error)
resolve('')
}
})
}
})
}