refactor(user): 移除不必要的组件状态追踪代码

- 删除 isComponentMounted 状态变量及相关检查逻辑
- 简化异步函数中的组件挂载状态验证
- 保留必要的资源清理逻辑(定时器和Blob URL)
- 优化代码结构,提高可维护性

Vue 3 的响应式系统已经能够自动处理组件卸载时的状态更新,
无需手动追踪组件生命周期状态。
This commit is contained in:
Leo 2025-07-06 02:52:45 +08:00
parent 7254d8f9bd
commit 92ab0c3159

View File

@ -67,8 +67,6 @@ const selectedFile = ref<File | null>(null)
const updateSupport = ref(false)
const uploadProgress = ref(0)
//
const isComponentMounted = ref(true)
const progressInterval = ref<NodeJS.Timeout | null>(null)
const createdBlobUrls = ref<string[]>([])
@ -113,6 +111,7 @@ const rules = {
{ type: 'email', message: '请输入正确的邮箱格式', trigger: 'blur' },
],
phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号格式', trigger: 'blur' },
],
password: [
@ -351,9 +350,6 @@ const columns: DataTableColumns<UserVo> = [
//
async function getUserList() {
if (!isComponentMounted.value)
return
loading.value = true
try {
//
@ -381,10 +377,6 @@ async function getUserList() {
const { isSuccess, data } = await fetchUserPage(params)
//
if (!isComponentMounted.value)
return
if (isSuccess && data) {
tableData.value = data.records || []
pagination.value.itemCount = data.total || 0
@ -397,18 +389,14 @@ async function getUserList() {
}
}
catch (error) {
if (!isComponentMounted.value)
return
console.error('获取用户列表失败:', error)
coiMsgError('获取用户列表失败,请检查网络连接')
tableData.value = []
pagination.value.itemCount = 0
}
finally {
if (isComponentMounted.value) {
loading.value = false
}
}
}
//
@ -890,10 +878,6 @@ async function handleConfirmImport() {
const response = await importUserData(selectedFile.value, updateSupport.value)
//
if (!isComponentMounted.value)
return
if (progressInterval.value) {
clearInterval(progressInterval.value)
progressInterval.value = null
@ -915,11 +899,9 @@ async function handleConfirmImport() {
}
}
catch (error) {
if (isComponentMounted.value) {
console.error('导入失败:', error)
coiMsgError('导入失败,请检查文件格式或联系管理员')
}
}
finally {
//
if (progressInterval.value) {
@ -927,11 +909,9 @@ async function handleConfirmImport() {
progressInterval.value = null
}
if (isComponentMounted.value) {
importLoading.value = false
uploadProgress.value = 0
}
}
}
//
@ -1105,9 +1085,6 @@ onMounted(() => {
//
onBeforeUnmount(() => {
//
isComponentMounted.value = false
//
if (progressInterval.value) {
clearInterval(progressInterval.value)