gy-ui-plus 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,170 +0,0 @@
1
- <template>
2
- <el-dropdown trigger="click" popper-class="column_set">
3
- <el-button v-bind="columnBind">{{ columnBind.btnTxt || "列设置" }}</el-button>
4
- <template #dropdown>
5
- <div class="title" v-if="columnBind.isShowTitle">{{ columnBind.title || "列设置" }}</div>
6
- <el-dropdown-menu>
7
- <el-dropdown-item :divided="columnBind.isShowTitle">
8
- <el-tree
9
- ref="treeRef"
10
- class="t_table_column_setting_dropdown"
11
- :data="state.columnSet"
12
- node-key="prop"
13
- :props="{ label: 'label', children: 'children', disabled: 'checkBoxDisabled' }"
14
- show-checkbox
15
- draggable
16
- default-expand-all
17
- check-strictly
18
- :allow-drag="allowDrag"
19
- :allow-drop="allowDrop"
20
- :default-checked-keys="defaultCheckedKeys"
21
- @check="onTreeCheck"
22
- @node-drop="handleDrop"
23
- >
24
- </el-tree>
25
- </el-dropdown-item>
26
- </el-dropdown-menu>
27
- </template>
28
- </el-dropdown>
29
- </template>
30
-
31
- <script setup lang="ts">
32
- import { watch, onMounted, reactive, computed, useAttrs, ref } from "vue"
33
- defineOptions({
34
- name: "ColumnSet"
35
- })
36
- export interface Column {
37
- label: string
38
- prop: string
39
- checkBoxDisabled?: boolean
40
- hidden?: boolean
41
- }
42
-
43
- export interface ColumnSetProps {
44
- columns: Column[]
45
- title?: string
46
- name?: string
47
- columnSetBind?: Record<string, any>
48
- }
49
-
50
- const props = withDefaults(defineProps<ColumnSetProps>(), {
51
- columns: () => [],
52
- title: "",
53
- name: "",
54
- columnSetBind: () => ({})
55
- })
56
- const treeRef = ref()
57
- const $attrs: any = useAttrs()
58
- const columnBind = computed(() => {
59
- const columnSetBind = { btnTxt: "列设置", title: "列设置", ...props.columnSetBind }
60
- return { size: "default", icon: "Setting", isShowTitle: true, ...$attrs, ...columnSetBind }
61
- })
62
-
63
- const emits = defineEmits(["columnSetting"])
64
- const state = reactive({
65
- columnSet: [] as Column[]
66
- })
67
- const defaultCheckedKeys = ref<string[]>([])
68
-
69
- const getColumnSetCache = () => {
70
- let value =
71
- localStorage.getItem(`t-ui-plus:TTable.columnSet-${props.name || props.title}`) || "[]"
72
- let columnOption = initColumnSet()
73
- let valueArr = (JSON.parse(value) as any[]) || []
74
- columnOption.forEach(item => {
75
- let findEle = valueArr.find(
76
- (ele: { label: any; prop: any }) => ele.label === item.label && ele.prop === item.prop
77
- )
78
- item.hidden = findEle ? findEle.hidden : false
79
- })
80
- value = JSON.stringify(valueArr.length ? valueArr : columnOption)
81
- return value ? JSON.parse(value) : initColumnSet()
82
- }
83
- const initColumnSet = () => {
84
- return props.columns.map((col: any) => ({
85
- label: col.label,
86
- prop: col.prop,
87
- checkBoxDisabled: false,
88
- hidden: false
89
- }))
90
- }
91
-
92
- onMounted(() => {
93
- state.columnSet = getColumnSetCache()
94
- defaultCheckedKeys.value = state.columnSet.filter(c => !c.hidden).map(c => c.prop)
95
- emits("columnSetting", state.columnSet)
96
- })
97
-
98
- watch(
99
- () => state.columnSet,
100
- val => {
101
- emits("columnSetting", val)
102
- localStorage.setItem(
103
- `t-ui-plus:TTable.columnSet-${props.name || props.title}`,
104
- JSON.stringify(val)
105
- )
106
- defaultCheckedKeys.value = state.columnSet.filter(c => !c.hidden).map(c => c.prop)
107
- },
108
- { deep: true }
109
- )
110
-
111
- const reSetColumnSet = () => {
112
- let value: any = localStorage.getItem(`t-ui-plus:TTable.columnSet-${props.name || props.title}`)
113
- state.columnSet = JSON.parse(value)
114
- defaultCheckedKeys.value = state.columnSet.filter(c => !c.hidden).map(c => c.prop)
115
- emits("columnSetting", state.columnSet)
116
- }
117
-
118
- const onTreeCheck = () => {
119
- // 获取最新勾选的key
120
- const checkedKeys = treeRef.value?.getCheckedKeys() || []
121
- state.columnSet.forEach(col => {
122
- col.hidden = !checkedKeys.includes(col.prop)
123
- })
124
- // 至少保留一个可见列
125
- const visibleCols = state.columnSet.filter(col => !col.hidden)
126
- if (visibleCols.length < 2) {
127
- visibleCols.forEach(col => (col.checkBoxDisabled = true))
128
- } else {
129
- state.columnSet.forEach(col => (col.checkBoxDisabled = false))
130
- }
131
- }
132
- // 限制拖拽结点
133
- const allowDrag = () => {
134
- return true
135
- }
136
- const allowDrop = (draggingNode: any, dropNode: any, type: any) => {
137
- // 只允许同级节点之间的拖拽
138
- if (draggingNode.level !== dropNode.level) {
139
- return false
140
- }
141
- // 如果是同级节点,还需要判断是否是前后节点的拖拽
142
- if (type !== "prev" && type !== "next") {
143
- return false
144
- }
145
- return true
146
- }
147
- // 拖拽排序
148
- const handleDrop = (draggingNode: any, dropNode: any, dropType: string, ev: Event) => {
149
- // 只允许拖拽到同级(禁止拖为子级)
150
- if (dropType === "inner") {
151
- ev.preventDefault()
152
- return
153
- }
154
- const draggingIndex = state.columnSet.findIndex(col => col.prop === draggingNode.data.prop)
155
- const dropIndex = state.columnSet.findIndex(col => col.prop === dropNode.data.prop)
156
- if (draggingIndex === -1 || dropIndex === -1) return
157
- const item = state.columnSet.splice(draggingIndex, 1)[0]
158
- if (dropType === "before") {
159
- // 如果拖拽项在目标项后面,直接插入;如果在前面,dropIndex要减1
160
- const insertIndex = draggingIndex < dropIndex ? dropIndex - 1 : dropIndex
161
- state.columnSet.splice(insertIndex, 0, item)
162
- } else if (dropType === "after") {
163
- state.columnSet.splice(dropIndex + 1, 0, item)
164
- }
165
- }
166
-
167
- defineExpose({
168
- reSetColumnSet
169
- })
170
- </script>
@@ -1,100 +0,0 @@
1
- <template>
2
- <el-table-column
3
- v-if="typeof item.isShowCol == 'function' ? item.isShowCol(item) : !item.isShowCol"
4
- :prop="item.prop"
5
- :label="item.label"
6
- :type="item.type"
7
- :align="item.align || align"
8
- :min-width="item['min-width'] || item.minWidth"
9
- :width="item.width"
10
- :fixed="item.fixed"
11
- >
12
- <template #header v-if="item.renderHeader">
13
- <render-header :column="item" :render="item.renderHeader" />
14
- </template>
15
- <template v-for="(val, index) of item.children">
16
- <gy-table-column v-if="val.children" :key="index" :item="val" v-bind="$attrs">
17
- <template v-for="(_index, name) in slots" v-slot:[name]="data">
18
- <slot :name="name" v-bind="data"></slot>
19
- </template>
20
- </gy-table-column>
21
- <el-table-column
22
- v-else
23
- :key="val.prop"
24
- :prop="val.prop"
25
- :label="val.label"
26
- :min-width="val['min-width'] || val.minWidth"
27
- :width="val.width"
28
- :sortable="val.sortable || val.sort || sortable"
29
- :align="val.align || align"
30
- :fixed="val.fixed"
31
- :formatter="val.formatter"
32
- v-if="typeof val.isShowCol == 'function' ? val.isShowCol(val) : !val.isShowCol"
33
- v-bind="{ 'show-overflow-tooltip': true, ...val.bind, ...$attrs }"
34
- >
35
- <template #header v-if="val.renderHeader">
36
- <render-header :column="val" :render="val.renderHeader" />
37
- </template>
38
- <template #default="scope">
39
- <!-- render渲染 -->
40
- <template v-if="val.render">
41
- <render-col :column="val" :row="scope.row" :render="val.render" :index="scope.$index" />
42
- </template>
43
- <!-- 自定义插槽 -->
44
- <template v-if="val.slotNameMerge">
45
- <slot :name="val.slotNameMerge" :scope="scope"></slot>
46
- </template>
47
- <!-- 单个单元格编辑 -->
48
- <template v-if="val.canEdit">
49
- <single-edit-cell
50
- :isShowRules="false"
51
- :configEdit="val.configEdit"
52
- v-model="scope.row[val.prop]"
53
- :prop="val.prop"
54
- :scope="scope"
55
- @handleEvent="({ type, val }:any) => emits('handleEvent', type, val, scope.$index)"
56
- v-bind="$attrs"
57
- >
58
- <template v-for="(_index, name) in slots" v-slot:[name]="data">
59
- <slot :name="name" v-bind="data"></slot>
60
- </template>
61
- </single-edit-cell>
62
- </template>
63
- <div v-if="!val.render && !val.slotNameMerge && !val.canEdit && !val.formatter">
64
- {{ scope.row[val.prop] }}
65
- </div>
66
- </template>
67
- </el-table-column>
68
- </template>
69
- </el-table-column>
70
- </template>
71
-
72
- <script setup lang="tsx">
73
- import SingleEditCell from './singleEditCell.vue'
74
- import RenderCol from './renderCol.vue'
75
- import RenderHeader from './renderHeader.vue'
76
- import { useSlots } from 'vue'
77
- defineOptions({
78
- name: 'GyTableColumn',
79
- })
80
- defineProps({
81
- item: {
82
- type: Object,
83
- default: () => {
84
- return {}
85
- },
86
- required: true,
87
- },
88
- align: {
89
- type: String,
90
- default: 'center',
91
- },
92
- sortable: {
93
- type: [Boolean, String],
94
- },
95
- })
96
- // 抛出事件
97
- const emits = defineEmits(['handleEvent'])
98
- // 获取所有插槽
99
- const slots = useSlots()
100
- </script>