index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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" :data="item.data" />
  14. <baseInfoEdit v-if="item.path === 'baseInfoEdit'" ref="componentRef" :id="item.id" :data="item.data" />
  15. <advantageEdit v-if="item.path === 'advantageEdit'" ref="componentRef" :id="item.id" :data="item.data" />
  16. <educationEdit v-if="item.path === 'educationEdit'" ref="componentRef" :id="item.id" :data="item.data" />
  17. <workExperienceEdit v-if="item.path === 'workExperienceEdit'" ref="componentRef" :id="item.id" :data="item.data" />
  18. <trainingExperienceEdit v-if="item.path === 'trainingExperienceEdit'" ref="componentRef" :id="item.id" :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 { data } 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. // const baseUrl = envObj.previewUrl
  131. // fileUrl.value = !url.includes('.pdf') ? `${baseUrl}/onlinePreview?url=${encodeURIComponent(Base64.encode(url))}` : url
  132. try {
  133. const res = await resumeParser2({ fileUrl: url })
  134. result.value = res?.data || {}
  135. await transformToLIst(result.value)
  136. step.value = 2
  137. } catch (error) {
  138. step.value = 4
  139. console.log(error)
  140. } finally {
  141. loading.value = false
  142. }
  143. }
  144. const handleResumeAnalysis = (url) => {
  145. if (!url) {
  146. return uni.showToast({ icon: 'none', title: '请选择要解析的简历' })
  147. }
  148. handleAnalysis(url)
  149. }
  150. const componentRef = ref()
  151. const getValue = async () => {
  152. let id = ''
  153. let data = {}
  154. for (let index = 0; index < componentRef.value.length; index++) {
  155. const e = componentRef.value[index]
  156. const query = await e.submit()
  157. if (query && query.data) {
  158. data[query.id] = query.data
  159. } else {
  160. id = id ? id : query.id
  161. }
  162. }
  163. console.log('id:', id)
  164. if (id) {
  165. uni.showToast({ icon: 'none', title: '请填写完整后提交!' })
  166. return
  167. }
  168. // 处理data
  169. let obj = Object.keys(data).length ? {} : null
  170. const keyTransform = { // 转换给后端的key
  171. eduList: 'eduExp',
  172. workList: 'workExp',
  173. trainList: 'trainExp',
  174. }
  175. if (obj) {
  176. Object.keys(data).forEach(key => {
  177. if (key.includes('_')) { // 数组
  178. const oldKey = key.split('_')[0]
  179. const newKey = keyTransform[oldKey] ? keyTransform[oldKey] : oldKey
  180. if (!obj[newKey]) obj[newKey] = [data[key]]
  181. else obj[newKey].push(data[key])
  182. } else {
  183. const newKey = keyTransform[key] ? keyTransform[key] : key
  184. obj[newKey] = data[key]
  185. }
  186. })
  187. }
  188. console.log('123456:', obj)
  189. return obj && Object.keys(obj).length ? JSON.stringify(obj) : null
  190. }
  191. const submitLoading = ref(false)
  192. const submit = async () => {
  193. const obj = await getValue()
  194. if (!obj) return
  195. submitLoading.value = true
  196. await saveResumeInfo(obj)
  197. dialogType = 'submitSuccess'
  198. dialogContent.value = '提交成功,立即前往在线简历查看'
  199. showClose.value = false
  200. confirmRef.value.open()
  201. // await useUserStore().getUserBaseInfos() // 更新用户信息
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .tips {
  206. text-align: center;
  207. margin-top: 50px;
  208. color: #777;
  209. }
  210. </style>