@weitutech/by-components 1.0.27 → 1.0.30

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,219 +1,240 @@
1
- <template>
2
- <div>
3
- <vxe-grid
4
- ref="xGrid"
5
- v-bind="options"
6
- v-on="eventListeners"
7
- @cell-click="handleCellClick"
8
- >
9
- <template v-for="item in slotMap" #[item]="context">
10
- <slot :name="item" v-bind="context" />
11
- </template>
12
- <template v-if="options.pagerConfig" #pager>
13
- <!-- 📢 由于BPager利用的是ElementUi分页目前只支持vxeTable中分页配置中的currentPage、pageSize、total、pageSizes选项配置 -->
14
- <by-pager
15
- :page="options.pagerConfig.currentPage"
16
- :limit="options.pagerConfig.pageSize"
17
- :total-count="options.pagerConfig.total"
18
- :page-sizes="options.pagerConfig.pageSizes"
19
- @onChange="pageChange"
20
- />
21
- </template>
22
- </vxe-grid>
23
- <CustomColumn
24
- v-if="gridOptions.customColumnConfig && gridOptions.customColumnConfig.showCustomColumn"
25
- ref="CustomColumnRef"
26
- :info-method="gridOptions.customColumnConfig.infoMethod"
27
- :submit-method="gridOptions.customColumnConfig.submitMethod"
28
- :dialog-visible="customTableVisible"
29
- @closeDialog="closeCustomColumnDialog"
30
- @changeTable="changeTableFields"
31
- @changeTableGroup="changeTableGroupFields"
32
- />
33
- </div>
34
- </template>
35
-
36
- <script>
37
- import CustomColumn from "../custom-column/index.vue"
38
- export default {
39
- name: 'BYTable',
40
- components: {
41
- CustomColumn
42
- },
43
- props: {
44
- gridOptions: {
45
- type: Object,
46
- default: () => {}
47
- }
48
- },
49
- data() {
50
- return {
51
- /**
52
- * @see https://vxetable.cn/v3.8/#/grid/api
53
- */
54
- events: [
55
- "keydown", "current-change", "radio-change", "checkbox-change", "checkbox-all",
56
- "checkbox-range-start", "checkbox-range-change", "checkbox-range-end",
57
- "cell-dblclick", "cell-menu", "cell-mouseenter", "cell-mouseleave", "cell-delete-value",
58
- "header-cell-click", "header-cell-dblclick", "header-cell-menu", "footer-cell-click",
59
- "footer-cell-dblclick", "footer-cell-menu", "clear-merge", "sort-change", "clear-sort",
60
- "filter-visible", "filter-change", "clear-filter", "resizable-change", "toggle-row-expand",
61
- "toggle-tree-expand", "menu-click", "cell-selected", "edit-closed", "edit-activated", "edit-disabled",
62
- "valid-error", "scroll", "custom", "page-change", "form-submit", "form-submit-invalid", "form-reset",
63
- "form-collapse", "proxy-query", "proxy-delete", "proxy-save", "toolbar-button-click", "toolbar-tool-click",
64
- "zoom"
65
- ],
66
- customTableVisible: false
67
- }
68
- },
69
- computed: {
70
- options() {
71
- const { customColumnConfig, ...others } = this.gridOptions
72
- return {
73
- border: true,
74
- resizable: true,
75
- showOverflow: true,
76
- height: 550,
77
- align: "left",
78
- copyFields: [],
79
- pagerConfig: false,
80
- emptyText: "暂无数据",
81
- loadingConfig: {
82
- text: "加载中..."
83
- },
84
- ...others,
85
- resizableConfig: {
86
- minWidth: 50,
87
- ...this.gridOptions.resizableConfig
88
- },
89
- rowConfig: {
90
- height: 41,
91
- isHover: true,
92
- ...this.gridOptions.rowConfig
93
- },
94
- sortConfig: {
95
- remote: true,
96
- trigger: "cell",
97
- ...this.gridOptions.sortConfig
98
- }
99
- }
100
- },
101
- // 插槽集合
102
- slotMap() {
103
- const slotSet = new Set([])
104
- const slots = this.gridOptions?.customColumnConfig?.slots ?? []
105
- this.options.columns.forEach(col => {
106
- if (col.slots) {
107
- const slots = Object.values(col.slots)
108
- slots.forEach(slot => slotSet.add(slot))
109
- }
110
- })
111
- return [...Array.from(slotSet), ...slots]
112
- },
113
- // 注册emit事件
114
- eventListeners() {
115
- const listeners = {}
116
- this.events.forEach(eventName => {
117
- listeners[eventName] = (event) => this.$emit(eventName, event)
118
- })
119
- return listeners
120
- }
121
- },
122
- methods: {
123
- handleCellClick(context) {
124
- if (this.options.copyFields.includes(context.column.field)) {
125
- const text = context.cell.outerText
126
- this.copy(text)
127
- }
128
- this.$emit("cell-click", context)
129
- },
130
- pageChange(values) {
131
- this.$emit("page-change", values)
132
- },
133
- copy(text) {
134
- const oInput = document.createElement("input")
135
- oInput.value = text
136
- document.body.appendChild(oInput)
137
- oInput.select() // 选择对象;
138
- document.execCommand("Copy") // 执行浏览器复制命令
139
- this.$message({
140
- message: "复制成功",
141
- type: "success"
142
- })
143
- oInput.remove()
144
- },
145
- getCustomColumnRef() {
146
- return this.$refs.CustomColumnRef
147
- },
148
- handleOpenCustomColumn() {
149
- this.customTableVisible = true
150
- },
151
- // 改变表头字段
152
- changeTableFields(cols) {
153
- const columns = []
154
- cols.forEach(item => {
155
- if (!columns.some(col => col.field === item.key) && item.type) {
156
- columns.push(
157
- {
158
- field: item.key,
159
- title: item.label,
160
- minWidth: item.minWidth || item.width,
161
- maxWidth: item.maxWidth,
162
- sortable: typeof (item.sortable) === "undefined" ? true : JSON.parse(item.sortable),
163
- fixed: item.fixed,
164
- slots: this.gridOptions.customColumnConfig.slots.includes(item.key) ? { default: item.key } : undefined
165
- }
166
- )
167
- }
168
- })
169
- this.$emit("setColumn", columns)
170
- },
171
- // 多层级表头
172
- changeTableGroupFields(cols) {
173
- const recursiveData = (cols)=> {
174
- const arr = []
175
- cols.forEach((item,index)=> {
176
- if(item.data && item.data.length > 0) {
177
- arr.push({
178
- title: item.label,
179
- align: 'center',
180
- children: recursiveData(item.data)
181
- })
182
- if(index < cols.length - 1) {
183
- arr.push({
184
- title: '',
185
- width: 5,
186
- headerClassName: 'group-split',
187
- className: 'group-split',
188
- })
189
- }
190
- }else {
191
- if (!arr.some(col => col.field === item.key) && item.type) {
192
- arr.push({
193
- field: item.key,
194
- title: item.label,
195
- minWidth: item.minWidth || item.width,
196
- maxWidth: item.maxWidth,
197
- sortable: typeof (item.sortable) === "undefined" ? true : JSON.parse(item.sortable),
198
- fixed: item.fixed,
199
- slots: this.gridOptions.customColumnConfig.slots.includes(item.key) ? { default: item.key } : undefined
200
- })
201
- }
202
- }
203
- })
204
- return arr
205
- }
206
- this.$emit("setGroupColumn", recursiveData(cols))
207
- },
208
-
209
- // 关闭自定义表头弹框
210
- closeCustomColumnDialog() {
211
- this.customTableVisible = false
212
- }
213
- }
214
- }
215
- </script>
216
-
217
- <style lang="scss" scoped>
218
-
219
- </style>
1
+ <template>
2
+ <div>
3
+ <vxe-grid
4
+ ref="xGrid"
5
+ v-bind="options"
6
+ v-on="eventListeners"
7
+ @cell-click="handleCellClick"
8
+ @resizable-change="handleResizableChange"
9
+ >
10
+ <template v-for="item in slotMap" #[item]="context">
11
+ <slot :name="item" v-bind="context" />
12
+ </template>
13
+ <template v-if="options.pagerConfig" #pager>
14
+ <!-- 📢 由于BPager利用的是ElementUi分页目前只支持vxeTable中分页配置中的currentPage、pageSize、total、pageSizes选项配置 -->
15
+ <by-pager
16
+ :page="options.pagerConfig.currentPage"
17
+ :limit="options.pagerConfig.pageSize"
18
+ :total-count="options.pagerConfig.total"
19
+ :page-sizes="options.pagerConfig.pageSizes"
20
+ @onChange="pageChange"
21
+ />
22
+ </template>
23
+ </vxe-grid>
24
+ <CustomColumn
25
+ v-if="gridOptions.customColumnConfig && gridOptions.customColumnConfig.showCustomColumn"
26
+ ref="CustomColumnRef"
27
+ :info-method="gridOptions.customColumnConfig.infoMethod"
28
+ :submit-method="gridOptions.customColumnConfig.submitMethod"
29
+ :dialog-visible="customTableVisible"
30
+ @closeDialog="closeCustomColumnDialog"
31
+ @changeTable="changeTableFields"
32
+ @changeTableGroup="changeTableGroupFields"
33
+ />
34
+ </div>
35
+ </template>
36
+
37
+ <script>
38
+ import CustomColumn from "../custom-column/index.vue"
39
+ export default {
40
+ name: 'BYTable',
41
+ components: {
42
+ CustomColumn
43
+ },
44
+ props: {
45
+ gridOptions: {
46
+ type: Object,
47
+ default: () => {}
48
+ },
49
+ name: {
50
+ type: String,
51
+ default: ""
52
+ }
53
+ },
54
+ data() {
55
+ return {
56
+ /**
57
+ * @see https://vxetable.cn/v3.8/#/grid/api
58
+ */
59
+ events: [
60
+ "keydown", "current-change", "radio-change", "checkbox-change", "checkbox-all",
61
+ "checkbox-range-start", "checkbox-range-change", "checkbox-range-end",
62
+ "cell-dblclick", "cell-menu", "cell-mouseenter", "cell-mouseleave", "cell-delete-value",
63
+ "header-cell-click", "header-cell-dblclick", "header-cell-menu", "footer-cell-click",
64
+ "footer-cell-dblclick", "footer-cell-menu", "clear-merge", "sort-change", "clear-sort",
65
+ "filter-visible", "filter-change", "clear-filter", "toggle-row-expand",
66
+ "toggle-tree-expand", "menu-click", "cell-selected", "edit-closed", "edit-activated", "edit-disabled",
67
+ "valid-error", "scroll", "custom", "page-change", "form-submit", "form-submit-invalid", "form-reset",
68
+ "form-collapse", "proxy-query", "proxy-delete", "proxy-save", "toolbar-button-click", "toolbar-tool-click",
69
+ "zoom"
70
+ ],
71
+ // 自定义对话框显示和隐藏控制
72
+ customTableVisible: false
73
+ }
74
+ },
75
+ computed: {
76
+ options() {
77
+ const { customColumnConfig, columns, ...others } = this.gridOptions
78
+ const cols = JSON.parse(localStorage.getItem(this.name)) || undefined
79
+ if (cols && this.name) {
80
+ columns.forEach(item => {
81
+ item.width = (cols.find(col => col.field === item.field) || {}).width || undefined
82
+ })
83
+ }
84
+ return {
85
+ border: true,
86
+ resizable: true,
87
+ showOverflow: true,
88
+ height: 550,
89
+ align: "left",
90
+ copyFields: [],
91
+ pagerConfig: false,
92
+ emptyText: "暂无数据",
93
+ loadingConfig: {
94
+ text: "加载中..."
95
+ },
96
+ columns,
97
+ ...others,
98
+ resizableConfig: {
99
+ minWidth: 50,
100
+ ...this.gridOptions.resizableConfig
101
+ },
102
+ rowConfig: {
103
+ height: 41,
104
+ isHover: true,
105
+ ...this.gridOptions.rowConfig
106
+ },
107
+ sortConfig: {
108
+ remote: true,
109
+ trigger: "cell",
110
+ ...this.gridOptions.sortConfig
111
+ }
112
+ }
113
+ },
114
+ // 插槽集合
115
+ slotMap() {
116
+ const slotSet = new Set([])
117
+ const slots = this.gridOptions?.customColumnConfig?.slots ?? []
118
+ this.options.columns.forEach(col => {
119
+ if (col.slots) {
120
+ const slots = Object.values(col.slots)
121
+ slots.forEach(slot => slotSet.add(slot))
122
+ }
123
+ })
124
+ return [...Array.from(slotSet), ...slots]
125
+ },
126
+ // 注册emit事件
127
+ eventListeners() {
128
+ const listeners = {}
129
+ this.events.forEach(eventName => {
130
+ listeners[eventName] = (event) => this.$emit(eventName, event)
131
+ })
132
+ return listeners
133
+ }
134
+ },
135
+ methods: {
136
+ handleCellClick(context) {
137
+ if (this.options.copyFields.includes(context.column.field)) {
138
+ const text = context.cell.outerText
139
+ this.copy(text)
140
+ }
141
+ this.$emit("cell-click", context)
142
+ },
143
+ handleResizableChange(context) {
144
+ this.$emit("resizable-change", context)
145
+ if (!this.name) return
146
+ const collectColumn = context.$table.collectColumn
147
+ console.log(collectColumn, "collectColumn")
148
+ const clos = collectColumn.map(col => ({ field: col.field, width: col.renderWidth }))
149
+ localStorage.setItem(this.name, JSON.stringify(clos))
150
+ },
151
+ pageChange(values) {
152
+ this.$emit("page-change", values)
153
+ },
154
+ copy(text) {
155
+ const oInput = document.createElement("input")
156
+ oInput.value = text
157
+ document.body.appendChild(oInput)
158
+ oInput.select() // 选择对象;
159
+ document.execCommand("Copy") // 执行浏览器复制命令
160
+ this.$message({
161
+ message: "复制成功",
162
+ type: "success"
163
+ })
164
+ oInput.remove()
165
+ },
166
+ getCustomColumnRef() {
167
+ return this.$refs.CustomColumnRef
168
+ },
169
+ handleOpenCustomColumn() {
170
+ this.customTableVisible = true
171
+ },
172
+ // 改变表头字段
173
+ changeTableFields(cols) {
174
+ const columns = []
175
+ cols.forEach(item => {
176
+ if (!columns.some(col => col.field === item.key) && item.type) {
177
+ columns.push(
178
+ {
179
+ field: item.key,
180
+ title: item.label,
181
+ minWidth: item.minWidth || item.width,
182
+ maxWidth: item.maxWidth,
183
+ sortable: typeof (item.sortable) === "undefined" ? true : JSON.parse(item.sortable),
184
+ fixed: item.fixed,
185
+ slots: this.gridOptions.customColumnConfig.slots.includes(item.key) ? { default: item.key } : undefined
186
+ }
187
+ )
188
+ }
189
+ })
190
+ this.$emit("setColumn", columns)
191
+ },
192
+ // 多层级表头
193
+ changeTableGroupFields(cols) {
194
+ const recursiveData = (cols)=> {
195
+ const arr = []
196
+ cols.forEach((item,index)=> {
197
+ if(item.data && item.data.length > 0) {
198
+ arr.push({
199
+ title: item.label,
200
+ align: 'center',
201
+ children: recursiveData(item.data)
202
+ })
203
+ if(index < cols.length - 1) {
204
+ arr.push({
205
+ title: '',
206
+ width: 5,
207
+ headerClassName: 'group-split',
208
+ className: 'group-split',
209
+ })
210
+ }
211
+ }else {
212
+ if (!arr.some(col => col.field === item.key) && item.type) {
213
+ arr.push({
214
+ field: item.key,
215
+ title: item.label,
216
+ minWidth: item.minWidth || item.width,
217
+ maxWidth: item.maxWidth,
218
+ sortable: typeof (item.sortable) === "undefined" ? true : JSON.parse(item.sortable),
219
+ fixed: item.fixed,
220
+ slots: this.gridOptions.customColumnConfig.slots.includes(item.key) ? { default: item.key } : undefined
221
+ })
222
+ }
223
+ }
224
+ })
225
+ return arr
226
+ }
227
+ this.$emit("setGroupColumn", recursiveData(cols))
228
+ },
229
+
230
+ // 关闭自定义表头弹框
231
+ closeCustomColumnDialog() {
232
+ this.customTableVisible = false
233
+ }
234
+ }
235
+ }
236
+ </script>
237
+
238
+ <style lang="scss" scoped>
239
+
240
+ </style>
package/src/index.js CHANGED
@@ -1,31 +1,31 @@
1
- import ByPager from './components/pager/index'
2
- import ByTable from './components/table/index'
3
- import ByForm from './components/form/form'
4
- import ByPageSearch from './components/page-search/page-search'
5
- import ByFoldSearch from './components/fold-search/index'
6
- import BySelect from './components/form/comps/select.vue'
7
- import ByDatePickerRange from './components/form/comps/date-picker-range.vue'
8
- import domZindex from 'dom-zindex'
9
- const components = {
10
- ByPager,
11
- ByTable,
12
- ByForm,
13
- ByPageSearch,
14
- ByFoldSearch,
15
- BySelect,
16
- ByDatePickerRange
17
- }
18
- // 设置当前 z-index 起始值
19
- domZindex.setCurrent(99999)
20
-
21
- const install = (Vue) => {
22
- Object.keys(components).forEach(name => {
23
- Vue.component(name, components[name])
24
- })
25
- }
26
-
27
- // 支持直接通过 script 标签引入
28
- if (typeof window !== 'undefined' && window.Vue) {
29
- install(window.Vue)
30
- }
1
+ import ByPager from './components/pager/index'
2
+ import ByTable from './components/table/index'
3
+ import ByForm from './components/form/form'
4
+ import ByPageSearch from './components/page-search/page-search'
5
+ import ByFoldSearch from './components/fold-search/index'
6
+ import BySelect from './components/form/comps/select.vue'
7
+ import ByDatePickerRange from './components/form/comps/date-picker-range.vue'
8
+ import domZindex from 'dom-zindex'
9
+ const components = {
10
+ ByPager,
11
+ ByTable,
12
+ ByForm,
13
+ ByPageSearch,
14
+ ByFoldSearch,
15
+ BySelect,
16
+ ByDatePickerRange
17
+ }
18
+ // 设置当前 z-index 起始值
19
+ domZindex.setCurrent(99999)
20
+
21
+ const install = (Vue) => {
22
+ Object.keys(components).forEach(name => {
23
+ Vue.component(name, components[name])
24
+ })
25
+ }
26
+
27
+ // 支持直接通过 script 标签引入
28
+ if (typeof window !== 'undefined' && window.Vue) {
29
+ install(window.Vue)
30
+ }
31
31
  export default {install }