From 0d82e795dfb9e44440daa03ced61af47f3acc0ef Mon Sep 17 00:00:00 2001 From: ruibaby Date: Wed, 28 Aug 2019 09:46:10 +0800 Subject: [PATCH] Add verification for form. --- .../components/AttachmentDetailDrawer.vue | 25 +- src/views/comment/components/CommentTab.vue | 11 +- src/views/dashboard/Dashboard.vue | 95 +++--- src/views/interface/ThemeList.vue | 7 + src/views/post/CategoryList.vue | 7 + src/views/post/TagList.vue | 7 + src/views/post/components/PostSetting.vue | 25 +- src/views/sheet/components/SheetSetting.vue | 18 +- src/views/system/OptionForm.vue | 275 ++++++++++++++++++ src/views/user/Profile.vue | 21 ++ 10 files changed, 440 insertions(+), 51 deletions(-) diff --git a/src/views/attachment/components/AttachmentDetailDrawer.vue b/src/views/attachment/components/AttachmentDetailDrawer.vue index 60254ba1..ecbe5bf1 100644 --- a/src/views/attachment/components/AttachmentDetailDrawer.vue +++ b/src/views/attachment/components/AttachmentDetailDrawer.vue @@ -19,13 +19,17 @@ >
此文件不支持预览
- + + :playsinline="true" + >
@@ -182,10 +186,12 @@ export default { controls: true, loop: false, playbackRates: [0.7, 1.0, 1.5, 2.0], - sources: [{ - type: 'video/mp4', - src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm' - }], + sources: [ + { + type: 'video/mp4', + src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm' + } + ], poster: '/static/images/author.jpg', width: document.documentElement.clientWidth, notSupportedMessage: '此视频暂无法播放,请稍后再试' @@ -253,6 +259,13 @@ export default { this.editable = !this.editable }, doUpdateAttachment() { + if (!this.attachment.name) { + this.$notification['error']({ + message: '提示', + description: '附件名称不能为空!' + }) + return + } attachmentApi.update(this.attachment.id, this.attachment).then(response => { this.$log.debug('Updated attachment', response.data.data) this.$message.success('附件修改成功!') diff --git a/src/views/comment/components/CommentTab.vue b/src/views/comment/components/CommentTab.vue index 1d8f1436..9f8d7ad1 100644 --- a/src/views/comment/components/CommentTab.vue +++ b/src/views/comment/components/CommentTab.vue @@ -250,12 +250,12 @@ - + /> --> diff --git a/src/views/interface/ThemeList.vue b/src/views/interface/ThemeList.vue index c4174162..9ed8f1b3 100644 --- a/src/views/interface/ThemeList.vue +++ b/src/views/interface/ThemeList.vue @@ -349,6 +349,13 @@ export default { this.activeTheme(theme.id) }, handleFetching() { + if (!this.fetchingUrl) { + this.$notification['error']({ + message: '提示', + description: '远程地址不能为空!' + }) + return + } this.fetchButtonLoading = true themeApi .fetching(this.fetchingUrl) diff --git a/src/views/post/CategoryList.vue b/src/views/post/CategoryList.vue index b123b952..6fc7b353 100644 --- a/src/views/post/CategoryList.vue +++ b/src/views/post/CategoryList.vue @@ -206,6 +206,13 @@ export default { }) }, createOrUpdateCategory() { + if (!this.categoryToCreate.name) { + this.$notification['error']({ + message: '提示', + description: '分类名称不能为空!' + }) + return + } if (this.categoryToCreate.id) { categoryApi.update(this.categoryToCreate.id, this.categoryToCreate).then(response => { this.$message.success('更新成功!') diff --git a/src/views/post/TagList.vue b/src/views/post/TagList.vue index 082a5d09..1da83e52 100644 --- a/src/views/post/TagList.vue +++ b/src/views/post/TagList.vue @@ -132,6 +132,13 @@ export default { }) }, createOrUpdateTag() { + if (!this.tagToCreate.name) { + this.$notification['error']({ + message: '提示', + description: '标签名称不能为空!' + }) + return + } if (this.tagToCreate.id) { tagApi.update(this.tagToCreate.id, this.tagToCreate).then(response => { this.$message.success('更新成功!') diff --git a/src/views/post/components/PostSetting.vue b/src/views/post/components/PostSetting.vue index b3fd24f6..6b374ca3 100644 --- a/src/views/post/components/PostSetting.vue +++ b/src/views/post/components/PostSetting.vue @@ -320,6 +320,13 @@ export default { this.selectedPost.thumbnail = null }, handlerCreateCategory() { + if (!this.categoryToCreate.name) { + this.$notification['error']({ + message: '提示', + description: '分类名称不能为空!' + }) + return + } categoryApi.create(this.categoryToCreate).then(response => { this.loadCategories() this.categoryToCreate = {} @@ -338,12 +345,26 @@ export default { }, savePost() { this.createOrUpdatePost( - () => this.$message.success('文章创建成功'), - () => this.$message.success('文章更新成功'), + () => this.$message.success('文章发布成功'), + () => this.$message.success('文章发布成功'), false ) }, createOrUpdatePost(createSuccess, updateSuccess, autoSave) { + if (!this.selectedPost.title) { + this.$notification['error']({ + message: '提示', + description: '文章标题不能为空!' + }) + return + } + if (!this.selectedPost.originalContent) { + this.$notification['error']({ + message: '提示', + description: '文章内容不能为空!' + }) + return + } // Set category ids this.selectedPost.categoryIds = this.selectedCategoryIds // Set tag ids diff --git a/src/views/sheet/components/SheetSetting.vue b/src/views/sheet/components/SheetSetting.vue index 437e3e0b..c880d260 100644 --- a/src/views/sheet/components/SheetSetting.vue +++ b/src/views/sheet/components/SheetSetting.vue @@ -208,12 +208,26 @@ export default { }, saveSheet() { this.createOrUpdateSheet( - () => this.$message.success('页面创建成功!'), - () => this.$message.success('页面更新成功!'), + () => this.$message.success('页面发布成功!'), + () => this.$message.success('页面发布成功!'), false ) }, createOrUpdateSheet(createSuccess, updateSuccess, autoSave) { + if (!this.selectedSheet.title) { + this.$notification['error']({ + message: '提示', + description: '页面标题不能为空!' + }) + return + } + if (!this.selectedSheet.originalContent) { + this.$notification['error']({ + message: '提示', + description: '页面内容不能为空!' + }) + return + } if (this.selectedSheet.id) { sheetApi.update(this.selectedSheet.id, this.selectedSheet, autoSave).then(response => { this.$log.debug('Updated sheet', response.data.data) diff --git a/src/views/system/OptionForm.vue b/src/views/system/OptionForm.vue index 90443bb0..6b076366 100644 --- a/src/views/system/OptionForm.vue +++ b/src/views/system/OptionForm.vue @@ -736,6 +736,260 @@ export default { }) }, handleSaveOptions() { + if (!this.options.blog_title) { + this.$notification['error']({ + message: '提示', + description: '博客标题不能为空!' + }) + return + } + + if (!this.options.blog_url) { + this.$notification['error']({ + message: '提示', + description: '博客地址不能为空!' + }) + return + } + + // 新评论通知和回复通知验证 + if (this.options.comment_new_notice || this.options.comment_reply_notice) { + if (!this.options.email_enabled) { + this.$notification['error']({ + message: '提示', + description: '新评论通知或回复通知需要打开和配置 SMTP 服务!' + }) + return + } + } + + // 附件配置验证 + switch (this.options.attachment_type) { + case 'SMMS': + if (!this.options.smms_api_secret_token) { + this.$notification['error']({ + message: '提示', + description: 'Secret Token不能为空!' + }) + return + } + break + case 'UPYUN': + if (!this.options.oss_upyun_domain) { + this.$notification['error']({ + message: '提示', + description: '域名不能为空!' + }) + return + } + if (!this.options.oss_upyun_bucket) { + this.$notification['error']({ + message: '提示', + description: '空间名称不能为空!' + }) + return + } + if (!this.options.oss_upyun_operator) { + this.$notification['error']({ + message: '提示', + description: '操作员名称不能为空!' + }) + return + } + if (!this.options.oss_upyun_password) { + this.$notification['error']({ + message: '提示', + description: '操作员密码不能为空!' + }) + return + } + if (!this.options.oss_upyun_source) { + this.$notification['error']({ + message: '提示', + description: '文件目录不能为空!' + }) + return + } + break + case 'QNYUN': + if (!this.options.oss_qiniu_domain) { + this.$notification['error']({ + message: '提示', + description: '域名不能为空!' + }) + return + } + if (!this.options.oss_qiniu_access_key) { + this.$notification['error']({ + message: '提示', + description: 'Access Key 不能为空!' + }) + return + } + if (!this.options.oss_qiniu_secret_key) { + this.$notification['error']({ + message: '提示', + description: 'Secret Key 不能为空!' + }) + return + } + if (!this.options.oss_qiniu_bucket) { + this.$notification['error']({ + message: '提示', + description: 'Bucket 不能为空!' + }) + return + } + break + case 'ALIYUN': + if (!this.options.oss_aliyun_bucket_name) { + this.$notification['error']({ + message: '提示', + description: 'Bucket 不能为空!' + }) + return + } + if (!this.options.oss_aliyun_endpoint) { + this.$notification['error']({ + message: '提示', + description: 'EndPoint(地域节点) 不能为空!' + }) + return + } + if (!this.options.oss_aliyun_access_key) { + this.$notification['error']({ + message: '提示', + description: 'Access Key 不能为空!' + }) + return + } + if (!this.options.oss_aliyun_access_secret) { + this.$notification['error']({ + message: '提示', + description: 'Access Secret 不能为空!' + }) + return + } + break + case 'BAIDUYUN': + if (!this.options.oss_baiduyun_bucket_name) { + this.$notification['error']({ + message: '提示', + description: 'Bucket 不能为空!' + }) + return + } + if (!this.options.oss_baiduyun_endpoint) { + this.$notification['error']({ + message: '提示', + description: 'EndPoint(地域节点) 不能为空!' + }) + return + } + if (!this.options.oss_baiduyun_access_key) { + this.$notification['error']({ + message: '提示', + description: 'Access Key 不能为空!' + }) + return + } + if (!this.options.oss_baiduyun_access_secret) { + this.$notification['error']({ + message: '提示', + description: 'Access Secret 不能为空!' + }) + return + } + break + case 'TENCENTYUN': + if (!this.options.oss_tencentyun_bucket_name) { + this.$notification['error']({ + message: '提示', + description: 'Bucket 不能为空!' + }) + return + } + if (!this.options.oss_tencentyun_region) { + this.$notification['error']({ + message: '提示', + description: '区域不能为空!' + }) + return + } + if (!this.options.oss_tencentyun_access_key) { + this.$notification['error']({ + message: '提示', + description: 'Secret Id 不能为空!' + }) + return + } + if (!this.options.oss_tencentyun_access_secret) { + this.$notification['error']({ + message: '提示', + description: 'Secret Key 不能为空!' + }) + return + } + break + } + + // SMTP 配置验证 + if (this.options.email_enabled) { + if (!this.options.email_host) { + this.$notification['error']({ + message: '提示', + description: 'SMTP 地址不能为空!' + }) + return + } + if (!this.options.email_protocol) { + this.$notification['error']({ + message: '提示', + description: '发送协议不能为空!' + }) + return + } + if (!this.options.email_ssl_port) { + this.$notification['error']({ + message: '提示', + description: 'SSL 端口不能为空!' + }) + return + } + if (!this.options.email_username) { + this.$notification['error']({ + message: '提示', + description: '邮箱账号不能为空!' + }) + return + } + if (!this.options.email_password) { + this.$notification['error']({ + message: '提示', + description: '邮箱密码不能为空!' + }) + return + } + if (!this.options.email_from_name) { + this.$notification['error']({ + message: '提示', + description: '发件人不能为空!' + }) + return + } + } + + // API 配置验证 + if (this.options.api_enabled) { + if (!this.options.api_access_key) { + this.$notification['error']({ + message: '提示', + description: 'Access key 不能为空!' + }) + return + } + } + optionApi.save(this.options).then(response => { this.loadOptions() this.loadUser() @@ -807,6 +1061,27 @@ export default { this.logoDrawerVisible = false }, handleTestMailClick() { + if (!this.mailParam.to) { + this.$notification['error']({ + message: '提示', + description: '收件人不能为空!' + }) + return + } + if (!this.mailParam.subject) { + this.$notification['error']({ + message: '提示', + description: '主题不能为空!' + }) + return + } + if (!this.mailParam.content) { + this.$notification['error']({ + message: '提示', + description: '内容不能为空!' + }) + return + } mailApi.testMail(this.mailParam).then(response => { this.$message.info(response.data.message) }) diff --git a/src/views/user/Profile.vue b/src/views/user/Profile.vue index 67f9a676..61ad2c5a 100644 --- a/src/views/user/Profile.vue +++ b/src/views/user/Profile.vue @@ -211,6 +211,27 @@ export default { userApi.updatePassword(this.passwordParam.oldPassword, this.passwordParam.newPassword).then(response => {}) }, handleUpdateProfile() { + if (!this.user.username) { + this.$notification['error']({ + message: '提示', + description: '用户名不能为空!' + }) + return + } + if (!this.user.nickname) { + this.$notification['error']({ + message: '提示', + description: '用户昵称不能为空!' + }) + return + } + if (!this.user.email) { + this.$notification['error']({ + message: '提示', + description: '邮箱不能为空!' + }) + return + } userApi.updateProfile(this.user).then(response => { this.user = response.data.data this.setUser(Object.assign({}, this.user))