优化了侧边栏数据请求代码

This commit is contained in:
xlmessage 2025-02-17 10:11:10 +08:00
parent 7ca272ab7e
commit c4e53ee2b6

@ -15,7 +15,7 @@ const message = ref(''); // 用于存储要发送的消息
* 万策页面进行保存筛选条件保存的是一个请求参数可在数据库的user_strategy表中查看 * 万策页面进行保存筛选条件保存的是一个请求参数可在数据库的user_strategy表中查看
* 通过https://wance.cqxqg.tech/api/v1/strategy/getStockPageList * 通过https://wance.cqxqg.tech/api/v1/strategy/getStockPageList
* 后端的逻辑处理可在src/akshare_data/router.py文件中查看 * 后端的逻辑处理可在src/akshare_data/router.py文件中查看
* 由于user_strategy表中的信息仅仅是请求参数对我在后续中对分组管理操作无任何帮助所以我将请求返回来的数据进行存储在 * 由于user_strategy表中的信息仅仅是请求参数对我在后续中对分组管理操作无法对接所以我将请求返回来的数据进行存储在
* 新的一个数据库表中名为new_user_strategy的数据库表中 * 新的一个数据库表中名为new_user_strategy的数据库表中
* 最后通过新的接口得到股票数据显示在侧边栏中 * 最后通过新的接口得到股票数据显示在侧边栏中
* 下面代码的逻辑大致就是这样 * 下面代码的逻辑大致就是这样
@ -193,27 +193,30 @@ let stocktypes = ref<StockType[]>([
info: [], info: [],
} }
]) ])
axios({
url: 'http://127.0.0.1:8012/akshare/ganggudata', const fetchData = async () => {
method: 'get', const urls = [
}).then((res) => { 'http://127.0.0.1:8012/akshare/ganggudata',
stocktypes.value[0].info = res.data 'http://127.0.0.1:8012/akshare/meigudata',
cacheinfo.value.push(res.data) 'http://127.0.0.1:8012/akshare/hushendata'
}) ];
axios({
url: 'http://127.0.0.1:8012/akshare/meigudata', try {
method: 'get', const responses = await Promise.all(urls.map(url => axios.get(url)));
}).then((res) => { responses.forEach((res, index) => {
stocktypes.value[1].info = res.data stocktypes.value[index].info = res.data;
cacheinfo.value.push(res.data) cacheinfo.value.push(res.data);
}) });
axios({ } catch (error) {
url: 'http://127.0.0.1:8012/akshare/hushendata', console.error('Error fetching data:', error);
method: 'get', }
}).then((res) => { };
stocktypes.value[2].info = res.data
cacheinfo.value.push(res.data) fetchData();
})
// ---------------------------------------------- // ----------------------------------------------
const changestate = (item: any) => { const changestate = (item: any) => {
item.state = !item.state item.state = !item.state