修复批量名称输入与错误提示(8e6ce09)
This commit is contained in:
parent
522a46b2b8
commit
b8037d52b2
|
|
@ -693,7 +693,7 @@ make changes # 页面同款结论
|
|||
|
||||
## 2026-11-03 补充:在选股计划中添加关注股票
|
||||
|
||||
PMS 在原选股计划抽屉提供“添加股票”。支持按名称或代码搜索、批量输入沪深 A 股代码、填写理由和关注截止日。北交所在登记入口排除。同一股票的有效登记不重复创建,移除和到期保留历史;不会由此生成卖出或撤单命令。
|
||||
PMS 在原选股计划抽屉提供“添加股票”。支持按名称或代码搜索、批量输入沪深 A 股完整名称或代码、填写理由和关注截止日。名称来自上市证券基础表,精确匹配后统一保存代码;模糊或重名输入需先选择搜索结果或改用代码,整批校验通过后才保存。北交所在资料读取和登记入口排除。同一股票的有效登记不重复创建,移除和到期保留历史;不会由此生成卖出或撤单命令。
|
||||
|
||||
| 上游接口 | 用途 |
|
||||
| --- | --- |
|
||||
|
|
|
|||
|
|
@ -1044,9 +1044,12 @@ def api_user_candidates():
|
|||
@app.post('/api/plan/user-candidates')
|
||||
def api_add_user_candidates(request: Request, payload: dict = Body(...)):
|
||||
from app.services import plan_candidates
|
||||
return ok_logged('add_plan_candidates', plan_candidates.request, 'POST',
|
||||
payload=payload, actor=_actor(request), by=_actor(request),
|
||||
params={k: payload.get(k) for k in ('codes', 'reason', 'expires_on')})
|
||||
result = ok_logged('add_plan_candidates', plan_candidates.request, 'POST',
|
||||
payload=payload, actor=_actor(request), by=_actor(request),
|
||||
params={k: payload.get(k) for k in ('codes', 'reason', 'expires_on')})
|
||||
if not result.get('ok') and str(result.get('error') or '').startswith('ValueError: '):
|
||||
result['error'] = result['error'][12:]
|
||||
return result
|
||||
|
||||
|
||||
@app.post('/api/plan/user-candidates/{identity}/remove')
|
||||
|
|
|
|||
|
|
@ -2596,10 +2596,11 @@ body.dock-r:not(.r-fold) .side-r .strip{display:none;}
|
|||
<el-form-item label="股票">
|
||||
<el-select v-model="planAdd.codes" multiple filterable remote :allow-create="!planSearchBusy && !planSearchRows.length" default-first-option
|
||||
:remote-method="searchPlanStocks" :loading="planSearchBusy" :reserve-keyword="false"
|
||||
placeholder="搜索名称或代码,也可输入代码后回车" :disabled="planUserBusy">
|
||||
@change="changePlanStocks" @paste="pastePlanStocks"
|
||||
placeholder="搜索或粘贴股票名称、代码" :disabled="planUserBusy">
|
||||
<el-option v-for="r in planSearchRows" :key="r.code" :value="r.code" :label="r.name+' '+r.code"></el-option>
|
||||
</el-select>
|
||||
<div class="muted" style="margin-top:5px">仅支持沪深 A 股。批量代码可用空格或逗号分隔,每次最多 30 只。</div>
|
||||
<div class="muted" style="margin-top:5px">仅支持沪深 A 股。可批量粘贴完整名称或代码,用空格、逗号或换行分隔,每次最多 30 只。</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="添加理由">
|
||||
<el-input v-model="planAdd.reason" type="textarea" :rows="2" maxlength="300" show-word-limit
|
||||
|
|
@ -2956,6 +2957,19 @@ createApp({
|
|||
if (!planUserWritable.value) planAddError.value=planUserError.value||'添加功能尚未启用,请联系管理员';
|
||||
}
|
||||
let planSearchSerial=0;
|
||||
const splitPlanStocks = values => [...new Set(values.flatMap(x=>String(x).trim().split(/[\s,,;;、]+/)).filter(Boolean))];
|
||||
function changePlanStocks(values) {
|
||||
planAdd.codes=splitPlanStocks(values);
|
||||
planAddError.value='';
|
||||
}
|
||||
function pastePlanStocks(event) {
|
||||
if(planUserBusy.value)return;
|
||||
const values=splitPlanStocks([event.clipboardData?.getData('text')||'']);
|
||||
if(values.length<2)return;
|
||||
event.preventDefault();
|
||||
changePlanStocks([...planAdd.codes,...values]);
|
||||
++planSearchSerial; planSearchRows.value=[]; planSearchBusy.value=false;
|
||||
}
|
||||
async function searchPlanStocks(q) {
|
||||
const serial=++planSearchSerial;
|
||||
if (!q || !q.trim()) { planSearchRows.value=[]; planSearchBusy.value=false; return; }
|
||||
|
|
@ -2966,14 +2980,17 @@ createApp({
|
|||
}
|
||||
async function submitPlanAdd() {
|
||||
if(planUserBusy.value)return;
|
||||
const codes=[...new Set(planAdd.codes.flatMap(x=>String(x).trim().split(/[\s,,;;]+/)).filter(Boolean))];
|
||||
const codes=splitPlanStocks(planAdd.codes);
|
||||
if(!codes.length || codes.length>30){planAddError.value='请选择 1 至 30 只股票';return;}
|
||||
if(!planAdd.reason.trim()){planAddError.value='请填写添加理由';return;}
|
||||
if(!planAdd.expires_on){planAddError.value='请选择关注截止日期';return;}
|
||||
planUserBusy.value=true; planAddError.value='';
|
||||
try {
|
||||
const d=await call('post','/api/plan/user-candidates',{codes,reason:planAdd.reason.trim(),expires_on:planAdd.expires_on});
|
||||
if(!d||!d.ok){planAddError.value=(d||{}).error||'添加未完成,请刷新列表核对';return;}
|
||||
if(!d||!d.ok){
|
||||
const message=String((d||{}).error||'添加未完成,请刷新列表核对');
|
||||
planAddError.value=message.startsWith('ValueError:') ? message.slice(11).trim() : message; return;
|
||||
}
|
||||
ElementPlus.ElMessage.success(d.added ? '已保存,等待更新评估' : '所选股票已在关注中');
|
||||
planAdd.codes=[];planAdd.reason='';planAddOpen.value=false;
|
||||
await loadPlanUsers();
|
||||
|
|
@ -5286,7 +5303,7 @@ createApp({
|
|||
loadPlan, openPlan, refreshPlan,
|
||||
planAddOpen, planUserBusy, planAddError, planUserError, planUserRows, planUserHistory,
|
||||
planUserShown, planUserActiveCount, planUserState, planUserDetail, planDateDisabled,
|
||||
planSearchRows, planSearchBusy, planAdd, openPlanAdd, searchPlanStocks, submitPlanAdd, removePlanUser,
|
||||
planSearchRows, planSearchBusy, planAdd, openPlanAdd, searchPlanStocks, changePlanStocks, pastePlanStocks, submitPlanAdd, removePlanUser,
|
||||
techStatus, techChipText, techChipCls,
|
||||
chgRaw, chgSt, chgLoading, chgTab, chg, chgHeld, chgLog, chgRevised, chgWatch,
|
||||
loadChanges,
|
||||
|
|
|
|||
|
|
@ -100,5 +100,10 @@ class UserCandidateTests(unittest.TestCase):
|
|||
result=main.api_add_user_candidates(request,{'codes':['600001'],'by':'冒名'})
|
||||
self.assertTrue(result['ok']);self.assertEqual(send.call_args.kwargs['actor'],'交易员甲')
|
||||
self.assertEqual(log.call_args.kwargs['by'],'交易员甲')
|
||||
with patch.object(pc,'request',side_effect=ValueError('未找到沪深 A 股“示例”,请检查完整名称或使用代码')), \
|
||||
patch.object(main.pms_repo,'insert_op_log',return_value=1) as log:
|
||||
result=main.api_add_user_candidates(request,{'codes':['示例']})
|
||||
self.assertFalse(result['ok']);self.assertTrue(result['error'].startswith('未找到沪深 A 股'))
|
||||
self.assertEqual(log.call_args.kwargs['result'],'BLOCKED')
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue