flat: 暂存
This commit is contained in:
@@ -472,4 +472,9 @@ html {
|
|||||||
|
|
||||||
.height-100 {
|
.height-100 {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.pointEveNone {
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
@@ -1,267 +1,295 @@
|
|||||||
<template>
|
<template>
|
||||||
<AppLayout title="个人信息" :sub-title="`完成度${percent}`" border back-gorund-color="#ffffff" :show-bg-image="false">
|
<AppLayout
|
||||||
<template #headerleft>
|
title="个人信息"
|
||||||
<view class="btn mar_le20 button-click" @click="navBack">取消</view>
|
:sub-title="`完成度${percent}`"
|
||||||
</template>
|
border
|
||||||
<template #headerright>
|
back-gorund-color="#ffffff"
|
||||||
<view class="btn mar_ri20 button-click" @click="confirm">确认</view>
|
:show-bg-image="false"
|
||||||
</template>
|
>
|
||||||
<view class="content">
|
<template #headerleft>
|
||||||
<view class="content-avatar">
|
<view class="btn mar_le20 button-click" @click="navBack">取消</view>
|
||||||
<view class="avatar-title">编辑头像</view>
|
</template>
|
||||||
<view @click="selectAvatar">
|
<template #headerright>
|
||||||
<image class="avatar" v-if="fromValue.avatar" :src="fromValue.avatar" />
|
<view class="btn mar_ri20 button-click" @click="confirm">确认</view>
|
||||||
<image class="avatar" v-else-if="fromValue.sex == '0'" src="@/static/icon/boy.png" />
|
</template>
|
||||||
<image class="avatar" v-else="fromValue.sex == '1'" src="@/static/icon/girl.png" />
|
<view class="content">
|
||||||
|
<view class="content-avatar">
|
||||||
|
<view class="avatar-title">编辑头像</view>
|
||||||
|
<view @click="selectAvatar">
|
||||||
|
<image class="avatar" v-if="fromValue.avatar" :src="fromValue.avatar" />
|
||||||
|
<image class="avatar" v-else-if="fromValue.sex == '0'" src="@/static/icon/boy.png" />
|
||||||
|
<image class="avatar" v-else="fromValue.sex == '1'" src="@/static/icon/girl.png" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="content-input">
|
||||||
|
<view class="input-titile">姓名</view>
|
||||||
|
<input class="input-con" v-model="fromValue.name" placeholder="请输入您的姓名" />
|
||||||
|
</view>
|
||||||
|
<view class="content-sex">
|
||||||
|
<view class="sex-titile">性别</view>
|
||||||
|
<view class="sext-ri">
|
||||||
|
<view class="sext-box" :class="{ 'sext-boxactive': fromValue.sex === 0 }" @click="changeSex(0)">
|
||||||
|
男
|
||||||
|
</view>
|
||||||
|
<view class="sext-box" :class="{ 'sext-boxactive': fromValue.sex === 1 }" @click="changeSex(1)">
|
||||||
|
女
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="content-input" @click="changeDateBirt">
|
||||||
|
<view class="input-titile">出生年月</view>
|
||||||
|
<input
|
||||||
|
class="input-con triangle pointEveNone"
|
||||||
|
v-model="fromValue.birthDate"
|
||||||
|
disabled
|
||||||
|
placeholder="请选择您的出生年月"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view class="content-input" @click="changeEducation">
|
||||||
|
<view class="input-titile">学历</view>
|
||||||
|
<input
|
||||||
|
class="input-con triangle pointEveNone"
|
||||||
|
v-model="state.educationText"
|
||||||
|
disabled
|
||||||
|
placeholder="请选择您的学历"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view class="content-input" @click="changePoliticalAffiliation">
|
||||||
|
<view class="input-titile">政治面貌</view>
|
||||||
|
<input
|
||||||
|
class="input-con triangle pointEveNone"
|
||||||
|
v-model="state.politicalAffiliationText"
|
||||||
|
disabled
|
||||||
|
placeholder="请选择您的政治面貌"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view class="content-input">
|
||||||
|
<view class="input-titile">手机号码</view>
|
||||||
|
<input class="input-con" v-model="fromValue.phone" placeholder="请输入您的手机号码" />
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</AppLayout>
|
||||||
<view class="content-input">
|
|
||||||
<view class="input-titile">姓名</view>
|
|
||||||
<input class="input-con" v-model="fromValue.name" placeholder="请输入您的姓名" />
|
|
||||||
</view>
|
|
||||||
<view class="content-sex">
|
|
||||||
<view class="sex-titile">性别</view>
|
|
||||||
<view class="sext-ri">
|
|
||||||
<view class="sext-box" :class="{ 'sext-boxactive': fromValue.sex === 0 }" @click="changeSex(0)"> 男 </view>
|
|
||||||
<view class="sext-box" :class="{ 'sext-boxactive': fromValue.sex === 1 }" @click="changeSex(1)"> 女 </view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
<view class="content-input" @click="changeDateBirt">
|
|
||||||
<view class="input-titile">出生年月</view>
|
|
||||||
<input class="input-con triangle" v-model="fromValue.birthDate" disabled placeholder="请选择您的出生年月" />
|
|
||||||
</view>
|
|
||||||
<view class="content-input" @click="changeEducation">
|
|
||||||
<view class="input-titile">学历</view>
|
|
||||||
<input class="input-con triangle" v-model="state.educationText" disabled placeholder="请选择您的学历" />
|
|
||||||
</view>
|
|
||||||
<view class="content-input" @click="changePoliticalAffiliation">
|
|
||||||
<view class="input-titile">政治面貌</view>
|
|
||||||
<input class="input-con triangle" v-model="state.politicalAffiliationText" disabled placeholder="请选择您的政治面貌" />
|
|
||||||
</view>
|
|
||||||
<view class="content-input">
|
|
||||||
<view class="input-titile">手机号码</view>
|
|
||||||
<input class="input-con" v-model="fromValue.phone" placeholder="请输入您的手机号码" />
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</AppLayout>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, inject, watch, ref, onMounted } from "vue";
|
import { reactive, inject, watch, ref, onMounted } from 'vue';
|
||||||
import { onLoad, onShow } from "@dcloudio/uni-app";
|
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||||
const { $api, navTo, navBack, checkingPhoneRegExp } = inject("globalFunction");
|
const { $api, navTo, navBack, checkingPhoneRegExp } = inject('globalFunction');
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from 'pinia';
|
||||||
import useUserStore from "@/stores/useUserStore";
|
import useUserStore from '@/stores/useUserStore';
|
||||||
import useDictStore from "@/stores/useDictStore";
|
import useDictStore from '@/stores/useDictStore';
|
||||||
const { userInfo } = storeToRefs(useUserStore());
|
const { userInfo } = storeToRefs(useUserStore());
|
||||||
const { getUserResume } = useUserStore();
|
const { getUserResume } = useUserStore();
|
||||||
const { dictLabel, oneDictData } = useDictStore();
|
const { dictLabel, oneDictData } = useDictStore();
|
||||||
const openSelectPopup = inject("openSelectPopup");
|
const openSelectPopup = inject('openSelectPopup');
|
||||||
|
|
||||||
const percent = ref("0%");
|
const percent = ref('0%');
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
educationText: "",
|
educationText: '',
|
||||||
politicalAffiliationText: "",
|
politicalAffiliationText: '',
|
||||||
});
|
});
|
||||||
const fromValue = reactive({
|
const fromValue = reactive({
|
||||||
name: "",
|
name: '',
|
||||||
sex: 0,
|
sex: 0,
|
||||||
birthDate: "",
|
birthDate: '',
|
||||||
education: "",
|
education: '',
|
||||||
politicalAffiliation: "",
|
politicalAffiliation: '',
|
||||||
avatar: "",
|
avatar: '',
|
||||||
});
|
});
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
initLoad();
|
initLoad();
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
// const { age, birthDate } = useUserStore().userInfo;
|
// const { age, birthDate } = useUserStore().userInfo;
|
||||||
// const newAge = calculateAge(birthDate);
|
// const newAge = calculateAge(birthDate);
|
||||||
// // 计算年龄是否对等
|
// // 计算年龄是否对等
|
||||||
// if (age != newAge) {
|
// if (age != newAge) {
|
||||||
// completeResume();
|
// completeResume();
|
||||||
// }
|
// }
|
||||||
// }, 1000);
|
// }, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function initLoad() {
|
function initLoad() {
|
||||||
fromValue.name = userInfo.value.name;
|
fromValue.name = userInfo.value.name;
|
||||||
fromValue.sex = Number(userInfo.value.sex);
|
fromValue.sex = Number(userInfo.value.sex);
|
||||||
fromValue.phone = userInfo.value.phone;
|
fromValue.phone = userInfo.value.phone;
|
||||||
fromValue.birthDate = userInfo.value.birthDate;
|
fromValue.birthDate = userInfo.value.birthDate;
|
||||||
fromValue.education = userInfo.value.education;
|
fromValue.education = userInfo.value.education;
|
||||||
fromValue.politicalAffiliation = userInfo.value.politicalAffiliation;
|
fromValue.politicalAffiliation = userInfo.value.politicalAffiliation;
|
||||||
fromValue.avatar = userInfo.value.avatar;
|
fromValue.avatar = userInfo.value.avatar;
|
||||||
// 回显
|
// 回显
|
||||||
state.educationText = dictLabel("education", userInfo.value.education);
|
state.educationText = dictLabel('education', userInfo.value.education);
|
||||||
state.politicalAffiliationText = dictLabel("affiliation", userInfo.value.politicalAffiliation);
|
state.politicalAffiliationText = dictLabel('affiliation', userInfo.value.politicalAffiliation);
|
||||||
const result = getFormCompletionPercent(fromValue);
|
const result = getFormCompletionPercent(fromValue);
|
||||||
percent.value = result;
|
percent.value = result;
|
||||||
}
|
}
|
||||||
const confirm = () => {
|
const confirm = () => {
|
||||||
if (!fromValue.name) {
|
if (!fromValue.name) {
|
||||||
return $api.msg("请输入姓名");
|
return $api.msg('请输入姓名');
|
||||||
}
|
}
|
||||||
if (!fromValue.birthDate) {
|
if (!fromValue.birthDate) {
|
||||||
return $api.msg("请选择出生年月");
|
return $api.msg('请选择出生年月');
|
||||||
}
|
}
|
||||||
if (!fromValue.education) {
|
if (!fromValue.education) {
|
||||||
return $api.msg("请选择学历");
|
return $api.msg('请选择学历');
|
||||||
}
|
}
|
||||||
if (!fromValue.politicalAffiliation) {
|
if (!fromValue.politicalAffiliation) {
|
||||||
return $api.msg("请选择政治面貌");
|
return $api.msg('请选择政治面貌');
|
||||||
}
|
}
|
||||||
// if (!checkingPhoneRegExp(fromValue.phone)) {
|
// if (!checkingPhoneRegExp(fromValue.phone)) {
|
||||||
// return $api.msg('请输入正确手机号');
|
// return $api.msg('请输入正确手机号');
|
||||||
// }
|
// }
|
||||||
const params = {
|
const params = {
|
||||||
...fromValue,
|
...fromValue,
|
||||||
age: calculateAge(fromValue.birthDate),
|
age: calculateAge(fromValue.birthDate),
|
||||||
};
|
};
|
||||||
$api.createRequest("/app/user/resume", params, "post").then((resData) => {
|
$api.createRequest('/app/user/resume', params, 'post').then((resData) => {
|
||||||
$api.msg("完成");
|
$api.msg('完成');
|
||||||
state.disbleDate = true;
|
state.disbleDate = true;
|
||||||
getUserResume().then(() => {
|
getUserResume().then(() => {
|
||||||
navBack();
|
navBack();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeDateBirt = () => {
|
const changeDateBirt = () => {
|
||||||
const datearray = generateDatePickerArrays();
|
const datearray = generateDatePickerArrays();
|
||||||
const defaultIndex = getDatePickerIndexes(fromValue.birthDate);
|
let defaultIndex = [0, 0, 0];
|
||||||
openSelectPopup({
|
if (fromValue.birthDate) {
|
||||||
title: "年龄段",
|
const defaultIndex = getDatePickerIndexes(fromValue.birthDate);
|
||||||
maskClick: true,
|
}
|
||||||
data: datearray,
|
console.log(defaultIndex);
|
||||||
defaultIndex,
|
openSelectPopup({
|
||||||
success: (_, value) => {
|
title: '年龄段',
|
||||||
const [year, month, day] = value;
|
maskClick: true,
|
||||||
const dateStr = `${year.value}-${month.value}-${day.value}`;
|
data: datearray,
|
||||||
if (isValidDate(dateStr)) {
|
defaultIndex,
|
||||||
fromValue.birthDate = dateStr;
|
success: (_, value) => {
|
||||||
} else {
|
const [year, month, day] = value;
|
||||||
$api.msg("没有这一天");
|
const dateStr = `${year.value}-${month.value}-${day.value}`;
|
||||||
}
|
if (isValidDate(dateStr)) {
|
||||||
},
|
fromValue.birthDate = dateStr;
|
||||||
});
|
} else {
|
||||||
|
$api.msg('没有这一天');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
const changeEducation = () => {
|
const changeEducation = () => {
|
||||||
openSelectPopup({
|
openSelectPopup({
|
||||||
title: "学历",
|
title: '学历',
|
||||||
maskClick: true,
|
maskClick: true,
|
||||||
data: [oneDictData("education")],
|
data: [oneDictData('education')],
|
||||||
success: (_, [value]) => {
|
success: (_, [value]) => {
|
||||||
fromValue.education = value.value;
|
fromValue.education = value.value;
|
||||||
state.educationText = value.label;
|
state.educationText = value.label;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const changeSex = (sex) => {
|
const changeSex = (sex) => {
|
||||||
fromValue.sex = sex;
|
fromValue.sex = sex;
|
||||||
};
|
};
|
||||||
|
|
||||||
const changePoliticalAffiliation = () => {
|
const changePoliticalAffiliation = () => {
|
||||||
openSelectPopup({
|
openSelectPopup({
|
||||||
title: "政治面貌",
|
title: '政治面貌',
|
||||||
maskClick: true,
|
maskClick: true,
|
||||||
data: [oneDictData("affiliation")],
|
data: [oneDictData('affiliation')],
|
||||||
success: (_, [value]) => {
|
success: (_, [value]) => {
|
||||||
fromValue.politicalAffiliation = value.value;
|
fromValue.politicalAffiliation = value.value;
|
||||||
state.politicalAffiliationText = value.label;
|
state.politicalAffiliationText = value.label;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function generateDatePickerArrays(startYear = 1975, endYear = new Date().getFullYear()) {
|
function generateDatePickerArrays(startYear = 1975, endYear = new Date().getFullYear()) {
|
||||||
const years = [];
|
const years = [];
|
||||||
const months = [];
|
const months = [];
|
||||||
const days = [];
|
const days = [];
|
||||||
|
|
||||||
for (let y = startYear; y <= endYear; y++) {
|
for (let y = startYear; y <= endYear; y++) {
|
||||||
years.push(y.toString());
|
years.push(y.toString());
|
||||||
}
|
}
|
||||||
for (let m = 1; m <= 12; m++) {
|
for (let m = 1; m <= 12; m++) {
|
||||||
months.push(m.toString().padStart(2, "0"));
|
months.push(m.toString().padStart(2, '0'));
|
||||||
}
|
}
|
||||||
for (let d = 1; d <= 31; d++) {
|
for (let d = 1; d <= 31; d++) {
|
||||||
days.push(d.toString().padStart(2, "0"));
|
days.push(d.toString().padStart(2, '0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return [years, months, days];
|
return [years, months, days];
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidDate(dateString) {
|
function isValidDate(dateString) {
|
||||||
const [year, month, day] = dateString.split("-").map(Number);
|
const [year, month, day] = dateString.split('-').map(Number);
|
||||||
|
|
||||||
const date = new Date(year, month - 1, day); // 月份从0开始
|
const date = new Date(year, month - 1, day); // 月份从0开始
|
||||||
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculateAge = (birthDate) => {
|
const calculateAge = (birthDate) => {
|
||||||
const birth = new Date(birthDate);
|
const birth = new Date(birthDate);
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
let age = today.getFullYear() - birth.getFullYear();
|
let age = today.getFullYear() - birth.getFullYear();
|
||||||
const monthDiff = today.getMonth() - birth.getMonth();
|
const monthDiff = today.getMonth() - birth.getMonth();
|
||||||
const dayDiff = today.getDate() - birth.getDate();
|
const dayDiff = today.getDate() - birth.getDate();
|
||||||
|
|
||||||
// 如果生日的月份还没到,或者刚到生日月份但当天还没过,则年龄减 1
|
// 如果生日的月份还没到,或者刚到生日月份但当天还没过,则年龄减 1
|
||||||
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
|
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
|
||||||
age--;
|
age--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return age;
|
return age;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getFormCompletionPercent(form) {
|
function getFormCompletionPercent(form) {
|
||||||
let total = Object.keys(form).length;
|
let total = Object.keys(form).length;
|
||||||
let filled = 0;
|
let filled = 0;
|
||||||
|
|
||||||
for (const key in form) {
|
for (const key in form) {
|
||||||
const value = form[key];
|
const value = form[key];
|
||||||
if (value !== "" && value !== null && value !== undefined) {
|
if (value !== '' && value !== null && value !== undefined) {
|
||||||
if (typeof value === "number") {
|
if (typeof value === 'number') {
|
||||||
filled += 1;
|
filled += 1;
|
||||||
} else if (typeof value === "string" && value.trim() !== "") {
|
} else if (typeof value === 'string' && value.trim() !== '') {
|
||||||
filled += 1;
|
filled += 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (total === 0) return "0%";
|
if (total === 0) return '0%';
|
||||||
const percent = (filled / total) * 100;
|
const percent = (filled / total) * 100;
|
||||||
return percent.toFixed(0) + "%"; // 取整,不要小数点
|
return percent.toFixed(0) + '%'; // 取整,不要小数点
|
||||||
}
|
}
|
||||||
// 主函数
|
// 主函数
|
||||||
function getDatePickerIndexes(dateStr) {
|
function getDatePickerIndexes(dateStr) {
|
||||||
const [year, month, day] = dateStr.split("-");
|
const [year, month, day] = dateStr.split('-');
|
||||||
|
|
||||||
const [years, months, days] = generateDatePickerArrays();
|
const [years, months, days] = generateDatePickerArrays();
|
||||||
|
|
||||||
const yearIndex = years.indexOf(year);
|
const yearIndex = years.indexOf(year);
|
||||||
const monthIndex = months.indexOf(month);
|
const monthIndex = months.indexOf(month);
|
||||||
const dayIndex = days.indexOf(day);
|
const dayIndex = days.indexOf(day);
|
||||||
|
|
||||||
return [yearIndex, monthIndex, dayIndex];
|
return [yearIndex, monthIndex, dayIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectAvatar() {
|
function selectAvatar() {
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
sizeType: ["original", "compressed"],
|
sizeType: ['original', 'compressed'],
|
||||||
sourceType: ["album", "camera"],
|
sourceType: ['album', 'camera'],
|
||||||
count: 1,
|
count: 1,
|
||||||
success: ({ tempFilePaths, tempFiles }) => {
|
success: ({ tempFilePaths, tempFiles }) => {
|
||||||
$api
|
$api.uploadFile(tempFilePaths[0], true)
|
||||||
.uploadFile(tempFilePaths[0], true)
|
.then((res) => {
|
||||||
.then((res) => {
|
res = JSON.parse(res);
|
||||||
res = JSON.parse(res);
|
if (res.msg) fromValue.avatar = res.msg;
|
||||||
if (res.msg) fromValue.avatar = res.msg;
|
})
|
||||||
})
|
.catch((err) => {
|
||||||
.catch((err) => {
|
$api.msg('上传失败');
|
||||||
$api.msg("上传失败");
|
});
|
||||||
});
|
},
|
||||||
},
|
fail: (error) => {},
|
||||||
fail: (error) => {},
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user