5421cb70fbc0bfe0ab0679a436f2a2eaa16f103c.svn-base 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div>
  3. <div class="table-operator">
  4. <a-button type="primary" icon="plus" @click="handleAddGraphRepoart">新增</a-button>
  5. <a-popconfirm v-if="selectedRowKeys.length" :title="'确定要删除这'+selectedRowKeys.length+'项吗?'" @confirm="() => handleRemoveGraphRepoart()">
  6. <a-button icon="minus" >删除</a-button>
  7. </a-popconfirm>
  8. </div>
  9. <a-table
  10. size="middle"
  11. bordered
  12. :rowKey="(record, index) => index"
  13. :columns="columns"
  14. :data-source="tableData_"
  15. :pagination="false"
  16. :row-selection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
  17. :scroll="getScroll"
  18. >
  19. <template v-for="(col,i) in scopedSlots" :slot="col.name" slot-scope="text, record">
  20. <div v-if="col.type === 'text'" :key="i" >
  21. <a-input
  22. :key="i"
  23. style="margin: -5px 0"
  24. v-model="record[col.name]"
  25. />
  26. </div>
  27. <div v-else-if="col.type === 'number'" :key="i" >
  28. <a-input
  29. :key="i"
  30. type="number"
  31. style="margin: -5px 0"
  32. v-model="record[col.name]"
  33. />
  34. </div>
  35. <div v-else-if="col.type === 'select'" :key="i" >
  36. <j-dict-select-tag
  37. :key="i"
  38. style="margin: -5px 0"
  39. :dict-code="col.dictCode"
  40. v-model="record[col.name]"
  41. >
  42. </j-dict-select-tag>
  43. </div>
  44. <div v-else-if="col.type === 'check'" :key="i" >
  45. <a-checkbox style="margin: -5px 0" :key="i" :checked="record[col.name]?true:false" @change="checkboxChange(record,col.name)"></a-checkbox>
  46. </div>
  47. <div v-else-if="col.type === 'JInputPop'" :key="i" >
  48. <j-input-pop style="margin: -5px 0" :key="i" v-model="record[col.name]"></j-input-pop>
  49. </div>
  50. <div v-else-if="col.type === 'JCodeEditorPop'" :key="i" >
  51. <j-code-editor-pop :key="i" v-model="record[col.name]"></j-code-editor-pop>
  52. </div>
  53. </template>
  54. </a-table>
  55. </div>
  56. </template>
  57. <script>
  58. import JInputPop from '@/components/jeecg/minipop/JInputPop'
  59. import JCodeEditorPop from '@/components/jeecg/minipop/JCodeEditorPop'
  60. export default {
  61. name: 'ConfigTable',
  62. components: {
  63. JInputPop,
  64. JCodeEditorPop
  65. },
  66. props: {
  67. tableData: {
  68. type: Array,
  69. default: []
  70. },
  71. extendData: {
  72. type: Object,
  73. default: {}
  74. }
  75. },
  76. data() {
  77. return {
  78. selectedRowKeys: [],
  79. columns: [
  80. {
  81. title: '#',
  82. dataIndex: '',
  83. key: 'rowIndex',
  84. width: 60,
  85. align: 'center',
  86. customRender: function(t, r, index) {
  87. return parseInt(index) + 1
  88. }
  89. },
  90. {
  91. title: '字段名',
  92. align: 'center',
  93. dataIndex: 'fieldName',
  94. width: 120,
  95. scopedSlots: { customRender: 'fieldName' }
  96. },
  97. {
  98. title: '字段文本',
  99. align: 'center',
  100. dataIndex: 'fieldTxt',
  101. width: 120,
  102. scopedSlots: { customRender: 'fieldTxt' }
  103. },
  104. {
  105. title: '排序',
  106. align: 'center',
  107. dataIndex: 'orderNum',
  108. width: 80,
  109. scopedSlots: { customRender: 'orderNum' }
  110. },
  111. {
  112. title: '字段类型',
  113. align: 'center',
  114. dataIndex: 'fieldType',
  115. width: 120,
  116. scopedSlots: { customRender: 'fieldType' }
  117. },
  118. {
  119. title: '控件宽度',
  120. align: 'center',
  121. dataIndex: 'fieldWidth',
  122. width: 80,
  123. scopedSlots: { customRender: 'fieldWidth' }
  124. },
  125. {
  126. title: '是否显示',
  127. align: 'center',
  128. dataIndex: 'isShow',
  129. width: 80,
  130. scopedSlots: { customRender: 'isShow' }
  131. },
  132. {
  133. title: '计算总计',
  134. align: 'center',
  135. dataIndex: 'isTotal',
  136. width: 80,
  137. scopedSlots: { customRender: 'isTotal' }
  138. },
  139. {
  140. title: '是否查询',
  141. align: 'center',
  142. dataIndex: 'searchFlag',
  143. width: 80,
  144. scopedSlots: { customRender: 'searchFlag' }
  145. },
  146. {
  147. title: '查询模式',
  148. align: 'center',
  149. dataIndex: 'searchMode',
  150. width: 150,
  151. scopedSlots: { customRender: 'searchMode' }
  152. },
  153. {
  154. title: '字典CODE',
  155. align: 'center',
  156. dataIndex: 'dictCode',
  157. width: 120,
  158. scopedSlots: { customRender: 'dictCode' }
  159. },
  160. {
  161. title: '表达式',
  162. align: 'center',
  163. dataIndex: 'func',
  164. width: 120,
  165. scopedSlots: { customRender: 'func' }
  166. },
  167. {
  168. title: '表达式参数',
  169. align: 'center',
  170. dataIndex: 'funcParam',
  171. width: 120,
  172. scopedSlots: { customRender: 'funcParam' }
  173. },
  174. {
  175. title: '聚合类型',
  176. align: 'center',
  177. dataIndex: 'aggregateType',
  178. width: 120,
  179. scopedSlots: { customRender: 'aggregateType' }
  180. },
  181. {
  182. title: 'JS增强',
  183. align: 'center',
  184. dataIndex: 'jsEnhance',
  185. width: 120,
  186. scopedSlots: { customRender: 'jsEnhance' }
  187. }
  188. ],
  189. scopedSlots: [
  190. { type: 'text', name: 'fieldName' },
  191. { type: 'text', name: 'fieldTxt' },
  192. { type: 'text', name: 'dictCode' },
  193. { type: 'number', name: 'orderNum' },
  194. { type: 'select', name: 'fieldType', dictCode: 'field_type' },
  195. { type: 'select', name: 'searchMode', dictCode: 'search_mode' },
  196. { type: 'check', name: 'isShow' },
  197. { type: 'check', name: 'isTotal' },
  198. { type: 'check', name: 'searchFlag' },
  199. { type: 'JInputPop', name: 'func' },
  200. { type: 'JInputPop', name: 'funcParam' },
  201. { type: 'select', name: 'aggregateType', dictCode: 'aggregate_type' },
  202. { type: 'JCodeEditorPop', name: 'jsEnhance' },
  203. { type: 'number', name: 'fieldWidth' }
  204. ],
  205. newTableData: {
  206. 'id': '',
  207. 'fieldName': '',
  208. 'fieldTxt': '',
  209. 'isShow': 1,
  210. 'isTotal': 0,
  211. 'searchFlag': 0,
  212. 'searchMode': null,
  213. 'dictCode': '',
  214. 'fieldHref': null,
  215. 'fieldType': 'String',
  216. 'orderNum': 1,
  217. 'replaceVal': null,
  218. 'createBy': '',
  219. 'createTime': '',
  220. 'updateBy': null,
  221. 'updateTime': null,
  222. 'func': null,
  223. 'funcParam': null,
  224. 'aggregateType': null
  225. },
  226. tableData_: JSON.parse(JSON.stringify(this.tableData))
  227. }
  228. },
  229. computed: {
  230. getScroll() {
  231. if (this.tableData_.length >= 5) {
  232. return { y: 200, x: 1600 }
  233. } else {
  234. return { x: 1600 }
  235. }
  236. }
  237. },
  238. methods: {
  239. handleAddGraphRepoart(addData) { // 新增
  240. let newData = JSON.parse(JSON.stringify(this.newTableData))
  241. if (addData) {
  242. newData = Object.assign(newData, this.extendData, addData)
  243. } else {
  244. newData = Object.assign(newData, this.extendData)
  245. }
  246. const length_ = this.tableData_.length
  247. if (length_ !== 0) {
  248. newData.orderNum = this.tableData_[length_ - 1]['orderNum'] + 1
  249. }
  250. this.tableData_.push(newData)
  251. // this.$emit('add', newData)
  252. },
  253. clearTableData() {
  254. this.tableData_ = []
  255. },
  256. onSelectChange(selectedRowKeys) {
  257. this.selectedRowKeys = selectedRowKeys
  258. },
  259. checkboxChange(data, name) {
  260. if (data[name]) {
  261. data[name] = 0
  262. } else {
  263. data[name] = 1
  264. }
  265. },
  266. handleRemoveGraphRepoart() { // 删除
  267. var that = this
  268. this.selectedRowKeys.sort(function(a, b) { return b - a })
  269. this.selectedRowKeys.forEach(function(index) {
  270. that.tableData_.splice(index, 1)
  271. })
  272. // this.$emit('del', this.selectedRowKeys)
  273. this.selectedRowKeys = []
  274. },
  275. getTableData() {
  276. return JSON.parse(JSON.stringify(this.tableData_))
  277. }
  278. }
  279. }
  280. </script>