index.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { ref } from 'vue'
  2. import { PC, Mobile } from './widgets/icons-vue'
  3. import { cloneDeep } from '@cip/utils/util'
  4. import CipDialog from '@cip/components/cip-dialog'
  5. import CipCodeMirror from '@cip/components/cip-code-mirror'
  6. import CipButtonText from '@cip/components/cip-button-text'
  7. import CipMessageBox from '@cip/components/cip-message-box'
  8. import CipFormRenderPreview from '@cip/components/cip-form-render/preview'
  9. import CipFormDesignFramework from './widgets/framework'
  10. import EquipmentRadio from './widgets/equipment-radio'
  11. import FormComponents from './widgets/form-components'
  12. import FormDrawing from './widgets/form-drawing'
  13. import FormProperty from './widgets/form-property'
  14. import { componentsGroupList } from './components-config'
  15. import { useSelect } from './hooks'
  16. export default {
  17. name: 'CipFormDesign',
  18. props: {
  19. scheme: Object,
  20. componentsGroupList: {
  21. type: Array,
  22. default: () => componentsGroupList
  23. }
  24. },
  25. setup (props, { emit }) {
  26. const equipmentOptions = [
  27. { value: 'pc', svg: PC },
  28. { value: 'mobile', svg: Mobile }
  29. ]
  30. const equipment = ref('pc')
  31. const { selectItem, selectItemId, changeSelect, updateSelectItem } = useSelect()
  32. const updateFormConfig = (val) => {
  33. emit('update:scheme', val)
  34. }
  35. const updateList = (value) => {
  36. const scheme = props.scheme
  37. scheme.list = value
  38. updateFormConfig(scheme)
  39. }
  40. const updateTableItem = val => {
  41. if (selectItem.value.config) selectItem.value.config.tableItem = cloneDeep(val)
  42. }
  43. const addItem = (item) => {
  44. // TODO: 考虑如何在当前选中的内容下新增 搜索当前选中元素所在列表及位置 [注:暂不开放此功能]
  45. }
  46. const initScheme = () => ({
  47. labelPosition: 'right',
  48. labelWidth: 100,
  49. tableSize: 'default',
  50. list: []
  51. })
  52. const reset = () => {
  53. CipMessageBox.confirm('确认重置表单配置', '提示', {
  54. type: 'warning'
  55. }).then(() => {
  56. const config = initScheme()
  57. // 清理已选中的row
  58. selectItem.value = {}
  59. updateFormConfig(config)
  60. }, () => {})
  61. }
  62. const previewFormDialog = ref(false)
  63. const previewForm = () => {
  64. previewFormDialog.value = true
  65. }
  66. const previewJSONDialog = ref(false)
  67. const previewJSON = () => {
  68. previewJSONDialog.value = true
  69. }
  70. return () => <CipFormDesignFramework>
  71. {{
  72. components: () => <FormComponents groupList={props.componentsGroupList} onAdd={(item) => addItem(item)}/>,
  73. toolbar: () => <div style={{ width: '100%', display: 'flex', justifyContent: 'space-between', itemsAlign: 'center', height: '100%' }}>
  74. <EquipmentRadio v-model={equipment.value} options={equipmentOptions}/>
  75. <div>
  76. <CipButtonText onClick={() => reset()}>重置</CipButtonText>
  77. <CipButtonText onClick={() => previewForm()}>预览</CipButtonText>
  78. <CipButtonText onClick={() => previewJSON()}>预览JSON</CipButtonText>
  79. </div>
  80. </div>,
  81. default: () => <>
  82. <FormDrawing
  83. data={props.scheme}
  84. equipment={equipment.value}
  85. selectId={selectItemId.value}
  86. onSelect={(item) => changeSelect(item)}
  87. onUpdateList={(list) => { updateList(list) }}
  88. />
  89. <CipFormRenderPreview
  90. v-model={previewFormDialog.value}
  91. scheme={props.scheme}
  92. equipment={equipment.value}
  93. />
  94. <CipDialog v-model={previewJSONDialog.value} title={'预览JSON'} showOnly={true}>
  95. <CipCodeMirror modelValue={props.scheme} theme={'dracula'} height={'500px'}/>
  96. </CipDialog>
  97. </>,
  98. property: () => <FormProperty
  99. selectItem={selectItem.value}
  100. data={props.scheme}
  101. onUpdate:data={(val) => updateFormConfig(val)}
  102. onUpdate:selectItem={(val) => updateSelectItem(val)}
  103. onUpdate:tableItem={(val) => updateTableItem(val)}
  104. />
  105. }}
  106. </CipFormDesignFramework>
  107. }
  108. }