vue2-client 1.2.34 → 1.2.35

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,338 +1,338 @@
1
- <template>
2
- <a-modal
3
- :title="businessTitle"
4
- :visible="visible"
5
- :width="1000"
6
- @cancel="onClose"
7
- okText="提交"
8
- :destroyOnClose="true"
9
- :confirm-loading="loading"
10
- :zIndex="1001"
11
- @ok="onSubmit">
12
- <div class="table-page-search-wrapper">
13
- <a-form-model
14
- v-if="loaded"
15
- ref="selectForm"
16
- :model="form"
17
- :rules="rules">
18
- <a-row :gutter="16">
19
- <x-form-item
20
- v-for="(item, index) in realJsonData"
21
- mode="新增/修改"
22
- :attr="item"
23
- :form="form"
24
- :key="index"
25
- :disabled="itemDisabled(item)"
26
- :xl="12"
27
- :xxl="8"
28
- />
29
- <div v-for="group in realJsonSelectsData" :key="group[0].group">
30
- <x-form-col v-for="groupItem in group" :key="groupItem.group + groupItem.groupIndex" :xl="12" :xxl="8">
31
- <a-form-model-item :label="groupItem.name" :disabled="itemDisabled(groupItem)">
32
- <a-select v-model="form[groupItem.model]" :disabled="itemDisabledPlus(groupItem.group,groupItem.groupIndex)" :allowClear="true" @change="selectsItemCheck(groupItem.group,groupItem.groupIndex,form[groupItem.model],group)" placeholder="请选择">
33
- <template v-for="option in SelectsArray[groupItem.group][groupItem.groupIndex]">
34
- <a-select-option :key="option.label" :value="option.value">
35
- {{ option.label }}
36
- </a-select-option>
37
- </template>
38
- </a-select>
39
- </a-form-model-item>
40
- </x-form-col>
41
- </div>
42
- </a-row>
43
- </a-form-model>
44
- </div>
45
- </a-modal>
46
- </template>
47
- <script>
48
- import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormItem'
49
- import { formatDate } from '@vue2-client/utils/util'
50
- import { mapState } from 'vuex'
51
- import { post } from '@vue2-client/services/api'
52
-
53
- export default {
54
- name: 'XAddForm',
55
- components: {
56
- XFormItem
57
- },
58
- data () {
59
- return {
60
- // 内容加载是否完成
61
- loaded: false,
62
- // 表单Model
63
- form: undefined,
64
- // 多层下拉框组 数据储存
65
- SelectsArray: {},
66
- // 多层下拉框组 各组数量
67
- SelectsNumber: {},
68
- // 校验
69
- rules: {},
70
- // 图标样式
71
- iconStyle: {
72
- position: 'relative',
73
- top: '1px'
74
- }
75
- }
76
- },
77
- computed: {
78
- // 过滤出用于新增/修改场景的表单项
79
- realJsonData: function () {
80
- return this.jsonData.filter(function (item) {
81
- return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && !item.group
82
- })
83
- },
84
- // 过滤出多个下拉框分组级联得数据
85
- realJsonSelectsData: function () {
86
- const Selectsata = this.jsonData.filter(item => !item.isOnlyAddOrEdit && item.group)
87
- const groupName = [...new Set(Selectsata.map(item => item.group))]
88
- // 初始化数据组
89
- groupName.forEach(item => {
90
- this.SelectsArray[item] = []
91
- })
92
- return groupName.map(groupName => {
93
- const SelectsItem = Selectsata.filter(item => {
94
- if (item.groupIndex === 1) {
95
- if (item.keyName.substring(0, 6) === 'logic@') {
96
- // 请求logic
97
- post('/webmeterapi/' + item.keyName.substring(6), {}).then(res => {
98
- this.SelectsArray[item.group][item.groupIndex] = res
99
- })
100
- } else {
101
- this.SelectsArray[item.group][item.groupIndex] = JSON.parse(item.keyName)
102
- }
103
- }
104
- return item.group === groupName
105
- }
106
- )
107
- this.SelectsNumber[groupName] = SelectsItem.length ? SelectsItem.length : 0
108
- return SelectsItem
109
- })
110
- },
111
- // 过滤出用于静默新增场景的表单项
112
- silenceAddJsonData: function () {
113
- return this.jsonData.filter(function (item) {
114
- return item.addOrEdit === 'silenceAdd'
115
- })
116
- },
117
- // 过滤出版本号表单项
118
- versionJsonData: function () {
119
- return this.jsonData.filter(function (item) {
120
- return item.addOrEdit === 'version'
121
- })
122
- },
123
- ...mapState('account', { currUser: 'user' })
124
- },
125
- props: {
126
- jsonData: {
127
- type: Array,
128
- default: () => {
129
- return []
130
- }
131
- },
132
- // 是否显示模态框
133
- visible: {
134
- type: Boolean,
135
- default: () => {
136
- return false
137
- }
138
- },
139
- // 业务类型
140
- businessType: {
141
- type: String,
142
- default: ''
143
- },
144
- // 业务标题
145
- businessTitle: {
146
- type: String,
147
- default: ''
148
- },
149
- // 修改操作前查询出的业务数据
150
- modifyModelData: {
151
- type: Object,
152
- default: () => {
153
- return {}
154
- }
155
- },
156
- // 新增或修改业务是否执行中
157
- loading: {
158
- type: Boolean,
159
- default: () => {
160
- return false
161
- }
162
- },
163
- // 固定新增表单
164
- fixedAddForm: {
165
- type: Object,
166
- default: () => {
167
- return {}
168
- }
169
- }
170
- },
171
- watch: {
172
- visible (rel) {
173
- if (rel) {
174
- this.formItemLoad()
175
- }
176
- }
177
- },
178
- mounted () {
179
- this.formItemLoad()
180
- },
181
- methods: {
182
- selectsItemCheck (groupName, index, value, group) {
183
- const tem = { }
184
- // 获取当前下拉框子下拉框的数据
185
- this.SelectsArray[groupName][index + 1] = this.SelectsArray[groupName][index].filter(item => item.value === value)[0].children
186
- // 清空子下拉框的子们的数据
187
- for (let i = index; i < this.SelectsNumber[groupName]; i++) {
188
- tem[group[i].model] = undefined
189
- }
190
- this.form = Object.assign({}, this.form, tem)
191
- // 清空子下拉框的子们的数据源
192
- for (let i = index + 2; i <= this.SelectsNumber[groupName]; i++) {
193
- this.SelectsArray[groupName][i] = []
194
- }
195
- },
196
- formItemLoad () {
197
- const formData = Object.assign({}, this.fixedAddForm)
198
- for (let i = 0; i < this.realJsonData.length; i++) {
199
- const item = this.realJsonData[i]
200
- formData[item.model] = undefined
201
- // 处理表单校验情况
202
- if (item.rule) {
203
- this.rules[item.model] = []
204
- const required = item.rule.required ? item.rule.required === true || item.rule.required === 'true' : false
205
- let trigger
206
- let message
207
- if (required) {
208
- switch (item.type) {
209
- case 'select':
210
- message = '请选择' + item.name
211
- trigger = 'change'
212
- break
213
- default:
214
- message = '请输入' + item.name
215
- trigger = 'blur'
216
- }
217
- this.rules[item.model].push({
218
- required: true,
219
- message: message,
220
- trigger: trigger
221
- })
222
- }
223
-
224
- switch (item.rule.type) {
225
- case 'number':
226
- case 'integer':
227
- case 'float':
228
- let defaultValue
229
- let message
230
- switch (item.rule.type) {
231
- case 'number':
232
- message = '数字'
233
- defaultValue = 0
234
- break
235
- case 'integer':
236
- message = '整数'
237
- defaultValue = 0
238
- break
239
- case 'float':
240
- message = '小数'
241
- defaultValue = 0.0
242
- break
243
- }
244
- this.rules[item.model].push({
245
- type: item.rule.type,
246
- message: item.name + '必须为' + message,
247
- transform: (value) => {
248
- if (value && value.length !== 0) {
249
- return Number(value)
250
- } else {
251
- return defaultValue
252
- }
253
- },
254
- trigger: 'blur'
255
- })
256
- break
257
- }
258
- }
259
- }
260
- this.form = formData
261
- if (Object.keys(this.modifyModelData).length > 0) {
262
- this.getModifyModelData()
263
- }
264
- this.loaded = true
265
- },
266
- itemDisabled (value) {
267
- return (this.businessType === '新增' && value.addOrEdit === 'edit') ||
268
- (this.businessType === '修改' && value.addOrEdit === 'add')
269
- },
270
- itemDisabledPlus (group, index) {
271
- return (!this.SelectsArray[group][index]) || (this.SelectsArray[group][index] && this.SelectsArray[group][index].length === 0)
272
- },
273
- resetForm () {
274
- this.$refs.selectForm.resetFields()
275
- },
276
- async onSubmit () {
277
- this.$refs.selectForm.validate(async valid => {
278
- for (const key of Object.keys(this.form)) {
279
- if (this.form[key] === null || this.form[key] === '') {
280
- this.form[key] = undefined
281
- }
282
- }
283
- const requestParameters = Object.assign({}, this.form)
284
- // 追加静默新增字段
285
- if (this.businessType === '新增') {
286
- for (const item of this.silenceAddJsonData) {
287
- switch (item.silencePurpose) {
288
- case 'createTime':
289
- requestParameters[item.model] = formatDate('now')
290
- break
291
- case 'operator':
292
- requestParameters[item.model] = this.currUser.name
293
- break
294
- case 'orgId':
295
- requestParameters[item.model] = this.currUser.orgid
296
- break
297
- }
298
- }
299
- // 通过请求追加静默新增:自定义字段
300
- for (const item of this.silenceAddJsonData.filter((item) => item.silencePurpose === 'customize')) {
301
- requestParameters[item.model] = await this.getSilenceSource(item.silenceSource, requestParameters)
302
- }
303
- }
304
- const data = {
305
- valid: valid,
306
- form: requestParameters
307
- }
308
- this.$emit('onSubmit', data)
309
- })
310
- },
311
- async getSilenceSource (silenceSource, requestParameters) {
312
- const result = await post('/webmeterapi/' + silenceSource, requestParameters)
313
- return result
314
- },
315
- getModifyModelData () {
316
- for (let i = 0; i < this.realJsonData.length; i++) {
317
- const item = this.realJsonData[i]
318
- if (this.modifyModelData[item.model] || this.modifyModelData[item.model] === 0) {
319
- this.form[item.model] = this.modifyModelData[item.model] + ''
320
- } else {
321
- this.form[item.model] = undefined
322
- }
323
- }
324
- // 追加版本号信息
325
- for (const item of this.versionJsonData) {
326
- if (!this.modifyModelData[item.model]) {
327
- this.form[item.model] = 0
328
- } else {
329
- this.form[item.model] = this.modifyModelData[item.model] + ''
330
- }
331
- }
332
- },
333
- onClose () {
334
- this.$emit('update:visible', false)
335
- }
336
- }
337
- }
338
- </script>
1
+ <template>
2
+ <a-modal
3
+ :title="businessTitle"
4
+ :visible="visible"
5
+ :width="1000"
6
+ @cancel="onClose"
7
+ okText="提交"
8
+ :destroyOnClose="true"
9
+ :confirm-loading="loading"
10
+ :zIndex="1001"
11
+ @ok="onSubmit">
12
+ <div class="table-page-search-wrapper">
13
+ <a-form-model
14
+ v-if="loaded"
15
+ ref="selectForm"
16
+ :model="form"
17
+ :rules="rules">
18
+ <a-row :gutter="16">
19
+ <x-form-item
20
+ v-for="(item, index) in realJsonData"
21
+ mode="新增/修改"
22
+ :attr="item"
23
+ :form="form"
24
+ :key="index"
25
+ :disabled="itemDisabled(item)"
26
+ :xl="12"
27
+ :xxl="8"
28
+ />
29
+ <div v-for="group in realJsonSelectsData" :key="group[0].group">
30
+ <x-form-col v-for="groupItem in group" :key="groupItem.group + groupItem.groupIndex" :xl="12" :xxl="8">
31
+ <a-form-model-item :label="groupItem.name" :disabled="itemDisabled(groupItem)">
32
+ <a-select v-model="form[groupItem.model]" :disabled="itemDisabledPlus(groupItem.group,groupItem.groupIndex)" :allowClear="true" @change="selectsItemCheck(groupItem.group,groupItem.groupIndex,form[groupItem.model],group)" placeholder="请选择">
33
+ <template v-for="option in SelectsArray[groupItem.group][groupItem.groupIndex]">
34
+ <a-select-option :key="option.label" :value="option.value">
35
+ {{ option.label }}
36
+ </a-select-option>
37
+ </template>
38
+ </a-select>
39
+ </a-form-model-item>
40
+ </x-form-col>
41
+ </div>
42
+ </a-row>
43
+ </a-form-model>
44
+ </div>
45
+ </a-modal>
46
+ </template>
47
+ <script>
48
+ import XFormItem from '@vue2-client/base-client/components/common/XForm/XFormItem'
49
+ import { formatDate } from '@vue2-client/utils/util'
50
+ import { mapState } from 'vuex'
51
+ import { post } from '@vue2-client/services/api'
52
+
53
+ export default {
54
+ name: 'XAddForm',
55
+ components: {
56
+ XFormItem
57
+ },
58
+ data () {
59
+ return {
60
+ // 内容加载是否完成
61
+ loaded: false,
62
+ // 表单Model
63
+ form: undefined,
64
+ // 多层下拉框组 数据储存
65
+ SelectsArray: {},
66
+ // 多层下拉框组 各组数量
67
+ SelectsNumber: {},
68
+ // 校验
69
+ rules: {},
70
+ // 图标样式
71
+ iconStyle: {
72
+ position: 'relative',
73
+ top: '1px'
74
+ }
75
+ }
76
+ },
77
+ computed: {
78
+ // 过滤出用于新增/修改场景的表单项
79
+ realJsonData: function () {
80
+ return this.jsonData.filter(function (item) {
81
+ return item.addOrEdit && item.addOrEdit !== 'no' && item.addOrEdit !== 'silenceAdd' && !item.group
82
+ })
83
+ },
84
+ // 过滤出多个下拉框分组级联得数据
85
+ realJsonSelectsData: function () {
86
+ const Selectsata = this.jsonData.filter(item => !item.isOnlyAddOrEdit && item.group)
87
+ const groupName = [...new Set(Selectsata.map(item => item.group))]
88
+ // 初始化数据组
89
+ groupName.forEach(item => {
90
+ this.SelectsArray[item] = []
91
+ })
92
+ return groupName.map(groupName => {
93
+ const SelectsItem = Selectsata.filter(item => {
94
+ if (item.groupIndex === 1) {
95
+ if (item.keyName.substring(0, 6) === 'logic@') {
96
+ // 请求logic
97
+ post('/webmeterapi/' + item.keyName.substring(6), {}).then(res => {
98
+ this.SelectsArray[item.group][item.groupIndex] = res
99
+ })
100
+ } else {
101
+ this.SelectsArray[item.group][item.groupIndex] = JSON.parse(item.keyName)
102
+ }
103
+ }
104
+ return item.group === groupName
105
+ }
106
+ )
107
+ this.SelectsNumber[groupName] = SelectsItem.length ? SelectsItem.length : 0
108
+ return SelectsItem
109
+ })
110
+ },
111
+ // 过滤出用于静默新增场景的表单项
112
+ silenceAddJsonData: function () {
113
+ return this.jsonData.filter(function (item) {
114
+ return item.addOrEdit === 'silenceAdd'
115
+ })
116
+ },
117
+ // 过滤出版本号表单项
118
+ versionJsonData: function () {
119
+ return this.jsonData.filter(function (item) {
120
+ return item.addOrEdit === 'version'
121
+ })
122
+ },
123
+ ...mapState('account', { currUser: 'user' })
124
+ },
125
+ props: {
126
+ jsonData: {
127
+ type: Array,
128
+ default: () => {
129
+ return []
130
+ }
131
+ },
132
+ // 是否显示模态框
133
+ visible: {
134
+ type: Boolean,
135
+ default: () => {
136
+ return false
137
+ }
138
+ },
139
+ // 业务类型
140
+ businessType: {
141
+ type: String,
142
+ default: ''
143
+ },
144
+ // 业务标题
145
+ businessTitle: {
146
+ type: String,
147
+ default: ''
148
+ },
149
+ // 修改操作前查询出的业务数据
150
+ modifyModelData: {
151
+ type: Object,
152
+ default: () => {
153
+ return {}
154
+ }
155
+ },
156
+ // 新增或修改业务是否执行中
157
+ loading: {
158
+ type: Boolean,
159
+ default: () => {
160
+ return false
161
+ }
162
+ },
163
+ // 固定新增表单
164
+ fixedAddForm: {
165
+ type: Object,
166
+ default: () => {
167
+ return {}
168
+ }
169
+ }
170
+ },
171
+ watch: {
172
+ visible (rel) {
173
+ if (rel) {
174
+ this.formItemLoad()
175
+ }
176
+ }
177
+ },
178
+ mounted () {
179
+ this.formItemLoad()
180
+ },
181
+ methods: {
182
+ selectsItemCheck (groupName, index, value, group) {
183
+ const tem = { }
184
+ // 获取当前下拉框子下拉框的数据
185
+ this.SelectsArray[groupName][index + 1] = this.SelectsArray[groupName][index].filter(item => item.value === value)[0].children
186
+ // 清空子下拉框的子们的数据
187
+ for (let i = index; i < this.SelectsNumber[groupName]; i++) {
188
+ tem[group[i].model] = undefined
189
+ }
190
+ this.form = Object.assign({}, this.form, tem)
191
+ // 清空子下拉框的子们的数据源
192
+ for (let i = index + 2; i <= this.SelectsNumber[groupName]; i++) {
193
+ this.SelectsArray[groupName][i] = []
194
+ }
195
+ },
196
+ formItemLoad () {
197
+ const formData = Object.assign({}, this.fixedAddForm)
198
+ for (let i = 0; i < this.realJsonData.length; i++) {
199
+ const item = this.realJsonData[i]
200
+ formData[item.model] = undefined
201
+ // 处理表单校验情况
202
+ if (item.rule) {
203
+ this.rules[item.model] = []
204
+ const required = item.rule.required ? item.rule.required === true || item.rule.required === 'true' : false
205
+ let trigger
206
+ let message
207
+ if (required) {
208
+ switch (item.type) {
209
+ case 'select':
210
+ message = '请选择' + item.name
211
+ trigger = 'change'
212
+ break
213
+ default:
214
+ message = '请输入' + item.name
215
+ trigger = 'blur'
216
+ }
217
+ this.rules[item.model].push({
218
+ required: true,
219
+ message: message,
220
+ trigger: trigger
221
+ })
222
+ }
223
+
224
+ switch (item.rule.type) {
225
+ case 'number':
226
+ case 'integer':
227
+ case 'float':
228
+ let defaultValue
229
+ let message
230
+ switch (item.rule.type) {
231
+ case 'number':
232
+ message = '数字'
233
+ defaultValue = 0
234
+ break
235
+ case 'integer':
236
+ message = '整数'
237
+ defaultValue = 0
238
+ break
239
+ case 'float':
240
+ message = '小数'
241
+ defaultValue = 0.0
242
+ break
243
+ }
244
+ this.rules[item.model].push({
245
+ type: item.rule.type,
246
+ message: item.name + '必须为' + message,
247
+ transform: (value) => {
248
+ if (value && value.length !== 0) {
249
+ return Number(value)
250
+ } else {
251
+ return defaultValue
252
+ }
253
+ },
254
+ trigger: 'blur'
255
+ })
256
+ break
257
+ }
258
+ }
259
+ }
260
+ this.form = formData
261
+ if (Object.keys(this.modifyModelData).length > 0) {
262
+ this.getModifyModelData()
263
+ }
264
+ this.loaded = true
265
+ },
266
+ itemDisabled (value) {
267
+ return (this.businessType === '新增' && value.addOrEdit === 'edit') ||
268
+ (this.businessType === '修改' && value.addOrEdit === 'add')
269
+ },
270
+ itemDisabledPlus (group, index) {
271
+ return (!this.SelectsArray[group][index]) || (this.SelectsArray[group][index] && this.SelectsArray[group][index].length === 0)
272
+ },
273
+ resetForm () {
274
+ this.$refs.selectForm.resetFields()
275
+ },
276
+ async onSubmit () {
277
+ this.$refs.selectForm.validate(async valid => {
278
+ for (const key of Object.keys(this.form)) {
279
+ if (this.form[key] === null || this.form[key] === '') {
280
+ this.form[key] = undefined
281
+ }
282
+ }
283
+ const requestParameters = Object.assign({}, this.form)
284
+ // 追加静默新增字段
285
+ if (this.businessType === '新增') {
286
+ for (const item of this.silenceAddJsonData) {
287
+ switch (item.silencePurpose) {
288
+ case 'createTime':
289
+ requestParameters[item.model] = formatDate('now')
290
+ break
291
+ case 'operator':
292
+ requestParameters[item.model] = this.currUser.name
293
+ break
294
+ case 'orgId':
295
+ requestParameters[item.model] = this.currUser.orgid
296
+ break
297
+ }
298
+ }
299
+ // 通过请求追加静默新增:自定义字段
300
+ for (const item of this.silenceAddJsonData.filter((item) => item.silencePurpose === 'customize')) {
301
+ requestParameters[item.model] = await this.getSilenceSource(item.silenceSource, requestParameters)
302
+ }
303
+ }
304
+ const data = {
305
+ valid: valid,
306
+ form: requestParameters
307
+ }
308
+ this.$emit('onSubmit', data)
309
+ })
310
+ },
311
+ async getSilenceSource (silenceSource, requestParameters) {
312
+ const result = await post('/webmeterapi/' + silenceSource, requestParameters)
313
+ return result
314
+ },
315
+ getModifyModelData () {
316
+ for (let i = 0; i < this.realJsonData.length; i++) {
317
+ const item = this.realJsonData[i]
318
+ if (this.modifyModelData[item.model] || this.modifyModelData[item.model] === 0) {
319
+ this.form[item.model] = this.modifyModelData[item.model] + ''
320
+ } else {
321
+ this.form[item.model] = undefined
322
+ }
323
+ }
324
+ // 追加版本号信息
325
+ for (const item of this.versionJsonData) {
326
+ if (!this.modifyModelData[item.model]) {
327
+ this.form[item.model] = 0
328
+ } else {
329
+ this.form[item.model] = this.modifyModelData[item.model] + ''
330
+ }
331
+ }
332
+ },
333
+ onClose () {
334
+ this.$emit('update:visible', false)
335
+ }
336
+ }
337
+ }
338
+ </script>