index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <!-- 简历附件解析 -->
  2. <template>
  3. <view>
  4. <!-- 选择简历 -->
  5. <resume v-if="step === 1" resumeAnalysis @submit="handleResumeAnalysis"></resume>
  6. <!-- 解析内容-表单 -->
  7. <view v-if="step === 2 && formLIst?.length" style="padding-bottom: 150rpx;">
  8. <uni-card v-for="item of formLIst" :key="item.id" :id="item.id">
  9. <uni-section :title="item.text" type="line">
  10. <template v-slot:right>
  11. <view v-if="item.path !== 'baseInfoEdit'" style="color: #e64340;" @click="del(item)">删除</view>
  12. </template>
  13. <avatarEdit v-if="item.path === 'avatarEdit'" ref="componentRef" :id="item.id" :text="item.text" :data="item.data" />
  14. <baseInfoEdit v-if="item.path === 'baseInfoEdit'" ref="componentRef" :id="item.id" :text="item.text" :data="item.data" />
  15. <advantageEdit v-if="item.path === 'advantageEdit'" ref="componentRef" :id="item.id" :text="item.text" :data="item.data" />
  16. <educationEdit v-if="item.path === 'educationEdit'" ref="componentRef" :id="item.id" :text="item.text" :data="item.data" />
  17. <workExperienceEdit v-if="item.path === 'workExperienceEdit'" ref="componentRef" :id="item.id" :text="item.text" :data="item.data" />
  18. <trainingExperienceEdit v-if="item.path === 'trainingExperienceEdit'" ref="componentRef" :id="item.id" :text="item.text" :data="item.data" />
  19. </uni-section>
  20. </uni-card>
  21. <!-- 保存 -->
  22. <view class="bottom-sticky flex-column ss-p-b-25" style="background-color: #fff; z-index: 2000; border-top: 1px solid #eee;">
  23. <button class="recomm-button" :loading="submitLoading" @click="submit">提交(保存至在线简历)</button>
  24. </view>
  25. </view>
  26. <view v-if="step === 3">
  27. <view class="tips">加载中...</view>
  28. </view>
  29. <view v-if="step === 4">
  30. <view class="tips">加载失败</view>
  31. </view>
  32. <!-- 确认框 -->
  33. <uni-popup ref="confirmRef" type="dialog">
  34. <uni-popup-dialog
  35. type="warn"
  36. cancelText="取消"
  37. confirmText="确认"
  38. title="系统提示"
  39. :showClose="showClose"
  40. :content="dialogContent"
  41. @confirm="handleConfirm"
  42. @close="null"
  43. ></uni-popup-dialog>
  44. </uni-popup>
  45. </view>
  46. </template>
  47. <script setup>
  48. import { saveResumeInfo, resumeParser2 } from '@/api/user'
  49. // import { envObj, baseUrl } from '@/utils/config'
  50. import resume from '../resume/index.vue'
  51. import { ref, shallowRef } from 'vue'
  52. import avatarEdit from './components/avatarEdit.vue'
  53. import baseInfoEdit from './components/baseInfoEdit.vue'
  54. import advantageEdit from './components/advantage.vue'
  55. import educationEdit from './components/educationExp.vue'
  56. import workExperienceEdit from './components/workExperience.vue'
  57. import trainingExperienceEdit from './components/trainingExperience.vue'
  58. import { resumeParser2Data } from './testData.js'
  59. const step = ref(1)
  60. const exampleList = {
  61. avatar: { text: '头像', id: 'avatar', path: 'avatarEdit' },
  62. person: { text: '基础信息', id: 'person', path: 'baseInfoEdit' },
  63. advantage: { text: '个人优势', id: 'advantage', path: 'advantageEdit' },
  64. eduList: { text: '教育经历', id: 'eduList', path: 'educationEdit' },
  65. workList: { text: '工作经历', id: 'workList', path: 'workExperienceEdit' },
  66. trainList: { text: '培训经历', id: 'trainList', path: 'trainingExperienceEdit' },
  67. }
  68. const resumeTxt = ref([]) // 查看文本信息
  69. const formLIst = shallowRef([])
  70. const transformToLIst = async (result) => {
  71. formLIst.value = []
  72. if (result && Object.keys(result)) {
  73. if (result.resume?.rawText) resumeTxt.value = result.resume.rawText.split('\n') || []
  74. if (result.person?.advantage) result.advantage = result.person.advantage
  75. if (result.person?.avatar) result.avatar = result.person.avatar
  76. // obj
  77. const dealObjKeys = ['avatar', 'person', 'advantage']
  78. dealObjKeys.forEach(key => {
  79. if (result[key]) {
  80. const obj = {...exampleList[key]}
  81. obj.data = result[key]
  82. formLIst.value.push(obj)
  83. }
  84. })
  85. // arr
  86. const dealArrKeys = ['eduList', 'workList', 'trainList']
  87. dealArrKeys.forEach(key => {
  88. if (result[key]?.length) {
  89. for (let index = 0; index < result[key].length; index++) {
  90. const obj = {...exampleList[key]}
  91. obj.id = obj.id + '_' + index
  92. obj.text = result[key].length > 1 ? obj.text + (index+1) : obj.text
  93. obj.data = result[key][index]
  94. formLIst.value.push(obj)
  95. }
  96. }
  97. })
  98. }
  99. // console.log('formLIst:', formLIst.value)
  100. }
  101. const confirmRef = ref()
  102. const dialogContent = ref('')
  103. const showClose = ref(true)
  104. let delId = null
  105. let dialogType = 'del'
  106. const del = (item) => {
  107. dialogContent.value = `是否确认删除${item.text}?`
  108. delId = item.id
  109. dialogType = 'del'
  110. showClose.value = true
  111. confirmRef.value.open()
  112. }
  113. const handleConfirm = () => {
  114. if (dialogType === 'del') {
  115. formLIst.value = formLIst.value.filter(e => e.id !== delId)
  116. }
  117. if (dialogType === 'submitSuccess') {
  118. uni.navigateTo({ url: '/pagesA/resumeOnline/index' })
  119. }
  120. }
  121. // const result = ref(JSON.parse(JSON.stringify(data))) // 测试
  122. // transformToLIst(result.value) // 测试
  123. const result = ref({})
  124. const loading = ref(false)
  125. const handleAnalysis = async (url) => {
  126. url = decodeURIComponent(url)
  127. if (!url) return
  128. loading.value = true
  129. step.value = 3
  130. try {
  131. // const res = await resumeParser2({ fileUrl: url })
  132. // result.value = res?.data || {}
  133. result.value = resumeParser2Data
  134. await transformToLIst(result.value)
  135. step.value = 2
  136. } catch (error) {
  137. step.value = 4
  138. console.log(error)
  139. } finally {
  140. loading.value = false
  141. }
  142. }
  143. const handleResumeAnalysis = (url) => {
  144. if (!url) {
  145. return uni.showToast({ icon: 'none', title: '请选择要解析的简历' })
  146. }
  147. handleAnalysis(url)
  148. }
  149. const componentRef = ref()
  150. const getValue = async () => {
  151. let text = ''
  152. let data = {}
  153. for (let index = 0; index < componentRef.value.length; index++) {
  154. const e = componentRef.value[index]
  155. const query = await e.submit()
  156. if (query && query.data) {
  157. data[query.id] = query.data
  158. } else {
  159. if (!text) text = query.text
  160. }
  161. }
  162. if (text) {
  163. uni.showToast({ icon: 'none', title: `请完整填写 ${text} 后提交!` })
  164. return
  165. }
  166. // 处理data
  167. let obj = Object.keys(data).length ? {} : null
  168. const keyTransform = { // 转换给后端的key
  169. eduList: 'eduExp',
  170. workList: 'workExp',
  171. trainList: 'trainExp',
  172. }
  173. if (obj) {
  174. Object.keys(data).forEach(key => {
  175. if (key.includes('_')) { // 数组
  176. const oldKey = key.split('_')[0]
  177. const newKey = keyTransform[oldKey] ? keyTransform[oldKey] : oldKey
  178. if (!obj[newKey]) obj[newKey] = [data[key]]
  179. else obj[newKey].push(data[key])
  180. } else {
  181. const newKey = keyTransform[key] ? keyTransform[key] : key
  182. obj[newKey] = data[key]
  183. }
  184. })
  185. }
  186. console.log('123456:', obj)
  187. return obj && Object.keys(obj).length ? JSON.stringify(obj) : null
  188. }
  189. const submitLoading = ref(false)
  190. const submit = async () => {
  191. const obj = await getValue()
  192. if (!obj) return
  193. submitLoading.value = true
  194. await saveResumeInfo(obj)
  195. dialogType = 'submitSuccess'
  196. dialogContent.value = '提交成功,立即前往在线简历查看'
  197. showClose.value = false
  198. confirmRef.value.open()
  199. // await useUserStore().getUserBaseInfos() // 更新用户信息
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .tips {
  204. text-align: center;
  205. margin-top: 50px;
  206. color: #777;
  207. }
  208. </style>