register.ts 4.69 KB
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('')
				}
			})
		}
	})
}