<template>
|
<view class="pages-my-log-upload">
|
<view class="list">
|
<checkbox-group @change="checkboxChange">
|
<label class="group" v-for="item in fileList" :key="item.name">
|
<view>
|
<checkbox :value="item.name" :checked="item.checked" />
|
</view>
|
<view class="name">{{item.name}}</view>
|
<template v-if="item.result"> <uni-icons v-if="item.result==1" type="checkmarkempty" size="20"
|
color="#55aa00"></uni-icons>
|
<uni-icons v-if="item.result ==2" type="info" size="20" color="#ff0000"></uni-icons>
|
</template>
|
|
|
<progress v-if="uploadingItem.fileName== item.name" :percent="uploadingItem.progress"
|
activeColor="#10AEFF" stroke-width="3" />
|
</label>
|
|
</checkbox-group>
|
</view>
|
<view class="button-line">
|
|
<checkbox :checked="checkeAll" @click="clickCheckeAll">{{translate("select_all")}}</checkbox>
|
<!-- <a-button
|
type="primary" class="button" @click="clickLogSendEmail">
|
{{translate('email_send')}}
|
</a-button> -->
|
<a-button type="primary" class="button" :loading="uploadingFlag" @click="clickLogSend">
|
{{translate('upload')}}
|
</a-button>
|
<a class="btn" @click="clickLogClear">
|
<uni-icons type="trash" size="28" :color="uploadingFlag?'gray':'#1890FF'"></uni-icons>
|
</a>
|
</view>
|
</view>
|
</template>
|
<script>
|
import {
|
showToast,
|
showModal,
|
showError,
|
showInfo
|
} from "@/comm/utils.js"
|
import TaskInit from "@/comm/extend.js"
|
|
import {
|
Button
|
} from 'antd-mobile-vue-next'
|
import {
|
uploadLogPackage
|
} from "@/api/version.js"
|
export default {
|
name: "PagesMyLogUpload",
|
components: {
|
'a-button': Button
|
},
|
data() {
|
return {
|
fileList: [],
|
host: "smtp.163.com",
|
port: "465",
|
yourEmail: "cuiqian2004@163.com",
|
yourPwd: "QWfCFwa54a6L66Xr",
|
toEmail: "nancy0606@qq.com",
|
checkeAll: false,
|
uploadList: [],
|
uploadingFlag: false,
|
uploadingItem: {
|
progress: 0,
|
fileName: ""
|
}
|
}
|
},
|
onLoad() {
|
|
this.loadData()
|
},
|
methods: {
|
setData(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
|
async loadData() {
|
try {
|
this.fileList = await TaskInit.fileUtils.listSavedFiles('download')
|
this.fileList.forEach((a) => {
|
a.checked = false
|
})
|
} catch (ex) {
|
console.log(ex)
|
}
|
},
|
clickCheckeAll() {
|
this.checkeAll = !this.checkeAll
|
var items = this.fileList
|
for (var i = 0, lenI = items.length; i < lenI; ++i) {
|
const item = items[i]
|
this.$set(item, 'checked', this.checkeAll)
|
}
|
},
|
checkboxChange(e) {
|
var items = this.fileList,
|
values = e.detail.value;
|
for (var i = 0, lenI = items.length; i < lenI; ++i) {
|
const item = items[i]
|
console.log(item)
|
if (values.includes(item.name)) {
|
this.$set(item, 'checked', true)
|
} else {
|
this.$set(item, 'checked', false)
|
}
|
}
|
},
|
async clickLogClear() {
|
|
try {
|
var flag = false
|
for (let i in this.fileList) {
|
const item = this.fileList[i]
|
if (item.checked) {
|
await TaskInit.fileUtils.deleteSavedFile("download", item.name)
|
flag = true
|
}
|
}
|
if (flag) {
|
try {
|
this.fileList = await TaskInit.fileUtils.listSavedFiles()
|
} catch (ex) {
|
console.log(ex)
|
}
|
showToast(this.translate("delete_success"))
|
}
|
} catch (ex) {
|
showError(ex)
|
}
|
|
},
|
clickLogSendEmail() {
|
|
const list = []
|
for (let i in this.fileList) {
|
const item = this.fileList[i]
|
if (item.checked) {
|
list.push(item.fullPath)
|
}
|
}
|
if (list.length > 0) {
|
uni.navigateTo({
|
url: "/pages/my/email?attachment=" + JSON.stringify(list)
|
})
|
}
|
|
},
|
clickLogSend() {
|
|
const list = []
|
this.uploadList = []
|
for (let i in this.fileList) {
|
const item = this.fileList[i]
|
if (item.checked) {
|
list.push(item)
|
}
|
item.result = 0
|
}
|
|
if (list.length > 0) {
|
this.uploadList = list
|
this.uploadLogs()
|
}
|
|
},
|
uploadLogs() {
|
const _this = this
|
if (this.uploadList.length > 0) {
|
console.log("uploadList", this.uploadList.length)
|
const item = this.uploadList.shift()
|
this.setData({
|
uploadingFlag: true,
|
uploadingItem: {
|
progress: 0,
|
fileName: item.name
|
}
|
})
|
uploadLogPackage(item.fullPath, () => {
|
const curItem = this.fileList.find((a) => a.name == item.name)
|
if (curItem) {
|
curItem.result = 1;
|
}
|
_this.uploadLogs()
|
}, (res) => {
|
_this.uploadingItem.progress = res.progress
|
}, (err) => {
|
showToast(`${_this.translate("upload_fail")}:${item.name},${err}`)
|
const curItem = this.fileList.find((a) => a.name == item.name)
|
if (curItem) {
|
curItem.result = 2;
|
}
|
_this.uploadLogs()
|
})
|
} else {
|
this.setData({
|
uploadingFlag: false,
|
uploadingItem: {
|
progress: 0,
|
fileName: ""
|
}
|
})
|
showToast(_this.translate("upload_finish"))
|
}
|
|
},
|
translate(t) {
|
if (typeof this.$t == "function") return this.$t(`page.${t}`)
|
else return t;
|
},
|
|
}
|
}
|
</script>
|
|
<style lang="less">
|
.pages-my-log-upload {
|
display: flex;
|
width: 750rpx;
|
height: 100vh;
|
flex-direction: column;
|
background-color: #F5F5F5;
|
|
.list {
|
flex: 1;
|
overflow-y: auto;
|
display: flex;
|
flex-direction: column;
|
width: 750rpx;
|
}
|
|
.group {
|
width: calc(100% - 20rpx);
|
padding: 15rpx 10rpx;
|
display: flex;
|
flex-direction: row;
|
margin: 10rpx 10rpx;
|
background-color: #fff;
|
border-radius: 10rpx;
|
font-size: 30rpx;
|
position: relative;
|
|
.progress {
|
position: absolute;
|
bottom: 0;
|
left: 0;
|
right: 0;
|
}
|
|
.name {
|
flex: 1;
|
}
|
}
|
|
.button-line {
|
margin: 20rpx;
|
display: flex;
|
flex-direction: row;
|
align-items: center;
|
/* 交叉轴 = 垂直方向居中 */
|
}
|
|
.button {
|
width: 360rpx !important;
|
border-radius: 40rpx;
|
height: 80rpx;
|
line-height: 50rpx;
|
margin: 20rpx;
|
}
|
|
}
|
</style>
|