Browse Source

Merge branch 'milestone-20251031-简版功能开发' of http://39.101.133.168:8807/qimaohong/deepChartVueApp into wangyi/feature-20251026183100-deepmate王毅

lihuilin/feature-20251024095243-我的
wangyi 4 weeks ago
parent
commit
55c614b078
  1. 185
      api/home/mySelections.js
  2. 70
      api/marketSituation/marketSituation.js
  3. 64
      components/IndexCard.vue
  4. 5
      components/login-prompt.vue
  5. 256
      pages/home/home.vue
  6. 141
      pages/marketSituation/countryMarket.vue
  7. 382
      pages/marketSituation/globalIndex.vue
  8. 74
      pages/marketSituation/marketCondition.vue
  9. 275
      pages/marketSituation/marketDetail.vue
  10. 121
      pages/marketSituation/marketOverview.vue
  11. 252
      pages/marketSituation/marketSituation.vue
  12. BIN
      static/marketSituation-image/country-flag/can.png
  13. BIN
      static/marketSituation-image/country-flag/cn.png
  14. BIN
      static/marketSituation-image/country-flag/global.png
  15. BIN
      static/marketSituation-image/country-flag/hk.png
  16. BIN
      static/marketSituation-image/country-flag/my.png
  17. BIN
      static/marketSituation-image/country-flag/sg.png
  18. BIN
      static/marketSituation-image/country-flag/th.png
  19. BIN
      static/marketSituation-image/country-flag/us.png
  20. BIN
      static/marketSituation-image/country-flag/vi.png
  21. 78
      stores/modules/marketSituation.js
  22. 2
      utils/http.js

185
api/home/mySelections.js

@ -0,0 +1,185 @@
/**
* 我的自选股相关API接口封装
* 使用utils/http.js中的拦截器封装请求方法
*/
import { http } from '../../utils/http.js'
/**
* 我的自选股API接口类
*/
class MySelectionsAPI {
/**
* 判断用户是否存在自选股分组
* @param {Function} successCallback - 成功回调函数
* @param {Function} failCallback - 失败回调函数
* @param {Object} data - 请求参数
* @returns {Promise}
*/
static async checkExist(successCallback, failCallback = null, data = {}) {
const url = '/api/homePage/userStock/checkExist'
try {
const response = await http({
url: url,
method: 'POST',
data: data
})
console.log('检查用户自选股分组存在性 - 响应:', response)
if (successCallback && typeof successCallback === 'function') {
successCallback(response)
}
return response
} catch (error) {
console.error('检查用户自选股分组存在性 - 失败:', error)
if (failCallback && typeof failCallback === 'function') {
failCallback(error)
}
throw error
}
}
/**
* 查询用户所有自选股分组
* @param {Function} successCallback - 成功回调函数
* @param {Function} failCallback - 失败回调函数
* @param {Object} data - 请求参数
* @returns {Promise}
*/
static async getUserStockGroupList(successCallback, failCallback = null, data = {}) {
const url = '/api/homePage/userStockGroup/list'
try {
const response = await http({
url: url,
method: 'POST',
data: data
})
console.log('查询用户自选股分组列表 - 响应:', response)
if (successCallback && typeof successCallback === 'function') {
successCallback(response)
}
return response
} catch (error) {
console.error('查询用户自选股分组列表 - 失败:', error)
if (failCallback && typeof failCallback === 'function') {
failCallback(error)
}
throw error
}
}
/**
* 分页查询某一个分组下的所有自选股
* @param {Function} successCallback - 成功回调函数
* @param {Function} failCallback - 失败回调函数
* @param {Object} data - 请求参数 {groupId, pageNum, pageSize, ...}
* @returns {Promise}
*/
static async getUserStockList(successCallback, failCallback = null, data = {}) {
const url = '/api/homePage/userStock/list'
// 设置默认分页参数
const requestData = {
pageNum: 1,
pageSize: 20,
...data
}
try {
const response = await http({
url: url,
method: 'POST',
data: requestData
})
console.log('分页查询分组自选股 - 响应:', response)
if (successCallback && typeof successCallback === 'function') {
successCallback(response)
}
return response
} catch (error) {
console.error('分页查询分组自选股 - 失败:', error)
if (failCallback && typeof failCallback === 'function') {
failCallback(error)
}
throw error
}
}
/**
* 查询默认自选股
* @param {Function} successCallback - 成功回调函数
* @param {Function} failCallback - 失败回调函数
* @param {Object} data - 请求参数
* @returns {Promise}
*/
static async getUserOrDefault(successCallback, failCallback = null, data = {}) {
const url = '/api/homePage/userStock/getUserOrDefault'
try {
const response = await http({
url: url,
method: 'POST',
data: data
})
console.log('查询默认自选股 - 响应:', response)
if (successCallback && typeof successCallback === 'function') {
successCallback(response)
}
return response
} catch (error) {
console.error('查询默认自选股 - 失败:', error)
if (failCallback && typeof failCallback === 'function') {
failCallback(error)
}
throw error
}
}
/**
* 游客查询默认自选股
* @param {Function} successCallback - 成功回调函数
* @param {Function} failCallback - 失败回调函数
* @returns {Promise}
*/
static async getDefaultStocks(successCallback, failCallback = null) {
const url = '/api/homePage/userStock/getDefaultStocks'
try {
const response = await http({
url: url,
method: 'POST',
data: {}
})
console.log('游客查询默认自选股 - 响应:', response)
if (successCallback && typeof successCallback === 'function') {
successCallback(response)
}
return response
} catch (error) {
console.error('游客查询默认自选股 - 失败:', error)
if (failCallback && typeof failCallback === 'function') {
failCallback(error)
}
throw error
}
}
}
// 导出API类
export default MySelectionsAPI
// 也可以导出单个方法供直接使用
export const {
checkExist,
getUserStockGroupList,
getUserStockList,
getUserOrDefault,
getDefaultStocks
} = MySelectionsAPI

70
api/marketSituation/marketSituation.js

