Skip to content

Commit 9591ed7

Browse files
committed
📖 code review:店铺装修逻辑
1 parent b86f082 commit 9591ed7

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

src/components/DiyEditor/components/ComponentContainer.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<component :is="component.id" :property="component.property" />
99
</div>
1010
<div class="component-wrap">
11-
<!-- 左侧组件名 -->
11+
<!-- 左侧:组件名(悬浮的小贴条) -->
1212
<div class="component-name" v-if="component.name">
1313
{{ component.name }}
1414
</div>
15-
<!-- 左侧:组件操作工具栏 -->
15+
<!-- 右侧:组件操作工具栏 -->
1616
<div class="component-toolbar" v-if="showToolbar && component.name && active">
1717
<VerticalButtonGroup type="primary">
1818
<el-tooltip content="上移" placement="right">
@@ -54,7 +54,7 @@ import { propTypes } from '@/utils/propTypes'
5454
import { object } from 'vue-types'
5555
5656
/**
57-
* 组件容器
57+
* 组件容器:目前在中间部分
5858
* 用于包裹组件,为组件提供 背景、外边距、内边距、边框等样式
5959
*/
6060
defineOptions({ name: 'ComponentContainer' })

src/components/DiyEditor/components/ComponentContainerProperty.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<template>
22
<el-tabs stretch>
3+
<!-- 每个组件的自定义内容 -->
34
<el-tab-pane label="内容" v-if="$slots.default">
45
<slot></slot>
56
</el-tab-pane>
7+
8+
<!-- 每个组件的通用内容 -->
69
<el-tab-pane label="样式" lazy>
710
<el-card header="组件样式" class="property-group">
811
<el-form :model="formData" label-width="80px">
@@ -51,7 +54,7 @@
5154
import { ComponentStyle, usePropertyForm } from '@/components/DiyEditor/util'
5255
5356
/**
54-
* 组件容器属性
57+
* 组件容器属性:目前右边部分
5558
* 用于包裹组件,为组件提供 背景、外边距、内边距、边框等样式
5659
*/
5760
defineOptions({ name: 'ComponentContainer' })

