From dcf85e1d955226071155cafd9b8ac4079a009ea3 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 14 Sep 2021 20:45:30 +0800 Subject: [PATCH] refactor: cleanup code. (halo-dev/console#351) * refactor: cleanup code. * refactor: cleanup code. * refactor: cleanup code. * fix: post list render error. --- package.json | 18 +- .../Attachment/AttachmentSelectDrawer.vue | 15 +- src/components/Editor/MarkdownEditor.vue | 6 +- src/components/Ellipsis/Ellipsis.vue | 4 +- .../SettingDrawer/SettingDrawer.vue | 6 +- src/components/Tools/UserMenu.vue | 2 +- src/components/Upload/FilePondUpload.vue | 2 +- src/filters/filter.js | 25 +- src/utils/datetime.js | 18 +- src/utils/service.js | 6 +- src/utils/util.js | 14 - src/views/attachment/AttachmentList.vue | 26 +- .../components/AttachmentDetailDrawer.vue | 8 +- .../components/AttachmentDrawer.vue | 14 +- src/views/comment/components/CommentTab.vue | 20 +- .../components/TargetCommentDrawer.vue | 2 +- src/views/dashboard/Dashboard.vue | 6 +- .../dashboard/components/RecentCommentTab.vue | 8 +- src/views/interface/MenuList.vue | 4 +- .../components/ThemeSettingDrawer.vue | 18 +- src/views/post/PostList.vue | 32 +- src/views/post/TagList.vue | 2 +- .../post/components/PostSettingDrawer.vue | 4 +- .../sheet/components/CustomSheetList.vue | 24 +- .../sheet/components/SheetSettingDrawer.vue | 4 +- src/views/sheet/independent/JournalList.vue | 4 +- src/views/sheet/independent/LinkList.vue | 4 +- src/views/system/Installation.vue | 6 +- src/views/system/SystemOptions.vue | 6 +- .../system/components/BackupWorkDirDrawer.vue | 4 +- .../system/components/ExportDataDrawer.vue | 4 +- .../components/ExportMarkdownDrawer.vue | 4 +- .../system/developer/tabs/OptionsList.vue | 6 +- .../system/developer/tabs/RuntimeLogs.vue | 6 +- src/views/system/optiontabs/AttachmentTab.vue | 43 +- src/views/system/optiontabs/CommentTab.vue | 10 - src/views/user/Login.vue | 2 +- src/views/user/Profile.vue | 3 +- yarn.lock | 5757 ++++++++--------- 39 files changed, 2898 insertions(+), 3249 deletions(-) diff --git a/package.json b/package.json index 7bca5d81a..3746a8263 100644 --- a/package.json +++ b/package.json @@ -21,21 +21,21 @@ "test:unit": "vue-cli-service test:unit" }, "dependencies": { - "ant-design-vue": "^1.7.6", - "axios": "^0.21.1", - "dayjs": "^1.10.5", + "ant-design-vue": "^1.7.8", + "axios": "^0.21.4", + "dayjs": "^1.10.7", "enquire.js": "^2.1.6", - "filepond": "^4.28.2", + "filepond": "^4.29.1", "filepond-plugin-file-validate-type": "^1.2.6", - "filepond-plugin-image-preview": "^4.6.6", - "flv.js": "^1.5.0", + "filepond-plugin-image-preview": "^4.6.10", + "flv.js": "^1.6.2", "halo-editor": "^2.8.3", "marked": "^2.1.3", "nprogress": "^0.2.0", "tiny-pinyin": "^1.3.2", "verte": "^0.0.12", "vue": "^2.6.14", - "vue-clipboard2": "^0.3.1", + "vue-clipboard2": "^0.3.2", "vue-codemirror-lite": "^1.0.4", "vue-contextmenujs": "^1.3.13", "vue-count-to": "^1.0.13", @@ -54,14 +54,14 @@ "@vue/cli-plugin-unit-jest": "^4.5.13", "@vue/cli-service": "^4.5.13", "@vue/eslint-config-prettier": "^6.0.0", - "@vue/test-utils": "^1.2.1", + "@vue/test-utils": "^1.2.2", "babel-core": "7.0.0-bridge.0", "babel-eslint": "^10.1.0", "babel-jest": "^26.6.3", "babel-plugin-import": "^1.13.3", "eslint": "^6.8.0", "eslint-plugin-html": "^6.1.2", - "eslint-plugin-prettier": "^3.4.0", + "eslint-plugin-prettier": "^3.4.1", "eslint-plugin-vue": "^6.2.2", "husky": "^6.0.0", "less": "^3.13.1", diff --git a/src/components/Attachment/AttachmentSelectDrawer.vue b/src/components/Attachment/AttachmentSelectDrawer.vue index 060ba7f9c..5a3580646 100644 --- a/src/components/Attachment/AttachmentSelectDrawer.vue +++ b/src/components/Attachment/AttachmentSelectDrawer.vue @@ -16,7 +16,7 @@ - +
{ - var responseObject = response.data - var HaloEditor = this.$refs.md + const responseObject = response.data + const HaloEditor = this.$refs.md HaloEditor.$img2Url(pos, encodeURI(responseObject.data.path)) }) }, diff --git a/src/components/Ellipsis/Ellipsis.vue b/src/components/Ellipsis/Ellipsis.vue index fc02a04ab..a13736575 100644 --- a/src/components/Ellipsis/Ellipsis.vue +++ b/src/components/Ellipsis/Ellipsis.vue @@ -1,6 +1,7 @@ diff --git a/src/components/SettingDrawer/SettingDrawer.vue b/src/components/SettingDrawer/SettingDrawer.vue index 1a6d91707..44fb1d420 100644 --- a/src/components/SettingDrawer/SettingDrawer.vue +++ b/src/components/SettingDrawer/SettingDrawer.vue @@ -73,7 +73,7 @@ @change="handleContentWidthChange" > 固定 - 流式 + 流式 @@ -230,8 +230,8 @@ export default { float: left; cursor: pointer; margin-right: 8px; - padding-left: 0px; - padding-right: 0px; + padding-left: 0; + padding-right: 0; text-align: center; color: #fff; font-weight: 700; diff --git a/src/components/Tools/UserMenu.vue b/src/components/Tools/UserMenu.vue index 83753c8d7..1df8a388d 100644 --- a/src/components/Tools/UserMenu.vue +++ b/src/components/Tools/UserMenu.vue @@ -28,7 +28,7 @@ - + 退出登录 diff --git a/src/components/Upload/FilePondUpload.vue b/src/components/Upload/FilePondUpload.vue index eca7abb09..de8724ef7 100644 --- a/src/components/Upload/FilePondUpload.vue +++ b/src/components/Upload/FilePondUpload.vue @@ -37,7 +37,7 @@ import FilePondPluginImagePreview from 'filepond-plugin-image-preview' import 'filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css' import FilePondPluginFileValidateType from 'filepond-plugin-file-validate-type' -// Create component and regist plugins +// Create component and register plugins const FilePond = vueFilePond(FilePondPluginImagePreview, FilePondPluginFileValidateType) export default { name: 'FilePondUpload', diff --git a/src/filters/filter.js b/src/filters/filter.js index 1d232c06d..f734772e4 100644 --- a/src/filters/filter.js +++ b/src/filters/filter.js @@ -4,14 +4,15 @@ import dayjs from 'dayjs' import 'dayjs/locale/zh-cn' import { timeAgo } from '@/utils/datetime' + dayjs.locale('zh-cn') Vue.filter('NumberFormat', function(value) { if (!value) { return '0' } - const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断 - return intPartFormat + // 将整数部分逢三一断 + return value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') }) Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm') { @@ -36,20 +37,18 @@ Vue.filter('fileSizeFormat', function(value) { if (!value) { return '0 Bytes' } - var unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] - var index = 0 - var srcsize = parseFloat(value) - index = Math.floor(Math.log(srcsize) / Math.log(1024)) - var size = srcsize / Math.pow(1024, index) + const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + const srcsize = parseFloat(value) + let index = Math.floor(Math.log(srcsize) / Math.log(1024)) + let size = srcsize / Math.pow(1024, index) size = size.toFixed(2) return size + ' ' + unitArr[index] }) Vue.filter('dayTime', function(value) { - var days = Math.floor(value / 86400) - var hours = Math.floor((value % 86400) / 3600) - var minutes = Math.floor(((value % 86400) % 3600) / 60) - var seconds = Math.floor(((value % 86400) % 3600) % 60) - var duration = days + 'd ' + hours + 'h ' + minutes + 'm ' + seconds + 's' - return duration + const days = Math.floor(value / 86400) + const hours = Math.floor((value % 86400) / 3600) + const minutes = Math.floor(((value % 86400) % 3600) / 60) + const seconds = Math.floor(((value % 86400) % 3600) % 60) + return days + 'd ' + hours + 'h ' + minutes + 'm ' + seconds + 's' }) diff --git a/src/utils/datetime.js b/src/utils/datetime.js index d0d5fd5d8..c6cea74ac 100644 --- a/src/utils/datetime.js +++ b/src/utils/datetime.js @@ -7,18 +7,18 @@ function datetimeFormat(datetime = new Date(), pattern = 'YYYY-MM-DD HH:mm') { } function timeAgo(datetime) { - var currentTime = new Date().getTime() - var between = currentTime - datetime - var days = Math.floor(between / (24 * 3600 * 1000)) + const currentTime = new Date().getTime() + const between = currentTime - datetime + const days = Math.floor(between / (24 * 3600 * 1000)) if (days === 0) { - var leave1 = between % (24 * 3600 * 1000) - var hours = Math.floor(leave1 / (3600 * 1000)) + const leave1 = between % (24 * 3600 * 1000) + const hours = Math.floor(leave1 / (3600 * 1000)) if (hours === 0) { - var leave2 = leave1 % (3600 * 1000) - var minutes = Math.floor(leave2 / (60 * 1000)) + const leave2 = leave1 % (3600 * 1000) + const minutes = Math.floor(leave2 / (60 * 1000)) if (minutes === 0) { - var leave3 = leave2 % (60 * 1000) - var seconds = Math.round(leave3 / 1000) + const leave3 = leave2 % (60 * 1000) + const seconds = Math.round(leave3 / 1000) return seconds + ' 秒前' } return minutes + ' 分钟前' diff --git a/src/utils/service.js b/src/utils/service.js index 7d152b3ab..e3e306e64 100644 --- a/src/utils/service.js +++ b/src/utils/service.js @@ -21,8 +21,7 @@ function setTokenToHeader(config) { async function reRequest(error) { const config = error.response.config setTokenToHeader(config) - const res = await axios.request(config) - return res + return await axios.request(config) } let refreshTask = null @@ -61,7 +60,6 @@ function getFieldValidationError(data) { service.interceptors.request.use( config => { config.baseURL = store.getters.apiUrl - // TODO set token setTokenToHeader(config) return config }, @@ -92,7 +90,6 @@ service.interceptors.response.use( // Business response Vue.$log.error('Business response status', data.status) if (data.status === 400) { - // TODO handle 400 status error const errorDetails = getFieldValidationError(data) if (errorDetails) { handled = true @@ -116,7 +113,6 @@ service.interceptors.response.use( }) } } else if (data.status === 401) { - // TODO handle 401 status error if (store.getters.token && store.getters.token.access_token === data.data) { const res = refreshToken(error) if (res !== error) { diff --git a/src/utils/util.js b/src/utils/util.js index 4a4c120cf..ea4db189c 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -9,20 +9,6 @@ export function isObject(value) { return value && typeof value === 'object' && value.constructor === Object } -/** - * decode html tag - * @param {*} html - * @returns - * @deprecated - */ -export function decodeHTML(html) { - let elem = document.createElement('div') - elem.innerHTML = html - const output = elem.innerText || elem.textContent - elem = null - return output -} - export function deepClone(source) { if (!source && typeof source !== 'object') { throw new Error('error arguments', 'deepClone') diff --git a/src/views/attachment/AttachmentList.vue b/src/views/attachment/AttachmentList.vue index 39cca3be8..e4c51a020 100644 --- a/src/views/attachment/AttachmentList.vue +++ b/src/views/attachment/AttachmentList.vue @@ -249,11 +249,7 @@ export default { }, handleShowDetailDrawer(attachment) { this.selectAttachment = attachment - if (this.supportMultipleSelection) { - this.drawerVisible = false - } else { - this.drawerVisible = true - } + this.drawerVisible = !this.supportMultipleSelection }, handleContextMenu(event, item) { this.$contextmenu({ @@ -320,18 +316,12 @@ export default { this.handleListTypes() }, handleJudgeMediaType(attachment) { - var mediaType = attachment.mediaType + const mediaType = attachment.mediaType // 判断文件类型 if (mediaType) { - var prefix = mediaType.split('/')[0] + const prefix = mediaType.split('/')[0] - if (prefix === 'image') { - // 是图片 - return true - } else { - // 非图片 - return false - } + return prefix === 'image' } // 没有获取到文件返回false return false @@ -351,24 +341,24 @@ export default { this.supportMultipleSelection = false this.drawerVisible = false this.batchSelectedAttachments = [] - for (var key in this.selectedCheckbox) { + for (const key in this.selectedCheckbox) { this.$set(this.selectedAttachmentCheckbox, key, false) } }, handleAttachmentSelectionChanged(e, item) { - var isChecked = e.target.checked || false + const isChecked = e.target.checked || false if (isChecked) { this.$set(this.selectedAttachmentCheckbox, item.id, true) this.batchSelectedAttachments.push(item.id) } else { this.$set(this.selectedAttachmentCheckbox, item.id, false) // 从选中id集合中删除id - var index = this.batchSelectedAttachments.indexOf(item.id) + const index = this.batchSelectedAttachments.indexOf(item.id) this.batchSelectedAttachments.splice(index, 1) } }, handleDeleteAttachmentInBatch() { - var that = this + const that = this if (this.batchSelectedAttachments.length <= 0) { this.$message.warn('你还未选择任何附件,请至少选择一个!') return diff --git a/src/views/attachment/components/AttachmentDetailDrawer.vue b/src/views/attachment/components/AttachmentDetailDrawer.vue index 71ff68649..0790324be 100644 --- a/src/views/attachment/components/AttachmentDetailDrawer.vue +++ b/src/views/attachment/components/AttachmentDetailDrawer.vue @@ -260,18 +260,18 @@ export default { this.$emit('close', false) }, handleJudgeMediaType(attachment) { - var mediaType = attachment.mediaType + const mediaType = attachment.mediaType // 判断文件类型 if (mediaType) { - var prefix = mediaType.split('/')[0] + const prefix = mediaType.split('/')[0] if (prefix === 'video' || prefix === 'flv') { // 控制各个组件的显示 this.handlePreviewVisible(false, true, false) // 去除视频地址后面的参数 - var lastIndex = attachment.path.lastIndexOf('?') - var path = attachment.path.substring(0, lastIndex) + const lastIndex = attachment.path.lastIndexOf('?') + const path = attachment.path.substring(0, lastIndex) // 设置视频地址 this.$set(this.videoOptions.video, 'url', path) diff --git a/src/views/attachment/components/AttachmentDrawer.vue b/src/views/attachment/components/AttachmentDrawer.vue index 409859bfa..322c88fa2 100644 --- a/src/views/attachment/components/AttachmentDrawer.vue +++ b/src/views/attachment/components/AttachmentDrawer.vue @@ -16,7 +16,7 @@ - +
- + @@ -74,13 +74,13 @@ - 通过 + 通过 - 通过并回复 + 通过并回复 - 回复 + 回复 - 还原 + 还原 @@ -99,7 +99,7 @@ okText="确定" cancelText="取消" > - 回收站 + 回收站 @@ -109,7 +109,7 @@ okText="确定" cancelText="取消" > - 删除 + 删除 @@ -212,7 +212,7 @@ cancelText="取消" v-else-if="record.status === 'RECYCLE'" > - 还原 + 还原 @@ -224,7 +224,7 @@ cancelText="取消" v-if="record.status === 'PUBLISHED' || record.status === 'AUDITING'" > - 回收站 + 回收站 - 删除 + 删除 diff --git a/src/views/comment/components/TargetCommentDrawer.vue b/src/views/comment/components/TargetCommentDrawer.vue index 3c3fc13fe..a38a49964 100644 --- a/src/views/comment/components/TargetCommentDrawer.vue +++ b/src/views/comment/components/TargetCommentDrawer.vue @@ -24,7 +24,7 @@ - + {{ item.title }} {{ item.title }} - + {{ item.title }} diff --git a/src/views/dashboard/components/RecentCommentTab.vue b/src/views/dashboard/components/RecentCommentTab.vue index c919fce63..48b527a7d 100644 --- a/src/views/dashboard/components/RecentCommentTab.vue +++ b/src/views/dashboard/components/RecentCommentTab.vue @@ -4,12 +4,12 @@