diff --git a/components/account/login.vue b/components/account/login.vue index e5b5484..51f3ef9 100644 --- a/components/account/login.vue +++ b/components/account/login.vue @@ -15,7 +15,9 @@ diff --git a/components/account/register.vue b/components/account/register.vue index 0fb7817..80ca01b 100644 --- a/components/account/register.vue +++ b/components/account/register.vue @@ -64,7 +64,7 @@ this.$refs.form.validate((valid: boolean)=>{ if(valid){ let that=this - this.GLOBAL.postJSON('/v1/api/users/sign_up',{ userName: this.form.user, password: this.form.password },function(res) { + this.GLOBAL.fetchJSON('/v1/api/users/sign_up','POST',{ userName: this.form.user, password: this.form.password },function(res) { if(res.code==='200'){ that.$message.info(that.$t('account.form.tip.register_ok').toString()) that.$router.push(that.localePath('/')) diff --git a/nuxt.config.js b/nuxt.config.js index 9dc7228..8a15d27 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -216,13 +216,14 @@ export default { }, "reading_online": "在线阅读", "reset": "重置", + "select_please": "请选择{keyword}", "tip": "提示", "today_recommend": "今日推荐", "unknown_error": "未知错误", "upload": { "form": { "author": "论文作者", - "content": "论文", + "content": "正文内容", "profession": "学科专业", "remove": "确定移除{file}", "school": "学校", @@ -237,6 +238,7 @@ export default { "ok": "论文上传成功" } }, + "upload_please": "请上传{keyword}", "user": "帐号", "zhCN": "简体中文" }, @@ -371,6 +373,7 @@ export default { }, "reading_online": "", "reset": "", + "select_please": "", "tip": "", "today_recommend": "", "unknown_error": "", @@ -392,6 +395,7 @@ export default { "ok": "" } }, + "upload_please": "", "user": "", "zhCN": "Simplified Chinese" } diff --git a/pages/index/upload.vue b/pages/index/upload.vue index 6fb481c..8143d86 100644 --- a/pages/index/upload.vue +++ b/pages/index/upload.vue @@ -1,40 +1,40 @@ @@ -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 + } + }) } } }) diff --git a/plugins/global.js b/plugins/global.js index 0a605d8..1a6bef3 100644 --- a/plugins/global.js +++ b/plugins/global.js @@ -14,16 +14,17 @@ Vue.prototype.GLOBAL ={ return !(r.top > z.bottom || r.bottom < z.top || r.left > z.right || r.right < z.left); }, - postJSON(url,form,success){ + fetchJSON(url,method, form, success){ fetch(this.server_address + url, { body:JSON.stringify(form), - method: 'POST', + method: method, headers: { 'Content-Type': 'application/json' - } + }, + credentials: "include" }).then(res=>res.json()).then(res=>success(res)).catch(err=>{ console.error(err) }) - } + }, }