mirror of
https://github.com/eyebluecn/tank-front
synced 2026-10-19 16:16:18 +00:00
Ready to integrety the Matter with Tank.
This commit is contained in:
@@ -14,9 +14,12 @@
|
||||
<i class="fa fa-plus"></i>
|
||||
创建文件夹
|
||||
</button>
|
||||
|
||||
</NbFilter>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<NbTank :tank="tank"/>
|
||||
</div>
|
||||
<div v-if="director.createMode">
|
||||
<MatterPanel ref="newMatterPanel" @createDirectorySuccess="refresh()" :matter="newMatter"
|
||||
:director="director"/>
|
||||
@@ -66,7 +69,11 @@
|
||||
pager: new Pager(Matter, 50),
|
||||
user: this.$store.state.user,
|
||||
breadcrumbs: this.$store.state.breadcrumbs,
|
||||
director: new Director()
|
||||
director: new Director(),
|
||||
//正在排队等待上传的文件。
|
||||
tanks: [],
|
||||
//一个测试的tank
|
||||
tank: new Tank("*", true, 1024 * 1024 * 1024)
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</span>
|
||||
|
||||
</div>
|
||||
<div class="right-part">
|
||||
<div class="right-part" v-if="matter.uuid">
|
||||
|
||||
<span class="matter-operation">
|
||||
<i class="fa fa-pencil btn-action text-primary" title="重命名" @click.stop.prevent="prepareRename"></i>
|
||||
|
||||
+21
-103
@@ -6,9 +6,7 @@ import {getMimeType} from "../../util/MimeUtil";
|
||||
//当前tank处于怎样的步骤中
|
||||
let Procedure = {
|
||||
'FREE': 'FREE',
|
||||
'FETCHING_UPLOAD_TOKEN': 'FETCHING_UPLOAD_TOKEN',
|
||||
'UPLOADING': 'UPLOADING',
|
||||
'FETCHING_DOWNLOAD_TOKEN': 'FETCHING_DOWNLOAD_TOKEN',
|
||||
'DOWNLOADING': 'DOWNLOADING'
|
||||
}
|
||||
|
||||
@@ -59,9 +57,7 @@ export default class Tank extends BaseEntity {
|
||||
|
||||
}
|
||||
|
||||
static URL_FETCH_UPLOAD_TOKEN = '/tank/fetch/upload/token'
|
||||
static URL_DOWNLOAD = '/tank/download/'
|
||||
static URL_CONFIRM = '/tank/confirm'
|
||||
static URL_UPLOAD = '/matter/upload'
|
||||
|
||||
render(obj) {
|
||||
super.render(obj)
|
||||
@@ -287,17 +283,6 @@ export default class Tank extends BaseEntity {
|
||||
return false
|
||||
}
|
||||
|
||||
//开始下载
|
||||
download() {
|
||||
|
||||
if (this.privacy) {
|
||||
window.open(Vue.http.options.root + Tank.URL_DOWNLOAD + this.uuid)
|
||||
} else {
|
||||
window.open(this.url)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//在上传的途中,清空一切,从头开始。
|
||||
clear() {
|
||||
|
||||
@@ -313,45 +298,6 @@ export default class Tank extends BaseEntity {
|
||||
|
||||
}
|
||||
|
||||
//去服务器上汇报自己上传工作已经完成。
|
||||
httpConfirm(successMessage, errorMessage) {
|
||||
let that = this
|
||||
|
||||
if (!this.uuid) {
|
||||
this.errorMessage = '不能正常确认文件'
|
||||
return
|
||||
}
|
||||
|
||||
this.httpPost(Tank.URL_CONFIRM, {uuid: this.uuid, matterUuid: this.matterUuid}, function (response) {
|
||||
|
||||
that.render(response.data.data);
|
||||
|
||||
|
||||
if (typeof successMessage === "function") {
|
||||
successMessage(response)
|
||||
}
|
||||
|
||||
}, errorMessage)
|
||||
}
|
||||
|
||||
//获取上传的token
|
||||
httpFetchUploadToken(successMessage, errorMessage) {
|
||||
let that = this
|
||||
|
||||
if (!this.validate()) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
this.httpPost(Tank.URL_FETCH_UPLOAD_TOKEN, this.getForm(), function (response) {
|
||||
|
||||
that.render(response.data.data);
|
||||
|
||||
(typeof successMessage === 'function') && successMessage()
|
||||
|
||||
}, errorMessage)
|
||||
}
|
||||
|
||||
//文件上传
|
||||
httpUpload(successCallback, failureCallback) {
|
||||
|
||||
@@ -372,64 +318,36 @@ export default class Tank extends BaseEntity {
|
||||
return
|
||||
}
|
||||
|
||||
this.procedure = Procedure.FETCHING_UPLOAD_TOKEN
|
||||
this.httpFetchUploadToken(function (response) {
|
||||
//(兼容性:chrome,ff,IE9及以上)
|
||||
let formData = new FormData()
|
||||
|
||||
//(兼容性:chrome,ff,IE9及以上)
|
||||
let formData = new FormData()
|
||||
formData.append('uploadTokenUuid', that.uploadTokenUuid)
|
||||
formData.append('file', that.file)
|
||||
|
||||
formData.append('uploadTokenUuid', that.uploadTokenUuid)
|
||||
formData.append('file', that.file)
|
||||
that.procedure = Procedure.UPLOADING
|
||||
that.httpPost(that.uploadUrl, formData, function (response) {
|
||||
|
||||
that.procedure = Procedure.UPLOADING
|
||||
that.httpPost(that.uploadUrl, formData, function (response) {
|
||||
//上传到tank服务器成功了,更新matterUuid.
|
||||
that.matterUuid = response.data.data.uuid
|
||||
|
||||
//上传到tank服务器成功了,更新matterUuid.
|
||||
that.matterUuid = response.data.data.uuid
|
||||
}, function (response) {
|
||||
|
||||
//去服务器确认文件
|
||||
that.httpConfirm(function (response) {
|
||||
console.log("上传到tank服务器失败", response.data)
|
||||
console.log(response)
|
||||
|
||||
console.log("确认成功啦!")
|
||||
that.procedure = Procedure.FREE
|
||||
that.procedure = Procedure.FREE
|
||||
that.errorMessage = '上传出错,请稍后重试'
|
||||
that.clear()
|
||||
|
||||
//已经被自己服务器确认过了
|
||||
that.confirmed = true
|
||||
that.defaultErrorHandler(response, failureCallback)
|
||||
|
||||
if (typeof successCallback === 'function') {
|
||||
successCallback(response)
|
||||
}
|
||||
}, {
|
||||
progress: function (event) {
|
||||
|
||||
}, function () {
|
||||
//上传进度。
|
||||
that.progress = event.loaded / event.total
|
||||
|
||||
|
||||
that.procedure = Procedure.FREE
|
||||
that.errorMessage = '准备去确认,出错啦'
|
||||
that.clear()
|
||||
|
||||
that.defaultErrorHandler(response, failureCallback)
|
||||
|
||||
})
|
||||
|
||||
}, function (response) {
|
||||
|
||||
console.log("上传到tank服务器失败", response.data)
|
||||
console.log(response)
|
||||
|
||||
that.procedure = Procedure.FREE
|
||||
that.errorMessage = '上传出错,请稍后重试'
|
||||
that.clear()
|
||||
|
||||
that.defaultErrorHandler(response, failureCallback)
|
||||
|
||||
}, {
|
||||
progress: function (event) {
|
||||
|
||||
//上传进度。
|
||||
that.progress = event.loaded / event.total
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -20,13 +20,6 @@
|
||||
</div>
|
||||
</NbExpanding>
|
||||
|
||||
|
||||
<NbExpanding>
|
||||
<div v-show="tank.procedure === tank.Procedure.FETCHING_UPLOAD_TOKEN">
|
||||
<i class="fa fa-spinner fa-spin fa-fw"></i> 准备上传中...
|
||||
</div>
|
||||
</NbExpanding>
|
||||
|
||||
<NbExpanding>
|
||||
<div class="huge-block clearfix"
|
||||
v-if="tank.procedure === tank.Procedure.UPLOADING">
|
||||
@@ -57,15 +50,12 @@
|
||||
</div>
|
||||
<div>
|
||||
<i class="f16" v-show="tank.fileIcon() && !tank.publicImgUrl()" :class="[tank.fileIcon()]"></i>
|
||||
<span class="f14 black cursor hover-underline" @click.stop.prevent="tank.download()">
|
||||
<span class="f14 black">
|
||||
{{tank.name}}
|
||||
</span>
|
||||
<span>
|
||||
{{tank.size | humanFileSize}}
|
||||
</span>
|
||||
<span>
|
||||
<i class="btn-action f16 fa fa-download text-success" @click.stop.prevent="tank.download()"></i>
|
||||
</span>
|
||||
<span v-if="edit">
|
||||
<i class="btn-action f16 fa fa-trash text-danger" @click.stop.prevent="del()"></i>
|
||||
</span>
|
||||
@@ -119,13 +109,15 @@
|
||||
methods: {
|
||||
fileChanged() {
|
||||
let that = this
|
||||
|
||||
let value = that.$refs['refFile'].value
|
||||
if (!value) {
|
||||
return
|
||||
}
|
||||
|
||||
this.tank.file = this.$refs['refFile'].files[0]
|
||||
this.beginUpload(this.$refs['refFile'].files[0])
|
||||
},
|
||||
beginUpload(file) {
|
||||
let that = this
|
||||
this.tank.file = file
|
||||
|
||||
this.tank.httpUpload(function (response) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user