enterpriseLogo.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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大小:200*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. </template>
  34. <script setup>
  35. defineOptions({name: 'informationSettingsComponents-enterpriseLogo'})
  36. import { ref } from 'vue'
  37. import { uploadFile } from '@/api/common'
  38. import { useI18n } from '@/hooks/web/useI18n'
  39. import { updateEnterpriseLogo, getEnterpriseBaseInfo } from '@/api/enterprise'
  40. import Snackbar from '@/plugins/snackbar'
  41. const { t } = useI18n()
  42. let squareImageUrl = ref('')
  43. const getInfo = async () => {
  44. const data = await getEnterpriseBaseInfo()
  45. if (data && data?.logoUrl) squareImageUrl.value = data.logoUrl
  46. }
  47. getInfo()
  48. // 选择文件
  49. const fileInput = ref()
  50. const clicked = ref(false)
  51. const openFileInput = () => {
  52. if (clicked.value) return
  53. clicked.value = true
  54. fileInput.value.click()
  55. clicked.value = false
  56. }
  57. // 上传
  58. const typeList = ['png', 'jpg', 'jpeg']
  59. const handleUploadFile = async (e) => {
  60. const file = e.target.files[0]
  61. const size = file.size
  62. if (size / (1024*1024) > 10) {
  63. Snackbar.warning(t('common.fileSizeExceed'))
  64. return
  65. }
  66. const arr = file.name.split('.')
  67. if (typeList.indexOf(arr[arr.length - 1]) < 0) {
  68. Snackbar.warning(t('common.fileFormatIncorrect'))
  69. return
  70. }
  71. const formData = new FormData()
  72. formData.append('file', file)
  73. const { data } = await uploadFile(formData)
  74. if (!data) return
  75. Snackbar.success(t('common.uploadSucMsg'))
  76. await updateEnterpriseLogo(data)
  77. getInfo()
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .topTip {
  82. background-color: #f7f8fa;
  83. color: #2f3640;
  84. padding: 12px 20px;
  85. margin: 10px 0 20px;
  86. font-size: 14px;
  87. }
  88. .uploadPrompt { font-size: 14px; line-height: 24px; }
  89. .logoBox {
  90. .typeTitle {
  91. font-weight: bold;
  92. }
  93. }
  94. .file-item {
  95. height: 130px;
  96. border-radius: 5px;
  97. margin-right: 8px;
  98. border: 1px solid rgba(188, 188, 188, 0.5);
  99. text-align: center;
  100. .logo {
  101. font-size: 38px;
  102. font-weight: 900;
  103. color: rgba(188, 188, 188, 0.65);
  104. height: 100%;
  105. line-height: 130px;
  106. }
  107. }
  108. </style>