fix: 策略编辑页面股票搜索修复
- 将u-input替换为原生input,解决事件参数问题 - 添加onStockInput方法正确处理input事件 - 添加调试日志便于排查再平衡策略资产加载问题
This commit is contained in:
parent
258d92ac1c
commit
924ac09535
@ -146,12 +146,11 @@
|
|||||||
<view class="asset-inputs">
|
<view class="asset-inputs">
|
||||||
<view class="asset-input relative">
|
<view class="asset-input relative">
|
||||||
<text class="asset-label">代码</text>
|
<text class="asset-label">代码</text>
|
||||||
<u-input
|
<input
|
||||||
v-model="asset.symbol"
|
v-model="asset.symbol"
|
||||||
|
class="stock-input"
|
||||||
placeholder="如 AAPL"
|
placeholder="如 AAPL"
|
||||||
:border="false"
|
@input="(e) => onStockInput(e, index)"
|
||||||
:customStyle="{ backgroundColor: '#F9FAFB', borderRadius: '16rpx', height: '72rpx', padding: '0 20rpx' }"
|
|
||||||
@input="(e) => searchStock(e, index)"
|
|
||||||
/>
|
/>
|
||||||
<!-- 搜索下拉列表 -->
|
<!-- 搜索下拉列表 -->
|
||||||
<view class="search-dropdown" v-if="searchResults.length > 0 && activeAssetIndex === index">
|
<view class="search-dropdown" v-if="searchResults.length > 0 && activeAssetIndex === index">
|
||||||
@ -302,10 +301,16 @@ const formData = ref({
|
|||||||
const searchResults = ref([]);
|
const searchResults = ref([]);
|
||||||
const activeAssetIndex = ref(-1);
|
const activeAssetIndex = ref(-1);
|
||||||
const searchTimer = ref(null);
|
const searchTimer = ref(null);
|
||||||
|
|
||||||
|
const onStockInput = (e, assetIndex) => {
|
||||||
|
const keyword = e.detail.value;
|
||||||
|
console.log('🔍 策略页面股票输入:', keyword, 'assetIndex:', assetIndex);
|
||||||
|
searchStock(keyword, assetIndex);
|
||||||
|
};
|
||||||
|
|
||||||
const searchStock = async (keyword, assetIndex) => {
|
const searchStock = async (keyword, assetIndex) => {
|
||||||
// 防抖
|
console.log('🔍 searchStock 调用:', keyword, 'assetIndex:', assetIndex);
|
||||||
if (searchTimer.value) clearTimeout(searchTimer.value);
|
if (searchTimer.value) clearTimeout(searchTimer.value);
|
||||||
// 赋值当前激活的搜索下标
|
|
||||||
activeAssetIndex.value = assetIndex;
|
activeAssetIndex.value = assetIndex;
|
||||||
if (!keyword || keyword.length < 1) {
|
if (!keyword || keyword.length < 1) {
|
||||||
searchResults.value = [];
|
searchResults.value = [];
|
||||||
@ -315,7 +320,9 @@ const searchStock = async (keyword, assetIndex) => {
|
|||||||
|
|
||||||
searchTimer.value = setTimeout(async () => {
|
searchTimer.value = setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
|
console.log('📤 调用 api.ticker.search:', keyword);
|
||||||
const res = await api.ticker.search(keyword);
|
const res = await api.ticker.search(keyword);
|
||||||
|
console.log('📥 搜索结果:', res);
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
searchResults.value = res.data.map(item => ({
|
searchResults.value = res.data.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
@ -520,6 +527,8 @@ const loadStrategyDetail = async (id) => {
|
|||||||
// 兼容旧格式
|
// 兼容旧格式
|
||||||
params = JSON.parse(data.config);
|
params = JSON.parse(data.config);
|
||||||
}
|
}
|
||||||
|
console.log('📊 策略类型:', data.type, '参数:', params);
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'ma_trend':
|
case 'ma_trend':
|
||||||
formData.value.maType = params.maType || 'SMA';
|
formData.value.maType = params.maType || 'SMA';
|
||||||
@ -529,11 +538,13 @@ const loadStrategyDetail = async (id) => {
|
|||||||
case 'risk_parity':
|
case 'risk_parity':
|
||||||
formData.value.lookbackPeriod = params.lookbackPeriod?.toString() || '';
|
formData.value.lookbackPeriod = params.lookbackPeriod?.toString() || '';
|
||||||
formData.value.rebalanceThreshold = params.rebalanceThreshold?.toString() || '';
|
formData.value.rebalanceThreshold = params.rebalanceThreshold?.toString() || '';
|
||||||
|
console.log('📊 再平衡策略 assets:', params.assets);
|
||||||
if (params.assets && params.assets.length > 0) {
|
if (params.assets && params.assets.length > 0) {
|
||||||
formData.value.assets = params.assets.map(asset => ({
|
formData.value.assets = params.assets.map(asset => ({
|
||||||
symbol: asset.symbol || '',
|
symbol: asset.symbol || '',
|
||||||
targetWeight: asset.targetWeight?.toString() || ''
|
targetWeight: asset.targetWeight?.toString() || ''
|
||||||
}));
|
}));
|
||||||
|
console.log('📊 填充后的 formData.assets:', formData.value.assets);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'chandelier_exit':
|
case 'chandelier_exit':
|
||||||
@ -850,6 +861,17 @@ onMounted(() => {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stock-input {
|
||||||
|
width: 100%;
|
||||||
|
height: 72rpx;
|
||||||
|
background-color: #F9FAFB;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #1F2937;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
/* 搜索下拉列表 */
|
/* 搜索下拉列表 */
|
||||||
.relative {
|
.relative {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user