|
@@ -24,6 +24,7 @@ const _sfc_main = {
|
|
|
};
|
|
|
},
|
|
|
onLoad() {
|
|
|
+ this.checkLogin();
|
|
|
this.checkUserInfo();
|
|
|
this.fetchJobList();
|
|
|
},
|
|
@@ -33,6 +34,42 @@ const _sfc_main = {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ checkLogin() {
|
|
|
+ const userInfo = common_vendor.index.getStorageSync("userInfo");
|
|
|
+ if (!userInfo) {
|
|
|
+ common_vendor.index.switchTab({
|
|
|
+ url: "/pages/my/my",
|
|
|
+ success: () => {
|
|
|
+ console.log("跳转到登录页面成功");
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error("跳转到登录页面失败:", err);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "跳转失败,请重试",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ const parsedUserInfo = JSON.parse(userInfo);
|
|
|
+ if (!parsedUserInfo.openid) {
|
|
|
+ common_vendor.index.switchTab({
|
|
|
+ url: "/pages/my/my"
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } catch (e) {
|
|
|
+ console.error("解析用户信息失败:", e);
|
|
|
+ common_vendor.index.removeStorageSync("userInfo");
|
|
|
+ common_vendor.index.switchTab({
|
|
|
+ url: "/pages/my/my"
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
goHome() {
|
|
|
common_vendor.index.navigateBack({
|
|
|
delta: 1
|
|
@@ -46,42 +83,58 @@ const _sfc_main = {
|
|
|
this.formData.relation = this.relationOptions[this.relationIndex];
|
|
|
},
|
|
|
checkUserInfo() {
|
|
|
+ if (!this.checkLogin()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
common_vendor.index.showLoading({
|
|
|
title: "加载中..."
|
|
|
});
|
|
|
- console.log("id:", JSON.parse(common_vendor.index.getStorageSync("userInfo")).id);
|
|
|
- api_user.getUserInfo(JSON.parse(common_vendor.index.getStorageSync("userInfo")).id).then((res) => {
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- if (res.code === 200 && res.data) {
|
|
|
- const userData = res.data;
|
|
|
- if (userData.name && userData.phone) {
|
|
|
- this.userInfoFilled = true;
|
|
|
- this.formData.name = userData.name || "";
|
|
|
- this.formData.gender = userData.gender || "";
|
|
|
- this.formData.phone = userData.phone || "";
|
|
|
- this.formData.idCard = userData.id_card || "";
|
|
|
- this.formData.emergencyContact = userData.emergency_contact || "";
|
|
|
- this.formData.emergencyPhone = userData.emergency_phone || "";
|
|
|
- this.formData.relation = userData.relation || "";
|
|
|
- if (userData.relation) {
|
|
|
- const index = this.relationOptions.findIndex((item) => item === userData.relation);
|
|
|
- if (index !== -1) {
|
|
|
- this.relationIndex = index;
|
|
|
+ try {
|
|
|
+ const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
|
|
|
+ console.log("id:", userInfo.id);
|
|
|
+ api_user.getUserInfo(userInfo.id).then((res) => {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ if (res.code === 200 && res.data) {
|
|
|
+ const userData = res.data;
|
|
|
+ if (userData.name && userData.phone) {
|
|
|
+ this.userInfoFilled = true;
|
|
|
+ this.formData.name = userData.name || "";
|
|
|
+ this.formData.gender = userData.gender || "";
|
|
|
+ this.formData.phone = userData.phone || "";
|
|
|
+ this.formData.idCard = userData.id_card || "";
|
|
|
+ this.formData.emergencyContact = userData.emergency_contact || "";
|
|
|
+ this.formData.emergencyPhone = userData.emergency_phone || "";
|
|
|
+ this.formData.relation = userData.relation || "";
|
|
|
+ if (userData.relation) {
|
|
|
+ const index = this.relationOptions.findIndex((item) => item === userData.relation);
|
|
|
+ if (index !== -1) {
|
|
|
+ this.relationIndex = index;
|
|
|
+ }
|
|
|
}
|
|
|
+ common_vendor.index.navigateTo({
|
|
|
+ url: "/pages/success/success"
|
|
|
+ });
|
|
|
}
|
|
|
- common_vendor.index.navigateTo({
|
|
|
- url: "/pages/success/success"
|
|
|
- });
|
|
|
}
|
|
|
- }
|
|
|
- }).catch((err) => {
|
|
|
+ }).catch((err) => {
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ console.error("获取用户信息失败:", err);
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "获取用户信息失败",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
common_vendor.index.hideLoading();
|
|
|
- console.error("获取用户信息失败:", err);
|
|
|
+ console.error("获取用户信息失败:", e);
|
|
|
common_vendor.index.showToast({
|
|
|
title: "获取用户信息失败",
|
|
|
icon: "none"
|
|
|
});
|
|
|
- });
|
|
|
+ common_vendor.index.navigateTo({
|
|
|
+ url: "/pages/my/my"
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
fetchJobList() {
|
|
|
common_vendor.index.showLoading({
|
|
@@ -105,6 +158,9 @@ const _sfc_main = {
|
|
|
this.selectedJob = job;
|
|
|
},
|
|
|
applyForJob() {
|
|
|
+ if (!this.checkLogin()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!this.selectedJobId) {
|
|
|
common_vendor.index.showToast({
|
|
|
title: "请选择一个职位",
|
|
@@ -133,6 +189,9 @@ const _sfc_main = {
|
|
|
});
|
|
|
},
|
|
|
submitForm() {
|
|
|
+ if (!this.checkLogin()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!this.formData.name.trim()) {
|
|
|
common_vendor.index.showToast({
|
|
|
title: "请输入姓名",
|
|
@@ -219,7 +278,7 @@ const _sfc_main = {
|
|
|
return;
|
|
|
}
|
|
|
const submitData = {
|
|
|
- openid: JSON.parse(common_vendor.index.getStorageSync("userInfo")).openid || "",
|
|
|
+ openid: JSON.parse(common_vendor.index.getStorageSync("userInfo") || "{}").openid || "",
|
|
|
name: this.formData.name,
|
|
|
phone: this.formData.phone,
|
|
|
id_card: this.formData.idCard,
|