@ -0,0 +1,70 @@
/** @format */
import { http } from "../../utils/http";
export const getData = () => {
return http({
method: "GET",
url: "/ka",
});
};
/**
* 获取全球指数
* POST /api/global/getGlobalIndex
*/
export const getGlobalIndexAPI = (data) => {
return http({
method: "POST",
url: "/api/global/getGlobalIndex",
data,
});
};
/**
* 获取地区分组列表
* POST /api/global/regionalGroup
*/
export const getRegionalGroupAPI = (data) => {
return http({
method: "POST",
url: "/api/global/regionalGroup",
data,
});
};
/**
* 获取地区详情
* POST /api/global/regionalGroupList
*/
export const getRegionalGroupListAPI = (data) => {
return http({
method: "POST",
url: "/api/global/regionalGroupList",
data,
});
};
/**
* 一次性查询所有Tab栏父子结构
* POST /api/homework/tab/getAll
*/
export const getAllTabsAPI = (data) => {
return http({
method: "POST",
url: "/api/homework/tab/getAll",
data,
});
};
/**
* 通用市场数据分页查询接口默认1页20条
* POST /api/market/data/page/query
*/
export const queryStockDataAPI = (data) => {
return http({
method: "POST",
url: "/api/market/data/page/query",
data,
});
};

64
components/IndexCard.vue

