basicInfo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 { timesTampChange } from '@/utils/date'
  117. import { updatePersonAvatar, saveResumeBasicInfo } from '@/api/recruit/personal/resume'
  118. import { useUserStore } from '@/store/user'
  119. import { uploadFile } from '@/api/common'
  120. import { getUserAvatar } from '@/utils/avatar'
  121. import { useI18n } from '@/hooks/web/useI18n'
  122. import portrait from './portrait.vue'
  123. import { checkEmail } from '@/utils/validate'
  124. import { ref } from 'vue';
  125. defineOptions({name: 'resume-components-basicInfo'})
  126. const emit = defineEmits(['complete'])
  127. const { t } = useI18n()
  128. const userStore = useUserStore()
  129. const CtFormRef = ref()
  130. const isEdit = ref(false)
  131. const showIcon = ref(false)
  132. let completeStatus = false
  133. const overlay = ref(false) // 加载中
  134. let baseInfo = ref({})
  135. let userInfo = ref({})
  136. const getBasicInfo = () => { // 获取基础信息
  137. const key = localStorage.getItem('baseInfo')
  138. if (!key || !Object.keys(key).length) return
  139. baseInfo.value = JSON.parse(key) // 人才信息
  140. userInfo.value = JSON.parse(localStorage.getItem('userInfo'))
  141. if (baseInfo.value && Object.keys(baseInfo.value).length) {
  142. completeStatus = true
  143. emit('complete', { status: completeStatus, id: 'basicInfo' })
  144. }
  145. }
  146. getBasicInfo()
  147. // 选择文件
  148. const fileInput = ref()
  149. const clicked = ref(false)
  150. const openFileInput = () => {
  151. if (clicked.value) return
  152. clicked.value = true
  153. fileInput.value.click()
  154. clicked.value = false
  155. }
  156. // 上传头像
  157. const selectPic = ref('')
  158. const isShowCopper = ref(false)
  159. const handleUploadFile = async (e) => {
  160. const file = e.target.files[0]
  161. const reader = new FileReader()
  162. reader.readAsDataURL(file)
  163. reader.onload = () => {
  164. selectPic.value = String(reader.result)
  165. isShowCopper.value = true
  166. }
  167. }
  168. // 图片裁剪
  169. const handleHideCopper = (data) => {
  170. isShowCopper.value = false
  171. if (data) {
  172. const { file } = data
  173. if (!file) return
  174. const formData = new FormData()
  175. formData.append('file', file)
  176. overlay.value = true
  177. uploadFile(formData).then(async ({data}) => {
  178. if (!data) return
  179. await updatePersonAvatar(data)
  180. setTimeout(async () => {
  181. await userStore.getUserBaseInfos(baseInfo.value.userId)
  182. getBasicInfo()
  183. overlay.value = false
  184. Snackbar.success(t('common.uploadSucMsg'))
  185. }, 1000)
  186. })
  187. }
  188. }
  189. const items = ref({
  190. options: [
  191. {
  192. type: 'text',
  193. key: 'name',
  194. value: null,
  195. default: null,
  196. label: '中文名 *',
  197. col: 6,
  198. outlined: true,
  199. rules: [
  200. value => {
  201. if (value) return true
  202. return '请输入您的中文名'
  203. },
  204. value => {
  205. var regex = /^[\u4e00-\u9fa5]+$/
  206. if (regex.test(value)) return true
  207. return '请输入正确的中文名'
  208. }
  209. ]
  210. },
  211. {
  212. type: 'ifRadio',
  213. key: 'sex',
  214. value: '1', // '1' ? '男' : '女'
  215. default: 0,
  216. label: '性别 *',
  217. col: 6,
  218. width: 70,
  219. dictTypeName: 'menduner_sex',
  220. items: [],
  221. },
  222. {
  223. type: 'datePicker',
  224. mode: 'date',
  225. labelWidth: 110,
  226. key: 'birthday',
  227. value: '2000-01-01',
  228. defaultValue: new Date(2000, 1, 1),
  229. label: '出生日期 *',
  230. col: 6,
  231. format: 'YYYY/MM/DD',
  232. outlined: true,
  233. rules: [v => !!v || '请选择出生日期']
  234. },
  235. {
  236. type: 'phoneNumber',
  237. key: 'phone',
  238. value: userInfo?.value?.phone || '',
  239. default: null,
  240. label: '电话号码',
  241. col: 6,
  242. outlined: true
  243. },
  244. {
  245. type: 'text',
  246. key: 'email',
  247. value: null,
  248. default: null,
  249. label: '常用邮箱',
  250. col: 6,
  251. outlined: true,
  252. rules: [
  253. value => {
  254. if (value && !checkEmail(value)) return '请输入正确的电子邮箱'
  255. return true
  256. }
  257. ]
  258. },
  259. {
  260. type: 'autocomplete',
  261. key: 'expType',
  262. value: null,
  263. default: null,
  264. label: '工作年限 *',
  265. col: 6,
  266. outlined: true,
  267. itemText: 'label',
  268. itemValue: 'value',
  269. dictTypeName: 'menduner_exp_type',
  270. rules: [v => !!v || '请选择工作年限'],
  271. items: []
  272. },
  273. {
  274. type: 'autocomplete',
  275. key: 'eduType',
  276. value: null,
  277. default: null,
  278. label: '最高学历 *',
  279. col: 6,
  280. outlined: true,
  281. itemText: 'label',
  282. itemValue: 'value',
  283. dictTypeName: 'menduner_education_type',
  284. rules: [v => !!v || '请选择最高学历'],
  285. items: []
  286. },
  287. {
  288. type: 'autocomplete',
  289. key: 'jobType',
  290. value: null,
  291. default: null,
  292. label: '求职类型 *',
  293. col: 6,
  294. outlined: true,
  295. itemText: 'label',
  296. itemValue: 'value',
  297. dictTypeName: 'menduner_job_type',
  298. rules: [v => !!v || '请选择求职类型'],
  299. items: []
  300. },
  301. {
  302. type: 'autocomplete',
  303. key: 'jobStatus',
  304. value: null,
  305. default: null,
  306. label: '求职状态 *',
  307. col: 6,
  308. outlined: true,
  309. itemText: 'label',
  310. itemValue: 'value',
  311. dictTypeName: 'menduner_job_seek_status',
  312. rules: [v => !!v || '请选择求职状态'],
  313. items: []
  314. },
  315. {
  316. type: 'autocomplete',
  317. key: 'maritalStatus',
  318. value: null,
  319. default: null,
  320. label: '婚姻状况',
  321. col: 6,
  322. outlined: true,
  323. itemText: 'label',
  324. itemValue: 'value',
  325. dictTypeName: 'menduner_marital_status',
  326. items: []
  327. },
  328. {
  329. type: 'cascade',
  330. key: 'areaId',
  331. value: null,
  332. default: null,
  333. label: '所在城市',
  334. itemText: 'name',
  335. itemValue: 'id',
  336. required: true,
  337. clearable: false,
  338. col: 6,
  339. items: [],
  340. },
  341. {
  342. type: 'cascade',
  343. key: 'regId',
  344. value: null,
  345. default: null,
  346. label: '户籍地',
  347. itemText: 'name',
  348. itemValue: 'id',
  349. required: false,
  350. clearable: true,
  351. col: 6,
  352. items: [],
  353. },
  354. {
  355. type: 'datePicker',
  356. mode: 'month',
  357. key: 'firstWorkTime',
  358. value: '2000-01',
  359. defaultValue: new Date(2000, 1),
  360. format: 'YYYY/MM',
  361. labelWidth: 130,
  362. label: '首次工作时间',
  363. col: 6,
  364. outlined: true
  365. }
  366. ]
  367. })
  368. // 保存-基础信息
  369. const handleSave = async () => {
  370. const { valid } = await CtFormRef.value.formRef.validate()
  371. if (!valid) return
  372. const obj = {}
  373. items.value.options.forEach(e => {
  374. // if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  375. obj[e.key] = e.value
  376. })
  377. if (!obj.sex) return Snackbar.warning('请先选择您的性别')
  378. if (!obj.birthday) return Snackbar.warning('请选择您的出生日期')
  379. await saveResumeBasicInfo(obj)
  380. Snackbar.success(t('common.saveMsg'))
  381. isEdit.value = false
  382. await userStore.getUserBaseInfos(baseInfo.value.userId || null)
  383. getBasicInfo()
  384. }
  385. // 获取字典内容
  386. const getDictData = async (dictTypeName) => {
  387. const item = items.value.options.find(e => e.dictTypeName === dictTypeName)
  388. if (item) {
  389. const { data } = await getDict(dictTypeName)
  390. item.items = data
  391. }
  392. }
  393. items.value.options.forEach((e, index) => {
  394. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  395. if (e.dictTypeName) getDictData(e.dictTypeName) // 查字典set options
  396. const infoExist = baseInfo.value && Object.keys(baseInfo.value).length
  397. if (infoExist && baseInfo.value[e.key]) e.value = baseInfo.value[e.key]
  398. // 日期相关
  399. // if (e.type === 'datepicker') e.value = timesTampChange(e.value, 'Y-M-D')
  400. if (e.value === undefined || e.value === null || e.value === '') completeStatus = false
  401. })
  402. // 完成度展示
  403. getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
  404. data = data?.length && data || []
  405. if (!data?.length) return console.error('areaTreeData获取失败!')
  406. const chinaTreeData = data
  407. if (!chinaTreeData?.length) return console.error('chinaTreeData获取失败!')
  408. const workAreaProvince = items.value.options.find(e => e.key === 'areaId')
  409. const regAreaProvince = items.value.options.find(e => e.key === 'regId')
  410. if (workAreaProvince?.items) workAreaProvince.items = chinaTreeData
  411. if (regAreaProvince?.items) regAreaProvince.items = chinaTreeData
  412. })
  413. </script>
  414. <style lang="scss" scoped>
  415. .jobTypeCardBox {
  416. position: absolute;
  417. top: -22px;
  418. left: 0;
  419. }
  420. .ml-50 {
  421. margin-left: 50px;
  422. }
  423. .avatarsBox {
  424. height: 150px;
  425. width: 120px;
  426. position: relative;
  427. cursor: pointer;
  428. margin: 0 32px;
  429. .camera {
  430. color: #fff;
  431. font-size: 42px;
  432. position: absolute;
  433. top: 50%;
  434. left: 50%;
  435. transform: translate(-50%, -50%);
  436. }
  437. }
  438. .listBox {
  439. display: flex;
  440. flex-wrap: wrap; /* 允许换行 */
  441. width: 100%; /* 设置容器宽度 */
  442. overflow: hidden;
  443. color: var(--color-666);
  444. div {
  445. width: 50%;
  446. margin-bottom: 10px;
  447. span {
  448. height: 32px;
  449. line-height: 32px;
  450. }
  451. .mdi {
  452. font-size: 22px;
  453. margin-right: 8px;
  454. }
  455. }
  456. }
  457. </style>