a1c795233f7cdf9796cbccfb3113814e03f438eb.svn-base 8.6 KB

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