n20-common-lib 1.3.29 → 1.3.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,6 +1,5 @@
1
1
  <template>
2
2
  <el-table
3
- v-if="!pageObj"
4
3
  ref="el-table"
5
4
  :header-cell-style="{ 'text-align': 'center' }"
6
5
  :data="data"
@@ -25,146 +24,30 @@
25
24
  :filters="item.filters | colftF(filtersMap)"
26
25
  v-bind="item"
27
26
  >
28
- <template slot="header">
29
- <span v-if="item.filter" class="">
30
- {{ item.label }}
31
- <ThSelectHeader
32
- :property="item.prop"
33
- :th-index="dataList"
34
- :check-list="checkList"
35
- @selectChange="selectChange"
36
- />
37
- </span>
27
+ <template v-if="item.filterPre" slot="header">
28
+ {{ item.label }}
29
+ <th-select-header
30
+ :property="item.prop"
31
+ :data-list="dataList"
32
+ :check-list="checkList"
33
+ @selectChange="selectChange"
34
+ />
38
35
  </template>
39
36
  </el-table-column>
40
37
  </template>
41
38
  </el-table>
42
-
43
- <div v-else :style="{ height: heightW }">
44
- <el-table
45
- ref="el-table"
46
- :header-cell-style="{ 'text-align': 'center' }"
47
- style="width: 100%"
48
- :data="data"
49
- v-bind="$attrs"
50
- :height="heightC"
51
- v-on="$listeners"
52
- >
53
- <template v-for="(item, i) in columns">
54
- <slot v-if="item.slotName" :name="item.slotName"></slot>
55
- <el-table-column
56
- v-else-if="item.render"
57
- :key="'cl-table-' + i"
58
- v-bind="item"
59
- >
60
- <columnRender
61
- slot-scope="{ row }"
62
- :c-render="item.render"
63
- :row="row"
64
- />
65
- </el-table-column>
66
- <el-table-column
67
- v-else
68
- :key="'cl-table-' + i"
69
- :formatter="item.formatter | colfF"
70
- v-bind="item"
71
- />
72
- </template>
73
- </el-table>
74
- <div v-if="pageObj" class="flex-box flex-r m-t-s">
75
- <Pagination
76
- :page-obj="pageObj"
77
- :page-key="pageKey"
78
- @change="(obj) => $emit('pageChange', obj)"
79
- />
80
- </div>
81
- </div>
82
39
  </template>
83
40
 
84
41
  <script>
85
42
  import numerify from 'numerify'
86
43
  import dayjs from 'dayjs'
87
- import Pagination from '../Pagination/index.vue'
88
-
89
- import ThSelectHeader from './ThSelectHeader.vue'
90
-
91
- const columnRender = {
92
- props: {
93
- cRender: {
94
- type: Function
95
- },
96
- row: {
97
- type: Object
98
- }
99
- },
100
- render(h) {
101
- return this.cRender(h, this.row)
102
- }
103
- }
104
-
105
- function colfF(colf, map) {
106
- if (typeof colf !== 'string') return colf
107
- let sc = colf.split(/{.+?}/g) || []
108
- let mc = colf.match(/{.+?}/g) || []
109
- let mck = []
110
- mc.forEach((t) => {
111
- t = t.replace(/^{|\s+|}$/g, '').split('|')
112
- mck.push(t)
113
- })
114
-
115
- return (row) => tplFn(row, sc, mck, map)
116
- }
117
- function tplFn(row, sc, mck, map = {}) {
118
- let str = ''
119
- sc.forEach((s, i) => {
120
- str += s
121
- let kA = mck[i]
122
- if (kA && kA.length) {
123
- let key = kA[0]
124
- if (kA.length === 1) {
125
- str += row[key]
126
- } else {
127
- let type = kA[1]
128
- switch (type) {
129
- case 'money':
130
- str += numerify(row[key], '0,0.00')
131
- break
132
- case 'rate':
133
- str += numerify(row[key], '0.000000')
134
- break
135
- case 'map':
136
- str += map[row[key]]
137
- break
138
- case 'date':
139
- str += dayjs(row[key]).format('YYYY-MM-DD')
140
- break
141
- case 'datetime':
142
- str += dayjs(row[key]).format('YYYY-MM-DD HH:mm:ss')
143
- break
144
- case 'time':
145
- str += dayjs(row[key]).format('HH:mm:ss')
146
- break
147
- default:
148
- str += row[key]
149
- break
150
- }
151
- }
152
- }
153
- })
154
- return str
155
- }
156
-
157
- function colftF(colft, fMap) {
158
- if (typeof colft !== 'string') return colft
159
- return fMap[colft]
160
- }
44
+ import thSelectHeader from './ThSelectHeader.vue'
161
45
 
