invite.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!-- 发起邀请 -->
  2. <template>
  3. <div style="font-size: 14px;">
  4. <div class="mt-5 color-777">将下面的公共邀请链接通过微信、00等任何方式发给同事,即可点击加入公司。请注意,用户同意后将自动加入到团队中,您需确保添加到的同事为同一公司招聘人员</div>
  5. <div class="mt-5 d-flex align-center">
  6. <div class="mr-5 shareUrlTxt">
  7. {{ shareUrlTxt }}
  8. </div>
  9. <v-btn color="primary" class="mr-3" @click="copy()">{{ $t('common.copy') }}</v-btn>
  10. <v-btn color="green" variant="outlined" @click="refresh()">{{ $t('common.refresh') }}</v-btn>
  11. </div>
  12. <div class="mt-5 color-777">链接{{ day }}天内有效</div>
  13. </div>
  14. </template>
  15. <script setup>
  16. import Snackbar from '@/plugins/snackbar'
  17. import {
  18. enterpriseInviteGenerateCode,
  19. enterpriseInviteGetCode,
  20. enterpriseInviteRefresh,
  21. } from '@/api/recruit/enterprise/enterpriseInvite.js'
  22. import { computed, ref } from 'vue'
  23. defineOptions({name: 'groupAccount-component-invite'})
  24. const props = defineProps({
  25. inviteType: {
  26. type: String,
  27. default: '0' // 类型(0 邀请同事 | 1 邀请子公司),示例值(2)
  28. }
  29. })
  30. const day = 30
  31. const code = ref('')
  32. const accessUrl = import.meta.env.VITE_ACCESS_BASE_URL
  33. // const shareUrlTxt = ref(accessUrl + '/groupAccount/add?code=' + code.value )
  34. const shareUrlTxt = computed(() => {
  35. return accessUrl + '/invite?code=' + code.value
  36. })
  37. // 逻辑:
  38. // 1.页面加载时: 是否已有-> 有:直接调用获取邀请码。 没有:有生成邀请码标识->获取邀请码
  39. // 2.刷新: 调用刷新邀请码接口->生成邀请码标识->获取邀请码
  40. // 获取邀请码
  41. const getCode = async (type) => {
  42. try {
  43. const data = await enterpriseInviteGetCode({ type: props.inviteType })
  44. if (!data) getGenerateCode()
  45. code.value = data
  46. if (type === 'refresh') Snackbar.success('刷新成功')
  47. } catch (err) {
  48. console.err(err)
  49. }
  50. }
  51. getCode()
  52. // 生成邀请码标识
  53. const getGenerateCode = async (type) => {
  54. try {
  55. const data = await enterpriseInviteGenerateCode({ type: props.inviteType, expireDay: 30 })
  56. if (!data) console.err('生成邀请码标识失败')
  57. getCode(type)
  58. } catch (err) {
  59. console.err(err)
  60. }
  61. }
  62. // 刷新邀请码
  63. const refresh = async () => {
  64. try {
  65. await enterpriseInviteRefresh({ code: code.value })
  66. getGenerateCode('refresh')
  67. } catch (err) {
  68. console.err(err)
  69. }
  70. }
  71. const copy = async () => {
  72. try {
  73. await navigator.clipboard.writeText(shareUrlTxt.value)
  74. Snackbar.success('复制成功')
  75. } catch (err) {
  76. Snackbar.error('复制失败,请手动复制。')
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .shareUrlTxt {
  82. line-height: 30px;
  83. background-color: #f0f0f0;
  84. // border-radius: 5px;
  85. padding: 6px 16px;
  86. }
  87. </style>