el-plus-crud 0.0.78 → 0.0.80

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.
@@ -0,0 +1,47 @@
1
+ <template>
2
+ <el-table-column v-if="props.item.__vif" v-bind="columnAttr">
3
+ <template #header="{ column }: any">
4
+ <div :class="{ 'th-required': item.required }" :style="item.hstyle">
5
+ {{ column.label }}
6
+ </div>
7
+ </template>
8
+ <template #default="scope: any">
9
+ <!-- 递归 -->
10
+ <template v-if="item.children?.length">
11
+ <ElPlusTableColumn v-for="(child, i) in item.children" :item="child" :size="size" :key="i"></ElPlusTableColumn>
12
+ </template>
13
+ <template v-else>
14
+ <ColumnItem v-if="scope['$index'] >= 0" :field="item.prop" :desc="item" :scope="scope" :size="size" v-model="scope.row[item.prop as any]" />
15
+ </template>
16
+ </template>
17
+ </el-table-column>
18
+ </template>
19
+
20
+ <script lang="ts">
21
+ export default {
22
+ name: 'ElPlusTableColumn',
23
+ inheritAttrs: false,
24
+ customOptions: {}
25
+ }
26
+ </script>
27
+
28
+ <script lang="ts" setup>
29
+ import { computed } from 'vue'
30
+ import { IColumnItem } from 'types'
31
+ import ColumnItem from './components/columnItem.vue'
32
+ import { cloneDeep } from 'lodash'
33
+
34
+ const props = defineProps<{
35
+ item: IColumnItem
36
+ size: string
37
+ }>()
38
+
39
+ /**
40
+ * 绑定属性
41
+ */
42
+ const columnAttr = computed(() => {
43
+ const tempAttr = cloneDeep(props.item)
44
+ delete tempAttr.children
45
+ return tempAttr
46
+ })
47
+ </script>
@@ -19,7 +19,7 @@ import { IColumnItem } from 'types'
19
19
 
