feat:【mall】diy editor 的 hot-zone 代码优化(70%)使用 Modal 替代 el-dialog
This commit is contained in:
@@ -5,9 +5,10 @@ import type { AppLink } from './data';
|
|||||||
|
|
||||||
import { nextTick, ref } from 'vue';
|
import { nextTick, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
import { getUrlNumberValue } from '@vben/utils';
|
import { getUrlNumberValue } from '@vben/utils';
|
||||||
|
|
||||||
import { ElScrollbar } from 'element-plus';
|
import { ElButton, ElScrollbar, ElTooltip } from 'element-plus';
|
||||||
|
|
||||||
import ProductCategorySelect from '#/views/mall/product/category/components/product-category-select.vue';
|
import ProductCategorySelect from '#/views/mall/product/category/components/product-category-select.vue';
|
||||||
|
|
||||||
@@ -39,12 +40,20 @@ const detailSelectDialog = ref<{
|
|||||||
type: undefined,
|
type: undefined,
|
||||||
}); // 详情选择对话框
|
}); // 详情选择对话框
|
||||||
|
|
||||||
const dialogVisible = ref(false);
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
onConfirm() {
|
||||||
|
emit('change', activeAppLink.value.path);
|
||||||
|
emit('appLinkChange', activeAppLink.value);
|
||||||
|
modalApi.close();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
defineExpose({ open });
|
||||||
|
|
||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
function open(link: string) {
|
async function open(link: string) {
|
||||||
activeAppLink.value.path = link;
|
activeAppLink.value.path = link;
|
||||||
dialogVisible.value = true;
|
modalApi.open();
|
||||||
// 滚动到当前的链接
|
// 滚动到当前的链接
|
||||||
const group = APP_LINK_GROUP_LIST.find((group) =>
|
const group = APP_LINK_GROUP_LIST.find((group) =>
|
||||||
group.links.some((linkItem) => {
|
group.links.some((linkItem) => {
|
||||||
@@ -56,14 +65,12 @@ function open(link: string) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if (group) {
|
if (group) {
|
||||||
// TODO @AI:await 方式;
|
|
||||||
// 使用 nextTick 的原因:可能 Dom 还没生成,导致滚动失败
|
// 使用 nextTick 的原因:可能 Dom 还没生成,导致滚动失败
|
||||||
nextTick(() => handleGroupSelected(group.name));
|
await nextTick();
|
||||||
|
handleGroupSelected(group.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ open });
|
|
||||||
|
|
||||||
/** 处理 APP 链接选中 */
|
/** 处理 APP 链接选中 */
|
||||||
function handleAppLinkSelected(appLink: AppLink) {
|
function handleAppLinkSelected(appLink: AppLink) {
|
||||||
if (!isSameLink(appLink.path, activeAppLink.value.path)) {
|
if (!isSameLink(appLink.path, activeAppLink.value.path)) {
|
||||||
@@ -87,12 +94,6 @@ function handleAppLinkSelected(appLink: AppLink) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubmit() {
|
|
||||||
dialogVisible.value = false;
|
|
||||||
emit('change', activeAppLink.value.path);
|
|
||||||
emit('appLinkChange', activeAppLink.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理右侧链接列表滚动
|
* 处理右侧链接列表滚动
|
||||||
*
|
*
|
||||||
@@ -156,15 +157,17 @@ function handleProductCategorySelected(id: number) {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<el-dialog v-model="dialogVisible" title="选择链接" width="65%">
|
<Modal title="选择链接" class="w-[65%]">
|
||||||
<div class="flex h-[500px] gap-2">
|
<div class="flex h-[500px] gap-2">
|
||||||
<!-- 左侧分组列表 -->
|
<!-- 左侧分组列表 -->
|
||||||
<ElScrollbar
|
<ElScrollbar
|
||||||
wrap-class="h-full"
|
wrap-class="h-full"
|
||||||
ref="groupScrollbar"
|
ref="groupScrollbar"
|
||||||
view-class="flex flex-col"
|
view-class="flex flex-col"
|
||||||
|
class="border-r border-gray-200 pr-2"
|
||||||
>
|
>
|
||||||
<el-button
|
<!-- TODO @AI:文字左对齐 -->
|
||||||
|
<ElButton
|
||||||
v-for="(group, groupIndex) in APP_LINK_GROUP_LIST"
|
v-for="(group, groupIndex) in APP_LINK_GROUP_LIST"
|
||||||
:key="groupIndex"
|
:key="groupIndex"
|
||||||
class="ml-0 mr-4 w-[90px] justify-start"
|
class="ml-0 mr-4 w-[90px] justify-start"
|
||||||
@@ -175,29 +178,32 @@ function handleProductCategorySelected(id: number) {
|
|||||||
@click="handleGroupSelected(group.name)"
|
@click="handleGroupSelected(group.name)"
|
||||||
>
|
>
|
||||||
{{ group.name }}
|
{{ group.name }}
|
||||||
</el-button>
|
</ElButton>
|
||||||
</ElScrollbar>
|
</ElScrollbar>
|
||||||
<!-- 右侧链接列表 -->
|
<!-- 右侧链接列表 -->
|
||||||
<ElScrollbar
|
<ElScrollbar
|
||||||
class="h-full flex-1"
|
class="h-full flex-1 pl-2"
|
||||||
@scroll="handleScroll"
|
@scroll="handleScroll"
|
||||||
ref="linkScrollbar"
|
ref="linkScrollbar"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-for="(group, groupIndex) in APP_LINK_GROUP_LIST"
|
v-for="(group, groupIndex) in APP_LINK_GROUP_LIST"
|
||||||
:key="groupIndex"
|
:key="groupIndex"
|
||||||
|
class="mb-4 border-b border-gray-100 pb-4 last:mb-0 last:border-b-0"
|
||||||
>
|
>
|
||||||
<!-- 分组标题 -->
|
<!-- 分组标题 -->
|
||||||
<div class="font-bold" ref="groupTitleRefs">{{ group.name }}</div>
|
<div class="mb-2 font-bold" ref="groupTitleRefs">
|
||||||
|
{{ group.name }}
|
||||||
|
</div>
|
||||||
<!-- 链接列表 -->
|
<!-- 链接列表 -->
|
||||||
<el-tooltip
|
<ElTooltip
|
||||||
v-for="(appLink, appLinkIndex) in group.links"
|
v-for="(appLink, appLinkIndex) in group.links"
|
||||||
:key="appLinkIndex"
|
:key="appLinkIndex"
|
||||||
:content="appLink.path"
|
:content="appLink.path"
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
:show-after="300"
|
:show-after="300"
|
||||||
>
|
>
|
||||||
<el-button
|
<ElButton
|
||||||
class="mb-2 ml-0 mr-2"
|
class="mb-2 ml-0 mr-2"
|
||||||
:type="
|
:type="
|
||||||
isSameLink(appLink.path, activeAppLink.path)
|
isSameLink(appLink.path, activeAppLink.path)
|
||||||
@@ -207,18 +213,14 @@ function handleProductCategorySelected(id: number) {
|
|||||||
@click="handleAppLinkSelected(appLink)"
|
@click="handleAppLinkSelected(appLink)"
|
||||||
>
|
>
|
||||||
{{ appLink.name }}
|
{{ appLink.name }}
|
||||||
</el-button>
|
</ElButton>
|
||||||
</el-tooltip>
|
</ElTooltip>
|
||||||
</div>
|
</div>
|
||||||
</ElScrollbar>
|
</ElScrollbar>
|
||||||
</div>
|
</div>
|
||||||
<!-- 底部对话框操作按钮 -->
|
</Modal>
|
||||||
<template #footer>
|
|
||||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
|
||||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
|
|
||||||
|
<!-- TODO @AI:这里要处理下; -->
|
||||||
<el-dialog v-model="detailSelectDialog.visible" title="" width="50%">
|
<el-dialog v-model="detailSelectDialog.visible" title="" width="50%">
|
||||||
<el-form class="min-h-[200px]">
|
<el-form class="min-h-[200px]">
|
||||||
<el-form-item
|
<el-form-item
|
||||||
@@ -236,8 +238,3 @@ function handleProductCategorySelected(id: number) {
|
|||||||
</el-form>
|
</el-form>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
<style lang="scss" scoped>
|
|
||||||
:deep(.el-button + .el-button) {
|
|
||||||
margin-left: 0 !important;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user