xm-formchildtable.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <div>
  3. <a-form-model-item>
  4. <a-button :class="$style.settingBtn" @click="show = true">字段设置</a-button>
  5. <sdHeader
  6. v-if="!inline"
  7. :value="checkedOptions"
  8. :columns="selectOptions"
  9. @change="settingColumn"
  10. />
  11. <a-button
  12. :class="$style.settingBtn"
  13. :disabled="!selectOptions.length"
  14. @click="defaultShow = true"
  15. >默认值设置</a-button
  16. >
  17. </a-form-model-item>
  18. <!-- <a-form-model-item
  19. v-if="!inline && component.attrFD.formItemProps.inputProps.modalProps"
  20. label="弹框宽度(px)"
  21. >
  22. <a-input-number
  23. v-model="component.attrFD.formItemProps.inputProps.modalProps.width"
  24. :min="0"
  25. />
  26. </a-form-model-item> -->
  27. <a-form-model-item label="新建表单pageId">
  28. <a-input v-model="component.attrFD.formItemProps.inputProps.pageId" />
  29. </a-form-model-item>
  30. <a-form-model-item label="列表查询formId">
  31. <a-input v-model="component.attrFD.formItemProps.inputProps.formId" />
  32. </a-form-model-item>
  33. <a-form-model-item label="新建URL参数">
  34. <a-input v-model="component.attrFD.formItemProps.inputProps.urlQuery" />
  35. </a-form-model-item>
  36. <a-form-model-item label="赋值字段名">
  37. <a-input v-model="component.attrFD.formItemProps.inputProps.fieldName" />
  38. </a-form-model-item>
  39. <!-- <a-form-model-item label="行数范围">
  40. <sd-range-input
  41. :max.sync="component.attr.maxLength"
  42. :min.sync="component.attr.minLength"
  43. disable-negative
  44. />
  45. </a-form-model-item> -->
  46. <a-modal
  47. v-model="show"
  48. :footer="null"
  49. destroy-on-close
  50. width="92%"
  51. :class="{ [$style.inline]: inline, [$style.modal]: true }"
  52. >
  53. <component :is="formDesinger" ref="designer" :value="editData" :show-form-props="false">
  54. <template v-slot:toolbar>
  55. <component :is="sdSwitchModebtn" v-if="!inline" />
  56. <a-button icon="save" type="link" @click="saveColumn">
  57. 确定
  58. </a-button>
  59. </template>
  60. </component>
  61. </a-modal>
  62. <!-- <a-modal v-model="defaultShow" :width="800" destroy-on-close title="设置默认值" @ok="handleOk">
  63. <SdChildTable
  64. v-model="defaultValue"
  65. :label="component.caption"
  66. :columns="columns"
  67. :min="parseInt(component.attr.maxLength) || 0"
  68. :max="parseInt(component.attr.maxLength) || Infinity"
  69. :fields="component.attr.dync.filter((item) => !item.attrFD.hidden)"
  70. :sequence-column="component.attrFD.formItemProps.inputProps.sequenceColumn"
  71. >
  72. </SdChildTable>
  73. </a-modal> -->
  74. <a-form-model-item>
  75. <a-checkbox slot="label" v-model="component.attr.disableAd">
  76. 禁用新建删除
  77. </a-checkbox>
  78. </a-form-model-item>
  79. <a-form-model-item>
  80. <a-checkbox slot="label" v-model="component.attrFD.formItemProps.inputProps.hideCaption">
  81. 隐藏表头
  82. </a-checkbox>
  83. </a-form-model-item>
  84. <!-- <a-form-model-item>
  85. <a-checkbox slot="label" v-model="component.attrFD.formItemProps.inputProps.sequenceColumn">
  86. 显示序号
  87. </a-checkbox>
  88. </a-form-model-item> -->
  89. <!-- <a-form-model-item>
  90. <a-checkbox slot="label" v-model="component.attrFD.formItemProps.inputProps.importable">
  91. Excel导入
  92. <a-tooltip title="子表只有文本、数字和单选类型的字段时支持导入">
  93. <a-icon type="question-circle-o" />
  94. </a-tooltip>
  95. </a-checkbox>
  96. </a-form-model-item> -->
  97. </div>
  98. </template>
  99. <script>
  100. import asyncComponent from '@/common/services/async-component'
  101. import XmChildTable from '../../../src_product/iam/components/xm-child-table.vue'
  102. import sdHeader from '../../../src/form-designer/component-library/child-table/sd-header-config'
  103. import components from './_import-components/xm-formchildtable-import'
  104. export const metaInfo = {
  105. caption: '新建表单子表',
  106. component: {
  107. props: ['designerData'],
  108. render() {
  109. const columns = this.designerData.attr.dync
  110. .filter((item) => item.attrFD.hidden)
  111. .map((item) => {
  112. return {
  113. dataIndex: item.name,
  114. sdHidden: true,
  115. }
  116. })
  117. .concat(this.designerData.attrFD.formItemProps?.inputProps?.columns || [])
  118. const defaultValue = JSON.parse(this.designerData.attr?.defaultValue || '[]')
  119. return (
  120. <XmChildTable
  121. readOnly
  122. label={
  123. this.designerData.attrFD.formItemProps?.inputProps?.hideCaption
  124. ? null
  125. : this.designerData.caption
  126. }
  127. fields={this.designerData.attr.dync.filter((item) => !item.attrFD.hidden)}
  128. // sd-table不支持响应列动态变化,这里加个key强制动态渲染
  129. key={this.designerData.key}
  130. // sequenceColumn={this.designerData.attrFD.formItemProps?.inputProps?.sequenceColumn}
  131. columns={columns}
  132. value={defaultValue}
  133. addbuttonvisiable={false}
  134. class='formchildtable'
  135. />
  136. )
  137. },
  138. },
  139. icon: 'sd-list',
  140. order: 900,
  141. excludeFormTypes: [3],
  142. hiddenProps: ['hideLabel'],
  143. }
  144. export const fieldProps = {
  145. dataType: 'collection',
  146. attr: { dync: [], disableAd: false },
  147. attrFD: {
  148. columns: 4,
  149. hideLabel: true,
  150. formItemProps: {
  151. inputProps: {
  152. // sequenceColumn: false,
  153. importable: false,
  154. columns: [],
  155. hideCaption: false,
  156. modalProps: {},
  157. pageId: '',
  158. formId: '',
  159. urlQuery: '',
  160. fieldName: '',
  161. },
  162. },
  163. },
  164. key: 1,
  165. }
  166. export default {
  167. name: 'XmFormchildtable',
  168. components: { XmChildTable, ...components, sdHeader },
  169. props: {
  170. inline: {
  171. type: Boolean,
  172. default: false,
  173. },
  174. },
  175. data() {
  176. return {
  177. show: false,
  178. defaultShow: false,
  179. formDesinger: asyncComponent(() =>
  180. import(
  181. /* webpackChunkName: "sd-form-designer" */ '../../../src/form-designer/sd-designer.vue'
  182. )
  183. ),
  184. sdSwitchModebtn: asyncComponent(() =>
  185. import(
  186. /* webpackChunkName: "sd-form-designer" */ '../../../src/form-designer/sd-switch-mode-btn.vue'
  187. )
  188. ),
  189. }
  190. },
  191. computed: {
  192. editData() {
  193. let attrFD = this.component?.attrFD.formItemProps?.inputProps?.childAttrFD
  194. if (attrFD) {
  195. attrFD.devMode = this.formProps.attrFD.devMode
  196. } else {
  197. attrFD = {
  198. columns: 1,
  199. theme: 'sd-default',
  200. type: this.inline ? 3 : 2,
  201. devMode: this.formProps.attrFD.devMode,
  202. layoutable: false,
  203. }
  204. }
  205. return {
  206. head: {
  207. tableTxt: '子表',
  208. tableName: 'form_' + Date.now(),
  209. tableType: 1, // 单表
  210. isDbSynch: this.formProps?.isDbSynch,
  211. attrFD,
  212. },
  213. fields: this.component?.attr?.dync || [],
  214. }
  215. },
  216. columns() {
  217. return this.component.attr.dync
  218. .filter((item) => item.attrFD.hidden)
  219. .map((item) => {
  220. return {
  221. dataIndex: item.name,
  222. sdHidden: true,
  223. }
  224. })
  225. .concat(this.component.attrFD.formItemProps?.inputProps?.columns || [])
  226. },
  227. defaultValue: {
  228. get() {
  229. return JSON.parse(this.component.attr?.defaultValue || '[]')
  230. },
  231. set(value) {
  232. this.$set(this.component.attr, 'defaultValue', JSON.stringify(value))
  233. },
  234. },
  235. selectOptions() {
  236. return this.component.attr.dync.filter(
  237. (item) => !item.attrFD.hidden && item.dataType !== 'collection'
  238. )
  239. },
  240. checkedOptions() {
  241. return this.component.attrFD.formItemProps.inputProps?.columns?.filter(
  242. (item) => !item.sdCandidate
  243. )
  244. },
  245. },
  246. created() {
  247. if (!this.component.attrFD.formItemProps.inputProps.modalProps) {
  248. this.component.attrFD.formItemProps.inputProps.modalProps = {}
  249. }
  250. },
  251. methods: {
  252. handleOk() {
  253. this.defaultShow = false
  254. this.component.key = this.component.key + 1
  255. },
  256. settingColumn(value) {
  257. const keys = [] // 设置的展示的列表
  258. const f = (arr) => {
  259. arr.forEach((a) => {
  260. a.dataIndex = a.name
  261. keys.push(a.name)
  262. if (a.children) f(a.children)
  263. })
  264. }
  265. f(value)
  266. // 其他的列设置成默认不展示
  267. const sdCandidateColumns = this.selectOptions
  268. .filter((item) => {
  269. return !keys.includes(item.name)
  270. })
  271. .map((item) => {
  272. return { sdCandidate: true, dataIndex: item.name }
  273. })
  274. // 设置子表列,包含树结构的情况
  275. this.$set(this.component.attrFD.formItemProps.inputProps, 'columns', [
  276. ...value,
  277. ...sdCandidateColumns,
  278. ])
  279. // dync排序按照列表的顺序排下
  280. const columnOrder = [...keys, ...sdCandidateColumns.map((item) => item.name)]
  281. this.component.attr.dync = this.component.attr.dync.sort((a, b) => {
  282. return columnOrder.indexOf(a.name) - columnOrder.indexOf(b.name)
  283. })
  284. this.component.key = this.component.key + 1
  285. },
  286. saveColumn() {
  287. this.$refs.designer.setComponentName(this.$refs.designer.selectedID)
  288. this.component.attr.dync = this.$refs.designer.getSaveData().fields
  289. this.component.attrFD.formItemProps.inputProps.childAttrFD = this.$refs.designer.getSaveData().head.attrFD
  290. this.updateColumns()
  291. this.show = false
  292. },
  293. updateColumns() {
  294. // 子表字段增减后,设置了列信息也同步修改
  295. const oldColumns = this.component.attrFD.formItemProps.inputProps.columns
  296. if (!oldColumns) {
  297. // 行内编辑,没有列设置
  298. this.component.key = this.component.key + 1
  299. return
  300. }
  301. let newColumns = this.component.attr.dync
  302. // 过滤掉被删除的字段
  303. const oldkeys = []
  304. const f = (columns) => {
  305. const c = columns.filter((item) => {
  306. const itemInew = newColumns.find((i) => i.name === item.dataIndex)
  307. if (itemInew) {
  308. oldkeys.push(item.dataIndex)
  309. }
  310. if (item.dataIndex.startsWith('auto') || itemInew) {
  311. return true
  312. }
  313. })
  314. columns.splice(0, 999)
  315. c.forEach((i) => columns.push(i))
  316. columns.forEach((column) => {
  317. if (column.children) f(column.children)
  318. })
  319. }
  320. f(oldColumns)
  321. // 找到新加的字段,追加到列设置里
  322. newColumns = newColumns
  323. .filter((i) => !oldkeys.includes(i.name))
  324. .map((m, index) => ({
  325. dataIndex: m.name,
  326. sdCandidate: index > 10 - oldkeys.length,
  327. }))
  328. this.component.attrFD.formItemProps.inputProps.columns = [
  329. ...oldColumns,
  330. ...newColumns,
  331. ].filter((item) => item.dataType !== 'collection')
  332. this.component.key = this.component.key + 1
  333. },
  334. },
  335. }
  336. </script>
  337. <style module lang="scss">
  338. @use '@/common/design' as *;
  339. .modal {
  340. :global(.ant-modal) {
  341. // 覆盖style标签里面的样式
  342. /* stylelint-disable-next-line */
  343. top: 0 !important;
  344. }
  345. :global(.ant-modal-body) {
  346. height: 100vh;
  347. max-height: 100vh;
  348. padding: 0;
  349. }
  350. }
  351. :global(.formchildtable) {
  352. :global(.caption_xm-child-table_product) {
  353. position: relative;
  354. }
  355. }
  356. .setting-btn {
  357. margin: 0 10px 10px 0;
  358. }
  359. .inline {
  360. :global(.ant-collapse-item:first-child) {
  361. display: none;
  362. }
  363. }
  364. .btnselect {
  365. position: relative;
  366. top: 2px;
  367. right: 80px;
  368. float: right;
  369. .batchselect {
  370. z-index: 100;
  371. margin-left: 10px;
  372. }
  373. }
  374. </style>