3be80d6ef3cc5544d8bc10ef129ea6aef9f08a5d.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div>
  3. <el-form label-position="top" class="panel" style="text-align:left;">
  4. <el-form-item v-show="false" :label="$t('common.dataSource')+':'">
  5. <el-select v-model="selectedBase" size="mini" filterable :placeholder="$t('dataSource.sourcePlaceholder')" style="width:200px;" clearable @change="handleBaseChange">
  6. <el-option v-for="item in baseList" :key="item.source_id" :label="item.base_alias || item.database" :value="item.source_id" />
  7. </el-select>
  8. </el-form-item>
  9. <!-- 表下拉框 -->
  10. <!-- label看到的 key=id -->
  11. <el-form-item>
  12. <el-select v-model="selectedTable" size="mini" filterable :placeholder="$t('dataSource.tablePlaceholder')" style="width:200px;" clearable @change="handleDataSrcChange">
  13. <el-option v-for="item in tableList" :key="item.table" :label="item.table_alias || item.tablename" :value="item.table" />
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item v-show="false" :label="$t('dataSource.table')+':'">
  17. <span style="font-size: 12px;margin-right: 5px;">{{ selectedTableName }}</span>
  18. <el-button type="text" size="mini" @click="editDataSrc">
  19. {{ $t('common.edit') }}
  20. </el-button>
  21. </el-form-item>
  22. <!-- 字段 -->
  23. <el-form-item :label="$t('dataSource.fields')+':'">
  24. <draggable v-model="tableSchema" v-loading="schemaLoading" :group="{name: 'col',pull: 'clone', put: false}" :move="handleMove">
  25. <div v-for="col in tableSchema" :key="col.Column" class="drag-list-item">
  26. <i class="el-icon-rank" style="font-size: 12px;color:#409EFF;" />
  27. {{ col.Comment }}
  28. </div>
  29. </draggable>
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. </template>
  34. <script>
  35. import { sourceList, linkedTablesByBase } from '@/api/source'
  36. import { GetDataByName } from '@/api/common'
  37. import draggable from 'vuedraggable'
  38. import exeSql from '@/api/exeSql'
  39. import store from '../store'
  40. export default {
  41. components: { draggable },
  42. props: {
  43. resultLoading: {
  44. default: false
  45. },
  46. dataSrc: {
  47. requred: true
  48. }
  49. },
  50. data() {
  51. return {
  52. schemaLoading: false,
  53. baseList: [],
  54. tableList: [],
  55. selectedTable: undefined,
  56. tableSchema: undefined,
  57. dataSrcVisible: true,
  58. existWarning: null,
  59. selectedBase: undefined
  60. }
  61. },
  62. computed: {
  63. allSelected() {
  64. return store.state.dimensions.concat(store.state.caculCols)
  65. },
  66. selectedBaseName() {
  67. const selectedBase = this.baseList.find(item => item.source_id === this.selectedBase)
  68. if (!selectedBase) return ''
  69. return selectedBase.base_alias || selectedBase.database
  70. },
  71. selectedTableName() {
  72. const selectedTable = this.tableList.find(item => item.table === this.selectedTable)
  73. if (!selectedTable) return ''
  74. return selectedTable.table_alias || selectedTable.table
  75. }
  76. },
  77. created() {
  78. // this.getBaseList()
  79. this.get_table_list()
  80. },
  81. methods: {
  82. // async getBaseList() {
  83. // const { data } = await sourceList()
  84. // this.baseList = data
  85. // },
  86. get_table_list() {
  87. var send_data = {
  88. name: 'getTABLESV2',
  89. page: 1,
  90. offset: 1
  91. }
  92. GetDataByName(send_data).then(response => {
  93. console.log('tableList数据', response.data.list)
  94. if (response.data.list !== null) {
  95. this.tableList = response.data.list
  96. } else {
  97. this.tableList = []
  98. }
  99. })
  100. },
  101. initWithDataSrc(dataSrc) {
  102. console.log('dataSrc', dataSrc)
  103. if (dataSrc) {
  104. this.selectedTable = dataSrc.table
  105. this.selectedBase = dataSrc.source_id
  106. this.fetchTables()
  107. this.fetchSchema()
  108. } else {
  109. this.selectedTable = ''
  110. this.selectedBase = ''
  111. this.tableSchema = []
  112. this.dataSrcVisible = true
  113. }
  114. },
  115. editDataSrc() {
  116. this.dataSrcVisible = true
  117. this.selectedTable = undefined
  118. },
  119. handleBaseChange() {
  120. this.fetchTables()
  121. },
  122. // async fetchTables() {
  123. // const { data } = await linkedTablesByBase(this.selectedBase)
  124. // this.tableList = data
  125. // },
  126. // handleDataSrcChange() {
  127. // this.dataSrcVisible = false
  128. // this.fetchSchema()
  129. // store.setAllColsAction([])
  130. // this.$emit('change', {
  131. // table: this.selectedTable,
  132. // source_id: this.selectedBase
  133. // })
  134. // },
  135. handleDataSrcChange(e) {
  136. console.log('selectedTable:', this.selectedTable)
  137. this.dataSrcVisible = false
  138. this.fetchSchema()
  139. store.setAllColsAction([])
  140. this.$emit('change', {
  141. table: this.selectedTable,
  142. source_id: this.selectedBase
  143. })
  144. },
  145. // fetchSchema() {
  146. // if (!this.selectedTable) {
  147. // this.tableSchema = []
  148. // return
  149. // }
  150. // this.schemaLoading = true
  151. // exeSql().fetch({ source_id: this.selectedBase, sql: `desc ${this.selectedTable}` }).then(resp => {
  152. // this.schemaLoading = false
  153. // this.tableSchema = resp.data.map((item, index) => {
  154. // return {
  155. // Column: item.Field,
  156. // Type: item.Type,
  157. // id: index
  158. // }
  159. // })
  160. // store.setAllColsAction(this.tableSchema)
  161. // })
  162. // },
  163. // 字段下拉框
  164. fetchSchema() {
  165. console.log('selectedTable:', this.selectedTable)
  166. if (!this.selectedTable) {
  167. this.tableSchema = []
  168. return
  169. }
  170. this.schemaLoading = true
  171. var send_data2 = {
  172. name: 'getColumnName',
  173. page: 1,
  174. offset: 1,
  175. returntype: 'Map',
  176. parammaps: {
  177. table_name: this.selectedTable
  178. }
  179. }
  180. GetDataByName(send_data2).then(resp => {
  181. console.log('字段数据:', resp.data.list)
  182. if (resp.data.list !== null) {
  183. this.schemaLoading = false
  184. this.tableSchema = resp.data.list.map((item, index) => {
  185. return {
  186. Column: item.Field,
  187. Type: item.Type,
  188. id: index,
  189. Comment: item.Comment
  190. }
  191. })
  192. store.setAllColsAction(this.tableSchema)
  193. } else {
  194. this.tableSchema = []
  195. }
  196. console.log('tableSchema数据:', this.tableSchema)
  197. })
  198. },
  199. handleMove(evt, originalEvent) {
  200. if (this.allSelected.find(item => item.Column === evt.draggedContext.element.Column)) {
  201. if (!this.existWarning) {
  202. this.existWarning = this.$message({
  203. type: 'warning',
  204. message: this.$t('chart.fieldExisted'),
  205. onClose: (instance) => {
  206. this.existWarning = null
  207. }
  208. })
  209. }
  210. return false
  211. }
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .panel {
  218. /deep/ .el-form-item__label {
  219. line-height: initial;
  220. }
  221. /deep/ .el-form-item__content {
  222. line-height: initial;
  223. }
  224. }
  225. .drag-list-item {
  226. line-height: 1.5;
  227. font-size: 14px;
  228. color:#606266;
  229. cursor: -webkit-grab;
  230. }
  231. </style>