소스 검색

feat: 数字过滤

ljc 2 주 전
부모
커밋
b3f47ac5e9
8개의 변경된 파일63개의 추가작업 그리고 76개의 파일을 삭제
  1. 7 19
      components/cwg-payment.vue
  2. 7 15
      components/cwg-sidebar.vue
  3. 27 17
      composables/useFilters.ts
  4. 2 2
      config/index.ts
  5. 4 4
      pages/customer/components/AccountList.vue
  6. 3 3
      pages/customer/dashboard.vue
  7. 11 11
      pages/ib/complexReport.vue
  8. 2 5
      pages/ib/index.vue

+ 7 - 19
components/cwg-payment.vue

@@ -71,18 +71,16 @@
 
 
 <script setup lang="ts">
 <script setup lang="ts">
 import { computed, ref, onMounted, onUnmounted, watch } from 'vue'
 import { computed, ref, onMounted, onUnmounted, watch } from 'vue'
-import { newsApi } from '@/service/news'
-import { storeToRefs } from 'pinia'
 import useRouter from '@/hooks/useRouter'
 import useRouter from '@/hooks/useRouter'
 import { drawApi } from '@/service/draw'
 import { drawApi } from '@/service/draw'
 import { useI18n } from 'vue-i18n'
 import { useI18n } from 'vue-i18n'
 import { useMenuSplit } from '@/composables/useMenuSplit'
 import { useMenuSplit } from '@/composables/useMenuSplit'
 import useUserStore from '@/stores/use-user-store'
 import useUserStore from '@/stores/use-user-store'
 import { userToken } from '@/composables/config'
 import { userToken } from '@/composables/config'
-import { onLoad } from '@dcloudio/uni-app'
 import { ibApi } from '@/service/ib'
 import { ibApi } from '@/service/ib'
 import { documentaryApi } from '@/service/documentary'
 import { documentaryApi } from '@/service/documentary'
-
+import { useFilters } from '@/composables/useFilters'
+const {  numberDecimal } = useFilters()
 const { mode } = useMenuSplit()
 const { mode } = useMenuSplit()
 
 
 const { t, locale } = useI18n()
 const { t, locale } = useI18n()
@@ -101,16 +99,6 @@ const walletData = ref({})
 const handleMenuClick = ({ value }) => {
 const handleMenuClick = ({ value }) => {
   goPages(value)
   goPages(value)
 }
 }
