feat: 修改代码结构,新增删除按钮

This commit is contained in:
奔跑的面条 2023-05-24 16:56:39 +08:00
parent 551fb08c7a
commit fe06b55a56
3 changed files with 100 additions and 35 deletions

View File

@ -55,7 +55,9 @@ const addConfig = {
image: 'upload.png', image: 'upload.png',
redirectComponent: './components/Informations/Mores/Image', // 虚拟组件路径,尾部不跟 /’,相对于 /packages/index.ts 文件的位置 redirectComponent: './components/Informations/Mores/Image', // 虚拟组件路径,尾部不跟 /’,相对于 /packages/index.ts 文件的位置
disabled: true, disabled: true,
clickHandle: (photoConfig: ConfigType) => { configEvents: {
// 点击上传事件
addHandle: (photoConfig: ConfigType) => {
goDialog({ goDialog({
message: `图片需小于 ${backgroundImageSize}M 且只暂存在浏览器中,请自行对接后端接口!现只编译成 base64 进行渲染,对接后端请返回地址使用!`, message: `图片需小于 ${backgroundImageSize}M 且只暂存在浏览器中,请自行对接后端接口!现只编译成 base64 进行渲染,对接后端请返回地址使用!`,
transformOrigin: 'center', transformOrigin: 'center',
@ -82,6 +84,14 @@ const addConfig = {
}) })
} }
}) })
},
deleteHandle: (photoConfig: ConfigType, index: number) => {
goDialog({
message: '是否删除此图片?',
transformOrigin: 'center',
onPositiveCallback: () => {}
})
}
} }
} }

View File

@ -41,8 +41,8 @@ export type ConfigType = {
disabled?: boolean disabled?: boolean
// 图标 // 图标
icon?: string icon?: string
// 自定义单击事件 // 事件
clickHandle?: Function configEvents?: { [T: string]: Function }
} }
// 数据请求 // 数据请求

View File

@ -31,6 +31,19 @@
<n-ellipsis style="max-width: 90%">{{ item.title }}</n-ellipsis> <n-ellipsis style="max-width: 90%">{{ item.title }}</n-ellipsis>
</n-text> </n-text>
</div> </div>
<!-- 遮罩 -->
<div v-if="item.disabled" class="list-model"></div>
<!-- 工具栏 -->
<div v-if="isShowTools(item)" class="list-tools go-transition">
<n-button text type="default" color="#ffffff">
<template #icon>
<n-icon>
<TrashIcon />
</n-icon>
</template>
<span>删除</span>
</n-button>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -47,13 +60,16 @@ import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayou
import { componentInstall, loadingStart, loadingFinish, loadingError, JSONStringify } from '@/utils' import { componentInstall, loadingStart, loadingFinish, loadingError, JSONStringify } from '@/utils'
import { DragKeyEnum } from '@/enums/editPageEnum' import { DragKeyEnum } from '@/enums/editPageEnum'
import { createComponent } from '@/packages' import { createComponent } from '@/packages'
import { ConfigType, CreateComponentType } from '@/packages/index.d' import { ConfigType, CreateComponentType, PackagesCategoryEnum } from '@/packages/index.d'
import { ChatCategoryEnum } from '@/packages/components/Photos/index.d'
import { fetchConfigComponent, fetchChartComponent } from '@/packages/index' import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
import { Icon } from '@iconify/vue' import { Icon } from '@iconify/vue'
import { icon } from '@/plugins'
import omit from 'lodash/omit' import omit from 'lodash/omit'
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const { TrashIcon } = icon.ionicons5
const props = defineProps({ const props = defineProps({
menuOptions: { menuOptions: {
@ -65,6 +81,11 @@ const props = defineProps({
const chartLayoutStore = useChartLayoutStore() const chartLayoutStore = useChartLayoutStore()
const contentChartsItemBoxRef = ref() const contentChartsItemBoxRef = ref()
//
const isShowTools = (item: ConfigType) => {
return !item.disabled && item.package === PackagesCategoryEnum.PHOTOS && item.category === ChatCategoryEnum.PRIVATE
}
// //
const chartMode: Ref<ChartModeEnum> = computed(() => { const chartMode: Ref<ChartModeEnum> = computed(() => {
return chartLayoutStore.getChartType return chartLayoutStore.getChartType
@ -114,7 +135,7 @@ const dblclickHandle = async (item: ConfigType) => {
} }
// //
const clickHandle = (item: ConfigType) => item.clickHandle && item.clickHandle(item) const clickHandle = (item: ConfigType) => item?.configEvents?.addHandle(item)
watch( watch(
() => chartMode.value, () => chartMode.value,
@ -127,9 +148,12 @@ watch(
} }
) )
watch(() => props.menuOptions, (n) => { watch(
() => props.menuOptions,
n => {
console.log(n) console.log(n)
}) }
)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -152,6 +176,7 @@ $halfCenterHeight: 50px;
gap: 9px; gap: 9px;
transition: all 0.7s linear; transition: all 0.7s linear;
.item-box { .item-box {
position: relative;
margin: 0; margin: 0;
width: $itemWidth; width: $itemWidth;
overflow: hidden; overflow: hidden;
@ -162,7 +187,10 @@ $halfCenterHeight: 50px;
&:hover { &:hover {
@include hover-border-color('background-color4'); @include hover-border-color('background-color4');
.list-img { .list-img {
transform: scale(1.1); transform: scale(1.08);
}
.list-tools {
opacity: 1;
} }
} }
.list-header { .list-header {
@ -194,6 +222,33 @@ $halfCenterHeight: 50px;
padding-left: 5px; padding-left: 5px;
} }
} }
.list-model {
z-index: 1;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0);
}
.list-tools {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
bottom: 0;
left: 0;
margin: 0 4px 2px;
height: 26px;
width: calc(100% - 8px);
opacity: 0;
border-radius: 6px;
backdrop-filter: blur(20px);
background-color: rgba(255, 255, 255, 0.1);
&:hover {
background-color: rgba(232, 128, 128, 0.7);
}
}
} }
&.single { &.single {
.item-box { .item-box {