infoForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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">导入简历快速填写 ({{ attachmentCount }}/5)</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 getEnterpriseData = async (name) => {
  76. const item = items.value.options.find(e => e.key === 'enterpriseId')
  77. if (!item) return
  78. if (item.items?.length && (enterpriseName === name)) return // 防抖
  79. enterpriseName = name
  80. if (name === null || name === '') { item.items = [] }
  81. else {
  82. const data = await enterpriseSearchByName({ name })
  83. item.items = data
  84. }
  85. }
  86. // 图片裁剪
  87. const selectPic = ref('')
  88. const isShowCopper = ref(false)
  89. const male = ref('1')
  90. const showIcon = ref(false)
  91. let positionName = null
  92. const items = ref({
  93. options: [
  94. {
  95. slotName: 'avatar',
  96. key: 'avatar',
  97. value: '',
  98. flexStyle: 'align-center mb-3'
  99. },
  100. {
  101. slotName: 'analysis',
  102. },
  103. {
  104. type: 'text',
  105. key: 'name',
  106. value: '',
  107. default: null,
  108. label: '姓名 *',
  109. outlined: true,
  110. rules: [
  111. value => {
  112. if (value) return true
  113. return '请输入您的中文名'
  114. },
  115. value => {
  116. var regex = /^[\u4e00-\u9fa5]+$/
  117. if (regex.test(value)) return true
  118. return '请输入正确的中文名'
  119. }
  120. ]
  121. },
  122. {
  123. type: 'autocomplete',
  124. key: 'sex',
  125. value: '1', // '1' ? '男' : '女'
  126. default: '1',
  127. label: '性别 *',
  128. outlined: true,
  129. dictTypeName: 'menduner_sex',
  130. rules: [v => !!v || '请选择性别'],
  131. items: [],
  132. change: val => male.value = val
  133. },
  134. {
  135. type: 'phoneNumber',
  136. key: 'phone',
  137. value: '',
  138. clearable: true,
  139. label: '联系手机号 *',
  140. rules: [v => !!v || '请填写联系手机号']
  141. },
  142. {
  143. type: 'text',
  144. key: 'email',
  145. value: null,
  146. default: null,
  147. label: '常用邮箱 *',
  148. outlined: true,
  149. rules: [
  150. value => {
  151. if (value) return true
  152. return '请输入联系邮箱'
  153. },
  154. value => {
  155. if (value && !checkEmail(value)) return '请输入正确的电子邮箱'
  156. return true
  157. }
  158. ]
  159. },
  160. {
  161. type: 'datePicker',
  162. mode: 'date',
  163. labelWidth: 80,
  164. key: 'birthday',
  165. value: new Date(1990, 0, 1).getTime(), // 月份是从 0 开始的
  166. label: '出生日期 *',
  167. disabledFutureDates: true,
  168. format: 'YYYY/MM/DD',
  169. flexStyle: 'mb-7',
  170. outlined: true,
  171. rules: [v => !!v || '请选择出生日期']
  172. },
  173. {
  174. type: 'combobox',
  175. key: 'enterpriseId',
  176. value: null,
  177. default: null,
  178. label: '任职企业名称 *(可填暂无)',
  179. outlined: true,
  180. clearable: true,
  181. canBeInputted: true, //
  182. itemTextName: 'enterpriseName',
  183. itemText: 'value',
  184. itemValue: 'key',
  185. rules: [v => !!v || '请填写任职企业名称(可填暂无)'],
  186. search: getEnterpriseData,
  187. items: []
  188. },
  189. {
  190. type: 'combobox',
  191. key: 'positionId',
  192. value: null,
  193. default: null,
  194. label: '任职职位名称 *(可填暂无)',
  195. outlined: true,
  196. clearable: true,
  197. canBeInputted: true, //
  198. itemTextName: 'positionName',
  199. itemText: 'nameCn',
  200. itemValue: 'id',
  201. dictTypeName: 'positionSecondData',
  202. rules: [v => !!v || '请填写任职职位名称(可填暂无)'],
  203. search: val => positionName = val,
  204. items: []
  205. },
  206. {
  207. type: 'autocomplete',
  208. key: 'interestedPositionList',
  209. value: null,
  210. default: null,
  211. label: '意向职位 *',
  212. outlined: true,
  213. itemText: 'nameCn',
  214. itemValue: 'id',
  215. multiple: true,
  216. dictTypeName: 'positionSecondData',
  217. rules: [v => !!v || '请选择意向职位'],
  218. items: []
  219. },
  220. {
  221. type: 'autocomplete',
  222. key: 'jobStatus',
  223. value: '',
  224. default: null,
  225. label: '求职状态 *',
  226. outlined: true,
  227. itemText: 'label',
  228. itemValue: 'value',
  229. dictTypeName: 'menduner_job_seek_status',
  230. rules: [v => !!v || '请选择求职状态'],
  231. items: []
  232. },
  233. {
  234. type: 'autocomplete',
  235. key: 'expType',
  236. value: '',
  237. default: null,
  238. label: '工作经验 *',
  239. outlined: true,
  240. itemText: 'label',
  241. itemValue: 'value',
  242. dictTypeName: 'menduner_exp_type',
  243. rules: [v => !!v || '请选择工作经验'],
  244. items: []
  245. },
  246. {
  247. type: 'autocomplete',
  248. key: 'eduType',
  249. value: '',
  250. default: null,
  251. label: '最高学历 *',
  252. outlined: true,
  253. itemText: 'label',
  254. itemValue: 'value',
  255. dictTypeName: 'menduner_education_type',
  256. rules: [v => !!v || '请选择最高学历'],
  257. items: []
  258. },
  259. // label: '学制类型 *', menduner_education_system_type
  260. ]
  261. })
  262. if (import.meta.env.VITE_NODE_ENV === 'production') {
  263. items.value.options = items.value.options.filter(e => e.slotName !== 'analysis')
  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. const file = e.target.files[0]
  278. if (!file) return
  279. const arr = file.name.split('.')
  280. const fileType = arr?.length ? arr[arr.length-1] : ''
  281. if (!accept.includes(fileType)) return Snackbar.warning('请上传图片格式文件')
  282. const size = file.size
  283. if (size / (1024*1024) > 20) {
  284. Snackbar.warning(t('common.fileSizeExceed'))
  285. return
  286. }
  287. const reader = new FileReader()
  288. reader.readAsDataURL(file)
  289. reader.onload = () => {
  290. selectPic.value = String(reader.result)
  291. isShowCopper.value = true
  292. }
  293. }
  294. const handleHideCopper = (data) => {
  295. isShowCopper.value = false
  296. if (data) {
  297. const { file } = data
  298. if (!file) return
  299. const formData = new FormData()
  300. formData.append('file', file)
  301. formData.append('path', 'img')
  302. uploadFile(formData).then(async ({ data }) => {
  303. if (!data) return
  304. items.value.options.find(e => e.key === 'avatar').value = data
  305. })
  306. }
  307. }
  308. // 获取字典内容
  309. const getDictData = async (dictTypeName, key) => {
  310. const item = items.value.options.find(e => e.key === key)
  311. if (item) {
  312. const apiType = dictTypeName === 'positionSecondData' ? 'positionSecondData' : 'dict'
  313. const { data } = await getDict(dictTypeName, apiType === 'dict' ? null : {}, apiType)
  314. item.items = data
  315. }
  316. }
  317. const userInfo = ref(localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : {})
  318. const baseInfo = ref(localStorage.getItem('baseInfo') ? JSON.parse(localStorage.getItem('baseInfo')) : {})
  319. items.value.options.forEach((e) => {
  320. if (e.dictTypeName) getDictData(e.dictTypeName, e.key) // 查字典set options
  321. if (userInfo.value && userInfo.value[e.key]) e.value = userInfo.value[e.key] // 人才信息回显
  322. if (baseInfo.value && baseInfo.value[e.key]) e.value = baseInfo.value[e.key] // 人才信息回显
  323. if (e.key === 'sex' && e.value === '0') e.value = e.default
  324. if (setInfo.value[e.key]) e.value = setInfo.value[e.key]
  325. })
  326. // const getName = (obj, key) => {
  327. // const item = items.value.options.find(e => e.key === key)
  328. // if (!item && !item.value) return
  329. // const select = item.items.find(e => item.value === e[item.itemValue || 'value'])
  330. // if (select) {
  331. // obj[item.itemTextName] = select[item.itemText || 'label']
  332. // }
  333. // }
  334. const dealQuery = () => {
  335. query.positionName = positionName || null
  336. if (query.positionId === positionName) delete query.positionId // 有选中id传id和name,否者只传name
  337. query.enterpriseName = enterpriseName || null
  338. if (query.enterpriseId === enterpriseName) delete query.enterpriseId // 有选中id传id和name,否者只传name
  339. //
  340. if (query.interestedPositionList?.length) {
  341. query.interestedList = query.interestedPositionList.map(e => { return {positionId: e} })
  342. }
  343. query.workExpList = [{
  344. enterpriseId: query.enterpriseId,
  345. enterpriseName: query.enterpriseName || null,
  346. positionId: query.positionId,
  347. positionName: query.positionName || null,
  348. }]
  349. }
  350. const getQuery = async () => {
  351. const { valid } = await formPageRef.value.formRef.validate()
  352. if (!valid) return false
  353. const obj = {}
  354. items.value.options.forEach(e => {
  355. if (Object.prototype.hasOwnProperty.call(e, 'data')) return obj[e.key] = e.data
  356. obj[e.key] = e.value === '' ? null : e.value
  357. })
  358. if (!obj.avatar) obj.avatar = getUserAvatar(null, obj.sex)
  359. query = Object.assign(query, obj)
  360. dealQuery()
  361. return query
  362. }
  363. // 填充
  364. const handleAnalyzeFill = (data) => {
  365. const person = data?.person || {}
  366. if (!Object.keys(person).length) return Snackbar.warning('无可用内容!')
  367. if (data.lastEmployed) {
  368. if (data.lastEmployed.enterpriseName) person.enterpriseId = person.enterpriseName = data.lastEmployed.enterpriseName
  369. if (data.lastEmployed.positionName) person.positionId = person.positionName = positionName = data.lastEmployed.positionName
  370. }
  371. if (data.lastPositionId) person.interestedPositionList = [data.lastPositionId]
  372. items.value.options.forEach((e) => {
  373. if (e.key && person[e.key]) e.value = person[e.key]
  374. })
  375. }
  376. const analyzeLoading = ref(false)
  377. const uploadFormRef = ref()
  378. const openUploadDialog = ref(false)
  379. // 上传附件-提交
  380. const uploadFileSubmit = async () => {
  381. const obj = await uploadFormRef.value.getQuery()
  382. if (!obj?.url || !obj?.title) return Snackbar.warning(t('resume.selectResumeToSubmit'))
  383. const query = { title: obj.title, url: obj.url }
  384. analyzeLoading.value = true
  385. await savePersonResumeCv(query)
  386. openUploadDialog.value = false
  387. const data = await resumeParser2({ fileUrl: obj.url })
  388. handleAnalyzeFill(data)
  389. getAttachmentList()
  390. analyzeLoading.value = false
  391. }
  392. // handleAnalyzeFill(JSON.parse(JSON.stringify(analyzeTestData)))
  393. const attachmentCount = ref(0)
  394. const getAttachmentList = async () => {
  395. const data = await getPersonResumeCv() // 获取附件
  396. attachmentCount.value = data?.length || 0
  397. }
  398. getAttachmentList()
  399. const handleImportAttachment = async () => {
  400. await getAttachmentList()
  401. if (attachmentCount.value >= 5) return Snackbar.warning('导入解析简历尝试不得超过5次!')
  402. openUploadDialog.value = true
  403. }
  404. defineExpose({
  405. getQuery
  406. })
  407. </script>
  408. <style scoped lang="scss">
  409. .avatarsBox {
  410. height: 80px;
  411. width: 80px;
  412. position: relative;
  413. cursor: pointer;
  414. // margin: 32px;
  415. // margin-right: 40px;
  416. margin: 0 40px 0 32px;
  417. .img {
  418. width: 100%;
  419. height: 100%;
  420. }
  421. .mdi {
  422. font-size: 42px;
  423. color: #fff;
  424. }
  425. div {
  426. position: absolute;
  427. top: 50%;
  428. left: 50%;
  429. transform: translate(-50%, -50%);
  430. border-radius: 50%;
  431. }
  432. }
  433. </style>