GenerateCard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <el-card
  3. :shadow="element.options.shadow"
  4. :body-style="{
  5. padding: element.options.padding
  6. }"
  7. :style="{
  8. width: element.options.width,
  9. 'border-width': element.options.bordered ? '1px' : '0px',
  10. '--padding': padding
  11. }"
  12. :class="{
  13. [element.options?.customClass]: element.options?.customClass ? true: false
  14. }"
  15. v-if="elementDisplay"
  16. >
  17. <div >
  18. <template v-for="item in element.list">
  19. <generate-col-item
  20. v-if="item.type == 'grid'"
  21. :key="item.key"
  22. :model="dataModels"
  23. :rules="rules"
  24. :element="item"
  25. :remote="remote"
  26. :blanks="blanks"
  27. :display="display"
  28. :sub-hide-fields="subHideFields"
  29. :sub-disabled-fields="subDisabledFields"
  30. :edit="edit"
  31. :remote-option="remoteOption"
  32. :platform="platform"
  33. :preview="preview"
  34. :container-key="containerKey"
  35. :data-source-value="dataSourceValue"
  36. :event-function="eventFunction"
  37. :print-read="printRead"
  38. :is-subform="isSubform"
  39. :row-index="rowIndex"
  40. :sub-name="subName"
  41. :is-dialog="isDialog"
  42. :dialog-name="dialogName"
  43. :is-group="isGroup"
  44. :group="group"
  45. :field-node="fieldNode"
  46. >
  47. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  48. <slot :name="blank.name" :model="scope.model"></slot>
  49. </template>
  50. </generate-col-item>
  51. <generate-tab-item
  52. v-else-if="item.type == 'tabs'"
  53. :key="item.key"
  54. :model="dataModels"
  55. :rules="rules"
  56. :element="item"
  57. :remote="remote"
  58. :blanks="blanks"
  59. :display="display"
  60. :sub-hide-fields="subHideFields"
  61. :sub-disabled-fields="subDisabledFields"
  62. :edit="edit"
  63. :remote-option="remoteOption"
  64. :platform="platform"
  65. :preview="preview"
  66. :container-key="containerKey"
  67. :data-source-value="dataSourceValue"
  68. :event-function="eventFunction"
  69. :print-read="printRead"
  70. :is-subform="isSubform"
  71. :row-index="rowIndex"
  72. :sub-name="subName"
  73. :is-dialog="isDialog"
  74. :dialog-name="dialogName"
  75. :is-group="isGroup"
  76. :group="group"
  77. :field-node="fieldNode"
  78. >
  79. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  80. <slot :name="blank.name" :model="scope.model"></slot>
  81. </template>
  82. </generate-tab-item>
  83. <generate-collapse
  84. v-else-if="item.type == 'collapse'"
  85. :key="item.key"
  86. :model="dataModels"
  87. :rules="rules"
  88. :element="item"
  89. :remote="remote"
  90. :blanks="blanks"
  91. :display="display"
  92. :sub-hide-fields="subHideFields"
  93. :sub-disabled-fields="subDisabledFields"
  94. :edit="edit"
  95. :remote-option="remoteOption"
  96. :platform="platform"
  97. :preview="preview"
  98. :container-key="containerKey"
  99. :data-source-value="dataSourceValue"
  100. :event-function="eventFunction"
  101. :print-read="printRead"
  102. :is-subform="isSubform"
  103. :row-index="rowIndex"
  104. :sub-name="subName"
  105. :is-dialog="isDialog"
  106. :dialog-name="dialogName"
  107. :is-group="isGroup"
  108. :group="group"
  109. :field-node="fieldNode"
  110. >
  111. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  112. <slot :name="blank.name" :model="scope.model"></slot>
  113. </template>
  114. </generate-collapse>
  115. <generate-report
  116. v-else-if="item.type == 'report'"
  117. :key="item.key"
  118. :model="dataModels"
  119. :rules="rules"
  120. :element="item"
  121. :remote="remote"
  122. :blanks="blanks"
  123. :display="display"
  124. :sub-hide-fields="subHideFields"
  125. :sub-disabled-fields="subDisabledFields"
  126. :edit="edit"
  127. :remote-option="remoteOption"
  128. :platform="platform"
  129. :preview="preview"
  130. :container-key="containerKey"
  131. :data-source-value="dataSourceValue"
  132. :event-function="eventFunction"
  133. :print-read="printRead"
  134. :is-subform="isSubform"
  135. :row-index="rowIndex"
  136. :sub-name="subName"
  137. :is-dialog="isDialog"
  138. :dialog-name="dialogName"
  139. :is-group="isGroup"
  140. :group="group"
  141. :field-node="fieldNode"
  142. >
  143. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  144. <slot :name="blank.name" :model="scope.model"></slot>
  145. </template>
  146. </generate-report>
  147. <generate-inline
  148. v-else-if="item.type == 'inline'"
  149. :key="item.key"
  150. :model="dataModels"
  151. :rules="rules"
  152. :element="item"
  153. :remote="remote"
  154. :blanks="blanks"
  155. :display="display"
  156. :sub-hide-fields="subHideFields"
  157. :sub-disabled-fields="subDisabledFields"
  158. :edit="edit"
  159. :remote-option="remoteOption"
  160. :platform="platform"
  161. :preview="preview"
  162. :container-key="containerKey"
  163. :data-source-value="dataSourceValue"
  164. :event-function="eventFunction"
  165. :print-read="printRead"
  166. :is-subform="isSubform"
  167. :row-index="rowIndex"
  168. :sub-name="subName"
  169. :is-dialog="isDialog"
  170. :dialog-name="dialogName"
  171. :is-group="isGroup"
  172. :group="group"
  173. :field-node="fieldNode"
  174. >
  175. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  176. <slot :name="blank.name" :model="scope.model"></slot>
  177. </template>
  178. </generate-inline>
  179. <generate-card
  180. v-else-if="item.type == 'card'"
  181. :key="item.key"
  182. :model="dataModels"
  183. :rules="rules"
  184. :element="item"
  185. :remote="remote"
  186. :blanks="blanks"
  187. :display="display"
  188. :sub-hide-fields="subHideFields"
  189. :sub-disabled-fields="subDisabledFields"
  190. :edit="edit"
  191. :remote-option="remoteOption"
  192. :platform="platform"
  193. :preview="preview"
  194. :container-key="containerKey"
  195. :data-source-value="dataSourceValue"
  196. :event-function="eventFunction"
  197. :print-read="printRead"
  198. :is-subform="isSubform"
  199. :row-index="rowIndex"
  200. :sub-name="subName"
  201. :is-dialog="isDialog"
  202. :dialog-name="dialogName"
  203. :is-group="isGroup"
  204. :group="group"
  205. :field-node="fieldNode"
  206. >
  207. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  208. <slot :name="blank.name" :model="scope.model"></slot>
  209. </template>
  210. </generate-card>
  211. <generate-form-item
  212. v-else
  213. :key="item.key"
  214. :models="dataModels"
  215. :rules="rules"
  216. :widget="item"
  217. :remote="remote"
  218. :blanks="blanks"
  219. :display="display"
  220. :sub-hide-fields="subHideFields"
  221. :sub-disabled-fields="subDisabledFields"
  222. :edit="edit"
  223. :remote-option="remoteOption"
  224. :platform="platform"
  225. :preview="preview"
  226. :container-key="containerKey"
  227. :data-source-value="dataSourceValue"
  228. :event-function="eventFunction"
  229. :print-read="printRead"
  230. :is-subform="isSubform"
  231. :row-index="rowIndex"
  232. :sub-name="subName"
  233. :is-dialog="isDialog"
  234. :dialog-name="dialogName"
  235. :is-group="isGroup"
  236. :group="group"
  237. :field-node="fieldNode"
  238. >
  239. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  240. <slot :name="blank.name" :model="scope.model"></slot>
  241. </template>
  242. </generate-form-item>
  243. </template>
  244. </div>
  245. <template #header v-if="element.options.showHeader">
  246. <div>
  247. <span>{{element.options.title}}</span>
  248. </div>
  249. </template>
  250. </el-card>
  251. </template>
  252. <script>
  253. import GenerateFormItem from './GenerateFormItem.vue'
  254. import GenerateInline from './GenerateInline.vue'
  255. import {executeExpression, isExpression, extractExpression} from '../util/expression'
  256. export default {
  257. name: 'generate-card',
  258. components: {
  259. GenerateFormItem,
  260. GenerateInline,
  261. GenerateReport: () => import('./GenerateReport.vue'),
  262. GenerateTabItem: () => import('./GenerateTabItem.vue'),
  263. GenerateCollapse: () => import('./GenerateCollapse.vue'),
  264. GenerateColItem: () => import('./GenerateColItem.vue'),
  265. },
  266. props: ['element', 'model', 'rules', 'remote', 'blanks', 'display', 'edit', 'remoteOption', 'platform', 'preview', 'containerKey', 'dataSourceValue', 'eventFunction', 'printRead', 'isSubform', 'rowIndex', 'subName', 'subHideFields', 'subDisabledFields', 'isDialog', 'dialogName', 'group', 'fieldNode', 'isGroup'],
  267. data () {
  268. return {
  269. dataModels: this.model
  270. }
  271. },
  272. inject: ['generateComponentInstance', 'deleteComponentInstance', 'dynamicHideFields', 'formContext'],
  273. mounted () {
  274. this.generateComponentInstance && this.generateComponentInstance(this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model, this)
  275. },
  276. beforeUnmount () {
  277. this.deleteComponentInstance && this.deleteComponentInstance(this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model)
  278. },
  279. computed: {
  280. padding () {
  281. return this.element.options.padding || '20px'
  282. },
  283. currentOptions () {
  284. if (this.isSubform) {
  285. return {
  286. fieldNode: this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model,
  287. rowIndex: this.rowIndex,
  288. row: this.model
  289. }
  290. } else {
  291. return {
  292. fieldNode: this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model,
  293. }
  294. }
  295. },
  296. elementDisplay () {
  297. let curFullField = this.fieldNode ? this.fieldNode + '.' + this.element.model : this.element.model
  298. let curField = this.group ? this.group + '.' + this.element.model : this.element.model
  299. if (this.dynamicHideFields[curFullField] != undefined) {
  300. return !this.dynamicHideFields[curFullField]
  301. }
  302. if (this.dynamicHideFields[curField] != undefined) {
  303. return !this.dynamicHideFields[curField]
  304. }
  305. if (typeof this.element.options.hidden === 'boolean') {
  306. return !this.element.options.hidden
  307. } else {
  308. if (isExpression(this.element.options.hidden)) {
  309. return !executeExpression(extractExpression(this.element.options.hidden), this.currentOptions, this.formContext)
  310. }
  311. }
  312. return true
  313. }
  314. },
  315. methods: {
  316. },
  317. watch: {
  318. model: {
  319. deep: true,
  320. handler (val) {
  321. this.dataModels = val
  322. }
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="scss">
  328. .fm-form{
  329. .el-card__header{
  330. padding: var(--padding)
  331. }
  332. }
  333. </style>