basicInfo.vue 15 KB

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