Browse Source

chore fix: 解决Modal弹窗无法关闭的bug

master
AaronWu 2 months ago
parent
commit
35403b509f
  1. 12924
      package-lock.json
  2. 2
      package.json
  3. 2
      src/plugins/antd.ts
  4. 162
      src/views/question/issue/index.vue
  5. 163
      src/views/question/knowledge/index.vue
  6. 3
      vite.config.ts
  7. 4357
      yarn.lock

12924
package-lock.json

File diff suppressed because it is too large

2
package.json

@ -24,7 +24,7 @@
"sortablejs": "^1.15.0",
"vite-plugin-md": "^0.22.5",
"vite-plugin-windicss": "^1.9.0",
"vue": "^3.2.47",
"vue": "~3.3.x",
"vue-i18n": "9.2.2",
"vue-router": "^4.2.1",
"windicss": "^3.5.6",

2
src/plugins/antd.ts

@ -1,6 +1,7 @@
import type { App } from 'vue';
import { AButton } from '@/components/basic/button/index';
import { Modal } from 'ant-design-vue';
// https://www.antdv.com/docs/vue/getting-started-cn#按需加载
import 'ant-design-vue/es/message/style/css'; //vite只能用 ant-design-vue/es 而非 ant-design-vue/lib
@ -10,4 +11,5 @@ import 'dayjs/locale/zh-cn';
export function setupAntd(app: App<Element>) {
app.component('AButton', AButton);
app.component('Modal', Modal);
}

162
src/views/question/issue/index.vue

