// import SparkMD5, { // hash // } from 'spark-md5' import $mConfig from '@/config/global.config.js'; export const getPhotograph = () => { uni.chooseImage({ count: 6, //默认9 sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 sourceType: ['camera ', 'album'], //从相册选择 success: function(res) { console.log(JSON.stringify(res.tempFilePaths)); } }); // // #ifdef APP-PLUS // var appid = plus.runtime.appid; // console.log('应用的 appid 为:' + appid); // // #endif // // #ifdef APP // var cmr = plus.camera.getCamera(); // // 属性: // // supportedImageResolutions: 字符串数组,摄像头支持的拍照分辨率 // // supportedVideoResolutions: 字符串数组,摄像头支持的摄像分辨率 // // supportedImageFormats: 字符串数组,摄像头支持的拍照文件格式 // // supportedVideoFormats: 字符串数组,摄像头支持的摄像文件格式 // // 方法: // // captureImage: 进行拍照操作 // // startVideoCapture: 调用摄像头进行摄像操作 // // stopVideoCapture: 结束摄像操作 // // 拍照 captureImage // var res = cmr.supportedImageResolutions[0]; // var fmt = cmr.supportedImageFormats[0]; // console.log("Resolution: " + res + ", Format: " + fmt); // cmr.captureImage(function(path) { // console.log("Capture image success: " + path); // }, // function(error) { // console.log("Capture image failed: " + error.message); // }, { // resolution: res, // format: fmt // } // ) // // 摄像 // // function videoCapture(){ // // } // // var cmr = plus.camera.getCamera(); // // var res = cmr.supportedVideoResolutions[0]; // // var fmt = cmr.supportedVideoFormats[0]; // // console.log("Resolution: " + res + ", Format: " + fmt); // // cmr.startVideoCapture(function(path) { // // console.log("Capture video success: " + path); // // }, // // function(error) { // // console.log("Capture video failed: " + error.message); // // }, { // // resolution: res, // // format: fmt // // } // // ); // // #endif } export const distanceCalculate = (num) => { if (typeof num === 'number') { if (num < 1000) { return `${num.toFixed(1)}米` } else { const n = (num / 1000).toFixed(1); return `${n}公里` }; } return num } export const uploadImage = (num = 1, type = 'img') => { return new Promise(async (resolve, reject) => { console.log('uploadImage = ', num) // // #ifdef APP-PLUS // let flag = await permision.showAuthTipModal("android.permission.READ_EXTERNAL_STORAGE") // reject() // if (!flag) return // // #endif // console.log('uploadImage = 2 ', num) 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) => { // 选中的文件对象 const FilePaths = res.tempFilePaths; // 记录失败的个数 let failNum = 0; // 上传成功返回的媒体资源 const successArr = [] uni.showLoading({ title: '上传中', mask: true }); FilePaths.forEach(el => { SingleFileUpload(el).then(res => { successArr.push(res.url) if ((successArr.length + failNum) >= FilePaths .length) { uni.hideLoading(); uni.showToast({ title: '上传成功', icon: 'success', duration: 1000 }) resolve(successArr) } }).catch(err => { failNum++ }) }) }, complete: () => { uni.hideLoading(); } }) }) } export const SingleFileUpload = (file, showLoading = false) => { return new Promise((resolve, reject) => { if (showLoading) { uni.showLoading({ title: '上传中', mask: true }); } uni.uploadFile({ url: $mConfig.baseUrl + '/common/upload', filePath: file, name: 'file', success: (uploadFileRes) => { const data = JSON.parse(uploadFileRes.data) .data; resolve(data) }, fail(fail) { reject() // if ((successArr.length + failNum) >= FilePaths // .length) { // uni.hideLoading(); // } }, complete: () => { if (showLoading) { uni.hideLoading(); } } }) }) } export const getLocation = async () => { // // #ifdef APP-PLUS // let flag = await permision.showAuthTipModal("android.permission.ACCESS_FINE_LOCATION") // if (!flag) return // // #endif return new Promise((resolve, reject) => { uni.getLocation({ type: 'gcj02', geocode: true, cacheTimeout: 30 * 60, success: res => { console.log('getLocation 666 = ', res) resolve(res) }, fail: err => { permision.showManualAuth("android.permission.ACCESS_FINE_LOCATION") return resolve(null) }, }); }) }