index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="form-property">
  3. <config-tabs v-model:active="activeType" :group-list="groupList"></config-tabs>
  4. <div class="config-form-wrapper">
  5. <div v-show="activeType === 'field' && !selectItem?.id" class="empty-form--text">请添加字段</div>
  6. <cip-form v-show="activeType === 'field' && selectItem.id"
  7. label-position="top"
  8. :model="itemConfig"
  9. @update:model="updateSelectItem"
  10. :field-list="fieldComponentConfigureFieldConfigList"
  11. model-key="id">
  12. <template #labelWidthInput="{fieldKey, updateModel}">
  13. <cip-input-switch :model-value="itemConfig[fieldKey]" @update:modelValue="updateModel">
  14. <template #input="{disabled, modelValue, updateModelValue}">
  15. <el-input-number :disabled="disabled"
  16. :modelValue="modelValue"
  17. :step="10"
  18. :min="0"
  19. controls-position="right"
  20. @update:modelValue="updateModelValue"></el-input-number>
  21. </template>
  22. </cip-input-switch>
  23. </template>
  24. <template #validateValueInput="{fieldKey, updateModel}">
  25. <cip-input-switch :model-value="itemConfig[fieldKey]" @update:modelValue="updateModel">
  26. <template #input="{disabled, modelValue, updateModelValue}">
  27. <el-select :disabled="disabled"
  28. :model-value="modelValue"
  29. @update:modelValue="updateModelValue"
  30. placeholder="选择值类型"
  31. clearable style="width:100%">
  32. <el-option value="email" label="电子邮箱"></el-option>
  33. <el-option value="mobilePhone" label="手机号"></el-option>
  34. <el-option value="identityCard" label="身份证号"></el-option>
  35. </el-select>
  36. </template>
  37. </cip-input-switch>
  38. </template>
  39. <template #regexpValidateInput="{fieldKey, updateModel}">
  40. <cip-input-switch :model-value="itemConfig[fieldKey]" @update:modelValue="updateModel">
  41. <template #input="{disabled, modelValue, updateModelValue}">
  42. <el-input placeholder="填写正则表达式"
  43. :disabled="disabled"
  44. :model-value="modelValue"
  45. @update:modelValue="updateModelValue"
  46. clearable>
  47. </el-input>
  48. </template>
  49. </cip-input-switch>
  50. </template>
  51. <template #dependOnInput="{disabled, fieldKey, updateModel}">
  52. <el-select multiple
  53. :disabled="disabled"
  54. :model-value="itemConfig[fieldKey]"
  55. @update:modelValue="updateModel"
  56. placeholder="选择数据依赖"
  57. clearable style="width:100%">
  58. <el-option v-for="item in dependOnSelectList" :key="item.id" :value="item.key" :label="`${item.config.label}(${item.key})`"></el-option>
  59. </el-select>
  60. </template>
  61. <template #changeValueStrInput="{fieldKey, updateModel}">
  62. <code-mirror-dialog fn-name="changeValue" :fieldKey="fieldKey" :updateModel="updateModel" :itemConfig="itemConfig"/>
  63. </template>
  64. <template #changeConfigStrInput="{fieldKey, updateModel}">
  65. <code-mirror-dialog fn-name="changeConfig" :fieldKey="fieldKey" :updateModel="updateModel" :itemConfig="itemConfig"/>
  66. </template>
  67. </cip-form>
  68. <cip-form v-show="activeType === 'form'"
  69. label-position="top"
  70. :model="data"
  71. @update:model="updateData"
  72. :field-list="formConfigFieldConfigList"></cip-form>
  73. <!-- <cip-form v-show="activeType === 'column'"-->
  74. <!-- label-position="top"-->
  75. <!-- :model="tableConfig"-->
  76. <!-- @update:model="updateTableItem"-->
  77. <!-- :field-list="columnConfigFieldConfigList"-->
  78. <!-- :inline="false"></cip-form>-->
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import { computed, nextTick, ref, watch } from 'vue'
  84. import CipForm from '@cip/components/cip-form'
  85. import CipInputSwitch from '@cip/components/cip-input-switch'
  86. import ConfigTabs from './config-tabs'
  87. import { formConfigFieldConfigList, getComponentConfigure } from './config'
  88. import { mergeFieldConfig, configMapToList } from '@cip/utils/config-util'
  89. import { configureOptionsFieldConfigMap, defaultConfigureOptions } from '@cip/components/cip-form-input/input-configure-options'
  90. import { ElInputNumber, ElSelect, ElOption, ElInput } from 'element-plus'
  91. import CodeMirrorDialog from './code-mirror-dialog.vue';
  92. import { isLayoutType } from '@cip/components/cip-form-layout/util'
  93. export default {
  94. components: {
  95. CipForm,
  96. CipInputSwitch,
  97. ConfigTabs,
  98. ElInputNumber,
  99. ElSelect,
  100. ElOption,
  101. ElInput,
  102. CodeMirrorDialog
  103. },
  104. props: {
  105. selectItem: { type: Object, default: () => ({}) },
  106. data: Object
  107. },
  108. name: 'FormProperty',
  109. emits: ['update:data', 'update:selectItem', 'update:tableItem'],
  110. setup (props, { emit }) {
  111. const activeType = ref('field')
  112. const groupList = ref([
  113. { label: '字段配置', value: 'field' },
  114. { label: '表单配置', value: 'form' }
  115. // { label: '列表配置', value: 'column' }
  116. ])
  117. const itemConfig = computed(() => {
  118. const result = props.selectItem.config || {}
  119. result.key = props.selectItem.key
  120. result.id = props.selectItem.id
  121. console.log(props.data,itemConfig);
  122. return result
  123. })
  124. const getFieldComponentConfigureFieldConfigList = async (val) => {
  125. let configure
  126. try {
  127. configure = await getComponentConfigure(val)
  128. } catch (e) {
  129. // 若获取配置发生错误直接使用默认配置
  130. console.warn(`form-design: 获取${val}组件配置文件发生错误,使用默认配置进行替换`)
  131. configure = defaultConfigureOptions()
  132. }
  133. return configMapToList(mergeFieldConfig(configure, configureOptionsFieldConfigMap))
  134. }
  135. const fieldComponentConfigureFieldConfigList = ref([])
  136. watch(() => itemConfig.value.type, (val) => {
  137. if (val) {
  138. fieldComponentConfigureFieldConfigList.value = []
  139. // dependOn存在缓存问题,暂时先进行清空再赋值操作
  140. getFieldComponentConfigureFieldConfigList(val).then(res => {
  141. nextTick(() => {
  142. fieldComponentConfigureFieldConfigList.value = res
  143. })
  144. })
  145. } else {
  146. return []
  147. }
  148. }, { immediate: true })
  149. const tableConfig = computed(() => {
  150. return props.selectItem?.config?.tableItem ?? {}
  151. })
  152. const getOtherKeyItem = (item, otherKey) => {
  153. return {
  154. config: {
  155. label: item.config?.label
  156. },
  157. id: otherKey,
  158. key: otherKey
  159. }
  160. }
  161. const getDependOnSelectList = (list = [], keyList = [], totalFields = [], otherKeyList = []) => {
  162. list.forEach((item) => {
  163. const type = item.config?.type
  164. if (isLayoutType(type)) {
  165. const options = item.config.options || []
  166. const children = options.map((option) => option.children).flat()
  167. getDependOnSelectList(children, keyList, totalFields, otherKeyList)
  168. } else if (type === 'table') {
  169. const options = item.config?.options
  170. if (options?.length) {
  171. getDependOnSelectList(options, keyList, totalFields, otherKeyList)
  172. }
  173. } else {
  174. keyList.push(item)
  175. if(item?.config?.otherKey){
  176. const otherKey = item.config.otherKey
  177. if(Array.isArray(otherKey)){
  178. otherKeyList = [ ...otherKeyList, ...otherKey.map(key => getOtherKeyItem(item, key)) ]
  179. } else {
  180. otherKeyList.push(getOtherKeyItem(item, otherKey))
  181. }
  182. }
  183. }
  184. })
  185. return {keyList, otherKeyList}
  186. }
  187. const dependOnSelectList = computed(() => {
  188. const { keyList, otherKeyList } = getDependOnSelectList(props?.data?.list ?? [])
  189. return [...keyList, ...otherKeyList].filter(item => item.key !== itemConfig.value.key)
  190. })
  191. const updateData = (val) => {
  192. emit('update:data', val)
  193. }
  194. const updateSelectItem = (val) => {
  195. emit('update:selectItem', val)
  196. }
  197. const updateTableItem = val => {
  198. emit('update:tableItem', val)
  199. }
  200. const onActivated = (name) => {
  201. activeType.value = name
  202. }
  203. return {
  204. formConfigFieldConfigList,
  205. fieldComponentConfigureFieldConfigList,
  206. // columnConfigFieldConfigList,
  207. itemConfig,
  208. tableConfig,
  209. onActivated,
  210. groupList,
  211. activeType,
  212. updateData,
  213. updateSelectItem,
  214. updateTableItem,
  215. dependOnSelectList
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="less">
  221. .form-property{
  222. height: 100%;
  223. }
  224. .config-form-wrapper{
  225. height: calc(100% - 45px);
  226. position: relative;
  227. overflow: auto;
  228. .cip-form{
  229. padding: 10px;
  230. }
  231. //padding: 10px;
  232. }
  233. </style>