refactor: 审批支持框选

bak
elseif 2 years ago
parent c3be5f3ca7
commit f1691d506c

@ -144,15 +144,18 @@ function downHandler(event: MouseEvent) {
if (!selectionBox) if (!selectionBox)
return return
selectIds.value.length = 0 const classname = (event.target as any).className
start = { x: event.clientX, y: event.clientY } if (!classname.includes('checkbox')) {
selectionBox.style.width = '0' selectIds.value.length = 0
selectionBox.style.height = '0' start = { x: event.clientX, y: event.clientY }
selectionBox.style.left = `${start.x}px` selectionBox.style.width = '0'
selectionBox.style.top = `${start.y}px` selectionBox.style.height = '0'
selectionBox.style.display = 'block' selectionBox.style.left = `${start.x}px`
selectionBox.style.zIndex = '9999' selectionBox.style.top = `${start.y}px`
selectionBox.style.display = 'block'
selectionBox.style.zIndex = '9999'
}
} }
function imUpdateSelectIds(x: number, y: number, w: number, h: number) { function imUpdateSelectIds(x: number, y: number, w: number, h: number) {
@ -238,6 +241,12 @@ function closeModal(event: MouseEvent) {
defineExpose({ defineExpose({
showModal, showModal,
}) })
const checked = ref(false)
function onCheckChange(val: any, item: any) {
checked.value = val
console.log('onCheckChange')
}
</script> </script>
<template> <template>
@ -295,6 +304,11 @@ defineExpose({
class="wrapper-content-item-img" class="wrapper-content-item-img"
:class="{ 'wrapper-content-item-img-fit': viewMode !== 'masonry' }" :src="item.imgUrl" :class="{ 'wrapper-content-item-img-fit': viewMode !== 'masonry' }" :src="item.imgUrl"
> >
<n-checkbox
v-model:checked="item.checked"
style="position:absolute;left:20px;top:20px" @click.prevent
@update:checked="onCheckChange($event, item)"
/>
</div> </div>
</div> </div>
<!-- </n-scrollbar> --> <!-- </n-scrollbar> -->
@ -421,6 +435,7 @@ defineExpose({
.scroll { .scroll {
overflow-y: scroll; overflow-y: scroll;
height: calc(100vh - 282px); height: calc(100vh - 282px);
background-color: aqua;
} }
} }
} }

@ -1,5 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onMounted, onUnmounted, onUpdated, reactive, ref, watch } from 'vue' import { computed, onMounted, onUpdated, reactive, ref, watch } from 'vue'
import Masonry from 'masonry-layout' import Masonry from 'masonry-layout'
import { useInfiniteScroll } from '@vueuse/core' import { useInfiniteScroll } from '@vueuse/core'
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
@ -56,6 +56,7 @@ const sortBy: PictureSortParam = {
orderbyname: 'asc', orderbyname: 'asc',
orderbyvalue: 'fromuptime', orderbyvalue: 'fromuptime',
} }
const batch = ref(false)
const layout = debounce(() => { const layout = debounce(() => {
if (!show.value) if (!show.value)
@ -135,23 +136,25 @@ onUpdated(() => {
let start: { x: number, y: number } | null = null let start: { x: number, y: number } | null = null
let selectionBox: HTMLDivElement | null let selectionBox: HTMLDivElement | null
const selectIds = ref<string[]>([]) const selectIds = ref<string[]>([])
const selectItems = ref<any[]>([])
function downHandler(event: MouseEvent) { function downHandler(event: MouseEvent) {
event.stopPropagation() event.stopPropagation()
if (!selectionBox) if (!selectionBox || batch.value === false)
return return
selectIds.value.length = 0 const classname = (event.target as any).className
start = { x: event.clientX, y: event.clientY } if (!classname.includes('checkbox')) {
selectionBox.style.width = '0' selectIds.value.length = 0
selectionBox.style.height = '0' start = { x: event.clientX, y: event.clientY }
selectionBox.style.left = `${start.x}px` selectionBox.style.width = '0'
selectionBox.style.top = `${start.y}px` selectionBox.style.height = '0'
selectionBox.style.display = 'block' selectionBox.style.left = `${start.x}px`
selectionBox.style.zIndex = '9999' selectionBox.style.top = `${start.y}px`
selectionBox.style.display = 'block'
selectionBox.style.zIndex = '9999'
}
} }
function imUpdateSelectIds(x: number, y: number, w: number, h: number) { function imUpdateSelectIds(x: number, y: number, w: number, h: number) {
@ -168,7 +171,7 @@ function imUpdateSelectIds(x: number, y: number, w: number, h: number) {
} }
function moveHandler(e: MouseEvent) { function moveHandler(e: MouseEvent) {
if (!selectionBox || !start) if (!selectionBox || !start || batch.value === false)
return return
const x = Math.min(e.clientX, start.x) const x = Math.min(e.clientX, start.x)
@ -197,39 +200,30 @@ const gridHeight = computed(() => {
}) })
function addListeners() { function addListeners() {
// selectionBox = document.querySelector('.selection-box') as HTMLDivElement selectionBox = document.querySelector('.selection-box') as HTMLDivElement
// on(el.value!, 'mousedown', downHandler) on(el.value!, 'mousedown', downHandler)
// on(el.value!, 'mousemove', moveHandler) on(el.value!, 'mousemove', moveHandler)
// on(document, 'mouseup', upHandler) on(document, 'mouseup', upHandler)
emitter.on('refresh', refreshHandler) emitter.on('refresh', refreshHandler)
} }
function removeListeners() { function removeListeners() {
// off(el.value!, 'mousedown', downHandler) off(el.value!, 'mousedown', downHandler)
// on(el.value!, 'mousemove', moveHandler) on(el.value!, 'mousemove', moveHandler)
// on(document, 'mouseup', upHandler) on(document, 'mouseup', upHandler)
emitter.off('refresh', refreshHandler) emitter.off('refresh', refreshHandler)
} }
async function afterEnter() { async function afterEnter() {
addListeners() addListeners()
refreshHandler()
const packageid = taskStore.getPackageid
const taskId = taskStore.getActiveId
taskDetailInfo.value = await getTaskDetailInfo(taskId, packageid)
const list = await featchList()
listData.value = list
} }
function afterLeave() { function afterLeave() {
removeListeners() removeListeners()
pagination.pageNo = 1
pagination.pageSize = 30
} }
onMounted(() => { onMounted(() => {
@ -257,57 +251,48 @@ function backHandler() {
} }
function onCheckChange(checked: any, item: any) { function onCheckChange(checked: any, item: any) {
const index = selectItems.value.indexOf(item) const index = selectIds.value.indexOf(item.id)
item.checked = checked
if (index === -1 && checked) if (index === -1 && checked)
selectItems.value.push(item) selectIds.value.push(item.id)
else else
selectItems.value.splice(index, 1) selectIds.value.splice(index, 1)
} }
// watch(() => selectIds.value.length, () => { watch(() => selectIds.value.length, () => {
// const list = listData.value const list = listData.value
// for (const item of list) { for (const item of list) {
// if (selectIds.value.includes(item.id)) if (selectIds.value.includes(item.id))
// item.checked = true item.checked = true
// else else
// item.checked = false item.checked = false
// } }
// }) })
const batch = ref(false)
const showActions = computed(() => { const showActions = computed(() => {
return selectItems.value.length > 0 && batch return selectIds.value.length > 0 && batch
}) })
function setBatch(value: boolean) { function setBatch(value: boolean) {
batch.value = value batch.value = value
if (value === false) { if (value === false)
selectItems.value.forEach(item => item.checked = false) selectIds.value.length = 0
selectItems.value.length = 0
}
} }
function reject() { function reject() {
emit('reject', selectItems.value) emit('reject', getSelectItems())
} }
function approval() { function approval() {
emit('approval', selectItems.value) emit('approval', getSelectItems())
} }
async function refreshHandler() { function getSelectItems() {
pagination.pageNo = 1 return listData.value.filter(item => selectIds.value.includes(item.id))
pagination.pageSize = 30
const list = await featchList()
listData.value = list
} }
watch(() => taskStore.activeId, async (newValue, oldValue) => { async function refreshHandler() {
const packageid = taskStore.getPackageid const packageid = taskStore.getPackageid
const taskId = taskStore.getActiveId const taskId = taskStore.getActiveId
taskDetailInfo.value = await getTaskDetailInfo(taskId, packageid) taskDetailInfo.value = await getTaskDetailInfo(taskId, packageid)
@ -319,6 +304,10 @@ watch(() => taskStore.activeId, async (newValue, oldValue) => {
const list = await featchList() const list = await featchList()
listData.value = list listData.value = list
layout() layout()
}
watch(() => taskStore.activeId, async (newValue, oldValue) => {
refreshHandler()
}) })
</script> </script>

Loading…
Cancel
Save