@ -9,62 +9,67 @@
修改时间
-->
<template>
<DynamicTable
size="small"
showIndex
headerTitle="问题工单列表"
titleTooltip=""
:data-request="loadData"
:columns="columns"
row-key="id"
@resize-column="handleResizeColumn"
:row-selection="rowSelection"
:scroll="{ x: '100vw' }"
>
<template v-if="isCheckRows" #title>
<Alert class="w-full" type="info" show-icon>
<template #message>
已选 {{ isCheckRows }}
<a-button type="link" @click="rowSelection.selectedRowKeys = []">取消选择</a-button>
</template>
</Alert>
</template>
<template #toolbar>
<a-button type="primary" @click="handleAdd">新增</a-button>
<a-button
type="danger"
:disabled="!isCheckRows"
@click="delRowConfirm(rowSelection.selectedRowKeys)"
>
<DeleteOutlined /> 删除
</a-button>
</template>
</DynamicTable>
<DraggableModal
v-model:visible="visible"
:width="700"
:bodyStyle="{
height: '70vh',
}"
:force-render="true"
:title="`${curRecord.id ? '编辑' : '新增'}问题工单`"
@ok="handleOk"
@cancel="handleCancel"
>
<SchemaForm>
<template #solution="{ formModel, field }">
<div class="ql-box">
<QuillEditor
ref="quillEditor"
theme="snow"
v-model:content="formModel[field]"
:options="editorOptions"
contentType="html"
/>
</div>
<div class="issue-container" ref="issueContainerRef">
<DynamicTable
size="small"
showIndex
headerTitle="问题工单列表"
titleTooltip=""
:data-request="loadData"
:columns="columns"
row-key="id"
@resize-column="handleResizeColumn"
:row-selection="rowSelection"
:scroll="{ x: '100vw' }"
>
<template v-if="isCheckRows" #title>
<Alert class="w-full" type="info" show-icon>
<template #message>
已选 {{ isCheckRows }}
<a-button type="link" @click="rowSelection.selectedRowKeys = []">取消选择</a-button>
</template>
</Alert>
</template>
<template #toolbar>
<a-button type="primary" @click="handleAdd">新增</a-button>
<a-button
type="danger"
:disabled="!isCheckRows"
@click="delRowConfirm(rowSelection.selectedRowKeys)"
>
<DeleteOutlined /> 删除
</a-button>
</template>
</SchemaForm>
</DraggableModal>
</DynamicTable>
<Modal
v-model:visible="visible"
:width="700"
:bodyStyle="{
height: '70vh',
overflow: 'auto',
}"
:title="`${curRecord.id ? '编辑' : '新增'}问题工单`"
@ok="handleOk"
@cancel="handleCancel"
:mask-closable="false"
:destroyOnClose="true"
:getContainer="() => issueContainerRef"
>
<SchemaForm>
<template #solution="{ formModel, field }">
<div class="ql-box">
<QuillEditor
ref="quillEditor"
theme="snow"
v-model:content="formModel[field]"
:options="editorOptions"
contentType="html"
/>
</div>
</template>
</SchemaForm>
</Modal>
</div>
</template>
<script lang="tsx" setup>
@ -83,7 +88,7 @@
addToknowledge,
} from '@/api/issue';
import { computed, nextTick, ref, watch, onMounted } from 'vue';
import { Modal, message, Alert } from 'ant-design-vue';
import { message, Alert } from 'ant-design-vue';
import { useRouter } from 'vue-router';
import { useFormModal } from '@/hooks/useModal/index';
import { getEditFormSchema, getFlowFormSchema } from './formSchemas';
@ -100,6 +105,7 @@
const router = useRouter();
const issueContainerRef = ref<HTMLElement | null>(null);
const curRecord = ref<Partial<TableListItem>>({});
const visible = ref(false);
const quillEditor = ref<InstanceType<typeof QuillEditor> | null>(null);
@ -132,20 +138,35 @@
},
});
// watch(
// () => curRecord.value,
// (newVal) => {
// formRef?.setFieldsValue(newVal);
// },
// {
// immediate: true,
// deep: true,
// },
// );
const time = ref(0);
watch(
() => curRecord.value,
() => visible.value,
(newVal) => {
formRef?.setFieldsValue(newVal);
},
{
immediate: true,
deep: true,
if (newVal) {
nextTick(() => {
if (time.value === 0) {
quillImageUploadCustom(quillEditor.value);
time.value++;
}
});
}
},
);
// Quill
onMounted(() => {
quillImageUploadCustom(quillEditor.value);
// quillImageUploadCustom(quillEditor.value);
});
const handleOk = async () => {
@ -388,8 +409,11 @@
formRef?.resetFields();
};
const openModal = () => {
const openModal = (cb: any) => {
visible.value = true;
nextTick(() => {
cb();
});
formRef.clearValidate();
};
@ -408,9 +432,10 @@
const handleAdd = () => {
curRecord.value = {};
// formRef?.setFieldsValue(curRecord.value);
formRef?.setFieldsValue(curRecord.value);
quillEditor.value?.setContents('');
resetFormFields();
openModal();
openModal(() => {});
};
const handleEdit = async (record: TableListItem) => {
@ -434,7 +459,7 @@
}
curRecord.value = res;
quillEditor.value?.setContents(res?.solution);
// quillEditor.value?.setContents(res?.solution);
// formRef?.setFieldsValue(res);
if (res?.productId) {
@ -459,7 +484,10 @@
}
nextTick(() => {
openModal();
openModal(() => {
formRef?.setFieldsValue(res);
quillEditor.value?.setContents(res?.solution);
});
});
}
};

163
src/views/question/knowledge/index.vue