20
20
  const props = defineProps<{
21
21
  modelValue?: any
22
- field?: string
22
+ field?: string | ((data?: any) => string)
23
23
  desc: IColumnItem
24
24
  scope: { [key: string]: any }
25
25
  size?: string
@@ -35,7 +35,8 @@ const cells = computed(() => {
35
35
  _cells.push(handelItem(item.field || props.field, item, i))
36
36
  })
37
37
  } else {
38
- const porpList = props.field ? props.field.split(',') : ([] as string[])
38
+ const tempField = (typeof props.field === 'function' ? props.field() : props.field) || ''
39
+ const porpList = tempField.split(',')
39
40
  porpList.map((item, i) => {
40
41
  _cells.push(handelItem(item, props.desc, i))
41
42
  })
@@ -117,7 +118,8 @@ const handelItem = (prop: string, item: any, i: number) => {
117
118
  tempCell.desc.style = item.style || {}
118
119
 
119
120
  if (typeof item.color === 'function') {
120
- tempCell.desc.style.color = item.color(props.scope?.row[props.field || ''], props.scope?.row, props.field)
121
+ const tempField = (typeof props.field === 'function' ? props.field() : props.field) || ''
122
+ tempCell.desc.style.color = item.color(props.scope?.row[tempField], props.scope?.row, props.field)
121
123
  } else if (typeof item.color === 'string') {
122
124
  tempCell.desc.style.color = item.color
123
125
  } else {
@@ -1,180 +1,172 @@
1
- <template>
2
- <div class="el-plus-table-edit-column">
3
- <el-button v-if="showText" type="primary" @click="showSettingDialog" :size="size" plain>编辑显示列</el-button>
4
- <el-button v-else type="primary" icon="ele-Setting" @click="showSettingDialog" :size="size" title="编辑显示列" plain circle />
5
-
6
- <!-- 编辑列 -->
7
- <el-dialog title="编辑显示列" v-model="showSettingColumn" width="40%">
8
- <template #default>
9
- <div class="select-panel">
10
- <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="selectAll"> 全选 </el-checkbox>
11
- </div>
12
- <el-checkbox-group v-model="localColumn" @change="changeSelect" style="padding: 0 10px; flex-wrap: wrap; display: flex">
13
- <template v-for="item in props.column" :key="item.label">
14
- <el-checkbox v-if="item._vif" :label="item.label" :disabled="item.required || item.noHide || false">
15
- {{ item.label }}
16
- </el-checkbox>
17
- </template>
18
- </el-checkbox-group>
19
- </template>
20
- <template #footer>
21
- <div class="dialog-footer">
22
- <el-button :size="size" @click="handelCancel"> </el-button>
23
- <el-button :size="size" type="primary" @click="changeColumnData"> </el-button>
24
- </div>
25
- </template>
26
- </el-dialog>
27
- </div>
28
- </template>
29
- <script lang="ts" setup>
30
- import { ref, onMounted, inject } from 'vue'
31
- import { ElMessage } from 'element-plus'
32
- import { ICRUDConfig, IColumnItem } from 'types'
33
-
34
- const defaultConf = inject('defaultConf') as ICRUDConfig
35
-
36
- const props = defineProps<{
37
- column: Array<IColumnItem>
38
- tbName: string
39
- size: string
40
- showText?: boolean
41
- }>()
42
-
43
- const showSettingColumn = ref(false)
44
- const localColumn = ref([] as Array<String>)
45
- const localOldColumn = ref([] as Array<String>)
46
- const isIndeterminate = ref(false)
47
- const checkAll = ref(false)
48
-
49
- /**
50
- * 打开弹框
51
- */
52
- function showSettingDialog() {
53
- showSettingColumn.value = true
54
- }
55
-
56
- function changeColumnData() {
57
- if (localColumn.value.length <= 0) {
58
- ElMessage.warning('请至少选择一列!')
59
- return false
60
- }
61
- // 定义一个需要隐藏的列表-存储到本地用
62
- const hideList = [] as Array<String>
63
- props.column.map((item: any) => {
64
- if (localColumn.value.indexOf(item.label) < 0) {
65
- hideList.push(item.label)
66
- item.scShow = false
67
- } else {
68
- item.scShow = true
69
- }
70
- })
71
- if (hideList.length > 0) {
72
- localStorage.setItem(defaultConf.storagePrefix + 'hideColumnsList_' + props.tbName, hideList.join('__'))
73
- } else {
74
- // 如果是对象,删除
75
- localStorage.removeItem(defaultConf.storagePrefix + 'hideColumnsList_' + props.tbName)
76
- }
77
- showSettingColumn.value = false
78
- // 赋值
79
- localOldColumn.value = localColumn.value
80
- }
81
-
82
- /**
83
- * 全选列
84
- */
85
- function selectAll() {
86
- localColumn.value = [] as Array<String>
87
- if (checkAll.value) {
88
- localColumn.value = props.column.map((item: any) => item.label)
89
- } else {
90
- // 这里要屏蔽掉禁止勾选的项
91
- localColumn.value = props.column.filter((item) => item.required || item.noHide).map((item: any) => item.label)
92
- }
93
- isIndeterminate.value = false
94
- }
95
-
96
- /**
97
- * 复选框改变时触发
98
- */
99
- function changeSelect() {
100
- if (localColumn.value.length === 0) {
101
- isIndeterminate.value = false
102
- checkAll.value = false
103
- } else if (props.column.length === localColumn.value.length) {
104
- isIndeterminate.value = false
105
- checkAll.value = true
106
- } else {
107
- isIndeterminate.value = true
108
- checkAll.value = false
109
- }
110
- }
111
-
112
- /**
113
- * 初始化选择列
114
- * @param init
115
- */
116
- function initLocalCheckList(init?: Boolean) {
117
- // 从本地获取处理过的字段一级顺序
118
- const tempLocalStr = localStorage.getItem(defaultConf.storagePrefix + 'hideColumnsList_' + props.tbName) as String
119
- let tempList: any[] = []
120
-
121
- // 判断为空
122
- if (tempLocalStr !== undefined && tempLocalStr !== null && tempLocalStr.length > 0) {
123
- // 用两个下划线拆分
124
- tempList = tempLocalStr.split('__')
125
- }
126
- props.column.map((item: any) => {
127
- // 这里初始化一下vif
128
- if (item.vif !== undefined && item.vif !== null) {
129
- if (typeof item.vif === 'function') {
130
- item._vif = item.vif(item)
131
- } else {
132
- item._vif = !!item.vif
133
- }
134
- } else {
135
- item._vif = true
136
- }
137
- if (tempList.indexOf(item.label) < 0 || item.required || item.noHide) {
138
- localColumn.value.push(item.label)
139
- }
140
- })
141
-
142
- // 初始化的时候需要执行一次全选的状态校验
143
- changeSelect()
144
- if (init) {
145
- changeColumnData()
146
- }
147
- }
148
-
149
- /**
150
- * 取消
151
- */
152
- function handelCancel() {
153
- showSettingColumn.value = false
154
- // 还原
155
- localColumn.value = localOldColumn.value
156
- }
157
-
158
- onMounted(() => {
159
- if (props.tbName) {
160
- initLocalCheckList(true)
161
- }
162
- })
163
-
164
- defineExpose({ initCol: initLocalCheckList })
165
- </script>
166
- <style lang="scss" scoped>
167
- .el-plus-table-edit-column {
168
- margin: 0 10px;
169
- display: inline-block;
170
-
171
- .select-panel {
172
- width: 100%;
173
- height: 30px;
174
- padding: 0 10px;
175
- border-bottom: 1px solid #eee;
176
- margin-bottom: 10px;
177
- }
178
- }
179
- </style>
180
- types
1
+ <template>
2
+ <div class="el-plus-table-edit-column">
3
+ <el-button v-if="showText" type="primary" @click="showSettingDialog" :size="size" plain>编辑显示列</el-button>
4
+ <el-button v-else type="primary" icon="ele-Setting" @click="showSettingDialog" :size="size" title="编辑显示列" plain circle />
5
+
6
+ <!-- 编辑列 -->
7
+ <el-dialog title="编辑显示列" v-model="showSettingColumn" draggable width="40%">
8
+ <template #default>
9
+ <el-tree ref="treeRef" :data="options" show-checkbox node-key="idx" :default-expand-all="true" :default-checked-keys="checkColumn" :props="defaultProps" @check="handelCheckChange" />
10
+ </template>
11
+ <template #footer>
12
+ <div class="dialog-footer">
13
+ <el-button :size="size" @click="handelCancel"> 取 消 </el-button>
14
+ <el-button :size="size" type="primary" @click="changeColumnData"> </el-button>
15
+ </div>
16
+ </template>
17
+ </el-dialog>
18
+ </div>
19
+ </template>
20
+ <script lang="ts" setup>
21
+ import { ref, onMounted, inject, reactive } from 'vue'
22
+ import { ElMessage } from 'element-plus'
23
+ import { ICRUDConfig, IColumnItem } from 'types'
24
+
25
+ const defaultConf = inject('defaultConf') as ICRUDConfig
26
+
27
+ const props = defineProps<{
28
+ column: Array<IColumnItem>
29
+ tbName: string
30
+ size: string
31
+ showText?: boolean
32
+ }>()
33
+
34
+ // 弹框显示
35
+ const showSettingColumn = ref(false)
36
+ const treeRef = ref()
37
+
38
+ let options = ref([])
39
+
40
+ const treeAll = ref([] as Array<String>)
41
+ const checkColumn = ref([] as Array<String>)
42
+ // 定义一个需要隐藏的列表-存储到本地用
43
+ let tempList = ref([] as Array<String>)
44
+
45
+ const defaultProps = {
46
+ children: 'children',
47
+ label: 'label',
48
+ disabled: 'disabledcheckd'
49
+ }
50
+
51
+ /**
52
+ * 匹配序号并获取全部序号
53
+ */
54
+
55
+ function addIndex(item: any, index?: string) {
56
+ item.map((i: any, idx: number) => {
57
+ // 匹配序号
58
+ i.idx = index !== undefined ? `${index}-${idx}` : `${idx}`
59
+ // 禁用判断
60
+ if (i.required || i.noHide || i.disabled) {
61
+ i.disabledcheckd = true
62
+ tempList.value.splice(tempList.value.indexOf(i.idx), 1)
63
+ }
64
+ // 如果子集全部禁用,那么父级也禁用 ,如果父集禁用,那么子级也禁用
65
+ i.children && i.children.every((info: any) => info.disabled) ? (i.disabled = true) : i.children && i.disabled ? i.children.map((info: any) => (info.disabled = true)) : ''
66
+ // 是否有子集
67
+ if (i.children?.length > 0) {
68
+ addIndex(i.children, `${i.idx}`)
69
+ }
70
+ i.children ? '' : treeAll.value.push(i.idx)
71
+ })
72
+ return item
73
+ }
74
+
75
+ /**
76
+ * 打开弹框
77
+ */
78
+ function showSettingDialog() {
79
+ showSettingColumn.value = true
80
+ }
81
+
82
+ /**
83
+ * 获取没有选中的选项
84
+ */
85
+ function handelCheckChange(val: any, data: any) {
86
+ data.checkedAllKeys = Array.from(new Set([...data.checkedKeys, ...data.halfCheckedKeys]))
87
+ tempList.value = treeAll.value.filter((x) => {
88
+ return data.checkedAllKeys.indexOf(x) < 0
89
+ })
90
+ }
91
+
92
+ // 设置是否显示
93
+ function setShow(item: any) {
94
+ for (let index = 0; index < item.length; index++) {
95
+ if (item[index].children) {
96
+ setShow(item[index].children)
97
+ }
98
+ if (tempList.value.indexOf(item[index].idx) < 0) {
99
+ item[index].scShow = true
100
+ } else {
101
+ item[index].scShow = false
102
+ }
103
+ }
104
+ }
105
+
106
+ function changeColumnData() {
107
+ if (treeAll.value.length === tempList.value.length) {
108
+ ElMessage.warning('请至少选择一列!')
109
+ return false
110
+ }
111
+ setShow(props.column)
112
+ if (tempList.value.length > 0) {
113
+ localStorage.setItem(defaultConf.storagePrefix + 'hideColumnsList_' + props.tbName, tempList.value.join('__'))
114
+ } else {
115
+ localStorage.removeItem(defaultConf.storagePrefix + 'hideColumnsList_' + props.tbName)
116
+ }
117
+ showSettingColumn.value = false
118
+ }
119
+
120
+ /**
121
+ * 初始化选择列
122
+ * @param init
123
+ */
124
+ function initLocalCheckList() {
125
+ // 从本地获取处理过的字段一级顺序
126
+ const tempLocalStr = localStorage.getItem(defaultConf.storagePrefix + 'hideColumnsList_' + props.tbName) as String
127
+ // 判断为空
128
+ if (tempLocalStr !== undefined && tempLocalStr !== null && tempLocalStr.length > 0) {
129
+ // 用两个下划线拆分
130
+ tempList.value = tempLocalStr.split('__')
131
+ }
132
+ options.value = addIndex(props.column)
133
+
134
+ setShow(props.column)
135
+ // 过滤出隐藏的节点
136
+ checkColumn.value = treeAll.value.filter((x) => {
137
+ return tempList.value.indexOf(x) < 0
138
+ })
139
+ }
140
+
141
+ /**
142
+ * 取消
143
+ */
144
+ function handelCancel() {
145
+ // 还原
146
+ treeRef.value.setCheckedKeys(checkColumn.value)
147
+
148
+ showSettingColumn.value = false
149
+ }
150
+
151
+ onMounted(() => {
152
+ if (props.tbName) {
153
+ initLocalCheckList()
154
+ }
155
+ })
156
+
157
+ defineExpose({ initCol: initLocalCheckList })
158
+ </script>
159
+ <style lang="scss" scoped>
160
+ .el-plus-table-edit-column {
161
+ margin: 0 10px;
162
+ display: inline-block;
163
+
164
+ .select-panel {
165
+ width: 100%;
166
+ height: 30px;
167
+ padding: 0 10px;
168
+ border-bottom: 1px solid #eee;
169
+ margin-bottom: 10px;
170
+ }
171
+ }
172
+ </style>