feat: 添加提交前验证

This commit is contained in:
xingyu 2022-10-17 11:24:22 +08:00
parent aa983a6fa9
commit 855d23aec3
26 changed files with 548 additions and 397 deletions

View File

@ -50,6 +50,10 @@
// 提交按钮 // 提交按钮
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// 提交请求 // 提交请求
try { try {
@ -68,6 +72,8 @@
actionLoading.value = false actionLoading.value = false
} }
} }
})
}
// ========== 详情相关 ========== // ========== 详情相关 ==========
const detailRef = ref() // 详情 Ref const detailRef = ref() // 详情 Ref

View File

@ -128,12 +128,18 @@ service.interceptors.response.use(
const refreshTokenRes = await refreshToken() const refreshTokenRes = await refreshToken()
// 2.1 刷新成功,则回放队列的请求 + 当前请求 // 2.1 刷新成功,则回放队列的请求 + 当前请求
setToken(refreshTokenRes.data) setToken(refreshTokenRes.data)
requestList.forEach((cb: any) => cb()) ;(config as Recordable).headers.Authorization = 'Bearer ' + getAccessToken()
requestList.forEach((cb: any) => {
cb()
})
requestList = []
return service(response.config) return service(response.config)
} catch (e) { } catch (e) {
// 为什么需要 catch 异常呢?刷新失败时,请求因为 Promise.reject 触发异常。 // 为什么需要 catch 异常呢?刷新失败时,请求因为 Promise.reject 触发异常。
// 2.2 刷新失败,只回放队列的请求 // 2.2 刷新失败,只回放队列的请求
requestList.forEach((cb: any) => cb()) requestList.forEach((cb: any) => {
cb()
})
// 提示是否要登出。即不回放当前请求!不然会形成递归 // 提示是否要登出。即不回放当前请求!不然会形成递归
return handleAuthorized() return handleAuthorized()
} finally { } finally {
@ -194,10 +200,7 @@ service.interceptors.response.use(
) )
const refreshToken = async () => { const refreshToken = async () => {
return await service({ return await axios.post(base_url + '/system/auth/refresh-token?refreshToken=' + getRefreshToken())
url: '/system/auth/refresh-token?refreshToken=' + getRefreshToken(),
method: 'post'
})
} }
const handleAuthorized = () => { const handleAuthorized = () => {
const { t } = useI18n() const { t } = useI18n()

View File

@ -111,6 +111,10 @@ const handleLogin = async (params) => {
} }
loginData.loginForm.captchaVerification = params.captchaVerification loginData.loginForm.captchaVerification = params.captchaVerification
const res = await LoginApi.loginApi(loginData.loginForm) const res = await LoginApi.loginApi(loginData.loginForm)
if (!res) {
loginLoading.value = false
return
}
setToken(res) setToken(res)
if (!redirect.value) { if (!redirect.value) {
redirect.value = '/' redirect.value = '/'

View File

@ -49,6 +49,10 @@ const handleUpdate = async (row: FormVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -66,6 +70,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -62,6 +62,10 @@ const handleUpdate = async (row: UserGroupVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -80,6 +84,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// //

View File

@ -51,6 +51,10 @@ const handleUpdate = async (row: ModelVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -68,6 +72,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
/** 流程表单的详情按钮操作 */ /** 流程表单的详情按钮操作 */

View File

@ -50,6 +50,10 @@ const handleUpdate = async (row: ConfigVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -67,6 +71,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -44,6 +44,10 @@ const handleUpdate = async (row: DataSourceConfigVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -61,6 +65,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
// //

View File

@ -60,6 +60,10 @@ const handleMaster = (row: FileConfigVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -77,6 +81,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -98,6 +98,10 @@ const handleRun = (row: JobVO) => {
} }
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -116,6 +120,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -50,6 +50,10 @@ const handleUpdate = async (row: AppVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -67,6 +71,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -50,6 +50,10 @@ const handleUpdate = async (row: MerchantVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -67,6 +71,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -48,6 +48,10 @@ const handleUpdate = async (row: OrderVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -65,6 +69,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -82,6 +82,10 @@ const handleDelete = async (data: { id: number }) => {
} }
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -98,6 +102,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
onMounted(async () => { onMounted(async () => {
await getTree() await getTree()

View File

@ -92,6 +92,10 @@ const setDialogTile = (type: string) => {
} }
// //
const submitTypeForm = async () => { const submitTypeForm = async () => {
const elForm = unref(typeFormRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -109,8 +113,14 @@ const submitTypeForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
const submitDataForm = async () => { const submitDataForm = async () => {
const elForm = unref(dataFormRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -129,6 +139,8 @@ const submitDataForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// //
onMounted(async () => { onMounted(async () => {

View File

@ -49,6 +49,10 @@ const handleUpdate = async (row: ErrorCodeVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -66,6 +70,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -127,7 +127,7 @@ const handleDelete = async (row: MenuVO) => {
await getList() await getList()
} }
// //
function isExternal(path: string) { const isExternal = (path: string) => {
return /^(https?:|mailto:|tel:)/.test(path) return /^(https?:|mailto:|tel:)/.test(path)
} }
const submitForm = async () => { const submitForm = async () => {

View File

@ -48,6 +48,10 @@ const handleUpdate = async (row: NoticeVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -65,6 +69,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -49,6 +49,10 @@ const handleUpdate = async (row: OAuth2ClientVo) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -66,6 +70,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -50,6 +50,10 @@ const handleUpdate = async (row: PostVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -67,6 +71,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -68,6 +68,10 @@ const handleUpdate = async (row: RoleVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -85,6 +89,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -56,6 +56,10 @@ const handleUpdate = async (row: SensitiveWordVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
@ -73,6 +77,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -49,6 +49,10 @@ const handleUpdate = async (row: SmsChannelVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -66,6 +70,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -49,6 +49,10 @@ const handleUpdate = async (row: SmsTemplateVO) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -66,6 +70,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -71,8 +71,12 @@ const handleUpdate = async (row: any) => {
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true actionLoading.value = true
// unix() //
try { try {
const data = unref(formRef)?.formModel as TenantVO const data = unref(formRef)?.formModel as TenantVO
data.packageId = tenantPackageId.value data.packageId = tenantPackageId.value
@ -91,6 +95,8 @@ const submitForm = async () => {
} finally { } finally {
actionLoading.value = false actionLoading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========

View File

@ -76,6 +76,10 @@ const handleUpdate = async (row: any) => {
} }
// //
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
loading.value = true loading.value = true
// //
try { try {
@ -94,6 +98,8 @@ const submitForm = async () => {
} finally { } finally {
loading.value = false loading.value = false
} }
}
})
} }
// ========== ========== // ========== ==========