index.vue 8.5 KB

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