Commit 58efbc50 authored by 郭铭瑶's avatar 郭铭瑶 🤘

移除选中组件&保存当前配置

parent fb23ab2a
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"": { "": {
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"@vicons/ionicons5": "^0.11.0",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"countup.js": "^2.0.8", "countup.js": "^2.0.8",
...@@ -955,6 +956,12 @@ ...@@ -955,6 +956,12 @@
"url": "https://opencollective.com/typescript-eslint" "url": "https://opencollective.com/typescript-eslint"
} }
}, },
"node_modules/@vicons/ionicons5": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@vicons/ionicons5/-/ionicons5-0.11.0.tgz",
"integrity": "sha512-4IWamqtXUsuCdlW6NQc2xyoJ+PUXGMwzSrppQbdVCYg0pjYld89jOfLOIkuTWq8o2XUa+Q1/78jzWBtXMTojNg==",
"license": "MIT"
},
"node_modules/@vitejs/plugin-vue": { "node_modules/@vitejs/plugin-vue": {
"version": "1.6.0", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.6.0.tgz", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.6.0.tgz",
...@@ -6086,6 +6093,11 @@ ...@@ -6086,6 +6093,11 @@
"eslint-visitor-keys": "^2.0.0" "eslint-visitor-keys": "^2.0.0"
} }
}, },
"@vicons/ionicons5": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@vicons/ionicons5/-/ionicons5-0.11.0.tgz",
"integrity": "sha512-4IWamqtXUsuCdlW6NQc2xyoJ+PUXGMwzSrppQbdVCYg0pjYld89jOfLOIkuTWq8o2XUa+Q1/78jzWBtXMTojNg=="
},
"@vitejs/plugin-vue": { "@vitejs/plugin-vue": {
"version": "1.6.0", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.6.0.tgz", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.6.0.tgz",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"serve": "vite preview" "serve": "vite preview"
}, },
"dependencies": { "dependencies": {
"@vicons/ionicons5": "^0.11.0",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"countup.js": "^2.0.8", "countup.js": "^2.0.8",
......
...@@ -37,7 +37,6 @@ export default defineComponent({ ...@@ -37,7 +37,6 @@ export default defineComponent({
watch( watch(
[() => props.template, () => props.columns, () => props.rows], [() => props.template, () => props.columns, () => props.rows],
async ([val]) => { async ([val]) => {
console.log(val)
if (val && val.length > 0) { if (val && val.length > 0) {
await nextTick() await nextTick()
setChildrenArea() setChildrenArea()
......
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import list from '@/utils/component-list' import list from '@/utils/component-list'
import useConfig from './useConfig'
export default function useComponent() { export default function useComponent() {
const showComponentModal = ref(false) // 展示组件选择框 const showComponentModal = ref(false) // 展示组件选择框
const curBox = ref<number | null>(null) // 当前容器下标 const curBox = ref<number | null>(null) // 当前容器下标
const components = ref<{ [key: number]: string }>({}) // {容器下标: 组件key} const components = ref<{ [key: number]: string }>({}) // {容器下标: 组件key}
const config = useConfig() // 获取组件选择配置
if (config?.components) {
components.value = config.components
}
const openComponentModal = (i: number) => { const openComponentModal = (i: number) => {
// 点击容器中的新增按钮 // 点击容器中的新增按钮
curBox.value = i curBox.value = i
showComponentModal.value = true showComponentModal.value = true
} }
const onChangeComponent = (key: string) => { const onSelectComponent = (key: string) => {
// 选择组件后将key存入 // 选择组件后将key存入
if (curBox.value === null) return if (curBox.value === null) return
components.value[curBox.value] = key components.value[curBox.value] = key
} }
const onCancelComponent = (i: number) => {
// 取消组件
delete components.value[i]
}
const componentList = computed(() => list) // key值-组件 对照表 const componentList = computed(() => list) // key值-组件 对照表
return { return {
...@@ -22,6 +33,7 @@ export default function useComponent() { ...@@ -22,6 +33,7 @@ export default function useComponent() {
componentList, componentList,
showComponentModal, showComponentModal,
openComponentModal, openComponentModal,
onChangeComponent, onSelectComponent,
onCancelComponent,
} }
} }
interface Config {
layout?: { template: string[]; rows: string; boxNum: number }
components?: { [key: number]: string }
}
export default function useConfig(config?: string) {
if (config) {
// 保存配置
window.sessionStorage.setItem('__layout_components__', config)
return
}
// 获取配置
let data = window.sessionStorage.getItem('__layout_components__')
data && (data = JSON.parse(data))
return data as Config
}
import { ref } from 'vue' import { ref } from 'vue'
import useConfig from './useConfig'
export default function useLayout() { export default function useLayout() {
const showLayoutModal = ref(false) // 展示布局选择弹窗 const showLayoutModal = ref(false) // 展示布局选择弹窗
...@@ -8,6 +9,12 @@ export default function useLayout() { ...@@ -8,6 +9,12 @@ export default function useLayout() {
rows: '', rows: '',
boxNum: 0, boxNum: 0,
}) })
const config = useConfig() // 获取布局配置
if (config?.layout) {
layout.value = config.layout
}
const onChangeLayout = (key: string) => { const onChangeLayout = (key: string) => {
// 选择某一布局后获取布局内容 // 选择某一布局后获取布局内容
layout.value = getLayout(key) layout.value = getLayout(key)
......
import { createApp } from 'vue' import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import MyComponent from '@/components/MyComponent' import MyComponent from '@/components/MyComponent'
import { create, NIcon } from 'naive-ui'
createApp(App).use(MyComponent).mount('#app') const naive = create({
components: [NIcon],
})
createApp(App).use(MyComponent).use(naive).mount('#app')
...@@ -56,6 +56,10 @@ watch( ...@@ -56,6 +56,10 @@ watch(
() => visible.value, () => visible.value,
(val) => { (val) => {
emit('update:modelValue', val) emit('update:modelValue', val)
if (!val) {
curTab.value = '1'
curComponent.value = ''
}
}, },
) )
......
<template> <template>
<div class="main"> <div class="main">
<m-title area="title" @touch="showLayoutModal = true">静安智慧房管</m-title> <m-title
area="title"
@click.prevent.stop="save"
@touch="showLayoutModal = true"
>静安智慧房管</m-title
>
<m-grid <m-grid
v-if="layout.boxNum > 0" v-if="layout.boxNum > 0"
:template="layout.template" :template="layout.template"
...@@ -24,11 +29,19 @@ ...@@ -24,11 +29,19 @@
src="@/assets/images/add.png" src="@/assets/images/add.png"
@click.prevent.stop="openComponentModal(index)" @click.prevent.stop="openComponentModal(index)"
/> />
<n-icon
v-show="!!components[index]"
class="del-btn"
size=".16rem"
@click="onCancelComponent(index)"
>
<TrashBin />
</n-icon>
</div> </div>
</m-grid> </m-grid>
</div> </div>
<LayoutModal v-model="showLayoutModal" @select="onChangeLayout" /> <LayoutModal v-model="showLayoutModal" @select="onChangeLayout" />
<ComponentModal v-model="showComponentModal" @select="onChangeComponent" /> <ComponentModal v-model="showComponentModal" @select="onSelectComponent" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
...@@ -36,6 +49,8 @@ import LayoutModal from './components/layout-modal.vue' ...@@ -36,6 +49,8 @@ import LayoutModal from './components/layout-modal.vue'
import ComponentModal from './components/component-modal.vue' import ComponentModal from './components/component-modal.vue'
import useLayout from '@/hooks/useLayout' import useLayout from '@/hooks/useLayout'
import useComponent from '@/hooks/useComponent' import useComponent from '@/hooks/useComponent'
import useConfig from '@/hooks/useConfig'
import { TrashBin } from '@vicons/ionicons5'
const { showLayoutModal, layout, onChangeLayout } = useLayout() const { showLayoutModal, layout, onChangeLayout } = useLayout()
const { const {
...@@ -43,8 +58,16 @@ const { ...@@ -43,8 +58,16 @@ const {
componentList, componentList,
showComponentModal, showComponentModal,
openComponentModal, openComponentModal,
onChangeComponent, onCancelComponent,
onSelectComponent,
} = useComponent() } = useComponent()
const save = () => {
const data = {
layout: layout.value,
components: components.value,
}
useConfig(JSON.stringify(data))
}
</script> </script>
<style lang="stylus" scoped> <style lang="stylus" scoped>
...@@ -61,6 +84,9 @@ const { ...@@ -61,6 +84,9 @@ const {
$blur(0.01rem) $blur(0.01rem)
position relative position relative
overflow hidden overflow hidden
&:hover
>.del-btn
opacity 0.7
&.done &.done
border none border none
background transparent background transparent
...@@ -79,4 +105,14 @@ const { ...@@ -79,4 +105,14 @@ const {
opacity 1 opacity 1
width .24rem width .24rem
height @width height @width
>.del-btn
position absolute
top .05rem
right .05rem
cursor pointer
color red
opacity 0
transition opacity .2s ease-in-out
&:hover
opacity 1
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment