|
|
|
@ -1,40 +1,40 @@ |
|
|
|
|
<template> |
|
|
|
|
<el-form ref="form" :model="form" label-width="80px"> |
|
|
|
|
<el-form-item :label="$t('upload.form.type')"> |
|
|
|
|
<el-select v-model="form.type" :placeholder="$t('input_please',{type:$t('upload.form.type')})"> |
|
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> |
|
|
|
|
<el-form-item :label="$t('upload.form.type')" prop="type"> |
|
|
|
|
<el-select v-model="form.type" :placeholder="$t('select_please',{keyword:$t('upload.form.type')})"> |
|
|
|
|
<el-option v-for="item in options" :key="item.value" :value="item.value">{{item.label}}</el-option> |
|
|
|
|
</el-select> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.author')"> |
|
|
|
|
<el-form-item :label="$t('upload.form.author')" prop="author"> |
|
|
|
|
<el-col :span="4"> |
|
|
|
|
<el-input v-model="form.author" |
|
|
|
|
:placeholder="$t('input_please',{keyword:$t('upload.form.author')})"></el-input> |
|
|
|
|
</el-col> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.profession')"> |
|
|
|
|
<el-form-item :label="$t('upload.form.profession')" prop="profession"> |
|
|
|
|
<el-col :span="4"> |
|
|
|
|
<el-input v-model="form.profession" |
|
|
|
|
:placeholder="$t('input_please',{keyword:$t('upload.form.profession')})"></el-input> |
|
|
|
|
</el-col> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.school')"> |
|
|
|
|
<el-form-item :label="$t('upload.form.school')" prop="school"> |
|
|
|
|
<el-col :span="4"> |
|
|
|
|
<el-input v-model="form.school" |
|
|
|
|
:placeholder="$t('input_please',{keyword:$t('upload.form.school')})"></el-input> |
|
|
|
|
</el-col> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.year')"> |
|
|
|
|
<el-select v-model="form.year" :placeholder="$t('input_please',{keyword:$t('upload.form.year')})"> |
|
|
|
|
<el-form-item :label="$t('upload.form.year')" prop="year"> |
|
|
|
|
<el-select v-model="form.year" :placeholder="$t('select_please',{keyword:$t('upload.form.year')})"> |
|
|
|
|
<el-option v-for="n in 10" :key="n" :value="2019-n">{{2019-n}}</el-option> |
|
|
|
|
</el-select> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.summary')"> |
|
|
|
|
<el-form-item :label="$t('upload.form.summary')" prop="summary"> |
|
|
|
|
<el-col :span="4"> |
|
|
|
|
<el-input v-model="form.summary" type="textarea" |
|
|
|
|
<el-input autosize v-model="form.summary" type="textarea" |
|
|
|
|
:placeholder="$t('input_please',{keyword:$t('upload.form.summary')})"></el-input> |
|
|
|
|
</el-col> |
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.tag')"> |
|
|
|
|
<el-form-item :label="$t('upload.form.tag')" prop="tag"> |
|
|
|
|
<el-tag |
|
|
|
|
:key="tag" |
|
|
|
|
v-for="tag in form.tag.dynamicTags" |
|
|
|
@ -57,22 +57,27 @@ |
|
|
|
|
<el-button v-else class="button-new-tag" size="small" @click="showInput">+ {{$t('upload.form.tag')}}</el-button> |
|
|
|
|
|
|
|
|
|
</el-form-item> |
|
|
|
|
<el-form-item :label="$t('upload.form.content')"> |
|
|
|
|
<el-form-item :label="$t('upload.form.content')" prop="content"> |
|
|
|
|
<el-upload |
|
|
|
|
class="upload-demo" |
|
|
|
|
action="https://jsonplaceholder.typicode.com/posts/" |
|
|
|
|
:action="GLOBAL.server_address+'/v1/api/file/upload'" |
|
|
|
|
:on-preview="handlePreview" |
|
|
|
|
:on-remove="handleRemove" |
|
|
|
|
:before-remove="beforeRemove" |
|
|
|
|
:on-success="uploadOK" |
|
|
|
|
:file-list="form.fileList" |
|
|
|
|
accept=".txt"> |
|
|
|
|
<el-button size="small" type="primary">{{$t('upload.form.upload')}}</el-button> |
|
|
|
|
:limit="1" |
|
|
|
|
accept=".txt" |
|
|
|
|
v-model="form.fileList" |
|
|
|
|
ref="file"> |
|
|
|
|
<el-button size="small" type="primary" v-if="form.fileList.length===0">{{$t('upload.form.upload')}}</el-button> |
|
|
|
|
<div slot="tip" class="el-upload__tip">{{$t('upload.form.upload_tip')}}</div> |
|
|
|
|
</el-upload> |
|
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
|
|
<el-form-item> |
|
|
|
|
<el-button type="primary" @click="onSubmit">{{$t('button.submit')}}</el-button> |
|
|
|
|
<el-button @click="$refs.form.resetFields();$refs.file.clearFiles();form.fileList=[]">{{$t('reset')}}</el-button> |
|
|
|
|
</el-form-item> |
|
|
|
|
</el-form> |
|
|
|
|
</template> |
|
|
|
@ -83,6 +88,7 @@ |
|
|
|
|
export default Vue.extend({ |
|
|
|
|
name: 'upload', |
|
|
|
|
data() { |
|
|
|
|
let that=this |
|
|
|
|
return { |
|
|
|
|
form: { |
|
|
|
|
type: '', |
|
|
|
@ -98,6 +104,42 @@ |
|
|
|
|
}, |
|
|
|
|
fileList: [] |
|
|
|
|
}, |
|
|
|
|
rules: { |
|
|
|
|
type:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('select_please',{keyword:this.$t('upload.form.type')}) |
|
|
|
|
}], |
|
|
|
|
author:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('input_please',{keyword:this.$t('upload.form.author')}) |
|
|
|
|
}], |
|
|
|
|
profession:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('input_please',{keyword:this.$t('upload.form.profession')}) |
|
|
|
|
}], |
|
|
|
|
school:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('input_please',{keyword:this.$t('upload.form.school')}) |
|
|
|
|
}], |
|
|
|
|
year:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('select_please',{keyword:this.$t('upload.form.year')}) |
|
|
|
|
}], |
|
|
|
|
summary:[{ |
|
|
|
|
required: true, |
|
|
|
|
message: this.$t('input_please',{keyword:this.$t('upload.form.summary')}) |
|
|
|
|
}], |
|
|
|
|
content:[{ |
|
|
|
|
validator:(rule, value, callback) => { |
|
|
|
|
if(that.form.fileList.length===0){ |
|
|
|
|
callback(rule.msg) |
|
|
|
|
}else{ |
|
|
|
|
callback() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
msg: this.$t('upload_please',{keyword:this.$t('upload.form.content')}) |
|
|
|
|
}] |
|
|
|
|
}, |
|
|
|
|
options: [{ |
|
|
|
|
value: '硕士论文', |
|
|
|
|
label: '硕士论文' |
|
|
|
@ -108,6 +150,11 @@ |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
//上传成功 |
|
|
|
|
uploadOK(response, file, fileList){ |
|
|
|
|
this.form.fileList=fileList |
|
|
|
|
file.id=response.data |
|
|
|
|
}, |
|
|
|
|
//删除标签 |
|
|
|
|
handleClose(tag:string) { |
|
|
|
|
this.form.tag.dynamicTags.splice(this.form.tag.dynamicTags.indexOf(tag), 1) |
|
|
|
@ -132,7 +179,14 @@ |
|
|
|
|
}, |
|
|
|
|
//删除论文 |
|
|
|
|
handleRemove(file: any, fileList: any) { |
|
|
|
|
console.log(file, fileList) |
|
|
|
|
let that=this |
|
|
|
|
this.GLOBAL.fetchJSON(`/v1/api/file/remove/${this.form.fileList[0].id}`,'DELETE',{},function(res) { |
|
|
|
|
if(res.code==='200'){ |
|
|
|
|
that.form.fileList=[] |
|
|
|
|
}else{ |
|
|
|
|
that.$message.error(that.$t('error_500').toString()) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
//预览论文 |
|
|
|
|
handlePreview(file: any) { |
|
|
|
@ -140,11 +194,40 @@ |
|
|
|
|
}, |
|
|
|
|
//确认移除论文 |
|
|
|
|
beforeRemove(file: { name: string }, fileList: any) { |
|
|
|
|
return this.$confirm(this.$t('upload.form.remove',{file:file.name}).toString()) |
|
|
|
|
return this.$confirm(this.$t('upload.form.remove',{file:file.name}).toString(),{ |
|
|
|
|
confirmButtonText:this.$t('button.ok').toString(), |
|
|
|
|
cancelButtonText:this.$t('button.cancel').toString() |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
//提交论文 |
|
|
|
|
onSubmit(){ |
|
|
|
|
this.$alert(this.$t('upload.tip.ok').toString()) |
|
|
|
|
this.$refs.form.validate((valid: boolean) => { |
|
|
|
|
if(valid){ |
|
|
|
|
let that=this |
|
|
|
|
this.GLOBAL.fetchJSON('/v1/api/paper/upload','POST',{ |
|
|
|
|
type: this.form.type, |
|
|
|
|
author: this.form.author, |
|
|
|
|
profession: this.form.profession, |
|
|
|
|
school: this.form.school, |
|
|
|
|
year: this.form.year, |
|
|
|
|
summary: this.form.summary, |
|
|
|
|
tag:this.form.tag.dynamicTags.join(','), |
|
|
|
|
fileId:this.form.fileList[0].id |
|
|
|
|
},function(res) { |
|
|
|
|
if(res.code==='200'){ |
|
|
|
|
that.$message.info(that.$t('upload.tip.ok').toString()) |
|
|
|
|
}else{ |
|
|
|
|
that.$message.error(that.$t('error_500').toString()) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}else{ |
|
|
|
|
this.$message.error({ |
|
|
|
|
message: this.$t('form_err').toString(), |
|
|
|
|
duration: 2000 |
|
|
|
|
}) |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|