Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support checking all blocks in material add block panel #923

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions packages/common/component/PluginBlockList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<div v-if="blockStyle === BlockStyles.Mini" class="header">
<div class="col-checkbox"></div>
<div class="col-checkbox" v-if="showCheckbox">
<select-all
:items="data"
:selected="checked"
:hidden-label="true"
@select-all="(items) => handleSelectAll(items)"
gene9831 marked this conversation as resolved.
Show resolved Hide resolved
@deselect-all="handleDeselectAll"
></select-all>
</div>
<div class="col-name">区块名称</div>
<div class="col-time">创建时间</div>
<div class="col-created-by">创建人</div>
Expand Down Expand Up @@ -143,6 +151,7 @@ import { Progress, Tooltip } from '@opentiny/vue'
import PluginBlockItemImg from './PluginBlockItemImg.vue'
import SearchEmpty from './SearchEmpty.vue'
import SvgButton from './SvgButton.vue'
import SelectAll from './SelectAll.vue'

const BlockStyles = {
Default: 'default',
Expand All @@ -160,7 +169,8 @@ export default {
TinyTooltip: Tooltip,
PluginBlockItemImg,
SvgButton,
SearchEmpty
SearchEmpty,
SelectAll
},
props: {
data: {
Expand Down Expand Up @@ -234,7 +244,7 @@ export default {
default: 2
}
},
emits: ['click', 'iconClick', 'add', 'deleteBlock', 'openVersionPanel', 'editBlock'],
emits: ['click', 'iconClick', 'add', 'deleteBlock', 'openVersionPanel', 'editBlock', 'checkAll', 'cancelCheckAll'],
setup(props, { emit }) {
const panelState = inject('panelState', {})
const blockUsers = inject('blockUsers')
Expand Down Expand Up @@ -361,6 +371,14 @@ export default {
}
)

const handleSelectAll = (items) => {
emit('checkAll', items)
}

const handleDeselectAll = () => {
emit('cancelCheckAll')
}

return {
BlockStyles,
isShortcutPanel: panelState.isShortcutPanel,
Expand All @@ -379,7 +397,9 @@ export default {
handleSettingMouseOver,
handleShowVersionMenu,
editBlock,
format
format,
handleSelectAll,
handleDeselectAll
}
}
}
Expand Down Expand Up @@ -446,6 +466,11 @@ export default {
}
}

