infoForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <div style="width: 100%;">
  3. <CtForm ref="formPageRef" :items="items">
  4. <!-- 头像 -->
  5. <template #avatar="{ item }">
  6. <!-- <div class="d-flex flex-column">
  7. <div class="d-flex align-center">
  8. </div>
  9. </div> -->
  10. <div style="color: #7a7a7a; min-width: 52px;">头像:</div>
  11. <div class="avatarsBox" @mouseover="showIcon = true" @mouseleave="showIcon = false">
  12. <v-avatar class="elevation-5" size=80 :image="getUserAvatar(item.value, male)"></v-avatar>
  13. <div v-show="showIcon" @click="openFileInput" v-bind="$attrs" class="mdi mdi-camera-outline">
  14. <input
  15. type="file"
  16. ref="fileInput"
  17. accept="image/png, image/jpg, image/jpeg"
  18. style="display: none;"
  19. @change="handleUploadFile"
  20. />
  21. </div>
  22. </div>
  23. <div style="font-size: 14px; color: var(--color-999);">只支持JPG、JPEG、PNG类型的图片,大小不超过20M</div>
  24. </template>
  25. <template #analysis>
  26. <div style="text-align: right; width: 100%;">
  27. <v-btn variant="text" color="primary" :loading="analyzeLoading" @click="handleImportAttachment">导入简历解析</v-btn>
  28. </div>
  29. </template>
  30. </CtForm>
  31. </div>
  32. <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false"></ImgCropper>
  33. <!-- 选择本地简历 -->
  34. <CtDialog
  35. :visible="openUploadDialog"
  36. :widthType="2"
  37. titleClass="text-h6"
  38. @close="openUploadDialog = false"
  39. title="附件简历上传"
  40. @submit="uploadFileSubmit"
  41. >
  42. <uploadForm ref="uploadFormRef"></uploadForm>
  43. <div class="color-warning" style="font-size: 14px;">提示:上传成功后将自动解析,导入解析简历尝试不得超过5次,请确认好简历后上传!</div>
  44. </CtDialog>
  45. <Loading :visible="analyzeLoading"></Loading>
  46. </template>
  47. <script setup>
  48. import { getDict } from '@/hooks/web/useDictionaries'
  49. defineOptions({name: 'dialogExtend-InfoForm'})
  50. import { reactive, ref } from 'vue'
  51. import { checkEmail } from '@/utils/validate'
  52. import {
  53. resumeParser2,
  54. getPersonResumeCv,
  55. enterpriseSearchByName,
  56. savePersonResumeCv
  57. } from '@/api/recruit/personal/resume'
  58. import { getUserAvatar } from '@/utils/avatar'
  59. import { uploadFile } from '@/api/common'
  60. import Snackbar from '@/plugins/snackbar'
  61. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  62. import uploadForm from './upload.vue'
  63. // import { analyzeTestData } from './analyzeTestData.js'
  64. const props = defineProps({
  65. option: {
  66. type: Object,
  67. default: () => {}
  68. }
  69. })
  70. const setInfo = ref(props.option?.setInfo ? props.option.setInfo : {})
  71. const formPageRef = ref()
  72. let query = reactive({})
  73. // 企业名称下拉列表
  74. let enterpriseName = null
  75. // const enterpriseNameInput = ref('')
  76. const getEnterpriseData = async (name) => {
  77. const item = items.value.options.find(e => e.key === 'enterpriseId')
  78. if (!item) return
  79. if (item.items?.length && (enterpriseName === name)) return // 防抖
  80. // item[item.itemTextName] =
  81. enterpriseName = name
  82. if (name === null || name === '') { item.items = [] }
  83. else {
  84. const data = await enterpriseSearchByName({ name })
  85. item.items = data
  86. }
  87. }
  88. // 图片裁剪
  89. const selectPic = ref('')
  90. const isShowCopper = ref(false)
  91. const male = ref('1')
  92. const showIcon = ref(false)
  93. let positionName = null
  94. const items = ref({
  95. options: [
  96. {
  97. slotName: 'avatar',
  98. key: 'avatar',
  99. value: '',
  100. flexStyle: 'align-center mb-3'
  101. },
  102. {
  103. slotName: 'analysis',
  104. },
  105. {
  106. type: 'text',
  107. key: 'name',
  108. value: '',
  109. default: null,
  110. label: '姓名 *',
  111. outlined: true,
  112. rules: [
  113. value => {
  114. if (value) return true
  115. return '请输入您的中文名'
  116. },
  117. value => {
  118. var regex = /^[\u4e00-\u9fa5]+$/
  119. if (regex.test(value)) return true
  120. return '请输入正确的中文名'
  121. }
  122. ]
  123. },
  124. {
  125. type: 'autocomplete',
  126. key: 'sex',
  127. value: '1', // '1' ? '男' : '女'
  128. default: '1',
  129. label: '性别 *',
  130. outlined: true,
  131. dictTypeName: 'menduner_sex',
  132. rules: [v => !!v || '请选择性别'],
  133. items: [],
  134. change: val => male.value = val
  135. },
  136. {
  137. type: 'phoneNumber',
  138. key: 'phone',
  139. value: '',
  140. clearable: true,
  141. label: '联系手机号 *',
  142. rules: [v => !!v || '请填写联系手机号']
  143. },
  144. {
  145. type: 'text',
  146. key: 'email',
  147. value: null,
  148. default: null,
  149. label: '常用邮箱 *',
  150. outlined: true,
  151. rules: [
  152. value => {
  153. if (value) return true
  154. return '请输入联系邮箱'
  155. },
  156. value => {
  157. if (value && !checkEmail(value)) return '请输入正确的电子邮箱'
  158. return true
  159. }
  160. ]
  161. },
  162. {
  163. type: 'datePicker',
  164. mode: 'date',
  165. labelWidth: 80,
  166. key: 'birthday',
  167. value: '1990-01-01',
  168. defaultValue: new Date(1990, 1, 1),
  169. label: '出生日期 *',
  170. disabledFutureDates: true,
  171. format: 'YYYY/MM/DD',
  172. flexStyle: 'mb-7',
  173. outlined: true,
  174. rules: [v => !!v || '请选择出生日期']
  175. },
  176. {
  177. type: 'combobox',
  178. key: 'enterpriseId',
  179. value: null,
  180. default: null,
  181. label: '任职企业名称 *(可填暂无)',
  182. outlined: true,
  183. clearable: true,
  184. canBeInputted: true, //
  185. itemTextName: 'enterpriseName',
  186. itemText: 'value',
  187. itemValue: 'key',
  188. rules: [v => !!v || '请填写任职企业名称(可填暂无)'],
  189. search: getEnterpriseData,
  190. items: []
  191. },
  192. {
  193. type: 'combobox',
  194. key: 'positionId',
  195. value: null,
  196. default: null,
  197. label: '任职职位名称 *(可填暂无)',
  198. outlined: true,
  199. clearable: true,
  200. canBeInputted: true, //
  201. itemTextName: 'positionName',
  202. itemText: 'nameCn',
  203. itemValue: 'id',
  204. dictTypeName: 'positionSecondData',
  205. rules: [v => !!v || '请填写任职职位名称(可填暂无)'],
  206. search: val => positionName = val,
  207. items: []
  208. },
  209. {
  210. type: 'autocomplete',
  211. key: 'interestedPositionList',
  212. value: null,
  213. default: null,
  214. label: '意向职位 *',
  215. outlined: true,
  216. itemText: 'nameCn',
  217. itemValue: 'id',
  218. multiple: true,
  219. dictTypeName: 'positionSecondData',
  220. rules: [v => !!v || '请选择意向职位'],
  221. items: []
  222. },
  223. {
  224. type: 'autocomplete',
  225. key: 'jobStatus',
  226. value: '',
  227. default: null,
  228. label: '求职状态 *',
  229. outlined: true,
  230. itemText: 'label',
  231. itemValue: 'value',
  232. dictTypeName: 'menduner_job_seek_status',
  233. rules: [v => !!v || '请选择求职状态'],
  234. items: []
  235. },
  236. {
  237. type: 'autocomplete',
  238. key: 'expType',
  239. value: '',
  240. default: null,
  241. label: '工作经验 *',
  242. outlined: true,
  243. itemText: 'label',
  244. itemValue: 'value',
  245. dictTypeName: 'menduner_exp_type',
  246. rules: [v => !!v || '请选择工作经验'],
  247. items: []
  248. },
  249. {
  250. type: 'autocomplete',
  251. key: 'eduType',
  252. value: '',
  253. default: null,
  254. label: '最高学历 *',
  255. outlined: true,
  256. itemText: 'label',
  257. itemValue: 'value',
  258. dictTypeName: 'menduner_education_type',
  259. rules: [v => !!v || '请选择最高学历'],
  260. items: []
  261. },
  262. // label: '学制类型 *', menduner_education_system_type
  263. ]
  264. })
  265. // 选择文件
  266. const fileInput = ref()
  267. const clicked = ref(false)
  268. const openFileInput = () => {
  269. if (clicked.value) return
  270. clicked.value = true
  271. fileInput.value.click()
  272. clicked.value = false
  273. }
  274. // 上传头像
  275. const accept = ['jpg', 'png', 'jpeg']
  276. const handleUploadFile = async (e) => {
  277. console.log('handleUploadFile:', e)
  278. const file = e.target.files[0]
  279. if (!file) return
  280. const arr = file.name.split('.')
  281. const fileType = arr?.length ? arr[arr.length-1] : ''
  282. if (!accept.includes(fileType)) return Snackbar.warning('请上传图片格式文件')
  283. const size = file.size
  284. if (size / (1024*1024) > 20) {
  285. Snackbar.warning(t('common.fileSizeExceed'))
  286. return
  287. }
  288. const reader = new FileReader()
  289. reader.readAsDataURL(file)
  290. reader.onload = () => {
  291. selectPic.value = String(reader.result)
  292. isShowCopper.value = true
  293. }
  294. }
  295. const handleHideCopper = (data) => {
  296. isShowCopper.value = false
  297. if (data) {
  298. const { file } = data
  299. if (!file) return
  300. const formData = new FormData()
  301. formData.append('file', file)
  302. formData.append('path', 'img')
  303. uploadFile(formData).then(async ({ data }) => {
  304. if (!data) return
  305. items.value.options.find(e => e.key === 'avatar').value = data
  306. })
  307. }
  308. }
  309. // 获取字典内容
  310. const getDictData = async (dictTypeName, key) => {
  311. const item = items.value.options.find(e => e.key === key)
  312. if (item) {
  313. const apiType = dictTypeName === 'positionSecondData' ? 'positionSecondData' : 'dict'
  314. const { data } = await getDict(dictTypeName, apiType === 'dict' ? null : {}, apiType)
  315. item.items = data
  316. // console.log(dictTypeName, '字典内容', data)
  317. }
  318. }
  319. const userInfo = ref(localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : {})
  320. const baseInfo = ref(localStorage.getItem('baseInfo') ? JSON.parse(localStorage.getItem('baseInfo')) : {})
  321. items.value.options.forEach((e) => {
  322. if (e.dictTypeName) getDictData(e.dictTypeName, e.key) // 查字典set options
  323. if (baseInfo.value && baseInfo.value[e.key]) e.value = baseInfo.value[e.key] // 人才信息回显
  324. if (userInfo.value && userInfo.value[e.key]) e.value = userInfo.value[e.key] // 人才信息回显
  325. if (e.key === 'sex' && e.value === '0') e.value = e.default
  326. if (setInfo.value[e.key]) e.value = setInfo.value[e.key]
  327. })
  328. // const getName = (obj, key) => {
  329. // const item = items.value.options.find(e => e.key === key)
  330. // if (!item && !item.value) return
  331. // const select = item.items.find(e => item.value === e[item.itemValue || 'value'])
  332. // if (select) {
  333. // obj[item.itemTextName] = select[item.itemText || 'label']
  334. // }
  335. // }
  336. const dealQuery = () => {
  337. query.positionName = positionName || null
  338. if (query.positionId === positionName) delete query.positionId // 有选中id传id和name,否者只传name
  339. query.enterpriseName = enterpriseName || null
  340. if (query.enterpriseId === enterpriseName) delete query.enterpriseId // 有选中id传id和name,否者只传name
  341. //
  342. if (query.interestedPositionList?.length) {
  343. query.interestedList = query.interestedPositionList.map(e => { return {positionId: e} })
  344. }
  345. query.workExpList = [{
  346. enterpriseId: query.enterpriseId,
  347. enterpriseName: query.enterpriseName || null,
  348. positionId: query.positionId,
  349. positionName: query.positionName || null,
  350. }]
  351. }
  352. const getQuery = async () => {
  353. const { valid } = await formPageRef.value.formRef.validate()
  354. if (!valid) return false
  355. const obj = {}
  356. items.value.options.forEach(e => {
  357. if (Object.prototype.hasOwnProperty.call(e, 'data')) return obj[e.key] = e.data
  358. obj[e.key] = e.value === '' ? null : e.value
  359. })
  360. if (!obj.avatar) obj.avatar = getUserAvatar(null, obj.sex)
  361. query = Object.assign(query, obj)
  362. dealQuery()
  363. return query
  364. }
  365. // 填充
  366. const handleAnalyzeFill = (data) => {
  367. const person = data?.person || null
  368. if (!person && !Object.keys(person).length) return Snackbar.warning('无可用内容!')
  369. if (person.enterpriseName) getEnterpriseData(person.enterpriseName)
  370. items.value.options.forEach((e) => {
  371. if (person[e.key]) e.value = person[e.key]
  372. })
  373. }
  374. const analyzeLoading = ref(false)
  375. const uploadFormRef = ref()
  376. const openUploadDialog = ref(false)
  377. // 上传附件-提交
  378. const uploadFileSubmit = async () => {
  379. const obj = await uploadFormRef.value.getQuery()
  380. if (!obj?.url || !obj?.title) return Snackbar.warning(t('resume.selectResumeToSubmit'))
  381. const query = { title: obj.title, url: obj.url }
  382. analyzeLoading.value = true
  383. await savePersonResumeCv(query)
  384. openUploadDialog.value = false
  385. const data = await resumeParser2({ fileUrl: obj.url })
  386. // const data = JSON.parse(JSON.stringify(analyzeTestData))
  387. console.log('resumeParser2:', data)
  388. handleAnalyzeFill(data)
  389. analyzeLoading.value = false
  390. }
  391. const handleImportAttachment = async () => {
  392. const data = await getPersonResumeCv() // 获取附件
  393. if (data?.length >= 5) return Snackbar.warning('导入解析简历尝试不得超过5次!')
  394. openUploadDialog.value = true
  395. }
  396. defineExpose({
  397. getQuery
  398. })
  399. </script>
  400. <style scoped lang="scss">
  401. .avatarsBox {
  402. height: 80px;
  403. width: 80px;
  404. position: relative;
  405. cursor: pointer;
  406. // margin: 32px;
  407. // margin-right: 40px;
  408. margin: 0 40px 0 32px;
  409. .img {
  410. width: 100%;
  411. height: 100%;
  412. }
  413. .mdi {
  414. font-size: 42px;
  415. color: #fff;
  416. }
  417. div {
  418. position: absolute;
  419. top: 50%;
  420. left: 50%;
  421. transform: translate(-50%, -50%);
  422. border-radius: 50%;
  423. }
  424. }
  425. </style>