vue2-client 1.6.0 → 1.6.1

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,289 +1,333 @@
1
- <template>
2
- <div>
3
- <a-skeleton :loading="loading" :paragraph="{ rows: 4 }" />
4
- <div v-show="!loading">
5
- <x-add-form
6
- ref="xAddForm"
7
- @onSubmit="onAddOrEditSubmit"
8
- />
9
- <x-form
10
- ref="xForm"
11
- style="margin-bottom: 14px;"
12
- @onSubmit="onSearchSubmit">
13
- <slot name="formBtnExpand"></slot>
14
- </x-form>
15
- <x-table
16
- ref="xTable"
17
- @add="add"
18
- @edit="edit"
19
- @afterDelete="afterDelete"
20
- @action="action"
21
- @selectRow="selectRow"
22
- @afterQuery="afterQuery"
23
- @tempTableEdit="tempTableEdit">
24
- <template slot="button" slot-scope="{selectedRowKeys, selectedRows}">
25
- <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
26
- </template>
27
- <template slot="rightBtnExpand" slot-scope="{selectedRowKeys, selectedRows}">
28
- <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
29
- <a-button @click="toggleIsFormShow">
30
- <a-icon :style="iconStyle" type="vertical-align-top"/>
31
- </a-button>
32
- </template>
33
- <!-- 底部插槽 -->
34
- <template slot="footer" slot-scope="{selectedRowKeys, selectedRows}">
35
- <slot name="footer" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
36
- </template>
37
- </x-table>
38
- </div>
39
- </div>
40
- </template>
41
- <script>
42
- import XForm from '@vue2-client/base-client/components/common/XForm'
43
- import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
44
- import XTable from '@vue2-client/base-client/components/common/XTable'
45
- import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
46
- import { addOrModify, commonApi } from '@vue2-client/services/api/common'
47
- import { indexedDB } from '@vue2-client/utils/indexedDB'
48
- import { mapState } from 'vuex'
49
- import { post } from '@vue2-client/services/api/restTools'
50
-
51
- export default {
52
- name: 'XFormTable',
53
- components: {
54
- XTable,
55
- XForm,
56
- XAddForm,
57
- XImportExcel
58
- },
59
- data () {
60
- return {
61
- // 加载状态
62
- loading: false,
63
- // 业务名称
64
- title: '',
65
- // 图标样式
66
- iconStyle: {
67
- position: 'relative',
68
- top: '1px'
69
- }
70
- }
71
- },
72
- computed: {
73
- ...mapState('setting', ['isMobile'])
74
- },
75
- methods: {
76
- /**
77
- * 初始化组件
78
- */
79
- init (params) {
80
- const {
81
- // 业务名称
82
- title = '',
83
- // 查询配置文件名
84
- queryParamsName,
85
- // 查询配置文件Json,用于查询配置生成器的预览
86
- queryParamsJson,
87
- // 业务逻辑名称, 通过logic获取表单表格配置
88
- logicName,
89
- // 执行logic传递的参数
90
- logicParam,
91
- // 固定新增表单
92
- fixedAddForm,
93
- // 固定查询表单
94
- fixedQueryForm,
95
- // 预览模式
96
- viewMode,
97
- // 数据只有一页时是否展示分页,true:展示,auto:隐藏
98
- showPagination,
99
- // 调用logic获取数据源的追加参数
100
- getDataParams
101
- } = params
102
- this.title = title
103
- const otherRes = {
104
- fixedQueryForm: fixedQueryForm,
105
- viewMode: viewMode,
106
- showPagination: showPagination,
107
- getDataParams: getDataParams,
108
- queryParamsName: queryParamsName,
109
- queryParamsJson: queryParamsJson,
110
- fixedAddForm: fixedAddForm
111
- }
112
- if (queryParamsName) {
113
- this.getColumnsJson(queryParamsName, otherRes)
114
- } else if (queryParamsJson) {
115
- this.getColumnsJsonBySource(queryParamsJson, otherRes)
116
- } else if (logicParam) {
117
- this.getColumnJsonByLogic(logicName, logicParam, otherRes)
118
- } else if (fixedQueryForm) {
119
- this.$refs.xTable.setFixedQueryForm(fixedQueryForm)
120
- }
121
- },
122
- getColumnsJson (queryParamsName, otherRes) {
123
- this.loading = true
124
- indexedDB.getByWeb(queryParamsName, commonApi.getColumnsJson, { str: queryParamsName }, (res) => {
125
- this.updateComponents(res, null, otherRes)
126
- })
127
- },
128
- getColumnsJsonBySource (queryParamsJson, otherRes) {
129
- this.loading = true
130
- post(commonApi.getColumnsJson, { queryObject: queryParamsJson }).then(res => {
131
- this.updateComponents(res, true, otherRes)
132
- })
133
- },
134
- getColumnJsonByLogic (logicName, logicParam, otherRes) {
135
- this.loading = true
136
- indexedDB.getByWeb(`${logicName}_${JSON.stringify(logicParam)}`, commonApi.getColumnsJson, { logic: logicName, logicParam: logicParam }, (res) => {
137
- this.updateComponents(res, true, otherRes)
138
- })
139
- },
140
- /**
141
- * 更新子组件
142
- * @param res 参数
143
- * @param setQueryParams 是否设置queryParams参数
144
- * @param otherRes 额外参数
145
- */
146
- updateComponents (res, setQueryParams, otherRes) {
147
- this.$refs.xTable.init({
148
- queryParams: setQueryParams ? res : null,
149
- tableColumns: res.columnJson,
150
- buttonState: res.buttonState,
151
- title: this.title,
152
- viewMode: otherRes.viewMode,
153
- serviceName: res.serviceName,
154
- queryParamsName: otherRes.queryParamsName,
155
- queryParamsJson: otherRes.queryParamsJson,
156
- showPagination: otherRes.showPagination,
157
- fixedQueryForm: otherRes.fixedQueryForm
158
- })
159
- this.$refs.xForm.init({
160
- formItems: res.formJson,
161
- serviceName: res.serviceName,
162
- getDataParams: otherRes.getDataParams
163
- })
164
- this.$refs.xAddForm.init({
165
- queryParamsName: otherRes.queryParamsName,
166
- queryParamsJson: otherRes.queryParamsJson,
167
- isShow: !res.buttonState || res.buttonState.add || res.buttonState.edit,
168
- formItems: res.formJson,
169
- viewMode: otherRes.viewMode,
170
- serviceName: res.serviceName,
171
- fixedAddForm: otherRes.fixedAddForm,
172
- getDataParams: otherRes.getDataParams
173
- })
174
- this.loading = false
175
- },
176
- /**
177
- * 提交查询表单事件
178
- * @param res 参数
179
- */
180
- onSearchSubmit (res) {
181
- if (res.valid) {
182
- // 表单赋值
183
- this.$refs.xTable.setQueryForm(res.form)
184
- // commit
185
- this.$emit('afterSearchSubmit', res)
186
- } else {
187
- return false
188
- }
189
- },
190
- /**
191
- * 提交新增表单事件
192
- */
193
- onAddOrEditSubmit (res, callback) {
194
- // 组织请求
195
- const requestParameters = {
196
- queryParamsName: res.queryParamsName,
197
- form: res.realForm,
198
- businessType: res.businessType,
199
- operator: res.currUserName
200
- }
201
- addOrModify(requestParameters, this.serviceName).then(data => {
202
- this.$message.success(res.businessType + '成功!')
203
- this.refreshTable(res.businessType === '新增')
204
- // commit
205
- this.$emit('afterSubmit', { type: res.businessType, id: data.id, form: requestParameters.form })
206
- }).catch(e => {
207
- this.$message.error(res.businessType + '失败:' + e)
208
- }).finally(() => {
209
- callback()
210
- })
211
- },
212
- /**
213
- * 表格查询后事件
214
- * @param res 参数
215
- * @param conditionParams 查询条件
216
- */
217
- afterQuery (res, conditionParams) {
218
- this.$emit('afterQuery', res, conditionParams)
219
- },
220
- /**
221
- * 详情按钮事件
222
- * @param record 本条数据
223
- * @param id 数据标识
224
- * @param actionType 操作类型
225
- */
226
- action (record, id, actionType) {
227
- this.$emit('action', record, id, actionType)
228
- },
229
- /**
230
- * 新增按钮事件
231
- */
232
- add () {
233
- this.$refs.xAddForm.open({
234
- businessType: '新增',
235
- title: this.title
236
- })
237
- },
238
- /**
239
- * 修改按钮事件
240
- * @param res 参数
241
- */
242
- edit (res) {
243
- this.$refs.xAddForm.open({
244
- businessType: '修改',
245
- modifyModelData: res,
246
- title: this.title
247
- })
248
- },
249
- /**
250
- * 删除后事件
251
- * @param res
252
- */
253
- afterDelete (res) {
254
- this.$emit('afterDelete', res)
255
- },
256
- /**
257
- * 查询表单部分显示/隐藏切换
258
- */
259
- toggleIsFormShow () {
260
- this.$refs.xForm.toggleVisible()
261
- },
262
- /**
263
- * 选择列事件
264
- * @param selectedRowKeys 选中列Key集合
265
- * @param selectedRows 选中列
266
- */
267
- selectRow (selectedRowKeys, selectedRows) {
268
- this.$emit('selectRow', selectedRowKeys, selectedRows)
269
- },
270
- /**
271
- * 临时表修改
272
- * @param res 参数
273
- */
274
- tempTableEdit (res) {
275
- this.$emit('tempTableEdit', res)
276
- },
277
- /**
278
- * 刷新表格
279
- * @param toFirstPage 是否到第一页
280
- */
281
- refreshTable (toFirstPage = true) {
282
- this.$refs.xTable.refresh(toFirstPage)
283
- },
284
- }
285
- }
286
- </script>
287
- <style lang="less" scoped>
288
-
289
- </style>
1
+ <template>
2
+ <div>
3
+ <a-skeleton :loading="loading" :paragraph="{ rows: 4 }" />
4
+ <div v-show="!loading">
5
+ <x-add-form
6
+ ref="xAddForm"
7
+ :get-data-params="getDataParams"
8
+ @onSubmit="onAddOrEditSubmit"
9
+ />
10
+ <x-form
11
+ ref="xForm"
12
+ :get-data-params="getDataParams"
13
+ style="margin-bottom: 14px;"
14
+ @onSubmit="onSearchSubmit">
15
+ <slot name="formBtnExpand"></slot>
16
+ </x-form>
17
+ <x-table
18
+ ref="xTable"
19
+ :fixedQueryForm="fixedQueryForm"
20
+ :queryParamsName="queryParamsName"
21
+ :query-params-json="queryParamsJson"
22
+ :show-pagination="showPagination"
23
+ @add="add"
24
+ @edit="edit"
25
+ @afterDelete="afterDelete"
26
+ @action="action"
27
+ @selectRow="selectRow"
28
+ @afterQuery="afterQuery"
29
+ @tempTableEdit="tempTableEdit">
30
+ <template slot="button" slot-scope="{selectedRowKeys, selectedRows}">
31
+ <slot name="button" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
32
+ </template>
33
+ <template slot="rightBtnExpand" slot-scope="{selectedRowKeys, selectedRows}">
34
+ <slot name="rightBtnExpand" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
35
+ <a-button @click="toggleIsFormShow">
36
+ <a-icon :style="iconStyle" type="vertical-align-top"/>
37
+ </a-button>
38
+ </template>
39
+ <!-- 底部插槽 -->
40
+ <template slot="footer" slot-scope="{selectedRowKeys, selectedRows}">
41
+ <slot name="footer" :selectedRowKeys="selectedRowKeys" :selectedRows="selectedRows"></slot>
42
+ </template>
43
+ </x-table>
44
+ </div>
45
+ </div>
46
+ </template>
47
+ <script>
48
+ import XForm from '@vue2-client/base-client/components/common/XForm'
49
+ import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
50
+ import XTable from '@vue2-client/base-client/components/common/XTable'
51
+ import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
52
+ import { addOrModify, commonApi } from '@vue2-client/services/api/common'
53
+ import { indexedDB } from '@vue2-client/utils/indexedDB'
54
+ import { mapState } from 'vuex'
55
+ import { post } from '@vue2-client/services/api/restTools'
56
+
57
+ export default {
58
+ name: 'XFormTable',
59
+ components: {
60
+ XTable,
61
+ XForm,
62
+ XAddForm,
63
+ XImportExcel
64
+ },
65
+ data () {
66
+ return {
67
+ // 加载状态
68
+ loading: false,
69
+ // 图标样式
70
+ iconStyle: {
71
+ position: 'relative',
72
+ top: '1px'
73
+ }
74
+ }
75
+ },
76
+ computed: {
77
+ ...mapState('setting', ['isMobile'])
78
+ },
79
+ props: {
80
+ // 业务名称
81
+ title: {
82
+ type: String,
83
+ default: ''
84
+ },
85
+ // 查询配置文件名
86
+ queryParamsName: {
87
+ type: String,
88
+ default: null
89
+ },
90
+ // 查询配置文件Json,用于查询配置生成器的预览
91
+ queryParamsJson: {
92
+ type: Object,
93
+ default: null
94
+ },
95
+ // 业务逻辑名称, 通过logic获取表单表格配置
96
+ logicName: {
97
+ type: String,
98
+ default: null
99
+ },
100
+ // 执行logic传递的参数
101
+ logicParam: {
102
+ type: Object,
103
+ default: () => {}
104
+ },
105
+ // 固定新增表单
106
+ fixedAddForm: {
107
+ type: Object,
108
+ default: () => {
109
+ return {}
110
+ }
111
+ },
112
+ // 固定查询表单
113
+ fixedQueryForm: {
114
+ type: Object,
115
+ default: () => {
116
+ return {}
117
+ }
118
+ },
119
+ // 预览模式
120
+ viewMode: {
121
+ type: Boolean,
122
+ default: () => {
123
+ return false
124
+ }
125
+ },
126
+ // 数据只有一页时是否展示分页,true:展示,auto:隐藏
127
+ showPagination: {
128
+ type: Boolean,
129
+ default: true
130
+ },
131
+ // 调用logic获取数据源的追加参数
132
+ getDataParams: {
133
+ type: Object,
134
+ default: undefined
135
+ }
136
+ },
137
+ watch: {
138
+ logicParam: {
139
+ handler () {
140
+ this.getColumnJsonByLogic()
141
+ },
142
+ deep: true
143
+ },
144
+ fixedQueryForm: {
145
+ handler () {
146
+ this.$nextTick(() => {
147
+ this.refreshTable(true)
148
+ })
149
+ },
150
+ deep: true
151
+ },
152
+ queryParamsJson: {
153
+ handler () {
154
+ this.getColumnsJsonBySource()
155
+ },
156
+ deep: true
157
+ },
158
+ queryParamsName: {
159
+ handler () {
160
+ this.getColumnsJson()
161
+ }
162
+ }
163
+ },
164
+ created () {
165
+ if (this.queryParamsName) {
166
+ this.getColumnsJson()
167
+ } else if (this.queryParamsJson) {
168
+ this.getColumnsJsonBySource()
169
+ }
170
+ },
171
+ methods: {
172
+ getColumnsJson () {
173
+ this.loading = true
174
+ indexedDB.getByWeb(this.queryParamsName, commonApi.getColumnsJson, { str: this.queryParamsName }, (res) => {
175
+ this.updateComponents(res)
176
+ })
177
+ },
178
+ getColumnsJsonBySource () {
179
+ this.loading = true
180
+ post(commonApi.getColumnsJson, { queryObject: this.queryParamsJson }).then(res => {
181
+ this.updateComponents(res, true)
182
+ })
183
+ },
184
+ getColumnJsonByLogic () {
185
+ this.loading = true
186
+ indexedDB.getByWeb(`${this.logicName}_${JSON.stringify(this.logicParam)}`, commonApi.getColumnsJson, { logic: this.logicName, logicParam: this.logicParam }, (res) => {
187
+ this.updateComponents(res, true)
188
+ })
189
+ },
190
+ /**
191
+ * 更新子组件
192
+ * @param res 参数
193
+ * @param setQueryParams 是否设置queryParams参数
194
+ */
195
+ updateComponents (res, setQueryParams) {
196
+ this.$refs.xTable.init({
197
+ queryParams: setQueryParams ? res : null,
198
+ tableColumns: res.columnJson,
199
+ buttonState: res.buttonState,
200
+ title: this.title,
201
+ viewMode: this.viewMode,
202
+ isTableTemp: this.isTableTemp,
203
+ serviceName: res.serviceName
204
+ })
205
+ this.$refs.xForm.init({
206
+ formItems: res.formJson,
207
+ serviceName: res.serviceName
208
+ })
209
+ this.$refs.xAddForm.init({
210
+ isShow: !res.buttonState || res.buttonState.add || res.buttonState.edit,
211
+ formItems: res.formJson,
212
+ viewMode: this.viewMode,
213
+ isTableTemp: this.isTableTemp,
214
+ serviceName: res.serviceName
215
+ })
216
+ this.loading = false
217
+ },
218
+ /**
219
+ * 提交查询表单事件
220
+ * @param res 参数
221
+ */
222
+ onSearchSubmit (res) {
223
+ if (res.valid) {
224
+ // 表单赋值
225
+ this.$refs.xTable.setQueryForm(res.form)
226
+ // commit
227
+ this.$emit('afterSearchSubmit', res)
228
+ } else {
229
+ return false
230
+ }
231
+ },
232
+ /**
233
+ * 提交新增表单事件
234
+ */
235
+ onAddOrEditSubmit (res, callback) {
236
+ // 组织请求
237
+ const requestParameters = {
238
+ queryParamsName: this.queryParamsName,
239
+ form: res.realForm,
240
+ businessType: res.businessType,
241
+ operator: res.currUserName
242
+ }
243
+ addOrModify(requestParameters, this.serviceName).then(data => {
244
+ this.$message.success(res.businessType + '成功!')
245
+ this.refreshTable(res.businessType === '新增')
246
+ // commit
247
+ this.$emit('afterSubmit', { type: res.businessType, id: data.id, form: requestParameters.form })
248
+ }).catch(e => {
249
+ this.$message.error(res.businessType + '失败:' + e)
250
+ }).finally(() => {
251
+ callback()
252
+ })
253
+ },
254
+ /**
255
+ * 表格查询后事件
256
+ * @param res 参数
257
+ * @param conditionParams 查询条件
258
+ */
259
+ afterQuery (res, conditionParams) {
260
+ this.$emit('afterQuery', res, conditionParams)
261
+ },
262
+ /**
263
+ * 详情按钮事件
264
+ * @param record 本条数据
265
+ * @param id 数据标识
266
+ * @param actionType 操作类型
267
+ */
268
+ action (record, id, actionType) {
269
+ this.$emit('action', record, id, actionType)
270
+ },
271
+ /**
272
+ * 新增按钮事件
273
+ */
274
+ add () {
275
+ this.$refs.xAddForm.open({
276
+ businessType: '新增',
277
+ title: this.title,
278
+ fixedAddForm: this.fixedAddForm
279
+ })
280
+ },
281
+ /**
282
+ * 修改按钮事件
283
+ * @param res 参数
284
+ */
285
+ edit (res) {
286
+ this.$refs.xAddForm.open({
287
+ businessType: '修改',
288
+ modifyModelData: res,
289
+ title: this.title,
290
+ fixedAddForm: this.fixedAddForm
291
+ })
292
+ },
293
+ /**
294
+ * 删除后事件
295
+ * @param res
296
+ */
297
+ afterDelete (res) {
298
+ this.$emit('afterDelete', res)
299
+ },
300
+ /**
301
+ * 查询表单部分显示/隐藏切换
302
+ */
303
+ toggleIsFormShow () {
304
+ this.$refs.xForm.toggleVisible()
305
+ },
306
+ /**
307
+ * 选择列事件
308
+ * @param selectedRowKeys 选中列Key集合
309
+ * @param selectedRows 选中列
310
+ */
311
+ selectRow (selectedRowKeys, selectedRows) {
312
+ this.$emit('selectRow', selectedRowKeys, selectedRows)
313
+ },
314
+ /**
315
+ * 临时表修改
316
+ * @param res 参数
317
+ */
318
+ tempTableEdit (res) {
319
+ this.$emit('tempTableEdit', res)
320
+ },
321
+ /**
322
+ * 刷新表格
323
+ * @param toFirstPage 是否到第一页
324
+ */
325
+ refreshTable (toFirstPage = true) {
326
+ this.$refs.xTable.refresh(toFirstPage)
327
+ },
328
+ }
329
+ }
330
+ </script>
331
+ <style lang="less" scoped>
332
+
333
+ </style>