@ -1,8 +1,10 @@
<!-- @format -->
<template>
<view class="index-card">
<view class="card-header">
<view class="flag-container">
<image :src="flagIcon" class="flag-icon" mode="aspectFit"></image>
<image :src="getMarketFlag(market)" class="flag-icon" mode="aspectFit"></image>
</view>
<text class="index-name">{{ stockName }}</text>
</view>
@ -25,51 +27,79 @@
</template>
<script setup>
import { computed } from 'vue'
import { computed } from "vue";
//
const props = defineProps({
//
flagIcon: {
market: {
type: String,
required: true
required: true,
},
//
stockName: {
type: String,
required: true
required: true,
},
//
currentPrice: {
type: [String, Number],
required: true
required: true,
},
//
changeAmount: {
type: [String, Number],
required: true
required: true,
},
//
changePercent: {
type: [String, Number],
required: true
required: true,
},
//
isRising: {
type: Boolean,
default: true
}
})
default: true,
},
});
const getMarketFlag = (market) => {
console.log("market", market);
let imagePath;
if (market === "cn") {
imagePath = "/static/marketSituation-image/country-flag/cn.png";
} else if (market === "hk") {
imagePath = "/static/marketSituation-image/country-flag/hk.png";
} else if (market === "can") {
imagePath = "/static/marketSituation-image/country-flag/can.png";
} else if (market === "my") {
imagePath = "/static/marketSituation-image/country-flag/my.png";
} else if (market === "sg") {
imagePath = "/static/marketSituation-image/country-flag/sg.png";
} else if (market === "th") {
imagePath = "/static/marketSituation-image/country-flag/th.png";
} else if (market === "vi") {
imagePath = "/static/marketSituation-image/country-flag/vi.png";
} else if (market === "us" || market === "usa") {
imagePath = "/static/marketSituation-image/country-flag/us.png";
} else {
imagePath = "/static/marketSituation-image/country-flag/global.png";
}
console.log("返回的图片路径:", imagePath);
return imagePath;
};
//
const priceColor = computed(() => {
return props.isRising ? '#00C853' : '#FF1744'
})
return props.isRising ? "#00C853" : "#FF1744";
});
//
const chartBgColor = computed(() => {
return props.isRising ? '#E8F5E8' : '#FFEBEE'
})
return props.isRising ? "#E8F5E8" : "#FFEBEE";
});
</script>
<style scoped>
@ -163,7 +193,7 @@ const chartBgColor = computed(() => {
/* 添加一些波浪效果 */
.chart-line::before {
content: '';
content: "";
position: absolute;
top: -10rpx;
left: 20%;
@ -176,7 +206,7 @@ const chartBgColor = computed(() => {
}
.chart-line::after {
content: '';
content: "";
position: absolute;
top: -6rpx;
right: 30%;

5
components/login-prompt.vue

@ -106,6 +106,11 @@ const continueAsVisitor = async () => {
userStore.setUserInfo(res.data);
console.log("0loginStore.loginInfo", loginStore.loginInfo);
hide();
//
uni.$emit('visitorLoginSuccess', {
userInfo: res.data
});
}
};

256
pages/home/home.vue

@ -2,7 +2,8 @@
<view class="main">
<!-- 顶部状态栏占位 -->
<view class="top" :style="{height:iSMT+'px'}"></view>
<!-- 登录的提示 -->
<LoginPrompt ref="loginPrompt"></LoginPrompt>
<!-- 头部导航 -->
<view class="header">
<view class="headphone-icon">
@ -26,8 +27,8 @@
<view class="section welcome-section">
<!-- 轮播图 -->
<swiper class="welcome-swiper" circular autoplay interval="3000" duration="500" indicator-dots indicator-active-color="#4080ff">
<swiper-item v-for="(item, index) in 5" :key="index">
<image class="swiper-image" src="https://d31zlh4on95l9h.cloudfront.net/images/e4272cc034fa2a3d1ca588ef84e51ab0.png" mode="aspectFill"></image>
<swiper-item v-for="(imageUrl, index) in swiperImages" :key="index">
<image class="swiper-image" :src="imageUrl" mode="aspectFill"></image>
</swiper-item>
</swiper>
</view>
@ -193,7 +194,8 @@ import MarketOverview from '../../components/MarketOverview.vue'
import DeepMate from '../../components/DeepMate.vue'
import tcpConnection from '../../api/tcpConnection.js'
import th from '../../static/language/th'
import MySelectionsAPI from '../../api/home/mySelections.js'
import { useUserStore } from '../../stores/modules/userInfo'
export default {
components: {
footerBar,
@ -205,6 +207,9 @@ export default {
type: 'home',
iSMT: 0,
// store
userStore: null,
//
explorationItems: [
{ title: '主力追踪', icon: '/static/c1.png' },
@ -213,6 +218,15 @@ export default {
{ title: '主力资金流', icon: '/static/c4.png' }
],
//
swiperImages: [
'https://d31zlh4on95l9h.cloudfront.net/images/44ec37501cf3ecf5438d401c3d66fcd3.png',
'https://d31zlh4on95l9h.cloudfront.net/images/80274b6626bb403d717469b3672333c9.png',
'https://d31zlh4on95l9h.cloudfront.net/images/14481c76b09509977d3879ba3141ebc7.png',
'https://d31zlh4on95l9h.cloudfront.net/images/19e4c5542e5f974e1c6938897aa20ef9.png',
'https://d31zlh4on95l9h.cloudfront.net/images/d0bc1c1bb71917132865b82dab99831b.png'
],
//
myStocks: [
{ name: '特斯拉', code: 'TSLA', price: '482.00', change: 2.80, chartImg: '/static/c5.png' },
@ -251,6 +265,9 @@ export default {
type: ''
},
// TCP使
currentStockCodes: ['SH.000001', 'SH.000002', 'SH.000003'],
// TCP
myStocksTcpData: {
count: 0,
@ -319,6 +336,9 @@ export default {
//
this.iSMT = uni.getSystemInfoSync().statusBarHeight;
// store
this.userStore = useUserStore();
//
this.myStocks.forEach(stock => {
// 使uni.getImageInfoImage
@ -334,9 +354,24 @@ export default {
})
})
//
if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) {
console.log('是用户登录,加载自选股数据', this.userStore.userInfo)
this.loadMySelectionsData()
} else if (this.userStore.userInfo && this.userStore.userInfo.isVisitor){
console.log('是游客登录,加载默认自选股',this.userStore.userInfo)
this.loadGuestDefaultStocks()
}else {
console.log('用户未登录',this.userStore.userInfo)
}
// TCP
this.initTcpListeners()
//
uni.$on('visitorLoginSuccess', this.handleVisitorLoginSuccess)
// TCP
this.$nextTick(() => {
console.log('页面渲染完成,开始自动连接TCP服务器...')
@ -389,9 +424,36 @@ export default {
// TCP
this.removeTcpListeners()
//
uni.$off('visitorLoginSuccess', this.handleVisitorLoginSuccess)
},
methods: {
//
handleVisitorLoginSuccess(data) {
console.log('收到游客登录成功事件:', data)
//
this.reloadPageData()
},
//
reloadPageData() {
console.log('重新加载页面数据...')
// store
this.userStore = useUserStore()
//
if (this.userStore.userInfo && this.userStore.userInfo.isVisitor) {
console.log('游客登录成功,加载默认自选股')
this.loadGuestDefaultStocks()
} else if (this.userStore.userInfo && !this.userStore.userInfo.isVisitor) {
console.log('用户登录,加载自选股数据')
this.loadMySelectionsData()
}
},
//
debounce(fn, delay = 300) {
if (this.debounceTimer) clearTimeout(this.debounceTimer)
@ -401,6 +463,186 @@ export default {
}, delay)
},
//
//
async loadMySelectionsData() {
try {
console.log('开始加载自选股数据...')
// checkExist
const checkResult = await MySelectionsAPI.checkExist()
console.log('检查用户自选股存在性结果:', checkResult)
if (checkResult.code === 200) {
const isHave = checkResult.data.is_have
if (isHave === 1) {
//
console.log('用户存在自选股,查询所有分组...')
await this.loadUserStockGroups()
} else {
//
console.log('用户不存在自选股,查询默认自选股...')
await this.loadDefaultStocks()
}
} else {
console.error('检查用户自选股存在性失败:', checkResult.message)
//
// await this.loadDefaultStocks()
}
} catch (error) {
console.error('加载自选股数据失败:', error)
//
await this.loadDefaultStocks()
}
},
//
async loadUserStockGroups() {
try {
const groupResult = await MySelectionsAPI.getUserStockGroupList()
console.log('查询用户自选股分组结果:', groupResult)
if (groupResult.code === 200 && groupResult.data && groupResult.data.length > 0) {
// id
const minIdGroup = groupResult.data.reduce((min, current) => {
return current.id < min.id ? current : min
})
console.log('找到最小id分组:', minIdGroup)
//
await this.loadGroupStocks(minIdGroup.id)
} else {
console.log('没有找到用户自选股分组,加载默认自选股')
await this.loadDefaultStocks()
}
} catch (error) {
console.error('加载用户自选股分组失败:', error)
await this.loadDefaultStocks()
}
},
//
async loadGroupStocks(groupId) {
try {
const stockResult = await MySelectionsAPI.getUserStockList(null, null, {
groupId: groupId,
pageNum: 1,
pageSize: 20
})
console.log('查询分组自选股结果:', stockResult)
if (stockResult.code === 200 && stockResult.data) {
this.processStockData(stockResult.data)
} else {
console.log('分组下没有股票数据,加载默认自选股')
await this.loadDefaultStocks()
}
} catch (error) {
console.error('加载分组股票失败:', error)
await this.loadDefaultStocks()
}
},
//
async loadDefaultStocks() {
try {
const defaultResult = await MySelectionsAPI.getUserOrDefault()
console.log('查询默认自选股结果:', defaultResult)
if (defaultResult.code === 200 && defaultResult.data) {
this.processStockData(defaultResult.data)
} else {
console.log('没有默认自选股数据')
}
} catch (error) {
console.error('加载默认自选股失败:', error)
}
},
//
async loadGuestDefaultStocks() {
try {
console.log('游客开始加载默认自选股...')
const guestResult = await MySelectionsAPI.getDefaultStocks()
console.log('游客查询默认自选股结果:', guestResult)
if (guestResult.code === 200 && guestResult.data) {
this.processStockData(guestResult.data)
} else {
console.log('游客没有默认自选股数据')
}
} catch (error) {
console.error('游客加载默认自选股失败:', error)
}
},
//
processStockData(stockData) {
console.log('处理股票数据:', stockData)
// myStocks
// API
if (Array.isArray(stockData)) {
//
this.myStocks = stockData.map(stock => ({
name: stock.name || stock.stock_name || '',
code: stock.code || stock.stock_code || '',
// price: stock.price || stock.current_price || '0.00',
// change: stock.change || stock.change_percent || 0,
chartImg: stock.chartImg || '/static/c5.png' //
}))
//
this.institutionalReports = stockData.map(stock => ({
stock: stock.name || stock.stock_name || '',
status: stock.code || stock.stock_code || '',
}))
} else if (stockData.list && Array.isArray(stockData.list)) {
//
this.myStocks = stockData.list.map(stock => ({
name: stock.name || stock.stock_name || '',
code: stock.code || stock.stock_code || '',
// price: stock.price || stock.current_price || '0.00',
// change: stock.change || stock.change_percent || 0,
chartImg: stock.chartImg || '/static/c5.png' //
}))
//
//
this.institutionalReports = stockData.map(stock => ({
stock: stock.name || stock.stock_name || '',
status: stock.code || stock.stock_code || '',
}))
}
console.log('更新后的自选股数据:', this.myStocks)
// TCP
this.updateTcpStockCodes()
},
// TCP
updateTcpStockCodes() {
// myStocks3
const stockCodes = this.myStocks.slice(0, 3).map(stock => stock.code).filter(code => code)
console.log('更新TCP消息股票代码:', stockCodes)
// TCP
if (stockCodes.length > 0) {
// 33
while (stockCodes.length < 3) {
stockCodes.push('SH.000001') //
}
// TCP使
this.currentStockCodes = stockCodes
console.log('当前TCP使用的股票代码:', this.currentStockCodes)
}
},
// TCP
// TCP
@ -856,7 +1098,7 @@ export default {
// }
// {"command": "stock_list"}
// {"command": "batch_real_time", "stock_codes": ["SH.000001"]}
{"command": "batch_real_time", "stock_codes": ["SH.000001","SH.000002","SH.000003"]}
{"command": "batch_real_time", "stock_codes": this.currentStockCodes}
//
const success = tcpConnection.send(messageData)
@ -873,7 +1115,7 @@ export default {
// TCP
sendMyStocksTcpMessage() {
// -
const messageData = {"command": "batch_real_time", "stock_codes": ["SH.000001","SH.000002","SH.000003"]}
const messageData = {"command": "batch_real_time", "stock_codes": this.currentStockCodes}
// channel 2TCP
const success = tcpConnection.send(messageData, { channel: '2' })
@ -1424,7 +1666,7 @@ export default {
.welcome-swiper {
width: 100%;
height: 150px;
height: 110px;
border-radius: 0;
overflow: hidden;
}

141
pages/marketSituation/countryMarket.vue

@ -1,9 +1,10 @@
<!-- @format -->
<template>
<view class="content">
<!-- 市场子Tab -->
<view class="sub_tabs">
<view v-for="(tab, i) in marketTabs" :key="tab" :class="['tab_item', i === activeTabIndex ? 'active' : '']"
@click="switchTab(i)">
<view v-for="(tab, i) in marketTabs" :key="tab" :class="['tab_item', i === activeTabIndex ? 'active' : '']" @click="switchTab(i)">
<text>{{ tab }}</text>
</view>
</view>
@ -16,8 +17,7 @@
</view>
<view class="indices_grid">
<view v-for="(index, i) in countryInfo.mainIndices" :key="i" class="index_item">
<IndexCard :flagIcon="countryInfo.flag" :indexName="index.name" :currentPrice="index.price"
:changeAmount="index.change" :changePercent="index.changePercent" :isRising="index.isRising" />
<IndexCard :market="countryInfo.market" :indexName="index.name" :currentPrice="index.price" :changeAmount="index.change" :changePercent="index.changePercent" :isRising="index.isRising" />
</view>
</view>
@ -92,115 +92,120 @@
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import IndexCard from '../../components/IndexCard.vue'
import { ref, computed, onMounted } from "vue";
import IndexCard from "../../components/IndexCard.vue";
// Tab
const marketTabs = ['全部', '美股', '纽交所', '纳斯达克']
const activeTabIndex = ref(0)
// const marketTabs = ["", "", "", ""];
const activeTabIndex = ref(0);
const switchTab = (i) => {
activeTabIndex.value = i
}
activeTabIndex.value = i;
};
//
const sentimentMeters = [
{ value: 90, label: '道琼斯', theme: 'hot' },
{ value: 60, label: '纳斯达克', theme: 'warm' },
{ value: 20, label: '标普500', theme: 'cool' }
]
{ value: 90, label: "道琼斯", theme: "hot" },
{ value: 60, label: "纳斯达克", theme: "warm" },
{ value: 20, label: "标普500", theme: "cool" },
];
//
const selectIcons = {
hot: '/static/marketSituation-image/hot.png',
warm: '/static/marketSituation-image/warm.png',
cool: '/static/marketSituation-image/cool.png'
}
hot: "/static/marketSituation-image/hot.png",
warm: "/static/marketSituation-image/warm.png",
cool: "/static/marketSituation-image/cool.png",
};
// Props
const props = defineProps({
countryId: {
type: Number,
required: true
}
})
required: true,
},
marketTabs: {
type: Array,
},
});
// /
const countryInfoMap = {
2: { //
name: '新加坡',
flag: '🇸🇬',
2: {
//
name: "新加坡",
flag: "🇸🇬",
isMarketOpen: true,
mainIndices: [
{ name: '海峡时报指数', price: '3,234.56', change: '+12.34', changePercent: '+0.38%', isRising: true },
{ name: 'FTSE ST Mid Cap', price: '1,234.56', change: '-5.67', changePercent: '-0.46%', isRising: false }
{ name: "海峡时报指数", price: "3,234.56", change: "+12.34", changePercent: "+0.38%", isRising: true },
{ name: "FTSE ST Mid Cap", price: "1,234.56", change: "-5.67", changePercent: "-0.46%", isRising: false },
],
hotStocks: [
{ name: '星展银行', code: 'D05.SI', price: '35.20', change: '+0.15', isRising: true },
{ name: '华侨银行', code: 'O39.SI', price: '13.45', change: '-0.05', isRising: false }
]
{ name: "星展银行", code: "D05.SI", price: "35.20", change: "+0.15", isRising: true },
{ name: "华侨银行", code: "O39.SI", price: "13.45", change: "-0.05", isRising: false },
],
},
3: { // 西
name: '马来西亚',
flag: '🇲🇾',
3: {
// 西
name: "马来西亚",
flag: "🇲🇾",
isMarketOpen: false,
mainIndices: [
{ name: '富时大马KLCI指数', price: '1,567.89', change: '+8.90', changePercent: '+0.57%', isRising: true }
],
mainIndices: [{ name: "富时大马KLCI指数", price: "1,567.89", change: "+8.90", changePercent: "+0.57%", isRising: true }],
hotStocks: [
{ name: '马来亚银行', code: '1155.KL', price: '9.85', change: '+0.10', isRising: true },
{ name: '大众银行', code: '1295.KL', price: '4.32', change: '-0.02', isRising: false }
]
{ name: "马来亚银行", code: "1155.KL", price: "9.85", change: "+0.10", isRising: true },
{ name: "大众银行", code: "1295.KL", price: "4.32", change: "-0.02", isRising: false },
],
},
4: { // 西
name: '印度尼西亚',
flag: '🇮🇩',
4: {
// 西
name: "印度尼西亚",
flag: "🇮🇩",
isMarketOpen: true,
mainIndices: [
{ name: '雅加达综合指数', price: '7,234.56', change: '+45.67', changePercent: '+0.63%', isRising: true }
],
hotStocks: []
mainIndices: [{ name: "雅加达综合指数", price: "7,234.56", change: "+45.67", changePercent: "+0.63%", isRising: true }],
hotStocks: [],
},
5: { //
name: '美国',
flag: '🇺🇸',
5: {
//
name: "美国",
flag: "🇺🇸",
isMarketOpen: false,
mainIndices: [
{ name: '道琼斯', price: '45,757.90', change: '-125.22', changePercent: '-0.27%', isRising: false },
{ name: '纳斯达克', price: '22,333.96', change: '+125.22', changePercent: '+0.47%', isRising: true },
{ name: '标普500', price: '6,606.08', change: '+125.22', changePercent: '+0.27%', isRising: true }
{ name: "道琼斯", price: "45,757.90", change: "-125.22", changePercent: "-0.27%", isRising: false },
{ name: "纳斯达克", price: "22,333.96", change: "+125.22", changePercent: "+0.47%", isRising: true },
{ name: "标普500", price: "6,606.08", change: "+125.22", changePercent: "+0.27%", isRising: true },
],
hotStocks: [
{ name: '苹果', code: 'AAPL', price: '195.89', change: '+2.34', isRising: true },
{ name: '微软', code: 'MSFT', price: '378.85', change: '-1.23', isRising: false }
]
}
}
{ name: "苹果", code: "AAPL", price: "195.89", change: "+2.34", isRising: true },
{ name: "微软", code: "MSFT", price: "378.85", change: "-1.23", isRising: false },
],
},
};
//
const countryInfo = computed(() => {
return countryInfoMap[props.countryId] || {
name: '未知地区',
flag: '🌍',
return (
countryInfoMap[props.countryId] || {
name: "未知地区",
flag: "🌍",
isMarketOpen: false,
mainIndices: [],
hotStocks: []
hotStocks: [],
}
})
);
});
//
const sectors = computed(() => {
return countryInfoMap[props.countryId]?.sectors || []
})
return countryInfoMap[props.countryId]?.sectors || [];
});
const stocks = computed(() => {
return countryInfoMap[props.countryId]?.stocks || []
})
return countryInfoMap[props.countryId]?.stocks || [];
});
//
const viewMore = (type) => {
// type
// indices/sectors/stocks
// uni.navigateTo({ url: `/pages/marketSituation/${type}List` })
}
};
</script>
<style scoped>
@ -256,12 +261,12 @@ const viewMore = (type) => {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20rpx;
background-color: #F6F6F6;
background-color: #f6f6f6;
}
/* 情绪温度 */
.sentiment {
background-color: #F6F6F6;
background-color: #f6f6f6;
padding: 0 20rpx 20rpx 20rpx;
}

382
pages/marketSituation/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>
@ -33,58 +32,25 @@
<!-- 内容区域 -->
<scroll-view class="content" :style="{ top: contentTopPosition + 'px' }" scroll-y="true">
<!-- 亚太-中华 -->
<view class="market-section">
<view class="market-header">
<text class="market-title">亚太-中华</text>
<view class="market-more" @click="viewMore('asia-china')">
<text class="more-text">查看更多</text>
<text class="more-arrow">></text>
</view>
</view>
<view class="cards-grid-three">
<view v-for="(item, index) in asiachinaIndexes" :key="index" class="card-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>
<!-- 亚太 -->
<view class="market-section">
<view class="market-section" v-for="item in globalIndexArray" :key="item">
<view class="market-header">
<text class="market-title">亚太</text>
<view class="market-more" @click="viewMore('asia')">
<text class="market-title">{{ item.ac }}</text>
<view class="market-more" @click="viewMore(item.ac)">
<text class="more-text">查看更多</text>
<text class="more-arrow">></text>
</view>
</view>
<view class="cards-grid-three">
<view v-for="(item, index) in asiaIndexes" :key="index" class="card-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>
<!-- 美洲 -->
<view class="market-section">
<view class="market-header">
<text class="market-title">美洲</text>
<view class="market-more" @click="viewMore('america')">
<text class="more-text">查看更多</text>
<text class="more-arrow">></text>
</view>
</view>
<view class="cards-grid-three">
<view v-for="(item, index) in americaIndexes" :key="index" class="card-item">
<IndexCard :flagIcon="item.flagIcon" :stockName="item.stockName"
:currentPrice="item.currentPrice" :changeAmount="item.changeAmount"
:changePercent="item.changePercent" :isRising="item.isRising"
@click="viewIndexDetail(item)" />
<view v-for="iitem in item.list" :key="iitem" class="card-item">
<IndexCard
:market="iitem.market"
:stockName="iitem.name"
:currentPrice="iitem.currentPrice"
:changeAmount="iitem.changeAmount"
:changePercent="iitem.changePercent"
:isRising="iitem.isRising"
@click="viewIndexDetail(iitem)"
/>
</view>
</view>
</view>
@ -99,201 +65,202 @@
</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";
import { getRegionalGroupAPI } from "../../api/marketSituation/marketSituation.js";
//
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)
isWarnTextOverflow.value = isOverflow
})
}, 500)
})
}
const isOverflow = textRect.width > containerRect.width - 10;
isWarnTextOverflow.value = isOverflow;
});
}, 500);
});
};
const globalIndexArray = ref([]);
// -
const asiachinaIndexes = ref([
{
flagIcon: '/static/c1.png',
stockName: '上证指数',
stockCode:'noCode',
currentPrice: '3933.96',
changeAmount: '+24.32',
changePercent: '+0.62%',
isRising: true
flagIcon: "/static/c1.png",
stockName: "上证指数",
stockCode: "noCode",
currentPrice: "3933.96",
changeAmount: "+24.32",
changePercent: "+0.62%",
isRising: true,
},
{
flagIcon: '/static/c2.png',
stockName: '深证成指',
stockCode:'noCode',
currentPrice: '45757.90',
changeAmount: '-123.45',
changePercent: '-0.27%',
isRising: false
flagIcon: "/static/c2.png",
stockName: "深证成指",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "-123.45",
changePercent: "-0.27%",
isRising: false,
},
{
flagIcon: '/static/c3.png',
stockName: '创业板指',
stockCode:'noCode',
currentPrice: '6606.08',
changeAmount: '+89.76',
changePercent: '+1.38%',
isRising: true
flagIcon: "/static/c3.png",
stockName: "创业板指",
stockCode: "noCode",
currentPrice: "6606.08",
changeAmount: "+89.76",
changePercent: "+1.38%",
isRising: true,
},
{
flagIcon: '/static/c4.png',
stockName: 'HSI50',
stockCode:'noCode',
currentPrice: '22333.96',
changeAmount: '+156.78',
changePercent: '+0.71%',
isRising: true
flagIcon: "/static/c4.png",
stockName: "HSI50",
stockCode: "noCode",
currentPrice: "22333.96",
changeAmount: "+156.78",
changePercent: "+0.71%",
isRising: true,
},
{
flagIcon: '/static/c5.png',
stockName: '沪深300',
stockCode:'noCode',
currentPrice: '45757.90',
changeAmount: '-89.12',
changePercent: '-0.19%',
isRising: false
flagIcon: "/static/c5.png",
stockName: "沪深300",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "-89.12",
changePercent: "-0.19%",
isRising: false,
},
{
flagIcon: '/static/c6.png',
stockName: '上证50',
stockCode:'noCode',
currentPrice: '45757.90',
changeAmount: '+234.56',
changePercent: '+0.52%',
isRising: true
}
])
flagIcon: "/static/c6.png",
stockName: "上证50",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "+234.56",
changePercent: "+0.52%",
isRising: true,
},
]);
//
const asiaIndexes = ref([
{
flagIcon: '/static/c7.png',
stockName: '日经225',
stockCode:'noCode',
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',
stockName: '韩国KOSPI',
stockCode:'noCode',
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',
stockName: '印度孟买',
stockCode:'noCode',
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',
stockName: '道琼斯指数',
stockCode:'noCode',
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',
stockName: '纳斯达克',
stockCode:'noCode',
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',
stockName: '标普500',
stockCode:'noCode',
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/marketSituation/marketDetail?market=${market}`
})
}
url: `/pages/marketSituation/marketDetail?market=${market}`,
});
};
//
const viewIndexDetail = (item) => {
console.log('查看指数详情:', item.stockName)
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
@ -301,40 +268,54 @@ const viewIndexDetail = (item) => {
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`
})
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
});
};
const getRegionalGroup = async () => {
try {
const result = await getRegionalGroupAPI();
globalIndexArray.value = result.data;
} catch (e) {
console.log("获取区域指数失败", e);
}
};
//
onMounted(() => {
onMounted(async () => {
await getRegionalGroup();
//
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>
@ -430,7 +411,6 @@ watch(headerHeight, (newHeight) => {
height: 40rpx;
}
.warn {
display: flex;
align-items: center;

74
pages/marketSituation/marketCondition.vue

@ -8,12 +8,12 @@
<view class="title">
<image class="back-homepage-btn" src="/static/marketSituation-image/back.png" mode="返回按钮" @click="backToHomepage()"> </image>
<view class="mid-title">
<view class="arrow-left"> </view>
<view class="arrow-left" @click="toLeftPage()"> </view>
<view class="stock-id">
<view class="stock-name"> {{ stockInformation.stockName }} </view>
<view class="stock-code"> {{ stockInformation.stockCode }} </view>
</view>
<view class="arrow-right"> </view>
<view class="arrow-right" @click="toRightPage()"> </view>
</view>
<image class="search" src="/static/marketSituation-image/search.png" mode="搜索" @click="search()"> </image>
<view class="more" @click="getMore()">···</view>
@ -240,6 +240,10 @@ const tcpConnected = ref(false);
const connectionListener = ref(null);
const messageListener = ref(null);
//
const currentStockFrom = ref();
//
const currentStockIndex = ref(-1);
//
const stockInformation = ref({
stockName: "----", //
@ -511,6 +515,35 @@ const backToHomepage = () => {
}
};
const toLeftPage = () => {
if(currentStockFrom.value == "marketOverview"){
return;
}
if (currentStockIndex.value > 0) {
currentStockIndex.value--;
// updateStockInformation();
} else {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
}
};
const toRightPage = () => {
if (currentStockIndex.value < stockList.length - 1) {
currentStockIndex.value++;
// updateStockInformation();
} else {
uni.showToast({
title: "没有更多股票了",
icon: "none",
duration: 1000,
});
}
};
const openStockDetail = () => {
isStockDetail.value = true;
};
@ -2136,10 +2169,10 @@ const startAddDataTimer = () => {
onLoad((options) => {
console.log("页面接收到的参数:", options);
// data
if (options.data) {
// stockInformation
if (options.stockInformation) {
try {
const stockData = JSON.parse(decodeURIComponent(options.data));
const stockData = JSON.parse(decodeURIComponent(options.stockInformation));
console.log("解析的股票数据:", stockData);
// stockInformation
@ -2152,30 +2185,17 @@ onLoad((options) => {
}
}
// 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);
}
// index
if (options.index !== undefined) {
const stockIndex = parseInt(options.index);
console.log("股票在列表中的索引:", stockIndex);
// index
currentStockIndex.value = stockIndex;
}
//
if (options.stockCode) {
stockInformation.value.stockCode = options.stockCode;
}
if (options.stockName) {
stockInformation.value.stockName = decodeURIComponent(options.stockName);
// stockFrom
if (options.stockFrom) {
currentStockFrom.value = options.stockFrom;
}
});

275
pages/marketSituation/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="viewIndexDetail(stock)">
<view class="stock-row" v-for="(stock, index) in sortedStockList" :key="index" @click="viewIndexDetail(stock)">
<view class="stock-cell name-column">
<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,174 +64,170 @@
</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";
import { getRegionalGroupListAPI } from "../../api/marketSituation/marketSituation.js";
//
const iSMT = ref(0)
const contentHeight = 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 contentHeight = ref(0);
const headerHeight = ref(80);
const marketTitle = ref();
const sortType = ref(""); // 'price' 'change'
const sortOrder = ref("desc"); // 'asc' 'desc'
//
const stockList = ref([
{
stockName: 'Telecommunication',
stockCode: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1349.47,
change: '+7.67%',
isRising: true
change: "+7.67%",
isRising: true,
},
{
stockName: 'Other',
stockCode: '888607',
stockName: "Other",
stockCode: "888607",
price: 1349.47,
change: '+6.67%',
isRising: true
change: "+6.67%",
isRising: true,
},
{
stockName: 'Consumer Discretio...',
stockCode: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1349.47,
change: '+5.67%',
isRising: true
change: "+5.67%",
isRising: true,
},
{
stockName: 'Telecommunication',
stockCode: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1349.47,
change: '+4.67%',
isRising: true
change: "+4.67%",
isRising: true,
},
{
stockName: 'Other',
stockCode: '888611',
stockName: "Other",
stockCode: "888611",
price: 1359.47,
change: '+3.67%',
isRising: true
change: "+3.67%",
isRising: true,
},
{
stockName: 'Consumer Discretio...',
stockCode: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1349.47,
change: '+2.67%',
isRising: true
change: "+2.67%",
isRising: true,
},
{
stockName: 'Telecommunication',
stockCode: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1349.47,
change: '+1.67%',
isRising: true
change: "+1.67%",
isRising: true,
},
{
stockName: 'Other',
stockCode: '888611',
stockName: "Other",
stockCode: "888611",
price: 1009.98,
change: '-1.67%',
isRising: false
change: "-1.67%",
isRising: false,
},
{
stockName: 'Consumer Discretio...',
stockCode: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-0.67%',
isRising: false
change: "-0.67%",
isRising: false,
},
{
stockName: 'Telecommunication',
stockCode: '888607',
stockName: "Telecommunication",
stockCode: "888607",
price: 1009.98,
change: '-0.67%',
isRising: false
change: "-0.67%",
isRising: false,
},
{
stockName: 'Other',
stockCode: '888611',
stockName: "Other",
stockCode: "888611",
price: 1009.98,
change: '-1.67%',
isRising: false
change: "-1.67%",
isRising: false,
},
{
stockName: 'Consumer Discretio...',
stockCode: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-4.67%',
isRising: false
change: "-4.67%",
isRising: false,
},
{
stockName: 'Consumer Discretio...',
stockCode: '888610',
stockName: "Consumer Discretio...",
stockCode: "888610",
price: 1009.98,
change: '-3.67%',
isRising: false
change: "-3.67%",
isRising: false,
},
{
stockName: 'Consumer Discretio...',
stockCode: '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;
});
const getRegionalGroupList = async () => {
try {
const result = await getRegionalGroupListAPI({
market: marketTitle.value,
});
} catch (e) {
console.error("获取区域分组列表失败:", e);
}
};
//
onLoad((options) => {
if (options && 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
default:
marketTitle.value = '全球指数'
}
marketTitle.value = options.market;
}
})
});
//
const goBack = () => {
uni.navigateBack()
}
uni.navigateBack();
};
//
const viewIndexDetail = (item) => {
console.log('查看指数详情:', item.stockName)
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
// icon: 'none',
@ -242,52 +235,56 @@ const viewIndexDetail = (item) => {
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`
})
}
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
});
};
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";
}
};
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>
@ -471,11 +468,11 @@ watch(headerHeight, (newHeight) => {
}
.rising {
color: #00C851;
color: #00c851;
}
.falling {
color: #FF4444;
color: #ff4444;
}
/* 底部安全区域 */

121
pages/marketSituation/marketOverview.vue

@ -20,8 +20,16 @@
<!-- 卡片网格 -->
<view class="cards_grid">
<view v-for="(card, index) in cardData" :key="index" class="card_item">
<IndexCard :flagIcon="card.flagIcon" :stockName="card.stockName" :currentPrice="card.currentPrice" :changeAmount="card.changeAmount" :changePercent="card.changePercent" :isRising="card.isRising" @click="viewIndexDetail(card)" />
<view v-for="(card, index) in marketSituationStore.cardData" :key="index" class="card_item">
<IndexCard
:market="card.market"
:stockName="card.stockName"
:currentPrice="card.currentPrice"
:changeAmount="card.changeAmount"
:changePercent="card.changePercent"
:isRising="card.isRising"
@click="viewIndexDetail(card, index)"
/>
</view>
</view>
<view class="warn">
@ -41,6 +49,9 @@
import { ref, onMounted, watch, nextTick, computed } from "vue";
import util from "../../common/util.js";
import IndexCard from "../../components/IndexCard.vue";
import { useMarketSituationStore } from "../../stores/modules/marketSituation.js";
const marketSituationStore = useMarketSituationStore();
import { getGlobalIndexAPI } from "../../api/marketSituation/marketSituation.js";
const iSMT = ref(0);
const searchValue = ref("");
@ -63,95 +74,7 @@ const warnTextClass = computed(() => {
return isWarnTextOverflow.value ? "warn_text scroll-active" : "warn_text";
});
//
const showCountryModal = ref(false);
const selectedCountry = ref("概况");
const countryList = ref(["概况", "新加坡", "马来西亚", "印度尼西亚", "美国", "中国香港", "泰国", "中国", "加拿大", "越南", "外汇", "贵金属"]);
//
const cardData = ref([
{
flagIcon: "🇺🇸",
stockName: "道琼斯",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "-125.22",
changePercent: "-0.27%",
isRising: false,
},
{
flagIcon: "🇺🇸",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "22333.96",
changeAmount: "+125.22",
changePercent: "+0.47%",
isRising: true,
},
{
flagIcon: "🇺🇸",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "6606.08",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
flagIcon: "🇨🇳",
stockName: "上证指数",
stockCode: "noCode",
currentPrice: "3333.96",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
flagIcon: "🇨🇳",
stockName: "科创50",
stockCode: "noCode",
currentPrice: "757.90",
changeAmount: "-25.22",
changePercent: "-0.27%",
isRising: false,
},
{
flagIcon: "🇭🇰",
stockName: "恒生指数",
stockCode: "noCode",
currentPrice: "19757.90",
changeAmount: "-125.22",
changePercent: "-0.63%",
isRising: false,
},
{
flagIcon: "🇸🇬",
stockName: "道琼斯",
stockCode: "noCode",
currentPrice: "3757.90",
changeAmount: "+85.22",
changePercent: "+2.31%",
isRising: true,
},
{
flagIcon: "🇲🇾",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "1657.90",
changeAmount: "-15.22",
changePercent: "-0.91%",
isRising: false,
},
{
flagIcon: "🇹🇭",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "1457.90",
changeAmount: "+35.22",
changePercent: "+2.48%",
isRising: true,
},
]);
const globalIndexArray = ref([]);
//
const onSearchInput = (e) => {
@ -216,7 +139,7 @@ const checkWarnTextOverflow = () => {
};
//
const viewIndexDetail = (item) => {
const viewIndexDetail = (item, index) => {
console.log("查看指数详情:", item.stockName);
// uni.showToast({
// title: ` ${item.stockName} `,
@ -225,7 +148,7 @@ const viewIndexDetail = (item) => {
// })
//
uni.navigateTo({
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}`,
url: `/pages/marketSituation/marketCondition?stockInformation=${encodeURIComponent(JSON.stringify(item))}&index=${index}&from=marketOverview`,
});
};
@ -236,7 +159,17 @@ const goToGlobalIndex = () => {
});
};
onMounted(() => {
const getGlobalIndex = async () => {
try {
const result = await getGlobalIndexAPI();
globalIndexArray.value = result.data;
} catch (e) {
console.log("获取全球指数失败", e);
}
};
onMounted(async () => {
await getGlobalIndex();
//
iSMT.value = uni.getSystemInfoSync().statusBarHeight;

252
pages/marketSituation/marketSituation.vue

@ -1,3 +1,5 @@
<!-- @format -->
<template>
<view>
<view class="main">
@ -5,11 +7,8 @@
<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">
@ -21,11 +20,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>
@ -40,7 +37,7 @@
<!-- 可滚动内容区域 -->
<scroll-view class="content_scroll" scroll-y="true" :style="{ top: contentTopPosition + 'px' }">
<!-- 动态组件切换 -->
<component :is="currentComponent" :countryId="currentChannelId" />
<component :is="currentComponent" :countryId="currentChannelId" :marketTabs="getChildMarketTabs(currentChannelId)" />
</scroll-view>
</view>
@ -57,10 +54,8 @@
</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)">
<text class="country_text">{{ country }}</text>
<view v-for="(item, index) in channelData" :key="index" :class="['country_item', selectedCountry === item.title ? 'selected' : '']" @click="selectCountry(item.title)">
<text class="country_text">{{ item.title }}</text>
</view>
</view>
</view>
@ -70,228 +65,229 @@
</template>
<script setup>
import { ref, onMounted, watch, nextTick, computed } from 'vue'
import footerBar from '../../components/footerBar.vue'
import forexMetals from './forexMetals.vue'
import marketOverview from './marketOverview.vue'
import countryMarket from './countryMarket.vue'
const type = ref('marketSituation')
const iSMT = ref(0)
const searchValue = ref('')
const contentHeight = ref(0)
const headerHeight = ref(0) // header
import { ref, onMounted, watch, nextTick, computed } from "vue";
import footerBar from "../../components/footerBar.vue";
import forexMetals from "./forexMetals.vue";
import marketOverview from "./marketOverview.vue";
import countryMarket from "./countryMarket.vue";
import { getAllTabsAPI } from "../../api/marketSituation/marketSituation.js";
const type = ref("marketSituation");
const iSMT = ref(0);
const searchValue = ref("");
const contentHeight = ref(0);
const headerHeight = ref(0); // header
// 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('')
const channelData = ref([{ id: 1, title: "概况" }]);
const pageIndex = ref(0);
const scrollToView = ref("");
//
const currentChannelId = computed(() => {
return channelData.value[pageIndex.value]?.id || 1
})
return channelData.value[pageIndex.value]?.id || 1;
});
const currentComponent = computed(() => {
const channelId = currentChannelId.value
const channelId = currentChannelId.value;
// 使 MarketOverview
if (pageIndex.value === 0) {
return marketOverview
return marketOverview;
}
// (id=11)(id=12)使 ForexMetals
else if (channelId === 11 || channelId === 12) {
return forexMetals
return forexMetals;
}
// /使 CountryMarket
else {
return countryMarket
return countryMarket;
}
})
});
// 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;
});
//
const showCountryModal = ref(false)
const selectedCountry = ref('概况')
const countryList = ref([
'概况', '新加坡', '马来西亚', '印度尼西亚', '美国', '中国香港',
'泰国', '中国', '加拿大', '越南', '外汇', '贵金属'
])
const showCountryModal = ref(false);
const selectedCountry = ref("概况");
const getAllTabs = async () => {
try {
const result = await getAllTabsAPI();
channelData.value = result.data.map((item) => ({ ...item, id: item.id, title: item.tradeName }));
} catch (e) {
console.error("获取地区分组列表失败", e);
}
};
const getChildMarketTabs = (id) => {
return channelData.value.filter((item) => item.id === id)[0]?.children?.map((child) => child.tradeName);
};
//
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;
};
onMounted(() => {
onMounted(async () => {
await getAllTabs();
//
iSMT.value = uni.getSystemInfoSync().statusBarHeight;
// 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;
}
// 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();
});
});
// 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>
@ -458,7 +454,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;

