basicInfo.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="resume-box mb-3 elevation-2" id="basicInfo">
  3. <div class="resume-header">
  4. <div class="resume-title">{{ $t('resume.basicInfo') }}</div>
  5. <v-btn v-if="!isEdit" variant="text" color="primary" prepend-icon="mdi-square-edit-outline" @click="isEdit = true">{{ $t('common.edit') }}</v-btn>
  6. </div>
  7. <div class="d-flex align-start mt-5">
  8. <!-- 头像 -->
  9. <div class="avatarsBox" @mouseover="showIcon = true" @mouseleave="showIcon = false">
  10. <v-badge
  11. v-if="baseInfo?.sex === '1' || baseInfo?.sex === '2'"
  12. bordered
  13. :color="baseInfo?.sex ? (baseInfo?.sex === '1' ? '#1867c0' : 'error') : 'error'"
  14. :icon="baseInfo?.sex ? (baseInfo?.sex === '1' ? 'mdi-gender-male' : 'mdi-gender-female') : 'mdi-gender-female'">
  15. <v-img :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" width="130" height="130" style="border-radius: 6px;"></v-img>
  16. <div v-show="showIcon" @click="openFileInput" class="mdi mdi-camera-outline camera">
  17. <input
  18. type="file"
  19. ref="fileInput"
  20. accept="image/png, image/jpg, image/jpeg"
  21. style="display: none;"
  22. @change="handleUploadFile"
  23. />
  24. </div>
  25. </v-badge>
  26. <div v-else style="width: 130px; height: 130px;">
  27. <v-img :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" width="130" height="130" style="border-radius: 6px;"></v-img>
  28. <div v-show="showIcon" @click="openFileInput" class="mdi mdi-camera-outline camera">
  29. <input
  30. type="file"
  31. ref="fileInput"
  32. accept="image/png, image/jpg, image/jpeg"
  33. style="display: none;"
  34. @change="handleUploadFile"
  35. />
  36. </div>
  37. </div>
  38. </div>
  39. <!-- 基础信息 -->
  40. <div style="flex: 1;" class="mr-8">
  41. <!-- 编辑 -->
  42. <div v-if="isEdit" class="ml-5">
  43. <CtForm ref="CtFormRef" :items="items" style="width: 100%;">
  44. <template v-slot:phone>
  45. <v-btn variant="text" class="ml-2" color="primary">{{ $t('common.change') }}</v-btn>
  46. </template>
  47. </CtForm>
  48. <div class="text-end">
  49. <v-btn class="half-button mr-3" variant="tonal" @click="isEdit = false">{{ $t('common.cancel') }}</v-btn>
  50. <v-btn color="primary" class="half-button" @click="handleSave">{{ $t('common.save') }}</v-btn>
  51. </div>
  52. </div>
  53. <!-- 展示 -->
  54. <div v-else>
  55. <span class="ml-50" style="font-size: 20px; font-weight: 600;color: var(--color-666);">
  56. {{ baseInfo?.name || userInfo?.phone }}
  57. <!-- <span v-if="baseInfo?.foreignName">(英文名:{{ baseInfo?.foreignName }})</span> -->
  58. </span>
  59. <div class="mt-3 d-flex">
  60. <div class="listBox ml-50">
  61. <div>
  62. <span class="mdi mdi-map-marker-outline"></span>
  63. <span>{{ baseInfo?.areaName || $t('common.currentlyUnavailable') }}</span>
  64. </div>
  65. <div>
  66. <span class="mdi mdi-phone-outline"></span>
  67. <span>{{ baseInfo?.phone || userInfo?.phone || $t('common.currentlyUnavailable') }}</span>
  68. </div>
  69. <div>
  70. <span class="mdi mdi-email-outline"></span>
  71. <span>{{ baseInfo?.email || $t('common.currentlyUnavailable') }}</span>
  72. </div>
  73. <div>
  74. <span class="mdi mdi-calendar-blank-outline"></span>
  75. <span>{{ baseInfo?.expTypeText || $t('common.currentlyUnavailable') }}</span>
  76. </div>
  77. <div>
  78. <span class="mdi mdi-school-outline"></span>
  79. <span>{{ baseInfo?.eduTypeText || $t('common.currentlyUnavailable') }}</span>
  80. </div>
  81. <div>
  82. <span class="mdi mdi-tag-outline"></span>
  83. <span>{{ baseInfo?.jobStatusText || $t('common.currentlyUnavailable') }}</span>
  84. </div>
  85. <div>
  86. <span class="mdi mdi-cake-variant-outline"></span>
  87. <span>{{ baseInfo?.birthdayText || $t('common.currentlyUnavailable') }}</span>
  88. </div>
  89. <div>
  90. <span class="mdi mdi-home-map-marker"></span>
  91. <span>{{ baseInfo?.regName || $t('common.currentlyUnavailable') }}</span>
  92. </div>
  93. <div>
  94. <span class="mdi mdi-account-heart"></span>
  95. <span>{{ baseInfo?.maritalText || $t('common.currentlyUnavailable') }}</span>
  96. </div>
  97. <div>
  98. <span>{{ $t('resume.firstWorkTime') }}:</span>
  99. <span>{{ baseInfo?.firstWorkTimeText || $t('common.currentlyUnavailable') }}</span>
  100. </div>
  101. </div>
  102. </div>
  103. <!-- 个人画像 -->
  104. <div class="mt-4 ml-50">
  105. <portrait></portrait>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. <Loading :visible="overlay"></Loading>
  112. <!-- 图片裁剪 -->
  113. <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false, selectPic = ''"></ImgCropper>
  114. </template>
  115. <script setup>
  116. import CtForm from '@/components/CtForm'
  117. import Snackbar from '@/plugins/snackbar'
  118. import { getDict } from '@/hooks/web/useDictionaries'
  119. import { updatePersonAvatar, saveResumeBasicInfo } from '@/api/recruit/personal/resume'
  120. import { useUserStore } from '@/store/user'
  121. import { uploadFile } from '@/api/common'
  122. import { getUserAvatar } from '@/utils/avatar'
  123. import { useI18n } from '@/hooks/web/useI18n'
  124. import portrait from './portrait.vue'
  125. import { checkEmail } from '@/utils/validate'
  126. import { ref } from 'vue'
  127. defineOptions({name: 'resume-components-basicInfo'})
  128. const emit = defineEmits(['complete'])
  129. const { t } = useI18n()
  130. const userStore = useUserStore()
  131. const CtFormRef = ref()
  132. const isEdit = ref(false)
  133. const showIcon = ref(false)
  134. let completeStatus = false
  135. const overlay = ref(false) // 加载中
  136. let baseInfo = ref({})
  137. let userInfo = ref({})
  138. const getBasicInfo = () => {
  139. const key = localStorage.getItem('baseInfo')
  140. if (!key || !Object.keys(key).length) return
  141. baseInfo.value = JSON.parse(key) // 人才信息
  142. userInfo.value = JSON.parse(localStorage.getItem('userInfo'))
  143. if (baseInfo.value && Object.keys(baseInfo.value).length) {
  144. completeStatus = true
  145. emit('complete', { status: completeStatus, id: 'basicInfo' })
  146. }
  147. }
  148. getBasicInfo()
  149. // 选择文件
  150. const fileInput = ref()
  151. const clicked = ref(false)
  152. const openFileInput = () => {
  153. if (clicked.value) return
  154. clicked.value = true
  155. fileInput.value.click()
  156. clicked.value = false
  157. }
  158. // 上传头像
  159. const selectPic = ref('')
  160. const isShowCopper = ref(false)
  161. const accept = ['jpg', 'png', 'jpeg']
  162. const handleUploadFile = async (e) => {
  163. const file = e.target.files[0]
  164. const fileType = file.name.split('.')[1]
  165. if (!accept.includes(fileType)) return Snackbar.warning('请上传图片格式')
  166. const reader = new FileReader()
  167. reader.readAsDataURL(file)
  168. reader.onload = () => {
  169. selectPic.value = String(reader.result)
  170. isShowCopper.value = true
  171. }
  172. }
  173. // 图片裁剪
  174. const handleHideCopper = (data) => {
  175. isShowCopper.value = false
  176. if (data) {
  177. const { file } = data
  178. if (!file) return
  179. const formData = new FormData()
  180. formData.append('file', file)
  181. formData.append('path', 'img')
  182. overlay.value = true
  183. uploadFile(formData).then(async ({data}) => {
  184. if (!data) return
  185. await updatePersonAvatar(data)
  186. setTimeout(async () => {
  187. await userStore.getUserBaseInfos(baseInfo.value.userId)
  188. getBasicInfo()
  189. overlay.value = false
  190. Snackbar.success(t('common.uploadSucMsg'))
  191. }, 1000)
  192. }).catch(err => {
  193. overlay.value = false
  194. })
  195. }
  196. }
  197. const items = ref({
  198. options: [
  199. {
  200. type: 'text',
  201. key: 'name',
  202. value: null,
  203. default: null,
  204. label: '中文名 *',
  205. col: 6,
  206. outlined: true,
  207. rules: [
  208. value => {
  209. if (value) return true
  210. return '请输入您的中文名'
  211. },
  212. value => {
  213. var regex = /^[\u4e00-\u9fa5]+$/
  214. if (regex.test(value)) return true
  215. return '请输入正确的中文名'
  216. }
  217. ]
  218. },
  219. // {
  220. // type: 'text',
  221. // key: 'foreignName',
  222. // value: null,
  223. // label: '英文名',
  224. // col: 6,
  225. // outlined: true,
  226. // clearable: true,
  227. // rules: [
  228. // value => {
  229. // if (!value) return true
  230. // var regex = /^[A-Za-z]+(?:\s[A-Za-z]+)?$/
  231. // if (regex.test(value)) return true
  232. // return '请输入正确的英文名'
  233. // }
  234. // ]
  235. // },
  236. {
  237. type: 'ifRadio',
  238. key: 'sex',
  239. value: '1', // '1' ? '男' : '女'
  240. default: 0,
  241. label: '性别 *',
  242. col: 6,
  243. width: 70,
  244. dictTypeName: 'menduner_sex',
  245. items: [],
  246. },
  247. {
  248. type: 'phoneNumber',
  249. key: 'phone',
  250. value: userInfo?.value?.phone || '',
  251. default: null,
  252. label: '电话号码 *',
  253. col: 6,
  254. outlined: true,
  255. rules: [v => !!v || '请填写联系手机号']
  256. },
  257. {
  258. type: 'datePicker',
  259. mode: 'date',
  260. labelWidth: 110,
  261. key: 'birthday',
  262. value: '2000-01-01',
  263. defaultValue: new Date(2000, 1, 1),
  264. label: '出生日期 *',
  265. disabledFutureDates: true,
  266. col: 6,
  267. format: 'YYYY/MM/DD',
  268. flexStyle: 'mb-7',
  269. outlined: true,
  270. rules: [v => !!v || '请选择出生日期']
  271. },
  272. {
  273. type: 'datePicker',
  274. mode: 'month',
  275. key: 'firstWorkTime',
  276. value: '2000-01',
  277. disabledFutureDates: true,
  278. defaultValue: new Date(2000, 1),
  279. format: 'YYYY/MM',
  280. labelWidth: 110,
  281. flexStyle: 'mb-7',
  282. label: '首次工作时间',
  283. col: 6,
  284. outlined: true
  285. },
  286. {
  287. type: 'text',
  288. key: 'email',
  289. value: null,
  290. default: null,
  291. label: '常用邮箱 *',
  292. col: 6,
  293. outlined: true,
  294. rules: [
  295. value => {
  296. if (value) return true
  297. return '请输入联系邮箱'
  298. },
  299. value => {
  300. if (value && !checkEmail(value)) return '请输入正确的电子邮箱'
  301. return true
  302. }
  303. ]
  304. },
  305. {
  306. type: 'autocomplete',
  307. key: 'expType',
  308. value: null,
  309. default: null,
  310. label: '工作年限 *',
  311. col: 6,
  312. outlined: true,
  313. itemText: 'label',
  314. itemValue: 'value',
  315. dictTypeName: 'menduner_exp_type',
  316. rules: [v => !!v || '请选择工作年限'],
  317. items: []
  318. },
  319. {
  320. type: 'autocomplete',
  321. key: 'eduType',
  322. value: null,
  323. default: null,
  324. label: '最高学历 *',
  325. col: 6,
  326. outlined: true,
  327. itemText: 'label',
  328. itemValue: 'value',
  329. dictTypeName: 'menduner_education_type',
  330. rules: [v => !!v || '请选择最高学历'],
  331. items: []
  332. },
  333. {
  334. type: 'autocomplete',
  335. key: 'jobType',
  336. value: null,
  337. default: null,
  338. label: '求职类型 *',
  339. col: 6,
  340. outlined: true,
  341. itemText: 'label',
  342. itemValue: 'value',
  343. dictTypeName: 'menduner_job_type',
  344. rules: [v => !!v || '请选择求职类型'],
  345. items: []
  346. },
  347. {
  348. type: 'autocomplete',
  349. key: 'jobStatus',
  350. value: null,
  351. default: null,
  352. label: '求职状态 *',
  353. col: 6,
  354. outlined: true,
  355. itemText: 'label',
  356. itemValue: 'value',
  357. dictTypeName: 'menduner_job_seek_status',
  358. rules: [v => !!v || '请选择求职状态'],
  359. items: []
  360. },
  361. {
  362. type: 'autocomplete',
  363. key: 'maritalStatus',
  364. value: null,
  365. default: null,
  366. label: '婚姻状况',
  367. col: 6,
  368. outlined: true,
  369. itemText: 'label',
  370. itemValue: 'value',
  371. dictTypeName: 'menduner_marital_status',
  372. items: []
  373. },
  374. {
  375. type: 'cascade',
  376. key: 'areaId',
  377. value: null,
  378. default: null,
  379. label: '所在城市',
  380. itemText: 'name',
  381. itemValue: 'id',
  382. required: true,
  383. checkStrictly: true,
  384. clearable: false,
  385. col: 6,
  386. items: [],
  387. },
  388. {
  389. type: 'cascade',
  390. key: 'regId',
  391. value: null,
  392. default: null,
  393. label: '户籍地',
  394. itemText: 'name',
  395. itemValue: 'id',
  396. checkStrictly: true,
  397. required: false,
  398. clearable: true,
  399. col: 6,
  400. items: [],
  401. },
  402. ]
  403. })
  404. // 保存-基础信息
  405. const handleSave = async () => {
  406. const { valid } = await CtFormRef.value.formRef.validate()
  407. if (!valid) return
  408. const obj = {}
  409. items.value.options.forEach(e => {
  410. obj[e.key] = e.value
  411. })
  412. if (!obj.sex) return Snackbar.warning('请先选择您的性别')
  413. if (!obj.birthday) return Snackbar.warning('请选择您的出生日期')
  414. await saveResumeBasicInfo(obj)
  415. Snackbar.success(t('common.saveMsg'))
  416. isEdit.value = false
  417. await userStore.getUserBaseInfos(baseInfo.value.userId || null)
  418. getBasicInfo()
  419. }
  420. items.value.options.forEach(async (e, index) => {
  421. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  422. if (e.dictTypeName) {
  423. const { data } = await getDict(e.dictTypeName)
  424. e.items = data
  425. }
  426. const infoExist = baseInfo.value && Object.keys(baseInfo.value).length
  427. if (infoExist && baseInfo.value[e.key]) e.value = baseInfo.value[e.key]
  428. if (e.value === undefined || e.value === null || e.value === '') completeStatus = false
  429. })
  430. getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
  431. data = data?.length && data || []
  432. if (!data?.length) return console.error('areaTreeData获取失败!')
  433. const chinaTreeData = data
  434. if (!chinaTreeData?.length) return console.error('chinaTreeData获取失败!')
  435. const workAreaProvince = items.value.options.find(e => e.key === 'areaId')
  436. const regAreaProvince = items.value.options.find(e => e.key === 'regId')
  437. if (workAreaProvince?.items) workAreaProvince.items = chinaTreeData
  438. if (regAreaProvince?.items) regAreaProvince.items = chinaTreeData
  439. })
  440. </script>
  441. <style lang="scss" scoped>
  442. .jobTypeCardBox {
  443. position: absolute;
  444. top: -22px;
  445. left: 0;
  446. }
  447. .ml-50 {
  448. margin-left: 50px;
  449. }
  450. .avatarsBox {
  451. height: 150px;
  452. width: 120px;
  453. position: relative;
  454. cursor: pointer;
  455. margin: 0 32px;
  456. .camera {
  457. color: #fff;
  458. font-size: 42px;
  459. position: absolute;
  460. top: 50%;
  461. left: 50%;
  462. transform: translate(-50%, -50%);
  463. }
  464. }
  465. .listBox {
  466. display: flex;
  467. flex-wrap: wrap; /* 允许换行 */
  468. width: 100%; /* 设置容器宽度 */
  469. overflow: hidden;
  470. color: var(--color-666);
  471. div {
  472. width: 50%;
  473. margin-bottom: 10px;
  474. span {
  475. height: 32px;
  476. line-height: 32px;
  477. }
  478. .mdi {
  479. font-size: 22px;
  480. margin-right: 8px;
  481. }
  482. }
  483. }
  484. </style>