You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

235 lines
8.6 KiB

import {getLocation, getUserInfo, setLocation} from "@/util/user";
import {API, MAIN_API} from "@/config";
import {get} from "@/api/request";
import {areaInfoByNameReq, areaInfoReq} from "@/api/common";
export const ORDER_STATUS_LIST = ['已取消', '进行中', '已完成', '申请退款中', '退款完成', '退款失败']
export const CHECK_STATUS_LIST = [
{
label: '审核中',
color: 'info'
},
{
label: '审核通过',
color: 'success'
},
{
label: '审核拒绝',
color: 'error'
},
{
label: '已到账',
color: 'success'
},
]
export const chooseImg = (limit = 1, sourceType = ['album', 'camera']) => {
return new Promise(resolveMain => {
const {token} = getUserInfo()
uni.chooseImage({
count: limit,
sourceType,
extension: ['png', 'jpg', 'jpeg'],
sizeType: ['compressed'],
success: ({tempFiles}) => {
const resList = []
tempFiles.forEach(file => {
const res = new Promise(resolve => {
uni.uploadFile({
url: `${MAIN_API}/api/file/upload`,
name: 'file',
filePath: file.path,
header: {
Authorization: token
},
formData: {
file: file
},
success: uploadRes => {
const {data} = JSON.parse(uploadRes.data)
resolve({
path: data.url,
})
}
})
})
resList.push(res)
})
Promise.all(resList).then(result => {
resolveMain(result)
})
}
})
})
}
export const uploadImg = filePath => {
const {token} = getUserInfo()
uni.showLoading({title: '上传中'})
return new Promise(resolve => {
uni.uploadFile({
url: `${MAIN_API}/api/file/upload`,
name: 'file',
filePath,
header: {
Authorization: token
},
formData: {
type: 'header'
},
success: uploadRes => {
uni.hideLoading()
const {data: {url}} = JSON.parse(uploadRes.data)
resolve({
path: url,
})
}
})
})
}
export const getLocationAction = (save = true) => {
return new Promise((resolve, reject) => {
const res = getLocation()
if (res.area_id) resolve(res)
else {
uni.authorize({
scope: 'scope.userLocation',
success: () => {
uni.getLocation({
isHighAccuracy: true,
success: async ({longitude, latitude}) => {
const {result} = await get(`https://api.tianditu.gov.cn/geocoder?postStr={'lon':${longitude},'lat':${latitude},'ver':1}&type=geocode&tk=1099ec280e86f4e9b632173326cde90b`)
const areaRes = await areaInfoByNameReq({name: result.addressComponent.county}).catch(() => {
if (!this.areaId) reject(false)
})
if (save) setLocation({
longitude,
latitude,
province_str: result.addressComponent.province,
city_str: result.addressComponent.city,
area_str: result.addressComponent.county,
area_id: areaRes.data.id,
city_id: areaRes.data.fid,
province_id: areaRes.data.city.fid
})
resolve({
longitude,
latitude,
area_id: areaRes.data.id,
city_id: areaRes.data.fid,
province_id: areaRes.data.city.fid,
province_str: result.addressComponent.province,
city_str: result.addressComponent.city,
area_str: result.addressComponent.county,
})
},
fail: () => {
reject(false)
}
})
},
fail: () => {
uni.showModal({
title: '提示',
content: '为了更好的提供服务,请开启定位服务',
success: ({confirm}) => {
if (confirm) uni.openSetting()
}
})
}
})
}
})
}
export const chooseVideo = (sourceType = ['album', 'camera']) => {
return new Promise((resolveMain, reject) => {
uni.chooseVideo({
sourceType,
compressed: true,
maxDuration: 60,
success: async ({tempFilePath, duration, size}) => {
if (duration > 180) {
uni.showToast({
title: '暂时不支持3分钟以上的视频',
icon: 'none'
})
return reject(false)
}
// 50M限制
if (size > 50 * 1024 * 1024) {
uni.showToast({
title: '暂时不支持50M以上的视频',
icon: 'none'
})
return reject(false)
}
const {token} = getUserInfo()
uni.showLoading({title: '上传中...'})
uni.uploadFile({
url: `${MAIN_API}/api/file/upload`,
name: 'file',
filePath: tempFilePath,
header: {
Authorization: token
},
success: uploadRes => {
const {data} = JSON.parse(uploadRes.data)
uni.hideLoading()
resolveMain({
path: data.url,
})
}
})
}
})
})
}
export const getLocationOnly = () => {
return new Promise((resolve, reject) => {
uni.authorize({
scope: 'scope.userLocation',
success: () => {
uni.getLocation({
isHighAccuracy: true,
success: async ({longitude, latitude}) => {
const {result} = await get(`https://api.tianditu.gov.cn/geocoder?postStr={'lon':${longitude},'lat':${latitude},'ver':1}&type=geocode&tk=1099ec280e86f4e9b632173326cde90b`)
const {data} = await areaInfoByNameReq({name: result.addressComponent.county}).catch(() => {
if (!this.areaId) reject(false)
})
resolve({
longitude,
latitude,
area_id: data.id,
city_id: data.fid,
province_id: data.city.fid,
province_str: result.addressComponent.province,
city_str: result.addressComponent.city,
area_str: result.addressComponent.county,
})
},
fail: () => {
uni.setStorageSync("no_more_realtime_location", 1)
reject(false)
}
})
},
fail: err => {
uni.showModal({
title: '提示',
content: '为了更好的提供服务,请开启定位服务',
success: ({confirm}) => {
if (confirm) uni.openSetting()
}
})
}
})
})
}
export const getExpressMode = () => parseInt(uni.getStorageSync("express_mode"))