<template>
<view style="padding: 10px;">
<uni-file-picker limit="1" file-mediatype="all" ref="files" :auto-upload="false" @success="apkupload" @select="selectapk">
<button type="primary">选择安装包</button>
</uni-file-picker>
</view>
</template>
<script>
import {
pathToBase64,
base64ToPath
} from 'image-tools'
export default {
data() {
return {
userid: null,
up: null,
apkinfo: {
package: null,
versionName: null,
Name: null,
icon: null,
}
};
},
onLoad(op) {
var data=op.data.split('')
this.up = data[1]
this.user_id = data[0]
},
methods: {
async selectapk(e) {
var that=this
if(e.tempFiles[0].size>=10241024200){
const verify = await uniCloud.callFunction({
name: 'verifyvip',
data:{
user_id:that.user_id
}
});
if(!verify.result){
uni.showModal({
title: '温馨提示',
content: '文件超过200MB,请购买会员解除限制'
});
return null
}
}
uni.showLoading({
title: '上传中请勿退出'
});
this.$refs.files.upload()
const getapkinfo = new window.AppInfoParser(e.tempFiles[0].file)
getapkinfo.parse().then(result => {
console.log(result);
this.apkinfo.package = result.package
this.apkinfo.versionName = result.versionName
if(typeof result.application.label=='object'){
this.apkinfo.Name = result.application.label[0]
}else{
this.apkinfo.Name = result.application.label
}
this.apkinfo.icon = result.icon
})
},
async apkupload(e) {
var that = this;
var size = e.tempFiles[0].size
var url = e.tempFilePaths[0]
if(this.apkinfo.icon==null){
await uniCloud.callFunction({
name: 'additem',
data: {
icon: "https://mp-e8736984-eb69-4fda-8fbc-8b94a79af7f9.cdn.bspapp.com/cloudstorage/f49947a7-8cbd-473e-a929-d212af2aa618.jpg",
url: url,
size: size,
title: that.apkinfo.Name,
type: 'apk',
version: that.apkinfo.versionName,
package: that.apkinfo.package,
up: that.up,
user_id: that.user_id
}
})
uni.hideLoading()
uni.showToast({
title: '上传成功',
duration: 2000
});
return null
}
base64ToPath(this.apkinfo.icon)
.then(async function(path) {
const imgurl = await uniCloud.uploadFile({
filePath: path,
cloudPath: "icon.png"
});
if(that.apkinfo.Name==null){
that.apkinfo.Name="未命名"
}
await uniCloud.callFunction({
name: 'additem',
data: {
icon: imgurl.fileID,
url: url,
size: size,
title: that.apkinfo.Name,
type: 'apk',
version: that.apkinfo.versionName,
package: that.apkinfo.package,
up: that.up,
user_id: that.user_id
}
})
uni.hideLoading()
uni.showToast({
title: '上传成功',
duration: 2000
});
})
}
}
}
</script>