index.vue
2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<div class="go-tables-basic">
<n-input
v-model:value="inputData"
placeholder="请输入信息"
:style="`display: ${inputShow}`"
style="margin-bottom: 5px; float: right; width: 240px"
>
<template #prefix>
<n-icon :component="SearchIcon" />
</template>
</n-input>
<n-data-table
:style="`
width: ${w}px;
height: ${h}px;
font-size: ${option.style.fontSize}px;
border-width: ${option.style.border === 'on' ? option.style.borderWidth : 0}px;
border-color: ${option.style.borderColor};
border-style: ${option.style.borderStyle}`"
:bordered="option.style.border === 'on'"
:single-column="option.style.singleColumn === 'on'"
:single-line="option.style.singleLine === 'on'"
:bottom-bordered="option.style.bottomBordered === 'on'"
:striped="option.style.striped === 'on'"
:max-height="h"
size="small"
:columns="option.dataset.dimensions"
:data="filterData"
:pagination="pagination"
/>
</div>
</template>
<script setup lang="ts">
import { computed, PropType, toRefs, watch, reactive, ref } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { icon } from '@/plugins'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType>,
required: true
}
})
const { SearchIcon } = icon.ionicons5
//查询字段
const inputData = ref('')
//前台过滤
const filterData = computed(() => {
return option?.dataset?.source?.filter((item: any) => {
return Object.values(item).some(val => {
return String(val).toLowerCase().includes(inputData.value.toLowerCase())
})
})
})
const { align, pagination, inputShow } = toRefs(props.chartConfig.option)
pagination.value.onChange = (page: number) => {
pagination.value.page = page
}
const { w, h } = toRefs(props.chartConfig.attr)
const option = reactive({
dataset: props.chartConfig.option.dataset,
style: props.chartConfig.option.style
})
watch(
() => props.chartConfig.option.dataset,
(newData: any) => {
option.dataset = newData
option?.dataset?.dimensions?.forEach((header: any) => {
header.align = align.value
})
},
{
immediate: true,
deep: true
}
)
</script>
<style lang="scss" scoped>
@include go('tables-basic') {
display: flex;
flex-direction: column;
gap: 15px;
align-items: flex-end;
}
</style>