.col-checkbox {
display: flex;
flex-direction: column;
align-items: center;
}
.col-checkbox,
.block-item-small-list:deep(.table-selection) {
width: 40px;
Expand Down
42 changes: 42 additions & 0 deletions packages/common/component/SelectAll.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<tiny-checkbox class="block-select-all" :indeterminate="isIndeterminate" v-model="selectedAll">
{{ hiddenLabel ? '' : '全选' }}
</tiny-checkbox>
</template>

<script setup lang="ts">
gene9831 marked this conversation as resolved.
Show resolved Hide resolved
import { Checkbox as TinyCheckbox } from '@opentiny/vue'
import { computed, defineEmits, defineProps } from 'vue'

const props = defineProps({
items: {
gene9831 marked this conversation as resolved.
Show resolved Hide resolved
type: Array,
default: () => []
},
selected: {
type: Array,
default: () => []
},
hiddenLabel: {
type: Boolean,
default: false
}
})

const emit = defineEmits(['selectAll', 'deselectAll'])
gene9831 marked this conversation as resolved.
Show resolved Hide resolved

const selectedAll = computed({
get() {
return props.items.length > 0 && props.items.length === props.selected.length
},
set(value) {
if (value) {
emit('selectAll', props.items)
} else {
emit('deselectAll')
}
}
})

const isIndeterminate = computed(() => props.selected.length > 0 && props.selected.length !== props.items.length)
</script>
1 change: 1 addition & 0 deletions packages/common/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export { default as BlockLinkField } from './BlockLinkField.vue'
export { default as BlockLinkEvent } from './BlockLinkEvent.vue'
export { default as BlockDescription } from './BlockDescription.vue'
export { default as PluginBlockList } from './PluginBlockList.vue'
export { default as SelectAll } from './SelectAll.vue'
export { default as ButtonGroup } from './ButtonGroup.vue'
export { default as CloseIcon } from './CloseIcon.vue'
export { default as LifeCycles } from './LifeCycles.vue'
Expand Down
10 changes: 10 additions & 0 deletions packages/plugins/block/src/composable/useBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ const cancelCheck = (block) => {
selectedBlockArray.value = selectedBlockArray.value.filter((item) => item.id !== block.id)
}

const checkAll = (blockList) => {
selectedBlockArray.value = blockList
}

const cancelCheckAll = () => {
selectedBlockArray.value = []
}

const getBlockAssetsByVersion = (block, version) => {
let assets = block.assets

Expand Down Expand Up @@ -737,6 +745,8 @@ export default function () {
sort,
check,
cancelCheck,
checkAll,
cancelCheckAll,
getBlockList,
setBlockList,
getBlockI18n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default {
TinyIconSearch: iconSearch()
},
setup() {
const { isDefaultGroupId, isRefresh, selectedGroup, selectedBlockArray, getGroupList } = useBlock()
const { isDefaultGroupId, isRefresh, selectedGroup, selectedBlockArray, getGroupList, cancelCheckAll } = useBlock()
const { panel, closePanel } = useGroupPanel()
const { message } = useModal()
const getAppId = () => getMetaApi(META_SERVICE.GlobalService).getBaseInfo().id
Expand Down Expand Up @@ -155,6 +155,9 @@ export default {
status: 'error'
})
})
.finally(() => {
cancelCheckAll()
})
panelState.isBlockGroupPanel = false
closePanel()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<div class="block-add-transfer">
<div class="block-add-transfer-footer">
<select-all
v-if="state.displayType === 'grid'"
class="block-select-all"
:items="state.blockList"
:selected="selectedBlockArray"
@select-all="checkAll"
@deselect-all="cancelCheckAll"
></select-all>
<slot name="search"></slot>
<tiny-select v-model="state.selectedSort" class="transfer-order-select" placeholder="请选择">
<tiny-option v-for="item in state.sortList" :key="item.id" :label="item.text" :value="item.id"></tiny-option>
Expand All @@ -18,6 +26,8 @@
:checked="selectedBlockArray"
:grid-columns="6"
@check="checkBlock"
@checkAll="checkAll"
@cancelCheckAll="cancelCheckAll"
></block-list>
</div>
</div>
Expand All @@ -26,6 +36,7 @@
<script>
import { computed, onMounted, provide, reactive, watch } from 'vue'
import { useBlock, useModal } from '@opentiny/tiny-engine-meta-register'
import { SelectAll } from '@opentiny/tiny-engine-common'
import BlockList from './BlockList.vue'
import BlockGroupArrange from './BlockGroupArrange.vue'
import { Select, Option } from '@opentiny/vue'
Expand All @@ -35,6 +46,7 @@ export default {
components: {
BlockList,
BlockGroupArrange,
SelectAll,
TinySelect: Select,
TinyOption: Option
},
Expand All @@ -45,7 +57,7 @@ export default {
}
},
setup(props) {
const { cancelCheck, check, selectedBlockArray, sort } = useBlock()
const { check, cancelCheck, checkAll, cancelCheckAll, selectedBlockArray, sort } = useBlock()

const sortList = [
{
Expand Down Expand Up @@ -139,7 +151,9 @@ export default {
return {
state,
selectedBlockArray,
checkBlock
checkBlock,
checkAll,
cancelCheckAll
}
}
}
Expand All @@ -164,6 +178,9 @@ export default {
display: flex;
align-items: center;
justify-content: space-between;
.block-select-all {
margin-right: 20px;
}
.transfer-order-select {
width: 120px;
margin-left: 8px;
Expand Down
16 changes: 14 additions & 2 deletions packages/plugins/materials/src/meta/block/src/BlockList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@openVersionPanel="openVersionPanel"
@add="setBlockPanelVisible(true)"
@deleteBlock="deleteBlock"
@checkAll="(items) => checkAll(items)"
@cancelCheckAll="cancelCheckAll"
></plugin-block-list>
</template>

Expand Down Expand Up @@ -72,7 +74,7 @@ export default {
default: 2
}
},
emits: ['check', 'close'],
emits: ['check', 'close', 'checkAll', 'cancelCheckAll'],
setup(props, { emit }) {
const { generateNode, registerBlock } = useMaterial()
const { isDefaultGroupId, isAllGroupId, selectedBlock, selectedGroup, isRefresh, getBlockAssetsByVersion } =
Expand Down Expand Up @@ -196,6 +198,14 @@ export default {
confirm({ title, status, message: messageRender, exec })
}

const checkAll = (items) => {
emit('checkAll', items)
}

const cancelCheckAll = () => {
emit('cancelCheckAll')
}

return {
blockRef,
state,
Expand All @@ -204,7 +214,9 @@ export default {
closeDetail,
setBlockPanelVisible,
openVersionPanel,
deleteBlock
deleteBlock,
checkAll,
cancelCheckAll
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/theme/base/src/component-common.less
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@
// 15、checkbox 复选框适配
.tiny-checkbox.tiny-checkbox {
.tiny-checkbox__input {
&.is-checked .tiny-checkbox__inner {
&.is-checked .tiny-checkbox__inner,
&.is-indeterminate .tiny-checkbox__inner {
background-color: var(--te-common-bg-primary-checked);
border-color: var(--te-common-border-checked);
}
Expand Down
Loading