3a8bc9b3134deceeb9cfc9f859859965085326f1.svn-base 7.6 KB

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