123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <template>
- <div class="props">
- <t-tabs v-model="data.tab">
- <t-tab-panel :value="1" :label="$t('布局容器')">
- <t-space direction="vertical" class="py-16 w-full">
- <div class="form-item px-12">
- <label style="width: 67px">ID</label>
- <div style="padding-left: 8px; line-height: 30px">
- {{ data.fit.id }}
- </div>
- </div>
- <div class="form-item px-12" style="margin-top: -12px">
- <label style="width: 50px">{{$t('名称')}}</label>
- <div style="padding-left: 8px; line-height: 30px">
- <t-input class="ml-8" v-model="data.fit.name" :placeholder="$t('默认0')"></t-input>
- </div>
- </div>
- <div class="form-item px-12">
- <label>{{$t('靠左')}}</label>
- <div class="flex center" style="align-items: center">
- <t-switch size="small" v-model="data.fit.left"></t-switch>
- <t-input-number theme="normal" class="ml-8" @change="onFitChange" v-model="data.fit.leftValue" :placeholder="$t('默认0')"></t-input-number>
- </div>
- </div>
- <div class="form-item px-12">
- <label>{{$t('靠右')}}</label>
- <div class="flex center" style="align-items: center">
- <t-switch size="small" v-model="data.fit.right"></t-switch>
- <t-input-number theme="normal" class="ml-8" @change="onFitChange" v-model="data.fit.rightValue" :placeholder="$t('默认0')"></t-input-number>
- </div>
- </div>
- <div class="form-item px-12">
- <label>{{$t('靠上')}}</label>
- <div class="flex center" style="align-items: center">
- <t-switch size="small" v-model="data.fit.top"></t-switch>
- <t-input-number theme="normal" class="ml-8" @change="onFitChange" v-model="data.fit.topValue" :placeholder="$t('默认0')"></t-input-number>
- </div>
- </div>
- <div class="form-item px-12">
- <label>{{$t('靠下')}}</label>
- <div class="flex center" style="align-items: center">
- <t-switch size="small" v-model="data.fit.bottom"></t-switch>
- <t-input-number theme="normal" class="ml-8" v-model="data.fit.bottomValue" @change="onFitChange" :placeholder="$t('默认0')"></t-input-number>
- </div>
- </div>
- <div class="form-item px-12">
- <label>{{$t('展示图元')}}</label>
- <div>
- <t-switch size="small" @change="fitPenVisible"></t-switch>
- </div>
- </div>
- <div class="px-12">
- <div class="mb-8">{{$t('图元列表')}}</div>
- <div class="grid head">
- <div class="title">{{$t('名称')}}</div>
- <div class="title">{{$t('图元')}}id</div>
- <div class="title">{{$t('操作')}}</div>
- </div>
- <div class="body">
- <div :data-penid="item.value" v-for="(item, i) in data.list" class="grid" :class="data.active.includes(item.value) ? 'active' : ''">
- <span class="hover" @click="doActive(item.value)">
- {{ item.label }}
- </span>
- <span class="hover" @click="doActive(item.value)">
- {{ item.value }}
- </span>
- <t-popconfirm @confirm="doRemove(i)" :content="$t('确认移除吗')">
- <t-tooltip :content="$t('从布局容器中移除此图元')">
- <div class="hover"><delete-icon></delete-icon></div>
- </t-tooltip>
- </t-popconfirm>
- </div>
- </div>
- </div>
- </t-space>
- </t-tab-panel>
- </t-tabs>
- </div>
- </template>
- <script lang="ts" setup>
- import {
- reactive,
- onBeforeMount,
- ref,
- watch,
- onUnmounted,
- onMounted,
- } from 'vue';
- import { useSelection } from '@/services/selections';
- import { DeleteIcon } from 'tdesign-icons-vue-next';
- const data = reactive({
- fit: undefined,
- tab: 1,
- list: [],
- active: [],
- });
- const { selections } = useSelection();
- onBeforeMount(() => {
- data.fit = selections.fit;
- getChildrenList();
- });
- onMounted(() => {
- meta2d.on('active', active);
- meta2d.on('fit', childChange);
- });
- onUnmounted(() => {
- watcher();
- meta2d.off('active', active);
- meta2d.off('fit', childChange);
- });
- const childChange = () => {
- getChildrenList();
- };
- const watcher = watch(
- () => selections.fit.id,
- (id) => {
- data.fit = selections.fit;
- getChildrenList();
- }
- );
- const getChildrenList = () => {
- data.list = [];
- selections.fit&&selections.fit.children?.forEach((id) => {
- const pen = meta2d.store.pens[id];
- if (pen) {
- data.list.push({
- label: (pen as any).description || pen.name,
- value: pen.id,
- locked: pen.locked,
- visible: pen.visible,
- tag: (pen as any).tag,
- });
- }
- });
- };
- const fitPenVisible = (e) => {
- if (e) {
- meta2d.store.data.pens.forEach((pen) => {
- if (!selections.fit.children?.includes(pen.id)) {
- meta2d.setValue(
- { id: pen.id, visible: false },
- { render: false, doEvent: false, history: false }
- );
- }
- });
- meta2d.canvas.hideFit();
- meta2d.canvas.canvasImage.init();
- meta2d.canvas.canvasImageBottom.init();
- meta2d.render();
- } else {
- meta2d.store.data.pens.forEach((pen) => {
- if (!selections.fit.children?.includes(pen.id)) {
- meta2d.setValue(
- { id: pen.id, visible: true },
- { render: false, doEvent: false, history: false }
- );
- }
- });
- meta2d.canvas.showFit();
- meta2d.canvas.canvasImage.init();
- meta2d.canvas.canvasImageBottom.init();
- meta2d.render();
- }
- };
- const doActive = (id) => {
- let pen = meta2d.store.pens[id];
- meta2d.active([pen], false);
- };
- const doRemove = (idx) => {
- let childId = data.list[idx].value;
- data.fit.children.splice(idx, 1);
- meta2d.inactive();
- meta2d.setVisible(meta2d.store.pens[childId], false);
- getChildrenList();
- };
- const active = () => {
- data.active = meta2d.store.active.map((pen) => pen.id);
- const element = document.body.querySelector(
- `[data-penid="${data.active[0]}"]`
- );
- if (element) {
- element.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
- }
- };
- const onFitChange = () => {
- meta2d.canvas.updateFitRect(data.fit);
- };
- </script>
- <style lang="postcss" scoped>
- .props {
- .grid {
- grid-template-columns: 100px 100px auto;
- padding: 0 12px;
- &.head {
- background: var(--color-background-input);
- line-height: 36px;
- margin-bottom: 6px;
- .title {
- line-height: 36px;
- }
- }
- }
- .active {
- color: var(--color-primary);
- }
- .body {
- max-height: 300px;
- overflow-y: auto;
- }
- }
- </style>
|