vue2-client 1.4.64 → 1.5.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,782 +1,713 @@
1
- <template>
2
- <a-modal
3
- :destroyOnClose="true"
4
- :visible="visible"
5
- :width="1250"
6
- :zIndex="1001"
7
- title="数据字段配置"
8
- @cancel="modelCancel"
9
- @ok="submitItem">
10
- <a-form-model
11
- ref="itemForm"
12
- :model="item"
13
- :rules="itemRules"
14
- layout="vertical">
15
- <a-row :gutter="16">
16
- <a-col :span="6">
17
- <a-card :bodyStyle="bodyStyle" title="基本属性">
18
- <a-divider style="font-size: 14px;margin-top: 0">字段信息</a-divider>
19
- <a-form-model-item label="标签名称" prop="title">
20
- <a-input v-model="item.title" placeholder="请输入标签名称"/>
21
- </a-form-model-item>
22
- <a-form-model-item
23
- label="字段名称"
24
- prop="key">
25
- <a-input ref="key" v-model="item.key" :disabled="keyDisabled" placeholder="请输入字段名">
26
- <a-popover slot="suffix" placement="bottom" title="关于字段名称">
27
- <template slot="content">
28
- <p>设置数据字段的名称</p>
29
- <p>用作SQL查询时为<span style="font-weight: bold">表别名.数据列名</span>的格式,如:i.id</p>
30
- </template>
31
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
32
- </a-popover>
33
- </a-input>
34
- </a-form-model-item>
35
- <a-form-model-item
36
- v-if="item.formType ==='addressSearch'"
37
- label="坐标字段名">
38
- <a-input :disabled="true" :value="`${item.key}_lng_lat`">
39
- <a-popover slot="suffix" placement="bottom" title="坐标字段名">
40
- <template slot="content">
41
- <p>表单类型为地点搜索框时:</p>
42
- <p>新增/修改表单内,字段名称会存放地址名称,坐标字段名会存放坐标信息</p>
43
- </template>
44
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
45
- </a-popover>
46
- </a-input>
47
- </a-form-model-item>
48
- <a-divider style="font-size: 14px;margin-top: 0">数据模式</a-divider>
49
- <a-form-model-item
50
- prop="dataMode"
51
- style="margin-top: 10px;">
52
- <a-checkbox-group v-model="dataModeArrayData" :disabled="dataModeDisabled" :options="dataModeTypeV"/>
53
- </a-form-model-item>
54
- </a-card>
55
- </a-col>
56
- <a-col :span="9">
57
- <a-card v-if="dataMode.queryForm || dataMode.addOrEditForm || dataMode.table" :bodyStyle="bodyStyle" title="核心配置">
58
- <template v-if="dataMode.queryForm || dataMode.addOrEditForm">
59
- <a-divider style="font-size: 14px;margin-top: 0">表单配置</a-divider>
60
- <a-form-model-item label="表单类型" prop="formType">
61
- <a-select v-model="item.formType" placeholder="请选择表单类型" @change="changeFormType(item)">
62
- <a-select-option v-for="formTypeItem in formType" :key="formTypeItem.key">{{ formTypeItem.label }}</a-select-option>
63
- </a-select>
64
- </a-form-model-item>
65
- <template v-if="item.formType">
66
- <a-form-model-item v-if="dataMode.sqlQueryCondition && item.formType !=='file' && item.formType !=='image' " label="表单查询方式" prop="queryType">
67
- <a-select
68
- v-model="item.queryType"
69
- :disabled="formQueryTypeDisabled"
70
- :getPopupContainer=" triggerNode => { return triggerNode.parentNode } "
71
- placeholder="表单查询方式">
72
- <a-select-option v-for="queryTypeItem in queryTypeV" :key="queryTypeItem.key">{{ queryTypeItem.label }}</a-select-option>
73
- </a-select>
74
- </a-form-model-item>
75
- <a-form-model-item v-if="dataMode.addOrEditForm" label="表单校验" prop="rule">
76
- <a-row :gutter="16">
77
- <a-col v-if="(item.formType === 'input' || item.formType === 'textarea' ) && item.formType !=='file' && item.formType !=='image' " :span="12" >
78
- <a-select v-model="item.rule.type" :getPopupContainer=" triggerNode => { return triggerNode.parentNode } " placeholder="校验类型">
79
- <a-select-option v-for="ruleTypeItem in formRuleType" :key="ruleTypeItem.key">{{ ruleTypeItem.label }}</a-select-option>
80
- <a-popover slot="suffixIcon" placement="bottom" title="关于表单校验类型">
81
- <template slot="content">
82
- <p>设置表单项的校验类型</p>
83
- </template>
84
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
85
- </a-popover>
86
- </a-select>
87
- </a-col>
88
- <a-col :span="12">
89
- <a-radio-group v-model="item.rule.required" button-style="solid" default-value="false">
90
- <a-radio-button value="true">
91
- 必选项
92
- </a-radio-button>
93
- <a-radio-button value="false">
94
- 非必选项
95
- </a-radio-button>
96
- </a-radio-group>
97
- </a-col>
98
- </a-row>
99
- </a-form-model-item>
100
- <a-form-model-item v-if="dataMode.addOrEditForm" label="新增/修改场景选择" prop="addOrEdit">
101
- <a-select v-model="item.addOrEdit" placeholder="请选择场景">
102
- <a-select-option v-for="addOrEditItem in addOrEditTypeV" :key="addOrEditItem.key">{{ addOrEditItem.label }}</a-select-option>
103
- <a-popover
104
- slot="suffixIcon"
105
- placement="bottom"
106
- title="关于新增/修改场景选择">
107
- <template slot="content">
108
- <p>设置表单项的新增/修改场景</p>
109
- <p>静默新增类型用于非人为新增的数据,不会生成表单项,且必须设置字段用途</p>
110
- </template>
111
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
112
- </a-popover>
113
- </a-select>
114
- </a-form-model-item>
115
- <a-form-model-item v-if="item.addOrEdit === 'silenceAdd'" label="字段用途" prop="silencePurpose">
116
- <a-select v-model="item.silencePurpose" :getPopupContainer=" triggerNode => { return triggerNode.parentNode } " placeholder="请选择字段用途">
117
- <a-select-option v-for="silencePurposeTypeItem in silencePurposeType" :key="silencePurposeTypeItem.key">{{ silencePurposeTypeItem.label }}</a-select-option>
118
- <a-popover
119
- slot="suffixIcon"
120
- placement="bottom"
121
- title="关于字段用途">
122
- <template slot="content">
123
- <p>用于静默新增时设置字段用途</p>
124
- <p>在新增数据的表单提交时,页面会根据设置的字段用途自动获取相关数据并追加到表单中</p>
125
- <p>当字段用途选择为<span style="font-weight: bold">自定义</span>时,必须指定一个业务逻辑(Logic)名称,表单提交前会将表单内容作为参数调用该Logic接口,并将Logic返回值作为表单值
126
- </p>
127
- </template>
128
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
129
- </a-popover>
130
- </a-select>
131
- </a-form-model-item>
132
- <a-form-model-item v-if="item.silencePurpose === 'customize'" label="字段用途对应Logic" prop="silenceSource">
133
- <a-input v-model="item.silenceSource" placeholder="请输入业务逻辑名称"/>
134
- </a-form-model-item>
135
- </template>
136
- </template>
137
- <template v-if="dataMode.table">
138
- <a-divider style="font-size: 14px;margin-top: 0">表格列配置</a-divider>
139
- <a-form-model-item v-if="item.formType" label="作用域插槽" prop="slot">
140
- <a-select v-model="item.slot.type" :disabled="slotTypeDisabled" :getPopupContainer=" triggerNode => { return triggerNode.parentNode } " placeholder="插槽类型">
141
- <a-select-option v-for="slotTypeItem in slotTypeV" :key="slotTypeItem.key">{{ slotTypeItem.label }}</a-select-option>
142
- <a-popover slot="suffixIcon" placement="bottom" title="关于作用域插槽">
143
- <template slot="content">
144
- <p>你可以通过设置表格列的作用域插槽实现一些效果</p>
145
- <p>如果没有指定,默认会设置为文本溢出省略(长度:16)</p>
146
- <p>如果你选择文本溢出省略,需要设置文本溢出上限长度,建议ID主键等类型设置为8</p>
147
- <p>如果你选择多彩徽标,需要设置徽标对应的数据样式字典键</p>
148
- <a-divider style="font-size: 14px;margin-top: 0">关于表格列宽度</a-divider>
149
- <p>V1.1之后不再支持自定义表格列宽度,表格列宽度将通过作用域插槽类型自适应</p>
150
- <p>设置为文本溢出省略时,表格列宽度 = 文本溢出上限长度 * 7 + 42</p>
151
- <p>设置为多彩徽标时,表格列宽度为130</p>
152
- <p>设置为日期时间格式化时,表格列宽度为160</p>
153
- </template>
154
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
155
- </a-popover>
156
- </a-select>
157
- </a-form-model-item>
158
- <a-form-model-item v-if="item.slot.type === 'badge'" label="徽标字典键" prop="slot.keyMap">
159
- <a-input v-model="item.slot.keyMap" :disabled="slotTypeDisabled" placeholder="请输入徽标字典键">
160
- <a-popover
161
- slot="suffix"
162
- placement="bottom"
163
- title="关于徽标字典键">
164
- <template slot="content">
165
- <p>如果你设置了表单类型为选择框,且数据源是字典键,该值会自动带出</p>
166
- </template>
167
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
168
- </a-popover>
169
- </a-input>
170
- </a-form-model-item>
171
- <a-form-model-item v-if="item.slot.type === 'ellipsis'" label="文本溢出上限长度" prop="slot.value">
172
- <a-input-number v-model="item.slot.value" placeholder="请输入文本溢出上限长度" style="width: 100%"/>
173
- </a-form-model-item>
174
- <a-form-model-item v-if="item.slot.type === 'action'" label="操作列文本" prop="slot.actionText">
175
- <a-input v-model="item.slot.actionText" placeholder="请输入操作列显示文本,默认为详情"/>
176
- </a-form-model-item>
177
- <a-form-model-item v-if="dataMode.sqlQueryItem || dataMode.sqlQueryCondition" label="字段默认值" prop="default">
178
- <a-input v-model="item.default" placeholder="当查询结果为null时,指定默认值"/>
179
- </a-form-model-item>
180
- </template>
181
- </a-card>
182
- </a-col>
183
- <a-col v-if="item.formType" :span="9">
184
- <a-card :bodyStyle="bodyStyle" title="扩展属性">
185
- <template v-if="(dataMode.addOrEditForm || dataMode.queryForm ) && (item.formType === 'input' || item.formType === 'select' || item.formType === 'selects' || item.formType === 'cascader')">
186
- <a-divider style="font-size: 14px;margin-top: 0">提示相关</a-divider>
187
- <a-form-model-item label="表单水印" prop="placeholder">
188
- <a-input v-model="item.placeholder" placeholder="表单水印(placeholder)" />
189
- </a-form-model-item>
190
- </template>
191
- <template v-if="item.formType === 'selects'">
192
- <a-divider style="font-size: 14px;margin-top: 0">级联选择相关</a-divider>
193
- <a-form-model-item label="是否根节点" prop="groupIndexView">
194
- <a-radio-group
195
- v-model="item.groupIndexView"
196
- button-style="solid"
197
- @change="groupIndexChange">
198
- <a-radio-button value="1">
199
-
200
- </a-radio-button>
201
- <a-radio-button value="0">
202
-
203
- </a-radio-button>
204
- </a-radio-group>
205
- </a-form-model-item>
206
- <a-form-model-item v-if="item.groupIndexView === '0' && item.groupIndex !== -1" label="所属父级联动框" prop="groupIndex">
207
- <a-select
208
- ref="groupIndex"
209
- v-model="item.parent_title"
210
- :getPopupContainer=" triggerNode => { return triggerNode.parentNode } "
211
- placeholder="请选择父级联动框"
212
- @change="parent_title_change">
213
- <a-select-option v-for="parent_item in parent_node" :key="parent_item.key">
214
- {{ parent_item.title }}
215
- </a-select-option>
216
- </a-select>
217
- </a-form-model-item>
218
- </template>
219
- <template v-if="selectDataShow">
220
- <a-divider style="font-size: 14px;margin-top: 0">数据源相关</a-divider>
221
- <a-form-model-item label="数据源类型" prop="selectType">
222
- <a-select v-model="item.selectType" placeholder="请选择数据源类型" @change="changeSelectKType">
223
- <a-select-option v-for="selectDataTypeItem in selectDataType.filter(h=>!h.noMatch.includes(item.formType))" :key="selectDataTypeItem.key">{{ selectDataTypeItem.label }}</a-select-option>
224
- <a-popover
225
- slot="suffixIcon"
226
- placement="bottom"
227
- title="关于数据源类型">
228
- <template slot="content">
229
- <p>设置数据源</p>
230
- <p>数据源类型分为三种,你可以根据需要选择</p>
231
- <p>字典键:选项从字典表(t_dictionary)获取,你只需要选择字典键的名称即可</p>
232
- <p>业务逻辑名称:选项通过发起http请求调用指定的业务逻辑(Logic)接口获取</p>
233
- <p>固定集合:选项为静态值,JSONArray格式</p>
234
- <p>当表单为级联选择框或树形选择框类型时,返回的数据需按照以下形式:</p>
235
- <json-viewer
236
- :expand-depth="parseInt('100')"
237
- :value="DemoJson"
238
- style="overflow: auto;max-height: 440px"></json-viewer>
239
- </template>
240
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
241
- </a-popover>
242
- </a-select>
243
- </a-form-model-item>
244
- <a-form-model-item v-if="item.selectType" label="数据源" prop="selectKey">
245
- <a-select
246
- v-if="item.selectType === 'key'"
247
- v-model="item.selectKey"
248
- :filter-option="filterOption"
249
- placeholder="请选择字典键"
250
- show-search
251
- @change="changeSelectKey(item)">
252
- <template>
253
- <a-select-option
254
- v-for="(optionItem,index) in option"
255
- :key="index"
256
- :value="Object.keys(optionItem)[0]">{{ optionItem[Object.keys(optionItem)[0]] }}
257
- </a-select-option>
258
- </template>
259
- </a-select>
260
- <a-input v-if="item.selectType === 'logic'" v-model="item.selectKey" placeholder="请输入业务逻辑名称"/>
261
- <a-textarea v-if="item.selectType === 'fixArray'" v-model="item.selectKey" placeholder="请录入数据源"/>
262
- </a-form-model-item>
263
- <a-form-model-item v-if="item.selectType === 'logic' && item.formType !== 'treeSelect'" label="数据源加载方式" prop="selectLoadType">
264
- <a-radio-group v-model="item.lazyLoad" button-style="solid" default-value="false">
265
- <a-radio-button value="true">
266
- 懒加载搜索
267
- </a-radio-button>
268
- <a-radio-button value="false">
269
- 一次性加载
270
- </a-radio-button>
271
- </a-radio-group>
272
- </a-form-model-item>
273
- </template>
274
- <a-form-model-item v-if="selectDataShow || item.groupIndexView" label="关联外键字段" prop="selectKeyName">
275
- <a-input v-model="item.selectKeyName" placeholder="该列关联的外键字段">
276
- <a-popover slot="suffix" placement="bottom" title="关于关联外键字段">
277
- <template slot="content">
278
- <p><span style="font-weight: bold;"><span style="color: #FF0036">非必需的实验性功能:</span>设置该参数需开发岗指导</span></p>
279
- <p>当字段与主子表外键有关系时,你可以指定<span style="font-weight: bold">该列所关联的外键字段名</span>
280
- </p>
281
- <p>设置该参数是为了该字段用作表单查询时,系统可以通过设置的关联外键字段,而非字面值作为查询条件</p>
282
- <p>示例:</p>
283
- <p>主表为t_userfiles(表档案)表,别名为u,与t_gasbrand(气表品牌表)有关联关系,别名为g,为了显示表档案对应的气表品牌数据,我们将数据字段名设置为g.f_gasbrand</p>
284
- <p>这样我们就可以在table中看到气表品牌了,但是用户如果通过气表品牌下拉框进行筛选,我们指定的g.f_gasbrand只是气表品牌的值,而实际关联字段是u.f_gasbrand_id</p>
285
- <p>所以如果我们指定了关联外键字段u.f_gasbrand_id,系统则会使用u.f_gasbrand_id筛选数据,而不是g.f_gasbrand,从而优化了查询效率
286
- </p>
287
- </template>
288
- <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
289
- </a-popover>
290
- </a-input>
291
- </a-form-model-item>
292
- <template v-if="item.formType === 'file' || item.formType === 'image'">
293
- <a-divider style="font-size: 14px;margin-top: 0">文件上传相关</a-divider>
294
- <a-form-model-item label="允许上传文件数量" prop="accept" style="margin-bottom: 5px;">
295
- <a-slider
296
- v-model="item.acceptCount"
297
- :marks="{ 1: '1', 3: '3', 5: '5', 10: '10', 15: '15', 20: '20'}"
298
- :max="20"
299
- :min="1"
300
- />
301
- </a-form-model-item>
302
- <a-form-model-item label="附件用途" prop="useType">
303
- <a-select v-model="item.useType" placeholder="指定文件用途,同表单不同用途">
304
- <a-select-option v-for="userTypeItem in $appdata.getDictionaryList('useType')" :key="userTypeItem.value">{{ userTypeItem.value }}</a-select-option>
305
- </a-select>
306
- </a-form-model-item>
307
- <a-form-model-item label="上传的仓库" prop="resUploadStock">
308
- <a-select v-model="item.resUploadStock" placeholder="选择文件上传到的仓库" @change="changeStock">
309
- <a-select-option v-for="stock in stockList" :key="stock.id">{{ stock.f_name }}</a-select-option>
310
- </a-select>
311
- </a-form-model-item>
312
- <a-form-model-item v-if="item.resUploadStock" label="具体路径" prop="pathKey">
313
- <a-select v-model="item.pathKey" placeholder="仓库扩展路径">
314
- <a-select-option v-for="pathKey in lowerPath" :key="pathKey.label">{{ pathKey.label }}</a-select-option>
315
- </a-select>
316
- </a-form-model-item>
317
- <a-form-model-item v-if="item.formType === 'file'" label="允许上传文件类型" prop="accept">
318
- <a-select v-model="item.accept" mode="tags" placeholder="指定文件类型,默认不限制" @change="itemAcceptChange">
319
- <a-select-option v-for="type_item in fileType" :key="type_item.accept">{{ type_item.label }}</a-select-option>
320
- </a-select>
321
- </a-form-model-item>
322
- </template>
323
- </a-card>
324
- </a-col>
325
- </a-row>
326
- <a-alert
327
- v-if="dataModeArrayData.length === 0"
328
- message="错误:请至少选择一种数据模式"
329
- show-icon
330
- style="margin-top: 5px"
331
- type="error"/>
332
- <a-alert
333
- v-if="dataMode.addOrEditForm && !dataMode.sqlQueryItem && item.formType !== 'file' && item.formType !== 'image' && item.formType !== 'personSetting' && item.formType !== 'cascader' "
334
- message="错误:如果要生成新增/修改表单项,必须勾选生成SQL查询项"
335
- show-icon
336
- style="margin-top: 5px"
337
- type="error"/>
338
- <a-alert
339
- v-if="dataMode.queryForm && !dataMode.sqlQueryCondition"
340
- message="提示:您没有勾选生成SQL查询表达式,渲染的表单项不会生成SQL查询条件"
341
- show-icon
342
- style="margin-top: 5px"
343
- type="info"/>
344
- <a-alert
345
- v-if="dataMode.table && !dataMode.sqlQueryItem"
346
- message="提示:您没有勾选生成SQL查询项,渲染的表格列不会绑定SQL结果集数据"
347
- show-icon
348
- style="margin-top: 5px"
349
- type="info"/>
350
- </a-form-model>
351
- </a-modal>
352
- </template>
353
-
354
- <script>
355
- import {
356
- dataModeType,
357
- fileType,
358
- formRuleType,
359
- formType,
360
- queryType,
361
- slotType,
362
- silencePurposeType,
363
- addOrEditType,
364
- selectDataType
365
- } from '@vue2-client/config/CreateQueryConfig'
366
- import { commonApi, post } from '@vue2-client/services/api'
367
- import JsonViewer from 'vue-json-viewer'
368
-
369
- const DemoJson = [{
370
- value: 'zhejiang',
371
- label: 'Zhejiang',
372
- children: [{ value: 'hangzhou', label: 'Hangzhou', children: [{ value: 'xihu', label: 'West Lake' }] }]
373
- }]
374
-
375
- export default {
376
- name: 'CreateQueryItem',
377
- components: {
378
- JsonViewer
379
- },
380
- computed: {
381
- // 是否展示数据源相关字段
382
- selectDataShow () {
383
- return this.item.formType === 'select' || this.item.formType === 'cascader' || (this.item.formType === 'selects' && this.item.groupIndexView === '1') || this.item.formType === 'checkbox' || this.item.formType === 'radio' || this.item.formType === 'treeSelect'
384
- },
385
- // 作用域插槽是否禁用
386
- slotTypeDisabled () {
387
- return this.item.selectKey && this.item.selectType === 'key'
388
- },
389
- // 字段名称是否禁用
390
- keyDisabled () {
391
- return this.item.formType === 'file' || this.item.formType === 'image'
392
- },
393
- // 数据模式是否禁用
394
- dataModeDisabled () {
395
- return this.item.formType === 'file' || this.item.formType === 'image' || this.item.formType === 'addressSearch'
396
- },
397
- dataMode: function () {
398
- const result = {
399
- queryForm: false,
400
- table: false,
401
- addOrEditForm: false,
402
- sqlQueryItem: false,
403
- sqlQueryCondition: false
404
- }
405
- for (const item of this.dataModeArrayData) {
406
- result[item] = true
407
- }
408
- return result
409
- },
410
- queryTypeV () {
411
- return queryType.filter(item => {
412
- return item.match.findIndex(type => type === this.item.formType || type === 'all') > -1
413
- })
414
- },
415
- dataModeTypeV () {
416
- if (this.item.formType) {
417
- return dataModeType.filter(item => {
418
- return item.noMatch.findIndex(type => type === this.item.formType) === -1
419
- })
420
- } else {
421
- return dataModeType
422
- }
423
- },
424
- slotTypeV () {
425
- return slotType.filter(item => {
426
- return item.match.findIndex(type => type === this.item.formType || type === 'all') > -1
427
- })
428
- },
429
- addOrEditTypeV () {
430
- return addOrEditType.filter(item => {
431
- return item.match.findIndex(type => type === this.item.formType || type === 'all') > -1
432
- })
433
- }
434
- },
435
- data () {
436
- return {
437
- DemoJson,
438
- dataModeType,
439
- queryType,
440
- formType,
441
- formRuleType,
442
- slotType,
443
- fileType,
444
- silencePurposeType,
445
- addOrEditType,
446
- selectDataType,
447
- // 控制modal框
448
- visible: false,
449
- type: '',
450
- bodyStyle: {
451
- height: '500px',
452
- overflowY: 'auto'
453
- },
454
- // 表单查询方式是否禁用
455
- formQueryTypeDisabled: false,
456
- // 数据模式类型集合值
457
- dataModeArrayData: [],
458
- // 表单项
459
- item: {
460
- key: '',
461
- title: '',
462
- slot: {
463
- type: 'default'
464
- },
465
- rule: {
466
- required: 'false'
467
- },
468
- queryType: '=',
469
- formType: 'input',
470
- accept: undefined,
471
- pathKey: undefined,
472
- groupIndexView: undefined,
473
- selectType: undefined,
474
- addOrEdit: 'all',
475
- fileRootPath: undefined,
476
- selectKeyName: undefined,
477
- resUploadStock: undefined,
478
- dataModeArray: []
479
- },
480
- // 数据仓库列表
481
- stockList: [],
482
- // 扩展目录
483
- lowerPath: [],
484
- parent_node: [],
485
- // 必填控制
486
- itemRules: {
487
- formType: [{ required: true, message: '请输入表单类型', trigger: 'change' }],
488
- key: [{ required: true, message: '请输入字段名称', trigger: 'blur' }],
489
- title: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
490
- selectType: [{ required: true, message: '请选择数据源类型', trigger: 'change' }],
491
- selectKey: [{ required: true, message: '请输入数据源内容', trigger: 'blur' }],
492
- 'slot.value': [{ required: true, message: '请输入文本溢出上限长度', trigger: 'blur' }],
493
- 'slot.keyMap': [{ required: true, message: '请输入徽标字典键', trigger: 'blur' }],
494
- silencePurpose: [{ required: true, message: '请选择字段用途', trigger: 'change' }],
495
- silenceSource: [{ required: true, message: '请输入业务逻辑名称', trigger: 'blur' }],
496
- groupIndex: [{ required: true, message: '请选择父级联动框', trigger: 'blur' }],
497
- resUploadStock: [{ required: true, message: '请选择上传到的仓库', trigger: 'blur' }],
498
- pathKey: [{ required: true, message: '请选择上传到的扩展目录', trigger: 'blur' }]
499
- },
500
- // 字典键集合
501
- option: []
502
- }
503
- },
504
- mounted () {
505
- this.resetDataMode()
506
- },
507
- props: { },
508
- methods: {
509
- initItem (lysis = {}) {
510
- this.item = Object.assign({
511
- key: '',
512
- title: '',
513
- slot: {
514
- type: 'default'
515
- },
516
- rule: {
517
- required: 'false'
518
- },
519
- selectKey: undefined,
520
- queryType: '=',
521
- formType: 'input',
522
- fileRootPath: undefined,
523
- pathKey: undefined,
524
- accept: undefined,
525
- selectType: undefined,
526
- groupIndex: undefined,
527
- groupIndexView: undefined,
528
- addOrEdit: 'all',
529
- selectKeyName: undefined,
530
- resUploadStock: undefined,
531
- dataModeArray: []
532
- }, lysis)
533
- },
534
- // 控制 展示
535
- flashModal (show = 'None') {
536
- const bool = show === 'None' ? !this.visible : !!show
537
- if (bool && this.option.length === 0) {
538
- post(commonApi.getDictionaryParam, {}).then(res => {
539
- this.option = res
540
- })
541
- }
542
- this.visible = bool
543
- },
544
- // 编辑数据字段前准备数据
545
- editColumnItemExecute (_item) {
546
- this.type = '修改'
547
- const defaultValue = { formType: 'input', type: 'string', addOrEdit: 'all', slot: { type: 'default' }, rule: {}, selectKey: {} }
548
- if (!_item.queryType) {
549
- defaultValue.queryType = '='
550
- }
551
- _item = Object.assign({}, defaultValue, _item)
552
- if (_item.formType === 'file' || _item.formType === 'image') {
553
- this.getStocks()
554
- // 如果有仓库 则获取该仓库的扩展路径
555
- if (_item.resUploadStock) {
556
- this.lowerPath = this.stockList.filter(item => item.id === _item.resUploadStock)[0]?.f_lower_path_json ?? []
557
- }
558
- }
559
- if (_item.selectKey && _item.selectKey.length >= 6 && _item.selectType === 'logic' && _item.selectKey.substring(0, 6) === 'logic@') {
560
- _item.selectKey = _item.selectKey.substring(6)
561
- }
562
- if (_item.formType === 'selects') {
563
- // 因为 groupIndex 可能有很多值 单选框不行 赋给一个新的变量
564
- _item.groupIndexView = _item.groupIndex === 1 ? '1' : '0'
565
- }
566
- // 兼容旧作用域插槽属性
567
- this.compatibleTheSlot(_item)
568
- this.item = _item
569
- this.dataModeArrayData = this.item.dataModeArray
570
- this.flashModal()
571
- },
572
- // 增加数据字段前数据处理
573
- addColumnItemExecute () {
574
- this.type = '新增'
575
- this.dataModeArrayData = ['queryForm', 'table', 'addOrEditForm', 'sqlQueryItem', 'sqlQueryCondition']
576
- this.initItem()
577
- this.flashModal()
578
- },
579
- modelCancel () {
580
- this.flashModal()
581
- // this.$emit('update:visible', false)
582
- // // 延迟是为了避免编辑数据窗口关闭时重置表单导致的闪烁
583
- // setTimeout(() => {
584
- // this.resetDataMode()
585
- // this.resetFormProp()
586
- // }, 100)
587
- },
588
- submitItem () {
589
- this.$refs.itemForm.validate(valid => {
590
- if (valid) {
591
- const fileBool = this.item.formType === 'file' || this.item.formType === 'image'
592
- if (this.dataModeArrayData.length === 0) {
593
- this.$message.error('请至少选择一种数据模式')
594
- return
595
- }
596
- if (!fileBool && (this.dataMode.addOrEditForm && !this.dataMode.sqlQueryItem) && this.item.formType !== 'personSetting' && this.item.formType !== 'cascader') {
597
- this.$message.error('如果要生成新增/修改表单项,必须勾选生成SQL查询项')
598
- return
599
- }
600
- if (fileBool && !(!this.dataMode.table && !this.dataMode.sqlQueryCondition && !this.dataMode.queryForm)) {
601
- this.$message.error(`上传类表单项只能选择 "渲染新增/修改表单项"`)
602
- return
603
- }
604
- this.itemHandle()
605
- }
606
- })
607
- },
608
- visitAcceptFile () {
609
- window.open('https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#attr-accept')
610
- },
611
- // 修改上传到哪个仓库
612
- changeStock (stock) {
613
- if (stock) {
614
- const stockValue = this.stockList.filter(item => item.id === stock)[0]
615
- this.lowerPath = stockValue.f_lower_path_json ?? []
616
- this.item.resUploadMode = stockValue.f_stock_type
617
- this.item.fileRootPath = stockValue.f_root_path
618
- this.item.stockAlias = stockValue.f_alias
619
- this.item.pathKey = undefined
620
- }
621
- },
622
- // 文件上传限制类型修改
623
- itemAcceptChange (newVal) {
624
- if (newVal.includes('*')) {
625
- this.item.accept = ['*']
626
- }
627
- },
628
- parent_title_change (parentKey) {
629
- const parentArr = this.getColumn().filter(item => item.formType === 'selects' && item.key === parentKey)
630
- if (parentArr.length === 1) {
631
- this.item.groupIndex = parentArr[0].groupIndex + 1
632
- this.item.group = parentArr[0].group
633
- this.item.parent_title = parentArr[0].title
634
- } else {
635
- this.$message.error('数据字段中有字段别名相同,请检查!')
636
- }
637
- },
638
- groupIndexChange ({ target }) {
639
- if (target.value === '1') {
640
- this.item.groupIndex = 1
641
- this.item.groupIndexView = '1'
642
- if (this.item.title) {
643
- this.item.group = this.item.title + '组'
644
- } else {
645
- this.item.groupIndex = undefined
646
- this.item.groupIndexView = undefined
647
- this.$message.error('请先输入字段中文名称!')
648
- }
649
- } else {
650
- if (!this.item.title) {
651
- this.$message.error('请先输入字段名称!')
652
- this.item.groupIndex = -1
653
- this.item.groupIndexView = undefined
654
- return
655
- }
656
- this.item.groupIndex = undefined
657
- // 获取所有可以当作父节点的字段
658
- this.parent_node = this.getColumn().filter(item => item.formType === 'selects' && item.key !== this.item.key)
659
- }
660
- },
661
- getColumn () {
662
- let result = {}
663
- this.$emit('getColumn', val => { result = val })
664
- return result
665
- },
666
- changeFormType (item) {
667
- this.initItem({ key: item.key, title: item.title, formType: item.formType })
668
- if (item.formType === 'file' || item.formType === 'image') {
669
- this.item.acceptCount = 3
670
- this.getStocks()
671
- this.item.accept = item.formType === 'file' ? ['*'] : ['.jpg,.jpeg,.ico,.gif,svg,.webp,.png,.bmp,.pjpeg,']
672
- this.item.resUploadMode = 'server'
673
- this.item.key = item.formType === 'file' ? 'FilesId' : 'Images'
674
- this.dataModeArrayData = ['addOrEditForm']
675
- } else if (item.formType === 'addressSearch') {
676
- this.dataModeArrayData = ['addOrEditForm', 'sqlQueryItem']
677
- } else {
678
- if (['FilesId', 'Images'].includes(this.item.key)) { this.item.key = '' }
679
- this.resetDataMode()
680
- // 表单查询方式有预选项时
681
- if (this.queryTypeV.length) {
682
- this.item.queryType = this.queryTypeV[0].key
683
- }
684
- }
685
- },
686
- // 获取所有仓库
687
- getStocks () {
688
- if (this.stockList.length === 0) {
689
- post('/api/af-system/logic/getFilesStock', {}).then(res => {
690
- this.stockList = res.sort((a, b) => b.progress - a.progress)
691
- }).catch(e => {})
692
- }
693
- },
694
- // 重置数据模式
695
- resetDataMode () {
696
- this.dataModeArrayData = this.dataModeTypeV.map(item => item.value)
697
- },
698
- itemHandle () {
699
- // 查询表单项或者新增/修改表单项
700
- if (this.dataMode.queryForm || this.dataMode.addOrEditForm) {
701
- if (!this.dataMode.sqlQueryItem || !this.dataMode.addOrEditForm) {
702
- this.delKey(this.item, 'addOrEdit', 'silencePurpose', 'silenceSource')
703
- }
704
- if (this.item.selectType && this.item.selectType === 'logic' && this.item.selectKey.substring(0, 6) !== 'logic@') {
705
- // 数据源为logic
706
- this.item.selectKey = 'logic@' + this.item.selectKey
707
- } else if (this.item.selectType && this.item.selectType === 'fixArray' && !this.isJSON(this.item.selectKey)) {
708
- // 数据源为固定json集合
709
- this.$message.warning('下拉框数据源不是JSON集合')
710
- return
711
- }
712
- } else {
713
- this.delKey(this.item, 'queryType', 'formType', 'addOrEdit', 'silencePurpose', 'silenceSource', 'placeholder', 'rule', 'selectKey', 'selectKeyName', 'lazyLoad')
714
- }
715
- // 如果和数据源字段无关
716
- if (!this.selectDataShow) {
717
- this.delKey(this.item, 'selectType', 'selectKey', 'lazyLoad', 'selectKeyName')
718
- }
719
- // 删除空的关联外键字段
720
- if (!this.item.selectKeyName) {
721
- delete this.item.selectKeyName
722
- }
723
- // 默认插槽就先删除
724
- if (this.item.slot && (this.item.slot.type === 'default' || !this.item.slot.type)) { delete this.item.slot }
725
- // 根据数据模式处理数据
726
- if (!this.dataMode.sqlQueryCondition) {
727
- delete this.item.queryType
728
- }
729
- if (!this.dataMode.sqlQueryItem) { this.delKey(this.item, 'default') }
730
- this.item.dataModeArray = this.dataModeArrayData
731
- this.$emit('itemHandle', this.item, this.type)
732
- this.initItem()
733
- this.resetDataMode()
734
- },
735
- changeSelectKType () {
736
- this.item.selectKey = undefined
737
- },
738
- changeSelectKey (item) {
739
- if (item.selectType === 'key' && item.selectKey) {
740
- this.item.slot = Object.assign({}, this.item.slot, { keyMap: item.selectKey, type: 'badge' })
741
- }
742
- },
743
- filterOption (input, option) {
744
- return (
745
- option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
746
- )
747
- },
748
- delKey (obj, ...args) {
749
- args.forEach(v => {
750
- delete obj[v]
751
- })
752
- return obj
753
- },
754
- // 判断是否为json字符串
755
- isJSON (str) {
756
- if (typeof str == 'string') {
757
- try {
758
- const obj = JSON.parse(str)
759
- return !!(typeof obj == 'object' && obj)
760
- } catch (e) {
761
- return false
762
- }
763
- }
764
- },
765
- // 兼容旧插槽函数
766
- compatibleTheSlot (_item) {
767
- if (_item.slotKeyMap) {
768
- _item.slot.keyMap = _item.slotKeyMap
769
- delete _item.slotKeyMap
770
- }
771
- if (_item.slotValue) {
772
- _item.slot.value = _item.slotValue
773
- delete _item.slotValue
774
- }
775
- if (_item.actionText) {
776
- _item.slot.actionText = _item.actionText
777
- delete _item.actionText
778
- }
779
- }
780
- }
781
- }
782
- </script>
1
+ <template>
2
+ <a-modal
3
+ :destroyOnClose="true"
4
+ :visible="visible"
5
+ :width="1250"
6
+ :zIndex="1001"
7
+ title="数据字段配置"
8
+ @cancel="modelCancel"
9
+ @ok="submitItem">
10
+ <a-form-model
11
+ ref="itemForm"
12
+ :model="item"
13
+ :rules="itemRules"
14
+ layout="vertical">
15
+ <a-row :gutter="16">
16
+ <a-col :span="6">
17
+ <a-card :bodyStyle="bodyStyle" title="基本属性">
18
+ <a-divider style="font-size: 14px;margin-top: 0">字段信息</a-divider>
19
+ <a-form-model-item label="标签名称" prop="title">
20
+ <a-input v-model="item.title" placeholder="请输入标签名称"/>
21
+ </a-form-model-item>
22
+ <a-form-model-item
23
+ label="字段名称"
24
+ prop="key">
25
+ <a-input ref="key" v-model="item.key" :disabled="keyDisabled" placeholder="请输入字段名">
26
+ <a-popover slot="suffix" placement="bottom" title="关于字段名称">
27
+ <template slot="content">
28
+ <p>设置数据字段的名称</p>
29
+ <p>用作SQL查询时为<span style="font-weight: bold">表别名.数据列名</span>的格式,如:i.id</p>
30
+ </template>
31
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
32
+ </a-popover>
33
+ </a-input>
34
+ </a-form-model-item>
35
+ <a-form-model-item
36
+ v-if="item.formType ==='addressSearch'"
37
+ label="坐标字段名">
38
+ <a-input :disabled="true" :value="`${item.key}_lng_lat`">
39
+ <a-popover slot="suffix" placement="bottom" title="坐标字段名">
40
+ <template slot="content">
41
+ <p>表单类型为地点搜索框时:</p>
42
+ <p>新增/修改表单内,字段名称会存放地址名称,坐标字段名会存放坐标信息</p>
43
+ </template>
44
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
45
+ </a-popover>
46
+ </a-input>
47
+ </a-form-model-item>
48
+ <a-divider style="font-size: 14px;margin-top: 0">数据模式</a-divider>
49
+ <a-form-model-item
50
+ prop="dataMode"
51
+ style="margin-top: 10px;">
52
+ <a-checkbox-group v-model="dataModeArrayData" :disabled="dataModeDisabled" :options="dataModeTypeV"/>
53
+ </a-form-model-item>
54
+ </a-card>
55
+ </a-col>
56
+ <a-col :span="9">
57
+ <a-card v-if="dataMode.queryForm || dataMode.addOrEditForm || dataMode.table" :bodyStyle="bodyStyle" title="核心配置">
58
+ <template v-if="dataMode.queryForm || dataMode.addOrEditForm">
59
+ <a-divider style="font-size: 14px;margin-top: 0">表单配置</a-divider>
60
+ <a-form-model-item label="表单类型" prop="formType">
61
+ <a-select v-model="item.formType" placeholder="请选择表单类型" @change="changeFormType(item)">
62
+ <a-select-option v-for="formTypeItem in formType" :key="formTypeItem.key">{{ formTypeItem.label }}</a-select-option>
63
+ </a-select>
64
+ </a-form-model-item>
65
+ <template v-if="item.formType">
66
+ <a-form-model-item v-if="dataMode.sqlQueryCondition && item.formType !=='file' && item.formType !=='image' " label="表单查询方式" prop="queryType">
67
+ <a-select
68
+ v-model="item.queryType"
69
+ :disabled="formQueryTypeDisabled"
70
+ :getPopupContainer=" triggerNode => { return triggerNode.parentNode } "
71
+ placeholder="表单查询方式">
72
+ <a-select-option v-for="queryTypeItem in queryTypeV" :key="queryTypeItem.key">{{ queryTypeItem.label }}</a-select-option>
73
+ </a-select>
74
+ </a-form-model-item>
75
+ <a-form-model-item v-if="dataMode.addOrEditForm" label="表单校验" prop="rule">
76
+ <a-row :gutter="16">
77
+ <a-col v-if="(item.formType === 'input' || item.formType === 'textarea' ) && item.formType !=='file' && item.formType !=='image' " :span="12" >
78
+ <a-select v-model="item.rule.type" :getPopupContainer=" triggerNode => { return triggerNode.parentNode } " placeholder="校验类型">
79
+ <a-select-option v-for="ruleTypeItem in formRuleType" :key="ruleTypeItem.key">{{ ruleTypeItem.label }}</a-select-option>
80
+ <a-popover slot="suffixIcon" placement="bottom" title="关于表单校验类型">
81
+ <template slot="content">
82
+ <p>设置表单项的校验类型</p>
83
+ </template>
84
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
85
+ </a-popover>
86
+ </a-select>
87
+ </a-col>
88
+ <a-col :span="12">
89
+ <a-radio-group v-model="item.rule.required" button-style="solid" default-value="false">
90
+ <a-radio-button value="true">
91
+ 必选项
92
+ </a-radio-button>
93
+ <a-radio-button value="false">
94
+ 非必选项
95
+ </a-radio-button>
96
+ </a-radio-group>
97
+ </a-col>
98
+ </a-row>
99
+ </a-form-model-item>
100
+ <a-form-model-item v-if="dataMode.addOrEditForm" label="新增/修改场景选择" prop="addOrEdit">
101
+ <a-select v-model="item.addOrEdit" placeholder="请选择场景">
102
+ <a-select-option v-for="addOrEditItem in addOrEditTypeV" :key="addOrEditItem.key">{{ addOrEditItem.label }}</a-select-option>
103
+ <a-popover
104
+ slot="suffixIcon"
105
+ placement="bottom"
106
+ title="关于新增/修改场景选择">
107
+ <template slot="content">
108
+ <p>设置表单项的新增/修改场景</p>
109
+ <p>静默新增类型用于非人为新增的数据,不会生成表单项,且必须设置字段用途</p>
110
+ </template>
111
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
112
+ </a-popover>
113
+ </a-select>
114
+ </a-form-model-item>
115
+ <a-form-model-item v-if="item.addOrEdit === 'silenceAdd'" label="字段用途" prop="silencePurpose">
116
+ <a-select v-model="item.silencePurpose" :getPopupContainer=" triggerNode => { return triggerNode.parentNode } " placeholder="请选择字段用途">
117
+ <a-select-option v-for="silencePurposeTypeItem in silencePurposeType" :key="silencePurposeTypeItem.key">{{ silencePurposeTypeItem.label }}</a-select-option>
118
+ <a-popover
119
+ slot="suffixIcon"
120
+ placement="bottom"
121
+ title="关于字段用途">
122
+ <template slot="content">
123
+ <p>用于静默新增时设置字段用途</p>
124
+ <p>在新增数据的表单提交时,页面会根据设置的字段用途自动获取相关数据并追加到表单中</p>
125
+ <p>当字段用途选择为<span style="font-weight: bold">自定义</span>时,必须指定一个业务逻辑(Logic)名称,表单提交前会将表单内容作为参数调用该Logic接口,并将Logic返回值作为表单值
126
+ </p>
127
+ </template>
128
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
129
+ </a-popover>
130
+ </a-select>
131
+ </a-form-model-item>
132
+ <a-form-model-item v-if="item.silencePurpose === 'customize'" label="字段用途对应Logic" prop="silenceSource">
133
+ <a-input v-model="item.silenceSource" placeholder="请输入业务逻辑名称"/>
134
+ </a-form-model-item>
135
+ </template>
136
+ </template>
137
+ <template v-if="dataMode.table">
138
+ <a-divider style="font-size: 14px;margin-top: 0">表格列配置</a-divider>
139
+ <a-form-model-item v-if="item.formType" label="作用域插槽" prop="slot">
140
+ <a-select v-model="item.slot.type" :disabled="slotTypeDisabled" :getPopupContainer=" triggerNode => { return triggerNode.parentNode } " placeholder="插槽类型">
141
+ <a-select-option v-for="slotTypeItem in slotTypeV" :key="slotTypeItem.key">{{ slotTypeItem.label }}</a-select-option>
142
+ <a-popover slot="suffixIcon" placement="bottom" title="关于作用域插槽">
143
+ <template slot="content">
144
+ <p>你可以通过设置表格列的作用域插槽实现一些效果</p>
145
+ <p>如果没有指定,默认会设置为文本溢出省略(长度:16)</p>
146
+ <p>如果你选择文本溢出省略,需要设置文本溢出上限长度,建议ID主键等类型设置为8</p>
147
+ <p>如果你选择多彩徽标,需要设置徽标对应的数据样式字典键</p>
148
+ <a-divider style="font-size: 14px;margin-top: 0">关于表格列宽度</a-divider>
149
+ <p>V1.1之后不再支持自定义表格列宽度,表格列宽度将通过作用域插槽类型自适应</p>
150
+ <p>设置为文本溢出省略时,表格列宽度 = 文本溢出上限长度 * 7 + 42</p>
151
+ <p>设置为多彩徽标时,表格列宽度为130</p>
152
+ <p>设置为日期时间格式化时,表格列宽度为160</p>
153
+ </template>
154
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
155
+ </a-popover>
156
+ </a-select>
157
+ </a-form-model-item>
158
+ <a-form-model-item v-if="item.slot.type === 'badge'" label="徽标字典键" prop="slot.keyMap">
159
+ <a-input v-model="item.slot.keyMap" :disabled="slotTypeDisabled" placeholder="请输入徽标字典键">
160
+ <a-popover
161
+ slot="suffix"
162
+ placement="bottom"
163
+ title="关于徽标字典键">
164
+ <template slot="content">
165
+ <p>如果你设置了表单类型为选择框,且数据源是字典键,该值会自动带出</p>
166
+ </template>
167
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
168
+ </a-popover>
169
+ </a-input>
170
+ </a-form-model-item>
171
+ <a-form-model-item v-if="item.slot.type === 'ellipsis'" label="文本溢出上限长度" prop="slot.value">
172
+ <a-input-number v-model="item.slot.value" placeholder="请输入文本溢出上限长度" style="width: 100%"/>
173
+ </a-form-model-item>
174
+ <a-form-model-item v-if="item.slot.type === 'action'" label="操作列文本" prop="slot.actionText">
175
+ <a-input v-model="item.slot.actionText" placeholder="请输入操作列显示文本,默认为详情"/>
176
+ </a-form-model-item>
177
+ <a-form-model-item v-if="dataMode.sqlQueryItem || dataMode.sqlQueryCondition" label="字段默认值" prop="default">
178
+ <a-input v-model="item.default" placeholder="当查询结果为null时,指定默认值"/>
179
+ </a-form-model-item>
180
+ </template>
181
+ </a-card>
182
+ </a-col>
183
+ <a-col v-if="item.formType" :span="9">
184
+ <a-card :bodyStyle="bodyStyle" title="扩展属性">
185
+ <template v-if="(dataMode.addOrEditForm || dataMode.queryForm ) && (item.formType === 'input' || item.formType === 'select')">
186
+ <a-divider style="font-size: 14px;margin-top: 0">提示相关</a-divider>
187
+ <a-form-model-item label="表单水印" prop="placeholder">
188
+ <a-input v-model="item.placeholder" placeholder="表单水印(placeholder)" />
189
+ </a-form-model-item>
190
+ </template>
191
+ <template v-if="selectDataShow">
192
+ <a-divider style="font-size: 14px;margin-top: 0">数据源相关</a-divider>
193
+ <a-form-model-item label="数据源类型" prop="selectType">
194
+ <a-select v-model="item.selectType" placeholder="请选择数据源类型" @change="changeSelectKType">
195
+ <a-select-option v-for="selectDataTypeItem in selectDataType.filter(h=>!h.noMatch.includes(item.formType))" :key="selectDataTypeItem.key">{{ selectDataTypeItem.label }}</a-select-option>
196
+ <a-popover
197
+ slot="suffixIcon"
198
+ placement="bottom"
199
+ title="关于数据源类型">
200
+ <template slot="content">
201
+ <p>设置数据源</p>
202
+ <p>数据源类型分为三种,你可以根据需要选择</p>
203
+ <p>字典键:选项从字典表(t_dictionary)获取,你只需要选择字典键的名称即可</p>
204
+ <p>业务逻辑名称:选项通过发起http请求调用指定的业务逻辑(Logic)接口获取</p>
205
+ <p>固定集合:选项为静态值,JSONArray格式</p>
206
+ <p>当表单为树形选择框类型时,返回的数据需按照以下形式:</p>
207
+ <json-viewer
208
+ :expand-depth="parseInt('100')"
209
+ :value="DemoJson"
210
+ style="overflow: auto;max-height: 440px"></json-viewer>
211
+ </template>
212
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
213
+ </a-popover>
214
+ </a-select>
215
+ </a-form-model-item>
216
+ <a-form-model-item v-if="item.selectType" label="数据源" prop="selectKey">
217
+ <a-select
218
+ v-if="item.selectType === 'key'"
219
+ v-model="item.selectKey"
220
+ :filter-option="filterOption"
221
+ placeholder="请选择字典键"
222
+ show-search
223
+ @change="changeSelectKey(item)">
224
+ <template>
225
+ <a-select-option
226
+ v-for="(optionItem,index) in option"
227
+ :key="index"
228
+ :value="Object.keys(optionItem)[0]">{{ optionItem[Object.keys(optionItem)[0]] }}
229
+ </a-select-option>
230
+ </template>
231
+ </a-select>
232
+ <a-input v-if="item.selectType === 'logic'" v-model="item.selectKey" placeholder="请输入业务逻辑名称"/>
233
+ <a-textarea v-if="item.selectType === 'fixArray'" v-model="item.selectKey" placeholder="请录入数据源"/>
234
+ </a-form-model-item>
235
+ <a-form-model-item v-if="item.selectType === 'logic'" label="数据源加载方式" prop="selectLoadType">
236
+ <a-radio-group v-model="item.lazyLoad" button-style="solid" default-value="false">
237
+ <a-radio-button value="true">
238
+ {{ item.formType === 'treeSelect' ? '异步加载节点' : '懒加载搜索' }}
239
+ </a-radio-button>
240
+ <a-radio-button value="false">
241
+ 一次性加载
242
+ </a-radio-button>
243
+ </a-radio-group>
244
+ </a-form-model-item>
245
+ </template>
246
+ <a-form-model-item v-if="selectDataShow || item.groupIndexView" label="关联外键字段" prop="selectKeyName">
247
+ <a-input v-model="item.selectKeyName" placeholder="该列关联的外键字段">
248
+ <a-popover slot="suffix" placement="bottom" title="关于关联外键字段">
249
+ <template slot="content">
250
+ <p><span style="font-weight: bold;"><span style="color: #FF0036">非必需的实验性功能:</span>设置该参数需开发岗指导</span></p>
251
+ <p>当字段与主子表外键有关系时,你可以指定<span style="font-weight: bold">该列所关联的外键字段名</span>
252
+ </p>
253
+ <p>设置该参数是为了该字段用作表单查询时,系统可以通过设置的关联外键字段,而非字面值作为查询条件</p>
254
+ <p>示例:</p>
255
+ <p>主表为t_userfiles(表档案)表,别名为u,与t_gasbrand(气表品牌表)有关联关系,别名为g,为了显示表档案对应的气表品牌数据,我们将数据字段名设置为g.f_gasbrand</p>
256
+ <p>这样我们就可以在table中看到气表品牌了,但是用户如果通过气表品牌下拉框进行筛选,我们指定的g.f_gasbrand只是气表品牌的值,而实际关联字段是u.f_gasbrand_id</p>
257
+ <p>所以如果我们指定了关联外键字段u.f_gasbrand_id,系统则会使用u.f_gasbrand_id筛选数据,而不是g.f_gasbrand,从而优化了查询效率
258
+ </p>
259
+ </template>
260
+ <a-icon style="color: rgba(0,0,0,.45)" type="info-circle"/>
261
+ </a-popover>
262
+ </a-input>
263
+ </a-form-model-item>
264
+ <template v-if="item.formType === 'file' || item.formType === 'image'">
265
+ <a-divider style="font-size: 14px;margin-top: 0">文件上传相关</a-divider>
266
+ <a-form-model-item label="允许上传文件数量" prop="accept" style="margin-bottom: 5px;">
267
+ <a-slider
268
+ v-model="item.acceptCount"
269
+ :marks="{ 1: '1', 3: '3', 5: '5', 10: '10', 15: '15', 20: '20'}"
270
+ :max="20"
271
+ :min="1"
272
+ />
273
+ </a-form-model-item>
274
+ <a-form-model-item label="附件用途" prop="useType">
275
+ <a-select v-model="item.useType" placeholder="指定文件用途,同表单不同用途">
276
+ <a-select-option v-for="userTypeItem in $appdata.getDictionaryList('useType')" :key="userTypeItem.value">{{ userTypeItem.value }}</a-select-option>
277
+ </a-select>
278
+ </a-form-model-item>
279
+ <a-form-model-item label="上传的仓库" prop="resUploadStock">
280
+ <a-select v-model="item.resUploadStock" placeholder="选择文件上传到的仓库" @change="changeStock">
281
+ <a-select-option v-for="stock in stockList" :key="stock.id">{{ stock.f_name }}</a-select-option>
282
+ </a-select>
283
+ </a-form-model-item>
284
+ <a-form-model-item v-if="item.resUploadStock" label="具体路径" prop="pathKey">
285
+ <a-select v-model="item.pathKey" placeholder="仓库扩展路径">
286
+ <a-select-option v-for="pathKey in lowerPath" :key="pathKey.label">{{ pathKey.label }}</a-select-option>
287
+ </a-select>
288
+ </a-form-model-item>
289
+ <a-form-model-item v-if="item.formType === 'file'" label="允许上传文件类型" prop="accept">
290
+ <a-select v-model="item.accept" mode="tags" placeholder="指定文件类型,默认不限制" @change="itemAcceptChange">
291
+ <a-select-option v-for="type_item in fileType" :key="type_item.accept">{{ type_item.label }}</a-select-option>
292
+ </a-select>
293
+ </a-form-model-item>
294
+ </template>
295
+ </a-card>
296
+ </a-col>
297
+ </a-row>
298
+ <a-alert
299
+ v-if="dataModeArrayData.length === 0"
300
+ message="错误:请至少选择一种数据模式"
301
+ show-icon
302
+ style="margin-top: 5px"
303
+ type="error"/>
304
+ <a-alert
305
+ v-if="dataMode.addOrEditForm && !dataMode.sqlQueryItem && item.formType !== 'file' && item.formType !== 'image'"
306
+ message="错误:如果要生成新增/修改表单项,必须勾选生成SQL查询项"
307
+ show-icon
308
+ style="margin-top: 5px"
309
+ type="error"/>
310
+ <a-alert
311
+ v-if="dataMode.queryForm && !dataMode.sqlQueryCondition"
312
+ message="提示:您没有勾选生成SQL查询表达式,渲染的表单项不会生成SQL查询条件"
313
+ show-icon
314
+ style="margin-top: 5px"
315
+ type="info"/>
316
+ <a-alert
317
+ v-if="dataMode.table && !dataMode.sqlQueryItem"
318
+ message="提示:您没有勾选生成SQL查询项,渲染的表格列不会绑定SQL结果集数据"
319
+ show-icon
320
+ style="margin-top: 5px"
321
+ type="info"/>
322
+ </a-form-model>
323
+ </a-modal>
324
+ </template>
325
+
326
+ <script>
327
+ import {
328
+ dataModeType,
329
+ fileType,
330
+ formRuleType,
331
+ formType,
332
+ queryType,
333
+ slotType,
334
+ silencePurposeType,
335
+ addOrEditType,
336
+ selectDataType
337
+ } from '@vue2-client/config/CreateQueryConfig'
338
+ import { commonApi, post } from '@vue2-client/services/api'
339
+ import JsonViewer from 'vue-json-viewer'
340
+
341
+ const DemoJson = [{
342
+ value: 'zhejiang',
343
+ label: 'Zhejiang',
344
+ children: [{ value: 'hangzhou', label: 'Hangzhou', children: [{ value: 'xihu', label: 'West Lake' }] }]
345
+ }]
346
+
347
+ export default {
348
+ name: 'CreateQueryItem',
349
+ components: {
350
+ JsonViewer
351
+ },
352
+ computed: {
353
+ // 是否展示数据源相关字段
354
+ selectDataShow () {
355
+ return this.item.formType === 'select' || this.item.formType === 'checkbox' || this.item.formType === 'radio' || this.item.formType === 'treeSelect'
356
+ },
357
+ // 作用域插槽是否禁用
358
+ slotTypeDisabled () {
359
+ return this.item.selectKey && this.item.selectType === 'key'
360
+ },
361
+ // 字段名称是否禁用
362
+ keyDisabled () {
363
+ return this.item.formType === 'file' || this.item.formType === 'image'
364
+ },
365
+ // 数据模式是否禁用
366
+ dataModeDisabled () {
367
+ return this.item.formType === 'file' || this.item.formType === 'image' || this.item.formType === 'addressSearch'
368
+ },
369
+ dataMode: function () {
370
+ const result = {
371
+ queryForm: false,
372
+ table: false,
373
+ addOrEditForm: false,
374
+ sqlQueryItem: false,
375
+ sqlQueryCondition: false
376
+ }
377
+ for (const item of this.dataModeArrayData) {
378
+ result[item] = true
379
+ }
380
+ return result
381
+ },
382
+ queryTypeV () {
383
+ return queryType.filter(item => {
384
+ return item.match.findIndex(type => type === this.item.formType || type === 'all') > -1
385
+ })
386
+ },
387
+ dataModeTypeV () {
388
+ if (this.item.formType) {
389
+ return dataModeType.filter(item => {
390
+ return item.noMatch.findIndex(type => type === this.item.formType) === -1
391
+ })
392
+ } else {
393
+ return dataModeType
394
+ }
395
+ },
396
+ slotTypeV () {
397
+ return slotType.filter(item => {
398
+ return item.match.findIndex(type => type === this.item.formType || type === 'all') > -1
399
+ })
400
+ },
401
+ addOrEditTypeV () {
402
+ return addOrEditType.filter(item => {
403
+ return item.match.findIndex(type => type === this.item.formType || type === 'all') > -1
404
+ })
405
+ }
406
+ },
407
+ data () {
408
+ return {
409
+ DemoJson,
410
+ dataModeType,
411
+ queryType,
412
+ formType,
413
+ formRuleType,
414
+ slotType,
415
+ fileType,
416
+ silencePurposeType,
417
+ addOrEditType,
418
+ selectDataType,
419
+ // 控制modal框
420
+ visible: false,
421
+ type: '',
422
+ bodyStyle: {
423
+ height: '500px',
424
+ overflowY: 'auto'
425
+ },
426
+ // 表单查询方式是否禁用
427
+ formQueryTypeDisabled: false,
428
+ // 数据模式类型集合值
429
+ dataModeArrayData: [],
430
+ // 表单项
431
+ item: {
432
+ key: '',
433
+ title: '',
434
+ slot: {
435
+ type: 'default'
436
+ },
437
+ rule: {
438
+ required: 'false'
439
+ },
440
+ queryType: '=',
441
+ formType: 'input',
442
+ accept: undefined,
443
+ acceptCount: 3,
444
+ pathKey: undefined,
445
+ groupIndexView: undefined,
446
+ selectType: undefined,
447
+ selectKey: undefined,
448
+ addOrEdit: 'all',
449
+ fileRootPath: undefined,
450
+ selectKeyName: undefined,
451
+ resUploadStock: undefined,
452
+ dataModeArray: []
453
+ },
454
+ // 数据仓库列表
455
+ stockList: [],
456
+ // 扩展目录
457
+ lowerPath: [],
458
+ parent_node: [],
459
+ // 必填控制
460
+ itemRules: {
461
+ formType: [{ required: true, message: '请输入表单类型', trigger: 'change' }],
462
+ key: [{ required: true, message: '请输入字段名称', trigger: 'blur' }],
463
+ title: [{ required: true, message: '请输入标签名称', trigger: 'blur' }],
464
+ selectType: [{ required: true, message: '请选择数据源类型', trigger: 'change' }],
465
+ selectKey: [{ required: true, message: '请输入数据源内容', trigger: 'blur' }],
466
+ 'slot.value': [{ required: true, message: '请输入文本溢出上限长度', trigger: 'blur' }],
467
+ 'slot.keyMap': [{ required: true, message: '请输入徽标字典键', trigger: 'blur' }],
468
+ silencePurpose: [{ required: true, message: '请选择字段用途', trigger: 'change' }],
469
+ silenceSource: [{ required: true, message: '请输入业务逻辑名称', trigger: 'blur' }],
470
+ resUploadStock: [{ required: true, message: '请选择上传到的仓库', trigger: 'blur' }],
471
+ pathKey: [{ required: true, message: '请选择上传到的扩展目录', trigger: 'blur' }]
472
+ },
473
+ // 字典键集合
474
+ option: []
475
+ }
476
+ },
477
+ mounted () {
478
+ this.resetDataMode()
479
+ },
480
+ props: { },
481
+ methods: {
482
+ initItem (lysis = {}) {
483
+ this.item = Object.assign({
484
+ key: '',
485
+ title: '',
486
+ slot: {
487
+ type: 'default'
488
+ },
489
+ rule: {
490
+ required: 'false'
491
+ },
492
+ selectKey: undefined,
493
+ queryType: '=',
494
+ formType: 'input',
495
+ acceptCount: 3,
496
+ fileRootPath: undefined,
497
+ pathKey: undefined,
498
+ accept: undefined,
499
+ selectType: undefined,
500
+ groupIndex: undefined,
501
+ groupIndexView: undefined,
502
+ addOrEdit: 'all',
503
+ selectKeyName: undefined,
504
+ resUploadStock: undefined,
505
+ dataModeArray: []
506
+ }, lysis)
507
+ },
508
+ // 控制 展示
509
+ flashModal (show = 'None') {
510
+ const bool = show === 'None' ? !this.visible : !!show
511
+ if (bool && this.option.length === 0) {
512
+ post(commonApi.getDictionaryParam, {}).then(res => {
513
+ this.option = res
514
+ })
515
+ }
516
+ this.visible = bool
517
+ },
518
+ // 编辑数据字段前准备数据
519
+ editColumnItemExecute (_item) {
520
+ this.type = '修改'
521
+ const defaultValue = { formType: 'input', type: 'string', addOrEdit: 'all', slot: { type: 'default' }, rule: {}, selectKey: {} }
522
+ if (!_item.queryType) {
523
+ defaultValue.queryType = '='
524
+ }
525
+ _item = Object.assign({}, defaultValue, _item)
526
+ if (_item.formType === 'file' || _item.formType === 'image') {
527
+ this.getStocks()
528
+ // 如果有仓库 则获取该仓库的扩展路径
529
+ if (_item.resUploadStock) {
530
+ this.lowerPath = this.stockList.filter(item => item.id === _item.resUploadStock)[0]?.f_lower_path_json ?? []
531
+ }
532
+ }
533
+ if (_item.selectKey && _item.selectKey.length >= 6 && _item.selectType === 'logic' && _item.selectKey.substring(0, 6) === 'logic@') {
534
+ _item.selectKey = _item.selectKey.substring(6)
535
+ }
536
+ // 兼容旧作用域插槽属性
537
+ this.compatibleTheSlot(_item)
538
+ this.item = _item
539
+ this.dataModeArrayData = this.item.dataModeArray
540
+ this.flashModal()
541
+ },
542
+ // 增加数据字段前数据处理
543
+ addColumnItemExecute () {
544
+ this.type = '新增'
545
+ this.dataModeArrayData = ['queryForm', 'table', 'addOrEditForm', 'sqlQueryItem', 'sqlQueryCondition']
546
+ this.initItem()
547
+ this.flashModal()
548
+ },
549
+ modelCancel () {
550
+ this.flashModal()
551
+ },
552
+ submitItem () {
553
+ this.$refs.itemForm.validate(valid => {
554
+ if (valid) {
555
+ const fileBool = this.item.formType === 'file' || this.item.formType === 'image'
556
+ if (this.dataModeArrayData.length === 0) {
557
+ this.$message.error('请至少选择一种数据模式')
558
+ return
559
+ }
560
+ if (!fileBool && (this.dataMode.addOrEditForm && !this.dataMode.sqlQueryItem)) {
561
+ this.$message.error('如果要生成新增/修改表单项,必须勾选生成SQL查询项')
562
+ return
563
+ }
564
+ if (fileBool && !(!this.dataMode.table && !this.dataMode.sqlQueryCondition && !this.dataMode.queryForm)) {
565
+ this.$message.error(`上传类表单项只能选择 "渲染新增/修改表单项"`)
566
+ return
567
+ }
568
+ this.itemHandle()
569
+ }
570
+ })
571
+ },
572
+ visitAcceptFile () {
573
+ window.open('https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/file#attr-accept')
574
+ },
575
+ // 修改上传到哪个仓库
576
+ changeStock (stock) {
577
+ if (stock) {
578
+ const stockValue = this.stockList.filter(item => item.id === stock)[0]
579
+ this.lowerPath = stockValue.f_lower_path_json ?? []
580
+ this.item.resUploadMode = stockValue.f_stock_type
581
+ this.item.fileRootPath = stockValue.f_root_path
582
+ this.item.stockAlias = stockValue.f_alias
583
+ this.item.pathKey = undefined
584
+ }
585
+ },
586
+ // 文件上传限制类型修改
587
+ itemAcceptChange (newVal) {
588
+ if (newVal.includes('*')) {
589
+ this.item.accept = ['*']
590
+ }
591
+ },
592
+ getColumn () {
593
+ let result = {}
594
+ this.$emit('getColumn', val => { result = val })
595
+ return result
596
+ },
597
+ changeFormType (item) {
598
+ this.initItem({ key: item.key, title: item.title, formType: item.formType })
599
+ if (item.formType === 'file' || item.formType === 'image') {
600
+ this.item.acceptCount = 3
601
+ this.getStocks()
602
+ this.item.accept = item.formType === 'file' ? ['*'] : ['.jpg,.jpeg,.ico,.gif,svg,.webp,.png,.bmp,.pjpeg,']
603
+ this.item.resUploadMode = 'server'
604
+ this.item.key = item.formType === 'file' ? 'FilesId' : 'Images'
605
+ this.dataModeArrayData = ['addOrEditForm']
606
+ } else if (item.formType === 'addressSearch') {
607
+ this.dataModeArrayData = ['addOrEditForm', 'sqlQueryItem']
608
+ } else {
609
+ if (['FilesId', 'Images'].includes(this.item.key)) { this.item.key = '' }
610
+ this.resetDataMode()
611
+ // 表单查询方式有预选项时
612
+ if (this.queryTypeV.length) {
613
+ this.item.queryType = this.queryTypeV[0].key
614
+ }
615
+ }
616
+ },
617
+ // 获取所有仓库
618
+ getStocks () {
619
+ if (this.stockList.length === 0) {
620
+ post('/api/af-system/logic/getFilesStock', {}).then(res => {
621
+ this.stockList = res.sort((a, b) => b.progress - a.progress)
622
+ }).catch(e => {})
623
+ }
624
+ },
625
+ // 重置数据模式
626
+ resetDataMode () {
627
+ this.dataModeArrayData = this.dataModeTypeV.map(item => item.value)
628
+ },
629
+ itemHandle () {
630
+ // 查询表单项或者新增/修改表单项
631
+ if (this.dataMode.queryForm || this.dataMode.addOrEditForm) {
632
+ if (!this.dataMode.sqlQueryItem || !this.dataMode.addOrEditForm) {
633
+ this.delKey(this.item, 'addOrEdit', 'silencePurpose', 'silenceSource')
634
+ }
635
+ if (this.item.selectType && this.item.selectType === 'logic' && this.item.selectKey.substring(0, 6) !== 'logic@') {
636
+ // 数据源为logic
637
+ this.item.selectKey = 'logic@' + this.item.selectKey
638
+ } else if (this.item.selectType && this.item.selectType === 'fixArray' && !this.isJSON(this.item.selectKey)) {
639
+ // 数据源为固定json集合
640
+ this.$message.warning('下拉框数据源不是JSON集合')
641
+ return
642
+ }
643
+ } else {
644
+ this.delKey(this.item, 'queryType', 'formType', 'addOrEdit', 'silencePurpose', 'silenceSource', 'placeholder', 'rule', 'selectKey', 'selectKeyName', 'lazyLoad')
645
+ }
646
+ // 如果和数据源字段无关
647
+ if (!this.selectDataShow) {
648
+ this.delKey(this.item, 'selectType', 'selectKey', 'lazyLoad', 'selectKeyName')
649
+ }
650
+ // 删除空的关联外键字段
651
+ if (!this.item.selectKeyName) {
652
+ delete this.item.selectKeyName
653
+ }
654
+ // 默认插槽就先删除
655
+ if (this.item.slot && (this.item.slot.type === 'default' || !this.item.slot.type)) { delete this.item.slot }
656
+ // 根据数据模式处理数据
657
+ if (!this.dataMode.sqlQueryCondition) {
658
+ delete this.item.queryType
659
+ }
660
+ if (!this.dataMode.sqlQueryItem) { this.delKey(this.item, 'default') }
661
+ this.item.dataModeArray = this.dataModeArrayData
662
+ this.$emit('itemHandle', this.item, this.type)
663
+ this.initItem()
664
+ this.resetDataMode()
665
+ },
666
+ changeSelectKType () {
667
+ this.item.selectKey = undefined
668
+ },
669
+ changeSelectKey (item) {
670
+ if (item.selectType === 'key' && item.selectKey) {
671
+ this.item.slot = Object.assign({}, this.item.slot, { keyMap: item.selectKey, type: 'badge' })
672
+ }
673
+ },
674
+ filterOption (input, option) {
675
+ return (
676
+ option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
677
+ )
678
+ },
679
+ delKey (obj, ...args) {
680
+ args.forEach(v => {
681
+ delete obj[v]
682
+ })
683
+ return obj
684
+ },
685
+ // 判断是否为json字符串
686
+ isJSON (str) {
687
+ if (typeof str == 'string') {
688
+ try {
689
+ const obj = JSON.parse(str)
690
+ return !!(typeof obj == 'object' && obj)
691
+ } catch (e) {
692
+ return false
693
+ }
694
+ }
695
+ },
696
+ // 兼容旧插槽函数
697
+ compatibleTheSlot (_item) {
698
+ if (_item.slotKeyMap) {
699
+ _item.slot.keyMap = _item.slotKeyMap
700
+ delete _item.slotKeyMap
701
+ }
702
+ if (_item.slotValue) {
703
+ _item.slot.value = _item.slotValue
704
+ delete _item.slotValue
705
+ }
706
+ if (_item.actionText) {
707
+ _item.slot.actionText = _item.actionText
708
+ delete _item.actionText
709
+ }
710
+ }
711
+ }
712
+ }
713
+ </script>