Detail.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <a-card :tab-list="tabList" size="small" style="min-height:600px" :active-tab-key="selectKey" @tabChange="onTabChange">
  3. <a-form v-show="model.id" size="small" v-if="selectKey === '0'">
  4. <a-form-item label="标题">
  5. <a-input v-model="model.label" />
  6. </a-form-item>
  7. <template v-if="model.type!=='divider'">
  8. <a-form-item label="字段名称">
  9. <a-input v-model="model.value" @blur="valueChange" />
  10. </a-form-item>
  11. <a-form-item label="是否必填">
  12. <a-switch v-model="model.required" />
  13. </a-form-item>
  14. <a-form-item label="默认提示" v-if="model.attrs">
  15. <a-input v-model="model.attrs.placeholder" />
  16. </a-form-item>
  17. </template>
  18. <template v-else>
  19. <a-form-item label="布局">
  20. <a-radio-group name="radioGroup" v-model="model.attrs.orientation">
  21. <a-radio value="left">
  22. 左边
  23. </a-radio>
  24. <a-radio value="center">
  25. 中间
  26. </a-radio>
  27. <a-radio value="right">
  28. 右边
  29. </a-radio>
  30. </a-radio-group>
  31. </a-form-item>
  32. </template>
  33. <!-- 数字输入框 -->
  34. <template v-if="model.type === 'number'">
  35. <a-form-item label="最小值">
  36. <a-input-number v-model="model.min" />
  37. </a-form-item>
  38. <a-form-item label="最大值">
  39. <a-input-number v-model="model.max" />
  40. </a-form-item>
  41. <a-form-item label="数值精度">
  42. <a-input-number v-model="model.precision" />
  43. </a-form-item>
  44. </template>
  45. <!-- 下拉框 -->
  46. <template v-if="model.type === 'select'">
  47. <a-form-item label="选项">
  48. <VueDraggable v-model="model.attrs.options" :animation="150" handle=".handle">
  49. <div v-for="(item, index) in model.attrs.options" :key="index" class="options">
  50. <a-space>
  51. <a-icon class="handle cursor-move" type="unordered-list" />
  52. <a-input-group compact>
  53. <a-input style="width:50%" v-model="item.label" />
  54. <a-input style="width:50%" v-model="item.value" />
  55. </a-input-group>
  56. <a-icon type="close" @click="deleteOption(index)" />
  57. </a-space>
  58. </div>
  59. </VueDraggable>
  60. <a-button @click="addOption" style="width:100%"><a-icon type="plus" /></a-button>
  61. </a-form-item>
  62. </template>
  63. <!-- 日期选择 -->
  64. <template v-if="model.type === 'date'">
  65. <a-form-item label="是否显示时间">
  66. <a-switch v-model="model.attrs.showTime" />
  67. </a-form-item>
  68. <a-form-item label="时间格式">
  69. <a-input placeholder="YYYY-MM-DD HH:mm:ss" v-model="model.attrs.format"></a-input>
  70. </a-form-item>
  71. </template>
  72. <!-- 上传 -->
  73. <template v-if="model.type === 'uploadFile'||model.type === 'uploadImg'">
  74. <a-form-item label="最大上传数">
  75. <a-input-number v-model="model.attrs.maxSize" />
  76. </a-form-item>
  77. </template>
  78. <!-- 选择数据 -->
  79. <template v-if="model.type === 'dataSelect'">
  80. <a-form-item label="选择表单">
  81. <a-select v-model="model.attrs.dict" placeholder="请选择" :options="DictCache.getChildrenList('TABLE_MAPPING')" @change="dictChange">
  82. </a-select>
  83. </a-form-item>
  84. <a-form-item label="选择类型">
  85. <a-radio-group name="radioGroup" v-model="model.attrs.selectType" @change="selectTypeChange">
  86. <a-radio value="radio">
  87. 单选
  88. </a-radio>
  89. <a-radio value="checkbox">
  90. 多选
  91. </a-radio>
  92. </a-radio-group>
  93. </a-form-item>
  94. <a-form-item label="默认字段" v-if="model.attrs.connect.length">
  95. <a-select v-model="model.attrs.connect[0].columnName" placeholder="请选择">
  96. <a-select-option v-for="item in tableList" :value="item.columnName" :key="item.columnName">
  97. {{ item.columnComment }}
  98. </a-select-option>
  99. </a-select>
  100. </a-form-item>
  101. <!-- <a-form-item label="附加字段" v-if="model.attrs.connect.length&&model.attrs.selectType=='radio'">
  102. <a-select mode="multiple" v-model="additionalField" placeholder="请选择" @change="additionalFieldChange">
  103. <a-select-option v-for="item in tableList" :value="item.columnName" :key="item.columnName" :label=" item.columnComment">
  104. {{ item.columnComment }}
  105. </a-select-option>
  106. </a-select>
  107. <a-button type="primary" @click="addForm()">添加到表单</a-button>
  108. </a-form-item> -->
  109. </template>
  110. <a-popconfirm title="确定删除该组件?" ok-text="确定" cancel-text="取消" @confirm="deleteModel">
  111. <a-button type="danger" style="width:100%">删除</a-button>
  112. </a-popconfirm>
  113. </a-form>
  114. <a-form size="small" v-if="selectKey === '1'">
  115. <a-form-item label="布局">
  116. <a-radio-group name="radioGroup" v-model="config.layout">
  117. <a-radio :value="1">
  118. 单列
  119. </a-radio>
  120. <a-radio :value="2">
  121. 双列
  122. </a-radio>
  123. <a-radio :value="3">
  124. 三列
  125. </a-radio>
  126. </a-radio-group>
  127. </a-form-item>
  128. </a-form>
  129. <BindTable ref="bindTable" @bind="handleBind" />
  130. </a-card>
  131. </template>
  132. <script>
  133. import { VueDraggable } from 'vue-draggable-plus'
  134. import { getTableInfos } from '@/api/custom/form'
  135. import BindTable from './BindTable.vue'
  136. export default {
  137. components: {
  138. VueDraggable,
  139. BindTable,
  140. },
  141. data() {
  142. return {
  143. model: {
  144. attrs: {
  145. placeholder: '',
  146. },
  147. },
  148. config: {},
  149. selectKey: '0',
  150. tabList: [
  151. {
  152. key: '0',
  153. tab: '字段属性',
  154. },
  155. {
  156. key: '1',
  157. tab: '表单属性',
  158. },
  159. ],
  160. tableList: [],
  161. additionalField: [],
  162. }
  163. },
  164. created() {},
  165. methods: {
  166. base(val, config) {
  167. this.model = val
  168. this.config = config
  169. if (this.model.attrs.dict !== undefined && this.model.attrs.dict !== '') {
  170. this.dictChange(this.model.attrs.dict)
  171. }
  172. this.additionalField =
  173. val.attrs.connect && val.attrs.connect.length > 1
  174. ? val.attrs.connect.slice(1, val.attrs.connect.length).map((item) => item.columnName)
  175. : []
  176. },
  177. addOption() {
  178. this.model.attrs.options.push({
  179. label: '选项' + (this.model.attrs.options.length + 1),
  180. value: 'newValue' + (this.model.attrs.options.length + 1),
  181. })
  182. },
  183. deleteOption(i) {
  184. this.model.attrs.options.splice(i, 1)
  185. },
  186. deleteModel() {
  187. this.$emit('delete', this.model)
  188. },
  189. dictChange(tableName) {
  190. getTableInfos({ tableName }).then((res) => {
  191. this.tableList = res.data
  192. if (this.model.attrs.connect.length === 0) {
  193. this.model.attrs.connect.push({
  194. bind: this.model.value,
  195. columnName: 'id',
  196. columnComment: 'id',
  197. })
  198. }
  199. })
  200. },
  201. valueChange() {
  202. if (this.model.type === 'dataSelect' && this.model.attrs.connect.length > 0) {
  203. this.model.attrs.connect[0].bind = this.model.value
  204. }
  205. },
  206. selectTypeChange() {
  207. this.model.attrs.connect.splice(1)
  208. this.additionalField = []
  209. },
  210. additionalFieldChange(val, e) {
  211. const arr = e.map((item) => {
  212. return {
  213. bind: item.key,
  214. columnName: item.key,
  215. columnComment: item.componentOptions.propsData.label,
  216. }
  217. })
  218. this.model.attrs.connect.splice(1, this.model.attrs.connect.length - 1, ...arr)
  219. },
  220. addForm() {
  221. this.$emit('addForm', this.model.attrs.connect.slice(1, this.model.attrs.connect.length))
  222. },
  223. bindTable(tableName) {
  224. this.$refs.bindTable.base(this.tableList)
  225. },
  226. handleBind(val) {
  227. this.model.attrs.connect = val
  228. },
  229. onTabChange(key) {
  230. this.selectKey = key
  231. },
  232. },
  233. }
  234. </script>
  235. <style lang="less" scoped>
  236. .options {
  237. margin-bottom: 5px;
  238. }
  239. </style>