index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div class="pa-3" style="background-color: #FFF;">
  3. <filter-list :option="filter" @search="handleSearch" />
  4. <table-list
  5. class="mt-3"
  6. :loading="loading"
  7. :headers="headers"
  8. :items="items"
  9. :total="total"
  10. :page-info="pageInfo"
  11. @add="handleAdd"
  12. @pageHandleChange="pageHandleChange"
  13. @sort="handleSort"
  14. >
  15. <template #actions="{ item }">
  16. <v-btn text color="primary" @click="handleEdit(item)">编辑</v-btn>
  17. <v-btn text color="error" @click="handleDelete(item.id)">删除</v-btn>
  18. </template>
  19. <template v-slot:remark="{item}">
  20. <td >
  21. {{ item.remark && item.remark.substr(0, 8) }}
  22. <template v-if="item.remark && item.remark.length > 8">...</template>
  23. </td>
  24. </template>
  25. <template #status="{ item }">
  26. <v-chip :color="item.status ? 'success' : 'error'" small>{{ item.status ? '启用' : '禁用' }}</v-chip>
  27. </template>
  28. </table-list>
  29. <edit-dialog :title="title" :visible.sync="show" @submit="handleSubmit">
  30. <edit-page class="pt-5" v-if="show" ref="edit" :type-items="dataSource_type" :item-data="itemData" @test="handleTest"></edit-page>
  31. </edit-dialog>
  32. <Linear :visible.sync="submitLoading"></Linear>
  33. </div>
  34. </template>
  35. <script>
  36. import EditPage from './components/edit.vue'
  37. import FilterList from '@/components/Filter'
  38. import TableList from '@/components/List/table.vue'
  39. import EditDialog from '@/components/Dialog'
  40. import Linear from '@/components/Progress/linear.vue'
  41. import {
  42. dataFactoryDictList,
  43. sourceConfigTest
  44. // sourceAdd,
  45. // sourceUpdate,
  46. // sourceDelete
  47. } from '@/api/dataFactory'
  48. import {
  49. getDatasourceList,
  50. saveDatasource,
  51. deleteDatasource
  52. } from '@/api/dataOrigin'
  53. import {
  54. setLocalStorageAndTime
  55. // getLocalStorageAndTime
  56. } from '@/utils/localStorageAndTime'
  57. export default {
  58. name: 'RDbmsDataSource',
  59. components: { FilterList, TableList, EditDialog, EditPage, Linear },
  60. data () {
  61. return {
  62. show: false,
  63. filter: {
  64. list: [
  65. { type: 'textField', value: '', label: '数据源名称', key: 'name' }
  66. // { type: 'autocomplete', value: null, label: '配置类型', key: 'type', items: [] }
  67. ]
  68. },
  69. queryForm: {
  70. name: '' // 配置名称
  71. },
  72. pageInfo: {
  73. current: 1,
  74. size: 10
  75. },
  76. total: 0,
  77. orders: [],
  78. loading: true,
  79. submitLoading: false,
  80. headers: [
  81. { text: '中文名称', align: 'start', value: 'name', slotName: 'name' },
  82. { text: '英文名称', align: 'start', value: 'en_name' },
  83. { text: '数据库类型', align: 'start', value: 'type' },
  84. { text: '主机地址', align: 'start', value: 'host' },
  85. { text: '端口', align: 'start', value: 'port' },
  86. { text: '数据库名称', align: 'start', value: 'database' },
  87. { text: '用户名', align: 'start', value: 'username' },
  88. { text: '连接参数', align: 'start', value: 'param' },
  89. { text: '状态', align: 'start', value: 'status' },
  90. { text: '更新时间', align: 'start', value: 'updateTime' },
  91. { text: '备注', align: 'start', value: 'desc', useSlot: true },
  92. { text: '操作', align: 'start', value: 'actions' }
  93. ],
  94. items: [],
  95. dataSource_type: [],
  96. itemData: {}
  97. }
  98. },
  99. computed: {
  100. title () {
  101. return `${Object.keys(this.itemData).length ? '新增' : '编辑'}数据源`
  102. }
  103. },
  104. created () {
  105. // this.init()
  106. // this.initPage()
  107. },
  108. methods: {
  109. // async init () {
  110. // // const dictionary = getLocalStorageAndTime('dataFactory', 'dataSource_type') || {}
  111. // // if (!dictionary.dataSource_type) {
  112. // // await this.initDictionary(dictionary)
  113. // // } else this.dataSource_type = dictionary.dataSource_type
  114. // // // this.formData.options.find(e => e.key === 'type').items = this.dataSource_type
  115. // // this.filter.list.find(e => e.key === 'type').items = this.dataSource_type
  116. // this.initPage()
  117. // },
  118. async initDictionary (dictionary) {
  119. try {
  120. const { data } = await dataFactoryDictList({ type: 'dataSource_type' })
  121. this.dataSource_type = dictionary.dataSource_type = data[0].itemList
  122. setLocalStorageAndTime('dataFactory', 'dataSource_type', dictionary)
  123. } catch (error) {
  124. this.$snackbar.error(error)
  125. }
  126. },
  127. async initPage () {
  128. try {
  129. this.loading = true
  130. const { data } = await getDatasourceList({
  131. ...this.queryForm
  132. // ...this.pageInfo
  133. // orders: this.orders
  134. })
  135. this.total = data.total
  136. this.items = data.data_source
  137. // .map(item => {
  138. // item.type = this.dataSource_type.find(filter => filter.value === item.type).label
  139. // return item
  140. // })
  141. } catch (error) {
  142. this.$snackbar.error(error)
  143. } finally {
  144. this.loading = false
  145. }
  146. },
  147. handleSearch (val) {
  148. this.pageInfo.current = 1
  149. Object.assign(this.queryForm, val)
  150. this.initPage()
  151. },
  152. async handleSubmit () {
  153. const _ref = this.$refs.edit
  154. if (_ref.validate()) {
  155. const isEdit = Object.keys(this.itemData).length
  156. const data = {}
  157. if (isEdit) data.id = this.itemData.id
  158. Object.assign(data, _ref.getQuery())
  159. try {
  160. this.submitLoading = true
  161. const { msg } = await saveDatasource(data)
  162. this.$snackbar.success(msg)
  163. this.show = false
  164. this.initPage()
  165. } catch (error) {
  166. this.$snackbar.error(error)
  167. } finally {
  168. this.submitLoading = false
  169. }
  170. }
  171. },
  172. async handleTest (data) {
  173. try {
  174. this.submitLoading = true
  175. const { msg } = await sourceConfigTest(data)
  176. this.$snackbar.success(msg)
  177. } catch (error) {
  178. this.$snackbar.error(error)
  179. } finally {
  180. this.submitLoading = false
  181. }
  182. },
  183. // table 关联操作 新增
  184. handleAdd () {
  185. this.show = true
  186. this.itemData = {}
  187. },
  188. // table 关联操作 编辑
  189. async handleEdit (item) {
  190. this.itemData = item
  191. this.show = true
  192. },
  193. // table 关联操作 删除
  194. handleDelete (id) {
  195. // if (!ids.length) return this.$snackbar.warning('请选择删除项')
  196. this.$confirm('提示', '是否确定删除该选项').then(async () => {
  197. try {
  198. await deleteDatasource({ id })
  199. this.$snackbar.success('删除成功')
  200. this.initPage()
  201. } catch (error) {
  202. this.$snackbar.error(error)
  203. }
  204. })
  205. },
  206. // table 关联操作 切换分页
  207. pageHandleChange (index) {
  208. this.pageInfo.current = index
  209. this.initPage()
  210. },
  211. handleSort (val) {
  212. this.orders = val
  213. this.initPage()
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. </style>