更新:登录功能
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
@import '../common/abstracts/variable';
|
||||
@import '../common/abstracts/mixin';
|
||||
|
||||
@import '../wd-table/index';
|
||||
|
||||
.wot-theme-dark {
|
||||
@include b(table-col) {
|
||||
@include when(shadow) {
|
||||
&::after {
|
||||
background: linear-gradient(270deg, rgba(17, 17, 17, 0.2) 0%, rgba(0, 0, 0, 0) 100%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@include b(table-col) {
|
||||
.wd-table__cell {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@include m(fixed) {
|
||||
position: sticky;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
@include when(shadow) {
|
||||
&::after {
|
||||
content: ' ';
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
right: -30rpx;
|
||||
top: 0;
|
||||
width: 30rpx;
|
||||
height: 100%;
|
||||
background: linear-gradient(270deg, rgba(255, 255, 255, 0) 0%, rgba(0, 0, 0, 0.04) 100%);
|
||||
}
|
||||
}
|
||||
|
||||
.wd-table__cell:last-child {
|
||||
@include when(border) {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
uni_modules/wot-design-uni/components/wd-table-col/types.ts
Normal file
54
uni_modules/wot-design-uni/components/wd-table-col/types.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import type { ComponentPublicInstance, ExtractPropTypes } from 'vue'
|
||||
import { makeBooleanProp, makeNumericProp, makeRequiredProp, makeStringProp } from '../common/props'
|
||||
|
||||
export type AlignType = 'left' | 'center' | 'right' // 列的对齐方式
|
||||
|
||||
export type SortDirection = 0 | 1 | -1 // 列的排序方向
|
||||
|
||||
export interface TableColumn {
|
||||
// 列对应字段
|
||||
prop: string
|
||||
// 列对应字段标题
|
||||
label: string
|
||||
// 列宽度
|
||||
width: string | number
|
||||
// 是否开启列排序
|
||||
sortable?: boolean
|
||||
// 列的对齐方式,可选值left,center,right
|
||||
align?: AlignType
|
||||
// 列的排序方向
|
||||
sortDirection: SortDirection
|
||||
// 是否i固定列
|
||||
fixed?: boolean
|
||||
}
|
||||
|
||||
export const tableColumnProps = {
|
||||
/**
|
||||
* 列对应字段
|
||||
*/
|
||||
prop: makeRequiredProp(String),
|
||||
/**
|
||||
* 列对应字段标题
|
||||
*/
|
||||
label: makeRequiredProp(String),
|
||||
/**
|
||||
* 列宽度,单位px
|
||||
*/
|
||||
width: makeNumericProp(100),
|
||||
/**
|
||||
* 是否开启列排序
|
||||
*/
|
||||
sortable: makeBooleanProp(false),
|
||||
/**
|
||||
* 是否固定本列
|
||||
*/
|
||||
fixed: makeBooleanProp(false),
|
||||
/**
|
||||
* 列的对齐方式,可选值left,center,right
|
||||
*/
|
||||
align: makeStringProp<AlignType>('left')
|
||||
}
|
||||
|
||||
export type TableColumnProps = ExtractPropTypes<typeof tableColumnProps>
|
||||
|
||||
export type TableColumnInstance = ComponentPublicInstance<TableColumnProps>
|
||||
@@ -0,0 +1,149 @@
|
||||
<template>
|
||||
<view
|
||||
:class="`wd-table-col ${fixed ? 'wd-table-col--fixed' : ''} ${isLastFixed && isDef(table) && table.state.scrollLeft ? 'is-shadow' : ''}`"
|
||||
:style="columnStyle"
|
||||
>
|
||||
<view
|
||||
:class="`wd-table__cell ${stripe && isOdd(index) ? 'is-stripe' : ''} ${border ? 'is-border' : ''} is-${align}`"
|
||||
v-for="(row, index) in column"
|
||||
:key="index"
|
||||
:style="cellStyle"
|
||||
@click="handleRowClick(index)"
|
||||
>
|
||||
<slot name="value" v-if="$slots.value" :row="getScope(index)" :index="index"></slot>
|
||||
<text :class="`wd-table__value ${ellipsis ? 'is-ellipsis' : ''}`" v-else>{{ row }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'wd-table-col',
|
||||
options: {
|
||||
addGlobalClass: true,
|
||||
virtualHost: true,
|
||||
styleIsolation: 'shared'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script lang="ts" setup>
|
||||
import { type CSSProperties, computed, ref } from 'vue'
|
||||
import { addUnit, isDef, objToStyle, isOdd, isFunction } from '../common/util'
|
||||
import { tableColumnProps, type SortDirection } from './types'
|
||||
import { useParent } from '../composables/useParent'
|
||||
import { TABLE_KEY } from '../wd-table/types'
|
||||
|
||||
const props = defineProps(tableColumnProps)
|
||||
|
||||
const { parent: table, index: columnIndex } = useParent(TABLE_KEY)
|
||||
|
||||
const sortDirection = ref<SortDirection>(0) // 排序方向
|
||||
|
||||
// 是否开启斑马纹
|
||||
const stripe = computed(() => {
|
||||
if (isDef(table)) {
|
||||
return table.props.stripe
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 是否有边框
|
||||
*/
|
||||
const border = computed(() => {
|
||||
if (isDef(table)) {
|
||||
return table.props.border
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 是否超出省略
|
||||
*/
|
||||
const ellipsis = computed(() => {
|
||||
if (isDef(table)) {
|
||||
return table.props.ellipsis
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 是否最后一个固定元素
|
||||
*/
|
||||
const isLastFixed = computed(() => {
|
||||
let isLastFixed: boolean = false
|
||||
if (props.fixed && isDef(table)) {
|
||||
isLastFixed = table.getIsLastFixed(props)
|
||||
}
|
||||
return isLastFixed
|
||||
})
|
||||
|
||||
/**
|
||||
* 列样式
|
||||
*/
|
||||
const columnStyle = computed(() => {
|
||||
let style: CSSProperties = {}
|
||||
if (isDef(props.width)) {
|
||||
style['width'] = addUnit(props.width)
|
||||
}
|
||||
if (props.fixed && isDef(table) && isFunction(table.getFixedStyle)) {
|
||||
style = table.getFixedStyle(columnIndex.value, style)
|
||||
}
|
||||
return style
|
||||
})
|
||||
|
||||
/**
|
||||
* 单元格样式
|
||||
*/
|
||||
const cellStyle = computed(() => {
|
||||
let style: CSSProperties = {}
|
||||
const rowHeight: string | number = isDef(table) && isDef(table.props) ? table.props.rowHeight : 50 // 自定义行高
|
||||
if (isDef(rowHeight)) {
|
||||
style['height'] = addUnit(rowHeight)
|
||||
}
|
||||
if (props.fixed && isDef(table) && isFunction(table.getFixedStyle)) {
|
||||
style = table.getFixedStyle(columnIndex.value, style)
|
||||
}
|
||||
return objToStyle(style)
|
||||
})
|
||||
|
||||
// 列数据
|
||||
const column = computed(() => {
|
||||
if (!isDef(table) || !isDef(table.props) || !isDef(table.props.data) || !Array.isArray(table.props.data)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const column: any[] = table.props.data.map((item) => {
|
||||
return item[props.prop]
|
||||
})
|
||||
return column
|
||||
})
|
||||
|
||||
/**
|
||||
* 行点击事件
|
||||
* @param index 行下标
|
||||
*/
|
||||
function handleRowClick(index: number) {
|
||||
if (!isDef(table)) {
|
||||
return
|
||||
}
|
||||
isFunction(table.rowClick) && table.rowClick(index)
|
||||
}
|
||||
|
||||
// 行数据
|
||||
function getScope(index: number) {
|
||||
if (!isDef(table) || !isDef(table.props) || !isDef(table.props.data) || !Array.isArray(table.props.data)) {
|
||||
return {}
|
||||
}
|
||||
return table.props.data[index] || {}
|
||||
}
|
||||
|
||||
defineExpose({ sortDirection: sortDirection })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './index.scss';
|
||||
</style>
|
||||
Reference in New Issue
Block a user