create.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <el-dialog
  3. :visible.sync="dialogVisible"
  4. :close-on-click-modal="false"
  5. :close-on-press-escape="false"
  6. append-to-body
  7. :title="title"
  8. class="dialog dataTemplate-create-dialog"
  9. @open="getFormData"
  10. @close="closeDialog"
  11. >
  12. <el-form
  13. ref="dataTemplateForm"
  14. v-loading="dialogLoading"
  15. :element-loading-text="$t('common.loading')"
  16. :model="dataTemplate"
  17. :rules="rules"
  18. :label-width="formLabelWidth"
  19. @submit.native.prevent
  20. >
  21. <el-form-item label="模版名称:" prop="name">
  22. <el-input v-model="dataTemplate.name" v-pinyin="{vm:dataTemplate}" />
  23. </el-form-item>
  24. <el-form-item label="模版Key:" prop="key">
  25. <el-input v-model="dataTemplate.key" />
  26. </el-form-item>
  27. <el-form-item label="分类:" prop="typeId">
  28. <ibps-type-select
  29. ref="typeSelect"
  30. v-model="dataTemplate.typeId"
  31. category-key="BO_TYPE"
  32. clearable
  33. />
  34. </el-form-item>
  35. <el-form-item label="模版类型:" prop="type">
  36. <el-select v-model="dataTemplate.type" style="width:100%;">
  37. <el-option
  38. v-for="option in templateTypeOptions"
  39. :key="option.value"
  40. :value="option.value"
  41. :label="option.label"
  42. />
  43. </el-select>
  44. </el-form-item>
  45. <el-form-item v-if="dataTemplate.type !== 'valueSource'" label="展示形式:" prop="showType">
  46. <el-select v-model="dataTemplate.showType" style="width:100%;">
  47. <el-option
  48. v-for="option in showTypeOptions"
  49. :key="option.value"
  50. :value="option.value"
  51. :label="option.label"
  52. />
  53. </el-select>
  54. </el-form-item>
  55. <el-form-item v-if="dataTemplate.type !== 'valueSource' && dataTemplate.showType === 'compose'" label="组合形式:" prop="composeType">
  56. <el-select v-model="dataTemplate.composeType" style="width:100%;">
  57. <el-option
  58. v-for="option in composeTypeOptions"
  59. :key="option.value"
  60. :value="option.value"
  61. :label="option.label"
  62. />
  63. </el-select>
  64. </el-form-item>
  65. <el-form-item v-if="dataTemplate.showType !== 'compose'||dataTemplate.composeType==='treeForm'" prop="datasetKey">
  66. <span slot="label">
  67. <label>数据集</label>
  68. <el-tooltip
  69. v-if="!readonly"
  70. class="item"
  71. effect="light"
  72. content="左树右表单需选择有树形结构的表数据"
  73. placement="bottom"
  74. >
  75. <ibps-icon name="help" style="color:#dd5b44;" />
  76. </el-tooltip>:
  77. </span>
  78. <dataset-selector
  79. v-model="dataTemplate.datasetKey"
  80. value-key="key"
  81. @change="changeDataset"
  82. />
  83. </el-form-item>
  84. </el-form>
  85. <div slot="footer" class="el-dialog--center">
  86. <ibps-toolbar
  87. :actions="toolbars"
  88. @action-event="handleActionEvent"
  89. />
  90. </div>
  91. <!--字段设置-->
  92. <setting-field
  93. :visible="settingFieldDialogVisible"
  94. :dataset-key="dataTemplate.datasetKey"
  95. :dataset-type="dataTemplate.datasetType"
  96. :width="dataTemplate.datasetType==='thirdparty'?'60%':'60%'"
  97. :top="dataTemplate.datasetType==='thirdparty'?'0vh':'5vh'"
  98. type="next"
  99. @callback="handleSettingField"
  100. @close="visible => settingFieldDialogVisible = visible"
  101. />
  102. <thirdparty-config
  103. :visible="thirdpartyConfigDialogVisible"
  104. :datasets="dataTemplate.datasets"
  105. type="next"
  106. @callback="handleSettingField"
  107. @close="visible => settingFieldDialogVisible = visible"
  108. />
  109. <!--数据模版设置-->
  110. <template-builder
  111. :visible="templatebuilderDialogVisible"
  112. :data="dataTemplate"
  113. @callback="$emit('callback')"
  114. @close="visible => templatebuilderDialogVisible = visible"
  115. />
  116. </el-dialog>
  117. </template>
  118. <script>
  119. import { isKeyExists } from '@/api/platform/data/dataTemplate'
  120. import ActionUtils from '@/utils/action'
  121. import { templateTypeOptions, showTypeOptions, composeTypeOptions } from '@/business/platform/data/constants'
  122. import IbpsTypeSelect from '@/business/platform/cat/type/select'
  123. import DatasetSelector from '@/business/platform/data/dataset/selector'
  124. import SettingField from '@/business/platform/data/setting-field'
  125. import ThirdpartyConfig from '@/business/platform/data/setting-field/thirdparty-config'
  126. import TemplateBuilder from '@/business/platform/data/templatebuilder/dialog'
  127. // import Utils from '@/business/platform/data/templatebuilder/utils'
  128. import { testKey } from '@/utils/validate'
  129. import i18n from '@/utils/i18n'
  130. const validateFormKey = (rule, dataTemplateKey, callback) => {
  131. if (!testKey(dataTemplateKey)) {
  132. callback(new Error(i18n.t('validate.key')))
  133. } else {
  134. isKeyExists({
  135. dataTemplateKey: dataTemplateKey
  136. }).then(response => {
  137. if (response.data === true) {
  138. callback(new Error(`数据模版key已经存在`))
  139. return
  140. }
  141. callback()
  142. }).catch((err) => {
  143. callback(new Error(err))
  144. })
  145. }
  146. }
  147. export default {
  148. components: {
  149. IbpsTypeSelect,
  150. DatasetSelector,
  151. SettingField,
  152. ThirdpartyConfig,
  153. TemplateBuilder
  154. },
  155. props: {
  156. visible: {
  157. type: Boolean,
  158. default: false
  159. },
  160. readonly: {
  161. type: Boolean,
  162. default: false
  163. },
  164. id: String,
  165. title: String,
  166. typeId: String
  167. },
  168. data() {
  169. return {
  170. formName: 'dataTemplateForm',
  171. formLabelWidth: '120px',
  172. dialogVisible: this.visible,
  173. dialogLoading: false,
  174. templatebuilderDialogVisible: false,
  175. templateTypeOptions,
  176. showTypeOptions,
  177. composeTypeOptions,
  178. settingFieldDialogVisible: false,
  179. thirdpartyConfigDialogVisible: false,
  180. defaultForm: {},
  181. dataTemplate: {
  182. name: '',
  183. key: '',
  184. typeId: '',
  185. type: 'default',
  186. showType: 'list',
  187. composeType: 'treeList',
  188. datasetKey: '',
  189. datasetType: 'table',
  190. unique: ''
  191. },
  192. rules: {
  193. name: [{ required: true, message: this.$t('validate.required') }],
  194. key: [{ required: true, message: this.$t('validate.required') },
  195. { validator: validateFormKey, trigger: 'change' }],
  196. type: [{ required: true, message: this.$t('validate.required') }],
  197. composeType: [{ required: false, message: this.$t('validate.required') }],
  198. showType: [{ required: true, message: this.$t('validate.required') }],
  199. datasetKey: [{ required: true, message: this.$t('validate.required') }]
  200. },
  201. toolbars: [
  202. { key: 'next', icon: 'ibps-icon-arrow-circle-right', label: '下一步' },
  203. { key: 'cancel' }
  204. ]
  205. }
  206. },
  207. computed: {
  208. formId() {
  209. return this.id
  210. }
  211. },
  212. watch: {
  213. visible: {
  214. handler: function(val, oldVal) {
  215. this.dialogVisible = this.visible
  216. },
  217. immediate: true
  218. },
  219. 'dataTemplate.showType': {
  220. handler: function(val, oldVal) {
  221. if (val === 'compose') {
  222. this.formValidate()
  223. }
  224. },
  225. immediate: true
  226. }
  227. },
  228. created() {
  229. this.defaultForm = JSON.parse(JSON.stringify(this.dataTemplate))
  230. },
  231. methods: {
  232. changeDataset(data) {
  233. this.dataTemplate.datasetType = data.type
  234. },
  235. handleActionEvent({ key }) {
  236. switch (key) {
  237. case 'next':
  238. this.handleNext()
  239. break
  240. case 'cancel':
  241. this.closeDialog()
  242. break
  243. default:
  244. break
  245. }
  246. },
  247. // 设置字段
  248. handleNext() {
  249. this.$refs[this.formName].validate(valid => {
  250. if (valid) {
  251. // if (this.dataTemplate.datasetType === 'thirdparty') {
  252. // if (!(this.dataTemplate.type === 'dialog' || this.dataTemplate.type === 'valueSource')) {
  253. // ActionUtils.warning('第三方服务数据集只支持"对话框、值来源"模版类型!')
  254. // return
  255. // }
  256. // }
  257. if (this.dataTemplate.showType !== 'compose') {
  258. this.settingFieldDialogVisible = true
  259. this.closeDialog()
  260. } else {
  261. this.templatebuilderDialogVisible = true
  262. this.closeDialog()
  263. }
  264. } else {
  265. ActionUtils.saveErrorMessage()
  266. }
  267. })
  268. },
  269. handleSettingField(data) {
  270. // 如果是第三方服务,需要解析数据字段columns
  271. if (this.dataTemplate.datasetType === 'thirdparty') {
  272. this.dataTemplate.thirdparty = data
  273. // const queryColumnsAll = Utils.getFieldsByType('query')
  274. // console.log('queryColumnsAll', queryColumnsAll)
  275. // 1.1解析第三方服务字段-接口参数
  276. // const queryColumns = []
  277. // const requestData = data.requestData// array
  278. // if (this.$utils.isNotEmpty(requestData.bodyData)) {
  279. // requestData.bodyData.forEach(item => {
  280. // // 找到参数配置
  281. // this.forEachColumnArray('queryRootColumn', item, queryColumns)
  282. // })
  283. // console.log('queryColumns', queryColumns)
  284. // this.dataTemplate.queryColumns = queryColumns
  285. // }
  286. // TODO 1.2解析第三方服务字段-接口参数-分页
  287. // 2.1解析第三方服务字段-接口返回
  288. const dataColumns = []
  289. // const responseData = data.responseData// array
  290. // responseData.forEach(item => {
  291. // // 找到数据配置
  292. // this.forEachColumnArray('dataRootClumn', item, dataColumns)
  293. // })
  294. // console.log('dataColumns', dataColumns)
  295. this.dataTemplate.datasets = dataColumns
  296. // TODO 2.2解析第三方服务字段-接口返回-分页
  297. } else {
  298. this.dataTemplate.datasets = data
  299. }
  300. this.templatebuilderDialogVisible = true
  301. this.settingFieldDialogVisible = false
  302. },
  303. forEachColumnArray(bind, item, columns) {
  304. if (item.bindType.includes(bind)) {
  305. if (item.dataType === 'array') {
  306. const primaryItem = item.children[0]
  307. if (primaryItem.dataType === 'object') {
  308. const primaryObject = primaryItem.children
  309. const rootId = this.$utils.guid()
  310. const rootColumn = {
  311. 'id': rootId,
  312. 'label': primaryItem.desc,
  313. 'name': primaryItem.name,
  314. 'parentId': '0',
  315. 'type': 'table',
  316. 'attrType': 'table',
  317. 'objName': primaryItem.name,
  318. 'isPk': 'N',
  319. 'icon': 'table'
  320. }
  321. columns.push(rootColumn)
  322. primaryObject.forEach(item2 => {
  323. if (item2.dataType === 'array' || item2.dataType === 'object') {
  324. console.log('暂不支持子表字段解析')
  325. } else {
  326. // ibps-icon-table ibps-icon-varchar ibps-icon-number ibps-icon-date
  327. // id bindType name dataType children desc
  328. const type_ = (item2.dataType === 'string' ? 'varchar' : item2.dataType)
  329. const column = {
  330. 'id': item2.id,
  331. 'label': item2.desc,
  332. 'name': item2.name,
  333. 'parentId': rootId,
  334. 'type': type_,
  335. 'attrType': 'column',
  336. 'objName': item2.name,
  337. 'isPk': 'N',
  338. 'icon': type_
  339. }
  340. columns.push(column)
  341. }
  342. })
  343. } else {
  344. // 暂不支持
  345. ActionUtils.warning('返回数据体类型不支持非对象类型!')
  346. return
  347. }
  348. } else {
  349. // 暂不支持
  350. ActionUtils.warning('返回数据根类型不支持非数组数据!')
  351. return
  352. }
  353. }
  354. if (item.dataType === 'object' || item.dataType === 'array') {
  355. item.children.forEach(item2 => {
  356. this.forEachColumnArray(bind, item2, columns)
  357. })
  358. }
  359. },
  360. // 关闭当前窗口
  361. closeDialog() {
  362. this.$emit('close', false)
  363. },
  364. /**
  365. * 表单验证
  366. */
  367. formValidate() {
  368. if (this.readonly) return
  369. this.$nextTick(() => {
  370. this.$refs[this.formName].validate(() => {})
  371. })
  372. },
  373. /**
  374. * 获取表单数据
  375. */
  376. getFormData() {
  377. // 重置表单
  378. this.dataTemplate = JSON.parse(JSON.stringify(this.defaultForm))
  379. this.dataTemplate.typeId = this.typeId
  380. this.formValidate()
  381. this.$nextTick(() => {
  382. this.$refs['typeSelect'].loadTreeData()
  383. })
  384. }
  385. }
  386. }
  387. </script>
  388. <style lang="scss">
  389. .dataTemplate-create-dialog{
  390. .el-dialog__body{
  391. height: calc(70vh - 120px) !important;
  392. }
  393. }
  394. </style>