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.
 
 
 
 

153 lines
4.0 KiB

const app = getApp();
import store from '@/store'
const formatTime = date => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`;
};
const formatNumber = n => {
n = n.toString();
return n[1] ? n : `0${n}`;
};
function chooseImages(callback) {
console.log('weixinupload')
uni.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success: res => {
const tempFilePaths = res.tempFilePaths;
for (let i = 0; i < tempFilePaths.length; i++) {
uni.getImageInfo({
src: tempFilePaths[i],
success: image => {
uni.showLoading({
title: '图片上传中',
mask: true
});
uni.uploadFile({
url: `${app.globalData.baseURL}api/upload`,
file: image,
filePath: image.path,
header: {
Authorization: 'Bearer ' + uni.getStorageSync('login_status'),
},
name: 'file',
success: res => {
if (callback) {
callback(JSON.parse(res.data).link);
}
},
fail: err => {
uni.showToast({
title: '上传图片失败',
icon: 'none',
duration: 2000
});
},
complete: res => {
uni.hideLoading();
}
});
},
fail: err => {
uni.showToast({
title: '获取图片信息失败',
icon: 'none',
duration: 2000
});
}
});
}
}
});
}
function chooseImages2(callback) {
uni.chooseImage({
count: 3,
sourceType: ['album', 'camera'],
success: res => {
const tempFilePaths = res.tempFilePaths;
for (let i = 0; i < tempFilePaths.length; i++) {
uni.getImageInfo({
src: tempFilePaths[i],
success: image => {
uni.showLoading({
title: '图片上传中',
mask: true
});
uni.uploadFile({
url: `${app.globalData.baseURL}api/upload`,
file: image,
filePath: image.path,
header: {
Authorization: 'Bearer ' + uni.getStorageSync('login_status')
},
name: 'file',
success: res => {
if (callback) {
callback(JSON.parse(res.data).link);
}
},
fail: err => {
uni.showToast({
title: '上传图片失败',
icon: 'none',
duration: 2000
});
},
complete: res => {
uni.hideLoading();
}
});
},
fail: err => {
uni.showToast({
title: '获取图片信息失败',
icon: 'none',
duration: 2000
});
}
});
}
}
});
}
const getWeek = date => {
let timeDate = new Date(date.replace(/-/g, "/")); //兼容IOS
let month = timeDate.getMonth() + 1,
day = timeDate.getDay();
return addZero(month) + '.' + addZero(day) + ' ' + '周' + '日一二三四五六'.charAt(day);
};
const addZero = function (num) {
num = num.toString();
return num[1] ? num : '0' + num;
};
const setTime = val => {
let date = val.split(' ')[0];
let times = val.split(' ')[1];
let day = date.split('-')[1] + '.' + date.split('-')[2];
let time = times.split(':')[0] + ':' + times.split(':')[1];
return day + ' ' + time;
};
module.exports = {
formatTime,
chooseImages,
chooseImages2,
getWeek,
setTime
};