@lambo-design/schema-paging-table 1.0.0-beta.5 → 1.0.0-beta.51

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.
Files changed (2) hide show
  1. package/package.json +14 -6
  2. package/src/index.vue +620 -368
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/schema-paging-table",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.51",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -10,10 +10,18 @@
10
10
  "registry": "https://registry.npmjs.org/"
11
11
  },
12
12
  "devDependencies": {
13
- "@lambo-design/shared": "^1.0.0-beta.93",
14
- "@lambo-design/core": "^4.7.1-beta.103",
15
- "@lambo-design/paging-table": "^1.0.0-beta.69",
16
- "@lambo-design/schema-form": "^1.0.0-beta.25"
13
+ "standard-version": "^9.5.0",
14
+ "@lambo-design/core": "^4.7.1-beta.146",
15
+ "@lambo-design/shared": "^1.0.0-beta.222",
16
+ "@lambo-design/paging-table": "^1.0.0-beta.86",
17
+ "@lambo-design/schema-form": "^1.0.0-beta.73"
17
18
  },
18
- "scripts": {}
19
+ "scripts": {
20
+ "release": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
21
+ "release-major": "standard-version --release-as major",
22
+ "release-minor": "standard-version --release-as minor",
23
+ "release-patch": "standard-version --release-as patch",
24
+ "release-beta": "standard-version --prerelease beta",
25
+ "re-publish": "pnpm publish --access public --no-git-checks"
26
+ }
19
27
  }
