basicInfo.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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);">{{ 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 || userInfo?.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: '1', // '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. value: '2000-01-01',
  227. label: '出生日期 *',
  228. col: 6,
  229. outlined: true,
  230. rules: [v => !!v || '请选择出生日期']
  231. },
  232. {
  233. type: 'phoneNumber',
  234. key: 'phone',
  235. value: userInfo?.value?.phone || '',
  236. default: null,
  237. label: '电话号码',
  238. col: 6,
  239. outlined: true
  240. },
  241. {
  242. type: 'text',
  243. key: 'email',
  244. value: null,
  245. default: null,
  246. label: '常用邮箱',
  247. col: 6,
  248. outlined: true,
  249. rules: [
  250. value => {
  251. if (value && !checkEmail(value)) return '请输入正确的电子邮箱'
  252. return true
  253. }
  254. ]
  255. },
  256. {
  257. type: 'autocomplete',
  258. key: 'expType',
  259. value: null,
  260. default: null,
  261. label: '工作年限 *',
  262. col: 6,
  263. outlined: true,
  264. itemText: 'label',
  265. itemValue: 'value',
  266. dictTypeName: 'menduner_exp_type',
  267. rules: [v => !!v || '请选择工作年限'],
  268. items: []
  269. },
  270. {
  271. type: 'autocomplete',
  272. key: 'eduType',
  273. value: null,
  274. default: null,
  275. label: '最高学历 *',
  276. col: 6,
  277. outlined: true,
  278. itemText: 'label',
  279. itemValue: 'value',
  280. dictTypeName: 'menduner_education_type',
  281. rules: [v => !!v || '请选择最高学历'],
  282. items: []
  283. },
  284. {
  285. type: 'autocomplete',
  286. key: 'jobType',
  287. value: null,
  288. default: null,
  289. label: '求职类型 *',
  290. col: 6,
  291. outlined: true,
  292. itemText: 'label',
  293. itemValue: 'value',
  294. dictTypeName: 'menduner_job_type',
  295. rules: [v => !!v || '请选择求职类型'],
  296. items: []
  297. },
  298. {
  299. type: 'autocomplete',
  300. key: 'jobStatus',
  301. value: null,
  302. default: null,
  303. label: '求职状态 *',
  304. col: 6,
  305. outlined: true,
  306. itemText: 'label',
  307. itemValue: 'value',
  308. dictTypeName: 'menduner_job_seek_status',
  309. rules: [v => !!v || '请选择求职状态'],
  310. items: []
  311. },
  312. {
  313. type: 'autocomplete',
  314. key: 'maritalStatus',
  315. value: null,
  316. default: null,
  317. label: '婚姻状况',
  318. col: 6,
  319. outlined: true,
  320. itemText: 'label',
  321. itemValue: 'value',
  322. dictTypeName: 'menduner_marital_status',
  323. items: []
  324. },
  325. {
  326. type: 'autocomplete',
  327. key: 'workAreaProvinceId',
  328. value: null,
  329. label: '所在城市:省',
  330. outlined: true,
  331. itemText: 'name',
  332. itemValue: 'id',
  333. returnSelect: true,
  334. noParam: true,
  335. col: 6,
  336. flexStyle: 'mr-3',
  337. items: [],
  338. change: null
  339. },
  340. {
  341. type: 'autocomplete',
  342. key: 'areaId',
  343. value: null,
  344. label: '所在城市:市',
  345. outlined: true,
  346. itemText: 'name',
  347. itemValue: 'id',
  348. col: 6,
  349. items: [],
  350. change: null
  351. },
  352. {
  353. type: 'autocomplete',
  354. key: 'regProvinceId',
  355. value: null,
  356. label: '户籍地:省',
  357. outlined: true,
  358. clearable: true,
  359. itemText: 'name',
  360. itemValue: 'id',
  361. returnSelect: true,
  362. noParam: true,
  363. col: 6,
  364. flexStyle: 'mr-3',
  365. items: [],
  366. change: null
  367. },
  368. {
  369. type: 'autocomplete',
  370. key: 'regId',
  371. value: null,
  372. label: '户籍地:市',
  373. outlined: true,
  374. clearable: true,
  375. itemText: 'name',
  376. itemValue: 'id',
  377. col: 6,
  378. items: [],
  379. change: null
  380. },
  381. {
  382. type: 'datePicker',
  383. dateType: 'month',
  384. key: 'firstWorkTime',
  385. value: '2000-01',
  386. label: '首次工作时间',
  387. col: 6,
  388. outlined: true
  389. }
  390. ]
  391. })
  392. // 保存-基础信息
  393. const handleSave = async () => {
  394. const { valid } = await CtFormRef.value.formRef.validate()
  395. if (!valid) return
  396. const obj = {}
  397. let clearRegProvinceId = false
  398. items.value.options.forEach(e => {
  399. if (e.key === 'regId' && !obj[e.key]) clearRegProvinceId = true
  400. if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  401. else obj[e.key] = e.value
  402. })
  403. if (!obj.sex) return Snackbar.warning('请先选择您的性别')
  404. await saveResumeBasicInfo(obj)
  405. Snackbar.success(t('common.saveMsg'))
  406. isEdit.value = false
  407. await userStore.getUserBaseInfos(baseInfo.value.userId || null)
  408. getBasicInfo()
  409. // 清除户籍地:省
  410. if (clearRegProvinceId) items.value.options.forEach(e => { if (e.key === 'regProvinceId') e.value = null })
  411. }
  412. // 获取字典内容
  413. const getDictData = async (dictTypeName) => {
  414. const item = items.value.options.find(e => e.dictTypeName === dictTypeName)
  415. if (item) {
  416. const { data } = await getDict(dictTypeName)
  417. item.items = data
  418. }
  419. }
  420. const timeCount = {}
  421. const deal = async (id, cityKey, provinceKey) => {
  422. if (!id && id !== 0) return
  423. // 省份回显
  424. const province = items.value.options.find(pv => pv.key === provinceKey)
  425. if (!province?.items.length) { // 字典数据未获取
  426. timeCount[provinceKey] = 0
  427. setTimeout(() => {
  428. timeCount[provinceKey]++
  429. if (timeCount[provinceKey] < 6) deal(id, cityKey, provinceKey)
  430. }, 2000)
  431. return
  432. }
  433. if (province) {
  434. const dealReturnObj = await cityToProvince(id, {}, province.items || [])
  435. const city = items.value.options.find(pv => pv.key === cityKey)
  436. if (city) city.items = dealReturnObj.cityList || []
  437. province.value = dealReturnObj.pid || ''
  438. }
  439. }
  440. items.value.options.forEach((e, index) => {
  441. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  442. if (e.dictTypeName) getDictData(e.dictTypeName) // 查字典set options
  443. const infoExist = baseInfo.value && Object.keys(baseInfo.value).length
  444. if (infoExist && baseInfo.value[e.key]) e.value = baseInfo.value[e.key]
  445. // 日期相关
  446. if (e.type === 'datepicker') e.value = timesTampChange(e.value, 'Y-M-D')
  447. // 所在城市回显
  448. if (infoExist && e.key === 'areaId' && baseInfo.value[e.key]) {
  449. const id = baseInfo.value[e.key]
  450. deal(id, e.key, 'workAreaProvinceId')
  451. }
  452. if (infoExist && e.key === 'regId' && baseInfo.value[e.key]) {
  453. const id = baseInfo.value[e.key]
  454. deal(id, e.key, 'regProvinceId')
  455. }
  456. if (e.value === undefined || e.value === null || e.value === '') completeStatus = false
  457. })
  458. // 完成度展示
  459. const provinceChange = (value, val, obj) => {
  460. console.log(obj, 'area')
  461. let cityKey
  462. if (val?.key === 'workAreaProvinceId') cityKey = 'areaId'
  463. if (val?.key === 'regProvinceId') cityKey = 'regId'
  464. if (!cityKey) return
  465. const item = items.value.options.find(e => e.key === cityKey)
  466. if (!item) return
  467. item.items = obj?.children || []
  468. item.value = null
  469. }
  470. getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
  471. data = data?.length && data || []
  472. if (!data?.length) return console.error('areaTreeData获取失败!')
  473. const chinaTreeData = data
  474. if (!chinaTreeData?.length) return console.error('chinaTreeData获取失败!')
  475. const workAreaProvince = items.value.options.find(e => e.key === 'workAreaProvinceId')
  476. const regAreaProvince = items.value.options.find(e => e.key === 'regProvinceId')
  477. if (workAreaProvince?.items) {
  478. workAreaProvince.items = chinaTreeData
  479. workAreaProvince.change = provinceChange
  480. }
  481. if (regAreaProvince?.items) {
  482. regAreaProvince.items = chinaTreeData
  483. regAreaProvince.change = provinceChange
  484. }
  485. })
  486. </script>
  487. <style lang="scss" scoped>
  488. .jobTypeCardBox {
  489. position: absolute;
  490. top: -22px;
  491. left: 0;
  492. }
  493. .ml-50 {
  494. margin-left: 50px;
  495. }
  496. .avatarsBox {
  497. height: 150px;
  498. width: 120px;
  499. position: relative;
  500. cursor: pointer;
  501. margin: 0 32px;
  502. .camera {
  503. color: #fff;
  504. font-size: 42px;
  505. position: absolute;
  506. top: 50%;
  507. left: 50%;
  508. transform: translate(-50%, -50%);
  509. }
  510. }
  511. .listBox {
  512. display: flex;
  513. flex-wrap: wrap; /* 允许换行 */
  514. width: 100%; /* 设置容器宽度 */
  515. overflow: hidden;
  516. color: var(--color-666);
  517. div {
  518. width: 50%;
  519. margin-bottom: 10px;
  520. span {
  521. height: 32px;
  522. line-height: 32px;
  523. }
  524. .mdi {
  525. font-size: 22px;
  526. margin-right: 8px;
  527. }
  528. }
  529. }
  530. </style>