@lambo-design/schema-paging-table 1.0.0-beta.0
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.
- package/index.js +2 -0
- package/package.json +19 -0
- package/src/index.vue +357 -0
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lambo-design/schema-paging-table",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "lambo",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@lambo-design/core": "^4.7.1-beta.103",
|
|
14
|
+
"@lambo-design/paging-table": "^1.0.0-beta.69",
|
|
15
|
+
"@lambo-design/schema-form": "^1.0.0-beta.20",
|
|
16
|
+
"@lambo-design/shared": "^1.0.0-beta.92"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {}
|
|
19
|
+
}
|
package/src/index.vue
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
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 :labelWidth="100" ref="lamboSchemaForm" v-model="queryForm" :form-type="'search'" :fieldList="formFields" @doSearch="doSearch" @reset="onReset"/>
|
|
16
|
+
<div v-if="rowName" class="tags">
|
|
17
|
+
<Tag v-for="item in selectTags" :key="item.key" :name="item.key" closable @on-close="tagClose">
|
|
18
|
+
{{ item.value }}
|
|
19
|
+
</Tag>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
<div slot="buttons">
|
|
23
|
+
<Button
|
|
24
|
+
v-if="spreadButton.length > 0"
|
|
25
|
+
v-for="(item,index) in spreadButton"
|
|
26
|
+
type="primary"
|
|
27
|
+
:ghost="true"
|
|
28
|
+
:icon="item.icon"
|
|
29
|
+
v-permission="item.permission"
|
|
30
|
+
:key="index"
|
|
31
|
+
@click="doClick(item)"
|
|
32
|
+
style="margin-right: 5px">
|
|
33
|
+
{{ item.name }}
|
|
34
|
+
</Button>
|
|
35
|
+
<Dropdown v-if="dropDownButton.length > 0">
|
|
36
|
+
<Button type="primary" :ghost="true" icon="md-more">
|
|
37
|
+
更多操作
|
|
38
|
+
<Icon type="ios-arrow-down"></Icon>
|
|
39
|
+
</Button>
|
|
40
|
+
<DropdownMenu slot="list">
|
|
41
|
+
<DropdownItem
|
|
42
|
+
v-for="(item,index) in dropDownButton"
|
|
43
|
+
v-permission="item.permission"
|
|
44
|
+
:key="index"
|
|
45
|
+
>
|
|
46
|
+
<Icon :type="item.icon" style="margin-right: 5px"></Icon>
|
|
47
|
+
<span @click="doClick(item)">{{ item.name }}</span>
|
|
48
|
+
</DropdownItem>
|
|
49
|
+
</DropdownMenu>
|
|
50
|
+
</Dropdown>
|
|
51
|
+
</div>
|
|
52
|
+
</LamboPagingTable>
|
|
53
|
+
</template>
|
|
54
|
+
<script>
|
|
55
|
+
import ajax from '@lambo-design/shared/utils/ajax'
|
|
56
|
+
import { operateBtn, operateHref } from '@lambo-design/shared/utils/assist'
|
|
57
|
+
import LamboPagingTable from '@lambo-design/paging-table'
|
|
58
|
+
import LamboSchemaForm from '@lambo-design/schema-form'
|
|
59
|
+
|
|
60
|
+
export default {
|
|
61
|
+
components: {
|
|
62
|
+
LamboSchemaForm,
|
|
63
|
+
LamboPagingTable,
|
|
64
|
+
},
|
|
65
|
+
data() {
|
|
66
|
+
return {
|
|
67
|
+
queryForm: null,
|
|
68
|
+
tableSearchParams: {},
|
|
69
|
+
selection: [],
|
|
70
|
+
selectStore: [],
|
|
71
|
+
selectTags: [],
|
|
72
|
+
selectRows: [],
|
|
73
|
+
selectedKeys: [],
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
props:{
|
|
77
|
+
dataUrl:{
|
|
78
|
+
type: String,
|
|
79
|
+
required: true,
|
|
80
|
+
default: ''
|
|
81
|
+
},
|
|
82
|
+
columnList:{
|
|
83
|
+
type: Array,
|
|
84
|
+
required: true,
|
|
85
|
+
default(){
|
|
86
|
+
return []
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
rowKey: {
|
|
90
|
+
type: String,
|
|
91
|
+
require: false,
|
|
92
|
+
default: ""
|
|
93
|
+
},
|
|
94
|
+
rowName: {
|
|
95
|
+
type: String,
|
|
96
|
+
require: false,
|
|
97
|
+
default: ""
|
|
98
|
+
},
|
|
99
|
+
form:{
|
|
100
|
+
type: Object,
|
|
101
|
+
required: true,
|
|
102
|
+
default(){
|
|
103
|
+
return {}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
formFields:{
|
|
107
|
+
type: Array,
|
|
108
|
+
required: true,
|
|
109
|
+
default(){
|
|
110
|
+
return []
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
buttonList:{
|
|
114
|
+
type: Array,
|
|
115
|
+
required: true,
|
|
116
|
+
default(){
|
|
117
|
+
return []
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
computed: {
|
|
122
|
+
tableColumn: function () {
|
|
123
|
+
let columns = []
|
|
124
|
+
let self = this
|
|
125
|
+
self.columnList.forEach((item,index)=>{
|
|
126
|
+
let obj = item
|
|
127
|
+
if(obj.hasOwnProperty("enums") && obj.hasOwnProperty("translate") && obj.translate === 'enums'){
|
|
128
|
+
obj.render = function (h, param) {
|
|
129
|
+
let state = param.row[obj.key]
|
|
130
|
+
return h('span', obj.enums[state])
|
|
131
|
+
}
|
|
132
|
+
}else if(obj.hasOwnProperty("type") && obj.type === "operate"){
|
|
133
|
+
obj.render = (h, param) => {
|
|
134
|
+
return h('div',
|
|
135
|
+
obj.button.map((item,index)=>{
|
|
136
|
+
return operateHref(self, h, param.row, item.name, (vm, currentRow) => {
|
|
137
|
+
if(item.clickEvent?.type==="route"){
|
|
138
|
+
// self.$Message.info(item.clickEvent.name)
|
|
139
|
+
let query = item.clickEvent?.route?.keys?.reduce((acc,sourceItem)=>{
|
|
140
|
+
return Object.assign(acc,{[sourceItem]:currentRow[sourceItem]})
|
|
141
|
+
},{})
|
|
142
|
+
this.$router.push({
|
|
143
|
+
path: item.clickEvent?.route?.path,
|
|
144
|
+
query
|
|
145
|
+
})
|
|
146
|
+
}else if(item.clickEvent?.type==="request"){
|
|
147
|
+
// self.$Message.info(item.clickEvent.name)
|
|
148
|
+
let data = item.clickEvent?.request?.keys?.reduce((acc,sourceItem)=>{
|
|
149
|
+
return Object.assign(acc,{[sourceItem]:currentRow[sourceItem]})
|
|
150
|
+
},{})
|
|
151
|
+
let request = {
|
|
152
|
+
url:item.clickEvent.request.url,
|
|
153
|
+
method:item.clickEvent.request.method,
|
|
154
|
+
param:data,
|
|
155
|
+
}
|
|
156
|
+
let response = item.clickEvent.response
|
|
157
|
+
self.fetch(request,response)
|
|
158
|
+
}else if(item.clickEvent?.type==="method"){
|
|
159
|
+
let args = item.clickEvent?.method?.keys?.reduce((total,current)=>{
|
|
160
|
+
return Object.assign(total,{[current]:currentRow[current]})
|
|
161
|
+
},{})
|
|
162
|
+
self.$emit(item.clickEvent?.method?.name,args)
|
|
163
|
+
}else if(item.clickEvent?.type==="modal"){
|
|
164
|
+
self.$Message.info(item.clickEvent.name)
|
|
165
|
+
}
|
|
166
|
+
},item.permission)
|
|
167
|
+
})
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
columns.push(item)
|
|
172
|
+
})
|
|
173
|
+
return columns
|
|
174
|
+
},
|
|
175
|
+
spreadButton: function () {
|
|
176
|
+
return this.buttonList.slice(0,3)
|
|
177
|
+
},
|
|
178
|
+
dropDownButton: function () {
|
|
179
|
+
return this.buttonList.slice(3 - this.buttonList.length)
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
watch:{
|
|
183
|
+
form: function(val) {
|
|
184
|
+
this.queryForm = val
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
created() {
|
|
188
|
+
},
|
|
189
|
+
methods: {
|
|
190
|
+
doClick(item){
|
|
191
|
+
let self = this;
|
|
192
|
+
if(item.clickEvent?.type==="route"){
|
|
193
|
+
// self.$Message.info(item.clickEvent.name)
|
|
194
|
+
let query = item.clickEvent?.route?.keys?.reduce((acc,sourceItem)=>{
|
|
195
|
+
return Object.assign(acc,{[sourceItem]:param.row[sourceItem]})
|
|
196
|
+
},{})
|
|
197
|
+
this.$router.push({
|
|
198
|
+
path: item.clickEvent?.route?.path,
|
|
199
|
+
query
|
|
200
|
+
})
|
|
201
|
+
}else if(item.clickEvent?.type==="method"){
|
|
202
|
+
// self.$Message.info(item.clickEvent.name)
|
|
203
|
+
let param = item.clickEvent?.method?.keys?.reduce((acc,sourceItem)=>{
|
|
204
|
+
return Object.assign(acc,{[sourceItem]:self.selection[sourceItem]})
|
|
205
|
+
},{})
|
|
206
|
+
self.$emit(item.clickEvent?.method?.name,param)
|
|
207
|
+
}else if(item.clickEvent?.type==="modal"){
|
|
208
|
+
self.$Message.info(item.clickEvent.name)
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
doSearch: function () {
|
|
212
|
+
this.tableSearchParams = Object.assign({}, this.queryForm)
|
|
213
|
+
},
|
|
214
|
+
onReset() {
|
|
215
|
+
this.doSearch()
|
|
216
|
+
},
|
|
217
|
+
fetch: function (request,response) {
|
|
218
|
+
let self = this
|
|
219
|
+
let options = {
|
|
220
|
+
url: request.url,
|
|
221
|
+
method: request.method,
|
|
222
|
+
[request.method==='GET'?"params":"data"]:request.param
|
|
223
|
+
}
|
|
224
|
+
ajax.request(options).then(function (resp) {
|
|
225
|
+
// todo 判断返回码
|
|
226
|
+
self.$Message.success(response.successMsg)
|
|
227
|
+
self.doSearch()
|
|
228
|
+
}).catch(function (err) {
|
|
229
|
+
console.error(err)
|
|
230
|
+
self.$Message.error(response.errorMsg)
|
|
231
|
+
})
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @param row
|
|
236
|
+
* @param index
|
|
237
|
+
*/
|
|
238
|
+
onRowClick: function (row, index) {
|
|
239
|
+
this.selectOnChange(row, index);
|
|
240
|
+
},
|
|
241
|
+
//单选
|
|
242
|
+
selectOnChange: function (row, index) {
|
|
243
|
+
this.selection = Array(index).fill(false);
|
|
244
|
+
this.selection.splice(index, 1, true);
|
|
245
|
+
this.selectStore = [row];
|
|
246
|
+
},
|
|
247
|
+
//多选
|
|
248
|
+
onSelectionChange: function (rows) {
|
|
249
|
+
if (!this.rowKey) {
|
|
250
|
+
this.selectStore = rows;
|
|
251
|
+
} else {
|
|
252
|
+
this.selectStore = rows;
|
|
253
|
+
if (rows && rows.length > 0) {
|
|
254
|
+
for (let i = 0; i < rows.length; i++) {
|
|
255
|
+
let row = rows[i];
|
|
256
|
+
if (!this.selectTags.some(item => item.key === row[this.rowKey])) {
|
|
257
|
+
let tagItem = {"key": row[this.rowKey], "value": row[this.rowName]}
|
|
258
|
+
this.selectTags.push(tagItem);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
onSelect: function (selection, row) {
|
|
265
|
+
if (this.rowKey) {
|
|
266
|
+
this.selectRows[row[this.rowKey]] = row;
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
onSelectCancel: function (selection, row) {
|
|
270
|
+
if (this.rowKey) {
|
|
271
|
+
delete this.selectRows[row[this.rowKey]];
|
|
272
|
+
const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === row[this.rowKey])
|
|
273
|
+
if (selectIndex > -1) {
|
|
274
|
+
this.selectTags.splice(selectIndex, 1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
onSelectAll: function (selection) {
|
|
279
|
+
if (this.rowKey) {
|
|
280
|
+
for (let item of selection) {
|
|
281
|
+
this.selectRows[item[this.rowKey]] = item;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
onSelectAllCancel: function () {
|
|
286
|
+
if (this.rowKey) {
|
|
287
|
+
let currentTableData = this.$refs.schemaPagingTable.$data.tableData;
|
|
288
|
+
for (let i = 0; i < currentTableData.length; i++) {
|
|
289
|
+
let tempData = currentTableData[i][this.rowKey];
|
|
290
|
+
delete this.selectRows[tempData];
|
|
291
|
+
const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === tempData)
|
|
292
|
+
if (selectIndex > -1) {
|
|
293
|
+
this.selectTags.splice(selectIndex, 1);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
transformResponse: function (resp) {
|
|
299
|
+
if (this.rowKey) {
|
|
300
|
+
let self = this;
|
|
301
|
+
if (resp.code === 1 || resp.code === "000") {
|
|
302
|
+
let tableData = resp.data.rows;
|
|
303
|
+
for (let i = 0; i < tableData.length; i++) {
|
|
304
|
+
if (self.selectRows[tableData[i][self.rowKey]]) {
|
|
305
|
+
tableData[i]._checked = true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
resp.data.rows = tableData;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return resp;
|
|
312
|
+
},
|
|
313
|
+
clearSelectData: function () {
|
|
314
|
+
this.selection = [];//清空已选项
|
|
315
|
+
this.selectStore = [];//清空已选数据
|
|
316
|
+
this.selectRows = [];//清空已选数据
|
|
317
|
+
this.selectTags = [];//清空所选标签
|
|
318
|
+
this.selectedKeys = [];//清空默认选择
|
|
319
|
+
},
|
|
320
|
+
tagClose: function (event, name) {
|
|
321
|
+
const selectIndex = (this.selectTags || []).findIndex((selectItem) => selectItem.key === name)
|
|
322
|
+
const dataIndex = (this.$refs.schemaPagingTable.$data.tableData || []).findIndex((selectItem) => selectItem[this.rowKey] === name)
|
|
323
|
+
if (selectIndex > -1) {
|
|
324
|
+
this.selectTags.splice(selectIndex, 1);
|
|
325
|
+
this.selectStore.splice(selectIndex, 1);
|
|
326
|
+
}
|
|
327
|
+
delete this.selectRows[name];
|
|
328
|
+
if (dataIndex > -1) {
|
|
329
|
+
this.$refs.schemaPagingTable.$refs.tableRef.toggleSelect(dataIndex);
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
getSelection(){
|
|
333
|
+
if (this.selectRows.length > 0 && this.rowKey) {
|
|
334
|
+
let selectStore = [];
|
|
335
|
+
for (let item in this.selectRows) {
|
|
336
|
+
selectStore.push(this.selectRows[item]);
|
|
337
|
+
}
|
|
338
|
+
this.selectStore = selectStore;
|
|
339
|
+
}
|
|
340
|
+
return this.selectStore
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
</script>
|
|
345
|
+
<style lang="less" scoped>
|
|
346
|
+
.lambo-grid-table {
|
|
347
|
+
/deep/.ivu-form {
|
|
348
|
+
.ivu-form-item {
|
|
349
|
+
display: block !important;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
.tags {
|
|
354
|
+
margin: 10px auto;
|
|
355
|
+
}
|
|
356
|
+
</style>
|
|
357
|
+
|