perf:前端部分事件优化使用try/finally,编辑获取数据增加校验

This commit is contained in:
ktianc 2023-06-19 13:38:07 +08:00
parent ff0990331c
commit 7f4c0d3fa1
13 changed files with 81 additions and 61 deletions

View File

@ -143,7 +143,7 @@ const signIn = async () => {
} else { } else {
loading.value = false loading.value = false
} }
} catch (e: any) { } finally {
loading.value = false loading.value = false
} }
} }

View File

@ -111,7 +111,7 @@ const telephoneCodeLogin = async () => {
} else { } else {
loading.value = false loading.value = false
} }
} catch (e: any) { } finally {
loading.value = false loading.value = false
} }
} }
@ -143,7 +143,7 @@ const getSMSCode = async () => {
ElMessage.error('发送失败,请联系管理员') ElMessage.error('发送失败,请联系管理员')
SMSCodeStatus.value = true SMSCodeStatus.value = true
} }
} catch (e: any) { } finally {
SMSCodeStatus.value = true SMSCodeStatus.value = true
} }
} }

View File

@ -110,7 +110,7 @@ const save = async () => {
} else { } else {
loading.value = false loading.value = false
} }
} catch (e: any) { } finally {
loading.value = false loading.value = false
} }
} }

View File

@ -96,8 +96,8 @@ const save = async () => {
if (isValid) { if (isValid) {
loading.value = true loading.value = true
const data = await write?.getFormData() const data = await write?.getFormData()
const res = ref({})
try { try {
const res = ref({})
if (actionType.value === 'add') { if (actionType.value === 'add') {
res.value = await addMenuListApi(data) res.value = await addMenuListApi(data)
if (res.value) { if (res.value) {

View File

@ -56,11 +56,13 @@ const addAction = () => {
// //
const updateAction = async (row: any) => { const updateAction = async (row: any) => {
const res = await getRoleApi(row.id) const res = await getRoleApi(row.id)
dialogTitle.value = '编辑' if (res) {
tableObject.currentRow = res.data dialogTitle.value = '编辑'
defaultCheckedKeys.value = res.data.menus.map((item: any) => item.id) tableObject.currentRow = res.data
dialogVisible.value = true defaultCheckedKeys.value = res.data.menus.map((item: any) => item.id)
actionType.value = 'edit' dialogVisible.value = true
actionType.value = 'edit'
}
} }
// //
@ -82,8 +84,8 @@ const save = async () => {
return ElMessage.error('未获取到数据') return ElMessage.error('未获取到数据')
} }
data.menu_ids = write?.getTreeCheckedKeys() data.menu_ids = write?.getTreeCheckedKeys()
const res = ref({})
try { try {
const res = ref({})
if (actionType.value === 'add') { if (actionType.value === 'add') {
res.value = await addRoleListApi(data) res.value = await addRoleListApi(data)
if (res.value) { if (res.value) {

View File

@ -95,11 +95,13 @@ const addAction = () => {
// //
const updateAction = async (row: any) => { const updateAction = async (row: any) => {
const res = await getUserApi(row.id) const res = await getUserApi(row.id)
dialogTitle.value = '编辑' if (res) {
res.data.role_ids = res.data.roles.map((item: any) => item.id) dialogTitle.value = '编辑'
tableObject.currentRow = res.data res.data.role_ids = res.data.roles.map((item: any) => item.id)
dialogVisible.value = true tableObject.currentRow = res.data
actionType.value = 'edit' dialogVisible.value = true
actionType.value = 'edit'
}
} }
// //

View File

@ -62,11 +62,13 @@ const searchSetSchemaList = ref([] as FormSetPropsType[])
const getOptions = async () => { const getOptions = async () => {
const res = await getIssueCategoryOptionsApi() const res = await getIssueCategoryOptionsApi()
searchSetSchemaList.value.push({ if (res) {
field: 'category_id', searchSetSchemaList.value.push({
path: 'componentProps.options', field: 'category_id',
value: res.data path: 'componentProps.options',
}) value: res.data
})
}
} }
getOptions() getOptions()

View File

@ -95,10 +95,12 @@ const addAction = async () => {
// //
const updateAction = async (row: any) => { const updateAction = async (row: any) => {
const res = await getIssueCategoryApi(row.id) const res = await getIssueCategoryApi(row.id)
dialogTitle.value = '编辑' if (res) {
tableObject.currentRow = res.data dialogTitle.value = '编辑'
dialogVisible.value = true tableObject.currentRow = res.data
actionType.value = 'edit' dialogVisible.value = true
actionType.value = 'edit'
}
} }
// //
@ -116,8 +118,8 @@ const save = async () => {
if (isValid) { if (isValid) {
loading.value = true loading.value = true
let data = await write?.getFormData() let data = await write?.getFormData()
const res = ref({})
try { try {
const res = ref({})
if (actionType.value === 'add') { if (actionType.value === 'add') {
res.value = await addIssueCategoryApi(data) res.value = await addIssueCategoryApi(data)
if (res.value) { if (res.value) {

View File

@ -1,8 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { Echart } from '@/components/Echart' import { Echart } from '@/components/Echart'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { EChartsOption } from 'echarts' import { PropType, ref, watch } from 'vue'
import { PropType, ref, watch, reactive } from 'vue'
import { CenterTopPropsType } from '../typers' import { CenterTopPropsType } from '../typers'
const props = defineProps({ const props = defineProps({
@ -123,8 +122,6 @@ watch(
deep: true deep: true
} }
) )
// const lineOptions: EChartsOption = reactive()
</script> </script>
<template> <template>

View File

@ -38,11 +38,13 @@ const searchSetSchemaList = ref([] as FormSetPropsType[])
const getOptions = async () => { const getOptions = async () => {
const res = await getDictTypeOptionsApi() const res = await getDictTypeOptionsApi()
searchSetSchemaList.value.push({ if (res) {
field: 'dict_type_id', searchSetSchemaList.value.push({
path: 'componentProps.options', field: 'dict_type_id',
value: res.data path: 'componentProps.options',
}) value: res.data
})
}
} }
getOptions() getOptions()
@ -81,10 +83,12 @@ const addAction = () => {
// //
const updateAction = async (row: any) => { const updateAction = async (row: any) => {
const res = await getDictDetailsApi(row.id) const res = await getDictDetailsApi(row.id)
dialogTitle.value = '编辑' if (res) {
tableObject.currentRow = res.data dialogTitle.value = '编辑'
dialogVisible.value = true tableObject.currentRow = res.data
actionType.value = 'edit' dialogVisible.value = true
actionType.value = 'edit'
}
} }
// //
@ -106,19 +110,23 @@ const save = async () => {
return ElMessage.error('未获取到数据') return ElMessage.error('未获取到数据')
} }
data.dict_type_id = dictType data.dict_type_id = dictType
const res = ref({}) try {
if (actionType.value === 'add') { const res = ref({})
res.value = await addDictDetailsListApi(data) if (actionType.value === 'add') {
if (res.value) { res.value = await addDictDetailsListApi(data)
dialogVisible.value = false if (res.value) {
getList() dialogVisible.value = false
} getList()
} else if (actionType.value === 'edit') { }
res.value = await putDictDetailsListApi(data) } else if (actionType.value === 'edit') {
if (res.value) { res.value = await putDictDetailsListApi(data)
dialogVisible.value = false if (res.value) {
getList() dialogVisible.value = false
getList()
}
} }
} finally {
loading.value = false
} }
} }
}) })

View File

@ -56,10 +56,12 @@ const addAction = () => {
// //
const updateAction = async (row: any) => { const updateAction = async (row: any) => {
const res = await getDictTypeApi(row.id) const res = await getDictTypeApi(row.id)
dialogTitle.value = '编辑' if (res) {
tableObject.currentRow = res.data dialogTitle.value = '编辑'
dialogVisible.value = true tableObject.currentRow = res.data
actionType.value = 'edit' dialogVisible.value = true
actionType.value = 'edit'
}
} }
// //

View File

@ -40,12 +40,15 @@ const save = async () => {
loading.value = false loading.value = false
return ElMessage.error('未获取到数据') return ElMessage.error('未获取到数据')
} }
const res = await putSystemSettingsApi(data) try {
if (res) { const res = await putSystemSettingsApi(data)
getData() if (res) {
return ElMessage.success('更新成功') getData()
return ElMessage.success('更新成功')
}
} finally {
loading.value = false
} }
loading.value = false
} }
}) })
} }

View File

@ -22,7 +22,9 @@ const tabs = ref([] as Recordable[])
const getList = async () => { const getList = async () => {
const res = await getSystemSettingsTabsApi({ classify: 'web' }) const res = await getSystemSettingsTabsApi({ classify: 'web' })
tabs.value = res.data if (res) {
tabs.value = res.data
}
} }
getList() getList()