package/src/index.vue CHANGED
@@ -1,368 +1,620 @@
1
- <template>
2
- <LamboPagingTable
3
- ref="schemaPagingTable"
4
- :dataUrl="dataUrl"
5
- :columns="tableColumn"
6
- :searchParams="tableSearchParams"
7
- :transformResponse="transformResponse"
8
- @on-row-click="onRowClick"
9
- @on-selection-change="onSelectionChange"
10
- @on-select="onSelect"
11
- @on-select-cancel="onSelectCancel"
12
- @on-select-all="onSelectAll"
13
- @on-select-all-cancel="onSelectAllCancel">
14
- <div slot="search">
15
- <LamboSchemaForm
16
- ref="lamboSchemaForm"
17
- v-model="queryForm"
18
- :form-type="'search'"
19
- :fieldList="formFields"
20
- :labelWidth="100"
21
- :customComponents="customComponents"
22
- :customValidates="customValidates"
23
- @doSearch="doSearch" @reset="onReset"/>
24
- <div v-if="rowName" class="tags">
25
- <Tag v-for="item in selectTags" :key="item.key" :name="item.key" closable @on-close="tagClose">
26
- {{ item.value }}
27
- </Tag>
28
- </div>
29
- </div>
30
- <div slot="buttons">
31
- <Button
32
- v-if="spreadButton.length > 0"
33
- v-for="(item,index) in spreadButton"
34
- type="primary"
35
- :ghost="true"
36
- :icon="item.icon"
37
- v-permission="item.permission"
38
- :key="index"
39
- @click="doClick(item)"
40
- style="margin-right: 5px">
41
- {{ item.name }}
42
- </Button>
43
- <Dropdown v-if="dropDownButton.length > 0">
44
- <Button type="primary" :ghost="true" icon="md-more">
45
- 更多操作
46
- <Icon type="ios-arrow-down"></Icon>
47
- </Button>
48
- <DropdownMenu slot="list">
49
- <DropdownItem
50
- v-for="(item,index) in dropDownButton"
51
- v-permission="item.permission"
52
- :key="index"
53
- >
54
- <Icon :type="item.icon" style="margin-right: 5px"></Icon>
55
- <span @click="doClick(item)">{{ item.name }}</span>
56
- </DropdownItem>
57
- </DropdownMenu>
58
- </Dropdown>
59
- </div>
60
- </LamboPagingTable>
61
- </template>
62
- <script>
63
- import ajax from '@lambo-design/shared/utils/ajax'
64
- import { operateBtn, operateHref } from '@lambo-design/shared/utils/assist'
65
- import LamboPagingTable from '@lambo-design/paging-table'
66
- // import LamboSchemaForm from '@lambo-design/schema-form'
67
- // const LamboSchemaForm = ()=> import('@lambo-design/schema-form')
68
- export default {
69
- name:"schema-paging-table",
70
- components: {
71
- LamboSchemaForm: () => import('@lambo-design/schema-form'),
72
- LamboPagingTable,
73
- },
74
- data() {
75
- return {
76
- queryForm: {},
77
- tableSearchParams: {},
78
- selection: [],
79
- selectStore: [],
80
- selectTags: [],
81
- selectRows: [],
82
- selectedKeys: [],
83
- }
84
- },
85
- props:{
86
- dataUrl:{
87
- type: String,
88
- required: true,
89
- default: ''
90
- },
91
- columnList:{
92
- type: Array,
93
- required: true,
94
- default(){
95
- return []
96
- }
97
- },
98
- rowKey: {
99
- type: String,
100
- require: false,
101
- default: ""
102
- },
103
- rowName: {
104
- type: String,
105
- require: false,
106
- default: ""
107
- },
108
- form:{
109
- type: Object,
110
- required: true,
111
- default(){
112
- return {}
113
- }
114
- },
115
- formFields:{
116
- type: Array,
117
- required: true,
118
- default(){
119
- return []
120
- }
121
- },
122
- buttonList:{
123
- type: Array,
124
- required: true,
125
- default(){
126
- return []
127
- }
128
- },
129
- customComponents: Object,
130
- customValidates: Object
131
- },
132
- computed: {
133
- tableColumn: function () {
134
- let columns = []
135
- let self = this
136
- self.columnList.forEach((item,index)=>{
137
- let obj = item
138
- if(obj.hasOwnProperty("enums") && obj.hasOwnProperty("translate") && obj.translate === 'enums'){
139
- obj.render = function (h, param) {
140
- let state = param.row[obj.key]
141
- return h('span', obj.enums[state])
142
- }
143
- }else if(obj.hasOwnProperty("type") && obj.type === "operate"){
144
- obj.render = (h, param) => {
145
- return h('div',
146
- obj.button.map((item,index)=>{
147
- return operateHref(self, h, param.row, item.name, (vm, currentRow) => {
148
- if(item.clickEvent?.type==="route"){
149
- // self.$Message.info(item.clickEvent.name)
150
- let query = item.clickEvent?.route?.keys?.reduce((acc,sourceItem)=>{
151
- return Object.assign(acc,{[sourceItem]:currentRow[sourceItem]})
152
- },{})
153
- this.$router.push({
154
- path: item.clickEvent?.route?.path,
155
- query
156
- })
157
- }else if(item.clickEvent?.type==="request"){
158
- // self.$Message.info(item.clickEvent.name)
159
- let data = item.clickEvent?.request?.keys?.reduce((acc,sourceItem)=>{
160
- return Object.assign(acc,{[sourceItem]:currentRow[sourceItem]})
161
- },{})
162
- let request = {
163
- url:item.clickEvent.request.url,
164
- method:item.clickEvent.request.method,
165
- param:data,
166
- }
167
- let response = item.clickEvent.response
168
- self.fetch(request,response)
169
- }else if(item.clickEvent?.type==="method"){
170
- let args = item.clickEvent?.method?.keys?.reduce((total,current)=>{
171
- return Object.assign(total,{[current]:currentRow[current]})
172
- },{})
173
- self.$emit(item.clickEvent?.method?.name,args)
174
- }else if(item.clickEvent?.type==="modal"){
175
- self.$Message.info(item.clickEvent.name)
176
- }
177
- },item.permission)
178
- })
179
- )
180
- }
181
- }
182
- columns.push(item)
183
- })
184
- return columns
185
- },
186
- spreadButton: function () {
187
- return this.buttonList.slice(0,3)
188
- },
189
- dropDownButton: function () {
190
- return this.buttonList.slice(3 - this.buttonList.length)
191
- },
192
- },
193
- watch:{
194
- form: function(val) {
195
- this.queryForm = val
196
- }
197
- },
198
- created() {
199
- },
200
- methods: {
201
- doClick(item){
202
- let self = this;
203
- if(item.clickEvent?.type==="route"){
204
- // self.$Message.info(item.clickEvent.name)
205
- let query = item.clickEvent?.route?.keys?.reduce((acc,sourceItem)=>{
206
- return Object.assign(acc,{[sourceItem]:param.row[sourceItem]})
207
- },{})
208
- this.$router.push({
209
- path: item.clickEvent?.route?.path,
210
- query
211
- })
212
- }else if(item.clickEvent?.type==="method"){
213
- // self.$Message.info(item.clickEvent.name)
214
- let param = item.clickEvent?.method?.keys?.reduce((acc,sourceItem)=>{
215
- return Object.assign(acc,{[sourceItem]:self.selection[sourceItem]})
216
- },{})
217
- self.$emit(item.clickEvent?.method?.name,param)
218
- }else if(item.clickEvent?.type==="modal"){
219
- self.$Message.info(item.clickEvent.name)
220
- }
221
- },
222
- doSearch: function () {
223
- this.tableSearchParams = Object.assign({}, this.queryForm)
224
- },
225
- onReset() {
226
- this.doSearch()
227
- },
228
- fetch: function (request,response) {
229
- let self = this
230
- let options = {
231
- url: request.url,
232
- method: request.method,
233
- [request.method==='GET'?"params":"data"]:request.param
234
- }
235
- ajax.request(options).then(function (resp) {
236
- // todo 判断返回码
237
- self.$Message.success(response.successMsg)
238
- self.doSearch()
239
- }).catch(function (err) {
240
- console.error(err)
241
- self.$Message.error(response.errorMsg)
242
- })
243
- },
244
- /**
245
- *
246
- * @param row
247
- * @param index
248
- */
249
- onRowClick: function (row, index) {
250
- this.selectOnChange(row, index);
251
- },
252
- //单选
253
- selectOnChange: function (row, index) {
254
- this.selection = Array(index).fill(false);
255
- this.selection.splice(index, 1, true);
256
- this.selectStore = [row];
257
- },
258
- //多选
259
- onSelectionChange: function (rows) {
260
- if (!this.rowKey) {
261
- this.selectStore = rows;
262
- } else {
263
- this.selectStore = rows;
264
- if (rows && rows.length > 0) {
265
- for (let i = 0; i < rows.length; i++) {
266
- let row = rows[i];
267
- if (!this.selectTags.some(item => item.key === row[this.rowKey])) {
268
- let tagItem = {"key": row[this.rowKey], "value": row[this.rowName]}
269
- this.selectTags.push(tagItem);
270
- }
271
- }
272
- }
273
- }
274
- },
275
- onSelect: function (selection, row) {
276
- if (this.rowKey) {
277
- this.selectRows[row[this.rowKey]] = row;
278
- }
279
- },
280
- onSelectCancel: function (selection, row) {
281
- if (this.rowKey) {
282
- delete this.selectRows[row[this.rowKey]];
283
- const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === row[this.rowKey])
284
- if (selectIndex > -1) {
285
- this.selectTags.splice(selectIndex, 1);
286
- }
287
- }
288
- },
289
- onSelectAll: function (selection) {
290
- if (this.rowKey) {
291
- for (let item of selection) {
292
- this.selectRows[item[this.rowKey]] = item;
293
- }
294
- }
295
- },
296
- onSelectAllCancel: function () {
297
- if (this.rowKey) {
298
- let currentTableData = this.$refs.schemaPagingTable.$data.tableData;
299
- for (let i = 0; i < currentTableData.length; i++) {
300
- let tempData = currentTableData[i][this.rowKey];
301
- delete this.selectRows[tempData];
302
- const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === tempData)
303
- if (selectIndex > -1) {
304
- this.selectTags.splice(selectIndex, 1);
305
- }
306
- }
307
- }
308
- },
309
- transformResponse: function (resp) {
310
- if (this.rowKey) {
311
- let self = this;
312
- if (resp.code === 1 || resp.code === "000") {
313
- let tableData = resp.data.rows;
314
- for (let i = 0; i < tableData.length; i++) {
315
- if (self.selectRows[tableData[i][self.rowKey]]) {
316
- tableData[i]._checked = true;
317
- }
318
- }
319
- resp.data.rows = tableData;
320
- }
321
- }
322
- return resp;
323
- },
324
- clearSelectData: function () {
325
- this.selection = [];//清空已选项
326
- this.selectStore = [];//清空已选数据
327
- this.selectRows = [];//清空已选数据
328
- this.selectTags = [];//清空所选标签
329
- this.selectedKeys = [];//清空默认选择
330
- },
331
- tagClose: function (event, name) {
332
- const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === name)
333
- const dataIndex = (this.$refs.schemaPagingTable.$data.tableData || []).findIndex((selectItem) => selectItem[this.rowKey] === name)
334
- if (selectIndex > -1) {
335
- this.selectTags.splice(selectIndex, 1);
336
- this.selectStore.splice(selectIndex, 1);
337
- }
338
- delete this.selectRows[name];
339
- if (dataIndex > -1) {
340
- this.$refs.schemaPagingTable.$refs.tableRef.toggleSelect(dataIndex);
341
- }
342
- },
343
- getSelection(){
344
- if (this.selectRows.length > 0 && this.rowKey) {
345
- let selectStore = [];
346
- for (let item in this.selectRows) {
347
- selectStore.push(this.selectRows[item]);
348
- }
349
- this.selectStore = selectStore;
350
- }
351
- return this.selectStore
352
- }
353
- }
354
- }
355
- </script>
356
- <style lang="less" scoped>
357
- .lambo-grid-table {
358
- /deep/.ivu-form {
359
- .ivu-form-item {
360
- display: block !important;
361
- }
362
- }
363
- }
364
- .tags {
365
- margin: 10px auto;
366
- }
367
- </style>
368
-
1
+ <template>
2
+ <LamboPagingTable
3
+ ref="schemaPagingTable"
4
+ :dataUrl="dataUrl"
5
+ :data="data"
6
+ :columns="tableColumn"
7
+ :autoSearch="autoSearch"
8
+ :searchParams="tableSearchParams"
9
+ :transformResponse="transformResponse"
10
+ :showTableOption="showTableOption"
11
+ :buttonFlex="buttonFlex"
12
+ :pageDisable="pageDisable"
13
+ :radioSelectIndex="radioSelectIndex"
14
+ @on-row-click="onRowClick"
15
+ @on-selection-change="onSelectionChange"
16
+ @on-select="onSelect"
17
+ @on-select-cancel="onSelectCancel"
18
+ @on-select-all="onSelectAll"
19
+ @on-select-all-cancel="onSelectAllCancel">
20
+ <div slot="search">
21
+ <LamboSchemaForm
22
+ ref="lamboSchemaForm"
23
+ v-model="queryForm"
24
+ :form-type="'search'"
25
+ :fieldList="formFields"
26
+ :labelWidth="labelWidth"
27
+ :default-rows="2"
28
+ :grid-columns="gridColumns"
29
+ :customComponents="customComponents"
30
+ :customValidates="customValidates"
31
+ @doSearch="doSearch" @reset="onReset"/>
32
+ <div v-if="rowName && selectTags.length > 0">
33
+ <Tag v-for="item in selectTags" :key="item.key" :name="item.key" closable @on-close="tagClose">
34
+ {{ item.value }}
35
+ </Tag>
36
+ </div>
37
+ <div v-else-if="rowName && selectTags.length === 0" style="height: 26px">
38
+ 无选中数据
39
+ </div>
40
+ </div>
41
+ <Row slot="buttons" type="flex" justify="space-between" :wrap="false">
42
+ <Col flex="auto" ref="container" :class="totalButtons.length > buttonsInFirstRow ? collapsed ? 'buttons-hidden' : '' : ''">
43
+ <Row type="flex" :justify="buttonFlex">
44
+ <Button
45
+ ref="buttons"
46
+ v-if="dropDownButton.length > 0"
47
+ v-for="(item,index) in dropDownButton"
48
+ type="primary"
49
+ :ghost="true"
50
+ :icon="item.icon"
51
+ v-permission="item.permission"
52
+ :key="index"
53
+ @click="doClick(item)"
54
+ :class="buttonShowClass">
55
+ {{ item.name }}
56
+ </Button>
57
+ </Row>
58
+ </Col>
59
+ <Col flex="0 1 77px" v-if="totalButtons.length > buttonsInFirstRow">
60
+ <Button type="text" class="more-btn" @click=setCollapse>
61
+ {{collapsed ?'展开':'收起'}}
62
+ <Icon :type="collapsed ? 'ios-arrow-down' : 'ios-arrow-up'"></Icon>
63
+ </Button>
64
+ </Col>
65
+ </Row>
66
+ </LamboPagingTable>
67
+ </template>
68
+ <script>
69
+ import ajax from '@lambo-design/shared/utils/ajax'
70
+ import {operateBtn, operateHref, operateMore} from '@lambo-design/shared/utils/assist'
71
+ import LamboPagingTable from '@lambo-design/paging-table'
72
+ // import LamboSchemaForm from '@lambo-design/schema-form'
73
+ // const LamboSchemaForm = ()=> import('@lambo-design/schema-form')
74
+ export default {
75
+ name:"schema-paging-table",
76
+ components: {
77
+ LamboSchemaForm: () => import('@lambo-design/schema-form'),
78
+ LamboPagingTable,
79
+ },
80
+ data() {
81
+ return {
82
+ buttonsInFirstRow:0,
83
+ totalButtons:0,
84
+ collapsed:true,
85
+ queryForm: {},
86
+ tableSearchParams: {},
87
+ selection: [],
88
+ selectTags: [],
89
+ selectRows: [],
90
+ selectedKeys: [],
91
+ radioSelectIndex: -1,
92
+ selectCondition:''
93
+ }
94
+ },
95
+ props:{
96
+ dataUrl:{
97
+ type: String,
98
+ required: true,
99
+ default: ''
100
+ },
101
+ data: {
102
+ type: Array,
103
+ default() {
104
+ return [];
105
+ }
106
+ },
107
+ autoSearch: {
108
+ type: Boolean,
109
+ required: false,
110
+ default: false
111
+ },
112
+ columnList: {
113
+ type: Array,
114
+ required: true,
115
+ default(){
116
+ return []
117
+ }
118
+ },
119
+ showTableOption: {
120
+ type: Boolean,
121
+ default: true
122
+ },
123
+ buttonFlex: {
124
+ type: String,
125
+ default () {
126
+ return 'start';
127
+ },
128
+ validator(value) {
129
+ return ['start', 'end'].indexOf(value) > -1;
130
+ }
131
+ },
132
+ //是否禁用分页
133
+ pageDisable: {
134
+ type: Boolean,
135
+ default: false
136
+ },
137
+ rowKey: {
138
+ type: String,
139
+ require: false,
140
+ default: ""
141
+ },
142
+ rowName: {
143
+ type: String,
144
+ require: false,
145
+ default: ""
146
+ },
147
+ labelWidth: {
148
+ type: Number,
149
+ require: false,
150
+ default: 100
151
+ },
152
+ operColumnDropdownNum: {
153
+ type: Number,
154
+ require: false,
155
+ default: 2
156
+ },
157
+ form:{
158
+ type: Object,
159
+ required: true,
160
+ default(){
161
+ return {}
162
+ }
163
+ },
164
+ formFields:{
165
+ type: Array,
166
+ required: true,
167
+ default(){
168
+ return []
169
+ }
170
+ },
171
+ buttonList:{
172
+ type: Array,
173
+ required: true,
174
+ default(){
175
+ return []
176
+ }
177
+ },
178
+ gridColumns:{
179
+ type: Number,
180
+ default: 4
181
+ },
182
+ customComponents: Object,
183
+ customValidates: Object,
184
+ //父组件回填已选中的值
185
+ selectedKey: {
186
+ type: Array,
187
+ require: false,
188
+ default: () => {return []}
189
+ }
190
+ },
191
+ computed: {
192
+ tableColumn: function () {
193
+ let columns = []
194
+ let self = this
195
+ self.columnList.forEach((item,index)=>{
196
+ let obj = item
197
+ if(obj.hasOwnProperty("enums") && obj.hasOwnProperty("translate") && obj.translate === 'enums'){
198
+ obj.render = function (h, param) {
199
+ let state = param.row[obj.key]
200
+ return h('span', obj.enums[state])
201
+ }
202
+ } else if (obj.hasOwnProperty("type") && obj.type === "status" && obj.statusList){
203
+ obj.render = function (h, param) {
204
+ let label = "";
205
+ let tagColor = "";
206
+ obj.statusList.forEach(item => {
207
+ if(item.statusKey === param.row[obj.key]){
208
+ label = item.statusValue;
209
+ tagColor = item.color ? item.color : item.customColor;
210
+ }
211
+ })
212
+ if(label){
213
+ return h('Tag', {
214
+ props: {
215
+ color: tagColor
216
+ }
217
+ }, label);
218
+ }
219
+ }
220
+ } else if(obj.hasOwnProperty("type") && obj.type === "operate"){
221
+ obj.render = (h, param) => {
222
+ let visibleDomsd = [];
223
+ let dropdownDomsd = [];
224
+ obj.button.map((item, index) => {
225
+ const conditionMet = item && typeof item.condition === "function" ? item.condition(param) : true;
226
+ const execConditionMet = item && typeof item.execCondition === "function" ? item.execCondition(param) : true;
227
+ if(conditionMet){
228
+ let doms
229
+ if (!execConditionMet) {
230
+ doms = item.name ? item.name : param.row[obj.key]
231
+ } else {
232
+ doms = operateHref(self, h, param.row, item.name || param.row[obj.key], (vm, currentRow) => {
233
+ if (item.clickEvent?.type === "route") {
234
+ // self.$Message.info(item.clickEvent.name)
235
+ let query = item.clickEvent?.route?.keys?.reduce((acc, sourceItem) => {
236
+ return Object.assign(acc, {[sourceItem]: currentRow[sourceItem]})
237
+ }, {})
238
+ self.$router.push({
239
+ path: item.clickEvent?.route?.path,
240
+ query
241
+ })
242
+ } else if (item.clickEvent?.type === "request") {
243
+ // self.$Message.info(item.clickEvent.name)
244
+ let data = item.clickEvent?.request?.keys?.reduce((acc, sourceItem) => {
245
+ return Object.assign(acc, {[sourceItem]: currentRow[sourceItem]})
246
+ }, {})
247
+ let request = {
248
+ url: item.clickEvent.request.url,
249
+ method: item.clickEvent.request.method,
250
+ param: data,
251
+ }
252
+ let response = item.clickEvent.response
253
+ if (item.clickEvent.tips) {
254
+ let tips = item.clickEvent.tips
255
+ this.$Modal.confirm({
256
+ title: tips.title,
257
+ content: '<p>' + tips.content + '</p>',
258
+ onOk: () => {
259
+ self.fetch(request, response)
260
+ }
261
+ });
262
+ } else {
263
+ self.fetch(request, response)
264
+ }
265
+ } else if (item.clickEvent?.type === "method") {
266
+ if(!item.clickEvent?.method?.keys) {
267
+ self.$emit(item.clickEvent?.method?.name, param.index);
268
+ return ;
269
+ }
270
+ let args = item.clickEvent?.method?.keys?.reduce((total, current) => {
271
+ return Object.assign(total, {[current]: currentRow[current]})
272
+ }, {})
273
+ self.$emit(item.clickEvent?.method?.name, args)
274
+ } else if (item.clickEvent?.type === "modal") {
275
+ self.$Message.info(item.clickEvent.name)
276
+ }
277
+ }, item.permission)
278
+ }
279
+ if (visibleDomsd.length < self.operColumnDropdownNum) {
280
+ visibleDomsd.push(doms);
281
+ } else if (visibleDomsd.length === self.operColumnDropdownNum && dropdownDomsd.length === 0){
282
+ dropdownDomsd.push(h('DropdownItem', {}, [visibleDomsd[self.operColumnDropdownNum - 1]]))
283
+ dropdownDomsd.push(h('DropdownItem', {}, [doms]))
284
+ } else {
285
+ dropdownDomsd.push(h('DropdownItem', {}, [doms]))
286
+ }
287
+ }
288
+ })
289
+ if (dropdownDomsd.length !== 0) {
290
+ visibleDomsd.splice(self.operColumnDropdownNum - 1, 1)
291
+ }
292
+ return h('div', {}, [
293
+ ...visibleDomsd,
294
+ dropdownDomsd.length !== 0 ? operateMore(self,h,dropdownDomsd) : null
295
+ ]);
296
+ }
297
+ } else if (obj.hasOwnProperty('type') && (obj.type === 'selection'||obj.type === 'single-selection')) {
298
+ this.selectCondition = item.selectCondition ? item.selectCondition : ''
299
+ } else if (item.isFlotTip) {
300
+ obj.render = (h, param) => {
301
+ return h('span', {
302
+ style: {
303
+ display: 'inline-block',
304
+ width: '100%',
305
+ overflow: 'hidden',
306
+ textOverflow: 'ellipsis',
307
+ whiteSpace: 'nowrap'
308
+ },
309
+ domProps: { title: item.name ? item.name : param.row[obj.key] }
310
+ }, item.name ? item.name : param.row[obj.key])
311
+ }
312
+ }
313
+ columns.push(item)
314
+ })
315
+ return columns
316
+ },
317
+ dropDownButton: function () {
318
+ return this.buttonList
319
+ },
320
+ multiSelect: function() {
321
+ return this.columnList.some((item)=>{
322
+ return item.type === "selection"
323
+ })
324
+ },
325
+ buttonShowClass(){
326
+ return 'buttons-show-'+this.buttonFlex
327
+ }
328
+ },
329
+ watch: {
330
+ form: {
331
+ handler: function (val) {
332
+ this.tableSearchParams = val
333
+ this.queryForm = val
334
+ },
335
+ deep: true
336
+ },
337
+ rowKey: {
338
+ handler: function () {
339
+ if(this.rowKey){
340
+ if (this.selectedKey.length === 0) return
341
+ this.selectedKeys = this.selectedKey
342
+ //重置标签
343
+ this.selectTags = []
344
+ this.selectRows = []
345
+ for (let item of this.selectedKeys) {
346
+ this.selectRows[item[this.rowKey]] = item;
347
+ let tagItem = {"key": item[this.rowKey], "value": item[this.rowName]}
348
+ this.selectTags.push(tagItem);
349
+ }
350
+ }
351
+ },
352
+ immediate:true
353
+ }
354
+ },
355
+ created() {
356
+ let self = this
357
+ setTimeout(()=>{
358
+ self.calculateButtonsInFirstRow();
359
+ },1000)
360
+ window.addEventListener('resize', this.calculateButtonsInFirstRow);
361
+ },
362
+ beforeDestroy() {
363
+ window.removeEventListener('resize', this.calculateButtonsInFirstRow);
364
+ },
365
+ methods: {
366
+ //计算第一行有多少个button,根据父div宽度和每个button的宽度计算
367
+ calculateButtonsInFirstRow() {
368
+ let container = this.$refs.container
369
+ if (!container){return}
370
+ let containerWidth = container.$el.offsetWidth
371
+ const buttons = this.$refs.buttons;
372
+ let totalWidth = 0;
373
+ let buttonsInFirstRow = 0;
374
+ for (let i = 0; buttons && i < buttons.length; i++) {
375
+ totalWidth += buttons[i].$el.offsetWidth + 5
376
+ if (totalWidth <= containerWidth) {
377
+ buttonsInFirstRow++;
378
+ } else {
379
+ break;
380
+ }
381
+ }
382
+ this.totalButtons = this.dropDownButton
383
+ this.buttonsInFirstRow = buttonsInFirstRow;
384
+ },
385
+ setCollapse: function() {
386
+ this.collapsed = !this.collapsed
387
+ },
388
+ doClick(item){
389
+ let self = this;
390
+ if (item.clickEvent?.type === "route") {
391
+ const routeInfo = item.clickEvent.route;
392
+ const keysExist = routeInfo.keys && routeInfo.keys.length !== 0;
393
+ const selection = keysExist ? self.getSelection() : null;
394
+ if (keysExist && selection.length === 0) {
395
+ self.$Message.info('请选择一条记录!');
396
+ return;
397
+ }
398
+ if (keysExist && self.multiSelect) {
399
+ const query = selection.map((select, index) => {
400
+ if (item.clickEvent?.route?.keys) {
401
+ let obj = item.clickEvent?.route?.keys?.reduce((acc, sourceItem) => {
402
+ return Object.assign(acc, {[sourceItem]: select[sourceItem]})
403
+ }, {})
404
+ return obj
405
+ } else {
406
+ return item
407
+ }
408
+ })
409
+ self.$router.push({ path: routeInfo.path, query })
410
+ } else {
411
+ const query = keysExist
412
+ ? routeInfo.keys.reduce((acc, key) => ({ ...acc, [key]: selection[0][key] }), {})
413
+ : null;
414
+ self.$router.push({ path: routeInfo.path, query })
415
+ }
416
+ } else if (item.clickEvent?.type === "method") {
417
+ const methodInfo = item.clickEvent.method;
418
+ const keysExist = methodInfo.keys && methodInfo.keys.length !== 0;
419
+ let selection = self.getSelection()
420
+ if (keysExist && selection.length === 0) {
421
+ self.$Message.info('请选择一条记录!')
422
+ return
423
+ }
424
+ if (self.multiSelect) {
425
+ let param = selection.map((select, index) => {
426
+ if (item.clickEvent?.method?.keys) {
427
+ let obj = item.clickEvent?.method?.keys?.reduce((acc, sourceItem) => {
428
+ return Object.assign(acc, {[sourceItem]: select[sourceItem]})
429
+ }, {})
430
+ return obj
431
+ } else {
432
+ return item
433
+ }
434
+ })
435
+ self.$emit(item.clickEvent?.method?.name, param)
436
+ } else {
437
+ if (item.clickEvent?.method?.keys) {
438
+ let param = item.clickEvent?.method?.keys?.reduce((acc, sourceItem) => {
439
+ return Object.assign(acc, {[sourceItem]: selection[0][sourceItem]})
440
+ }, {})
441
+ self.$emit(item.clickEvent?.method?.name, param)
442
+ } else {
443
+ let param = selection[0]
444
+ self.$emit(item.clickEvent?.method?.name, param)
445
+ }
446
+ }
447
+ }
448
+ },
449
+ doSearch: function () {
450
+ this.tableSearchParams = Object.assign({}, this.queryForm)
451
+ // 帮助框查询不清空已选择项
452
+ if (!this.rowName) {
453
+ this.clearSelectData();
454
+ }
455
+ },
456
+ boxShowSearch: function () {
457
+ this.tableSearchParams = Object.assign({}, this.queryForm)
458
+ },
459
+ onReset() {
460
+ // Object.assign(this.queryForm, this.$options.propsData.form)
461
+ this.queryForm = this.$options.propsData.form;
462
+ this.doSearch()
463
+ },
464
+ fetch: function (request,response) {
465
+ let self = this
466
+ let options = {
467
+ url: request.url,
468
+ method: request.method,
469
+ [request.method==='GET'?"params":"data"]:request.param
470
+ }
471
+ ajax.request(options).then(function (resp) {
472
+ // todo 判断返回码
473
+ self.$Message.success(response.successMsg)
474
+ self.doSearch()
475
+ }).catch(function (err) {
476
+ console.error(err)
477
+ self.$Message.error(response.errorMsg)
478
+ })
479
+ },
480
+ /**
481
+ *
482
+ * @param row
483
+ * @param index
484
+ */
485
+ onRowClick: function (row, index) {
486
+ // 单选触发
487
+ if (this.$refs.schemaPagingTable.isSingleSelectModel) {
488
+ this.selectOnChange(row, index);
489
+ }
490
+ },
491
+ //单选
492
+ selectOnChange: function (row, index) {
493
+ this.radioSelectIndex = -1
494
+ this.selection = Array(index).fill(false);
495
+ this.selection.splice(index, 1, true);
496
+ this.selectRows = []
497
+ this.selectRows[row[this.rowKey]] = row
498
+ this.selectTags = [{"key": row[this.rowKey], "value": row[this.rowName]}]
499
+ },
500
+ //多选
501
+ onSelectionChange: function (rows) {
502
+ if (this.rowKey) {
503
+ if (rows && rows.length > 0) {
504
+ for (let i = 0; i < rows.length; i++) {
505
+ let row = rows[i];
506
+ if (!this.selectTags.some(item => item.key === row[this.rowKey])) {
507
+ let tagItem = {"key": row[this.rowKey], "value": row[this.rowName]}
508
+ this.selectTags.push(tagItem);
509
+ }
510
+ }
511
+ }
512
+ }
513
+ },
514
+ onSelect: function (selection, row) {
515
+ if (this.rowKey) {
516
+ this.selectRows[row[this.rowKey]] = row;
517
+ }
518
+ },
519
+ onSelectCancel: function (selection, row) {
520
+ if (this.rowKey) {
521
+ delete this.selectRows[row[this.rowKey]];
522
+ const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === row[this.rowKey])
523
+ if (selectIndex > -1) {
524
+ this.selectTags.splice(selectIndex, 1);
525
+ }
526
+ }
527
+ },
528
+ onSelectAll: function (selection) {
529
+ if (this.rowKey) {
530
+ for (let item of selection) {
531
+ this.selectRows[item[this.rowKey]] = item;
532
+ }
533
+ }
534
+ },
535
+ onSelectAllCancel: function () {
536
+ if (this.rowKey) {
537
+ let currentTableData = this.$refs.schemaPagingTable.$data.tableData;
538
+ for (let i = 0; i < currentTableData.length; i++) {
539
+ let tempData = currentTableData[i][this.rowKey];
540
+ delete this.selectRows[tempData];
541
+ const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === tempData)
542
+ if (selectIndex > -1) {
543
+ this.selectTags.splice(selectIndex, 1);
544
+ }
545
+ }
546
+ }
547
+ },
548
+ transformResponse: function (resp) {
549
+ if (this.rowKey) {
550
+ let self = this;
551
+ self.radioSelectIndex = -1
552
+ if (resp.code === 1 || resp.code === "000") {
553
+ let tableData = resp.data.rows;
554
+ for (let i = 0; i < tableData.length; i++) {
555
+ if (self.selectCondition && typeof self.selectCondition === "function") {
556
+ tableData[i]._disabled = !self.selectCondition({row:tableData[i]})
557
+ }
558
+ if (self.selectRows[tableData[i][self.rowKey]]) {
559
+ self.radioSelectIndex = i
560
+ tableData[i]._checked = true;
561
+ }
562
+ }
563
+ resp.data.rows = tableData;
564
+ }
565
+ }
566
+ return resp;
567
+ },
568
+ clearSelectData: function () {
569
+ this.selection = [];//清空已选项
570
+ this.selectRows = [];//清空已选数据
571
+ this.selectTags = [];//清空所选标签
572
+ this.selectedKeys = [];//清空默认选择
573
+ this.radioSelectIndex = -1
574
+ },
575
+ tagClose: function (event, name) {
576
+ this.radioSelectIndex = -1
577
+ const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === name)
578
+ const dataIndex = (this.$refs.schemaPagingTable.$data.tableData || []).findIndex((selectItem) => selectItem[this.rowKey] === name)
579
+ if (selectIndex > -1) {
580
+ this.selectTags.splice(selectIndex, 1);
581
+ }
582
+ delete this.selectRows[name];
583
+ if (dataIndex > -1) {
584
+ this.$refs.schemaPagingTable.$refs.tableRef.toggleSelect(dataIndex);
585
+ }
586
+ },
587
+ getSelection() {
588
+ let selectStore = [];
589
+ if (Object.keys(this.selectRows).length > 0 && this.rowKey) {
590
+ for (let item in this.selectRows) {
591
+ selectStore.push(this.selectRows[item]);
592
+ }
593
+ }
594
+ return selectStore
595
+ }
596
+ }
597
+ }
598
+ </script>
599
+ <style lang="less" scoped>
600
+ .lambo-grid-table {
601
+ /deep/.ivu-form {
602
+ .ivu-form-item {
603
+ display: block;
604
+ }
605
+ }
606
+ }
607
+
608
+ .buttons-hidden{
609
+ height:33px;
610
+ overflow: hidden;
611
+ }
612
+
613
+ .buttons-show-start:not(:last-child){
614
+ margin:0 5px 5px 0
615
+ }
616
+ .buttons-show-end:not(:first-child){
617
+ margin:0 0 5px 5px
618
+ }
619
+ </style>
620
+