@ -9,62 +9,67 @@
修改时间
-->
<template>
<DynamicTable
size="small"
showIndex
headerTitle="知识库列表"
titleTooltip=""
:data-request="loadData"
:columns="columns"
row-key="id"
@resize-column="handleResizeColumn"
:row-selection="rowSelection"
:scroll="{ x: '100vw' }"
>
<template v-if="isCheckRows" #title>
<Alert class="w-full" type="info" show-icon>
<template #message>
已选 {{ isCheckRows }}
<a-button type="link" @click="rowSelection.selectedRowKeys = []">取消选择</a-button>
</template>
</Alert>
</template>
<template #toolbar>
<a-button type="primary" @click="handleAdd">新增</a-button>
<a-button
type="danger"
:disabled="!isCheckRows"
@click="delRowConfirm(rowSelection.selectedRowKeys)"
>
<DeleteOutlined /> 删除
</a-button>
</template>
</DynamicTable>
<DraggableModal
v-model:visible="visible"
:width="700"
:bodyStyle="{
height: '70vh',
}"
:force-render="true"
:title="`${curRecord.id ? '编辑' : '新增'}知识库`"
@ok="handleOk"
@cancel="handleCancel"
>
<SchemaForm>
<template #solution="{ formModel, field }">
<div class="ql-box">
<QuillEditor
ref="quillEditor"
theme="snow"
v-model:content="formModel[field]"
:options="editorOptions"
contentType="html"
/>
</div>
<div class="know-container" ref="knowContainerRef">
<DynamicTable
size="small"
showIndex
headerTitle="知识库列表"
titleTooltip=""
:data-request="loadData"
:columns="columns"
row-key="id"
@resize-column="handleResizeColumn"
:row-selection="rowSelection"
:scroll="{ x: '100vw' }"
>
<template v-if="isCheckRows" #title>
<Alert class="w-full" type="info" show-icon>
<template #message>
已选 {{ isCheckRows }}
<a-button type="link" @click="rowSelection.selectedRowKeys = []">取消选择</a-button>
</template>
</Alert>
</template>
<template #toolbar>
<a-button type="primary" @click="handleAdd">新增</a-button>
<a-button
type="danger"
:disabled="!isCheckRows"
@click="delRowConfirm(rowSelection.selectedRowKeys)"
>
<DeleteOutlined /> 删除
</a-button>
</template>
</SchemaForm>
</DraggableModal>
</DynamicTable>
<Modal
v-model:visible="visible"
:width="700"
:bodyStyle="{
height: '70vh',
overflow: 'auto',
}"
:title="`${curRecord.id ? '编辑' : '新增'}知识库`"
:mask-closable="false"
:getContainer="() => knowContainerRef"
:destroyOnClose="true"
@ok="handleOk"
@cancel="handleCancel"
>
<SchemaForm>
<template #solution="{ formModel, field }">
<div class="ql-box">
<QuillEditor
ref="quillEditor"
theme="snow"
v-model:content="formModel[field]"
:options="editorOptions"
contentType="html"
/>
</div>
</template>
</SchemaForm>
</Modal>
</div>
</template>
<script lang="tsx" setup>
@ -81,7 +86,7 @@
findOneById,
} from '@/api/knowledgeBase';
import { computed, nextTick, ref, watch, onMounted, h } from 'vue';
import { Modal, message, Alert } from 'ant-design-vue';
import { message, Alert } from 'ant-design-vue';
import { useRouter } from 'vue-router';
import { useFormModal } from '@/hooks/useModal/index';
import { getEditFormSchema } from './formSchemas';
@ -131,20 +136,38 @@
},
});
const knowContainerRef = ref<HTMLElement | null>(null);
// watch(
// () => curRecord.value,
// (newVal) => {
// formRef?.setFieldsValue(newVal);
// },
// {
// immediate: true,
// deep: true,
// },
// );
const time = ref(0);
watch(
() => curRecord.value,
() => visible.value,
(newVal) => {
formRef?.setFieldsValue(newVal);
},
{
immediate: true,
deep: true,
if (newVal) {
nextTick(() => {
if (time.value === 0) {
quillImageUploadCustom(quillEditor.value);
time.value++;
}
});
}
},
);
// Quill
onMounted(() => {
quillImageUploadCustom(quillEditor.value);
// quillImageUploadCustom(quillEditor.value);
});
const handleOk = async () => {
@ -321,8 +344,11 @@
formRef?.resetFields();
};
const openModal = () => {
const openModal = (cb: any) => {
visible.value = true;
nextTick(() => {
cb();
});
formRef.clearValidate();
};
@ -333,7 +359,7 @@
quillEditor.value?.setContents('');
resetFormFields();
openModal();
openModal(() => {});
};
const handleEdit = async (record: TableListItem) => {
@ -357,7 +383,7 @@
}
curRecord.value = res;
quillEditor.value?.setContents(res?.solution);
// quillEditor.value?.setContents(res?.solution);
// formRef?.setFieldsValue(res);
@ -383,7 +409,10 @@
}
nextTick(() => {
openModal();
openModal(() => {
formRef?.setFieldsValue(res);
quillEditor.value?.setContents(res?.solution);
});
});
}
};

3
vite.config.ts

@ -16,6 +16,9 @@ const CWD = process.cwd();
// https://vitejs.dev/config/
export default defineConfig({
build: {
minify: false, // 禁用代码压缩
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),

4357
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save