Browse Source

chore: 修复tab新增错误

master
wangxiang 1 year ago
parent
commit
310c7d43aa
  1. 37
      src/views/system/devtools/template/TemplateModal.vue
  2. 3
      src/views/system/devtools/template/TemplatePromptModal.vue

37
src/views/system/devtools/template/TemplateModal.vue

@ -149,7 +149,9 @@
} }
function handleEditTab() { function handleEditTab() {
openPromptModal(true, { _tag: 'edit' }); if (state.typeActiveKey == '0' ? state.mainActiveKey : state.childActiveKey) {
openPromptModal(true, { _tag: 'edit' });
}
} }
function handleRemoveTab(targetKey: string) { function handleRemoveTab(targetKey: string) {
@ -184,22 +186,23 @@
} }
} }
function handlePrompt({ name }) { function handlePrompt({ name, tag }) {
const index = state.templateObjs.findIndex(item => (item.index || item.id) == (state.typeActiveKey == '0' ? state.mainActiveKey : state.childActiveKey)); if (tag === 'add') {
let template: templateTypePartial = { const template: templateTypePartial = {
name, name,
contents: '', contents: '',
isChild: state.typeActiveKey, isChild: state.typeActiveKey,
index: `t${Date.now()}` index: `t${Date.now()}`
}; };
if (index != -1) { state.templateObjs.push(template);
template = Object.assign({}, state.templateObjs[index], { name }); // tab
state.templateObjs.splice(index, 1, template); state.typeActiveKey == '0' ? (state.mainActiveKey = template.index!) : (state.childActiveKey = template.index!);
} else state.templateObjs.push(template); } else {
// tab const index = state.templateObjs.findIndex(item => (item.index || item.id) == (state.typeActiveKey == '0' ? state.mainActiveKey : state.childActiveKey));
if (state.typeActiveKey == '0'){ if (index != -1) {
state.mainActiveKey = (template.index || template.id)!; state.templateObjs.splice(index, 1, Object.assign({}, state.templateObjs[index], { name }));
} else state.childActiveKey = (template.index || template.id)!; }
}
} }
/** 处理弹出框提交 */ /** 处理弹出框提交 */

3
src/views/system/devtools/template/TemplatePromptModal.vue

@ -27,6 +27,7 @@
/** 类型规范统一声明定义区域 */ /** 类型规范统一声明定义区域 */
interface WindowState { interface WindowState {
tag: string;
name: string; name: string;
} }
@ -37,6 +38,7 @@
const FormItem = Form.Item; const FormItem = Form.Item;
const useForm = Form.useForm; const useForm = Form.useForm;
const modelRef = reactive<WindowState>({ const modelRef = reactive<WindowState>({
tag: '',
name: '' name: ''
}); });
const rulesRef = reactive<Recordable>({ const rulesRef = reactive<Recordable>({
@ -54,6 +56,7 @@
resetFields(); resetFields();
clearValidate(); clearValidate();
// //
modelRef.tag = data._tag;
const props: Partial<ModalProps> = { confirmLoading: false }; const props: Partial<ModalProps> = { confirmLoading: false };
switch (data._tag) { switch (data._tag) {
case 'add': case 'add':

Loading…
Cancel
Save