1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <!-- 发起邀请 -->
- <template>
- <div style="font-size: 14px;">
- <div class="mt-5 color-777">将下面的公共邀请链接通过微信、00等任何方式发给同事,即可点击加入公司。请注意,用户同意后将自动加入到团队中,您需确保添加到的同事为同一公司招聘人员</div>
- <div class="mt-5 d-flex align-center">
- <div class="mr-5 shareUrlTxt">
- {{ shareUrlTxt }}
- </div>
- <v-btn color="primary" class="mr-3" @click="copy()">{{ $t('common.copy') }}</v-btn>
- <v-btn color="green" variant="outlined" @click="refresh()">{{ $t('common.refresh') }}</v-btn>
- </div>
- <div class="mt-5 color-777">链接{{ day }}天内有效</div>
- </div>
- </template>
- <script setup>
- import Snackbar from '@/plugins/snackbar'
- import {
- enterpriseInviteGenerateCode,
- enterpriseInviteGetCode,
- enterpriseInviteRefresh,
- } from '@/api/recruit/enterprise/enterpriseInvite.js'
- import { computed, ref } from 'vue'
- defineOptions({name: 'groupAccount-component-invite'})
- const props = defineProps({
- inviteType: {
- type: String,
- default: '0' // 类型(0 邀请同事 | 1 邀请子公司),示例值(2)
- }
- })
- const day = 30
- const code = ref('')
- const accessUrl = import.meta.env.VITE_ACCESS_BASE_URL
- // const shareUrlTxt = ref(accessUrl + '/groupAccount/add?code=' + code.value )
- const shareUrlTxt = computed(() => {
- return accessUrl + '/invite?code=' + code.value
- })
- // 逻辑:
- // 1.页面加载时: 是否已有-> 有:直接调用获取邀请码。 没有:有生成邀请码标识->获取邀请码
- // 2.刷新: 调用刷新邀请码接口->生成邀请码标识->获取邀请码
- // 获取邀请码
- const getCode = async (type) => {
- try {
- const data = await enterpriseInviteGetCode({ type: props.inviteType })
- if (!data) getGenerateCode()
- code.value = data
- if (type === 'refresh') Snackbar.success('刷新成功')
- } catch (err) {
- console.err(err)
- }
- }
- getCode()
- // 生成邀请码标识
- const getGenerateCode = async (type) => {
- try {
- const data = await enterpriseInviteGenerateCode({ type: props.inviteType, expireDay: 30 })
- if (!data) console.err('生成邀请码标识失败')
- getCode(type)
- } catch (err) {
- console.err(err)
- }
- }
- // 刷新邀请码
- const refresh = async () => {
- try {
- await enterpriseInviteRefresh({ code: code.value })
- getGenerateCode('refresh')
- } catch (err) {
- console.err(err)
- }
- }
- const copy = async () => {
- try {
- await navigator.clipboard.writeText(shareUrlTxt.value)
- Snackbar.success('复制成功')
- } catch (err) {
- Snackbar.error('复制失败,请手动复制。')
- }
- }
- </script>
- <style lang="scss" scoped>
- .shareUrlTxt {
- line-height: 30px;
- background-color: #f0f0f0;
- // border-radius: 5px;
- padding: 6px 16px;
- }
- </style>
|