perf:前端部分事件增加try, finally,用于取消 loading 状态, 因为使用await 方式,报错 status=5xx,不会执行后面的语句

This commit is contained in:
ktianc 2023-06-18 23:14:11 +08:00
parent f5d5de8785
commit ff0990331c
15 changed files with 189 additions and 117 deletions

View File

@ -97,17 +97,24 @@ const save = async () => {
loading.value = true
const data = await write?.getFormData()
const res = ref({})
try {
if (actionType.value === 'add') {
res.value = await addMenuListApi(data)
} else if (actionType.value === 'edit') {
res.value = await putMenuListApi(data)
}
if (res.value) {
dialogVisible.value = false
getList()
}
} else if (actionType.value === 'edit') {
res.value = await putMenuListApi(data)
if (res.value) {
dialogVisible.value = false
getList()
}
}
} finally {
loading.value = false
}
}
})
}

View File

@ -83,17 +83,24 @@ const save = async () => {
}
data.menu_ids = write?.getTreeCheckedKeys()
const res = ref({})
try {
if (actionType.value === 'add') {
res.value = await addRoleListApi(data)
} else if (actionType.value === 'edit') {
res.value = await putRoleListApi(data)
}
if (res.value) {
dialogVisible.value = false
getList()
}
} else if (actionType.value === 'edit') {
res.value = await putRoleListApi(data)
if (res.value) {
dialogVisible.value = false
getList()
}
}
} finally {
loading.value = false
}
}
})
}

View File

@ -58,6 +58,7 @@ const handleImport = async () => {
importLoading.value = true
const formData = new FormData()
formData.append('file', importFile.value)
try {
const res = await postImportUserApi(formData)
if (res) {
resultTableData.value.push({
@ -70,7 +71,9 @@ const handleImport = async () => {
handleDelete()
emit('getList')
}
} finally {
importLoading.value = false
}
}
const downloadTemplate = async () => {

View File

@ -24,13 +24,15 @@ const initPassword = async () => {
if (ids.length <= 0) {
return ElMessage.warning('已全部重置完成,无需重复操作')
}
const res = await postUsersInitPasswordSendEmailApi(ids).finally(() => {
loading.value = false
})
try {
const res = await postUsersInitPasswordSendEmailApi(ids)
if (res) {
tableData.value = res.data
ElMessage.success('重置成功')
}
} finally {
loading.value = false
}
}
</script>

View File

@ -24,13 +24,15 @@ const initPassword = async () => {
if (ids.length <= 0) {
return ElMessage.warning('已全部重置完成,无需重复操作')
}
const res = await postUsersInitPasswordSendSMSApi(ids).finally(() => {
loading.value = false
})
try {
const res = await postUsersInitPasswordSendSMSApi(ids)
if (res) {
tableData.value = res.data
ElMessage.success('重置成功')
}
} finally {
loading.value = false
}
}
</script>

View File

@ -127,24 +127,34 @@ const save = async () => {
loading.value = false
return ElMessage.error('未获取到数据')
}
try {
const res = ref({})
if (actionType.value === 'add') {
res.value = await addUserListApi(data)
} else if (actionType.value === 'edit') {
const user = authStore.getUser
res.value = await putUserListApi(data)
if (user.id === data.id && user.telephone !== data.telephone) {
dialogVisible.value = false
authStore.logout()
return ElMessage.warning('认证已过期,请您重新登陆!')
}
}
if (res.value) {
dialogVisible.value = false
getList()
}
} else if (actionType.value === 'edit') {
const user = authStore.getUser
const userId = data.id
const userTelephone = data.telephone
res.value = await putUserListApi(data)
if (res.value) {
dialogVisible.value = false
if (user.id === userId && user.telephone !== userTelephone) {
dialogVisible.value = false
authStore.logout()
return ElMessage.warning('认证已过期,请您重新登陆!')
} else {
getList()
}
}
}
} finally {
loading.value = false
}
}
})
}

View File

@ -111,19 +111,27 @@ const save = async () => {
loading.value = false
return ElMessage.error('未获取到数据')
}
const tagsViewStore = useTagsViewStore()
const res = ref({})
try {
if (actionType.value === 'add') {
res.value = await addIssueApi(data)
} else if (actionType.value === 'edit') {
res.value = await putIssueApi(data)
}
loading.value = false
if (res.value) {
const tagsViewStore = useTagsViewStore()
//
tagsViewStore.delView(unref(currentRoute))
push('/help/issue')
}
} else if (actionType.value === 'edit') {
res.value = await putIssueApi(data)
if (res.value) {
//
tagsViewStore.delView(unref(currentRoute))
push('/help/issue')
}
}
} finally {
loading.value = false
}
}
})
}

View File

@ -117,17 +117,24 @@ const save = async () => {
loading.value = true
let data = await write?.getFormData()
const res = ref({})
try {
if (actionType.value === 'add') {
res.value = await addIssueCategoryApi(data)
} else if (actionType.value === 'edit') {
res.value = await putIssueCategoryApi(data)
}
if (res.value) {
dialogVisible.value = false
getList()
}
} else if (actionType.value === 'edit') {
res.value = await putIssueCategoryApi(data)
if (res.value) {
dialogVisible.value = false
getList()
}
}
} finally {
loading.value = false
}
}
})
}

View File

@ -109,14 +109,17 @@ const save = async () => {
const res = ref({})
if (actionType.value === 'add') {
res.value = await addDictDetailsListApi(data)
} else if (actionType.value === 'edit') {
res.value = await putDictDetailsListApi(data)
}
if (res.value) {
dialogVisible.value = false
getList()
}
loading.value = false
} else if (actionType.value === 'edit') {
res.value = await putDictDetailsListApi(data)
if (res.value) {
dialogVisible.value = false
getList()
}
}
}
})
}

View File

@ -93,17 +93,24 @@ const save = async () => {
return ElMessage.error('未获取到数据')
}
const res = ref({})
try {
if (actionType.value === 'add') {
res.value = await addDictTypeListApi(data)
} else if (actionType.value === 'edit') {
res.value = await putDictTypeListApi(data)
}
if (res.value) {
dialogVisible.value = false
getList()
}
} else if (actionType.value === 'edit') {
res.value = await putDictTypeListApi(data)
if (res.value) {
dialogVisible.value = false
getList()
}
}
} finally {
loading.value = false
}
}
})
}

View File

@ -25,12 +25,16 @@ const loading = ref(false)
const save = async () => {
loading.value = true
const res = await putSystemSettingsApi({ web_agreement: defaultHtml.value })
if (res) {
try {
const res = ref({})
res.value = await putSystemSettingsApi({ web_agreement: defaultHtml.value })
if (res.value) {
getData()
return ElMessage.success('更新成功')
}
} finally {
loading.value = false
}
}
const editorConfig = {

View File

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

View File

@ -92,6 +92,7 @@ const save = async () => {
loading.value = false
return ElMessage.error('未获取到数据')
}
try {
const res = await putSystemSettingsApi(data)
if (res) {
appStore.setTitle(data.web_title || import.meta.env.VITE_APP_TITLE)
@ -100,8 +101,10 @@ const save = async () => {
appStore.setIcpNumber(data.web_icp_number || '')
return ElMessage.success('更新成功')
}
} finally {
loading.value = false
}
}
})
}

View File

@ -25,12 +25,15 @@ const loading = ref(false)
const save = async () => {
loading.value = true
try {
const res = await putSystemSettingsApi({ web_privacy: defaultHtml.value })
if (res) {
getData()
return ElMessage.success('更新成功')
}
} finally {
loading.value = false
}
}
const editorConfig = {

View File

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