上传视频
uploadImg() {
let that = this;
uni.chooseVideo({
count: 1,
compressed: false,
success: chooseImageRes => {
const tempFilePaths = chooseImageRes.tempFile;
console.log(chooseImageRes);
let token = uni.getStorageSync('token');
token = token ? token : 'X';
uni.showLoading({
title: 'loading...',
mask: true
});
uni.uploadFile({
url: '
',
file: tempFilePaths,
header: {
Authorization: 'Bearer ' +
token
},
success: uploadFileRes => {
uni.hideLoading();
},
fail: () => {
console.log(
'uploadImage#fail');
uni.hideLoading();
uni.showToast({
title: 'err',
icon: 'none'
});
}
});
}
});
},
上传图片
upload() {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['camera',
'album'
], // camera调拍照,album是打开手机相册
success: (res) => {
console.log(res);
const tempFilePaths = res.tempFiles[0];
console.log(tempFilePaths);
// console.log('tempFilePaths555', tempFilePaths)
const tempFiles = res.tempFiles;
// console.log('tempFiles--555', tempFiles[0])
let token = '122174bf0b6a0c8de8e494fd10818c14'
uni.showLoading({
title: 'loading...',
mask: true
});
// 上传图片到服务器
uni.uploadFile({
url: '
', //服务器地址
fileType: "image", //ZFB必填,不然报错
// filePath: tempFiles, // 上面拍照返回或者选中照片返回的数组
file: tempFilePaths, // 上面拍照返回或者选中照片返回的数组
name: 'imgFile',
header: {
"token": token,
'content-type': 'multipart/form-data'
},
success: (uploadFileRes) => {
let imgData = JSON.parse(
console.log('2222',
uploadFileRes);
uni.hideLoading();
// console.log('2222', imgData);
// console.log(imgData.data.imgUrl);
// console.log(this);
// this.selectedSrc = imgData.data.imgUrl
},
fail: (err) => {
console.log("err", err)
console.log(
'uploadImage#fail');
uni.hideLoading();
uni.showToast({
title: 'err',
icon: 'none'
});
}
});
}
});
},
小数转百分比
toPercent(point) {
let str = Number(point * 100);
str += '%';
return str;
},
时分秒倒计时
let activity_time={
houer: '24',
minute: '00',
second: '00'
}, //活动倒计时
activityTime() {
let that = this;
let timer = setInterval(function() {
if (that.activity_time.second == 0) {
if (
that.activity_time.minute == 0 &&
that.activity_time.houer == 0 &&
that.activity_time.second == 0
) {
clearTimeout(timer);
return;
}
if (that.activity_time.minute == 0) {
that.activity_time.houer = that.roundNumber(
that.activity_time.houer
);
that.activity_time.second = 59;
that.activity_time.minute = 59;
} else {
that.activity_time.minute = that.roundNumber(
that.activity_time.minute
);
that.activity_time.second = 59;
}
} else {
that.activity_time.second = that.roundNumber(
that.activity_time.second
);
}
}, 1000);
},
roundNumber(number) {
number--;
number = number.toString();
if (number.length == 1) {
return '0' + number;
}
return number;
},
防抖
let timers
if (this.timers) {
clearTimeout(this.timers);
}
this.timers = setTimeout(() => {
log(123)
}, 1000);
筛选数组所有值不为空
let bool = this.answerList.every(function(item, index) {
return item !== '';
});
if (bool) {
this.buttonState = true
}
跳转
goCheck(url) {
let that = this
let arr = [
{(主页面-setTabBar)},
{(主页面-setTabBar)}
];
if (url != '' && url != null) {
let bool = arr.some(function(item, index) {
return item.url == url;
});
if (bool) {
uni.switchTab({
url: url
});
return;
}
if (url.indexOf('h') == 0) {
window.location.href = url;
} else {
uni.navigateTo({
url: url
});
}
}
},
希望有不足的地方可以指出,持续改进
作者:superKun
链接:https://juejin.cn/post/7249386837368848439
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。