Browse Source

chore: 修复tab新增错误

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

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

@ -149,8 +149,10 @@
} }
function handleEditTab() { function handleEditTab() {
if (state.typeActiveKey == '0' ? state.mainActiveKey : state.childActiveKey) {
openPromptModal(true, { _tag: 'edit' }); openPromptModal(true, { _tag: 'edit' });
} }
}
function handleRemoveTab(targetKey: string) { function handleRemoveTab(targetKey: string) {
let lastIndex = 0; let lastIndex = 0;
@ -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()}`
}; };
state.templateObjs.push(template);
// tab
state.typeActiveKey == '0' ? (state.mainActiveKey = template.index!) : (state.childActiveKey = template.index!);
} else {
const index = state.templateObjs.findIndex(item => (item.index || item.id) == (state.typeActiveKey == '0' ? state.mainActiveKey : state.childActiveKey));
if (index != -1) { if (index != -1) {
template = Object.assign({}, state.templateObjs[index], { name }); state.templateObjs.splice(index, 1, Object.assign({}, state.templateObjs[index], { name }));
state.templateObjs.splice(index, 1, template); }
} else state.templateObjs.push(template); }
// tab
if (state.typeActiveKey == '0'){
state.mainActiveKey = (template.index || template.id)!;
} 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