add reference

This commit is contained in:
liangping 2025-05-31 11:53:17 +08:00
parent d61287abb6
commit d8876c55b6
2 changed files with 47 additions and 11 deletions

View File

@ -12,13 +12,12 @@ import {
useParamStore,
} from '@/stores';
import { onMounted, ref } from 'vue';
import { useIndexModule, colorMap } from './indexStore';
import { useIndexModule, colorMap, tickerUrl } from './indexStore';
import { computed } from '@vue/reactivity';
import CardStatisticsVertical from '@/components/CardStatisticsVertical.vue';
import ProposalListItem from '@/components/ProposalListItem.vue';
import ArrayObjectElement from '@/components/dynamic/ArrayObjectElement.vue'
import AdBanner from '@/components/ad/AdBanner.vue';
const props = defineProps(['chain']);
@ -233,7 +232,7 @@ const amount = computed({
</div>
<label class="modal-backdrop" for="calculator">{{ $t('index.close') }}</label>
</div>
<a class="my-5 !text-white btn grow" :class="{'!btn-success': store.trustColor === 'green', '!btn-warning': store.trustColor === 'yellow'}" :href="ticker.trade_url"
<a class="my-5 !text-white btn grow" :class="{'!btn-success': store.trustColor === 'green', '!btn-warning': store.trustColor === 'yellow'}" :href="tickerUrl(ticker.trade_url)"
target="_blank">
{{ $t('index.buy') }} {{ coinInfo.symbol || '' }}
</a>

View File

@ -24,6 +24,13 @@ export function colorMap(color: string) {
}
}
const CODEMAP: Record<string, string[]> = {
"binance.com": ["ref", "CPA_004JZGRX6A"],
"gate.com": ["ref", "U1gVBl9a"],
"bybit": ["affiliate_id", "JKRRZX9"],
}
export const useIndexModule = defineStore('module-index', {
state: () => {
return {
@ -87,33 +94,33 @@ export const useIndexModule = defineStore('module-index', {
return useBankStore();
},
twitter(): string {
if(!this.coinInfo?.links?.twitter_screen_name) return ""
if (!this.coinInfo?.links?.twitter_screen_name) return ""
return `https://twitter.com/${this.coinInfo?.links.twitter_screen_name}`;
},
homepage(): string {
if(!this.coinInfo?.links?.homepage) return ""
if (!this.coinInfo?.links?.homepage) return ""
const [page1, page2, page3] = this.coinInfo?.links?.homepage;
return page1 || page2 || page3;
},
github(): string {
if(!this.coinInfo?.links?.repos_url) return ""
if (!this.coinInfo?.links?.repos_url) return ""
const [page1, page2, page3] = this.coinInfo?.links?.repos_url?.github;
return page1 || page2 || page3;
},
telegram(): string {
if(!this.coinInfo?.links?.homepage) return ""
if (!this.coinInfo?.links?.homepage) return ""
return `https://t.me/${this.coinInfo?.links.telegram_channel_identifier}`;
},
priceChange(): string {
if(!this.coinInfo?.market_data?.price_change_percentage_24h) return ""
if (!this.coinInfo?.market_data?.price_change_percentage_24h) return ""
const change =
this.coinInfo?.market_data?.price_change_percentage_24h || 0;
return numeral(change).format('+0.[00]');
},
priceColor(): string {
if(!this.coinInfo?.market_data?.price_change_percentage_24h) return ""
if (!this.coinInfo?.market_data?.price_change_percentage_24h) return ""
const change =
this.coinInfo?.market_data?.price_change_percentage_24h || 0;
switch (true) {
@ -126,7 +133,7 @@ export const useIndexModule = defineStore('module-index', {
}
},
trustColor(): string {
if(!this.coinInfo?.tickers) return ""
if (!this.coinInfo?.tickers) return ""
const change = this.coinInfo?.tickers[this.tickerIndex]?.trust_score;
return change;
},
@ -239,6 +246,7 @@ export const useIndexModule = defineStore('module-index', {
if (firstAsset && firstAsset.coingecko_id) {
this.coingecko.getCoinInfo(firstAsset.coingecko_id).then((x) => {
this.coinInfo = x;
// this.coinInfo.tickers.sort((a, b) => a.converted_last.usd - b.converted_last.usd)
});
this.coingecko
.getMarketChart(this.days, firstAsset.coingecko_id)
@ -249,6 +257,35 @@ export const useIndexModule = defineStore('module-index', {
},
selectTicker(i: number) {
this.tickerIndex = i;
},
}
},
});
/**
* Adds or replaces a query parameter in the provided URL.
* @param url - The base URL.
* @param param - The name of the parameter to add or replace.
* @param value - The value to set for the parameter.
* @returns The new URL with the parameter added or replaced.
*/
export function addOrReplaceUrlParam(url: string, param: string, value: string): string {
// Parse the URL
const urlObj = new URL(url, window.location.origin);
// Set (add or replace) the query parameter
urlObj.searchParams.set(param, value);
// Return the string representation of the new URL
return urlObj.toString();
}
export function tickerUrl(url: string) {
for (const domain of Object.keys(CODEMAP)) {
if (url.indexOf(domain) > -1) {
const v = CODEMAP[domain];
return addOrReplaceUrlParam(url, v[0], v[1])
}
}
return url
}