Browse Source

修改行情页面跳转方法

zhaowenkang/feature-20251028181547-行情页面
no99 4 weeks ago
parent
commit
026263009b
  1. 4
      components/IndexCard.vue
  2. 313
      pages/home/globalIndex.vue
  3. 50
      pages/home/marketCondition.vue
  4. 272
      pages/home/marketDetail.vue
  5. 436
      pages/home/marketSituation.vue

4
components/IndexCard.vue

@ -4,7 +4,7 @@
<view class="flag-container">
<image :src="flagIcon" class="flag-icon" mode="aspectFit"></image>
</view>
<text class="index-name">{{ indexName }}</text>
<text class="index-name">{{ stockName }}</text>
</view>
<view class="price-info">
@ -35,7 +35,7 @@ const props = defineProps({
required: true
},
//
indexName: {
stockName: {
type: String,
required: true
},

313
pages/home/globalIndex.vue

@ -1,3 +1,5 @@
<!-- @format -->
<template>
<view class="main">
<!-- 固定头部 -->
@ -7,11 +9,8 @@
<image src="/static/marketSituation-image/back.png" mode=""></image>
</view>
<view class="header_input_wrapper">
<image class="search_icon" src="/static/marketSituation-image/search.png" mode=""
@click="onSearchClick"></image>
<input class="header_input" type="text" placeholder="搜索"
placeholder-style="color: #A6A6A6; font-size: 22rpx;" v-model="searchValue"
@input="onSearchInput" @confirm="onSearchConfirm" />
<image class="search_icon" src="/static/marketSituation-image/search.png" mode="" @click="onSearchClick"></image>
<input class="header_input" type="text" placeholder="搜索" placeholder-style="color: #A6A6A6; font-size: 22rpx;" v-model="searchValue" @input="onSearchInput" @confirm="onSearchConfirm" />
</view>
<view class="header_icons">
<view class="header_icon" @click="selected">
@ -25,7 +24,7 @@
<view class="warn">
<image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image>
<view class="warn_text_container">
<text :class="warnTextClass">{{ $t('marketSituation.warn') }}</text>
<text :class="warnTextClass">{{ $t("marketSituation.warn") }}</text>
</view>
</view>
</view>
@ -43,10 +42,7 @@
</view>
<view class="cards-grid-three">
<view v-for="(item, index) in asiachinaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" />
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName" :currentPrice="item.currentPrice" :changeAmount="item.changeAmount" :changePercent="item.changePercent" :isRising="item.isRising" @click="viewIndexDetail(item)" />
</view>
</view>
</view>
@ -62,10 +58,7 @@
</view>
<view class="cards-grid-three">
<view v-for="(item, index) in asiaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" />
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName" :currentPrice="item.currentPrice" :changeAmount="item.changeAmount" :changePercent="item.changePercent" :isRising="item.isRising" @click="viewIndexDetail(item)" />
</view>
</view>
</view>
@ -81,10 +74,7 @@
</view>
<view class="cards-grid-three">
<view v-for="(item, index) in americaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :indexName="item.indexName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" />
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName" :currentPrice="item.currentPrice" :changeAmount="item.changeAmount" :changePercent="item.changePercent" :isRising="item.isRising" @click="viewIndexDetail(item)" />
</view>
</view>
</view>
@ -99,230 +89,246 @@
</template>
<script setup>
import { ref, onMounted, computed, nextTick, watch } from 'vue'
import footerBar from '../../components/footerBar.vue'
import IndexCard from '../../components/IndexCard.vue'
import { ref, onMounted, computed, nextTick, watch } from "vue";
import footerBar from "../../components/footerBar.vue";
import IndexCard from "../../components/IndexCard.vue";
//
const iSMT = ref(0) //
const contentHeight = ref(0)
const headerHeight = ref(0) //
const searchValue = ref('') //
const isWarnTextOverflow = ref(false) // warn
const iSMT = ref(0); //
const contentHeight = ref(0);
const headerHeight = ref(0); //
const searchValue = ref(""); //
const isWarnTextOverflow = ref(false); // warn
// warnclass
const warnTextClass = computed(() => {
return isWarnTextOverflow.value ? 'warn_text scroll-active' : 'warn_text'
})
return isWarnTextOverflow.value ? "warn_text scroll-active" : "warn_text";
});
// warn
const checkWarnTextOverflow = () => {
nextTick(() => {
setTimeout(() => {
const query = uni.createSelectorQuery()
const query = uni.createSelectorQuery();
//
query.select('.warn_text_container').boundingClientRect()
query.select('.warn_text').boundingClientRect()
query.select(".warn_text_container").boundingClientRect();
query.select(".warn_text").boundingClientRect();
query.exec((res) => {
const containerRect = res[0]
const textRect = res[1]
const containerRect = res[0];
const textRect = res[1];
if (!containerRect || !textRect) {
return
return;
}
//
const isOverflow = textRect.width > (containerRect.width - 10)
const isOverflow = textRect.width > containerRect.width - 10;
isWarnTextOverflow.value = isOverflow
})
}, 500)
})
}
isWarnTextOverflow.value = isOverflow;
});
}, 500);
});
};
// -
const asiachinaIndexes = ref([
{
flagIcon: '/static/c1.png',
indexName: '上证指数',
currentPrice: '3933.96',
changeAmount: '+24.32',
changePercent: '+0.62%',
isRising: true
flagIcon: "/static/c1.png",
stockName: "上证指数",
stockCode: "1A0001",
currentPrice: "3933.96",
changeAmount: "+24.32",
changePercent: "+0.62%",
isRising: true,
},
{
flagIcon: '/static/c2.png',
indexName: '深证成指',
currentPrice: '45757.90',
changeAmount: '-123.45',
changePercent: '-0.27%',
isRising: false
flagIcon: "/static/c2.png",
stockName: "深证成指",
stockCode: "2A01",
currentPrice: "45757.90",
changeAmount: "-123.45",
changePercent: "-0.27%",
isRising: false,
},
{
flagIcon: '/static/c3.png',
indexName: '创业板指',
currentPrice: '6606.08',
changeAmount: '+89.76',
changePercent: '+1.38%',
isRising: true
flagIcon: "/static/c3.png",
stockName: "创业板指",
stockCode: "399006",
currentPrice: "6606.08",
changeAmount: "+89.76",
changePercent: "+1.38%",
isRising: true,
},
{
flagIcon: '/static/c4.png',
indexName: 'HSI50',
currentPrice: '22333.96',
changeAmount: '+156.78',
changePercent: '+0.71%',
isRising: true
flagIcon: "/static/c4.png",
stockName: "沪深300",
stockCode: "1B0300",
currentPrice: "45757.90",
changeAmount: "-89.12",
changePercent: "-0.19%",
isRising: false,
},
{
flagIcon: '/static/c5.png',
indexName: '沪深300',
currentPrice: '45757.90',
changeAmount: '-89.12',
changePercent: '-0.19%',
isRising: false
flagIcon: "/static/c5.png",
stockName: "上证50",
stockCode: "1B0011",
currentPrice: "45757.90",
changeAmount: "+234.56",
changePercent: "+0.52%",
isRising: true,
},
{
flagIcon: '/static/c6.png',
indexName: '上证50',
currentPrice: '45757.90',
changeAmount: '+234.56',
changePercent: '+0.52%',
isRising: true
}
])
flagIcon: "/static/c6.png",
stockName: "科创50",
stockCode: "1B0688",
currentPrice: "22333.96",
changeAmount: "+156.78",
changePercent: "+0.71%",
isRising: true,
},
]);
//
const asiaIndexes = ref([
{
flagIcon: '/static/c7.png',
indexName: '日经225',
currentPrice: '28456.78',
changeAmount: '+234.56',
changePercent: '+0.83%',
isRising: true
flagIcon: "/static/c7.png",
stockName: "日经225",
stockCode: "noCode",
currentPrice: "28456.78",
changeAmount: "+234.56",
changePercent: "+0.83%",
isRising: true,
},
{
flagIcon: '/static/c8.png',
indexName: '韩国KOSPI',
currentPrice: '2567.89',
changeAmount: '-12.34',
changePercent: '-0.48%',
isRising: false
flagIcon: "/static/c8.png",
stockName: "韩国KOSPI",
stockCode: "noCode",
currentPrice: "2567.89",
changeAmount: "-12.34",
changePercent: "-0.48%",
isRising: false,
},
{
flagIcon: '/static/c9.png',
indexName: '印度孟买',
currentPrice: '65432.10',
changeAmount: '+456.78',
changePercent: '+0.70%',
isRising: true
}
])
flagIcon: "/static/c9.png",
stockName: "印度孟买",
stockCode: "noCode",
currentPrice: "65432.10",
changeAmount: "+456.78",
changePercent: "+0.70%",
isRising: true,
},
]);
//
const americaIndexes = ref([
{
flagIcon: '/static/c7.png',
indexName: '道琼斯指数',
currentPrice: '34567.89',
changeAmount: '+123.45',
changePercent: '+0.36%',
isRising: true
flagIcon: "/static/c7.png",
stockName: "道琼斯指数",
stockCode: "noCode",
currentPrice: "34567.89",
changeAmount: "+123.45",
changePercent: "+0.36%",
isRising: true,
},
{
flagIcon: '/static/c8.png',
indexName: '纳斯达克',
currentPrice: '13456.78',
changeAmount: '-67.89',
changePercent: '-0.50%',
isRising: false
flagIcon: "/static/c8.png",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "13456.78",
changeAmount: "-67.89",
changePercent: "-0.50%",
isRising: false,
},
{
flagIcon: '/static/c9.png',
indexName: '标普500',
currentPrice: '4234.56',
changeAmount: '+23.45',
changePercent: '+0.56%',
isRising: true
}
])
flagIcon: "/static/c9.png",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "4234.56",
changeAmount: "+23.45",
changePercent: "+0.56%",
isRising: true,
},
]);
//
const contentTopPosition = computed(() => {
const statusBarHeight = iSMT.value || 0
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 100
return statusBarHeight + currentHeaderHeight
})
const statusBarHeight = iSMT.value || 0;
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 100;
return statusBarHeight + currentHeaderHeight;
});
//
const goBack = () => {
uni.navigateBack()
}
uni.navigateBack();
};
//
const onSearchInput = (e) => {
searchValue.value = e.detail.value
}
searchValue.value = e.detail.value;
};
//
const clearSearch = () => {
searchValue.value = ''
}
searchValue.value = "";
};
//
const viewMore = (market) => {
console.log('查看更多:', market)
console.log("查看更多:", market);
uni.navigateTo({
url: `/pages/home/marketDetail?market=${market}`
})
}
url: `/pages/home/marketDetail?market=${market}`,
});
};
//
const viewIndexDetail = (item) => {
console.log('查看指数详情:', item.indexName)
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.indexName} `,
// title: ` ${item.stockName} `,
// icon: 'none',
// duration: 2000
// })
//
uni.navigateTo({
url: `/pages/home/marketCondition`
})
}
url: `/pages/home/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
});
};
//
onMounted(() => {
//
const systemInfo = uni.getSystemInfoSync()
iSMT.value = systemInfo.statusBarHeight || 0
const systemInfo = uni.getSystemInfoSync();
iSMT.value = systemInfo.statusBarHeight || 0;
console.log('全球指数页面加载完成')
console.log("全球指数页面加载完成");
// header
uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
uni
.createSelectorQuery()
.select(".header_fixed")
.boundingClientRect((rect) => {
if (rect) {
headerHeight.value = rect.height
console.log('Header实际高度:', headerHeight.value, 'px')
headerHeight.value = rect.height;
console.log("Header实际高度:", headerHeight.value, "px");
}
}).exec()
// warn
checkWarnTextOverflow()
})
.exec();
// warn
checkWarnTextOverflow();
});
// headerHeightcontentHeight
watch(headerHeight, (newHeight) => {
if (newHeight > 0) {
const systemInfo = uni.getSystemInfoSync()
const windowHeight = systemInfo.windowHeight
const statusBarHeight = systemInfo.statusBarHeight || 0
const footerHeight = 100
const systemInfo = uni.getSystemInfoSync();
const windowHeight = systemInfo.windowHeight;
const statusBarHeight = systemInfo.statusBarHeight || 0;
const footerHeight = 100;
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
console.log('重新计算contentHeight:', contentHeight.value)
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight;
console.log("重新计算contentHeight:", contentHeight.value);
}
})
});
</script>
<style lang="scss" scoped>
@ -418,7 +424,6 @@ watch(headerHeight, (newHeight) => {
height: 40rpx;
}
.warn {
display: flex;
align-items: center;

50
pages/home/marketCondition.vue

@ -9,13 +9,11 @@
<image class="back-homepage-btn" src="/static/marketSituation-image/back.png" mode="返回按钮" @click="backToHomepage()"> </image>
<view class="mid-title">
<view class="arrow-left"> </view>
<image class="left-page" src="/static/img/left-page.png" mode="向左翻页"></image>
<view class="stock-id">
<view class="stock-name"> {{ stockInformation.stockName }} </view>
<view class="stock-code"> {{ stockInformation.stockCode }} </view>
</view>
<view class="arrow-right"> </view>
<image class="right-page" src="/static/img/right-page.png" mode="向右翻页"></image>
</view>
<image class="search" src="/static/marketSituation-image/search.png" mode="搜索" @click="startTcp()"> </image>
<view class="more" @click="disconnect()">···</view>
@ -227,6 +225,7 @@
<script setup>
import { ref, reactive, computed, onMounted, watch, nextTick, onUnmounted, getCurrentInstance } from "vue";
import { onLoad } from "@dcloudio/uni-app";
const instance = getCurrentInstance();
import { prevClosePrice, timeData as testTimeData, klineData as testKlineData } from "@/common/stockTimeInformation.js";
import { throttle } from "@/common/util.js";
@ -1534,6 +1533,52 @@ const startAddDataTimer = () => {
}, 2000); // 5000 = 5
};
onLoad((options) => {
console.log("页面接收到的参数:", options);
// data
if (options.data) {
try {
const stockData = JSON.parse(decodeURIComponent(options.data));
console.log("解析的股票数据:", stockData);
// stockInformation
if (stockData) {
stockInformation.value.stockName=stockData.stockName;
stockInformation.value.stockCode=stockData.stockCode;
}
} catch (error) {
console.error("解析股票数据失败:", error);
}
}
// stockInformationglobalIndex.vue
if (options.stockInformation) {
try {
const stockData = JSON.parse(decodeURIComponent(options.stockInformation));
console.log("解析的股票信息:", stockData);
// stockInformation
if (stockData) {
stockInformation.value = {
...stockInformation.value,
...stockData
};
}
} catch (error) {
console.error("解析股票信息失败:", error);
}
}
//
if (options.stockCode) {
stockInformation.value.stockCode = options.stockCode;
}
if (options.stockName) {
stockInformation.value.stockName = decodeURIComponent(options.stockName);
}
});
//
onUnmounted(() => {
// disconnect();
@ -1910,7 +1955,6 @@ onMounted(async () => {
margin-bottom: 5rpx;
}
.moreTabItem {
flex: 1;
padding: 10rpx 20rpx;

272
pages/home/marketDetail.vue

@ -1,3 +1,5 @@
<!-- @format -->
<template>
<view class="main">
<!-- 自定义导航栏 -->
@ -21,36 +23,31 @@
</view>
<view class="header-item price-column" @click="sortByPrice">
<text class="header-text">最新</text>
<text class="sort-icon">{{ sortType === 'price' ? (sortOrder === 'asc' ? '↑' : '↓') : '↕' }}</text>
<text class="sort-icon">{{ sortType === "price" ? (sortOrder === "asc" ? "↑" : "↓") : "↕" }}</text>
</view>
<view class="header-item change-column" @click="sortByChange">
<text class="header-text">涨幅</text>
<text class="sort-icon">{{ sortType === 'change' ? (sortOrder === 'asc' ? '↑' : '↓') : '↕' }}</text>
<text class="sort-icon">{{ sortType === "change" ? (sortOrder === "asc" ? "↑" : "↓") : "↕" }}</text>
</view>
</view>
</view>
<!-- 内容区域 -->
<scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
<!-- 股票列表 -->
<view class="stock-list">
<view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index"
@click="viewStockDetail(stock)">
<view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index" @click="viewStockDetail(stock)">
<view class="stock-cell name-column">
<view class="stock-name">{{ stock.name }}</view>
<view class="stock-code">{{ stock.code }}</view>
<view class="stock-name">{{ stock.stockName }}</view>
<view class="stock-code">{{ stock.stockCode }}</view>
</view>
<view class="stock-cell price-column">
<text class="stock-price"
:class="stock.isRising ? 'rising' : 'falling'">
{{ typeof stock.price === 'number' ? stock.price.toFixed(2) : stock.price }}
<text class="stock-price" :class="stock.isRising ? 'rising' : 'falling'">
{{ typeof stock.price === "number" ? stock.price.toFixed(2) : stock.price }}
</text>
</view>
<view class="stock-cell change-column">
<text class="stock-change"
:class="stock.isRising ? 'rising' : 'falling'">
<text class="stock-change" :class="stock.isRising ? 'rising' : 'falling'">
{{ stock.change || stock.changePercent }}
</text>
</view>
@ -67,217 +64,224 @@
</template>
<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import footerBar from '@/components/footerBar.vue'
import { ref, computed, onMounted, watch } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import footerBar from "@/components/footerBar.vue";
//
const iSMT = ref(0)
const headerHeight = ref(80)
const marketType = ref('america')
const marketTitle = ref('美洲')
const sortType = ref('') // 'price' 'change'
const sortOrder = ref('desc') // 'asc' 'desc'
const iSMT = ref(0);
const headerHeight = ref(80);
const marketType = ref("america");
const marketTitle = ref("美洲");
const sortType = ref(""); // 'price' 'change'
const sortOrder = ref("desc"); // 'asc' 'desc'
//
const stockList = ref([
{
name: 'Telecommunication',
code: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1349.47,
change: '+7.67%',
isRising: true
change: "+7.67%",
isRising: true,
},
{
name: 'Other',
code: '888607',
stockName: "Other",
stockCode: "888607",
price: 1349.47,
change: '+6.67%',
isRising: true
change: "+6.67%",
isRising: true,
},
{
name: 'Consumer Discretio...',
code: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1349.47,
change: '+5.67%',
isRising: true
change: "+5.67%",
isRising: true,
},
{
name: 'Telecommunication',
code: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1349.47,
change: '+4.67%',
isRising: true
change: "+4.67%",
isRising: true,
},
{
name: 'Other',
code: '888611',
stockName: "Other",
stockCode: "888611",
price: 1359.47,
change: '+3.67%',
isRising: true
change: "+3.67%",
isRising: true,
},
{
name: 'Consumer Discretio...',
code: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1349.47,
change: '+2.67%',
isRising: true
change: "+2.67%",
isRising: true,
},
{
name: 'Telecommunication',
code: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1349.47,
change: '+1.67%',
isRising: true
change: "+1.67%",
isRising: true,
},
{
name: 'Other',
code: '888611',
stockName: "Other",
stockCode: "888611",
price: 1009.98,
change: '-1.67%',
isRising: false
change: "-1.67%",
isRising: false,
},
{
name: 'Consumer Discretio...',
code: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-0.67%',
isRising: false
change: "-0.67%",
isRising: false,
},
{
name: 'Telecommunication',
code: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1009.98,
change: '-0.67%',
isRising: false
change: "-0.67%",
isRising: false,
},
{
name: 'Other',
code: '888611',
stockName: "Other",
stockCode: "888611",
price: 1009.98,
change: '-1.67%',
isRising: false
change: "-1.67%",
isRising: false,
},
{
name: 'Consumer Discretio...',
code: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-4.67%',
isRising: false
change: "-4.67%",
isRising: false,
},
{
name: 'Consumer Discretio...',
code: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-3.67%',
isRising: false
change: "-3.67%",
isRising: false,
},
{
name: 'Consumer Discretio...',
code: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-3.67%',
isRising: false
}
])
change: "-3.67%",
isRising: false,
},
]);
//
const contentTopPosition = computed(() => {
return iSMT.value + headerHeight.value
})
return iSMT.value + headerHeight.value;
});
const sortedStockList = computed(() => {
console.log('计算sortedStockList,原始数据长度:', stockList.value.length);
let list = [...stockList.value]
console.log("计算sortedStockList,原始数据长度:", stockList.value.length);
let list = [...stockList.value];
if (sortType.value === 'price') {
if (sortType.value === "price") {
list.sort((a, b) => {
return sortOrder.value === 'asc' ? a.price - b.price : b.price - a.price
})
} else if (sortType.value === 'change') {
return sortOrder.value === "asc" ? a.price - b.price : b.price - a.price;
});
} else if (sortType.value === "change") {
list.sort((a, b) => {
const aChange = parseFloat(a.change.replace(/[+%-]/g, ''))
const bChange = parseFloat(b.change.replace(/[+%-]/g, ''))
return sortOrder.value === 'asc' ? aChange - bChange : bChange - aChange
})
const aChange = parseFloat(a.change.replace(/[+%-]/g, ""));
const bChange = parseFloat(b.change.replace(/[+%-]/g, ""));
return sortOrder.value === "asc" ? aChange - bChange : bChange - aChange;
});
}
console.log('排序后数据长度:', list.length);
return list
})
console.log("排序后数据长度:", list.length);
return list;
});
//
onLoad((options) => {
if (options && options.market) {
marketType.value = options.market
marketType.value = options.market;
switch (options.market) {
case 'america':
marketTitle.value = '美洲'
break
case 'asia':
marketTitle.value = '亚太'
break
case 'asia-china':
marketTitle.value = '亚太-中华'
break
case "america":
marketTitle.value = "美洲";
break;
case "asia":
marketTitle.value = "亚太";
break;
case "asia-china":
marketTitle.value = "亚太-中华";
break;
default:
marketTitle.value = '全球指数'
marketTitle.value = "全球指数";
}
}
})
});
//
const goBack = () => {
uni.navigateBack()
}
uni.navigateBack();
};
const sortByPrice = () => {
if (sortType.value === 'price') {
sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
if (sortType.value === "price") {
sortOrder.value = sortOrder.value === "asc" ? "desc" : "asc";
} else {
sortType.value = 'price'
sortOrder.value = 'desc'
}
sortType.value = "price";
sortOrder.value = "desc";
}
};
const sortByChange = () => {
if (sortType.value === 'change') {
sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc'
if (sortType.value === "change") {
sortOrder.value = sortOrder.value === "asc" ? "desc" : "asc";
} else {
sortType.value = 'change'
sortOrder.value = 'desc'
}
sortType.value = "change";
sortOrder.value = "desc";
}
};
const viewStockDetail = (stock) => {
console.log('查看股票详情:', stock)
console.log("查看股票详情:", stock);
//
}
uni.navigateTo({
url: `/pages/home/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(stock))}`,
});
};
onMounted(() => {
//
iSMT.value = uni.getSystemInfoSync().statusBarHeight;
// header
uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
uni
.createSelectorQuery()
.select(".header_fixed")
.boundingClientRect((rect) => {
if (rect) {
headerHeight.value = rect.height
console.log('Header实际高度:', headerHeight.value, 'px')
headerHeight.value = rect.height;
console.log("Header实际高度:", headerHeight.value, "px");
}
}).exec()
})
.exec();
});
// headerHeightcontentHeight
watch(headerHeight, (newHeight) => {
if (newHeight > 0) {
const systemInfo = uni.getSystemInfoSync()
const windowHeight = systemInfo.windowHeight
const statusBarHeight = systemInfo.statusBarHeight || 0
const footerHeight = 100
const systemInfo = uni.getSystemInfoSync();
const windowHeight = systemInfo.windowHeight;
const statusBarHeight = systemInfo.statusBarHeight || 0;
const footerHeight = 100;
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
console.log('重新计算contentHeight:', contentHeight.value)
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight;
console.log("重新计算contentHeight:", contentHeight.value);
}
})
});
</script>
<style scoped>
@ -461,11 +465,11 @@ watch(headerHeight, (newHeight) => {
}
.rising {
color: #00C851;
color: #00c851;
}
.falling {
color: #FF4444;
color: #ff4444;
}
/* 底部安全区域 */

436
pages/home/marketSituation.vue

@ -1,14 +1,13 @@
<!-- @format -->
<template>
<view class="main">
<!-- 固定头部 -->
<view class="header_fixed" :style="{ top: iSMT + 'px' }">
<view class="header_content">
<view class="header_input_wrapper">
<image class="search_icon" src="/static/marketSituation-image/search.png" mode=""
@click="onSearchClick"></image>
<input class="header_input" type="text" placeholder="搜索"
placeholder-style="color: #A6A6A6; font-size: 22rpx;" v-model="searchValue"
@input="onSearchInput" @confirm="onSearchConfirm" />
<image class="search_icon" src="/static/marketSituation-image/search.png" mode="" @click="onSearchClick"></image>
<input class="header_input" type="text" placeholder="搜索" placeholder-style="color: #A6A6A6; font-size: 22rpx;" v-model="searchValue" @input="onSearchInput" @confirm="onSearchConfirm" />
</view>
<view class="header_icons">
<view class="header_icon" @click="selected">
@ -20,11 +19,9 @@
</view>
</view>
<view class="channel_li" v-if="channelData.length > 0">
<scroll-view class="channel_wrap" scroll-x="true" :scroll-into-view="scrollToView"
:scroll-with-animation="true" show-scrollbar="false">
<scroll-view class="channel_wrap" scroll-x="true" :scroll-into-view="scrollToView" :scroll-with-animation="true" show-scrollbar="false">
<view class="channel_innerWrap">
<view v-for="(item, index) in channelData" :key="item.id" :id="'nav' + item.id"
:class="['channel_item', index === pageIndex ? 'active' : '']" @click="navClick(index)">
<view v-for="(item, index) in channelData" :key="item.id" :id="'nav' + item.id" :class="['channel_item', index === pageIndex ? 'active' : '']" @click="navClick(index)">
<text class="channel_text">{{ item.title }}</text>
<view v-if="index === pageIndex" class="active_indicator"></view>
</view>
@ -44,10 +41,10 @@
</view>
<view class="global_index">
<view class="global_index_title">
{{ $t('marketSituation.globalIndex') }}
{{ $t("marketSituation.globalIndex") }}
</view>
<view class="global_index_more" @click="goToGlobalIndex">
<text>{{ $t('marketSituation.globalIndexMore') }}</text>
<text>{{ $t("marketSituation.globalIndexMore") }}</text>
<image src="/static/marketSituation-image/more.png" mode="aspectFit"></image>
</view>
</view>
@ -55,15 +52,13 @@
<!-- 卡片网格 -->
<view class="cards_grid">
<view v-for="(card, index) in cardData" :key="index" class="card_item">
<IndexCard :flagIcon="card.flagIcon" :indexName="card.indexName"
:currentPrice="card.currentPrice" :changeAmount="card.changeAmount"
:changePercent="card.changePercent" :isRising="card.isRising" />
<IndexCard :flagIcon="card.flagIcon" :stockName="card.stockName" :currentPrice="card.currentPrice" :changeAmount="card.changeAmount" :changePercent="card.changePercent" :isRising="card.isRising" @click="viewIndexDetail(card)" />
</view>
</view>
<view class="warn">
<image src="/static/marketSituation-image/warn.png" mode="aspectFit"></image>
<view class="warn_text_container">
<text :class="warnTextClass">{{ $t('marketSituation.warn') }}</text>
<text :class="warnTextClass">{{ $t("marketSituation.warn") }}</text>
</view>
</view>
<!-- 底部安全区域防止被导航栏遮挡 -->
@ -85,9 +80,7 @@
</view>
<view class="modal_body">
<view class="country_grid">
<view v-for="(country, index) in countryList" :key="index"
:class="['country_item', selectedCountry === country ? 'selected' : '']"
@click="selectCountry(country)">
<view v-for="(country, index) in countryList" :key="index" :class="['country_item', selectedCountry === country ? 'selected' : '']" @click="selectCountry(country)">
<text class="country_text">{{ country }}</text>
</view>
</view>
@ -97,285 +90,305 @@
</template>
<script setup>
import { ref, onMounted, watch, nextTick, computed } from 'vue'
import util from '../../common/util.js'
import footerBar from '../../components/footerBar.vue'
import IndexCard from '../../components/IndexCard.vue'
const type = ref('marketSituation')
const iSMT = ref(0)
const searchValue = ref('')
const contentHeight = ref(0)
const headerHeight = ref(0) // header
const isWarnTextOverflow = ref(false) // warn
import { ref, onMounted, watch, nextTick, computed } from "vue";
import util from "../../common/util.js";
import footerBar from "../../components/footerBar.vue";
import IndexCard from "../../components/IndexCard.vue";
const type = ref("marketSituation");
const iSMT = ref(0);
const searchValue = ref("");
const contentHeight = ref(0);
const headerHeight = ref(0); // header
const isWarnTextOverflow = ref(false); // warn
// Tab
const channelData = ref([
{ id: 1, title: '概况' },
{ id: 2, title: '新加坡' },
{ id: 3, title: '马来西亚' },
{ id: 4, title: '印度尼西亚' },
{ id: 5, title: '美国' },
{ id: 6, title: '中国香港' },
{ id: 7, title: '泰国' },
{ id: 8, title: '中国' },
{ id: 9, title: '加拿大' },
{ id: 10, title: '越南' },
{ id: 11, title: '外汇' },
{ id: 12, title: '贵金属' },
])
const pageIndex = ref(0)
const scrollToView = ref('')
{ id: 1, title: "概况" },
{ id: 2, title: "新加坡" },
{ id: 3, title: "马来西亚" },
{ id: 4, title: "印度尼西亚" },
{ id: 5, title: "美国" },
{ id: 6, title: "中国香港" },
{ id: 7, title: "泰国" },
{ id: 8, title: "中国" },
{ id: 9, title: "加拿大" },
{ id: 10, title: "越南" },
{ id: 11, title: "外汇" },
{ id: 12, title: "贵金属" },
]);
const pageIndex = ref(0);
const scrollToView = ref("");
// contenttop
const contentTopPosition = computed(() => {
const statusBarHeight = iSMT.value || 0
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140
return statusBarHeight + currentHeaderHeight
})
const statusBarHeight = iSMT.value || 0;
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140;
return statusBarHeight + currentHeaderHeight;
});
// warnclass
const warnTextClass = computed(() => {
return isWarnTextOverflow.value ? 'warn_text scroll-active' : 'warn_text'
})
return isWarnTextOverflow.value ? "warn_text scroll-active" : "warn_text";
});
//
const showCountryModal = ref(false)
const selectedCountry = ref('概况')
const countryList = ref([
'概况', '新加坡', '马来西亚', '印度尼西亚', '美国', '中国香港',
'泰国', '中国', '加拿大', '越南', '外汇', '贵金属'
])
const showCountryModal = ref(false);
const selectedCountry = ref("概况");
const countryList = ref(["概况", "新加坡", "马来西亚", "印度尼西亚", "美国", "中国香港", "泰国", "中国", "加拿大", "越南", "外汇", "贵金属"]);
//
const cardData = ref([
{
flagIcon: '🇺🇸',
indexName: '道琼斯',
currentPrice: '45757.90',
changeAmount: '-125.22',
changePercent: '-0.27%',
isRising: false
flagIcon: "🇺🇸",
stockName: "道琼斯",
stockCode: "DJIA",
currentPrice: "45757.90",
changeAmount: "-125.22",
changePercent: "-0.27%",
isRising: false,
},
{
flagIcon: '🇺🇸',
indexName: '纳斯达克',
currentPrice: '22333.96',
changeAmount: '+125.22',
changePercent: '+0.47%',
isRising: true
flagIcon: "🇺🇸",
stockName: "纳斯达克",
stockCode: "NDX",
currentPrice: "22333.96",
changeAmount: "+125.22",
changePercent: "+0.47%",
isRising: true,
},
{
flagIcon: '🇺🇸',
indexName: '标普500',
currentPrice: '6606.08',
changeAmount: '+125.22',
changePercent: '+0.27%',
isRising: true
flagIcon: "🇺🇸",
stockName: "标普500",
stockCode: "SPX",
currentPrice: "6606.08",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
flagIcon: '🇨🇳',
indexName: '上证指数',
currentPrice: '3333.96',
changeAmount: '+125.22',
changePercent: '+0.27%',
isRising: true
flagIcon: "🇨🇳",
stockName: "上证指数",
stockCode: "1A0001",
currentPrice: "3333.96",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
flagIcon: '🇨🇳',
indexName: '科创50',
currentPrice: '757.90',
changeAmount: '-25.22',
changePercent: '-0.27%',
isRising: false
flagIcon: "🇨🇳",
stockName: "科创50",
stockCode: "1B0688",
currentPrice: "757.90",
changeAmount: "-25.22",
changePercent: "-0.27%",
isRising: false,
},
{
flagIcon: '🇭🇰',
indexName: '恒生指数',
currentPrice: '19757.90',
changeAmount: '-125.22',
changePercent: '-0.63%',
isRising: false
flagIcon: "🇭🇰",
stockName: "恒生指数",
stockCode: "HSI",
currentPrice: "19757.90",
changeAmount: "-125.22",
changePercent: "-0.63%",
isRising: false,
},
{
flagIcon: '🇸🇬',
indexName: '道琼斯',
currentPrice: '3757.90',
changeAmount: '+85.22',
changePercent: '+2.31%',
isRising: true
flagIcon: "🇸🇬",
stockName: "道琼斯",
stockCode: "DJIA",
currentPrice: "3757.90",
changeAmount: "+85.22",
changePercent: "+2.31%",
isRising: true,
},
{
flagIcon: '🇲🇾',
indexName: '纳斯达克',
currentPrice: '1657.90',
changeAmount: '-15.22',
changePercent: '-0.91%',
isRising: false
flagIcon: "🇲🇾",
stockName: "纳斯达克",
stockCode: "NDX",
currentPrice: "1657.90",
changeAmount: "-15.22",
changePercent: "-0.91%",
isRising: false,
},
{
flagIcon: '🇹🇭',
indexName: '标普500',
currentPrice: '1457.90',
changeAmount: '+35.22',
changePercent: '+2.48%',
isRising: true
}
])
flagIcon: "🇹🇭",
stockName: "标普500",
stockCode: "SPX",
currentPrice: "1457.90",
changeAmount: "+35.22",
changePercent: "+2.48%",
isRising: true,
},
]);
//
const onSearchInput = (e) => {
searchValue.value = e.detail.value
}
searchValue.value = e.detail.value;
};
//
const onSearchConfirm = (e) => {
console.log('搜索内容:', e.detail.value)
console.log("搜索内容:", e.detail.value);
//
performSearch(e.detail.value)
}
performSearch(e.detail.value);
};
//
const onSearchClick = () => {
if (searchValue.value.trim()) {
performSearch(searchValue.value)
}
performSearch(searchValue.value);
}
};
//
const performSearch = (keyword) => {
if (!keyword.trim()) {
uni.showToast({
title: '请输入搜索内容',
icon: 'none'
})
return
title: "请输入搜索内容",
icon: "none",
});
return;
}
uni.showToast({
title: `搜索: ${keyword}`,
icon: 'none'
})
icon: "none",
});
//
}
};
//
const selected = () => {
uni.showToast({
title: '我的收藏',
icon: 'none'
})
title: "我的收藏",
icon: "none",
});
//
}
};
//
const history = () => {
uni.showToast({
title: '历史记录',
icon: 'none'
})
title: "历史记录",
icon: "none",
});
//
}
};
// Tab
const navClick = (index) => {
pageIndex.value = index
const currentItem = channelData.value[index]
scrollToView.value = 'nav' + currentItem.id
pageIndex.value = index;
const currentItem = channelData.value[index];
scrollToView.value = "nav" + currentItem.id;
//
selectedCountry.value = currentItem.title
selectedCountry.value = currentItem.title;
uni.showToast({
title: `切换到: ${currentItem.title}`,
icon: 'none'
})
icon: "none",
});
// tab
console.log('当前选中的 tab:', currentItem)
}
console.log("当前选中的 tab:", currentItem);
};
//
const channel_more = () => {
showCountryModal.value = true
}
showCountryModal.value = true;
};
//
const selectCountry = (country) => {
selectedCountry.value = country
selectedCountry.value = country;
// tab
const targetIndex = channelData.value.findIndex(item => item.title === country)
const targetIndex = channelData.value.findIndex((item) => item.title === country);
if (targetIndex !== -1) {
// tab
pageIndex.value = targetIndex
const currentItem = channelData.value[targetIndex]
scrollToView.value = 'nav' + currentItem.id
pageIndex.value = targetIndex;
const currentItem = channelData.value[targetIndex];
scrollToView.value = "nav" + currentItem.id;
console.log('选中了:' + country + ',同步到tab索引:' + targetIndex)
console.log("选中了:" + country + ",同步到tab索引:" + targetIndex);
uni.showToast({
title: '已切换到:' + country,
icon: 'none',
duration: 2000
})
title: "已切换到:" + country,
icon: "none",
duration: 2000,
});
} else {
// ""tab
if (country === '概况' || country === '全部') {
pageIndex.value = 0
scrollToView.value = 'nav' + channelData.value[0].id
if (country === "概况" || country === "全部") {
pageIndex.value = 0;
scrollToView.value = "nav" + channelData.value[0].id;
}
console.log('选中了:' + country)
console.log("选中了:" + country);
uni.showToast({
title: '已选择:' + country,
icon: 'none',
duration: 2000
})
title: "已选择:" + country,
icon: "none",
duration: 2000,
});
}
// /
// loadMarketData(country)
closeModal()
}
closeModal();
};
//
const closeModal = () => {
showCountryModal.value = false
}
showCountryModal.value = false;
};
// warn
const checkWarnTextOverflow = () => {
nextTick(() => {
setTimeout(() => {
const query = uni.createSelectorQuery()
const query = uni.createSelectorQuery();
//
query.select('.warn_text_container').boundingClientRect()
query.select('.warn_text').boundingClientRect()
query.select(".warn_text_container").boundingClientRect();
query.select(".warn_text").boundingClientRect();
query.exec((res) => {
const containerRect = res[0]
const textRect = res[1]
const containerRect = res[0];
const textRect = res[1];
if (!containerRect || !textRect) {
return
return;
}
//
const isOverflow = textRect.width > (containerRect.width - 10)
const isOverflow = textRect.width > containerRect.width - 10;
isWarnTextOverflow.value = isOverflow
})
}, 500)
})
}
isWarnTextOverflow.value = isOverflow;
});
}, 500);
});
};
//
const goToGlobalIndex = () => {
uni.navigateTo({
url: '/pages/home/globalIndex'
})
}
url: "/pages/home/globalIndex",
});
};
//
const viewIndexDetail = (item) => {
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
// duration: 2000
// })
//
uni.navigateTo({
url: `/pages/home/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
});
};
onMounted(() => {
//
@ -383,45 +396,54 @@ onMounted(() => {
// tab
if (channelData.value.length > 0) {
pageIndex.value = 0
scrollToView.value = 'nav' + channelData.value[0].id
pageIndex.value = 0;
scrollToView.value = "nav" + channelData.value[0].id;
}
util.request('link/api/brain/privilege', (res) => {
console.log(res)
},{
'token': '9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnIlrmTwo5FbqJ9lWrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs'
}, (err) => {
console.log(err)
})
util.request(
"link/api/brain/privilege",
(res) => {
console.log(res);
},
{
token: "9ior41AF0xTIbIG2pRnnbZi0+fEeMx8pywnIlrmTwo5FbqJ9lWrSWOxp9MkpKiNtedtUafqvzIwpFKrwuMs",
},
(err) => {
console.log(err);
}
);
// DOM
nextTick(() => {
// header
uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
uni
.createSelectorQuery()
.select(".header_fixed")
.boundingClientRect((rect) => {
if (rect) {
headerHeight.value = rect.height
console.log('Header实际高度:', headerHeight.value, 'px')
headerHeight.value = rect.height;
console.log("Header实际高度:", headerHeight.value, "px");
}
}).exec()
})
.exec();
// warn
checkWarnTextOverflow()
})
})
checkWarnTextOverflow();
});
});
// headerHeightcontentHeight
watch(headerHeight, (newHeight) => {
if (newHeight > 0) {
const systemInfo = uni.getSystemInfoSync()
const windowHeight = systemInfo.windowHeight
const statusBarHeight = systemInfo.statusBarHeight || 0
const footerHeight = 100
const systemInfo = uni.getSystemInfoSync();
const windowHeight = systemInfo.windowHeight;
const statusBarHeight = systemInfo.statusBarHeight || 0;
const footerHeight = 100;
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
console.log('重新计算contentHeight:', contentHeight.value)
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight;
console.log("重新计算contentHeight:", contentHeight.value);
}
})
});
</script>
<style scoped>
@ -580,7 +602,7 @@ watch(headerHeight, (newHeight) => {
min-width: 40rpx;
max-width: 120rpx;
height: 8rpx;
background-image: url('/static/marketSituation-image/bg.png');
background-image: url("/static/marketSituation-image/bg.png");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
@ -629,9 +651,9 @@ watch(headerHeight, (newHeight) => {
display: flex;
align-items: center;
justify-content: center;
background-color: #F3F3F3;
background-color: #f3f3f3;
border-radius: 30rpx;
border: 1rpx solid #E0E0E0;
border: 1rpx solid #e0e0e0;
padding: 30rpx 20rpx;
box-sizing: border-box;
/* 设置最小高度保护,但允许内容撑开 */

Loading…
Cancel
Save