index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. <uni-card v-for="(item, index) in bioList" :key="index" :is-shadow="true" :border='false' shadow="0px 0px 3px 1px rgba(0,0,0,0.1)">
  6. <view class="d-flex align-center">
  7. <view @click="preview(item.url)" style="flex: 1;">
  8. <view class="font-size-14" style="font-weight: bold;">{{ item.title }}</view>
  9. <view>上传时间:{{ timesTampChange(item.createTime, 'Y-M-D') }}</view>
  10. </view>
  11. <view class="ss-m-l-30" style="width: 60rpx;">
  12. <uni-icons @click="handleOpenPopup(item)" type="more-filled" size="20"></uni-icons>
  13. </view>
  14. </view>
  15. </uni-card>
  16. </view>
  17. <view v-else class="nodata-img-parent">
  18. <image src="https://minio.citupro.com/dev/static/nodata.png" mode="widthFix" style="width: 100vw;height: 100vh;"></image>
  19. </view>
  20. <view class="bottom-sticky flex-column">
  21. <button class="recomm-button" style="margin-bottom: 0;" @click="handleUpload">微信聊天文件上传</button>
  22. <view class="color-primary font-size-14 ss-m-b-25 ss-m-t-10" style="text-align: center;">上传文件大小不能超过20MB</view>
  23. </view>
  24. <uni-popup ref="popup" type="bottom">
  25. <button class="big-cancel-button" style="color: #333 !important;" @click="handleDelete">删除附件</button>
  26. <button class="big-cancel-button" @click="popup.close(); currentId = ''">取消</button>
  27. </uni-popup>
  28. </view>
  29. </template>
  30. <script setup>
  31. import { ref } from 'vue'
  32. import { getPersonResumeCv, saveResume, deleteResume } from '@/api/user'
  33. import { uploadFile } from '@/api/file'
  34. import { timesTampChange } from '@/utils/date'
  35. import { preview } from '@/utils/preview'
  36. // 获取附件
  37. const bioList = ref([])
  38. const getList = async () => {
  39. const { data } = await getPersonResumeCv()
  40. bioList.value = data
  41. }
  42. getList()
  43. // 更多
  44. const currentId = ref('')
  45. const popup = ref()
  46. const handleOpenPopup = (item) => {
  47. currentId.value = item.id
  48. popup.value.open()
  49. }
  50. // 删除附件
  51. const handleDelete = async () => {
  52. if (!currentId.value) return
  53. await deleteResume(currentId.value)
  54. uni.showToast({
  55. title: '删除成功',
  56. icon: 'success',
  57. duration: 2000
  58. })
  59. currentId.value = ''
  60. popup.value.close()
  61. getList()
  62. }
  63. // 上传附件
  64. const handleUpload = () => {
  65. if (bioList.value.length >= 5) {
  66. uni.showToast({
  67. icon: 'none',
  68. title: '最多可上传5份简历'
  69. })
  70. return
  71. }
  72. wx.chooseMessageFile({
  73. count: 1,
  74. type: 'file',
  75. success (res) {
  76. // 限制文件上传大小
  77. const size = res.tempFiles[0].size
  78. if (size / (1024*1024) > 20) {
  79. uni.showToast({ icon: 'none', title: '文件大小不能超过20M' })
  80. return
  81. }
  82. const title = res.tempFiles[0].name
  83. const path = res.tempFiles[0].path
  84. //效验是否为支持的文件格式
  85. if(/\.(pdf|docx|doc)$/.test(title)){
  86. uploadFile(path, 'attachment').then(async (res) => {
  87. if (!res.data) {
  88. uni.showToast({
  89. title: '上传失败',
  90. icon: 'none'
  91. })
  92. return
  93. }
  94. await saveResume({ title, url: res.data })
  95. uni.showToast({
  96. title: '上传成功',
  97. icon: 'success'
  98. })
  99. getList()
  100. })
  101. }else{
  102. uni.showToast({
  103. icon: 'none',
  104. title: '请上传pdf、doc、docx类型的文件',
  105. duration: 2000
  106. })
  107. return
  108. }
  109. }
  110. })
  111. }
  112. </script>
  113. <style scoped lang="scss">
  114. </style>