index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="名称" prop="name">
  12. <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter="handleQuery" class="!w-180px" />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button @click="handleQuery('search')"><Icon icon="ep:search" /> 搜索</el-button>
  16. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  17. <el-button type="primary" plain @click="handleAdd">
  18. <Icon icon="ep:plus" class="mr-5px" /> 新增人才
  19. </el-button>
  20. </el-form-item>
  21. </el-form>
  22. </ContentWrap>
  23. <!-- 列表 -->
  24. <ContentWrap>
  25. <el-table v-loading="loading" :data="list" :stripe="true">
  26. <el-table-column label="中文名称" align="center" prop="name_zh" fixed="left" />
  27. <el-table-column label="英文名称" align="center" prop="name_en" />
  28. <el-table-column label="职位" align="center" prop="title_zh" />
  29. <el-table-column label="酒店/公司" align="center" prop="hotel_zh" />
  30. <el-table-column label="手机号码" align="center" prop="mobile" />
  31. <el-table-column label="固定电话" align="center" prop="phone" />
  32. <el-table-column label="状态" align="center" prop="status" width="80">
  33. <template #default="scope">
  34. <el-tag type="success" v-if="scope.row.status === 'active'">已启用</el-tag>
  35. <el-tag type="danger" v-else>已禁用</el-tag>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="创建日期" align="center" prop="created_at" :formatter="dateFormatter" />
  39. <el-table-column label="操作" align="center" fixed="right" min-width="110">
  40. <template #default="scope">
  41. <el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>
  42. <el-button link type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
  43. <el-button link :type="scope.row.status === 'active' ? 'warning': 'success'" @click="handleDisable(scope.row)">
  44. {{ scope.row.status === 'active' ? '禁用' : '启用'}}
  45. </el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <!-- 选择来源 -->
  50. <Dialog title="解析方式" v-model="openSelect" width="500" @close="openSelect = false">
  51. <el-radio-group v-model="radioValue" size="large" class="radioBox">
  52. <el-radio
  53. v-for="item in radioList"
  54. :key="item.value"
  55. :value="item.value"
  56. >
  57. {{ item.label }}
  58. </el-radio>
  59. </el-radio-group>
  60. <template #footer>
  61. <el-button type="primary" @click="handleSelect">确 认</el-button>
  62. <el-button @click="null">取 消</el-button>
  63. </template>
  64. </Dialog>
  65. <!-- 解析文件上传 -->
  66. <Dialog :title="radioObject[radioValue]" v-model="dialog_upload" :width="DialogWidth" @close="handleCancel">
  67. <div>
  68. <!-- 门墩儿人才库 -->
  69. <!-- <template v-if="radioValue === 'menduner'">
  70. </template> -->
  71. <!-- 简历解析 -->
  72. <template v-if="radioValue === 'file'">
  73. <el-upload
  74. ref="uploadRef"
  75. v-model:file-list="fileList"
  76. :action="uploadUrl"
  77. :auto-upload="false"
  78. :data="data"
  79. :limit="1"
  80. :on-change="handleChange"
  81. :on-error="submitFormError"
  82. :on-exceed="handleExceed"
  83. :on-success="submitFormSuccess"
  84. :http-request="httpRequest"
  85. accept=".pdf, doc, .docx"
  86. drag
  87. class="flex-1"
  88. >
  89. <i class="el-icon-upload"></i>
  90. <div class="el-upload__text">上传附件, 将文件拖到此处,或 <em>点击上传</em></div>
  91. <template #tip>
  92. <div class="el-upload__tip color-red">
  93. 提示:仅允许导入 pdf、doc、docx 格式文件!
  94. </div>
  95. </template>
  96. </el-upload>
  97. </template>
  98. <!-- 名片解析 -->
  99. <template v-if="radioValue === 'card'">
  100. <UploadImg
  101. v-model="cardImgUrl"
  102. :limit="1"
  103. :uploadSuccessTip="false"
  104. @handle-change="cardUploadChange"
  105. height="150px" width="150px" style="margin: 20px auto; width: 150px;"
  106. >
  107. <template #tip>{{ cardImgUrl ? '' : '请上传名片' }}</template>
  108. </UploadImg>
  109. </template>
  110. <!-- 网页解析 -->
  111. <!-- <template v-if="radioValue === 'web'"></template> -->
  112. </div>
  113. <template #footer>
  114. <el-button @click="handleAnalysis" type="success" :disabled="analysisLoading" :loading="analysisLoading">解 析</el-button>
  115. <el-button @click="handleCancel">取 消</el-button>
  116. </template>
  117. </Dialog>
  118. <!-- 解析回显 -->
  119. <Dialog :title="radioObject[radioValue]" v-model="dialog_analysisInfo" width="80%">
  120. <div class="analysisInfoBox">
  121. <div class="analysisFile">
  122. <!-- 门墩儿人才库 -->
  123. <template v-if="radioValue === 'menduner'">
  124. <Search @detail="handleDetail" :detailButTxt="detailButTxt" :searchName="formData?.name_zh || formData?.name_en || ''" />
  125. </template>
  126. <!-- 简历解析 -->
  127. <template v-if="radioValue === 'file'">
  128. <div v-if="fileUrl" style="position: relative;">
  129. <div class="text-right m-b-10px">
  130. <el-button v-if="!isEdit" @click="handleText">查看文本信息</el-button>
  131. <el-button type="primary" @click="handleResetUpload">重新上传简历</el-button>
  132. </div>
  133. <IFrame :src="fileUrl" />
  134. <el-drawer
  135. v-model="drawer"
  136. modal-class="drawer"
  137. size="75%"
  138. direction="ltr"
  139. title="简历解析(可复制文本使用)"
  140. >
  141. <p v-for="(text, index) in resumeTxt" :key="text + index">{{ text }}</p>
  142. </el-drawer>
  143. </div>
  144. <el-upload
  145. v-else
  146. ref="uploadRef"
  147. v-model:file-list="fileList"
  148. :action="uploadUrl"
  149. :auto-upload="false"
  150. :data="data"
  151. :limit="1"
  152. :on-change="handleChange"
  153. :on-error="submitFormError"
  154. :on-exceed="handleExceed"
  155. :on-success="submitFormSuccess"
  156. :http-request="httpRequest"
  157. accept=".pdf, doc, .docx"
  158. drag
  159. class="flex-1"
  160. >
  161. <i class="el-icon-upload"></i>
  162. <div class="el-upload__text">上传附件, 将文件拖到此处,或 <em>点击上传</em></div>
  163. <template #tip>
  164. <div class="el-upload__tip color-red">
  165. 提示:仅允许导入 pdf、doc、docx 格式文件!
  166. </div>
  167. </template>
  168. </el-upload>
  169. </template>
  170. <!-- 名片解析 -->
  171. <template v-if="radioValue === 'card'">
  172. <div class="image">
  173. <el-image v-if="cardImgUrl" class="!w-100%" :src="cardImgUrl" />
  174. <div v-else>
  175. <UploadImg
  176. v-model="cardImgUrl"
  177. :limit="1"
  178. :uploadSuccessTip="false"
  179. drag
  180. buttonUpload
  181. @handle-change="cardUploadChange"
  182. height="32px" width="104px"
  183. style="margin: 0 auto; width: 104px;margin-top: 40%;"
  184. >
  185. <template #tip>{{ cardImgUrl ? '' : '请上传名片' }}</template>
  186. </UploadImg>
  187. </div>
  188. </div>
  189. </template>
  190. <!-- 网页解析 -->
  191. <template v-if="radioValue === 'web'">
  192. <webAnalysis v-if="showWebAnalysis"/>
  193. </template>
  194. </div>
  195. <FormPage ref="FormPageRef" :analysisType="analysisType" :itemData="formData" />
  196. </div>
  197. <template #footer>
  198. <el-button @click="handleSave" type="success" :disabled="analysisLoading">保 存</el-button>
  199. <el-button @click="dialog_analysisInfo = false">取 消</el-button>
  200. </template>
  201. </Dialog>
  202. </ContentWrap>
  203. <MergeForm ref="mergeFormRef" @refresh="getList" />
  204. </template>
  205. <script setup>
  206. defineOptions({ name: 'TalentMapStoreIndex' })
  207. import { dateFormatter } from '@/utils/formatTime'
  208. import { talentLabelingApi } from '@/api/menduner/system/talentMap/labeling'
  209. import { TalentMap } from '@/api/menduner/system/talentMap'
  210. import { Delete, Plus } from '@element-plus/icons-vue'
  211. import MergeForm from '@/views/menduner/system/talentMap/components/merge.vue'
  212. import FormPage from '@/views/menduner/system/talentMap/components/FormPage.vue'
  213. // import uploadDialog from './components/uploadDialog.vue'
  214. import { timesTampChange, timestampToAge } from '@/utils/transform/date'
  215. import Search from './components/search.vue'
  216. import webAnalysis from './components/webAnalysis.vue'
  217. import { useUpload } from '@/components/UploadFile/src/useUpload'
  218. import { commonApi } from '@/api/menduner/common'
  219. import { Base64 } from 'js-base64'
  220. const baseUrl = import.meta.env.VITE_PREVIEW_URL
  221. const { uploadUrl, httpRequest } = useUpload()
  222. const message = useMessage() // 消息弹窗
  223. const { t } = useI18n() // 国际化
  224. const loading = ref(false) // 列表的加载中
  225. const list = ref([]) // 列表的数据
  226. const total = ref(0) // 列表的总页数
  227. const queryParams = reactive({
  228. name: undefined
  229. })
  230. const queryFormRef = ref() // 搜索的表单
  231. const dialog_upload = ref(false)
  232. /** 查询列表 */
  233. const getList = async () => {
  234. loading.value = true
  235. try {
  236. list.value = []
  237. const data = await talentLabelingApi.getCardList()
  238. list.value = data ? data.reverse() : []
  239. } finally {
  240. loading.value = false
  241. }
  242. }
  243. /** 搜索按钮操作 */
  244. const handleQuery = (type) => {
  245. if (type !== 'reset') {
  246. message.warning('搜索正在建设中...')
  247. return
  248. }
  249. getList()
  250. }
  251. /** 重置按钮操作 */
  252. const resetQuery = () => {
  253. queryFormRef.value.resetFields()
  254. handleQuery('reset')
  255. }
  256. /** 删除按钮操作 */
  257. const handleDelete = async (id) => {
  258. try {
  259. // 删除的二次确认
  260. await message.delConfirm()
  261. // 发起删除
  262. await talentLabelingApi.deleteBusinessCard(id)
  263. message.success(t('common.delSuccess'))
  264. // 刷新列表
  265. setTimeout(async () => {
  266. await getList()
  267. }, 0)
  268. } catch {}
  269. }
  270. /** 编辑 */
  271. const { push } = useRouter()
  272. const handleEdit = async (item) => {
  273. analysisType.value = 'edit'
  274. formData.value = item
  275. radioValue.value = item.type || 'card' // menduner
  276. try {
  277. if (radioValue.value === 'card') {
  278. if (!item?.image_path) {
  279. cardUploadRow.value = null
  280. cardImgUrl.value = null
  281. dialog_analysisInfo.value = true
  282. return
  283. }
  284. const data = await talentLabelingApi.getBusinessCardImage(item.image_path)
  285. cardUploadRow.value = data?.type ? new File([data], item.image_path, { type: data.type }) : null
  286. cardImgUrl.value = data?.type ? URL.createObjectURL(data) : null
  287. }
  288. } catch (error) {
  289. console.log('打印->getBusinessCardImage', error)
  290. } finally {
  291. dialog_analysisInfo.value = true
  292. }
  293. }
  294. /** 禁用按钮操作 */
  295. const handleDisable = async (item) => {
  296. if (!item?.id) return message.warning('操作失败,请稍后再试')
  297. try {
  298. // 禁用的二次确认
  299. const status = item.status === 'active' ? 'inactive' : 'active'
  300. const text = status === 'inactive' ? '禁用' : '启用'
  301. await message.delConfirm(`是否${text}该名片?`)
  302. // 发起禁用
  303. await talentLabelingApi.updateBusinessCardStatus({
  304. status,
  305. }, item.id)
  306. message.success(`${text}成功`)
  307. // 刷新列表
  308. await getList()
  309. } catch {}
  310. }
  311. // 更新
  312. const dialog_analysisInfo = ref(false)
  313. const formLoading = ref(false)
  314. const analysisType = ref('')
  315. const FormPageRef = ref(null)
  316. const mergeFormRef = ref() // 合并表单 Ref
  317. const handleSave = async () => {
  318. const params = { ...FormPageRef.value.formQuery, type: radioValue.value }
  319. if (!params.name_zh) return message.warning('请填写姓名!')
  320. // 数组转为字符串保存
  321. if (Array.isArray(params?.mobile)) {
  322. params.mobile = params.mobile.filter(i => Boolean(i)).map(j => String(j).replace(/,|,/g, '')).join(',');
  323. }
  324. console.log(params, 'handleSubmit')
  325. try {
  326. formLoading.value = true
  327. let result = {}
  328. if (analysisType.value === 'create') {
  329. if (cardFileQuery.value) {
  330. cardFileQuery.value.append('card_data', JSON.stringify(params)) // 名片
  331. result = await talentLabelingApi.createBusinessCard(cardFileQuery.value)
  332. } else {
  333. // 结构化数据源 不传递文件
  334. result = await talentLabelingApi.createBusinessCardPost(params)
  335. }
  336. message.success('新增成功')
  337. dialog_analysisInfo.value = false
  338. // 刷新列表
  339. getList()
  340. if (result.code === 202 || result.message.includes('疑似重复')) {
  341. if (!result.data?.main_card?.id) return
  342. await message.confirm('发现与当前名片的疑似重复数据,去处理')
  343. mergeFormRef.value.open(result.data?.main_card?.id)
  344. }
  345. } else {
  346. await talentLabelingApi.updateBusinessCard(params, formData.value.id)
  347. message.success('更新成功')
  348. dialog_analysisInfo.value = false
  349. // 刷新列表
  350. getList()
  351. }
  352. } catch (error) {
  353. console.log('更新失败', error)
  354. } finally {
  355. cardFileQuery.value = null
  356. formLoading.value = false
  357. }
  358. }
  359. // 解析中
  360. const analysisLoading = ref(false)
  361. const formData = ref({})
  362. const handleAnalysis = async () => {
  363. // 开始解析
  364. analysisLoading.value = true
  365. cardFileQuery.value = null
  366. formData.value = null
  367. const type = radioValue.value
  368. try {
  369. // if (type === 'menduner') { // 门墩儿人才库
  370. // } else
  371. if (type === 'file') { // 简历解析
  372. if (!fileUrl.value) return message.warning('获取文件失败,请重新上传!')
  373. const data = await commonApi.resumeParser({ fileUrl: fileUrl.value })
  374. resumeAnalysisToForm(data) // 简历解析
  375. } else if (type === 'card') { // 名片解析
  376. if (!cardImgUrl.value) {
  377. message.warning('请先上传名片!')
  378. return
  379. }
  380. cardFileQuery.value = new FormData()
  381. cardFileQuery.value.append('image', cardUploadRow.value)
  382. message.warning('正在解析...')
  383. const index = createAnalysisNum.value
  384. const res = await talentLabelingApi.businessCardParse(cardFileQuery.value)
  385. if (index !== createAnalysisNum.value || !dialog_upload.value) return // 不是最新的名片解析数据(用户在解析完成前已重新上传)或用户已取消解析
  386. formData.value = res?.data || res
  387. message.success('名片解析成功')
  388. }
  389. // else if (type === 'web') {}
  390. dialog_upload.value = false
  391. dialog_analysisInfo.value = true
  392. } catch (error) {
  393. console.log('解析失败', error)
  394. cardFileQuery.value = null
  395. } finally {
  396. analysisLoading.value = false
  397. }
  398. }
  399. // 简历解析
  400. const fileUrl = ref('') // https://minio.menduner.com/dev/person/229988673960153088/attachment/ee3eb21f45e13ede3557a03d18585ed80c5b4212ac5634e3436e309afaa8fe6a.pdf
  401. const uploadRef = ref()
  402. const fileList = ref([])
  403. const data = ref({ path: '' })
  404. // 文件上传
  405. const handleChange = async (file) => {
  406. data.value.path = file.name
  407. unref(uploadRef)?.submit()
  408. if (!fileList.value.length) return
  409. const url = fileList.value[0].response.data
  410. fileUrl.value = !url.includes('.pdf') ? `${baseUrl}/onlinePreview?url=${encodeURIComponent(Base64.encode(url))}` : url
  411. if (dialog_analysisInfo.value) {
  412. if (FormPageRef.value?.changeLoading) FormPageRef.value.changeLoading(true)
  413. message.warning('正在解析...')
  414. const data = await commonApi.resumeParser({ fileUrl: fileUrl.value })
  415. resumeAnalysisToForm(data) // 简历解析
  416. if (FormPageRef.value?.changeLoading) FormPageRef.value.changeLoading(false)
  417. }
  418. }
  419. const submitFormError = () => {
  420. message.error('上传失败,请您重新上传!')
  421. }
  422. const handleExceed = () => {
  423. message.error('最多只能上传一个文件!')
  424. }
  425. const submitFormSuccess = (e) => {
  426. // 清理
  427. // unref(uploadRef)?.clearFiles()
  428. }
  429. const drawer = ref(false)
  430. const resumeTxt = ref([])
  431. // 查看文本信息
  432. const handleText = () => {
  433. drawer.value = true
  434. }
  435. // 重新上传简历
  436. const handleResetUpload = async () => {
  437. await message.confirm('是否确定重新上传简历?确定后将清空当前信息')
  438. fileUrl.value = ''
  439. data.value.path = ''
  440. fileList.value = []
  441. resumeAnalysisToForm('reset') // 简历解析
  442. }
  443. const detailButTxt = '应用'
  444. // 搜索-查看详情
  445. const handleDetail = async (userId) => {
  446. if (!userId) return message.warning('请先选择人才!')
  447. try {
  448. const data = await TalentMap.getTalentMapDetail(userId)
  449. // 去除id
  450. resumeAnalysisToForm(data) // 简历解析
  451. message.success(`${detailButTxt}成功`)
  452. } catch {}
  453. }
  454. // 简历解析数据解构赋值
  455. const resumeAnalysisToForm = (data) => {
  456. if (data === 'reset') {
  457. // 重置表单
  458. resumeTxt.value = ''
  459. if (FormPageRef.value?.resetFormData) FormPageRef.value.resetFormData()
  460. }
  461. formData.value = {
  462. name_zh: data?.person?.name || '',
  463. email: data?.person?.email || '',
  464. mobile: data?.person?.phone || '',
  465. birthday: data?.person?.birthday ? timesTampChange(data.person.birthday, 'Y-M-D') : '',
  466. age: data?.person?.birthday ? timestampToAge(data.person.birthday) : null,
  467. career_path: data?.workList ? data.workList.map(e => {
  468. return {
  469. hotel_zh: e?.enterpriseName || null,
  470. title_zh: e?.positionName || null,
  471. date: e?.startTime ? timesTampChange(e.startTime, 'Y-M-D') : null
  472. }
  473. }) : null,
  474. created_at: data?.person?.createTime ? timesTampChange(data.person.createTime, 'Y-M-D') : null,
  475. updated_at: data?.person?.updateTime ? timesTampChange(data.person.updateTime, 'Y-M-D') : null,
  476. }
  477. resumeTxt.value = data?.resume?.rawText?.split('\n') || ''
  478. if (FormPageRef.value?.setFormData) FormPageRef.value.setFormData(formData.value)
  479. }
  480. // 名片解析
  481. const createAnalysisNum = ref(0)
  482. const cardFileQuery = ref(null)
  483. const cardUploadRow = ref(null)
  484. const cardImgUrl = ref(null)
  485. const cardUploadChange = (raw) => {
  486. cardUploadRow.value = raw
  487. }
  488. const DialogWidth = ref('500')
  489. const showWebAnalysis = ref(false)
  490. // 选择解析方式
  491. const handleSelect = () => {
  492. openSelect.value = false
  493. formData.value = null
  494. showWebAnalysis.value = false
  495. const type = radioValue.value
  496. if (type === 'card') {
  497. createAnalysisNum.value++
  498. }
  499. if (type === 'menduner') {
  500. dialog_analysisInfo.value = true
  501. return
  502. }
  503. if (type === 'web') {
  504. showWebAnalysis.value = true
  505. dialog_analysisInfo.value = true
  506. return
  507. }
  508. dialog_upload.value = true
  509. }
  510. // 关闭上传弹窗
  511. const handleCancel = () => {
  512. dialog_upload.value = false
  513. analysisLoading.value = false
  514. }
  515. const openSelect = ref(false)
  516. const radioObject = { card: '名片解析', file: '简历解析', web: '网页解析', menduner: '门墩儿人才库(普通新增)' }
  517. const radioList = ref(Object.keys(radioObject).map(key => ({ value: key, label: radioObject[key]}) ))
  518. const defaultValue = radioList.value[0].value // 默认选中
  519. const radioValue = ref(defaultValue)
  520. // 新增解析
  521. const handleAdd = () => {
  522. cardUploadRow.value = null
  523. cardImgUrl.value = null
  524. analysisLoading.value = false
  525. analysisType.value = 'create'
  526. radioValue.value = defaultValue // 重置解析类型
  527. //
  528. openSelect.value = true
  529. }
  530. /** 初始化 **/
  531. onMounted(() => {
  532. getList()
  533. })
  534. </script>
  535. <style lang="scss" scoped>
  536. .analysisInfoBox {
  537. display: flex;
  538. .analysisFile {
  539. width: 50%;
  540. max-height: 70vh;
  541. padding-right: 12px;
  542. overflow: auto;
  543. }
  544. }
  545. .radioBox {
  546. margin: 40px 0;
  547. }
  548. :deep(.drawer) {
  549. position: absolute;
  550. .el-drawer {
  551. background-color: aliceblue;
  552. }
  553. }
  554. </style>