You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import { getCurrentInstance , inject , onMounted , onBeforeMount , ref , watch } from 'vue'
export function useCell() {
const border = ref < boolean > ( false ) // 是否展示边框
const cellGroup : any = inject ( 'cell-group' , null ) || { }
const cellList : any = inject ( 'cell-list' , null ) || ref < any [ ] > ( [ ] )
const { proxy } = getCurrentInstance ( ) as any
watch (
( ) = > cellGroup . border ,
( newVal ) = > {
setIndexAndStatus ( Boolean ( newVal ) , proxy . $ . uid )
} ,
{
deep : true ,
immediate : true
}
)
onBeforeMount ( ( ) = > {
cellList . value = [ . . . cellList . value . concat ( [ { uid : proxy.$.uid } ] ) ]
setIndexAndStatus ( cellGroup . border , proxy . $ . uid )
} )
/**
* @description 从cellGroup获取此组件的索引
* @return {Number} 此组件的索引
*/
function getIndex ( uuid : string ) {
if ( ! cellList || ! cellList . value ) return
return cellList . value . findIndex ( ( cell ) = > {
return cell . uid === uuid
} )
}
/**
* @description 为所有索引非0的组件设置刘海线, 此方法由cellGroup调用
*/
function setIndexAndStatus ( isBorder : boolean , uuid : string ) {
const index = getIndex ( uuid )
border . value = isBorder && index
}
return { border , cellGroup , cellList , setIndexAndStatus , getIndex }
}