import $Config from "@/config/index.js" import { uploadFile_Api } from "@/api/feedback.js" // 计算点位距离 export const distanceCalculate = (num) => { const num_ = Number(num); if (typeof num_ === 'number') { if (num_ < 1000) { return `${num_.toFixed(1)}米` } else { const n = (num_ / 1000).toFixed(1); return `${n}公里` }; } return num_ || num } // 拨打电话 export const PhoneCall = (tel) => { return new Promise((resolve, reject) => { if (tel) { uni.makePhoneCall({ phoneNumber: tel + '', success: res => { resolve() }, fail: () => { reject() } }); } else { uni.showToast({ title: '暂未设置电话' }); } }) } // 导航 export const getMapLocation = (parmas = {}) => { const { latitude, longitude, name, detailedAddress } = parmas uni.openLocation({ latitude: parseFloat(latitude), // 要去的地址经度,浮点数 longitude: parseFloat(longitude), // 要去的地址纬度,浮点数 name: name, // 位置名 address: detailedAddress, // 要去的地址详情说明 scale: 16, // 地图缩放级别,整形值,范围从1~28。默认为最大 }); } export const getLocation = () => { return new Promise((resolve, reject) => { try { uni.getLocation({ type: 'wgs84', // 返回可以用于uni.openLocation的经纬度 success: (res) => { console.log("getLocation 1111111111111111111= ", res) // this.selfLatitude = res.longitude; // this.selfLongitude = res.latitude; resolve(res) }, fail: (err) => { console.log('获取位置失败2 :', err); reject() } }); } catch (error) { console.log('获取位置失败 1:', error); //TODO handle the exception } }) } export const uploadImage = (num = 1, type = 'img') => { return new Promise(async (resolve, reject) => { uni.chooseImage({ count: num, sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 sourceType: ['album'], //从相册选择 // crop: { // quality: 100, // 图片裁剪质量 // width: 100, // 裁剪的宽度 // height: 100, //裁剪的高度 // resize: false //是否将width和height作为裁剪保存图片真实的像素值。默认值为true。注:设置为false时在裁剪编辑界面显示图片的像素值,设置为true时不显示 // }, success: (res) => { console.log("res = ", res) // 选中的文件对象 const FilePaths = res.tempFilePaths; const Names = [] res.tempFiles.forEach(el => { Names.push(el.name) }) uni.showLoading({ title: '上传中', mask: true }); const UploadList = FilePaths.map(el => SingleFileUpload(el)) Promise.all(UploadList).then(res => { const Files = []; res.forEach((el, index) => { if (el) { Files.push({ annexUrl: el, annexName: Names[index] }) } }); if (Files && Files.length) { uni.hideLoading(); uni.showToast({ title: '上传成功', icon: 'none', duration: 1000 }) resolve(Files) } else { uni.showToast({ title: '上传失败', icon: 'none', duration: 1000 }) resolve([]) } }); }, fail: () => { uni.hideLoading(); }, complete: () => { // uni.hideLoading(); } }) }) } // uploadFile_Api export const SingleFileUpload = (file, showLoading = false) => { return new Promise((resolve, reject) => { if (showLoading) { uni.showLoading({ title: '上传中', mask: true }); } uni.uploadFile({ url: $Config.baseURL + '/dev/file/uploadHuaweiYunReturnUrl', filePath: file, name: 'file', success: (uploadFileRes) => { const { code, data, msg } = JSON.parse(uploadFileRes.data) if (code === 200) { resolve(data) } else { resolve() } }, fail(fail) { resolve() }, complete: () => { if (showLoading) { uni.hideLoading(); } } }) }) }