basicInfo.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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 }}</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. const getBasicInfo = () => { // 获取基础信息
  129. const key = localStorage.getItem('baseInfo')
  130. if (!key || !Object.keys(key).length) return
  131. baseInfo.value = JSON.parse(key) // 人才信息
  132. }
  133. getBasicInfo()
  134. // 选择文件
  135. const fileInput = ref()
  136. const clicked = ref(false)
  137. const openFileInput = () => {
  138. if (clicked.value) return
  139. clicked.value = true
  140. fileInput.value.click()
  141. clicked.value = false
  142. }
  143. // 上传头像
  144. const selectPic = ref('')
  145. const isShowCopper = ref(false)
  146. const handleUploadFile = async (e) => {
  147. const file = e.target.files[0]
  148. const reader = new FileReader()
  149. reader.readAsDataURL(file)
  150. reader.onload = () => {
  151. selectPic.value = String(reader.result)
  152. isShowCopper.value = true
  153. }
  154. }
  155. // 图片裁剪
  156. const handleHideCopper = (data) => {
  157. isShowCopper.value = false
  158. if (data) {
  159. const { file } = data
  160. if (!file) return
  161. const formData = new FormData()
  162. formData.append('file', file)
  163. overlay.value = true
  164. uploadFile(formData).then(async ({data}) => {
  165. if (!data) return
  166. await updatePersonAvatar(data)
  167. setTimeout(async () => {
  168. await userStore.getUserBaseInfos(baseInfo.value.userId)
  169. getBasicInfo()
  170. overlay.value = false
  171. Snackbar.success(t('common.uploadSucMsg'))
  172. }, 1000)
  173. })
  174. }
  175. }
  176. const items = ref({
  177. options: [
  178. {
  179. type: 'text',
  180. key: 'name',
  181. value: null,
  182. default: null,
  183. label: '中文名 *',
  184. col: 6,
  185. outlined: true,
  186. rules: [v => !!v || '请输入您的中文名']
  187. },
  188. {
  189. type: 'ifRadio',
  190. key: 'sex',
  191. value: '0', // '1' ? '男' : '女'
  192. default: 0,
  193. label: '性别',
  194. col: 6,
  195. width: 70,
  196. dictTypeName: 'system_user_sex',
  197. items: [],
  198. },
  199. {
  200. type: 'datePicker',
  201. key: 'birthday',
  202. // dateType: 'date', // 时间类型 year month date time
  203. value: null,
  204. label: '出生日期 *',
  205. col: 6,
  206. outlined: true,
  207. rules: [v => !!v || '请选择出生日期']
  208. // options: {},
  209. },
  210. {
  211. type: 'phoneNumber',
  212. key: 'phone',
  213. value: null,
  214. default: null,
  215. label: '电话号码',
  216. col: 6,
  217. outlined: true,
  218. rules: [v => !!v || '请填写手机号码']
  219. // disabled: true,
  220. // slotName: 'phone',
  221. },
  222. // {
  223. // slotName: 'areaType',
  224. // key: 'areaId',
  225. // value: null,
  226. // label: '所在城市 *',
  227. // nameKey: 'areaName', // 展示出来id对应的内容
  228. // col: 6,
  229. // flexStyle: 'mr-3',
  230. // rules: [v => !!v || '请选择所在城市']
  231. // },
  232. {
  233. type: 'text',
  234. key: 'email',
  235. value: null,
  236. default: null,
  237. label: '常用邮箱 *',
  238. col: 6,
  239. outlined: true,
  240. rules: [v => !!v || '请输入常用邮箱']
  241. },
  242. {
  243. type: 'autocomplete',
  244. key: 'expType',
  245. value: null,
  246. default: null,
  247. label: '工作经验 *',
  248. col: 6,
  249. outlined: true,
  250. itemText: 'label',
  251. itemValue: 'value',
  252. dictTypeName: 'menduner_exp_type',
  253. rules: [v => !!v || '请选择工作经验'],
  254. items: []
  255. },
  256. {
  257. type: 'autocomplete',
  258. key: 'eduType',
  259. value: null,
  260. default: null,
  261. label: '最高学历 *',
  262. col: 6,
  263. outlined: true,
  264. itemText: 'label',
  265. itemValue: 'value',
  266. dictTypeName: 'menduner_education_type',
  267. rules: [v => !!v || '请选择最高学历'],
  268. items: []
  269. },
  270. {
  271. type: 'autocomplete',
  272. key: 'jobType',
  273. value: null,
  274. default: null,
  275. label: '求职类型 *',
  276. col: 6,
  277. outlined: true,
  278. itemText: 'label',
  279. itemValue: 'value',
  280. dictTypeName: 'menduner_job_type',
  281. rules: [v => !!v || '请选择求职类型'],
  282. items: []
  283. },
  284. {
  285. type: 'autocomplete',
  286. key: 'jobStatus',
  287. value: null,
  288. default: null,
  289. label: '求职状态 *',
  290. col: 6,
  291. outlined: true,
  292. itemText: 'label',
  293. itemValue: 'value',
  294. dictTypeName: 'menduner_job_status',
  295. rules: [v => !!v || '请选择求职状态'],
  296. items: []
  297. },
  298. {
  299. type: 'autocomplete',
  300. key: 'maritalStatus',
  301. value: null,
  302. default: null,
  303. label: '婚姻状况 *',
  304. col: 6,
  305. outlined: true,
  306. itemText: 'label',
  307. itemValue: 'value',
  308. dictTypeName: 'menduner_marital_status',
  309. rules: [v => !!v || '请选择婚姻状况'],
  310. items: []
  311. },
  312. {
  313. type: 'autocomplete',
  314. key: 'workAreaProvinceId',
  315. value: null,
  316. label: '所在城市:省 *',
  317. outlined: true,
  318. itemText: 'name',
  319. itemValue: 'id',
  320. returnSelect: true,
  321. noParam: true,
  322. col: 6,
  323. flexStyle: 'mr-3',
  324. rules: [v => !!v || '请选择所在城市:省'],
  325. items: [],
  326. change: null
  327. },
  328. {
  329. type: 'autocomplete',
  330. key: 'areaId',
  331. value: null,
  332. label: '所在城市:市 *',
  333. outlined: true,
  334. itemText: 'name',
  335. itemValue: 'id',
  336. col: 6,
  337. rules: [v => !!v || '请选择所在城市:市'],
  338. items: [],
  339. change: null
  340. },
  341. {
  342. type: 'datePicker',
  343. dateType: 'month',
  344. key: 'firstWorkTime',
  345. value: null,
  346. label: '首次工作时间 *',
  347. col: 6,
  348. outlined: true,
  349. // clearable: true,
  350. rules: [v => !!v || '请选择首次工作时间']
  351. // options: {},
  352. },
  353. ]
  354. })
  355. // 保存-基础信息
  356. const handleSave = async () => {
  357. const { valid } = await CtFormRef.value.formRef.validate()
  358. if (!valid) return
  359. const obj = {}
  360. items.value.options.forEach(e => {
  361. if (e.type === 'datepicker') obj[e.key] = getTimeStamp(e.value)
  362. else obj[e.key] = e.value
  363. })
  364. await saveResumeBasicInfo(obj)
  365. Snackbar.success(t('common.saveMsg'))
  366. isEdit.value = false
  367. // 获取当前登录账户信息
  368. // if (baseInfo.value.userId) await userStore.getUserBaseInfos(baseInfo.value.userId)
  369. await userStore.getUserBaseInfos(baseInfo.value.userId || null)
  370. getBasicInfo()
  371. }
  372. // 获取字典内容
  373. const getDictData = async (dictTypeName) => {
  374. const item = items.value.options.find(e => e.dictTypeName === dictTypeName)
  375. if (item) {
  376. const { data } = await getDict(dictTypeName)
  377. item.items = data
  378. }
  379. }
  380. let timeCount = 0
  381. let workAreaId = ''
  382. const deal = async () => {
  383. if (workAreaId) { // 省份回显
  384. const province = items.value.options.find(pv => pv.key === 'workAreaProvinceId')
  385. if (!province?.items.length) { // 字典数据未获取
  386. setTimeout(() => {
  387. timeCount++
  388. if (timeCount < 6) deal()
  389. }, 2000)
  390. return
  391. }
  392. if (province) {
  393. const dealReturnObj = await cityToProvince(workAreaId, {}, province.items || [])
  394. const city = items.value.options.find(pv => pv.key === 'areaId')
  395. if (city) city.items = dealReturnObj.cityList || []
  396. province.value = dealReturnObj.pid || ''
  397. }
  398. }
  399. }
  400. items.value.options.forEach((e, index) => {
  401. if ((index + 2) % 2 === 0) e.flexStyle = 'mr-3'
  402. if (e.dictTypeName) getDictData(e.dictTypeName) // 查字典set options
  403. // formItems回显
  404. const infoExist = baseInfo.value && Object.keys(baseInfo.value).length
  405. if (infoExist && baseInfo.value[e.key]) e.value = baseInfo.value[e.key]
  406. // 日期相关
  407. if (e.type === 'datepicker') e.value = timesTampChange(e.value, 'Y-M-D')
  408. // 所在城市回显
  409. // if (infoExist && e.nameKey) e[e.nameKey] = baseInfo.value[e.nameKey]
  410. if (infoExist && e.key === 'areaId' && baseInfo.value[e.key]) {
  411. workAreaId = baseInfo.value[e.key]
  412. deal()
  413. }
  414. })
  415. const provinceChange = (value, val, obj) => {
  416. const item = items.value.options.find(e => e.key === 'areaId')
  417. if (!item) return
  418. item.items = obj.children || []
  419. item.value = null
  420. }
  421. getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
  422. data = data?.length && data || []
  423. if (!data?.length) return console.error('areaTreeData获取失败!')
  424. //
  425. const china = data.find(e => e.id === '1')
  426. const chinaTreeData = china?.children?.length ? china.children : []
  427. //
  428. if (!chinaTreeData?.length) return console.error('chinaTreeData获取失败!')
  429. const item = items.value.options.find(e => e.key === 'workAreaProvinceId')
  430. if (item?.items) {
  431. item.items = chinaTreeData
  432. item.change = provinceChange
  433. }
  434. })
  435. </script>
  436. <style lang="scss" scoped>
  437. .jobTypeCardBox {
  438. position: absolute;
  439. top: -22px;
  440. left: 0;
  441. }
  442. .avatarsBox {
  443. height: 80px;
  444. width: 80px;
  445. position: relative;
  446. cursor: pointer;
  447. margin: 32px;
  448. margin-right: 40px;
  449. .img {
  450. width: 100%;
  451. height: 100%;
  452. }
  453. .mdi {
  454. font-size: 42px;
  455. color: #fff;
  456. }
  457. div {
  458. position: absolute;
  459. top: 50%;
  460. left: 50%;
  461. transform: translate(-50%, -50%);
  462. border-radius: 50%;
  463. }
  464. }
  465. .listBox {
  466. display: flex;
  467. flex-wrap: wrap; /* 允许换行 */
  468. width: 100%; /* 设置容器宽度 */
  469. // height: 68px;
  470. overflow: hidden;
  471. color: var(--color-666);
  472. div {
  473. margin-right: 50px;
  474. span {
  475. height: 32px;
  476. line-height: 32px;
  477. }
  478. .mdi {
  479. font-size: 22px;
  480. margin-right: 8px;
  481. // margin-top: 2px;
  482. }
  483. }
  484. // border: 1px solid red; /* 可视化边界 */
  485. // .jobItems {
  486. // font-size: 14px;
  487. // margin-left: 12px;
  488. // cursor: pointer;
  489. // color: var(--color-666);
  490. // font-family: 微软雅黑;
  491. // }
  492. }
  493. </style>