BIN
static/marketSituation-image/country-flag/can.png

After

Width: 32  |  Height: 32  |  Size: 1.1 KiB

BIN
static/marketSituation-image/country-flag/cn.png

After

Width: 32  |  Height: 32  |  Size: 1.1 KiB

BIN
static/marketSituation-image/country-flag/global.png

After

Width: 32  |  Height: 32  |  Size: 2.5 KiB

BIN
static/marketSituation-image/country-flag/hk.png

After

Width: 32  |  Height: 32  |  Size: 1.7 KiB

BIN
static/marketSituation-image/country-flag/my.png

After

Width: 32  |  Height: 32  |  Size: 1.7 KiB

BIN
static/marketSituation-image/country-flag/sg.png

After

Width: 32  |  Height: 32  |  Size: 1.1 KiB

BIN
static/marketSituation-image/country-flag/th.png

After

Width: 32  |  Height: 32  |  Size: 703 B

BIN
static/marketSituation-image/country-flag/us.png

After

Width: 32  |  Height: 32  |  Size: 1.4 KiB

BIN
static/marketSituation-image/country-flag/vi.png

After

Width: 32  |  Height: 32  |  Size: 1.1 KiB

78
stores/modules/marketSituation.js

@ -0,0 +1,78 @@
/** @format */
import { defineStore } from "pinia";
import { ref } from "vue";
// 定义 Store
export const useMarketSituationStore = defineStore(
"marketSituation",
() => {
const cardData = ref([
{
market: "usa",
stockName: "道琼斯",
stockCode: "noCode",
currentPrice: "45757.90",
changeAmount: "-125.22",
changePercent: "-0.27%",
isRising: false,
},
{
market: "usa",
stockName: "纳斯达克",
stockCode: "noCode",
currentPrice: "22333.96",
changeAmount: "+125.22",
changePercent: "+0.47%",
isRising: true,
},
{
market: "usa",
stockName: "标普500",
stockCode: "noCode",
currentPrice: "6606.08",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
market: "cn",
stockName: "上证指数",
stockCode: "noCode",
currentPrice: "3333.96",
changeAmount: "+125.22",
changePercent: "+0.27%",
isRising: true,
},
{
market: "cn",
stockName: "科创50",
stockCode: "noCode",
currentPrice: "757.90",
changeAmount: "-25.22",
changePercent: "-0.27%",
isRising: false,
},
]);
// 记得 return
return {
cardData
};
},
// TODO: 持久化
{
// 网页端持久化
// persist: true,
// 小程序端持久化
persist: {
storage: {
getItem(key) {
return uni.getStorageSync(key);
},
setItem(key, value) {
uni.setStorageSync(key, value);
},
},
},
}
);

2
utils/http.js

@ -44,10 +44,12 @@ const httpInterceptor = {
//4 添加token,优先用store,没有则回退到body中的token,保持与Apifox一致
const memberStore = useUserStore()
const token = memberStore.userInfo?.token || options.data?.token
// const token = '2d0b5654409646713cdd40ec0d0bb56c'
// const token = '1b3a58424c5324e40d4bf4d085e18047'
if (token) {
options.header.token = token
}
console.log("最终请求参数:",options)
// 避免误用 Authorization 头,后端要求的是 token 头
// if (options.header.Authorization) delete options.header.Authorization
return options

Loading…
Cancel
Save