|
@@ -95,14 +95,7 @@ class KeyWordEdit extends React.Component {
|
|
|
this.state.msgActiveIndex++ ;
|
|
|
const activeKey = '' + this.state.msgActiveIndex;
|
|
|
msgPanes.push({ title: `第${this.state.msgActiveIndex+1}条`, key: activeKey ,closable:true});
|
|
|
- //超过一条消息 并且 只有最后一条才可删除
|
|
|
- msgPanes.forEach((pane, i)=>{
|
|
|
- if(i==msgPanes.length-1 && msgPanes.length>1){
|
|
|
- pane.closable=true;
|
|
|
- }else{
|
|
|
- pane.closable=false;
|
|
|
- }
|
|
|
- });
|
|
|
+ msgPanes[0].closable=true;
|
|
|
this.state.msgList.push({msgId:0 ,chooseKey:'text',msgType:'text' ,content:'' ,title:'' , description:'' ,url:'' ,miniProgramAppId:'',
|
|
|
pagepath:'' ,mediaId:''});
|
|
|
this.setState({ msgPanes:msgPanes, msgActiveKey:activeKey });
|
|
@@ -114,32 +107,31 @@ class KeyWordEdit extends React.Component {
|
|
|
}else if(action=='remove'){
|
|
|
// 删除消息
|
|
|
let { msgActiveKey } = this.state;
|
|
|
- let lastActiveIndex;
|
|
|
+ let activeIndex;
|
|
|
this.state.msgPanes.forEach((pane, i) => {
|
|
|
if (pane.key === targetKey) {
|
|
|
- lastActiveIndex = i - 1;
|
|
|
+ activeIndex=i;
|
|
|
}
|
|
|
});
|
|
|
const panes = this.state.msgPanes.filter(pane => pane.key !== targetKey);
|
|
|
- if (panes.length && msgActiveKey === targetKey) {
|
|
|
- if (lastActiveIndex >= 0) {
|
|
|
- msgActiveKey = panes[lastActiveIndex].key;
|
|
|
- } else {
|
|
|
- msgActiveKey = panes[0].key;
|
|
|
- }
|
|
|
- }
|
|
|
//msgList删除一条
|
|
|
- this.state.msgList.splice(lastActiveIndex+1,1);
|
|
|
+ this.state.msgList.splice(activeIndex,1);
|
|
|
//标识index减少 1
|
|
|
this.state.msgActiveIndex--;
|
|
|
- //超过一条消息 且最后一条才可删除
|
|
|
- panes.forEach((pane, i)=>{
|
|
|
- if(i==panes.length-1 && panes.length>1){
|
|
|
- pane.closable=true;
|
|
|
- }else{
|
|
|
- pane.closable=false;
|
|
|
+ if(this.state.msgActiveIndex==0){
|
|
|
+ panes[0].closable=false;
|
|
|
+ }
|
|
|
+ for(let i=activeIndex;i<panes.length;i++){
|
|
|
+ panes[i].key=''+i;
|
|
|
+ panes[i].title= `第${i+1}条`
|
|
|
+ }
|
|
|
+ if (panes && panes.length) {
|
|
|
+ if (activeIndex > 0) {
|
|
|
+ msgActiveKey = panes[activeIndex-1].key;
|
|
|
+ } else {
|
|
|
+ msgActiveKey = panes[0].key;
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
this.setState({ msgPanes:panes, msgActiveKey:msgActiveKey });
|
|
|
}
|
|
|
}
|