src/components/DiyEditor/components/ComponentLibrary.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,19 @@ import { componentConfigs } from '../components/mobile/index'
4141
import { cloneDeep } from 'lodash-es'
4242
import { DiyComponent, DiyComponentLibrary } from '@/components/DiyEditor/util'
4343
44-
/** 组件库 */
44+
/** 组件库:目前左侧的【基础组件】、【图文组件】部分 */
4545
defineOptions({ name: 'ComponentLibrary' })
4646
4747
// 组件列表
4848
const props = defineProps<{
4949
list: DiyComponentLibrary[]
5050
}>()
51+
// 组件分组
5152
const groups = reactive<any[]>([])
5253
// 展开的折叠面板
5354
const extendGroups = reactive<string[]>([])
55+
56+
// 监听 list 属性,按照 DiyComponentLibrary 的 name 分组
5457
watch(
5558
() => props.list,
5659
() => {

src/components/DiyEditor/index.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
</el-tooltip>
2828
</el-button-group>
2929
</el-header>
30+
3031
<!-- 中心区域 -->
3132
<el-container class="editor-container">
32-
<!-- 左侧:组件库 -->
33+
<!-- 左侧:组件库(ComponentLibrary) -->
3334
<ComponentLibrary ref="componentLibrary" :list="libs" v-if="libs && libs.length > 0" />
34-
<!-- 中心设计区域 -->
35+
<!-- 中心:设计区域(ComponentContainer) -->
3536
<div class="editor-center page-prop-area" @click="handlePageSelected">
3637
<!-- 手机顶部 -->
3738
<div class="editor-design-top">
@@ -132,7 +133,7 @@
132133
</template>
133134
</div>
134135
</div>
135-
<!-- 右侧属性面板 -->
136+
<!-- 右侧:属性面板(ComponentContainerProperty) -->
136137
<el-aside class="editor-right" width="350px" v-if="selectedComponent?.property">
137138
<el-card
138139
shadow="never"
@@ -160,6 +161,7 @@
160161
</el-aside>
161162
</el-container>
162163
</el-container>
164+
163165
<!-- 预览弹框 -->
164166
<Dialog v-model="previewDialogVisible" title="预览" width="700">
165167
<div class="flex justify-around">
@@ -231,6 +233,7 @@ const props = defineProps({
231233
})
232234
233235
// 监听传入的页面配置
236+
// 解析出 pageConfigComponent 页面整体的配置,navigationBarComponent、pageComponents、tabBarComponent 页面上、中、下的配置
234237
watch(
235238
() => props.modelValue,
236239
() => {
@@ -251,6 +254,7 @@ watch(
251254
immediate: true
252255
}
253256
)
257+
254258
// 保存
255259
const handleSave = () => {
256260
const pageConfig = {
@@ -303,7 +307,7 @@ const handleTabBarSelected = () => {
303307
handleComponentSelected(unref(tabBarComponent))
304308
}
305309
306-
// 组件变动
310+
// 组件变动(拖拽)
307311
const handleComponentChange = (dragEvent: any) => {
308312
// 新增,即从组件库拖拽添加组件
309313
if (dragEvent.added) {
@@ -327,19 +331,21 @@ const swapComponent = (oldIndex: number, newIndex: number) => {
327331
selectedComponentIndex.value = newIndex
328332
}
329333
330-
/** 移动组件 */
334+
/** 移动组件(上移、下移) */
331335
const handleMoveComponent = (index: number, direction: number) => {
332336
const newIndex = index + direction
333337
if (newIndex < 0 || newIndex >= pageComponents.value.length) return
334338
335339
swapComponent(index, newIndex)
336340
}
341+
337342
/** 复制组件 */
338343
const handleCopyComponent = (index: number) => {
339344
const component = cloneDeep(pageComponents.value[index])
340345
component.uid = new Date().getTime()
341346
pageComponents.value.splice(index + 1, 0, component)
342347
}
348+
343349
/**
344350
* 删除组件
345351
* @param index 当前组件index
@@ -371,6 +377,7 @@ const handleReset = () => {
371377
if (reload) reload()
372378
emits('reset')
373379
}
380+
374381
// 预览
375382
const previewDialogVisible = ref(false)
376383
const handlePreview = () => {
@@ -388,10 +395,12 @@ const setDefaultSelectedComponent = () => {
388395
selectedComponent.value = unref(tabBarComponent)
389396
}
390397
}
398+
391399
watch(
392400
() => [props.showPageConfig, props.showNavigationBar, props.showTabBar],
393401
() => setDefaultSelectedComponent()
394402
)
403+
395404
onMounted(() => setDefaultSelectedComponent())
396405
</script>
397406
<style lang="scss" scoped>

src/router/modules/remaining.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ const remainingRouter: AppRouteRecordRaw[] = [
472472
meta: {
473473
title: '模板装修',
474474
noCache: true,
475-
hidden: true
475+
hidden: true,
476+
// TODO @疯狂:建议 menu 那的 /mall/promotion/diy-template/diy-template 改成 /mall/promotion/diy/template
477+
activeMenu: '/mall/promotion/diy-template/diy-template'
476478
},
477479
component: () => import('@/views/mall/promotion/diy/template/decorate.vue')
478480
},
@@ -482,7 +484,9 @@ const remainingRouter: AppRouteRecordRaw[] = [
482484
meta: {
483485
title: '页面装修',
484486
noCache: true,
485-
hidden: true
487+
hidden: true,
488+
// TODO @疯狂:建议 menu 那的 /mall/promotion/diy-template/diy-page 改成 /mall/promotion/diy/page
489+
activeMenu: '/mall/promotion/diy-template/diy-page'
486490
},
487491
component: () => import('@/views/mall/promotion/diy/page/decorate.vue')
488492
}

src/views/mall/promotion/diy/page/decorate.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const getPageDetail = async (id: any) => {
3030
formLoading.value = false
3131
}
3232
}
33+
3334
// 提交表单
3435
const submitForm = async () => {
3536
// 校验表单

0 commit comments

Comments
 (0)