enterpriseLogo.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!-- 企业LOGO -->
  2. <template>
  3. <div>
  4. <div class="topTip">温馨提示:上传企业LOGO,可以获得更多的关注,提升招聘效果哦!</div>
  5. <div class="logoBox d-flex py-4 align-center justify-center">
  6. <div class="mt-8">
  7. <div class="file-item mr-4" style="width: 130px;">
  8. <v-img v-if="squareImageUrl" width="100%" height="100%" :src="squareImageUrl"></v-img>
  9. <span v-else class="logo">LOGO</span>
  10. </div>
  11. <div class="d-flex flex-column justify-space-between">
  12. <div class="my-3">
  13. <div class="uploadPrompt">LOGO大小:130*130像素</div>
  14. <div class="uploadPrompt">仅支持JPG、JPEG、PNG常见图片类</div>
  15. <div class="uploadPrompt">型,且文件大于10M</div>
  16. </div>
  17. <div>
  18. <v-btn prepend-icon="mdi mdi-upload" color="primary" @click.stop="openFileInput">
  19. {{ $t('common.uploadPictures') }}
  20. <input
  21. type="file"
  22. ref="fileInput"
  23. accept="image/png, image/jpg, image/jpeg"
  24. style="display: none;"
  25. @change="handleUploadFile"
  26. />
  27. </v-btn>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <ImgCropper
  34. :visible="isShowCopper"
  35. :image="selectPic"
  36. :cropBoxResizable="true"
  37. @submit="handleHideCopper"
  38. :aspectRatio="1 / 1"
  39. @close="isShowCopper = false; selectPic = ''"
  40. ></ImgCropper>
  41. </template>
  42. <script setup>
  43. defineOptions({name: 'informationSettingsComponents-enterpriseLogo'})
  44. import { useUserStore } from '@/store/user'; const userStore = useUserStore()
  45. import { ref } from 'vue'
  46. import { uploadFile } from '@/api/common'
  47. import { useI18n } from '@/hooks/web/useI18n'
  48. import { updateEnterpriseLogo, getEnterpriseBaseInfo } from '@/api/enterprise'
  49. import Snackbar from '@/plugins/snackbar'
  50. const emit = defineEmits(['complete'])
  51. const { t } = useI18n()
  52. let squareImageUrl = ref('')
  53. const selectPic = ref('')
  54. const isShowCopper = ref(false)
  55. const getInfo = async () => {
  56. const data = await getEnterpriseBaseInfo()
  57. if (data && data?.logoUrl) {
  58. squareImageUrl.value = data.logoUrl
  59. // 完成度展示
  60. await userStore.getEnterpriseInfo() // 更新当前登录的企业用户信息
  61. }
  62. emit('complete', { status: Boolean(squareImageUrl.value), id: 'enterpriseLogo' })
  63. }
  64. getInfo()
  65. // 选择文件
  66. const fileInput = ref()
  67. const clicked = ref(false)
  68. const openFileInput = () => {
  69. if (clicked.value) return
  70. clicked.value = true
  71. fileInput.value.click()
  72. clicked.value = false
  73. }
  74. // 图片裁剪成功上传
  75. const handleHideCopper = (data) => {
  76. isShowCopper.value = false
  77. if (data) {
  78. const { file } = data
  79. if (!file) return
  80. const formData = new FormData()
  81. formData.append('file', file)
  82. uploadFile(formData).then(async ({ data }) => {
  83. if (!data) return
  84. Snackbar.success(t('common.uploadSucMsg'))
  85. await updateEnterpriseLogo(data)
  86. getInfo()
  87. })
  88. }
  89. }
  90. // 上传
  91. const typeList = ['png', 'jpg', 'jpeg']
  92. const handleUploadFile = async (e) => {
  93. if (!e.target.files.length) return
  94. const file = e.target.files[0]
  95. const size = file.size
  96. if (size / (1024*1024) > 10) {
  97. Snackbar.warning(t('common.fileSizeExceed'))
  98. return
  99. }
  100. const arr = file.name.split('.')
  101. if (typeList.indexOf(arr[arr.length - 1]) < 0) {
  102. Snackbar.warning(t('common.fileFormatIncorrect'))
  103. return
  104. }
  105. const reader = new FileReader()
  106. reader.onload = (e) => {
  107. const img = new Image()
  108. img.onload = async () => {
  109. if (img.width > 130 || img.height > 130) {
  110. selectPic.value = String(reader.result)
  111. isShowCopper.value = true
  112. return
  113. }
  114. // 大小符合直接上传logo
  115. const formData = new FormData()
  116. formData.append('file', file)
  117. const { data } = await uploadFile(formData)
  118. if (!data) return
  119. Snackbar.success(t('common.uploadSucMsg'))
  120. await updateEnterpriseLogo(data)
  121. getInfo()
  122. }
  123. img.src = e.target.result
  124. }
  125. reader.readAsDataURL(file)
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .topTip {
  130. background-color: #f7f8fa;
  131. color: #2f3640;
  132. padding: 12px 20px;
  133. margin: 10px 0 20px;
  134. font-size: 14px;
  135. }
  136. .uploadPrompt { font-size: 14px; line-height: 24px; }
  137. .logoBox {
  138. .typeTitle {
  139. font-weight: bold;
  140. }
  141. }
  142. .file-item {
  143. height: 130px;
  144. border-radius: 5px;
  145. margin-right: 8px;
  146. border: 1px solid rgba(188, 188, 188, 0.5);
  147. text-align: center;
  148. .logo {
  149. font-size: 38px;
  150. font-weight: 900;
  151. color: rgba(188, 188, 188, 0.65);
  152. height: 100%;
  153. line-height: 130px;
  154. }
  155. }
  156. </style>