Commit ba5a8664 authored by 郭铭瑶's avatar 郭铭瑶 🤘

筛选出现符合box的组件

parent cd909b8c
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<div v-if="msg" class="msg"> <div v-if="msg" class="msg">
<p v-if="msg.name">{{ msg.name }}</p> <p v-if="msg.name">{{ msg.name }}</p>
<p v-if="msg.value" :style="{ color: msg.color }"> <p v-if="msg.value" :style="{ color: msg.color }">
<MonitorCount :value="msg.value" /> <MonitorCount v-if="typeof msg.value === 'number'" :value="msg.value" />
<span v-else>{{ msg.value }}</span>
<span v-if="msg.unit">{{ msg.unit }}</span> <span v-if="msg.unit">{{ msg.unit }}</span>
</p> </p>
</div> </div>
...@@ -34,6 +35,10 @@ export default defineComponent({ ...@@ -34,6 +35,10 @@ export default defineComponent({
type: [String, Array] as PropType<string | string[]>, type: [String, Array] as PropType<string | string[]>,
default: () => ['#0094FF', '#1EFBFF'], default: () => ['#0094FF', '#1EFBFF'],
}, },
backgroundColor: {
type: String as PropType<string>,
default: null,
},
/** 进度百分值 */ /** 进度百分值 */
value: { value: {
type: Number as PropType<number>, type: Number as PropType<number>,
...@@ -60,6 +65,9 @@ export default defineComponent({ ...@@ -60,6 +65,9 @@ export default defineComponent({
return { background: props.color } return { background: props.color }
}) })
const bgColor = computed(() => { const bgColor = computed(() => {
if (props.backgroundColor) {
return { background: props.backgroundColor, opacity: 1 }
}
if (Array.isArray(props.color)) { if (Array.isArray(props.color)) {
return { return {
background: props.color[0], background: props.color[0],
...@@ -108,6 +116,7 @@ export default defineComponent({ ...@@ -108,6 +116,7 @@ export default defineComponent({
top 0 top 0
&.inner &.inner
transition width .5s ease-in-out transition width .5s ease-in-out
z-index 2
&.bg &.bg
opacity .3 opacity .3
</style> </style>
import { ref } from 'vue' import { ref } from 'vue'
import componentList, { tabs } from '@/utils/component-list' import componentList, { tabs } from '@/utils/component-list'
import useConfig, { Config } from './useConfig' import useConfig, { Config } from './useConfig'
import take2rows from '@/utils/take2rows'
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<Config['components']>({}) // {容器下标: 组件key} const components = ref<Config['components']>({}) // {容器下标: 组件key}
const isTake2rows = ref<boolean>(false)
const config = useConfig() // 获取组件选择配置 const config = useConfig() // 获取组件选择配置
if (config?.components) { if (config?.components) {
components.value = config.components components.value = config.components
} }
const openComponentModal = (i: number) => { const openComponentModal = (i: number, template: string[]) => {
// 点击容器中的新增按钮 // 点击容器中的新增按钮
curBox.value = i curBox.value = i
const name = `box${i + 1}`
isTake2rows.value = take2rows(template, name)
showComponentModal.value = true showComponentModal.value = true
} }
const onSelectComponent = (key: string) => { const onSelectComponent = (key: string) => {
...@@ -35,5 +39,6 @@ export default function useComponent() { ...@@ -35,5 +39,6 @@ export default function useComponent() {
onSelectComponent, onSelectComponent,
onCancelComponent, onCancelComponent,
tabs, tabs,
isTake2rows,
} }
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
// import * as vue from 'vue' // import * as vue from 'vue'
// import fetchComponents from 'http://127.0.0.1:8081/component-lib.min.js' // import fetchComponents from 'http://127.0.0.1:8081/component-lib.min.js'
// const { A001, A002, A003, A004, A005, A006, A007, A008, A009 } = // const {
// fetchComponents(vue)('http://127.0.0.1:8082') // A001,
// A002,
// A003,
// A004,
// A005,
// A006,
// A007,
// A008,
// A009,
// A010,
// A011,
// A012,
// A013,
// A014,
// } = fetchComponents(vue)('http://127.0.0.1:8082')
import { import {
A001, A001,
...@@ -13,6 +27,11 @@ import { ...@@ -13,6 +27,11 @@ import {
A007, A007,
A008, A008,
A009, A009,
A010,
A011,
A012,
A013,
A014,
} from './component-lib.esm' // 未正式上生产暂时先如此代替 } from './component-lib.esm' // 未正式上生产暂时先如此代替
export default { export default {
...@@ -25,6 +44,11 @@ export default { ...@@ -25,6 +44,11 @@ export default {
A007, A007,
A008, A008,
A009, A009,
A010,
A011,
A012,
A013,
A014,
} }
export const tabs = { export const tabs = {
...@@ -39,7 +63,7 @@ export const tabs = { ...@@ -39,7 +63,7 @@ export const tabs = {
'A008', 'A008',
'A009', 'A009',
], ],
市场: [], 市场: ['A010', 'A011'],
修缮: [], 修缮: ['A012', 'A013'],
保障: [], 保障: ['A014'],
} }
export default function take2rows(template: string[], name: string): boolean {
let count = 0,
curIndex: null | number = null
for (let index = 0; index < template.length; index++) {
const arr = template[index].split(' ')
const location = arr.indexOf(name)
if (location < 0) continue
if (count === 0) {
count += 1
curIndex = location
} else {
if (curIndex === location) {
count += 1
}
}
}
return count === 2
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<div class="container"> <div class="container">
<div class="tabs"> <div class="tabs">
<div <div
v-for="tab in tabs" v-for="tab in tabList"
:key="tab.key" :key="tab.key"
class="tab" class="tab"
:class="{ on: curTab === tab.key }" :class="{ on: curTab === tab.key }"
...@@ -20,15 +20,17 @@ ...@@ -20,15 +20,17 @@
</div> </div>
<div class="list"> <div class="list">
<template v-if="componentKeys.length > 0"> <template v-if="componentKeys.length > 0">
<div <template v-for="key in componentKeys">
v-for="key in componentKeys" <div
:key="key" v-if="componentList[key].row == rows"
class="component" :key="key"
:class="{ checked: curComponent === key }" class="component"
@click.prevent.stop="onSelect(key)" :class="{ checked: curComponent === key }"
> @click.prevent.stop="onSelect(key)"
<component :is="componentList[key]" /> >
</div> <component :is="componentList[key]" />
</div>
</template>
</template> </template>
<m-empty v-else text="暂无组件" /> <m-empty v-else text="暂无组件" />
</div> </div>
...@@ -45,6 +47,10 @@ const props = defineProps({ ...@@ -45,6 +47,10 @@ const props = defineProps({
type: Boolean as PropType<boolean>, type: Boolean as PropType<boolean>,
default: false, default: false,
}, },
rows: {
type: Number as PropType<number>,
default: 1,
},
}) })
const emit = defineEmits(['update:modelValue', 'select']) const emit = defineEmits(['update:modelValue', 'select'])
const visible = ref(false) const visible = ref(false)
...@@ -63,7 +69,6 @@ watch( ...@@ -63,7 +69,6 @@ watch(
}, },
) )
const { componentList, tabs } = useComponent() const { componentList, tabs } = useComponent()
const curTab = ref('1') const curTab = ref('1')
const tabList = [ const tabList = [
{ name: '物业', key: '1', list: tabs['物业'] }, { name: '物业', key: '1', list: tabs['物业'] },
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
v-else v-else
class="add-btn" class="add-btn"
src="@/assets/images/add.png" src="@/assets/images/add.png"
@click.prevent.stop="openComponentModal(index)" @click.prevent.stop="openComponentModal(index, layout.template)"
/> />
<n-icon <n-icon
v-show="!!components[index]" v-show="!!components[index]"
...@@ -42,7 +42,11 @@ ...@@ -42,7 +42,11 @@
</m-grid> </m-grid>
</div> </div>
<LayoutModal v-model="showLayoutModal" @select="onChangeLayout" /> <LayoutModal v-model="showLayoutModal" @select="onChangeLayout" />
<ComponentModal v-model="showComponentModal" @select="onSelectComponent" /> <ComponentModal
v-model="showComponentModal"
:rows="isTake2rows ? 2 : 1"
@select="onSelectComponent"
/>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
...@@ -61,6 +65,7 @@ const { ...@@ -61,6 +65,7 @@ const {
openComponentModal, openComponentModal,
onCancelComponent, onCancelComponent,
onSelectComponent, onSelectComponent,
isTake2rows,
} = useComponent() } = useComponent()
const save = () => { const save = () => {
const data = { const data = {
......
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