import $http from './request'
// 时间戳转日期
function timestampToTime(timestamp) {
var date = new Date(timestamp*1000); //10位*1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
return Y+M+D;
}
function timestampToTimes(timestamp) {
var date = new Date(timestamp*1000); //10位*1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
var h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes()) + ':';
var s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
return Y+M+D+h+m+s;
}
// 跳转页面 1返回首页
function toPage(type,url){
if(type == 1){
uni.switchTab({
url: "/pages/index/index"
})
}if(type == 3){
uni.switchTab({
url:url
})
}else{
uni.navigateTo({
url:url
})
}
}
function toMine() {
uni.switchTab({
url: "/pages/mine/mine"
})
}
// function dataFormat(data,str){
// for(let i=0;i<this[data].length;i++){
// for(var key in this[data][i]){
// var a = str+"["+[i]+"]"+"["+[key]+"]"
// data[a] = this[data][i][key]
// }
// }
// }
// 返回上一页面
function goBack(){
uni.navigateBack({
delta:1
})
}
// 上传图片
function uploadFile(path,imgList){
uni.showLoading({
title: '上传中'
});
uni.uploadFile({
url: '/wk/api/app/uploadify', //post请求的地址
filePath:path,
name: 'file',
success: res => {
let temp = JSON.parse(res.data)
// 鉴黄
$http.post('/wk/api/life/imageCensor', {
image_url: temp.data,
}).then((res) => {
if (res.conclusion == "合规") {
uni.hideLoading()
imgList.push(temp.data)
uni.showToast({
title: temp.msg,
duration: 2000
});
} else {
uni.hideLoading()
uni.showToast({
title:res.conclusion,
icon:'none'
})
}
});
},
file: res => {
uni.hideLoading()
}
})
}
module.exports = {
timestampToTime:timestampToTime,
timestampToTimes: timestampToTimes,
toPage:toPage,
toMine:toMine,
goBack:goBack,
uploadFile:uploadFile
}
页面调用方法
that.util.timestampToTime(需要转换的时间)
@tap="util.toPage(1)"
@tap="util.toMine()"
@tap="util.goBack()"
//上传图片
// 主图
handleAvatarSuccess() {
let that = this
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success(res) {
that.util.uploadFile(res.tempFiles[0].path).then(imgPath => {
that.sizeForm.photo = imgPath
})
}
})
},