带文件拖动上传的新版简历上传功能,独立文件操作组件,简历列表页和个人资料页有调用
This commit is contained in:
+36
-4
@@ -10,8 +10,8 @@
|
||||
@save="handleSaveEdit"
|
||||
/>
|
||||
|
||||
<!-- 欢迎上传简历弹窗 -->
|
||||
<ProfileWelcomeDialog v-model="showWelcomeDialog" />
|
||||
<!-- 欢迎上传简历弹窗(首次无个人资料时自动弹出) -->
|
||||
<ResumeUploadDialog v-model="showWelcomeDialog" @confirm="handleWelcomeUpload" />
|
||||
|
||||
<!-- 页面标题 -->
|
||||
<div class="profile-page__header">
|
||||
@@ -60,8 +60,11 @@ import { useStore } from 'vuex'
|
||||
import SideNav from '@/components/SideNav.vue'
|
||||
import ProfileEditDrawer from '@/components/ProfileEditDrawer.vue'
|
||||
import ProfilePageContent from '@/components/ProfilePageContent.vue'
|
||||
import ProfileWelcomeDialog from '@/components/ProfileWelcomeDialog.vue'
|
||||
import { saveProfile, fetchProfile, fetchEducation, saveEducation, fetchWork, saveWork, fetchInternship, saveInternship, fetchProject, saveProject, fetchCompetition, saveCompetition } from '@/api/profile'
|
||||
import ResumeUploadDialog from '@/components/ResumeUploadDialog.vue'
|
||||
import { saveProfile, fetchProfile, fetchEducation, saveEducation, fetchWork, saveWork, fetchInternship, saveInternship, fetchProject, saveProject, fetchCompetition, saveCompetition, syncProfileFromResume } from '@/api/profile'
|
||||
import { uploadResume } from '@/utils/aiRequest'
|
||||
import { ElMessage, ElLoading } from 'element-plus'
|
||||
import 'element-plus/es/components/loading/style/css'
|
||||
import type { SaveEducationItem, SaveWorkItem, SaveProjectItem, SaveCompetitionItem } from '@/api/profile'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -217,6 +220,35 @@ const showEditDrawer = ref(false)
|
||||
/** 欢迎弹窗的显示状态 */
|
||||
const showWelcomeDialog = ref(false)
|
||||
|
||||
/** 欢迎弹窗确认上传回调 — 上传简历并同步个人资料,完成后刷新页面 */
|
||||
async function handleWelcomeUpload(file: File) {
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: '简历解析中,请耐心等待…',
|
||||
background: 'rgba(0, 0, 0, 0.5)',
|
||||
customClass: 'profile-welcome-loading',
|
||||
})
|
||||
|
||||
try {
|
||||
const res = await uploadResume(file)
|
||||
if (res.code === 0 && res.data?.resumeId) {
|
||||
// 继续同步个人资料
|
||||
loading.setText('正在同步个人资料…')
|
||||
await syncProfileFromResume(String(res.data.resumeId))
|
||||
loading.close()
|
||||
ElMessage.success('简历上传并同步成功')
|
||||
// 刷新页面数据
|
||||
router.go(0)
|
||||
} else {
|
||||
loading.close()
|
||||
ElMessage.error(res.msg || '上传失败')
|
||||
}
|
||||
} catch {
|
||||
loading.close()
|
||||
ElMessage.error('上传失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
/** 登录状态 */
|
||||
const isAuthenticated = computed(() => store.state.isAuthenticated)
|
||||
|
||||
|
||||
+40
-35
@@ -92,6 +92,12 @@
|
||||
:resume-id="exportResumeId"
|
||||
:resume-name="exportResumeName"
|
||||
/>
|
||||
|
||||
<!-- 上传简历弹窗组件 -->
|
||||
<ResumeUploadDialog
|
||||
v-model="uploadDialogVisible"
|
||||
@confirm="handleUploadConfirm"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -101,13 +107,15 @@ import { useRouter } from 'vue-router'
|
||||
import SideNav from '@/components/SideNav.vue'
|
||||
import ResumeEditNameDialog from '@/components/ResumeEditNameDialog.vue'
|
||||
import ResumeExportDialog from '@/components/ResumeExportDialog.vue'
|
||||
import ResumeUploadDialog from '@/components/ResumeUploadDialog.vue'
|
||||
import { uploadResume } from '@/utils/aiRequest'
|
||||
import {
|
||||
fetchResumeList, deleteResume, type ResumeListItem,
|
||||
} from '@/api/resume'
|
||||
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus'
|
||||
// ElLoading.service() 是命令式调用,按需引入插件不会自动加载其样式,需手动引入
|
||||
// 命令式调用的组件,按需引入插件不会自动加载其样式,需手动引入
|
||||
import 'element-plus/es/components/loading/style/css'
|
||||
import 'element-plus/es/components/message-box/style/css'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -218,6 +226,11 @@ const exportResumeId = ref('')
|
||||
/** 当前导出的简历名称(用于文件名) */
|
||||
const exportResumeName = ref('')
|
||||
|
||||
// ==================== 上传简历弹窗状态 ====================
|
||||
|
||||
/** 上传弹窗是否可见 */
|
||||
const uploadDialogVisible = ref(false)
|
||||
|
||||
/** 弹出菜单操作项 */
|
||||
const popupActions = ['设为默认简历', '编辑名称岗位', '导出简历', '删除']
|
||||
|
||||
@@ -276,46 +289,38 @@ async function handleAction(action: string, id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 上传简历 — 弹出文件选择,选择后调用 AI 接口上传 */
|
||||
/** 上传简历 — 打开上传弹窗 */
|
||||
function handleUpload() {
|
||||
const input = document.createElement('input')
|
||||
input.type = 'file'
|
||||
// 限定 pdf 和 word 格式
|
||||
input.accept = '.pdf,.doc,.docx,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
uploadDialogVisible.value = true
|
||||
}
|
||||
|
||||
input.onchange = async () => {
|
||||
const file = input.files?.[0]
|
||||
if (!file) return
|
||||
/** 上传弹窗确认回调 — 接收 File 对象,调用接口上传 */
|
||||
async function handleUploadConfirm(file: File) {
|
||||
// 全屏加载提示,AI 接口响应较慢
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: '简历解析中,请耐心等待…',
|
||||
background: 'rgba(0, 0, 0, 0.5)',
|
||||
customClass: 'resume-upload-loading',
|
||||
})
|
||||
|
||||
// 全屏加载提示,AI 接口响应较慢
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: '简历解析中,请耐心等待…',
|
||||
background: 'rgba(0, 0, 0, 0.5)',
|
||||
customClass: 'resume-upload-loading',
|
||||
})
|
||||
|
||||
try {
|
||||
const res = await uploadResume(file)
|
||||
if (res.code === 0) {
|
||||
// 上传成功,刷新列表
|
||||
loadResumeList()
|
||||
// 等待让后端异步处理数据,再关闭加载动画并跳转详情页
|
||||
await new Promise(resolve => setTimeout(resolve, 2000))
|
||||
loading.close()
|
||||
// resumeId 已经是字符串(transformResponse 处理过),直接使用
|
||||
goDetail(res.data.resumeId)
|
||||
} else {
|
||||
loading.close()
|
||||
ElMessage.error(res.msg || '上传失败')
|
||||
}
|
||||
} catch {
|
||||
try {
|
||||
const res = await uploadResume(file)
|
||||
if (res.code === 0) {
|
||||
// 上传成功,刷新列表
|
||||
loadResumeList()
|
||||
// 等待让后端异步处理数据,再关闭加载动画并跳转详情页
|
||||
await new Promise(resolve => setTimeout(resolve, 2000))
|
||||
loading.close()
|
||||
ElMessage.error('上传失败,请稍后重试')
|
||||
goDetail(res.data.resumeId)
|
||||
} else {
|
||||
loading.close()
|
||||
ElMessage.error(res.msg || '上传失败')
|
||||
}
|
||||
} catch {
|
||||
loading.close()
|
||||
ElMessage.error('上传失败,请稍后重试')
|
||||
}
|
||||
|
||||
input.click()
|
||||
}
|
||||
|
||||
/** 跳转到简历详情页 */
|
||||
|
||||
Reference in New Issue
Block a user