enterpriseLogo.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. <ImgCropper
  33. :visible="isShowCopper"
  34. :image="selectPic"
  35. :cropBoxResizable="true"
  36. @submit="handleHideCopper"
  37. :aspectRatio="1 / 1"
  38. @close="isShowCopper = false; selectPic = ''"
  39. ></ImgCropper>
  40. </div>
  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', {
  63. totalCount: 10,
  64. completeCount: squareImageUrl?.value ? 10 : 0,
  65. id: 'enterpriseLogo'
  66. })
  67. }
  68. getInfo()
  69. // 选择文件
  70. const fileInput = ref()
  71. const clicked = ref(false)
  72. const openFileInput = () => {
  73. if (clicked.value) return
  74. clicked.value = true
  75. fileInput.value.click()
  76. clicked.value = false
  77. }
  78. // 图片裁剪成功上传
  79. const handleHideCopper = (data) => {
  80. isShowCopper.value = false
  81. if (data) {
  82. const { file } = data
  83. if (!file) return
  84. const formData = new FormData()
  85. formData.append('file', file)
  86. formData.append('path', 'img')
  87. uploadFile(formData).then(async ({ data }) => {
  88. if (!data) return
  89. Snackbar.success(t('common.uploadSucMsg'))
  90. await updateEnterpriseLogo(data)
  91. getInfo()
  92. })
  93. }
  94. }
  95. // 上传
  96. const typeList = ['jpg', 'png', 'jpeg']
  97. const handleUploadFile = async (e) => {
  98. if (!e.target.files.length) return
  99. const file = e.target.files[0]
  100. const size = file.size
  101. if (size / (1024*1024) > 20) {
  102. Snackbar.warning(t('common.fileSizeExceed'))
  103. return
  104. }
  105. const arr = file.name.split('.')
  106. if (typeList.indexOf(arr[arr.length - 1]) < 0) {
  107. Snackbar.warning(t('common.fileFormatIncorrect'))
  108. return
  109. }
  110. const reader = new FileReader()
  111. reader.onload = (e) => {
  112. const img = new Image()
  113. img.onload = async () => {
  114. if (img.width > 130 || img.height > 130) {
  115. selectPic.value = String(reader.result)
  116. isShowCopper.value = true
  117. return
  118. }
  119. // 大小符合直接上传logo
  120. const formData = new FormData()
  121. formData.append('file', file)
  122. formData.append('path', 'img')
  123. const { data } = await uploadFile(formData)
  124. if (!data) return
  125. Snackbar.success(t('common.uploadSucMsg'))
  126. await updateEnterpriseLogo(data)
  127. getInfo()
  128. }
  129. img.src = e.target.result
  130. }
  131. reader.readAsDataURL(file)
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .topTip {
  136. background-color: #f7f8fa;
  137. color: #2f3640;
  138. padding: 12px 20px;
  139. margin: 10px 0 20px;
  140. font-size: 14px;
  141. }
  142. .uploadPrompt { font-size: 14px; line-height: 24px; }
  143. .logoBox {
  144. .typeTitle {
  145. font-weight: bold;
  146. }
  147. }
  148. .file-item {
  149. height: 130px;
  150. border-radius: 5px;
  151. margin-right: 8px;
  152. border: 1px solid rgba(188, 188, 188, 0.5);
  153. text-align: center;
  154. .logo {
  155. font-size: 38px;
  156. font-weight: 900;
  157. color: rgba(188, 188, 188, 0.65);
  158. height: 100%;
  159. line-height: 130px;
  160. }
  161. }
  162. </style>