-const NumberDecimal = (value) => {
-  let realVal = ''
-  if (!isNaN(value) && value !== '') {
-    // 截取当前数据到小数点后两位
-    realVal = value// parseFloat(value).toFixed(2)
-  } else {
-    realVal = '0'
-  }
-  return realVal
-}
 const NumberDesensitization = (value) => {
 const NumberDesensitization = (value) => {
   let realVal = ''
   let realVal = ''
   if (!isNaN(value) && value !== '') {
   if (!isNaN(value) && value !== '') {
@@ -126,27 +114,27 @@ const walletbalance = ref(0)
 const pendingWithdrawAmount = ref(0)
 const pendingWithdrawAmount = ref(0)
 const formattedBalance = computed(() => {
 const formattedBalance = computed(() => {
   const value = walletbalance.value || '0'
   const value = walletbalance.value || '0'
-  const decimalValue = NumberDecimal(value)
+  const decimalValue = numberDecimal(value)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
 })
 })
 const formattedPendingWithdrawAmount = computed(() => {
 const formattedPendingWithdrawAmount = computed(() => {
   const value = pendingWithdrawAmount.value || '0'
   const value = pendingWithdrawAmount.value || '0'
-  const decimalValue = NumberDecimal(value)
+  const decimalValue = numberDecimal(value)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
 })
 })
 
 
 //ib金额
 //ib金额
 const ibBalance = computed(() => {
 const ibBalance = computed(() => {
-  const value = NumberDecimal(ibData.value?.balance || 0)
+  const value = numberDecimal(ibData.value?.balance || 0)
   return isShow.value ? value : NumberDesensitization(value)
   return isShow.value ? value : NumberDesensitization(value)
 })
 })
 const ibTotalBalance = computed(() => {
 const ibTotalBalance = computed(() => {
-  const value = NumberDecimal(ibData.value?.all || 0)
+  const value = numberDecimal(ibData.value?.all || 0)
   return isShow.value ? value : NumberDesensitization(value)
   return isShow.value ? value : NumberDesensitization(value)
 })
 })
 // 跟单
 // 跟单
 const followBalance = computed(() => {
 const followBalance = computed(() => {
-  const value = NumberDecimal(walletData.value?.walletAmount || 0)
+  const value = numberDecimal(walletData.value?.walletAmount || 0)
   return isShow.value ? value : NumberDesensitization(value)
   return isShow.value ? value : NumberDesensitization(value)
 })
 })
 const getWalletList = async () => {
 const getWalletList = async () => {

+ 7 - 15
components/cwg-sidebar.vue

@@ -110,6 +110,8 @@ import { useI18n } from 'vue-i18n'
 import { documentaryApi } from '@/service/documentary'
 import { documentaryApi } from '@/service/documentary'
 import useGlobalStore from '@/stores/use-global-store'
 import useGlobalStore from '@/stores/use-global-store'
 const globalStore = useGlobalStore()
 const globalStore = useGlobalStore()
+import { useFilters } from '@/composables/useFilters'
+const {  numberDecimal } = useFilters()
 const isDark = computed(() => globalStore.theme === 'dark')
 const isDark = computed(() => globalStore.theme === 'dark')
 
 
 const { t } = useI18n()
 const { t } = useI18n()
@@ -135,16 +137,6 @@ const walletbalance = ref(0)
 const pendingWithdrawAmount = ref(0)
 const pendingWithdrawAmount = ref(0)
 const ibData = ref({} as any)
 const ibData = ref({} as any)
 const walletData = ref({} as any)
 const walletData = ref({} as any)
-
-const NumberDecimal = (value: any) => {
-  let realVal = ''
-  if (!isNaN(value) && value !== '') {
-    realVal = value// parseFloat(value).toFixed(2)
-  } else {
-    realVal = '0.00'
-  }
-  return realVal
-}
 const NumberDesensitization = (value: any) => {
 const NumberDesensitization = (value: any) => {
   let realVal = ''
   let realVal = ''
   if (!isNaN(value) && value !== '') {
   if (!isNaN(value) && value !== '') {
@@ -158,28 +150,28 @@ const NumberDesensitization = (value: any) => {
 
 
 const formattedBalance = computed(() => {
 const formattedBalance = computed(() => {
   const value = walletbalance.value || '0'
   const value = walletbalance.value || '0'
-  const decimalValue = NumberDecimal(value)
+  const decimalValue = numberDecimal(value)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
 })
 })
 
 
 const ibBalance = computed(() => {
 const ibBalance = computed(() => {
-  const value = NumberDecimal(ibData.value?.balance || 0)
+  const value = numberDecimal(ibData.value?.balance || 0)
   return isShow.value ? value : NumberDesensitization(value)
   return isShow.value ? value : NumberDesensitization(value)
 })
 })
 
 
 const formattedPendingWithdrawAmount = computed(() => {
 const formattedPendingWithdrawAmount = computed(() => {
   const value = pendingWithdrawAmount.value || '0'
   const value = pendingWithdrawAmount.value || '0'
-  const decimalValue = NumberDecimal(value)
+  const decimalValue = numberDecimal(value)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
   return isShow.value ? decimalValue : NumberDesensitization(decimalValue)
 })
 })
 
 
 const ibTotalBalance = computed(() => {
 const ibTotalBalance = computed(() => {
-  const value = NumberDecimal(ibData.value?.all || 0)
+  const value = numberDecimal(ibData.value?.all || 0)
   return isShow.value ? value : NumberDesensitization(value)
   return isShow.value ? value : NumberDesensitization(value)
 })
 })
 // 跟单分润
 // 跟单分润
 const followBalance = computed(() => {
 const followBalance = computed(() => {
-  const value = NumberDecimal(walletData.value?.walletAmount || 0)
+  const value = numberDecimal(walletData.value?.walletAmount || 0)
   return isShow.value ? value : NumberDesensitization(value)
   return isShow.value ? value : NumberDesensitization(value)
 })
 })
 const getWalletList = async () => {
 const getWalletList = async () => {

+ 27 - 17
composables/useFilters.ts

@@ -3,7 +3,7 @@ interface Filters {
     numberFormat: (value: number | string) => string;
     numberFormat: (value: number | string) => string;
     numberFormat1: (value: number | string) => string;
     numberFormat1: (value: number | string) => string;
     pwdFormat: (value: string | number | null | undefined) => string;
     pwdFormat: (value: string | number | null | undefined) => string;
-    numberDecimal: (value: number | string) => string;
+    numberDecimal: (value: number | string, decimalPlaces?: number) => string;
     numberDesensitization: (value: number | string) => string;
     numberDesensitization: (value: number | string) => string;
     numberDesensitization1: (value: number | string) => string;
     numberDesensitization1: (value: number | string) => string;
 }
 }
@@ -31,27 +31,27 @@ export function useFilters(): Filters {
     /**
     /**
      * 数字千分位格式化(支持负数)
      * 数字千分位格式化(支持负数)
      * @param {number | string} value - 要格式化的数字或字符串
      * @param {number | string} value - 要格式化的数字或字符串
-     * @param {boolean} toArray - 是否转化为数组,默认值为false
+     * @param decimalPlaces 保留的小数位数,默认为2
      * @returns {string} 格式化后的字符串
      * @returns {string} 格式化后的字符串
      */
      */
-    const numberFormat = (value: number | string,toArray:boolean = false): string[] | string => {
+    const numberFormat = (value: number | string,decimalPlaces:number = 2): string[] | string => {
         if (value == '***') {
         if (value == '***') {
             return '***';
             return '***';
         }
         }
-        if (isNaN(Number(value))) {
-            return '0';
+        if (isNaN(Number(value))||!value ) {
+            return '0.00';
         }
         }
 
 
         // let value1 = Number(value).toFixed(2)
         // let value1 = Number(value).toFixed(2)
-      let value1 = value.toString();
-        
+      let value1 = numberDecimal(value,decimalPlaces);
+      console.log(value1)
         if (value1.indexOf('-') > -1) {
         if (value1.indexOf('-') > -1) {
             value1 = value1.split('-')[1];
             value1 = value1.split('-')[1];
             let num = value1.split('.');
             let num = value1.split('.');
             let interCount = num[0].length;
             let interCount = num[0].length;
             
             
             if (interCount < 3) {
             if (interCount < 3) {
-                return String(value);
+                return numberDecimal(value,decimalPlaces);
             }
             }
             
             
             let index = 0;
             let index = 0;
@@ -70,7 +70,7 @@ export function useFilters(): Filters {
             let interCount = num[0].length;
             let interCount = num[0].length;
             
             
             if (interCount < 3) {
             if (interCount < 3) {
-                return String(value);
+                return numberDecimal(value,decimalPlaces);
             }
             }
             
             
             let index = 0;
             let index = 0;
@@ -134,16 +134,26 @@ export function useFilters(): Filters {
     };
     };
 
 
     /**
     /**
-     * 数字保留两位小数
+     * 数字保留指定位数小数(不四舍五入)
+     * @param value 要格式化的数字或字符串
+     * @param decimalPlaces 保留的小数位数,默认为2
      */
      */
-    const numberDecimal = (value: number | string): string => {
-        let realVal = '';
-        if (!isNaN(Number(value)) && value !== '') {
-            realVal = parseFloat(String(value)).toFixed(2);
-        } else {
-            realVal = '0.00';
+    const numberDecimal = (value: number | string, decimalPlaces: number = 2): string => {
+        if (isNaN(Number(value)) || value === ''||value == null) {
+            return '0.' + '0'.repeat(decimalPlaces);
         }
         }
-        return realVal;
+
+        const strValue = String(value);
+        const [integerPart, decimalPart = ''] = strValue.split('.');
+
+        if (!decimalPart) {
+            return `${integerPart}.` + '0'.repeat(decimalPlaces);
+        }
+
+        const truncatedDecimalPart = decimalPart.slice(0, decimalPlaces);
+        const paddedDecimalPart = truncatedDecimalPart.padEnd(decimalPlaces, '0');
+
+        return `${integerPart}.${paddedDecimalPart}`;
     };
     };
 
 
     /**
     /**

+ 2 - 2
config/index.ts

@@ -7,8 +7,8 @@ let ht = p == 'http:' ? 'https:' : p;
 console.log(ho, dt, ht, 1009);
 console.log(ho, dt, ht, 1009);
 // #else
 // #else
 let ht = 'https:';
 let ht = 'https:';
-let ho = 'cwgvu'; // 默认主域名或可根据实际APP环境配置
-let dt = 'club'; // 默认域名后缀
+let ho = '44a5c8109e4'//'cwgvu'; // 默认主域名或可根据实际APP环境配置
+let dt = 'com'//'club'; // 默认域名后缀
 // #endif
 // #endif
 
 
 const config = {
 const config = {

+ 4 - 4
pages/customer/components/AccountList.vue

@@ -276,7 +276,7 @@ function formatMoney(value) {
     if (value === null || value === undefined) value = 0;
     if (value === null || value === undefined) value = 0;
     const sign = value >= 0 ? '' : '-';
     const sign = value >= 0 ? '' : '-';
     const absoluteValue = Math.abs(value);
     const absoluteValue = Math.abs(value);
-    return '$' + sign + absoluteValue.toFixed(2);
+    return '$' + sign + numberDecimal(absoluteValue);
 }
 }
 
 
 // 转换数组
 // 转换数组
@@ -311,9 +311,9 @@ const accounts = computed(() => {
             accountNumber: acc.login.toString(),
             accountNumber: acc.login.toString(),
             nickname,
             nickname,
             fwq,
             fwq,
-            balanceWithSymbol: acc.balanceWithSymbol ?? '$0',
-            creditWithSymbol: acc.creditWithSymbol ?? '$0',
-            equityWithSymbol: acc.equityWithSymbol ?? '$0',
+            balanceWithSymbol: acc.balanceWithSymbol ?? '$0.00',
+            creditWithSymbol: acc.creditWithSymbol ?? '$0.00',
+            equityWithSymbol: acc.equityWithSymbol ?? '$0.00',
             currency,
             currency,
             actualLeverage: '1:' + (acc.leverage ?? 0),
             actualLeverage: '1:' + (acc.leverage ?? 0),
             floatingPL: formatMoney(floating),
             floatingPL: formatMoney(floating),

+ 3 - 3
pages/customer/dashboard.vue

@@ -33,7 +33,7 @@
                       }}{{ compareData.totalBalanceGrowthRate || 0 }}%
                       }}{{ compareData.totalBalanceGrowthRate || 0 }}%
                     </text>
                     </text>
                   </view>
                   </view>
-                  <view class="fw-bold text-lg">${{ numberFormat(compareData.totalBalance || '0') }}</view>
+                  <view class="fw-bold text-lg">${{ numberDecimal(compareData.totalBalance || '0') }}</view>
                 </view>
                 </view>
               </view>
               </view>
             </view>
             </view>
@@ -230,7 +230,7 @@
   const router = useRouter()
   const router = useRouter()
   const { Code } = config
   const { Code } = config
   const userStore = useUserStore()
   const userStore = useUserStore()
-  const { numberFormat } = useFilters()
+  const { numberFormat ,numberDecimal} = useFilters()
 
 
 
 
   const loginOptions = ref([])
   const loginOptions = ref([])
@@ -607,7 +607,7 @@
     if (value === null || value === undefined) value = 0;
     if (value === null || value === undefined) value = 0;
     const sign = value >= 0 ? '' : '-';
     const sign = value >= 0 ? '' : '-';
     const absoluteValue = Math.abs(value);
     const absoluteValue = Math.abs(value);
-    return '$' + sign + absoluteValue.toFixed(2);
+    return '$' + sign + numberDecimal(absoluteValue);
   }
   }
   // 转换数组
   // 转换数组
   const accounts = computed(() => {
   const accounts = computed(() => {

+ 11 - 11
pages/ib/complexReport.vue

@@ -38,7 +38,7 @@
   import { ibApi } from '@/service/ib'
   import { ibApi } from '@/service/ib'
   import { useFilters } from '@/composables/useFilters'
   import { useFilters } from '@/composables/useFilters'
 
 
-  const { numberFormat } = useFilters()
+  const { numberDecimal } = useFilters()
   const { t } = useI18n()
   const { t } = useI18n()
 
 
   const searchParams = ref({})
   const searchParams = ref({})
@@ -137,63 +137,63 @@
       label: t('Documentary.Report.item21'),
       label: t('Documentary.Report.item21'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.deposit ? parseFloat(row.deposit).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.deposit ? numberDecimal(row.deposit) : '0.00',
     },
     },
     {
     {
       prop: 'withdrawal',
       prop: 'withdrawal',
       label: t('Documentary.Report.item22'),
       label: t('Documentary.Report.item22'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.withdrawal ? parseFloat(row.withdrawal).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.withdrawal ? numberDecimal(row.withdrawal) : '0.00',
     },
     },
     {
     {
       prop: 'netDeposit',
       prop: 'netDeposit',
       label: t('Documentary.Report.item23'),
       label: t('Documentary.Report.item23'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.netDeposit ? parseFloat(row.netDeposit).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.netDeposit ? numberDecimal(row.netDeposit) : '0.00',
     },
     },
     {
     {
       prop: 'volume',
       prop: 'volume',
       label: t('Documentary.Report.item24'),
       label: t('Documentary.Report.item24'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.volume ? parseFloat(row.volume).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.volume ? numberDecimal(row.volume) : '0.00',
     },
     },
     {
     {
       prop: 'sumRebate',
       prop: 'sumRebate',
       label: t('Documentary.Report.item25'),
       label: t('Documentary.Report.item25'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.sumRebate ? parseFloat(row.sumRebate).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.sumRebate ? numberDecimal(row.sumRebate) : '0.00',
     },
     },
     {
     {
       prop: 'storage',
       prop: 'storage',
       label: t('Documentary.Report.item26'),
       label: t('Documentary.Report.item26'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.storage ? parseFloat(row.storage).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.storage ? numberDecimal(row.storage) : '0.00',
     },
     },
     {
     {
       prop: 'balance',
       prop: 'balance',
       label: t('Label.Balance'),
       label: t('Label.Balance'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.balance != null && row.balance !== '' ? parseFloat(row.balance).toFixed(2) : '--',
+      formatter: ({ row }: any) => row.balance != null && row.balance !== '' ? numberDecimal(row.balance) : '--',
     },
     },
     {
     {
       prop: 'equity',
       prop: 'equity',
       label: t('Label.equity'),
       label: t('Label.equity'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.equity != null && row.equity !== '' ? parseFloat(row.equity).toFixed(2) : '--',
+      formatter: ({ row }: any) => row.equity != null && row.equity !== '' ? numberDecimal(row.equity) : '--',
     },
     },
     {
     {
       prop: 'profit',
       prop: 'profit',
       label: '盈亏',
       label: '盈亏',
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.profit ? parseFloat(row.profit).toFixed(2) : '0.00',
+      formatter: ({ row }: any) => row.profit ? numberDecimal(row.profit) : '0.00',
     },
     },
     {
     {
       prop: 'marginLevel',
       prop: 'marginLevel',
@@ -207,7 +207,7 @@
       label: t('Label.Credit'),
       label: t('Label.Credit'),
       align: 'center',
       align: 'center',
       sortable: 'custom',
       sortable: 'custom',
-      formatter: ({ row }: any) => row.credit != null && row.credit !== '' ? parseFloat(row.credit).toFixed(2) : '--',
+      formatter: ({ row }: any) => row.credit != null && row.credit !== '' ? numberDecimal(row.credit) : '--',
     },
     },
     {
     {
       prop: 'regDate',
       prop: 'regDate',

+ 2 - 5
pages/ib/index.vue

@@ -27,7 +27,7 @@
               <view class="clearfix pe-2 text-warning"> <image src="/static/images/dollar.png" alt="dollar" mode="aspectFill" class="img-fluid"/> </view>
               <view class="clearfix pe-2 text-warning"> <image src="/static/images/dollar.png" alt="dollar" mode="aspectFill" class="img-fluid"/> </view>
               <view class="clearfix">
               <view class="clearfix">
                 <view class="mb-2">{{ t('news_add_field.Label.Balance') }}</view>
                 <view class="mb-2">{{ t('news_add_field.Label.Balance') }}</view>
-                <view class="mb-0 fw-bold ">${{ ibData.balance?.toFixed(2) }}<text class="badge bg-danger-subtle text-danger">{{ t('Ib.Index.TotalRevenue') }}: ${{numberFormat(ibData.all || '0')}}</text></view>
+                <view class="mb-0 fw-bold ">${{ numberFormat(ibData.balance) }}<text class="badge bg-danger-subtle text-danger">{{ t('Ib.Index.TotalRevenue') }}: ${{numberFormat(ibData.all)}}</text></view>
               </view>
               </view>
             </view>
             </view>
           </view>
           </view>
@@ -263,10 +263,7 @@ const { userInfo } = useUserStore()
 const { numberFormat } = useFilters()
 const { numberFormat } = useFilters()
 const globalStore = useGlobalStore()
 const globalStore = useGlobalStore()
 // 数据
 // 数据
-const totalEarnings = ref(0.00)
-const partnerLink = ref('https://one.exnessonelink.com/a/plokue4yj3')
-const partnerCode = ref('PLOKUE4YJ3')
-const activeTab = ref('link') // 'link' 或 'code'
+
 const isDark = computed(() => globalStore.theme === 'dark')
 const isDark = computed(() => globalStore.theme === 'dark')
 const ibData = ref({
 const ibData = ref({
   customAmount: 0,
   customAmount: 0,