From d28d4bc110ac3dfa3f557dd9bc5347c5ffa84f1c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 23 Sep 2020 00:20:47 +0800 Subject: [PATCH] refactor: form verification. (#250) * refactor: form verification. * refactor: form verification. * refactor: form verification. --- src/components/global.less | 2 +- src/views/sheet/independent/JournalList.vue | 317 +++++++------- .../system/developer/tabs/OptionsList.vue | 182 ++++---- .../system/developer/tabs/RuntimeLogs.vue | 28 +- .../system/developer/tabs/StaticStorage.vue | 408 +++++++++++------- 5 files changed, 543 insertions(+), 394 deletions(-) diff --git a/src/components/global.less b/src/components/global.less index 853ea67b2..2f6003806 100644 --- a/src/components/global.less +++ b/src/components/global.less @@ -845,7 +845,7 @@ body { .journal-list-content, .comment-drawer-content { img { - width: 100%; + width: 50%; } } diff --git a/src/views/sheet/independent/JournalList.vue b/src/views/sheet/independent/JournalList.vue index e633932e5..5301d9694 100644 --- a/src/views/sheet/independent/JournalList.vue +++ b/src/views/sheet/independent/JournalList.vue @@ -15,7 +15,7 @@ > @@ -27,14 +27,14 @@ {{ journalType[type].text }} + >{{ list.journalType[type].text }} @@ -48,7 +48,7 @@ type="primary" @click="handleQuery()" >查询 - 重置 + 重置 @@ -59,18 +59,18 @@ 写日志
- + {{ item.commentCount }} @@ -110,7 +110,7 @@ @@ -174,38 +189,38 @@ const columns = [ title: 'Key', dataIndex: 'key', ellipsis: true, - scopedSlots: { customRender: 'key' } + scopedSlots: { customRender: 'key' }, }, { title: 'Value', dataIndex: 'value', ellipsis: true, - scopedSlots: { customRender: 'value' } + scopedSlots: { customRender: 'value' }, }, { title: '类型', dataIndex: 'typeProperty', width: '100px', - scopedSlots: { customRender: 'type' } + scopedSlots: { customRender: 'type' }, }, { title: '创建时间', dataIndex: 'createTime', width: '200px', - scopedSlots: { customRender: 'createTime' } + scopedSlots: { customRender: 'createTime' }, }, { title: '更新时间', dataIndex: 'updateTime', width: '200px', - scopedSlots: { customRender: 'updateTime' } + scopedSlots: { customRender: 'updateTime' }, }, { title: '操作', dataIndex: 'action', width: '120px', - scopedSlots: { customRender: 'action' } - } + scopedSlots: { customRender: 'action' }, + }, ] export default { name: 'OptionsList', @@ -213,37 +228,46 @@ export default { return { optionType: optionApi.type, columns: columns, - formVisible: false, pagination: { page: 1, size: 10, sort: null, - total: 1 + total: 1, }, queryParam: { page: 0, size: 10, sort: null, keyword: null, - type: null + type: null, }, - optionToStage: {}, loading: false, - options: [] + options: [], + + form: { + visible: false, + model: {}, + rules: { + key: [{ required: true, message: '* Key 不能为空', trigger: ['change'] }], + value: [{ required: true, message: '* Value 不能为空', trigger: ['change'] }], + }, + saving: false, + saveErrored: false, + }, } }, computed: { formattedDatas() { - return this.options.map(option => { + return this.options.map((option) => { option.typeProperty = this.optionType[option.type] return option }) }, formTitle() { - return this.optionToStage.id ? '编辑' : '新增' - } + return this.form.model.id ? '编辑' : '新增' + }, }, - created() { + beforeMount() { this.hanldeListOptions() }, methods: { @@ -255,7 +279,7 @@ export default { this.queryParam.sort = this.pagination.sort optionApi .query(this.queryParam) - .then(response => { + .then((response) => { this.options = response.data.data.content this.pagination.total = response.data.data.total }) @@ -271,7 +295,7 @@ export default { handleDeleteOption(id) { optionApi .delete(id) - .then(response => { + .then((response) => { this.$message.success('删除成功!') }) .finally(() => { @@ -280,8 +304,8 @@ export default { }) }, handleEditOption(option) { - this.optionToStage = option - this.formVisible = true + this.form.model = option + this.form.visible = true }, handlePaginationChange(page, pageSize) { this.$log.debug(`Current: ${page}, PageSize: ${pageSize}`) @@ -295,51 +319,51 @@ export default { this.handlePaginationChange(1, this.pagination.size) }, onFormClose() { - this.formVisible = false - this.optionToStage = {} + this.form.visible = false + this.form.model = {} }, - createOrUpdateOption() { - if (!this.optionToStage.key) { - this.$notification['error']({ - message: '提示', - description: 'Key 不能为空!' - }) - return - } - if (!this.optionToStage.value) { - this.$notification['error']({ - message: '提示', - description: 'Value 不能为空!' - }) - return - } - if (this.optionToStage.id) { - optionApi - .update(this.optionToStage.id, this.optionToStage) - .then(response => { - this.$message.success('更新成功!') - this.optionToStage = {} - this.formVisible = false - }) - .finally(() => { - this.hanldeListOptions() - this.refreshOptionsCache() - }) + handleSaveOrUpdate() { + const _this = this + _this.$refs.optionForm.validate((valid) => { + if (valid) { + _this.form.saving = true + if (_this.form.model.id) { + optionApi + .update(_this.form.model.id, _this.form.model) + .catch(() => { + _this.form.saveErrored = true + }) + .finally(() => { + setTimeout(() => { + _this.form.saving = false + }, 400) + }) + } else { + _this.form.model.type = _this.optionType.CUSTOM.value + optionApi + .create(_this.form.model) + .catch(() => { + _this.form.saveErrored = true + }) + .finally(() => { + setTimeout(() => { + _this.form.saving = false + }, 400) + }) + } + } + }) + }, + handleSaveOrUpdateCallback() { + if (this.form.saveErrored) { + this.form.saveErrored = false } else { - this.optionToStage.type = this.optionType.CUSTOM.value - optionApi - .create(this.optionToStage) - .then(response => { - this.$message.success('保存成功!') - this.optionToStage = {} - this.formVisible = false - }) - .finally(() => { - this.hanldeListOptions() - this.refreshOptionsCache() - }) + this.form.model = {} + this.form.visible = false + this.hanldeListOptions() + this.refreshOptionsCache() } - } - } + }, + }, } diff --git a/src/views/system/developer/tabs/RuntimeLogs.vue b/src/views/system/developer/tabs/RuntimeLogs.vue index c98d0429c..a6b410a15 100644 --- a/src/views/system/developer/tabs/RuntimeLogs.vue +++ b/src/views/system/developer/tabs/RuntimeLogs.vue @@ -24,10 +24,12 @@ 刷新 下载 @@ -41,7 +43,7 @@ import moment from 'moment' export default { name: 'RuntimeLogs', components: { - codemirror + codemirror, }, data() { return { @@ -49,14 +51,15 @@ export default { tabSize: 4, mode: 'shell', lineNumbers: true, - line: true + line: true, }, logContent: '', loading: false, - logLines: 200 + logLines: 200, + downloading: false, } }, - created() { + beforeMount() { this.handleLoadLogsLines() }, updated() { @@ -68,20 +71,21 @@ export default { this.loading = true adminApi .getLogFiles(this.logLines) - .then(response => { + .then((response) => { this.logContent = response.data.data }) .finally(() => { setTimeout(() => { this.loading = false - }, 200) + }, 400) }) }, handleDownloadLogFile() { const hide = this.$message.loading('下载中...', 0) + this.downloading = true adminApi .getLogFiles(this.logLines) - .then(response => { + .then((response) => { var blob = new Blob([response.data.data]) var downloadElement = document.createElement('a') var href = window.URL.createObjectURL(blob) @@ -91,15 +95,17 @@ export default { downloadElement.click() document.body.removeChild(downloadElement) window.URL.revokeObjectURL(href) - this.$message.success('下载成功!') }) .catch(() => { this.$message.error('下载失败!') }) .finally(() => { - hide() + setTimeout(() => { + this.downloading = false + hide() + }, 400) }) - } - } + }, + }, } diff --git a/src/views/system/developer/tabs/StaticStorage.vue b/src/views/system/developer/tabs/StaticStorage.vue index 961c29d4f..1994f1303 100644 --- a/src/views/system/developer/tabs/StaticStorage.vue +++ b/src/views/system/developer/tabs/StaticStorage.vue @@ -8,18 +8,18 @@ 上传 新建文件夹 刷新 @@ -27,11 +27,11 @@
上传 @@ -76,8 +76,8 @@ v-if="!record.isFile" > 创建文件夹 @@ -87,13 +87,13 @@ cancelText="取消" @confirm="handleDelete(record.relativePath)" > - 删除 + 删除 重命名 编辑 @@ -113,64 +113,88 @@ - - + + - - + + - - + + - - + + 取消 - 保存 + @@ -206,7 +234,6 @@