162
46
  export default {
163
47
  name: 'Table',
164
48
  components: {
165
- Pagination,
166
49
  columnRender,
167
- ThSelectHeader
50
+ thSelectHeader
168
51
  },
169
52
  filters: {
170
53
  colfF,
@@ -208,21 +91,6 @@ export default {
208
91
  dataList: []
209
92
  }
210
93
  },
211
- computed: {
212
- heightW() {
213
- if (this.height === undefined) {
214
- return undefined
215
- }
216
- if (/\D/.test(this.height)) {
217
- return this.height
218
- } else {
219
- return this.height + 'px'
220
- }
221
- },
222
- heightC() {
223
- return this.pageObj ? 'calc(100% - 38px)' : '100%'
224
- }
225
- },
226
94
  created() {
227
95
  this.dataList = JSON.parse(JSON.stringify(this.data))
228
96
  for (let k in this.dataList[0]) {
@@ -230,17 +98,11 @@ export default {
230
98
  }
231
99
  for (let i in this.dataList) {
232
100
  for (let k in this.dataList[i]) {
233
- if (
234
- this.checkList[k].findIndex((item) => item == this.dataList[i][k]) ==
235
- -1
236
- ) {
101
+ if (!this.checkList[k].some((item) => item === this.dataList[i][k])) {
237
102
  this.checkList[k].push(this.dataList[i][k])
238
103
  }
239
104
  }
240
105
  }
241
- if (this.column) {
242
- console.warn('调整列顺序,请使用ShowColumn组件')
243
- }
244
106
  },
245
107
  methods: {
246
108
  selectChange(val) {
@@ -258,4 +120,75 @@ export default {
258
120
  }
259
121
  }
260
122
  }
123
+
124
+ const columnRender = {
125
+ props: {
126
+ cRender: {
127
+ type: Function
128
+ },
129
+ row: {
130
+ type: Object
131
+ }
132
+ },
133
+ render(h) {
134
+ return this.cRender(h, this.row)
135
+ }
136
+ }
137
+
138
+ function colfF(colf, map) {
139
+ if (typeof colf !== 'string') return colf
140
+ let sc = colf.split(/{.+?}/g) || []
141
+ let mc = colf.match(/{.+?}/g) || []
142
+ let mck = []
143
+ mc.forEach((t) => {
144
+ t = t.replace(/^{|\s+|}$/g, '').split('|')
145
+ mck.push(t)
146
+ })
147
+
148
+ return (row) => tplFn(row, sc, mck, map)
149
+ }
150
+ function tplFn(row, sc, mck, map = {}) {
151
+ let str = ''
152
+ sc.forEach((s, i) => {
153
+ str += s
154
+ let kA = mck[i]
155
+ if (kA && kA.length) {
156
+ let key = kA[0]
157
+ if (kA.length === 1) {
158
+ str += row[key]
159
+ } else {
160
+ let type = kA[1]
161
+ switch (type) {
162
+ case 'money':
163
+ str += numerify(row[key], '0,0.00')
164
+ break
165
+ case 'rate':
166
+ str += numerify(row[key], '0.000000')
167
+ break
168
+ case 'map':
169
+ str += map[row[key]]
170
+ break
171
+ case 'date':
172
+ str += dayjs(row[key]).format('YYYY-MM-DD')
173
+ break
174
+ case 'datetime':
175
+ str += dayjs(row[key]).format('YYYY-MM-DD HH:mm:ss')
176
+ break
177
+ case 'time':
178
+ str += dayjs(row[key]).format('HH:mm:ss')
179
+ break
180
+ default:
181
+ str += row[key]
182
+ break
183
+ }
184
+ }
185
+ }
186
+ })
187
+ return str
188
+ }
189
+
190
+ function colftF(colft, fMap) {
191
+ if (typeof colft !== 'string') return colft
192
+ return fMap[colft]
193
+ }
261
194
  </script>
@@ -0,0 +1,73 @@
1
+ <template>
2
+ <span>
3
+ <el-button
4
+ v-for="item in dfBtns"
5
+ :key="item.label"
6
+ type="text"
7
+ size="mini"
8
+ @click="$emit('command', item.command)"
9
+ >{{ item.label }}</el-button
10
+ >
11
+ <el-dropdown v-if="moreBtns.length" @command="(c) => $emit('command', c)">
12
+ <el-button class="n20-icon-moren" type="text" size="mini" />
13
+ <el-dropdown-menu slot="dropdown" class="text-c">
14
+ <el-dropdown-item
15
+ v-for="item in moreBtns"
16
+ :key="item.label"
17
+ :command="item.command"
18
+ >{{ item.label }}</el-dropdown-item
19
+ >
20
+ </el-dropdown-menu>
21
+ </el-dropdown>
22
+ </span>
23
+ </template>
24
+
25
+ <script>
26
+ export default {
27
+ props: {
28
+ btnList: {
29
+ type: Array,
30
+ default: () => []
31
+ },
32
+ row: {
33
+ type: Object,
34
+ default: () => ({})
35
+ }
36
+ },
37
+ data() {
38
+ return {}
39
+ },
40
+ computed: {
41
+ hasBtns() {
42
+ return this.btnList.filter((btn) => this.hasBtn(btn.isHas, this.row))
43
+ },
44
+ dfBtns() {
45
+ if (this.hasBtns.length > 3) {
46
+ return this.hasBtns.slice(0, 2)
47
+ } else {
48
+ return this.hasBtns
49
+ }
50
+ },
51
+ moreBtns() {
52
+ if (this.hasBtns.length > 3) {
53
+ return this.hasBtns.slice(2)
54
+ } else {
55
+ return []
56
+ }
57
+ }
58
+ },
59
+ methods: {
60
+ hasBtn(isHas, row) {
61
+ if (isHas === undefined || isHas === null) {
62
+ return true
63
+ } else if (typeof isHas === 'boolean') {
64
+ return isHas
65
+ } else if (typeof isHas === 'string' || Array.isArray(isHas)) {
66
+ return this.$has(isHas)
67
+ } else if (typeof isHas === 'function') {
68
+ return isHas(row)
69
+ }
70
+ }
71
+ }
72
+ }
73
+ </script>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <el-table-column v-bind="$attrs">
3
+ <OperateBtns
4
+ slot-scope="{ row, $index }"
5
+ :btn-list="btnList"
6
+ :row="row"
7
+ @command="(c) => $emit(c, row, $index)"
8
+ />
9
+ </el-table-column>
10
+ </template>
11
+
12
+ <script>
13
+ import OperateBtns from './OperateBtns.vue'
14
+ export default {
15
+ name: 'TableOperateColumn',
16
+ components: {
17
+ OperateBtns
18
+ },
19
+ props: {
20
+ btnList: {
21
+ type: Array,
22
+ default: () => []
23
+ }
24
+ }
25
+ }
26
+ </script>
package/src/index.js CHANGED
@@ -35,6 +35,7 @@ import FileUploadTable from './components/FileUploadTable/index.vue'
35
35
  import FooterBox from './components/FooterBox/index.vue'
36
36
  import Filters from './components/Filters/index.vue'
37
37
  import Table from './components/Table/index.vue'
38
+ import TableOperateColumn from './components/TableOperateColumn/index.vue'
38
39
  import Button from './components/Button/index.vue'
39
40
  import ButtonGroup from './components/Button/button-group.vue'
40
41
  import ShowColumn from './components/ShowColumn/index.vue'
@@ -124,6 +125,7 @@ const components = [
124
125
  FooterBox,
125
126
  Filters,
126
127
  Table,
128
+ TableOperateColumn,
127
129
  Button,
128
130
  ButtonGroup,
129
131
  ShowColumn,
@@ -232,6 +234,7 @@ export {
232
234
  FooterBox,
233
235
  Filters,
234
236
  Table,
237
+ TableOperateColumn,
235
238
  Button,
236
239
  ButtonGroup,
237
240
  ShowColumn,