index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="ss-p-b-100" style="height: 100vh; background-color: #f2f4f7;">
  3. <uni-notice-bar text="温馨提示:最多可以上传5份附件简历。请在手机上打开此小程序进行文件上传,暂不支持在桌面版小程序中上传文件。" />
  4. <view v-if="bioList?.length > 0">
  5. <view v-for="(item, index) in bioList" :key="index" class="default-border list-item">
  6. <view class="d-flex align-center">
  7. <view v-if="props.resumeAnalysis" class="ss-m-r-15">
  8. <radio :value="index" color="#00B760" :checked="index === checkedIndex" @tap="radioChange(index)" />
  9. </view>
  10. <view @click="preview(item.url)" style="flex: 1;">
  11. <view class="MiSans-Semibold" style="font-weight: bold;">{{ item.title }}</view>
  12. <view class="color-666 MiSans-Normal ss-m-t-10 font-size-14">上传时间:{{ timesTampChange(item.createTime, 'Y-M-D') }}</view>
  13. </view>
  14. <view class="ss-m-l-30" style="width: 60rpx;">
  15. <uni-icons @click="handleOpenPopup(item)" type="more-filled" size="20"></uni-icons>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view v-else class="nodata-img-parent">
  21. <image src="https://minio.menduner.com/dev/bb43df1dc91945e05ee93da76e49b34f87b0d10203eb76c20e2d4999a13b9a0a.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
  22. </view>
  23. <view class="bottom-sticky flex-column">
  24. <button v-if="props.resumeAnalysis" class="recomm-button" style="margin-bottom: 0; border-radius: 25px;" :loading="analysisLoading" @click="handleResumeAnalysis">开始解析</button>
  25. <button class="recomm-button MiSans-Medium" style="margin-bottom: 0; border-radius: 25px;" @click="handleUpload">微信聊天文件上传</button>
  26. <view class="color-primary font-size-14 ss-m-b-25 ss-m-t-10 MiSans-Normal" style="text-align: center;">上传文件大小不能超过20MB</view>
  27. </view>
  28. <uni-popup ref="popup" type="bottom">
  29. <button class="big-cancel-button MiSans-Normal" style="color: #666 !important;" @click="handleDelete">删除附件</button>
  30. <button class="big-cancel-button MiSans-Normal" @click="popup.close(); currentId = ''">取消</button>
  31. </uni-popup>
  32. </view>
  33. </template>
  34. <script setup>
  35. import { ref } from 'vue'
  36. import { getPersonResumeCv, saveResume, deleteResume } from '@/api/user'
  37. import { uploadFile } from '@/api/file'
  38. import { timesTampChange } from '@/utils/date'
  39. import { preview } from '@/utils/preview'
  40. const emit = defineEmits(['submit'])
  41. const props = defineProps({
  42. resumeAnalysis: { type: Boolean, default: false }
  43. })
  44. // 获取附件
  45. const bioList = ref([])
  46. const getList = async () => {
  47. uni.showLoading({ title: '加载中...' })
  48. try {
  49. const { data } = await getPersonResumeCv()
  50. bioList.value = data
  51. } catch {
  52. uni.hideLoading()
  53. } finally {
  54. uni.hideLoading()
  55. }
  56. }
  57. getList()
  58. // 更多
  59. const currentId = ref('')
  60. const popup = ref()
  61. const handleOpenPopup = (item) => {
  62. currentId.value = item.id
  63. popup.value.open()
  64. }
  65. // 删除附件
  66. const handleDelete = async () => {
  67. if (!currentId.value) return
  68. await deleteResume(currentId.value)
  69. uni.showToast({
  70. title: '删除成功',
  71. icon: 'success',
  72. duration: 2000
  73. })
  74. currentId.value = ''
  75. popup.value.close()
  76. getList()
  77. }
  78. // 上传附件
  79. const handleUpload = () => {
  80. if (bioList.value.length >= 5) {
  81. uni.showToast({
  82. icon: 'none',
  83. title: '最多可上传5份简历'
  84. })
  85. return
  86. }
  87. // 检查API是否可用
  88. if (typeof wx === 'undefined' || typeof wx.chooseMessageFile !== 'function') {
  89. uni.showToast({
  90. icon: 'none',
  91. title: '当前环境不支持文件选择功能',
  92. duration: 3000
  93. })
  94. return
  95. }
  96. console.log('开始调用wx.chooseMessageFile')
  97. wx.chooseMessageFile({
  98. count: 1,
  99. type: 'file',
  100. success (res) {
  101. console.log('文件选择成功:', res)
  102. // 检查返回结果
  103. if (!res || !res.tempFiles || !res.tempFiles.length) {
  104. uni.showToast({
  105. icon: 'none',
  106. title: '文件选择失败,请重试',
  107. duration: 2000
  108. })
  109. return
  110. }
  111. // 限制文件上传大小
  112. const size = res.tempFiles[0].size
  113. if (size / (1024*1024) > 20) {
  114. uni.showToast({ icon: 'none', title: '文件大小不能超过20M' })
  115. return
  116. }
  117. const title = res.tempFiles[0].name
  118. const path = res.tempFiles[0].path
  119. //效验是否为支持的文件格式
  120. if(/\.(pdf|docx|doc)$/.test(title)){
  121. // 显示上传进度
  122. uni.showLoading({
  123. title: '上传中...'
  124. })
  125. uploadFile(path, 'attachment').then(async (res) => {
  126. uni.hideLoading()
  127. if (!res.data) {
  128. uni.showToast({
  129. title: '上传失败',
  130. icon: 'none'
  131. })
  132. return
  133. }
  134. await saveResume({ title, url: res.data })
  135. uni.showToast({
  136. title: '上传成功',
  137. icon: 'success'
  138. })
  139. getList()
  140. }).catch(error => {
  141. uni.hideLoading()
  142. console.error('上传文件失败:', error)
  143. uni.showToast({
  144. title: '上传失败,请重试',
  145. icon: 'none',
  146. duration: 2000
  147. })
  148. })
  149. }else{
  150. uni.showToast({
  151. icon: 'none',
  152. title: '请上传pdf、doc、docx类型的文件',
  153. duration: 2000
  154. })
  155. return
  156. }
  157. },
  158. fail (error) {
  159. console.error('文件选择失败:', error)
  160. uni.showToast({
  161. icon: 'none',
  162. title: '文件选择失败,请检查权限设置或重试',
  163. duration: 3000
  164. })
  165. }
  166. })
  167. }
  168. const fileUrl = ref('')
  169. const checkedIndex = ref()
  170. const radioChange = (index) => {
  171. if (!props.resumeAnalysis) return
  172. checkedIndex.value = index
  173. if (bioList.value[index]?.url) fileUrl.value = encodeURIComponent(bioList.value[index].url)
  174. }
  175. const analysisLoading = ref(false)
  176. const handleResumeAnalysis = () => {
  177. if (!fileUrl.value) return uni.showToast({ icon: 'none', title: '请选择要解析的简历' })
  178. analysisLoading.value = true
  179. emit('submit', fileUrl.value)
  180. // uni.navigateTo({
  181. // url: `/pagesA/resumeAnalysis/index?fileUrl=${fileUrl.value}`
  182. // })
  183. }
  184. </script>
  185. <style scoped lang="scss">
  186. .list-item {
  187. margin: 30rpx;
  188. border-radius: 20rpx;
  189. padding: 30rpx;
  190. background-color: #fff;
  191. box-shadow: 1px 2px 12px rgba(0, 0, 0, 0.17);
  192. &:last-child {
  193. margin-bottom: 0;
  194. }
  195. &:first-child {
  196. margin-top: 0;
  197. }
  198. }
  199. </style>