公共JS

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
						})
					}

				})
			},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值