config.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <template>
  2. <a-card :bordered="false">
  3. <s-table
  4. ref="tableRef"
  5. :columns="columns"
  6. :data="loadDate"
  7. :expand-row-by-click="true"
  8. :showPagination="false"
  9. bordered
  10. >
  11. <template #bodyCell="{ column, record, index }">
  12. <template v-if="column.dataIndex === 'fieldRemark'">
  13. <a-input v-model:value="record.fieldRemark"/>
  14. </template>
  15. <template v-if="column.dataIndex === 'fieldJavaType'">
  16. <a-select
  17. class="xn-wd"
  18. v-model:value="record.fieldJavaType"
  19. :options="fieldJavaTypeOptions"
  20. placeholder="请选择"
  21. :disabled="toCommonFieldEstimate(record)"
  22. @change="fieldJavaTypeChange(record)"
  23. />
  24. </template>
  25. <template v-if="column.dataIndex === 'effectType'">
  26. <a-select
  27. class="xn-wd"
  28. v-model:value="record.effectType"
  29. :options="effectTypeOptions"
  30. placeholder="请选择"
  31. :disabled="toCommonFieldEstimate(record) || toFieldSelectEstimate(record)"
  32. @change="effectTypeChange(record)"
  33. />
  34. </template>
  35. <template v-if="column.dataIndex === 'dictTypeCode'">
  36. <a-select
  37. v-if="record.effectType === 'radio' || record.effectType === 'select' || record.effectType === 'checkbox'"
  38. class="xn-wd"
  39. v-model:value="record.dictTypeCode"
  40. :options="dictTypeCodeOptions"
  41. placeholder="请选择字典"
  42. />
  43. <span v-else>无</span>
  44. </template>
  45. <template v-if="column.dataIndex === 'whetherTable'">
  46. <a-checkbox v-model:checked="record.whetherTable" @change="whetherTableChange(record)"/>
  47. </template>
  48. <template v-if="column.dataIndex === 'whetherRetract'">
  49. <a-checkbox v-model:checked="record.whetherRetract" :disabled="!record.whetherTable"/>
  50. </template>
  51. <template v-if="column.dataIndex === 'whetherSort'">
  52. <a-checkbox v-model:checked="record.whetherSort" :disabled="!record.whetherTable"/>
  53. </template>
  54. <template v-if="column.dataIndex === 'whetherFixed'">
  55. <a-radio-group v-model:value="record.whetherFixed" button-style="solid" size="small">
  56. <a-radio-button :value="1">左</a-radio-button>
  57. <a-radio-button :value="0">默认</a-radio-button>
  58. <a-radio-button :value="2">右</a-radio-button>
  59. </a-radio-group>
  60. </template>
  61. <template v-if="column.dataIndex === 'whetherAddUpdate'">
  62. <a-checkbox v-model:checked="record.whetherAddUpdate" :disabled="toFieldEstimate(record)"/>
  63. </template>
  64. <template v-if="column.dataIndex === 'whetherRequired'">
  65. <a-checkbox
  66. v-model:checked="record.whetherRequired"
  67. :disabled="toFieldEstimate(record) || !record.whetherAddUpdate"
  68. />
  69. </template>
  70. <template v-if="column.dataIndex === 'queryWhether'">
  71. <a-switch v-model:checked="record.queryWhether" :disabled="toQueryWhetherDisabled(record)"/>
  72. </template>
  73. <template v-if="column.dataIndex === 'queryType'">
  74. <a-select
  75. v-if="record.queryWhether === true && record.effectType !== 'datepicker'"
  76. class="xn-wd"
  77. v-model:value="record.queryType"
  78. :options="queryTypeOptions"
  79. placeholder="请选择"
  80. />
  81. <span v-else-if="record.effectType === 'datepicker' && record.queryWhether === true">时间段</span>
  82. <span v-else>无</span>
  83. </template>
  84. <template v-if="column.dataIndex === 'move'">
  85. <a-button type="primary" shape="circle" v-if="index !== 0" @click="rowMove(true, index)"
  86. :style="{marginRight: index > 0 ? '10px' : 0}">
  87. <template #icon>
  88. <ArrowUpOutlined/>
  89. </template>
  90. </a-button>
  91. <a-button type="primary" shape="circle" v-if="index < tableData.length - 1"
  92. @click="rowMove(false, index)">
  93. <template #icon>
  94. <ArrowDownOutlined/>
  95. </template>
  96. </a-button>
  97. </template>
  98. </template>
  99. </s-table>
  100. </a-card>
  101. </template>
  102. <script setup name="genConfig">
  103. import tool from '@/utils/tool'
  104. import genConfigApi from '@/api/gen/genConfigApi'
  105. import {cloneDeep} from 'lodash-es'
  106. const tableRef = ref()
  107. const recordData = ref()
  108. const tableData = ref()
  109. const columns = [
  110. {
  111. title: '字段',
  112. align: 'center',
  113. dataIndex: 'fieldName',
  114. ellipsis: true
  115. },
  116. {
  117. title: '注释',
  118. align: 'center',
  119. dataIndex: 'fieldRemark',
  120. ellipsis: true
  121. },
  122. {
  123. title: '类型',
  124. align: 'center',
  125. dataIndex: 'fieldType',
  126. ellipsis: true
  127. },
  128. {
  129. title: '实体类型',
  130. align: 'center',
  131. dataIndex: 'fieldJavaType',
  132. ellipsis: true
  133. },
  134. {
  135. title: '作用类型',
  136. align: 'center',
  137. dataIndex: 'effectType',
  138. ellipsis: true
  139. },
  140. {
  141. title: '字典',
  142. align: 'center',
  143. dataIndex: 'dictTypeCode',
  144. width: 140
  145. },
  146. {
  147. title: '列表显示',
  148. align: 'center',
  149. dataIndex: 'whetherTable',
  150. width: 80
  151. },
  152. {
  153. title: '列省略',
  154. align: 'center',
  155. dataIndex: 'whetherRetract',
  156. width: 80
  157. },
  158. {
  159. title: '列排序',
  160. align: 'center',
  161. dataIndex: 'whetherSort',
  162. width: 80
  163. },
  164. {
  165. title: '列固定',
  166. align: 'center',
  167. dataIndex: 'whetherFixed',
  168. width: 140
  169. },
  170. {
  171. title: '增改',
  172. align: 'center',
  173. dataIndex: 'whetherAddUpdate',
  174. width: 80
  175. },
  176. {
  177. title: '必填',
  178. align: 'center',
  179. dataIndex: 'whetherRequired',
  180. width: 80
  181. },
  182. {
  183. title: '查询',
  184. align: 'center',
  185. dataIndex: 'queryWhether',
  186. width: 80
  187. },
  188. {
  189. title: '查询方式',
  190. align: 'center',
  191. dataIndex: 'queryType'
  192. },
  193. {
  194. title: '移动',
  195. align: 'center',
  196. dataIndex: 'move',
  197. width: 120
  198. }
  199. ]
  200. const onOpen = (record) => {
  201. recordData.value = record
  202. nextTick(() => {
  203. tableRef.value.refresh()
  204. })
  205. }
  206. // 表格查询 返回 Promise 对象
  207. const loadDate = (parameter) => {
  208. if (recordData.value) {
  209. parameter.basicId = recordData.value.id
  210. return genConfigApi.configList(parameter).then((data) => {
  211. tableData.value = JSON.parse(JSON.stringify(data))
  212. let deleteIndex = []
  213. tableData.value.forEach((item, index) => {
  214. for (const key in item) {
  215. if (item[key] === 'Y') {
  216. item[key] = true
  217. }
  218. if (item[key] === 'N') {
  219. item[key] = false
  220. }
  221. }
  222. // 如果是主键,我们不提供主键的配置,也用不到
  223. if (item.isTableKey) {
  224. deleteIndex.push(index)
  225. }
  226. // 去掉删除标识
  227. if (item.fieldName.toLowerCase().indexOf('delete_flag') > -1) {
  228. deleteIndex.push(index)
  229. }
  230. // 让默认的变成设置的
  231. fieldJavaTypeChange(item)
  232. })
  233. if (deleteIndex) {
  234. deleteIndex.forEach((item, index) => {
  235. if (index > 0) {
  236. item = item - 1
  237. }
  238. delete tableData.value.splice(item, 1)
  239. })
  240. }
  241. return tableData.value
  242. })
  243. } else {
  244. return new Promise((resolve, reject) => {
  245. resolve([])
  246. })
  247. }
  248. }
  249. // 实体类型
  250. const fieldJavaTypeOptions = ref([
  251. {
  252. label: 'Integer',
  253. value: 'Integer'
  254. },
  255. {
  256. label: 'Long',
  257. value: 'Long'
  258. },
  259. {
  260. label: 'String',
  261. value: 'String'
  262. },
  263. {
  264. label: 'Boolean',
  265. value: 'Boolean'
  266. },
  267. {
  268. label: 'Float',
  269. value: 'Float'
  270. },
  271. {
  272. label: 'Double',
  273. value: 'Double'
  274. },
  275. {
  276. label: 'Date',
  277. value: 'Date'
  278. },
  279. {
  280. label: 'BigDecimal',
  281. value: 'BigDecimal'
  282. }
  283. ])
  284. // 类型
  285. const effectTypeOptions = ref([
  286. {
  287. label: '输入框',
  288. value: 'input'
  289. },
  290. {
  291. label: '文本框',
  292. value: 'textarea'
  293. },
  294. {
  295. label: '下拉框',
  296. value: 'select'
  297. },
  298. {
  299. label: '单选框',
  300. value: 'radio'
  301. },
  302. {
  303. label: '复选框',
  304. value: 'checkbox'
  305. },
  306. {
  307. label: '日期选择器',
  308. value: 'datepicker'
  309. },
  310. {
  311. label: '时间选择器',
  312. value: 'timepicker'
  313. },
  314. {
  315. label: '数字输入框',
  316. value: 'inputNumber'
  317. },
  318. {
  319. label: '滑动数字条',
  320. value: 'slider'
  321. },
  322. {
  323. label: '图片上传',
  324. value: 'imageUpload'
  325. },
  326. {
  327. label: '文件上传',
  328. value: 'fileUpload'
  329. },
  330. {
  331. label: '富文本',
  332. value: 'editor'
  333. }
  334. ])
  335. // 字典数据
  336. const dictTypeCodeOptions = tool.dictDataAll().map((item) => {
  337. return {
  338. label: item.name,
  339. value: item.dictValue
  340. }
  341. })
  342. // 查询方式
  343. const queryTypeOptions = ref([
  344. {
  345. label: '模糊包含',
  346. value: 'like'
  347. },
  348. {
  349. label: '模糊不包含',
  350. value: 'notLike'
  351. },
  352. {
  353. label: '等于',
  354. value: 'eq'
  355. },
  356. {
  357. label: '不等于',
  358. value: 'ne'
  359. },
  360. {
  361. label: '大于',
  362. value: 'gt'
  363. },
  364. {
  365. label: '大于等于',
  366. value: 'ge'
  367. },
  368. {
  369. label: '小于',
  370. value: 'lt'
  371. },
  372. {
  373. label: '小于等于',
  374. value: 'le'
  375. }
  376. ])
  377. const emit = defineEmits({successful: null}, {close: null})
  378. const toFieldEstimate = (data) => {
  379. if (
  380. data.fieldName.toLowerCase().indexOf('create_user') > -1 ||
  381. data.fieldName.toLowerCase().indexOf('create_time') > -1 ||
  382. data.fieldName.toLowerCase().indexOf('update_user') > -1 ||
  383. data.fieldName.toLowerCase().indexOf('update_time') > -1 ||
  384. data.fieldName.toLowerCase().indexOf('delete_flag') > -1 ||
  385. data.isTableKey === true
  386. ) {
  387. return true
  388. }
  389. return false
  390. }
  391. // 通用字段是否可选
  392. const toCommonFieldEstimate = (record) => {
  393. if (
  394. record.fieldName.toLowerCase().indexOf('create_user') > -1 ||
  395. record.fieldName.toLowerCase().indexOf('update_user') > -1
  396. ) {
  397. return true
  398. }
  399. return false
  400. }
  401. // 设置该下拉框是否能选
  402. const toFieldSelectEstimate = (record) => {
  403. if (record.fieldJavaType === 'Date' && record.effectType === 'datepicker') {
  404. return true
  405. }
  406. return false
  407. }
  408. // 选择作用类型触发-这里只负责字段类型的赋值,至于禁用是每一个字段自己的
  409. const effectTypeChange = (record) => {
  410. // 图片跟文件不可设置查询跟查询方式
  411. if (record.effectType === 'imageUpload' || record.effectType === 'fileUpload') {
  412. record.queryWhether = 'N'
  413. record.queryType = null
  414. }
  415. // 富文本只能模糊包含跟模糊不包含
  416. if (record.effectType === 'editor') {
  417. record.whetherTable = false
  418. record.whetherRetract = false
  419. record.whetherSort = false
  420. record.whetherFixed = 0
  421. record.queryWhether = 'N'
  422. record.queryType = null
  423. }
  424. }
  425. // 点击列表显示,处理
  426. const whetherTableChange = (record) => {
  427. // 如果去除了勾选,清理部分数据
  428. if (!record.whetherTable) {
  429. record.queryWhether = 'N'
  430. record.queryType = null
  431. }
  432. }
  433. // 查询条件是否可用
  434. const toQueryWhetherDisabled = (record) => {
  435. // 去掉了列表显示、图片上传、文件上传是不让生成搜索的
  436. return !record.whetherTable || record.effectType === 'imageUpload' || record.effectType === 'fileUpload'
  437. }
  438. // 实体类型选择触发
  439. const fieldJavaTypeChange = (record) => {
  440. if (record.fieldJavaType === 'Date') {
  441. record.effectType = 'datepicker'
  442. }
  443. }
  444. // 提交
  445. const onSubmit = (recordData) => {
  446. let submitParam = cloneDeep(tableData.value)
  447. let errStatus = 100
  448. submitParam.forEach((item, index) => {
  449. // 必填那一项转换
  450. for (const key in item) {
  451. if (item[key] === true) {
  452. item[key] = 'Y'
  453. }
  454. if (item[key] === false) {
  455. item[key] = 'N'
  456. }
  457. }
  458. if (item.queryWhether === 'Y' && !item.queryType) {
  459. // 排除掉时间选择
  460. if (item.fieldJavaType !== 'Date' && item.effectType !== 'checkbox') {
  461. errStatus++
  462. }
  463. }
  464. if (
  465. (item.effectType === 'select' || item.effectType === 'radio' || item.effectType === 'checkbox') &&
  466. !item.dictTypeCode
  467. ) {
  468. errStatus++
  469. }
  470. // 排序码重新生成,+1补位ID
  471. item.sortCode = index + 1
  472. })
  473. return new Promise((resolve, reject) => {
  474. if (errStatus > 100) {
  475. reject('校验失败,请选择对应的下拉框选项')
  476. return
  477. }
  478. genConfigApi
  479. .configEditBatch(submitParam)
  480. .then((data) => {
  481. resolve(data)
  482. })
  483. .catch((err) => {
  484. reject(err)
  485. })
  486. })
  487. }
  488. const rowMove = (flag, index) => {
  489. if (flag) {
  490. let temp = tableData.value[index - 1]
  491. tableData.value[index - 1] = tableData.value[index]
  492. tableData.value[index] = temp
  493. } else {
  494. let temp = tableData.value[index + 1]
  495. tableData.value[index + 1] = tableData.value[index]
  496. tableData.value[index] = temp
  497. }
  498. }
  499. // 抛出钩子
  500. defineExpose({
  501. onOpen,
  502. onSubmit
  503. })
  504. </script>
  505. <style scoped>
  506. .table-wrapper {
  507. margin-top: -16px !important;
  508. }
  509. </style>