feat:【antd】【mall】diy-editor 代码风格统一 & 逐个测试 20%

This commit is contained in:
YunaiV
2025-11-10 19:13:25 +08:00
parent a3356a0a5e
commit fadad35b20
47 changed files with 195 additions and 263 deletions

View File

@@ -0,0 +1 @@
export { default as ProductCategorySelect } from './select.vue';

View File

@@ -11,26 +11,25 @@ import { getCategoryList } from '#/api/mall/product/category';
defineOptions({ name: 'ProductCategorySelect' });
const props = defineProps({
// ID
modelValue: {
type: [Number, Array<Number>],
default: undefined,
},
//
}, // ID
multiple: {
type: Boolean,
default: false,
},
//
}, //
parentId: {
type: Number,
default: undefined,
},
}, //
});
/** 分类选择 */
const emit = defineEmits(['update:modelValue']);
const categoryList = ref<any[]>([]); //
/** 选中的分类 ID */
const selectCategoryId = computed({
get: () => {
@@ -42,7 +41,6 @@ const selectCategoryId = computed({
});
/** 初始化 */
const categoryList = ref<any[]>([]); //
onMounted(async () => {
const data = await getCategoryList({
parentId: props.parentId,

View File

@@ -3,7 +3,7 @@ import { ref, watch } from 'vue';
import { Button, Input } from 'ant-design-vue';
import AppLinkSelectDialog from './app-link-select-dialog.vue';
import AppLinkSelectDialog from './select-dialog.vue';
/** APP 链接输入框 */
defineOptions({ name: 'AppLinkInput' });
@@ -56,5 +56,6 @@ watch(
</Button>
</template>
</Input>
<AppLinkSelectDialog ref="dialogRef" @change="handleLinkSelected" />
</template>

View File

@@ -3,11 +3,12 @@ import type { AppLink } from './data';
import { nextTick, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { getUrlNumberValue } from '@vben/utils';
import { Button, Form, FormItem, Modal, Tooltip } from 'ant-design-vue';
import { Button, Form, FormItem, Tooltip } from 'ant-design-vue';
import ProductCategorySelect from '#/views/mall/product/category/components/product-category-select.vue';
import { ProductCategorySelect } from '#/views/mall/product/category/components/';
import { APP_LINK_GROUP_LIST, APP_LINK_TYPE_ENUM } from './data';
@@ -30,21 +31,31 @@ const groupBtnRefs = ref<HTMLButtonElement[]>([]); // 分组引用列表
const detailSelectDialog = ref<{
id?: number;
type?: APP_LINK_TYPE_ENUM;
visible: boolean;
}>({
visible: false,
id: undefined,
type: undefined,
}); //
const dialogVisible = ref(false);
const [Modal, modalApi] = useVbenModal({
onConfirm() {
emit('change', activeAppLink.value.path);
emit('appLinkChange', activeAppLink.value);
modalApi.close();
},
});
const [DetailSelectModal, detailSelectModalApi] = useVbenModal({
onConfirm() {
detailSelectModalApi.close();
},
});
defineExpose({ open });
/** 打开弹窗 */
async function open(link: string) {
activeAppLink.value.path = link;
dialogVisible.value = true;
modalApi.open();
//
const group = APP_LINK_GROUP_LIST.find((group) =>
group.links.some((linkItem) => {
@@ -76,7 +87,7 @@ function handleAppLinkSelected(appLink: AppLink) {
'id',
`http://127.0.0.1${activeAppLink.value.path}`,
) || undefined;
detailSelectDialog.value.visible = true;
detailSelectModalApi.open();
break;
}
default: {
@@ -85,13 +96,6 @@ function handleAppLinkSelected(appLink: AppLink) {
}
}
/** 处理确认提交 */
function handleSubmit() {
emit('change', activeAppLink.value.path);
emit('appLinkChange', activeAppLink.value);
dialogVisible.value = false;
}
/**
* 处理右侧链接列表滚动
*
@@ -138,7 +142,7 @@ function scrollToGroupBtn(group: string) {
/** 是否为相同的链接(不比较参数,只比较链接) */
function isSameLink(link1: string, link2: string) {
return link2 ? link1.split('?')[0] === link2.split('?')[0] : false;
return link2 ? link1?.split('?')[0] === link2.split('?')[0] : false;
}
/** 处理详情选择 */
@@ -149,17 +153,12 @@ function handleProductCategorySelected(id: number) {
activeAppLink.value.path = `${url.pathname}${url.search}`;
// id
detailSelectDialog.value.visible = false;
detailSelectModalApi.close();
detailSelectDialog.value.id = undefined;
}
</script>
<template>
<Modal
v-model:open="dialogVisible"
title="选择链接"
width="65%"
@ok="handleSubmit"
>
<Modal title="选择链接" class="w-[65%]">
<div class="flex h-[500px] gap-2">
<!-- 左侧分组列表 -->
<div
@@ -218,7 +217,7 @@ function handleProductCategorySelected(id: number) {
</div>
</Modal>
<Modal v-model:open="detailSelectDialog.visible" title="选择分类" width="65%">
<DetailSelectModal title="选择分类" class="w-[65%]">
<Form class="min-h-[200px]">
<FormItem
label="选择分类"
@@ -233,11 +232,5 @@ function handleProductCategorySelected(id: number) {
/>
</FormItem>
</Form>
</Modal>
</DetailSelectModal>
</template>
<style lang="scss" scoped>
:deep(.ant-btn + .ant-btn) {
margin-left: 0 !important;
}
</style>

View File

@@ -1,53 +0,0 @@
<script setup lang="ts">
import type { CarouselProperty } from './config';
import { ref } from 'vue';
import { IconifyIcon } from '@vben/icons';
import { Carousel, Image } from 'ant-design-vue';
/** 轮播图 */
defineOptions({ name: 'Carousel' });
defineProps<{ property: CarouselProperty }>();
const currentIndex = ref(0);
const handleIndexChange = (index: number) => {
currentIndex.value = index + 1;
};
</script>
<template>
<div>
<!-- 无图片 -->
<div
class="bg-card flex h-64 items-center justify-center"
v-if="property.items.length === 0"
>
<IconifyIcon icon="tdesign:image" class="size-6 text-gray-800" />
</div>
<div v-else class="relative">
<Carousel
:autoplay="property.autoplay"
:autoplay-speed="property.interval * 1000"
:dots="property.indicator !== 'number'"
@change="handleIndexChange"
class="h-44"
>
<div v-for="(item, index) in property.items" :key="index">
<Image
class="h-full w-full object-cover"
:src="item.imgUrl"
:preview="false"
/>
</div>
</Carousel>
<div
v-if="property.indicator === 'number'"
class="absolute bottom-2.5 right-2.5 rounded-xl bg-black px-2 py-1 text-xs text-white opacity-40"
>
{{ currentIndex }} / {{ property.items.length }}
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,53 @@
<script setup lang="ts">
import type { CarouselProperty } from './config';
import { ref } from 'vue';
import { IconifyIcon } from '@vben/icons';
import { Carousel, Image } from 'ant-design-vue';
/** 轮播图 */
defineOptions({ name: 'Carousel' });
defineProps<{ property: CarouselProperty }>();
const currentIndex = ref(0); // 当前索引
/** 处理索引变化 */
const handleIndexChange = (index: number) => {
currentIndex.value = index + 1;
};
</script>
<template>
<!-- 无图片 -->
<div
class="bg-card flex h-64 items-center justify-center"
v-if="property.items.length === 0"
>
<IconifyIcon icon="tdesign:image" class="size-6 text-gray-800" />
</div>
<div v-else class="relative">
<Carousel
:autoplay="property.autoplay"
:autoplay-speed="property.interval * 1000"
:dots="property.indicator !== 'number'"
@change="handleIndexChange"
class="h-44"
>
<div v-for="(item, index) in property.items" :key="index">
<Image
class="h-full w-full object-cover"
:src="item.imgUrl"
:preview="false"
/>
</div>
</Carousel>
<div
v-if="property.indicator === 'number'"
class="absolute bottom-2.5 right-2.5 rounded-xl bg-black px-2 py-1 text-xs text-white opacity-40"
>
{{ currentIndex }} / {{ property.items.length }}
</div>
</div>
</template>

View File

@@ -21,11 +21,13 @@ import { AppLinkInput, Draggable } from '#/views/mall/promotion/components';
import ComponentContainerProperty from '../../component-container-property.vue';
//
/** 轮播图属性面板 */
defineOptions({ name: 'CarouselProperty' });
const props = defineProps<{ modelValue: CarouselProperty }>();
const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit);
</script>

View File

@@ -8,21 +8,17 @@ import { Image } from 'ant-design-vue';
/** 菜单导航 */
defineOptions({ name: 'MenuSwiper' });
const props = defineProps<{ property: MenuSwiperProperty }>();
// 标题的高度
const TITLE_HEIGHT = 20;
// 图标的高度
const ICON_SIZE = 32;
// 垂直间距:一行上下的间距
const SPACE_Y = 16;
// 分页
const pages = ref<MenuSwiperItemProperty[][]>([]);
// 轮播图高度
const carouselHeight = ref(0);
// 行高
const rowHeight = ref(0);
// 列宽
const columnWidth = ref('');
const TITLE_HEIGHT = 20; // 标题的高度
const ICON_SIZE = 32; // 图标的高度
const SPACE_Y = 16; // 垂直间距:一行上下的间距
const pages = ref<MenuSwiperItemProperty[][]>([]); // 分页
const carouselHeight = ref(0); // 轮播图高度
const rowHeight = ref(0); // 行高
const columnWidth = ref(''); // 列宽
watch(
() => props.property,
() => {

View File

@@ -13,10 +13,11 @@ import { getSpuDetailList } from '#/api/mall/product/spu';
/** 商品栏 */
defineOptions({ name: 'ProductList' });
// 定义属性
const props = defineProps<{ property: ProductListProperty }>();
// 商品列表
const spuList = ref<MallSpuApi.Spu[]>([]);
watch(
() => props.property.spuIds,
async () => {
@@ -27,19 +28,15 @@ watch(
deep: true,
},
);
// 手机宽度
const phoneWidth = ref(384);
// 容器
const containerRef = ref();
// 商品的列数
const columns = ref(2);
// 滚动条宽度
const scrollbarWidth = ref('100%');
// 商品图大小
const imageSize = ref('0');
// 商品网络列数
const gridTemplateColumns = ref('');
// 计算布局参数
const phoneWidth = ref(375); // 手机宽度
const containerRef = ref(); // 容器
const columns = ref(2); // 商品的列数
const scrollbarWidth = ref('100%'); // 滚动条宽度
const imageSize = ref('0'); // 商品图大小
const gridTemplateColumns = ref(''); // 商品网络列数
/** 计算布局参数 */
watch(
() => [props.property, phoneWidth, spuList.value.length],
() => {
@@ -69,9 +66,10 @@ watch(
},
{ immediate: true, deep: true },
);
/** 初始化 */
onMounted(() => {
// 提取手机宽度
phoneWidth.value = containerRef.value?.wrapRef?.offsetWidth || 384;
phoneWidth.value = containerRef.value?.wrapRef?.offsetWidth || 375;
});
</script>
<template>
@@ -146,5 +144,3 @@ onMounted(() => {
</div>
</div>
</template>
<style scoped lang="scss"></style>

View File

@@ -17,17 +17,18 @@ import {
} from 'ant-design-vue';
import UploadImg from '#/components/upload/image-upload.vue';
import { InputWithColor as ColorInput } from '#/views/mall/promotion/components';
import SpuShowcase from '#/views/mall/product/spu/components/spu-showcase.vue';
import { ColorInput } from '#/views/mall/promotion/components';
import ComponentContainerProperty from '../../component-container-property.vue';
// TODO: 添加组件
// import SpuShowcase from '#/views/mall/product/spu/components/spu-showcase.vue';
// 商品栏属性面板
/** 商品栏属性面板 */
defineOptions({ name: 'ProductListProperty' });
const props = defineProps<{ modelValue: ProductListProperty }>();
const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit);
</script>
@@ -39,7 +40,7 @@ const formData = useVModel(props, 'modelValue', emit);
:model="formData"
>
<Card title="商品列表" class="property-group" :bordered="false">
<!-- <SpuShowcase v-model="formData.spuIds" /> -->
<SpuShowcase v-model="formData.spuIds" />
</Card>
<Card title="商品样式" class="property-group" :bordered="false">
<FormItem label="布局" prop="type">
@@ -117,5 +118,3 @@ const formData = useVModel(props, 'modelValue', emit);
</Form>
</ComponentContainerProperty>
</template>
<style scoped lang="scss"></style>

View File

@@ -5,19 +5,19 @@ import { IconifyIcon } from '@vben/icons';
/** 搜索框 */
defineOptions({ name: 'SearchBar' });
defineProps<{ property: SearchProperty }>();
</script>
<template>
<div
class="search-bar"
:style="{
color: property.textColor,
}"
>
<!-- 搜索框 -->
<div
class="inner"
class="relative flex min-h-7 items-center text-sm"
:style="{
height: `${property.height}px`,
background: property.backgroundColor,
@@ -25,7 +25,7 @@ defineProps<{ property: SearchProperty }>();
}"
>
<div
class="placeholder"
class="flex w-full items-center gap-0.5 overflow-hidden text-ellipsis whitespace-nowrap break-all px-2"
:style="{
justifyContent: property.placeholderPosition,
}"
@@ -33,7 +33,7 @@ defineProps<{ property: SearchProperty }>();
<IconifyIcon icon="lucide:search" />
<span>{{ property.placeholder || '搜索商品' }}</span>
</div>
<div class="right">
<div class="absolute right-2 flex items-center justify-center gap-2">
<!-- 搜索热词 -->
<span v-for="(keyword, index) in property.hotKeywords" :key="index">
{{ keyword }}
@@ -44,37 +44,3 @@ defineProps<{ property: SearchProperty }>();
</div>
</div>
</template>
<style scoped lang="scss">
.search-bar {
/* 搜索框 */
.inner {
position: relative;
display: flex;
align-items: center;
min-height: 28px;
font-size: 14px;
.placeholder {
display: flex;
gap: 2px;
align-items: center;
width: 100%;
padding: 0 8px;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
white-space: nowrap;
}
.right {
position: absolute;
right: 8px;
display: flex;
gap: 8px;
align-items: center;
justify-content: center;
}
}
}
</style>

View File

@@ -11,9 +11,9 @@ defineOptions({ name: 'TabBar' });
defineProps<{ property: TabBarProperty }>();
</script>
<template>
<div class="tab-bar">
<div class="z-[2] w-full">
<div
class="tab-bar-bg"
class="flex flex-row items-center justify-around py-2"
:style="{
background:
property.style.bgType === 'color'
@@ -26,12 +26,18 @@ defineProps<{ property: TabBarProperty }>();
<div
v-for="(item, index) in property.items"
:key="index"
class="tab-bar-item"
class="flex w-full flex-col items-center justify-center text-xs"
>
<Image :src="index === 0 ? item.activeIconUrl : item.iconUrl">
<Image
:src="index === 0 ? item.activeIconUrl : item.iconUrl"
class="!h-[26px] w-[26px] rounded"
>
<template #error>
<div class="flex h-full w-full items-center justify-center">
<IconifyIcon icon="lucide:image" />
<IconifyIcon
icon="lucide:image"
class="h-[26px] w-[26px] rounded"
/>
</div>
</template>
</Image>
@@ -47,33 +53,3 @@ defineProps<{ property: TabBarProperty }>();
</div>
</div>
</template>
<style lang="scss" scoped>
.tab-bar {
z-index: 2;
width: 100%;
.tab-bar-bg {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
padding: 8px 0;
.tab-bar-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
font-size: 12px;
:deep(img),
.el-icon {
width: 26px;
height: 26px;
border-radius: 4px;
}
}
}
}
</style>

View File

@@ -22,7 +22,8 @@ import {
} from '#/views/mall/promotion/components';
import { component, THEME_LIST } from './config';
// 底部导航栏
/** 底部导航栏 */
defineOptions({ name: 'TabBarProperty' });
const props = defineProps<{ modelValue: TabBarProperty }>();
@@ -32,7 +33,7 @@ const formData = useVModel(props, 'modelValue', emit);
// 将数据库的值更新到右侧属性栏
component.property.items = formData.value.items;
// 要的主题
/** 处理主题变更 */
const handleThemeChange = () => {
const theme = THEME_LIST.find((theme) => theme.id === formData.value.theme);
if (theme?.color) {
@@ -42,7 +43,7 @@ const handleThemeChange = () => {
</script>
<template>
<div class="tab-bar">
<div>
<!-- 表单 -->
<Form
:model="formData"
@@ -142,5 +143,3 @@ const handleThemeChange = () => {
</Form>
</div>
</template>
<style lang="scss" scoped></style>

View File

@@ -5,11 +5,13 @@ import { useVModel } from '@vueuse/core';
import ComponentContainerProperty from '../../component-container-property.vue';
// 用户卡片属性面板
/** 用户卡片属性面板 */
defineOptions({ name: 'UserCardProperty' });
const props = defineProps<{ modelValue: UserCardProperty }>();
const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit);
</script>

View File

@@ -2,11 +2,10 @@ import type { ComponentStyle, DiyComponent } from '../../../util';
/** 用户卡券属性 */
export interface UserCouponProperty {
// 组件样式
style: ComponentStyle;
style: ComponentStyle; // 组件样式
}
// 定义组件
/** 定义组件 */
export const component = {
id: 'UserCoupon',
name: '用户卡券',

View File

@@ -5,7 +5,8 @@ import { Image } from 'ant-design-vue';
/** 用户订单 */
defineOptions({ name: 'UserOrder' });
// 定义属性
/** 定义属性 */
defineProps<{ property: UserOrderProperty }>();
</script>
<template>

View File

@@ -5,11 +5,13 @@ import { useVModel } from '@vueuse/core';
import ComponentContainerProperty from '../../component-container-property.vue';
// 用户订单属性面板
/** 用户订单属性面板 */
defineOptions({ name: 'UserOrderProperty' });
const props = defineProps<{ modelValue: UserOrderProperty }>();
const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit);
</script>

View File

@@ -5,7 +5,8 @@ import { Image } from 'ant-design-vue';
/** 用户资产 */
defineOptions({ name: 'UserWallet' });
// 定义属性
/** 定义属性 */
defineProps<{ property: UserWalletProperty }>();
</script>
<template>

View File

@@ -5,11 +5,13 @@ import { useVModel } from '@vueuse/core';
import ComponentContainerProperty from '../../component-container-property.vue';
// 用户资产属性面板
/** 用户资产属性面板 */
defineOptions({ name: 'UserWalletProperty' });
const props = defineProps<{ modelValue: UserWalletProperty }>();
const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit);
</script>

View File

@@ -9,11 +9,13 @@ import UploadImg from '#/components/upload/image-upload.vue';
import ComponentContainerProperty from '../../component-container-property.vue';
// 视频播放属性面板
/** 视频播放属性面板 */
defineOptions({ name: 'VideoPlayerProperty' });
const props = defineProps<{ modelValue: VideoPlayerProperty }>();
const emit = defineEmits(['update:modelValue']);
const formData = useVModel(props, 'modelValue', emit);
</script>

View File

@@ -38,6 +38,12 @@ const props = defineProps({
const emits = defineEmits(['reset', 'save', 'update:modelValue']); // 工具栏操作
// TODO @xingyu要不要加这个
// const qrcode = useQRCode(props.previewUrl, {
// errorCorrectionLevel: 'H',
// margin: 4,
// }); // 预览二维码
const componentLibrary = ref(); // 左侧组件库
const pageConfigComponent = ref<DiyComponent<any>>(
cloneDeep(PAGE_CONFIG_COMPONENT),
@@ -169,6 +175,7 @@ function handleComponentSelected(
index: number = -1,
) {
// 使用深拷贝避免响应式追踪循环警告
// TODO @xingyu这个是必须的么ele 没有哈。
selectedComponent.value = cloneDeep(component);
selectedComponentIndex.value = index;
}
@@ -501,4 +508,5 @@ onMounted(() => {
</div>
</PreviewModal>
</Page>
<!-- TODO @xingyu这里改造完后类似 web-ele/src/views/mall/promotion/components/diy-editor/index.vue 里的全局样式递推到子组件里的就没没了类似 property-group -->
</template>

View File

@@ -66,10 +66,11 @@ const handleDelete = function (index: number) {
class="drag-icon cursor-move text-gray-500"
/>
</Tooltip>
<Tooltip v-if="formData.length > min" title="删除">
<Tooltip title="删除">
<IconifyIcon
icon="lucide:trash-2"
class="cursor-pointer text-red-500 hover:text-red-600"
icon="ep:delete"
class="cursor-pointer text-red-500"
v-if="formData.length > min"
@click="handleDelete(index)"
/>
</Tooltip>
@@ -79,11 +80,7 @@ const handleDelete = function (index: number) {
</div>
</template>
</VueDraggable>
<Tooltip
:title="
limit > 0 && limit < Number.MAX_VALUE ? `最多添加${limit}个` : undefined
"
>
<Tooltip :title="limit < Number.MAX_VALUE ? `最多添加${limit}个` : undefined">
<Button
type="primary"
ghost
@@ -98,5 +95,3 @@ const handleDelete = function (index: number) {
</Button>
</Tooltip>
</template>
<style scoped lang="scss"></style>

View File

@@ -29,7 +29,6 @@ const props = defineProps({
type: Number,
default: 4,
}, // 行数,默认 4 行
cols: {
type: Number,
default: 4,
@@ -167,9 +166,7 @@ function handleHotAreaSelected(hotArea: Rect, index: number) {
emit('hotAreaSelected', hotArea, index);
}
/**
* 结束热区选择模式
*/
/** 结束热区选择模式 */
function exitHotAreaSelectMode() {
// 移除方块激活标记
eachCube((_, __, cube) => {

View File

@@ -1,8 +1,10 @@
<script setup lang="ts">
import { Space } from 'ant-design-vue';
// TODO @芋艿、@xingyu貌似上下移动的按钮被遮住了
/**
* 垂直按钮组
* Ant Design Vue 的按钮组只支持水平显示,通过重写样式实现垂直布局
* Ant Design Vue 的按钮组,通过 Space 实现垂直布局
*/
defineOptions({ name: 'VerticalButtonGroup' });
</script>