vue2-client 1.12.43 → 1.12.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2-client",
3
- "version": "1.12.43",
3
+ "version": "1.12.45",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --no-eslint",
@@ -24,7 +24,7 @@ export default {
24
24
  data () {
25
25
  return {
26
26
  // 查询配置文件名
27
- queryParamsName: 'ceshiCRUD',
27
+ queryParamsName: 'outpatientRefund2CRUD',
28
28
  // 查询配置左侧tree
29
29
  // xTreeConfigName: 'addressType',
30
30
  // 新增表单固定值
@@ -24,7 +24,7 @@
24
24
  </template>
25
25
  <template v-else-if="cell.type === 'slot'">
26
26
  <template
27
- v-if="['x-form-table','x-add-native-form','x-tree-pro', 'x-his-editor', 'x-tab', 'x-form-group', 'x-report', 'x-buttons', 'x-label-select', 'x-conversation', 'x-check-list', 'x-cardSet', 'x-collapse','x-h-descriptions'].includes(cell.slotType)">
27
+ v-if="['x-form-table','x-add-native-form','x-tree-pro', 'x-his-editor', 'x-tab', 'x-form-group', 'x-report', 'x-buttons', 'x-label-select', 'x-conversation', 'x-check-list', 'x-cardSet', 'x-collapse','x-h-descriptions', 'x-sidebar'].includes(cell.slotType)">
28
28
  <component
29
29
  :is="getComponentName(cell.slotConfig, cell.serviceName, cell.slotType)"
30
30
  :key="cellIndex"
@@ -59,7 +59,7 @@
59
59
  </template>
60
60
  <template v-else-if="cell.type === 'slot'">
61
61
  <template
62
- v-if="['x-form-table','x-add-native-form','x-tree-pro', 'x-his-editor', 'x-tab', 'x-form-group', 'x-report', 'x-buttons', 'x-label-select', 'x-conversation', 'x-check-list', 'x-cardSet', 'x-collapse', 'x-h-descriptions'].includes(cell.slotType)">
62
+ v-if="['x-form-table','x-add-native-form','x-tree-pro', 'x-his-editor', 'x-tab', 'x-form-group', 'x-report', 'x-buttons', 'x-label-select', 'x-conversation', 'x-check-list', 'x-cardSet', 'x-collapse', 'x-h-descriptions', 'x-sidebar'].includes(cell.slotType)">
63
63
  <component
64
64
  :is="getComponentName(cell.slotConfig, cell.serviceName, cell.slotType)"
65
65
  :key="cellIndex"
@@ -106,6 +106,7 @@ export default {
106
106
  XCardSet: () => import('@vue2-client/base-client/components/common/XCardSet/XCardSet.vue'),
107
107
  XCollapse: () => import('@vue2-client/base-client/components/common/XCollapse/XCollapse.vue'),
108
108
  XHDescriptions: () => import('@vue2-client/base-client/components/his/XHDescriptions/XHDescriptions.vue'),
109
+ XSidebar: () => import('@vue2-client/base-client/components/his/XSidebar/XSidebar.vue'),
109
110
  },
110
111
  props: {
111
112
  // 每一行的配置
@@ -37,7 +37,13 @@
37
37
  />
38
38
  </template>
39
39
  <span v-else-if="item.slotType === 'rate'" :key="'rate-' + c_index">
40
- <x-rate :value="text" :disabled="true" :allow-half="item.allowHalf" :icon="item.rateIcon" :max-count="item.maxCount" />
40
+ <x-rate
41
+ :value="text"
42
+ :disabled="true"
43
+ :allow-half="item.allowHalf"
44
+ :icon="item.rateIcon"
45
+ :max-count="item.maxCount"
46
+ style="zoom:0.9"/>
41
47
  </span>
42
48
  <span v-else-if="item.slotType === 'index'" :key="'index-' + c_index">
43
49
  {{ index + 1 }}
@@ -107,7 +113,10 @@
107
113
  </span>
108
114
  </template>
109
115
  <template slot="footer">
110
- <slot name="footer" :selectedRowKeys="tableContext.selectedRowKeys" :selectedRows="tableContext.selectedRows"></slot>
116
+ <slot
117
+ name="footer"
118
+ :selectedRowKeys="tableContext.selectedRowKeys"
119
+ :selectedRows="tableContext.selectedRows"></slot>
111
120
  </template>
112
121
  </s-table>
113
122
  </template>
@@ -120,6 +129,7 @@ import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormIte
120
129
  import CustomFuncCel from '@vue2-client/base-client/components/common/XTable/CustomFuncCel.vue'
121
130
  import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
122
131
  import XRate from '@vue2-client/base-client/components/common/XRate/index.vue'
132
+
123
133
  export default {
124
134
  name: 'XTableWrapper',
125
135
  components: {
@@ -0,0 +1,197 @@
1
+ <template>
2
+ <div
3
+ class="drawer"
4
+ :class="{ 'drawer-collapsed': !isOpen }">
5
+ <div
6
+ class="drawer-toggle"
7
+ :class="{ 'toggle-collapsed': !isOpen }"
8
+ @click="toggleDrawer">
9
+ <div class="arrow">
10
+ {{ isOpen ? '›' : '‹' }}
11
+ </div>
12
+ </div>
13
+ <div class="drawer-content" v-if="isOpen">
14
+ <x-report
15
+ :configName="queryParamsName"
16
+ :server-name="serverName"
17
+ :show-img-in-cell="true"
18
+ :display-only="true"
19
+ :edit-mode="false"
20
+ :show-save-button="false"
21
+ :no-padding="true"
22
+ :dont-format="true">
23
+ </x-report>
24
+ </div>
25
+ </div>
26
+ </template>
27
+
28
+ <script>
29
+
30
+ import XReport from '@vue2-client/base-client/components/common/XReportGrid'
31
+
32
+ export default {
33
+ components: {
34
+ XReport
35
+ },
36
+ name: 'XSidebar',
37
+ props: {
38
+ // 配置参数
39
+ queryParamsName: {
40
+ type: String,
41
+ default: ''
42
+ },
43
+ serverName: {
44
+ type: String,
45
+ default: 'af-his'
46
+ }
47
+ },
48
+ data () {
49
+ return {
50
+ isOpen: true,
51
+ // 定义主内容区域的最大和最小宽度百分比
52
+ mainWithData: [{ max: 36, min: 25 }, { max: 60, min: 47 }]
53
+ }
54
+ },
55
+ mounted () {
56
+ // 在挂载后调整父元素宽度
57
+ this.updateLayout(this.isOpen)
58
+ },
59
+ methods: {
60
+
61
+ toggleDrawer () {
62
+ this.isOpen = !this.isOpen
63
+ this.$emit('on-drawer-change', this.isOpen)
64
+ this.updateLayout(this.isOpen)
65
+ },
66
+ // 获取同级的其他所有a-col元素
67
+ getSiblingCols () {
68
+ try {
69
+ // 找到当前组件所在的a-col
70
+ let currentCol = this.$el.parentNode
71
+ while (currentCol && !currentCol.className.includes('ant-col')) {
72
+ currentCol = currentCol.parentNode
73
+ }
74
+ if (!currentCol) {
75
+ console.warn('当前组件不在a-col内')
76
+ return []
77
+ }
78
+ // 找到a-col的父元素(a-row)
79
+ const row = currentCol.parentNode
80
+ if (!row || !row.className.includes('ant-row')) {
81
+ console.warn('未找到父级a-row元素')
82
+ return []
83
+ }
84
+ // 获取a-row中的所有a-col
85
+ const allCol1 = Array.from(row.querySelectorAll('.ant-col-6'))
86
+ const allCol2 = Array.from(row.querySelectorAll('.ant-col-12'))
87
+ const allCols = [...allCol1, ...allCol2]
88
+ // 过滤掉当前a-col,返回其他所有a-col
89
+ return allCols.filter(col => col !== currentCol)
90
+ } catch (error) {
91
+ console.error('获取同级a-col时出错:', error)
92
+ return []
93
+ }
94
+ },
95
+ updateLayout (isOpen) {
96
+ this.$nextTick(() => {
97
+ try {
98
+ // 获取所有同级a-col
99
+ const otherCols = this.getSiblingCols()
100
+ console.log('otherCols =', otherCols)
101
+ // 如果找到同级列,调整它们的宽度
102
+ if (otherCols.length > 0) {
103
+ // 获取当前组件所在的a-col
104
+ let currentCol = this.$el.parentNode
105
+ while (currentCol && !currentCol.className.includes('ant-col')) {
106
+ currentCol = currentCol.parentNode
107
+ }
108
+ if (currentCol) {
109
+ // 更新当前列的宽度
110
+ const drawerWidth = isOpen ? 28 : 2
111
+ currentCol.style.flex = `0 0 ${drawerWidth}%`
112
+ currentCol.style.maxWidth = `${drawerWidth}%`
113
+ // 根据mainWithData设置其他列的宽度
114
+ otherCols.forEach((col, index) => {
115
+ // 确保不超出mainWithData数组范围
116
+ if (index < this.mainWithData.length) {
117
+ // 抽屉打开用min值,关闭用max值
118
+ const widthValue = isOpen ? this.mainWithData[index].min : this.mainWithData[index].max
119
+ col.style.flex = `0 0 ${widthValue}%`
120
+ col.style.maxWidth = `${widthValue}%`
121
+ }
122
+ })
123
+ // 触发重新计算
124
+ window.dispatchEvent(new Event('resize'))
125
+ }
126
+ }
127
+ } catch (error) {
128
+ console.error('布局更新失败:', error)
129
+ }
130
+ })
131
+ }
132
+ },
133
+ watch: {
134
+ configData: {
135
+ handler (newValue) {
136
+ console.log('configData changed:', newValue)
137
+ this.renderingComponent(newValue)
138
+ },
139
+ immediate: true
140
+ }
141
+ }
142
+ }
143
+ </script>
144
+
145
+ <style scoped>
146
+ .drawer {
147
+ position: relative;
148
+ height: 88vh;
149
+ width: 100%;
150
+ background-color: #fff;
151
+ border-left: solid rgba(240, 242, 245) 2px;
152
+ transition: all 0.3s;
153
+ border-radius: 10px;
154
+ }
155
+
156
+ .drawer-collapsed {
157
+ width: 24px;
158
+ box-shadow: none;
159
+ }
160
+ .drawer-toggle {
161
+ position: absolute;
162
+ top: 50%;
163
+ transform: translateY(-50%);
164
+ width: 24px;
165
+ height: 48px;
166
+ background-color: #fff;
167
+ cursor: pointer;
168
+ display: flex;
169
+ align-items: center;
170
+ justify-content: center;
171
+ z-index: 1;
172
+ transition: all 0.3s;
173
+ }
174
+ /* 打开状态:箭头在抽屉内 */
175
+ .drawer:not(.drawer-collapsed) .drawer-toggle {
176
+ left: 0;
177
+ border-radius: 0;
178
+ box-shadow: none;
179
+ }
180
+ /* 关闭状态:箭头在抽屉内 */
181
+ .drawer-collapsed .drawer-toggle {
182
+ left: 0;
183
+ border-radius: 0;
184
+ box-shadow: none;
185
+ }
186
+ .arrow {
187
+ font-size: 20px;
188
+ line-height: 1;
189
+ color: rgba(24, 144, 245);
190
+ }
191
+ .drawer-content {
192
+ height: 100%;
193
+ overflow-y: auto;
194
+ padding: 20px;
195
+ padding-left: 44px; /* 为开关留出空间 */
196
+ }
197
+ </style>
@@ -1,426 +1,435 @@
1
- import T from 'ant-design-vue/es/table/Table'
2
- import get from 'lodash.get'
3
- import { mapState } from 'vuex'
4
-
5
- export default {
6
- data () {
7
- return {
8
- clickedRowKey: null,
9
- needTotalList: [],
10
-
11
- selectedRows: [],
12
- selectedRowKeys: [],
13
-
14
- localLoading: false,
15
- localDataSource: [],
16
- localPagination: Object.assign({}, this.pagination),
17
-
18
- sortField: undefined,
19
- sortOrder: undefined,
20
- pageNum: 1,
21
- pageSize: 10
22
- }
23
- },
24
- props: Object.assign({}, T.props, {
25
- rowKey: {
26
- type: [String, Function],
27
- default: 'key'
28
- },
29
- data: {
30
- type: Function,
31
- required: true
32
- },
33
- setScrollYHeight: {
34
- type: Function,
35
- required: true
36
- },
37
- showSizeChanger: {
38
- type: Boolean,
39
- default: true
40
- },
41
- showSummary: {
42
- type: Boolean,
43
- default: false
44
- },
45
- selectRowMode: {
46
- type: String,
47
- default: 'default'
48
- },
49
- size: {
50
- type: String,
51
- default: 'default'
52
- },
53
- /**
54
- * alert: {
55
- * show: true,
56
- * clear: Function
57
- * }
58
- */
59
- alert: {
60
- type: [Object, Boolean],
61
- default: null
62
- },
63
- rowSelection: {
64
- type: Object,
65
- default: null
66
- },
67
- /** @Deprecated */
68
- showAlertInfo: {
69
- type: Boolean,
70
- default: false
71
- },
72
- showPagination: {
73
- type: String | Boolean,
74
- default: 'auto'
75
- },
76
- // 是否隐藏翻页,如果隐藏,彻底不显示翻译
77
- hidePagination: {
78
- type: Boolean,
79
- default: false
80
- },
81
- // 是否显示表头已选择部分
82
- showSelected: {
83
- type: Boolean,
84
- default: true
85
- },
86
- /**
87
- * enable page URI mode
88
- *
89
- * e.g:
90
- * /users/1
91
- * /users/2
92
- * /users/3?queryParam=test
93
- * ...
94
- */
95
- pageURI: {
96
- type: Boolean,
97
- default: false
98
- }
99
- }),
100
- computed: {
101
- ...mapState('setting', ['theme']), // 添加 theme 到计算属性
102
-
103
- // 计算点击行的背景色,使用 10% 透明度
104
- clickedRowColor () {
105
- if (!this.theme?.color) return '#e6f7ff'
106
- return this.hexToRgba(this.theme.color, 0.1)
107
- }
108
- },
109
- watch: {
110
- 'localPagination.current' (val) {
111
- this.pageURI && this.$router.push({
112
- ...this.$route,
113
- name: this.$route.name,
114
- params: Object.assign({}, this.$route.params, {
115
- pageNo: val
116
- })
117
- })
118
- // change pagination, reset total data
119
- this.needTotalList = this.initTotalList(this.columns)
120
- if (this.selectRowMode === 'default') {
121
- this.selectedRowKeys = []
122
- this.selectedRows = []
123
- }
124
- },
125
- pageNum (val) {
126
- Object.assign(this.localPagination, {
127
- current: val
128
- })
129
- },
130
- pageSize (val) {
131
- Object.assign(this.localPagination, {
132
- pageSize: val
133
- })
134
- },
135
- showSizeChanger (val) {
136
- Object.assign(this.localPagination, {
137
- showSizeChanger: val
138
- })
139
- }
140
- },
141
- created () {
142
- const { pageNo } = this.$route.params
143
- const localPageNum = this.pageURI && (pageNo && parseInt(pageNo)) || this.pageNum
144
- this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
145
- current: localPageNum,
146
- pageSize: this.pageSize,
147
- showSizeChanger: this.showSizeChanger
148
- }) || false
149
- this.needTotalList = this.initTotalList(this.columns)
150
- // this.loadData()
151
- },
152
- methods: {
153
- /**
154
- * 表格重新加载方法
155
- * 如果参数为 true, 则强制刷新到第一页
156
- * @param Boolean bool
157
- */
158
- refresh (bool = false) {
159
- bool && (this.localPagination = Object.assign({}, {
160
- current: 1, pageSize: this.pageSize
161
- }))
162
- this.loadData()
163
- },
164
- /**
165
- * 加载数据方法
166
- * @param {Object} pagination 分页选项器
167
- * @param {Object} filters 过滤条件
168
- * @param {Object} sorter 排序条件
169
- */
170
- loadData (pagination, filters, sorter) {
171
- this.localLoading = true
172
- // 暂存排序方式,避免 refresh 之后排序失效
173
- if (sorter && sorter.field) {
174
- this.sortField = sorter.field
175
- }
176
- if (sorter && sorter.order) {
177
- this.sortOrder = sorter.order
178
- }
179
- const parameter = Object.assign({
180
- querySummary: !pagination && this.showSummary, // 分页查询的情况不重新获取汇总数据
181
- pageNo: (pagination && pagination.current) ||
182
- this.showPagination && this.localPagination.current || this.pageNum,
183
- pageSize: (pagination && pagination.pageSize) ||
184
- this.showPagination && this.localPagination.pageSize || this.pageSize
185
- },
186
- (this.sortField && { sortField: this.sortField }) || {},
187
- (this.sortOrder && { sortOrder: this.sortOrder }) || {},
188
- { ...filters }
189
- )
190
- const result = this.data(parameter)
191
- // 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data
192
- // eslint-disable-next-line
193
- if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
194
- result.then(r => {
195
- this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
196
- current: r.pageNo, // 返回结果中的当前分页数
197
- total: r.totalCount, // 返回结果中的总记录数
198
- showSizeChanger: this.showSizeChanger,
199
- pageSize: (pagination && pagination.pageSize) || this.localPagination.pageSize
200
- }) || false
201
- // 为防止删除数据后导致页面当前页面数据长度为 0 ,自动翻页到上一页
202
- if (r.data.length === 0 && this.showPagination && this.localPagination.current > 1) {
203
- this.localPagination.current--
204
- this.loadData()
205
- return
206
- }
207
-
208
- // 这里用于判断接口是否有返回 r.totalCount 且 this.showPagination = 'auto' 且 pageNo 和 pageSize 存在 且 totalCount 小于等于 pageNo * pageSize 的大小
209
- // 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能
210
- try {
211
- if ((['auto'].includes(this.showPagination) && r.totalCount <= (r.pageNo * this.localPagination.pageSize))) {
212
- this.localPagination.hideOnSinglePage = true
213
- }
214
- } catch (e) {
215
- this.localPagination = false
216
- }
217
- this.localDataSource = r.data // 返回结果中的数组数据
218
- this.localLoading = false
219
- this.setScrollYHeight({ type: 'default' })
220
- }, () => {
221
- this.localLoading = false
222
- this.setScrollYHeight({ type: 'default' })
223
- })
224
- }
225
- },
226
- initTotalList (columns) {
227
- const totalList = []
228
- columns && columns instanceof Array && columns.forEach(column => {
229
- if (column.needTotal) {
230
- totalList.push({
231
- ...column,
232
- total: 0
233
- })
234
- }
235
- })
236
- return totalList
237
- },
238
- /**
239
- * 用于更新已选中的列表数据 total 统计
240
- * @param selectedRowKeys
241
- * @param selectedRows
242
- */
243
- updateSelect (selectedRowKeys, selectedRows) {
244
- this.selectedRows = selectedRows
245
- this.selectedRowKeys = selectedRowKeys
246
- const list = this.needTotalList
247
- this.needTotalList = list.map(item => {
248
- return {
249
- ...item,
250
- total: selectedRows.reduce((sum, val) => {
251
- const total = sum + parseInt(get(val, item.dataIndex))
252
- return isNaN(total) ? 0 : total
253
- }, 0)
254
- }
255
- })
256
- },
257
- /**
258
- * 清空 table 已选中项
259
- */
260
- clearSelected () {
261
- if (this.rowSelection) {
262
- this.rowSelection.onChange([], [])
263
- this.updateSelect([], [])
264
- }
265
- },
266
- /**
267
- * 处理交给 table 使用者去处理 clear 事件时,内部选中统计同时调用
268
- * @param callback
269
- * @returns {*}
270
- */
271
- renderClear (callback) {
272
- if (this.selectedRowKeys.length <= 0) return null
273
- return (
274
- <a style="margin-left: 24px" onClick={() => {
275
- callback()
276
- this.clearSelected()
277
- }}>清空</a>
278
- )
279
- },
280
- renderAlert () {
281
- // 绘制统计列数据
282
- const needTotalItems = this.needTotalList.map((item) => {
283
- return (<span style="margin-right: 12px">
284
- {item.title}总计 <a
285
- style="font-weight: 600">{!item.customRender ? item.total : item.customRender(item.total)}</a>
286
- </span>)
287
- })
288
-
289
- // 绘制 清空 按钮
290
- const clearItem = (typeof this.alert.clear === 'boolean' && this.alert.clear) ? (
291
- this.renderClear(this.clearSelected)
292
- ) : (typeof this.alert.clear === 'function') ? (
293
- this.renderClear(this.alert.clear)
294
- ) : null
295
-
296
- // 绘制 alert 组件
297
- return (
298
- <a-alert showIcon={true} style={{ marginBottom: '8px', fontSize: '14px' }}>
299
- <template slot="message">
300
- <span style="margin-right: 12px;">已选择: <a style="font-weight: 600">{this.selectedRows.length}</a></span>
301
- {needTotalItems}
302
- {clearItem}
303
- </template>
304
- </a-alert>
305
- )
306
- },
307
- onExpand (expanded, record) {
308
- this.$emit('expand', expanded, record)
309
- },
310
- handleRowClick (record) {
311
- this.clickedRowKey = record[this.rowKey]
312
- this.$emit('rowClick', record)
313
- },
314
- hexToRgba (hex, alpha = 1) {
315
- try {
316
- const r = parseInt(hex.slice(1, 3), 16)
317
- const g = parseInt(hex.slice(3, 5), 16)
318
- const b = parseInt(hex.slice(5, 7), 16)
319
- return `rgba(${r}, ${g}, ${b}, ${alpha})`
320
- } catch (e) {
321
- return '#e6f7ff'
322
- }
323
- },
324
- },
325
-
326
- render () {
327
- const props = {}
328
- const localKeys = Object.keys(this.$data)
329
- const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) && typeof this.rowSelection.selectedRowKeys !== 'undefined' || this.alert
330
-
331
- Object.keys(T.props).forEach(k => {
332
- const localKey = `local${k.substring(0, 1).toUpperCase()}${k.substring(1)}`
333
- if (localKeys.includes(localKey)) {
334
- props[k] = this[localKey]
335
- return props[k]
336
- }
337
- if (k === 'rowSelection') {
338
- if (showAlert && this.rowSelection) {
339
- // 如果需要使用alert,则重新绑定 rowSelection 事件
340
- props[k] = {
341
- ...this.rowSelection,
342
- selectedRows: this.selectedRows,
343
- selectedRowKeys: this.selectedRowKeys,
344
- onChange: (selectedRowKeys, selectedRows) => {
345
- this.updateSelect(selectedRowKeys, selectedRows)
346
- typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
347
- }
348
- }
349
- return props[k]
350
- } else if (!this.rowSelection) {
351
- // 如果没打算开启 rowSelection 则清空默认的选择项
352
- props[k] = null
353
- return props[k]
354
- }
355
- }
356
- this[k] && (props[k] = this[k])
357
- return props[k]
358
- })
359
- // 取消原有的分页组件 产品设计分页组件和汇总在一行 重新分页逻辑
360
- props.pagination = false
361
- // props 中添加自定义行属性
362
- props.customRow = (record) => {
363
- return {
364
- on: {
365
- click: () => this.handleRowClick(record)
366
- },
367
- style: {
368
- 'background-color': this.clickedRowKey === record[this.rowKey] ? this.clickedRowColor : ''
369
- }
370
- }
371
- }
372
- // 自定义底部汇总插槽组件
373
- const pagination = (
374
- !!this.showPagination && <a-row type={'flex'} justify={'start'} style={{ marginTop: '8px' }}>
375
- <a-col flex="1" style={{
376
- alignItems: 'center',
377
- display: 'flex',
378
- justifyContent: 'start',
379
- boxSizing: 'border-box',
380
- paddingRight: '2rem'
381
- }}>
382
- {this.$slots.fixedfooter}
383
- </a-col>
384
- <a-col flex="0 0">
385
- <a-pagination
386
- total={this.localPagination.total}
387
- onChange={(page, pageSize) => {
388
- this.pageSize = pageSize
389
- this.pageNum = page
390
- this.loadData({
391
- current: page,
392
- pageSize: pageSize
393
- })
394
- }
395
- }
396
- onShowSizeChange={(page, pageSize) => {
397
- this.pageSize = pageSize
398
- this.pageNum = page
399
- this.loadData({
400
- current: page,
401
- pageSize: pageSize
402
- })
403
- }
404
- }
405
- show-total={(total, range) => range[0] === range[1] ? `${range[0]} | 共 ${total} 项` : `${range[0]}-${range[1]} | 共 ${total} 项`}
406
- default-current={this.localPagination.current}
407
- showSizeChanger={this.localPagination.showSizeChanger}/>
408
- </a-col>
409
- </a-row>
410
- )
411
- const table = (
412
- <a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}
413
- onExpand={(expanded, record) => this.onExpand(expanded, record)}>
414
- {Object.keys(this.$slots).map(name => (<template slot={name}>{this.$slots[name]}</template>))}
415
- </a-table>
416
- )
417
-
418
- return (
419
- <div class="table-wrapper">
420
- {showAlert && this.showSelected && this.selectRowMode === 'default' ? this.renderAlert() : null}
421
- {table}
422
- {!this.hidePagination ? pagination : null}
423
- </div>
424
- )
425
- }
426
- }
1
+ import T from 'ant-design-vue/es/table/Table'
2
+ import get from 'lodash.get'
3
+ import { mapState } from 'vuex'
4
+
5
+ export default {
6
+ data () {
7
+ return {
8
+ clickedRowKey: null,
9
+ needTotalList: [],
10
+
11
+ selectedRows: [],
12
+ selectedRowKeys: [],
13
+
14
+ localLoading: false,
15
+ localDataSource: [],
16
+ localPagination: Object.assign({}, this.pagination),
17
+
18
+ sortField: undefined,
19
+ sortOrder: undefined,
20
+ pageNum: 1,
21
+ pageSize: 10
22
+ }
23
+ },
24
+ props: Object.assign({}, T.props, {
25
+ rowKey: {
26
+ type: [String, Function],
27
+ default: 'key'
28
+ },
29
+ data: {
30
+ type: Function,
31
+ required: true
32
+ },
33
+ setScrollYHeight: {
34
+ type: Function,
35
+ required: true
36
+ },
37
+ showSizeChanger: {
38
+ type: Boolean,
39
+ default: true
40
+ },
41
+ showSummary: {
42
+ type: Boolean,
43
+ default: false
44
+ },
45
+ selectRowMode: {
46
+ type: String,
47
+ default: 'default'
48
+ },
49
+ size: {
50
+ type: String,
51
+ default: 'default'
52
+ },
53
+ /**
54
+ * alert: {
55
+ * show: true,
56
+ * clear: Function
57
+ * }
58
+ */
59
+ alert: {
60
+ type: [Object, Boolean],
61
+ default: null
62
+ },
63
+ rowSelection: {
64
+ type: Object,
65
+ default: null
66
+ },
67
+ /** @Deprecated */
68
+ showAlertInfo: {
69
+ type: Boolean,
70
+ default: false
71
+ },
72
+ showPagination: {
73
+ type: String | Boolean,
74
+ default: 'auto'
75
+ },
76
+ // 是否隐藏翻页,如果隐藏,彻底不显示翻译
77
+ hidePagination: {
78
+ type: Boolean,
79
+ default: false
80
+ },
81
+ // 是否显示表头已选择部分
82
+ showSelected: {
83
+ type: Boolean,
84
+ default: true
85
+ },
86
+ /**
87
+ * enable page URI mode
88
+ *
89
+ * e.g:
90
+ * /users/1
91
+ * /users/2
92
+ * /users/3?queryParam=test
93
+ * ...
94
+ */
95
+ pageURI: {
96
+ type: Boolean,
97
+ default: false
98
+ }
99
+ }),
100
+ computed: {
101
+ ...mapState('setting', ['theme']), // 添加 theme 到计算属性
102
+
103
+ // 计算点击行的背景色,使用 10% 透明度
104
+ clickedRowColor () {
105
+ const themeColor = this.$store.state.setting.theme.color
106
+ return this.hexToRgba(themeColor || '#1890ff', 0.1)
107
+ }
108
+ },
109
+ watch: {
110
+ 'localPagination.current' (val) {
111
+ this.pageURI && this.$router.push({
112
+ ...this.$route,
113
+ name: this.$route.name,
114
+ params: Object.assign({}, this.$route.params, {
115
+ pageNo: val
116
+ })
117
+ })
118
+ // change pagination, reset total data
119
+ this.needTotalList = this.initTotalList(this.columns)
120
+ if (this.selectRowMode === 'default') {
121
+ this.selectedRowKeys = []
122
+ this.selectedRows = []
123
+ }
124
+ },
125
+ pageNum (val) {
126
+ Object.assign(this.localPagination, {
127
+ current: val
128
+ })
129
+ },
130
+ pageSize (val) {
131
+ Object.assign(this.localPagination, {
132
+ pageSize: val
133
+ })
134
+ },
135
+ showSizeChanger (val) {
136
+ Object.assign(this.localPagination, {
137
+ showSizeChanger: val
138
+ })
139
+ }
140
+ },
141
+ created () {
142
+ const { pageNo } = this.$route.params
143
+ const localPageNum = this.pageURI && (pageNo && parseInt(pageNo)) || this.pageNum
144
+ this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
145
+ current: localPageNum,
146
+ pageSize: this.pageSize,
147
+ showSizeChanger: this.showSizeChanger
148
+ }) || false
149
+ this.needTotalList = this.initTotalList(this.columns)
150
+ // this.loadData()
151
+ },
152
+ methods: {
153
+ /**
154
+ * 表格重新加载方法
155
+ * 如果参数为 true, 则强制刷新到第一页
156
+ * @param Boolean bool
157
+ */
158
+ refresh (bool = false) {
159
+ bool && (this.localPagination = Object.assign({}, {
160
+ current: 1, pageSize: this.pageSize
161
+ }))
162
+ this.loadData()
163
+ },
164
+ /**
165
+ * 加载数据方法
166
+ * @param {Object} pagination 分页选项器
167
+ * @param {Object} filters 过滤条件
168
+ * @param {Object} sorter 排序条件
169
+ */
170
+ loadData (pagination, filters, sorter) {
171
+ this.localLoading = true
172
+ // 暂存排序方式,避免 refresh 之后排序失效
173
+ if (sorter && sorter.field) {
174
+ this.sortField = sorter.field
175
+ }
176
+ if (sorter && sorter.order) {
177
+ this.sortOrder = sorter.order
178
+ }
179
+ const parameter = Object.assign({
180
+ querySummary: !pagination && this.showSummary, // 分页查询的情况不重新获取汇总数据
181
+ pageNo: (pagination && pagination.current) ||
182
+ this.showPagination && this.localPagination.current || this.pageNum,
183
+ pageSize: (pagination && pagination.pageSize) ||
184
+ this.showPagination && this.localPagination.pageSize || this.pageSize
185
+ },
186
+ (this.sortField && { sortField: this.sortField }) || {},
187
+ (this.sortOrder && { sortOrder: this.sortOrder }) || {},
188
+ { ...filters }
189
+ )
190
+ const result = this.data(parameter)
191
+ // 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data
192
+ // eslint-disable-next-line
193
+ if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
194
+ result.then(r => {
195
+ this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
196
+ current: r.pageNo, // 返回结果中的当前分页数
197
+ total: r.totalCount, // 返回结果中的总记录数
198
+ showSizeChanger: this.showSizeChanger,
199
+ pageSize: (pagination && pagination.pageSize) || this.localPagination.pageSize
200
+ }) || false
201
+ // 为防止删除数据后导致页面当前页面数据长度为 0 ,自动翻页到上一页
202
+ if (r.data.length === 0 && this.showPagination && this.localPagination.current > 1) {
203
+ this.localPagination.current--
204
+ this.loadData()
205
+ return
206
+ }
207
+
208
+ // 这里用于判断接口是否有返回 r.totalCount 且 this.showPagination = 'auto' 且 pageNo 和 pageSize 存在 且 totalCount 小于等于 pageNo * pageSize 的大小
209
+ // 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能
210
+ try {
211
+ if ((['auto'].includes(this.showPagination) && r.totalCount <= (r.pageNo * this.localPagination.pageSize))) {
212
+ this.localPagination.hideOnSinglePage = true
213
+ }
214
+ } catch (e) {
215
+ this.localPagination = false
216
+ }
217
+ this.localDataSource = r.data // 返回结果中的数组数据
218
+ this.localLoading = false
219
+ this.setScrollYHeight({ type: 'default' })
220
+ }, () => {
221
+ this.localLoading = false
222
+ this.setScrollYHeight({ type: 'default' })
223
+ })
224
+ }
225
+ },
226
+ initTotalList (columns) {
227
+ const totalList = []
228
+ columns && columns instanceof Array && columns.forEach(column => {
229
+ if (column.needTotal) {
230
+ totalList.push({
231
+ ...column,
232
+ total: 0
233
+ })
234
+ }
235
+ })
236
+ return totalList
237
+ },
238
+ /**
239
+ * 用于更新已选中的列表数据 total 统计
240
+ * @param selectedRowKeys
241
+ * @param selectedRows
242
+ */
243
+ updateSelect (selectedRowKeys, selectedRows) {
244
+ this.selectedRows = selectedRows
245
+ this.selectedRowKeys = selectedRowKeys
246
+ const list = this.needTotalList
247
+ this.needTotalList = list.map(item => {
248
+ return {
249
+ ...item,
250
+ total: selectedRows.reduce((sum, val) => {
251
+ const total = sum + parseInt(get(val, item.dataIndex))
252
+ return isNaN(total) ? 0 : total
253
+ }, 0)
254
+ }
255
+ })
256
+ },
257
+ /**
258
+ * 清空 table 已选中项
259
+ */
260
+ clearSelected () {
261
+ if (this.rowSelection) {
262
+ this.rowSelection.onChange([], [])
263
+ this.updateSelect([], [])
264
+ }
265
+ },
266
+ /**
267
+ * 处理交给 table 使用者去处理 clear 事件时,内部选中统计同时调用
268
+ * @param callback
269
+ * @returns {*}
270
+ */
271
+ renderClear (callback) {
272
+ if (this.selectedRowKeys.length <= 0) return null
273
+ return (
274
+ <a style="margin-left: 24px" onClick={() => {
275
+ callback()
276
+ this.clearSelected()
277
+ }}>清空</a>
278
+ )
279
+ },
280
+ renderAlert () {
281
+ // 绘制统计列数据
282
+ const needTotalItems = this.needTotalList.map((item) => {
283
+ return (<span style="margin-right: 12px">
284
+ {item.title}总计 <a
285
+ style="font-weight: 600">{!item.customRender ? item.total : item.customRender(item.total)}</a>
286
+ </span>)
287
+ })
288
+
289
+ // 绘制 清空 按钮
290
+ const clearItem = (typeof this.alert.clear === 'boolean' && this.alert.clear) ? (
291
+ this.renderClear(this.clearSelected)
292
+ ) : (typeof this.alert.clear === 'function') ? (
293
+ this.renderClear(this.alert.clear)
294
+ ) : null
295
+
296
+ // 绘制 alert 组件
297
+ return (
298
+ <a-alert showIcon={true} style={{ marginBottom: '8px', fontSize: '14px' }}>
299
+ <template slot="message">
300
+ <span style="margin-right: 12px;">已选择: <a style="font-weight: 600">{this.selectedRows.length}</a></span>
301
+ {needTotalItems}
302
+ {clearItem}
303
+ </template>
304
+ </a-alert>
305
+ )
306
+ },
307
+ onExpand (expanded, record) {
308
+ this.$emit('expand', expanded, record)
309
+ },
310
+ handleRowClick (record, index) {
311
+ if (this.rowKey === '序号') {
312
+ this.clickedRowKey = index
313
+ } else {
314
+ this.clickedRowKey = record[this.rowKey]
315
+ }
316
+ this.$emit('rowClick', record)
317
+ },
318
+ hexToRgba (hex, alpha = 1) {
319
+ try {
320
+ const r = parseInt(hex.slice(1, 3), 16)
321
+ const g = parseInt(hex.slice(3, 5), 16)
322
+ const b = parseInt(hex.slice(5, 7), 16)
323
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`
324
+ } catch (e) {
325
+ return '#e6f7ff'
326
+ }
327
+ },
328
+ },
329
+
330
+ render () {
331
+ const props = {}
332
+ const localKeys = Object.keys(this.$data)
333
+ const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) && typeof this.rowSelection.selectedRowKeys !== 'undefined' || this.alert
334
+
335
+ Object.keys(T.props).forEach(k => {
336
+ const localKey = `local${k.substring(0, 1).toUpperCase()}${k.substring(1)}`
337
+ if (localKeys.includes(localKey)) {
338
+ props[k] = this[localKey]
339
+ return props[k]
340
+ }
341
+ if (k === 'rowSelection') {
342
+ if (showAlert && this.rowSelection) {
343
+ // 如果需要使用alert,则重新绑定 rowSelection 事件
344
+ props[k] = {
345
+ ...this.rowSelection,
346
+ selectedRows: this.selectedRows,
347
+ selectedRowKeys: this.selectedRowKeys,
348
+ onChange: (selectedRowKeys, selectedRows) => {
349
+ this.updateSelect(selectedRowKeys, selectedRows)
350
+ typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
351
+ }
352
+ }
353
+ return props[k]
354
+ } else if (!this.rowSelection) {
355
+ // 如果没打算开启 rowSelection 则清空默认的选择项
356
+ props[k] = null
357
+ return props[k]
358
+ }
359
+ }
360
+ this[k] && (props[k] = this[k])
361
+ return props[k]
362
+ })
363
+ // 取消原有的分页组件 产品设计分页组件和汇总在一行 重新分页逻辑
364
+ props.pagination = false
365
+ // props 中添加自定义行属性
366
+ props.customRow = (record, index) => {
367
+ const isRowKeySequence = this.rowKey === '序号'
368
+ const isCurrentRow = isRowKeySequence
369
+ ? this.clickedRowKey === index
370
+ : this.clickedRowKey === record[this.rowKey]
371
+ console.log(record, index, this.rowKey, isCurrentRow)
372
+ return {
373
+ on: {
374
+ click: () => this.handleRowClick(record, index)
375
+ },
376
+ style: {
377
+ 'background-color': isCurrentRow ? this.clickedRowColor : ''
378
+ }
379
+ }
380
+ }
381
+ // 自定义底部汇总插槽组件
382
+ const pagination = (
383
+ !!this.showPagination && <a-row type={'flex'} justify={'start'} style={{ marginTop: '8px' }}>
384
+ <a-col flex="1" style={{
385
+ alignItems: 'center',
386
+ display: 'flex',
387
+ justifyContent: 'start',
388
+ boxSizing: 'border-box',
389
+ paddingRight: '2rem'
390
+ }}>
391
+ {this.$slots.fixedfooter}
392
+ </a-col>
393
+ <a-col flex="0 0">
394
+ <a-pagination
395
+ total={this.localPagination.total}
396
+ onChange={(page, pageSize) => {
397
+ this.pageSize = pageSize
398
+ this.pageNum = page
399
+ this.loadData({
400
+ current: page,
401
+ pageSize: pageSize
402
+ })
403
+ }
404
+ }
405
+ onShowSizeChange={(page, pageSize) => {
406
+ this.pageSize = pageSize
407
+ this.pageNum = page
408
+ this.loadData({
409
+ current: page,
410
+ pageSize: pageSize
411
+ })
412
+ }
413
+ }
414
+ show-total={(total, range) => range[0] === range[1] ? `${range[0]} | 共 ${total} 项` : `${range[0]}-${range[1]} | 共 ${total} 项`}
415
+ default-current={this.localPagination.current}
416
+ showSizeChanger={this.localPagination.showSizeChanger}/>
417
+ </a-col>
418
+ </a-row>
419
+ )
420
+ const table = (
421
+ <a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}
422
+ onExpand={(expanded, record) => this.onExpand(expanded, record)}>
423
+ {Object.keys(this.$slots).map(name => (<template slot={name}>{this.$slots[name]}</template>))}
424
+ </a-table>
425
+ )
426
+
427
+ return (
428
+ <div class="table-wrapper">
429
+ {showAlert && this.showSelected && this.selectRowMode === 'default' ? this.renderAlert() : null}
430
+ {table}
431
+ {!this.hidePagination ? pagination : null}
432
+ </div>
433
+ )
434
+ }
435
+ }
@@ -56,10 +56,10 @@ routerResource.example = {
56
56
  // component: () => import('@vue2-client/base-client/components/common/XAddNativeForm/demo.vue'),
57
57
  // component: () => import('@vue2-client/base-client/components/common/XFormGroup/demo.vue'),
58
58
  // component: () => import('@vue2-client/base-client/components/common/XReport/XReportDemo.vue'),
59
- // component: () => import('@vue2-client/base-client/components/common/XFormTable/demo.vue'),
59
+ component: () => import('@vue2-client/base-client/components/common/XFormTable/demo.vue'),
60
60
  // component: () => import('@vue2-client/base-client/components/common/XDatePicker/demo.vue'),
61
61
  // component: () => import('@vue2-client/base-client/components/common/XTab/XTabDemo.vue'),
62
- component: () => import('@vue2-client/base-client/components/common/XRate/demo.vue'),
62
+ // component: () => import('@vue2-client/base-client/components/common/XRate/demo.vue'),
63
63
  // component: () => import('@vue2-client/base-client/components/common/XForm/demo.vue'),
64
64
  // component: () => import('@vue2-client/pages/WorkflowDetail/WorkFlowDemo.vue'),
65
65
  // component: () => import('@vue2-client/base-client/components/common/XConversation/XConversationDemo.vue'),