From d8876c55b69bcf2fec04cf638b978d23aa265a87 Mon Sep 17 00:00:00 2001
From: liangping <18786721@qq.com>
Date: Sat, 31 May 2025 11:53:17 +0800
Subject: [PATCH] add reference
---
src/modules/[chain]/index.vue | 5 ++-
src/modules/[chain]/indexStore.ts | 53 ++++++++++++++++++++++++++-----
2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/src/modules/[chain]/index.vue b/src/modules/[chain]/index.vue
index 0a7b518c..f380f09b 100644
--- a/src/modules/[chain]/index.vue
+++ b/src/modules/[chain]/index.vue
@@ -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({
-
{{ $t('index.buy') }} {{ coinInfo.symbol || '' }}
diff --git a/src/modules/[chain]/indexStore.ts b/src/modules/[chain]/indexStore.ts
index 440c7e81..7a93f7f4 100644
--- a/src/modules/[chain]/indexStore.ts
+++ b/src/modules/[chain]/indexStore.ts
@@ -24,6 +24,13 @@ export function colorMap(color: string) {
}
}
+const CODEMAP: Record = {
+ "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
+}