basicInfo.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <template>
  2. <div class="resume-box mb-3 elevation-2">
  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);">{{ baseInfo?.name || userInfo.phone }}</span>
  56. <div class="mt-3 d-flex">
  57. <div class="listBox ml-50">
  58. <div>
  59. <span class="mdi mdi-map-marker-outline"></span>
  60. <span>{{ baseInfo?.areaName || $t('common.currentlyUnavailable') }}</span>
  61. </div>
  62. <div>
  63. <span class="mdi mdi-phone-outline"></span>
  64. <span>{{ baseInfo?.phone || $t('common.currentlyUnavailable') }}</span>
  65. </div>
  66. <div>
  67. <span class="mdi mdi-email-outline"></span>
  68. <span>{{ baseInfo?.email || $t('common.currentlyUnavailable') }}</span>
  69. </div>
  70. <div>
  71. <span class="mdi mdi-calendar-blank-outline"></span>
  72. <span>{{ baseInfo?.expTypeText || $t('common.currentlyUnavailable') }}</span>
  73. </div>
  74. <div>
  75. <span class="mdi mdi-school-outline"></span>
  76. <span>{{ baseInfo?.eduTypeText || $t('common.currentlyUnavailable') }}</span>
  77. </div>
  78. <div>
  79. <span class="mdi mdi-tag-outline"></span>
  80. <span>{{ baseInfo?.jobStatusText || $t('common.currentlyUnavailable') }}</span>
  81. </div>
  82. <div>
  83. <span class="mdi mdi-cake-variant-outline"></span>
  84. <span>{{ baseInfo?.birthdayText || $t('common.currentlyUnavailable') }}</span>
  85. </div>
  86. <div>
  87. <span class="mdi mdi-home-map-marker"></span>
  88. <span>{{ baseInfo?.regName || $t('common.currentlyUnavailable') }}</span>
  89. </div>
  90. <div>
  91. <span class="mdi mdi-account-heart"></span>
  92. <span>{{ baseInfo?.maritalText || $t('common.currentlyUnavailable') }}</span>
  93. </div>
  94. <div>
  95. <span>{{ $t('resume.firstWorkTime') }}:</span>
  96. <span>{{ baseInfo?.firstWorkTimeText || $t('common.currentlyUnavailable') }}</span>
  97. </div>
  98. </div>
  99. </div>
  100. <!-- 个人画像 -->
  101. <div class="mt-4 ml-50">
  102. <portrait></portrait>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <Loading :visible="overlay"></Loading>
  109. <!-- 图片裁剪 -->
  110. <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false, selectPic = ''"></ImgCropper>
  111. </template>
  112. <script setup>
  113. import CtForm from '@/components/CtForm'
  114. import Snackbar from '@/plugins/snackbar'
  115. import { getDict } from '@/hooks/web/useDictionaries'
  116. import { cityToProvince } from '@/utils/areaDeal'
  117. import { getTimeStamp, timesTampChange } from '@/utils/date'
  118. import { updatePersonAvatar, saveResumeBasicInfo } from '@/api/recruit/personal/resume'
  119. import { useUserStore } from '@/store/user'
  120. import { uploadFile } from '@/api/common'
  121. import { getUserAvatar } from '@/utils/avatar'
  122. import { useI18n } from '@/hooks/web/useI18n'
  123. import portrait from './portrait.vue'
  124. import { checkEmail } from '@/utils/validate'
  125. import { ref } from 'vue';
  126. defineOptions({name: 'resume-components-basicInfo'})
  127. const emit = defineEmits(['complete'])
  128. const { t } = useI18n()
  129. const userStore = useUserStore()
  130. const CtFormRef = ref()
  131. const isEdit = ref(false)
  132. const showIcon = ref(false)
  133. let completeStatus = false
  134. const overlay = ref(false) // 加载中
  135. let baseInfo = ref({})
  136. let userInfo = ref({})
  137. const getBasicInfo = () => { // 获取基础信息
  138. const key = localStorage.getItem('baseInfo')
  139. if (!key || !Object.keys(key).length) return
  140. baseInfo.value = JSON.parse(key) // 人才信息
  141. userInfo.value = JSON.parse(localStorage.getItem('userInfo'))
  142. if (baseInfo.value && Object.keys(baseInfo.value).length) {
  143. completeStatus = true
  144. emit('complete', { status: completeStatus, id: 'basicInfo' })
  145. }
  146. }
  147. getBasicInfo()
  148. // 选择文件
  149. const fileInput = ref()
  150. const clicked = ref(false)
  151. const openFileInput = () => {
  152. if (clicked.value) return
  153. clicked.value = true
  154. fileInput.value.click()
  155. clicked.value = false
  156. }
  157. // 上传头像
  158. const selectPic = ref('')
  159. const isShowCopper = ref(false)
  160. const handleUploadFile = async (e) => {
  161. const file = e.target.files[0]
  162. const reader = new FileReader()
  163. reader.readAsDataURL(file)
  164. reader.onload = () => {
  165. selectPic.value = String(reader.result)
  166. isShowCopper.value = true
  167. }
  168. }
  169. // 图片裁剪
  170. const handleHideCopper = (data) => {
  171. isShowCopper.value = false
  172. if (data) {
  173. const { file } = data
  174. if (!file) return
  175. const formData = new FormData()
  176. formData.append('file', file)
  177. overlay.value = true
  178. uploadFile(formData).then(async ({data}) => {
  179. if (!data) return
  180. await updatePersonAvatar(data)
  181. setTimeout(async () => {
  182. await userStore.getUserBaseInfos(baseInfo.value.userId)
  183. getBasicInfo()
  184. overlay.value = false
  185. Snackbar.success(t('common.uploadSucMsg'))
  186. }, 1000)
  187. })
  188. }
  189. }
  190. const items = ref({
  191. options: [
  192. {
  193. type: 'text',
  194. key: 'name',
  195. value: null,
  196. default: null,
  197. label: '中文名 *',
  198. col: 6,
  199. outlined: true,
  200. rules: [
  201. value => {
  202. if (value) return true
  203. return '请输入您的中文名'
  204. },
  205. value => {
  206. var regex = /^[\u4e00-\u9fa5]+$/
  207. if (regex.test(value)) return true
  208. return '请输入正确的中文名'
  209. }
  210. ]
  211. },
  212. {
  213. type: 'ifRadio',
  214. key: 'sex',
  215. value: '0', // '1' ? '男' : '女'
  216. default: 0,
  217. label: '性别',
  218. col: 6,
  219. width: 70,
  220. dictTypeName: 'menduner_sex',
  221. items: [],
  222. },
  223. {
  224. type: 'datePicker',
  225. key: 'birthday',
  226. // dateType: 'date', // 时间类型 year month date time
  227. value: null,
  228. label: '出生日期 *',
  229. col: 6,
  230. outlined: true,
  231. rules: [v => !!v || '请选择出生日期']
  232. // options: {},
  233. },
  234. {
  235. type: 'phoneNumber',
  236. key: 'phone',
  237. value: null,
  238. default: null,
  239. label: '电话号码',
  240. col: 6,
  241. outlined: true,
  242. rules: [v => !!v || '请填写手机号码']
  243. // disabled: true,
  244. // slotName: 'phone',
  245. },
  246. {
  247. type: 'text',
  248. key: 'email',
  249. value: null,
  250. default: null,
  251. label: '常用邮箱 *',
  252. col: 6,
  253. outlined: true,
  254. rules: [
  255. value => {
  256. if (value) return true
  257. return '请输入常用邮箱'
  258. },
  259. value => {
  260. if (checkEmail(value)) return true
  261. return '请输入正确的电子邮箱'
  262. }
  263. ]
  264. },
  265. {
  266. type: 'autocomplete',
  267. key: 'expType',
  268. value: null,
  269. default: null,
  270. label: '工作年限 *',
  271. col: 6,
  272. outlined: true,
  273. itemText: 'label',
  274. itemValue: 'value',
  275. dictTypeName: 'menduner_exp_type',
  276. rules: [v => !!v || '请选择工作年限'],
  277. items: []
  278. },
  279. {
  280. type: 'autocomplete',
  281. key: 'eduType',
  282. value: null,
  283. default: null,
  284. label: '最高学历 *',
  285. col: 6,
  286. outlined: true,
  287. itemText: 'label',
  288. itemValue: 'value',
  289. dictTypeName: 'menduner_education_type',
  290. rules: [v => !!v || '请选择最高学历'],
  291. items: []
  292. },
  293. {
  294. type: 'autocomplete',
  295. key: 'jobType',
  296. value: null,
  297. default: null,
  298. label: '求职类型 *',
  299. col: 6,
  300. outlined: true,
  301. itemText: 'label',
  302. itemValue: 'value',
  303. dictTypeName: 'menduner_job_type',
  304. rules: [v => !!v || '请选择求职类型'],
  305. items: []
  306. },
  307. {
  308. type: 'autocomplete',
  309. key: 'jobStatus',
  310. value: null,
  311. default: null,
  312. label: '求职状态 *',
  313. col: 6,
  314. outlined: true,
  315. itemText: 'label',
  316. itemValue: 'value',
  317. dictTypeName: 'menduner_job_status',
  318. rules: [v => !!v || '请选择求职状态'],
  319. items: []
  320. },
  321. {
  322. type: 'autocomplete',
  323. key: 'maritalStatus',
  324. value: null,
  325. default: null,
  326. label: '婚姻状况 *',
  327. col: 6,
  328. outlined: true,
  329. itemText: 'label',
  330. itemValue: 'value',
  331. dictTypeName: 'menduner_marital_status',
  332. rules: [v => !!v || '请选择婚姻状况'],
  333. items: []
  334. },
  335. {
  336. type: 'autocomplete',
  337. key: 'workAreaProvinceId',
  338. value: null,
  339. label: '所在城市:省 *',
  340. outlined: true,
  341. itemText: 'name',
  342. itemValue: 'id',
  343. returnSelect: true,
  344. noParam: true,
  345. col: 6,
  346. flexStyle: 'mr-3',
  347. rules: [v => !!v || '请选择所在城市:省'],
  348. items: [],
  349. change: null
  350. },
  351. {
  352. type: 'autocomplete',
  353. key: 'areaId',
  354. value: null,
  355. label: '所在城市:市 *',
  356. outlined: true,
  357. itemText: 'name',
  358. itemValue: 'id',
  359. col: 6,
  360. rules: [v => !!v || '请选择所在城市:市'],
  361. items: [],
  362. change: null
  363. },
  364. {
  365. type: 'autocomplete',
  366. key: 'regProvinceId',
  367. value: null,
  368. label: '户籍地:省',
  369. outlined: true,
  370. clearable: true,
  371. itemText: 'name',
  372. itemValue: 'id',
  373. returnSelect: true,
  374. noParam: true,
  375. col: 6,
  376. flexStyle: 'mr-3',
  377. items: [],
  378. change: null
  379. },
  380. {
  381. type: 'autocomplete',
  382. key: 'regId',
  383. value: null,
  384. label: '户籍地:市',
  385. outlined: true,
  386. clearable: true,
  387. itemText: 'name',
  388. itemValue: 'id',
  389. col: 6,
  390. items: [],
  391. change: null
  392. },
  393. {
  394. type: 'datePicker',
  395. dateType: 'month',
  396. key: 'firstWorkTime',
  397. value: null,
  398. label: '首次工作时间 *',
  399. col: 6,
  400. outlined: true,
  401. // clearable: true,
  402. rules: [v => !!v || '请选择首次工作时间']
  403. // options: {},
  404. },
  405. ]
  406. })
  407. // 保存-基础信息
  408. const handleSave = async () => {
  409. const { valid } = await CtFormRef.value.formRef.validate()
  410. if (!valid) return
  411. const obj = {}
  412. let clearRegProvinceId = false
  413. items.value.options.forEach(e => {
  414. if (e.key === 'regId' && !obj[e.key]) clearRegProvinceId = true
  415. if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  416. else obj[e.key] = e.value
  417. })
  418. await saveResumeBasicInfo(obj)
  419. Snackbar.success(t('common.saveMsg'))
  420. isEdit.value = false
  421. await userStore.getUserBaseInfos(baseInfo.value.userId || null)
  422. getBasicInfo()
  423. // 清除户籍地:省
  424. if (clearRegProvinceId) items.value.options.forEach(e => { if (e.key === 'regProvinceId') e.value = null })
  425. }
  426. // 获取字典内容
  427. const getDictData = async (dictTypeName) => {
  428. const item = items.value.options.find(e => e.dictTypeName === dictTypeName)
  429. if (item) {
  430. const { data } = await getDict(dictTypeName)
  431. item.items = data
  432. }
  433. }
  434. const timeCount = {}
  435. const deal = async (id, cityKey, provinceKey) => {
  436. if (!id && id !== 0) return
  437. // 省份回显
  438. const province = items.value.options.find(pv => pv.key === provinceKey)
  439. if (!province?.items.length) { // 字典数据未获取
  440. timeCount[provinceKey] = 0
  441. setTimeout(() => {
  442. timeCount[provinceKey]++
  443. if (timeCount[provinceKey] < 6) deal(id, cityKey, provinceKey)
  444. }, 2000)
  445. return
  446. }
  447. if (province) {
  448. const dealReturnObj = await cityToProvince(id, {}, province.items || [])
  449. const city = items.value.options.find(pv => pv.key === cityKey)
  450. if (city) city.items = dealReturnObj.cityList || []
  451. province.value = dealReturnObj.pid || ''
  452. }
  453. }
  454. items.value.options.forEach((e, index) => {
  455. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  456. if (e.dictTypeName) getDictData(e.dictTypeName) // 查字典set options
  457. const infoExist = baseInfo.value && Object.keys(baseInfo.value).length
  458. if (infoExist && baseInfo.value[e.key]) e.value = baseInfo.value[e.key]
  459. // 日期相关
  460. if (e.type === 'datepicker') e.value = timesTampChange(e.value, 'Y-M-D')
  461. // 所在城市回显
  462. if (infoExist && e.key === 'areaId' && baseInfo.value[e.key]) {
  463. const id = baseInfo.value[e.key]
  464. deal(id, e.key, 'workAreaProvinceId')
  465. }
  466. if (infoExist && e.key === 'regId' && baseInfo.value[e.key]) {
  467. const id = baseInfo.value[e.key]
  468. deal(id, e.key, 'regProvinceId')
  469. }
  470. if (e.value === undefined || e.value === null || e.value === '') completeStatus = false
  471. })
  472. // 完成度展示
  473. const provinceChange = (value, val, obj) => {
  474. let cityKey
  475. if (val?.key === 'workAreaProvinceId') cityKey = 'areaId'
  476. if (val?.key === 'regProvinceId') cityKey = 'regId'
  477. if (!cityKey) return
  478. const item = items.value.options.find(e => e.key === cityKey)
  479. if (!item) return
  480. item.items = obj?.children || []
  481. item.value = null
  482. }
  483. getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
  484. data = data?.length && data || []
  485. if (!data?.length) return console.error('areaTreeData获取失败!')
  486. const chinaTreeData = data
  487. if (!chinaTreeData?.length) return console.error('chinaTreeData获取失败!')
  488. const workAreaProvince = items.value.options.find(e => e.key === 'workAreaProvinceId')
  489. const regAreaProvince = items.value.options.find(e => e.key === 'regProvinceId')
  490. if (workAreaProvince?.items) {
  491. workAreaProvince.items = chinaTreeData
  492. workAreaProvince.change = provinceChange
  493. }
  494. if (regAreaProvince?.items) {
  495. regAreaProvince.items = chinaTreeData
  496. regAreaProvince.change = provinceChange
  497. }
  498. })
  499. </script>
  500. <style lang="scss" scoped>
  501. .jobTypeCardBox {
  502. position: absolute;
  503. top: -22px;
  504. left: 0;
  505. }
  506. .ml-50 {
  507. margin-left: 50px;
  508. }
  509. .avatarsBox {
  510. height: 150px;
  511. width: 120px;
  512. position: relative;
  513. cursor: pointer;
  514. margin: 0 32px;
  515. .camera {
  516. color: #fff;
  517. font-size: 42px;
  518. position: absolute;
  519. top: 50%;
  520. left: 50%;
  521. transform: translate(-50%, -50%);
  522. }
  523. }
  524. .listBox {
  525. display: flex;
  526. flex-wrap: wrap; /* 允许换行 */
  527. width: 100%; /* 设置容器宽度 */
  528. overflow: hidden;
  529. color: var(--color-666);
  530. div {
  531. width: 50%;
  532. margin-bottom: 10px;
  533. span {
  534. height: 32px;
  535. line-height: 32px;
  536. }
  537. .mdi {
  538. font-size: 22px;
  539. margin-right: 8px;
  540. }
  541. }
  542. }
  543. </style>