index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div style="height: calc(100vh - 50px)">
  3. <template v-if="showSelect">
  4. <div class="d-flex flex-column pb-10" style="width: 800px; min-width: 800px; height: 100%; min-height: 500px; margin: 0 auto;">
  5. <attachmentPage analysis @analysis="handleAnalysis"></attachmentPage>
  6. </div>
  7. </template>
  8. <template v-else>
  9. <div class="d-flex pa-3" style="height: 100%">
  10. <!-- 简历附件回显 -->
  11. <v-card class="mr-3 pa-3" style="width: 50%; height: 100%; overflow: hidden; position: relative;">
  12. <v-tabs v-model="tab" align-tabs="start" color="primary" bg-color="#f7f8fa">
  13. <v-tab :value="1">查看附件简历</v-tab>
  14. <v-tab :value="2">查看文本信息</v-tab>
  15. </v-tabs>
  16. <v-btn style="position: absolute; right: 12px; top: 18px;" color="primary" @click="showSelect = true">重新选择附件简历</v-btn>
  17. <div class="mt-3 pb-3" style="width: 100%; height: calc(100% - 48px);overflow: auto;">
  18. <div v-show="tab === 1" style="width: 100%; height: 100%">
  19. <IFrame :src="decodeURIComponent(fileUrl)" initHeight="100%"></IFrame>
  20. </div>
  21. <div v-show="tab === 2" style="width: 100%; height: 100%; overflow: auto;" class="pb-5 px-3">
  22. <template v-if="resumeTxt?.length">
  23. <div style="color: #999;" class="mb-3 text-center">简历解析(可复制文本使用)</div>
  24. <p v-for="(text, resumeTxtIndex) in resumeTxt" :key="'简历解析' + resumeTxtIndex" class="my-3">{{ text }}</p>
  25. </template>
  26. <div v-else style="color: #666;" class="mt-3 text-center">无简历解析文本可用</div>
  27. </div>
  28. </div>
  29. </v-card>
  30. <!-- 解析内容 -->
  31. <v-card class="elevation-2 pa-3" style="flex: 1; height: 100%; overflow: hidden; position: relative;" >
  32. <div style="height: 100%; overflow: auto;">
  33. <div v-for="item of formLIst" :key="item.id" :id="item.id" class="pa-3 mb-3" style="background-color: var(--color-f8);">
  34. <div class="resume-header mb-3">
  35. <div class="resume-title">{{ item.text }}</div>
  36. <v-btn v-if="item.id !== 'person'" variant="text" color="error" density="compact" prepend-icon="mdi-delete-outline" @click="del(item)">删除</v-btn>
  37. <v-btn v-else disabled variant="text" color="error" density="compact">不可删除</v-btn>
  38. </div>
  39. <component ref="componentRef" :id="item.id" :is="item.path" :data="item.data" />
  40. </div>
  41. <!-- 保存 -->
  42. <div style="position: absolute; bottom: 0; background-color: #fff; z-index: 99; width: 100%; border-top: 1px solid #e4e7eb;" class="py-3 ml-n3 text-center">
  43. <v-btn class="buttons mx-3" color="primary" @click="submit">提交(保存至在线简历)</v-btn>
  44. <!-- <v-btn class="ml-2" variant="text" color="primary" to="/recruit/personal/personalCenter/resume/online">返回在线简历</v-btn> -->
  45. </div>
  46. </div>
  47. </v-card>
  48. <v-overlay
  49. v-model="loading"
  50. :close-on-content-click="false"
  51. :no-click-animation="true"
  52. contained
  53. class="align-center justify-center"
  54. >
  55. <v-progress-circular color="primary" size="64" indeterminate></v-progress-circular>
  56. </v-overlay>
  57. </div>
  58. </template>
  59. </div>
  60. </template>
  61. <script setup>
  62. defineOptions({ name: 'resume-analysis'})
  63. import { shallowRef, ref } from 'vue'
  64. import { useI18n } from '@/hooks/web/useI18n'
  65. import IFrame from '@/components/IFrame'
  66. import avatar from './components/avatar.vue'
  67. import basicInfo from './components/basicInfo.vue'
  68. import selfEvaluation from './components/selfEvaluation.vue'
  69. import educationExp from './components/educationExp.vue'
  70. import workExperience from './components/workExperience.vue'
  71. import trainingExperience from './components/trainingExperience.vue'
  72. import Snackbar from '@/plugins/snackbar'
  73. import Confirm from '@/plugins/confirm'
  74. import { saveResumeInfo, resumeParser2 } from '@/api/recruit/personal/resume'
  75. import { useUserStore } from '@/store/user'
  76. import attachmentPage from '../attachment'
  77. import { Base64 } from 'js-base64'
  78. const { t } = useI18n()
  79. const props = defineProps({
  80. data: {
  81. type: Object,
  82. default: () => {}
  83. }
  84. })
  85. const tab = ref(1)
  86. const exampleList = {
  87. avatar: { text: t('resume.avatar'), id: 'avatar', path: avatar },
  88. person: { text: t('resume.basicInfo'), id: 'person', path: basicInfo },
  89. advantage: { text: t('resume.personalAdvantages'), id: 'advantage', path: selfEvaluation },
  90. eduList: { text: t('resume.educationExp'), id: 'eduList', path: educationExp },
  91. workList: { text: t('resume.workExperience'), id: 'workList', path: workExperience },
  92. trainList: { text: t('resume.trainingExperience'), id: 'trainList', path: trainingExperience },
  93. }
  94. const del = (item) => {
  95. Confirm('系统提示', `是否确认删除${item.text}?`).then(async () => {
  96. formLIst.value = formLIst.value.filter(e => e.id !== item.id)
  97. })
  98. }
  99. const resumeTxt = ref([]) // 查看文本信息
  100. const formLIst = shallowRef([])
  101. const transformToLIst = async (result) => {
  102. formLIst.value = []
  103. if (result && Object.keys(result)) {
  104. if (result.resume?.rawText) resumeTxt.value = result.resume.rawText.split('\n') || []
  105. if (result.person?.advantage) result.advantage = result.person.advantage
  106. if (result.person?.avatar) result.avatar = result.person.avatar
  107. // obj
  108. const dealObjKeys = ['avatar', 'person', 'advantage']
  109. dealObjKeys.forEach(key => {
  110. if (result[key]) {
  111. const obj = {...exampleList[key]}
  112. obj.data = result[key]
  113. formLIst.value.push(obj)
  114. }
  115. })
  116. // arr
  117. const dealArrKeys = ['eduList', 'workList', 'trainList']
  118. dealArrKeys.forEach(key => {
  119. if (result[key]?.length) {
  120. for (let index = 0; index < result[key].length; index++) {
  121. const obj = {...exampleList[key]}
  122. obj.id = obj.id + '_' + index
  123. obj.text = result[key].length > 1 ? obj.text + (index+1) : obj.text
  124. obj.data = result[key][index]
  125. formLIst.value.push(obj)
  126. }
  127. }
  128. })
  129. }
  130. }
  131. const result = ref({}) // ref(JSON.parse(JSON.stringify(dataObj))) // 测试
  132. const fileUrl = ref('')
  133. const showSelect = ref(true)
  134. const handleAnalysis = async (url) => {
  135. url = decodeURIComponent(url)
  136. if (!url) return
  137. showSelect.value = false
  138. loading.value = true
  139. const baseUrl = import.meta.env.VITE_PREVIEW_URL
  140. fileUrl.value = !url.includes('.pdf') ? `${baseUrl}/onlinePreview?url=${encodeURIComponent(Base64.encode(url))}` : url
  141. try {
  142. const data = await resumeParser2({ fileUrl: url })
  143. result.value = data || {}
  144. // result.value = {person: data.person} || {} // 测试
  145. await transformToLIst(result.value)
  146. } catch (error) {
  147. console.log(error)
  148. } finally {
  149. loading.value = false
  150. }
  151. }
  152. const componentRef = ref()
  153. const getValue = async () => {
  154. let id = ''
  155. let data = {}
  156. for (let index = 0; index < componentRef.value.length; index++) {
  157. const e = componentRef.value[index]
  158. const query = await e.submit()
  159. if (query && query.data) {
  160. data[query.id] = query.data
  161. } else {
  162. id = id ? id : query.id
  163. }
  164. }
  165. console.log('id:', id)
  166. if (id) {
  167. Snackbar.warning('请填写完整后提交!')
  168. return
  169. }
  170. // 处理data
  171. let obj = Object.keys(data).length ? {} : null
  172. const keyTransform = { // 转换给后端的key
  173. eduList: 'eduExp',
  174. workList: 'workExp',
  175. trainList: 'trainExp',
  176. }
  177. if (obj) {
  178. Object.keys(data).forEach(key => {
  179. if (key.includes('_')) { // 数组
  180. const oldKey = key.split('_')[0]
  181. const newKey = keyTransform[oldKey] ? keyTransform[oldKey] : oldKey
  182. if (!obj[newKey]) obj[newKey] = [data[key]]
  183. else obj[newKey].push(data[key])
  184. } else {
  185. const newKey = keyTransform[key] ? keyTransform[key] : key
  186. obj[newKey] = data[key]
  187. }
  188. })
  189. // const defaultObj = { avatar: "", person: {}, advantage: { content: '' }, tag: { tagList: [] }, jobInterested: [], eduExp: [], workExp: [], trainExp: [] } // 必传字段
  190. // const defaultObj = { avatar: null, person: null, advantage: null, tag: null, jobInterested: null, eduExp: null, workExp: null, trainExp: null } // 必传字段
  191. // obj = { ...defaultObj, ...obj }
  192. }
  193. // console.log('123456:', obj)
  194. return obj && Object.keys(obj).length ? JSON.stringify(obj) : null
  195. }
  196. const loading = ref(false)
  197. const submit = async () => {
  198. const obj = await getValue()
  199. if (!obj) return
  200. try {
  201. loading.value = true
  202. await saveResumeInfo(obj)
  203. await useUserStore().getUserBaseInfos() // 更新用户信息
  204. // Snackbar.success(t('common.saveMsg'))
  205. // setTimeout(() => { window.location.reload() }, 1000) // 刷新页面
  206. Confirm('系统提示', `提交成功,是否前往在线简历查看?`, { sureText: '立即前往' }).then(() => {
  207. window.location.href = '/recruit/personal/personalCenter/resume/online'
  208. })
  209. } catch (error) {
  210. console.log(error)
  211. } finally {
  212. loading.value = false
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. </style>