h-usersite/angular/src/app/pages/account/ref-system/ref-system.component.ts
gofnnp 9b3488775c dev #14600
изменил названия для новой ветки
2023-06-28 11:56:16 +04:00

72 lines
1.8 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import * as barcode from 'jsbarcode';
import { MessageService } from 'primeng/api';
import { lastValueFrom } from 'rxjs';
import { JsonrpcService, RpcService } from 'src/app/services/jsonrpc.service';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-ref-system',
templateUrl: './ref-system.component.html',
styleUrls: ['./ref-system.component.scss']
})
export class RefSystemComponent implements OnInit {
public refUrl: string = `${environment.defaultUrl}/?refUserId=`
public loading: boolean = true;
constructor(
private jsonrpc: JsonrpcService,
private messageService: MessageService
) { }
async ngOnInit() {
const accountData = (await lastValueFrom(
this.jsonrpc
.rpc(
{
method: 'getTokenData',
params: [],
},
RpcService.authService,
true
)
)).data
this.refUrl += accountData.user_id
this.loading = false
}
share() {
if (navigator.share) {
navigator.share({
title: document.title,
text: "Coffee Like More",
url: this.refUrl
})
.then(() => console.log('Successful share'))
.catch((error) => {
console.log('Error sharing:', error)
});
}
}
copyUrl() {
navigator.clipboard.writeText(this.refUrl)
.then(() => {
this.messageService.clear();
this.messageService.add({
severity: 'custom',
summary: 'Ссылка скопирована!',
});
})
.catch(err => {
this.messageService.clear();
this.messageService.add({
severity: 'error',
summary: 'Произошла ошибка!',
});
});
}
}