app添加工作经历开发

This commit is contained in:
冯辉
2025-10-13 16:01:49 +08:00
parent 3d7cb0c561
commit 3d2c26650c
12 changed files with 840 additions and 74 deletions

View File

@@ -161,63 +161,111 @@ const { getDictData, oneDictData } = useDictStore();
const isUploading = ref(false); // 上传中状态
const uploadedResumeName = ref(''); // 已上传简历文件名
const uploadedResumeUrl = ref(''); // 已上传
const workExperiences = ref([
{
id: 1, // 唯一标识实际项目用后端返回ID
companyName: 'XX科技有限公司', // 公司名称
position: '前端开发工程师', // 职位
startDate: '2021-07', // 开始日期格式YYYY-MM
endDate: '2023-09', // 结束日期(空/undefined 表示“至今”)
description:
'1. 负责公司小程序及H5页面开发基于UniApp+Vue3技术栈2. 优化前端性能首屏加载时间减少30%3. 参与封装通用组件库,提升团队开发效率。', // 工作描述
},
{
id: 2,
companyName: 'YY互联网公司',
position: '实习前端工程师',
startDate: '2020-12',
endDate: '2021-06',
description: '1. 协助完成后台管理系统页面开发2. 修复页面兼容性问题适配多浏览器3. 整理前端开发文档。',
},
]);
const workExperiences = ref([]); // 工作经历列表
const isLoading = ref(false); // 加载状态
// 页面加载时可从接口拉取数据
// 获取工作经历列表
const getWorkExperiences = async () => {
try {
isLoading.value = true;
console.log('完整用户信息:', userInfo.value);
// 获取用户ID - 使用可选链操作符避免错误
const userId = userInfo.value?.userId;
console.log('用户ID:', userId);
if (!userId) {
console.log('用户ID为空等待用户信息加载...');
// 如果用户ID为空不执行任何操作避免触发退出登录
return;
}
// 只传递userId参数
console.log('请求参数:', { userId });
// 使用try-catch包装请求避免自动退出登录
try {
// 参数拼接到URL后面
const resData = await $api.createRequest(`/app/userworkexperiences/list?userId=${userId}`, {}, 'get');
console.log('工作经历列表响应:', resData);
if (resData.code === 200 && resData.rows) {
workExperiences.value = resData.rows;
console.log('工作经历数据设置成功:', resData.rows);
console.log('总数量:', resData.total);
} else {
console.log('接口返回非200状态或无数据:', resData);
// 如果接口返回错误,不显示错误提示,避免用户困惑
workExperiences.value = []; // 设置为空数组
}
} catch (requestError) {
console.error('接口请求失败:', requestError);
// 接口请求失败时,不显示错误提示,静默处理
workExperiences.value = []; // 设置为空数组
}
} catch (error) {
console.error('获取工作经历失败:', error);
// 静默处理错误,不显示错误提示
workExperiences.value = [];
} finally {
isLoading.value = false;
}
};
// 页面加载时获取数据
onLoad(() => {
// 实际项目中替换为接口请求:
// getWorkExperiences().then(res => {
// workExperiences.value = res.data;
// }).catch(err => {
// showToast({ title: '数据加载失败', icon: 'none' });
// });
// 延迟获取数据,确保用户信息完全加载
setTimeout(() => {
if (userInfo.value?.userId) {
getWorkExperiences();
}
}, 1000);
});
// 页面显示时刷新数据
onShow(() => {
// 延迟获取数据,确保用户信息完全加载
setTimeout(() => {
if (userInfo.value?.userId) {
getWorkExperiences();
}
}, 1000);
});
// 整体编辑/添加(跳转编辑页)
const handleEditOrAdd = () => {
// 跳转至“批量编辑”或“添加经历页面(根据实际需求设计编辑页)
// router.push({
// path: '/pages/workExperience/edit',
// query: { type: workExperiences.value.length > 0 ? 'edit' : 'add' }
// });
// 跳转添加经历页面,传递添加标识
navTo('/packageA/pages/addWorkExperience/addWorkExperience?type=add');
};
// 编辑单个经历
const handleEditItem = (item) => {
// 跳转至单个编辑页,并携带当前经历数据
// router.push({
// path: '/pages/workExperience/editItem',
// query: { item: JSON.stringify(item) } // 复杂数据需转JSON字符串UniApp路由query不支持直接传对象
// });
// 跳转到编辑页面,传递编辑标识和数据
const itemData = encodeURIComponent(JSON.stringify(item));
navTo(`/packageA/pages/addWorkExperience/addWorkExperience?type=edit&data=${itemData}`);
};
// 删除单个经历(带确认弹窗)
const handleDeleteItem = (index) => {
const handleDeleteItem = async (item, index) => {
uni.showModal({
title: '确认删除',
content: '此操作将删除该工作经历,是否继续?',
success: (res) => {
success: async (res) => {
if (res.confirm) {
workExperiences.value.splice(index, 1); // 删除本地数据
$api.msg('删除成功');
try {
// 调用删除接口
const deleteRes = await $api.createRequest(`/cms/userworkexperiences/${item.id}`, {}, 'delete');
if (deleteRes.code === 200) {
workExperiences.value.splice(index, 1); // 删除本地数据
$api.msg('删除成功');
} else {
$api.msg(deleteRes.msg || '删除失败');
}
} catch (error) {
console.error('删除工作经历失败:', error);
$api.msg('删除失败,请重试');
}
}
},
});