CanalCluster.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <!-- <el-input v-model="listQuery.name" placeholder="Server 名称" style="width: 200px;" class="filter-item" />
  5. <el-input v-model="listQuery.ip" placeholder="Server IP" style="width: 200px;" class="filter-item" />
  6. <el-button class="filter-item" type="primary" icon="el-icon-search" plain @click="fetchData()">查询</el-button> -->
  7. <el-button class="filter-item" type="primary" @click="handleCreate()">新建集群</el-button>
  8. </div>
  9. <el-table
  10. v-loading="listLoading"
  11. :data="list"
  12. element-loading-text="Loading"
  13. border
  14. fit
  15. highlight-current-row
  16. >
  17. <el-table-column label="集群名称" min-width="200" align="center">
  18. <template slot-scope="scope">
  19. {{ scope.row.name }}
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="ZK地址" min-width="300" align="center">
  23. <template slot-scope="scope">
  24. <span>{{ scope.row.zkHosts }}</span>
  25. </template>
  26. </el-table-column>
  27. <el-table-column align="center" prop="created_at" label="操作" min-width="150">
  28. <template slot-scope="scope">
  29. <el-dropdown trigger="click">
  30. <el-button type="primary" size="mini">
  31. 操作<i class="el-icon-arrow-down el-icon--right" />
  32. </el-button>
  33. <el-dropdown-menu slot="dropdown">
  34. <el-dropdown-item @click.native="handleConfig(scope.row)">主配置</el-dropdown-item>
  35. <el-dropdown-item @click.native="handleUpdate(scope.row)">修改集群</el-dropdown-item>
  36. <el-dropdown-item @click.native="handleDelete(scope.row)">删除集群</el-dropdown-item>
  37. <el-dropdown-item @click.native="handleView(scope.row)">查看Server</el-dropdown-item>
  38. </el-dropdown-menu>
  39. </el-dropdown>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <el-dialog :visible.sync="dialogFormVisible" :title="textMap[dialogStatus]" width="600px">
  44. <el-form ref="dataForm" :rules="rules" :model="canalCluster" label-position="left" label-width="120px" style="width: 400px; margin-left:30px;">
  45. <el-form-item label="集群名称" prop="name">
  46. <el-input v-model="canalCluster.name" />
  47. </el-form-item>
  48. <el-form-item label="ZK地址" prop="zkHosts">
  49. <el-input v-model="canalCluster.zkHosts" />
  50. </el-form-item>
  51. </el-form>
  52. <div slot="footer" class="dialog-footer">
  53. <el-button @click="dialogFormVisible = false">取消</el-button>
  54. <el-button type="primary" @click="dataOperation()">确定</el-button>
  55. </div>
  56. </el-dialog>
  57. </div>
  58. </template>
  59. <script>
  60. import { addCanalCluster, getCanalClusters, updateCanalCluster, deleteCanalCluster } from '@/api/canalCluster'
  61. export default {
  62. filters: {
  63. statusFilter(status) {
  64. const statusMap = {
  65. '1': 'success',
  66. '0': 'gray',
  67. '-1': 'danger'
  68. }
  69. return statusMap[status]
  70. },
  71. statusLabel(status) {
  72. const statusMap = {
  73. '1': '启动',
  74. '0': '停止',
  75. '-1': '断开'
  76. }
  77. return statusMap[status]
  78. }
  79. },
  80. data() {
  81. return {
  82. list: null,
  83. listLoading: true,
  84. listQuery: {
  85. name: '',
  86. ip: ''
  87. },
  88. dialogFormVisible: false,
  89. textMap: {
  90. create: '新建集群信息',
  91. update: '修改集群信息'
  92. },
  93. canalCluster: {
  94. id: null,
  95. name: null,
  96. zkHosts: null
  97. },
  98. rules: {
  99. name: [{ required: true, message: '集群名称不能为空', trigger: 'change' }],
  100. zkHosts: [{ required: true, message: 'zk地址不能为空', trigger: 'change' }]
  101. },
  102. dialogStatus: 'create'
  103. }
  104. },
  105. created() {
  106. this.fetchData()
  107. },
  108. methods: {
  109. fetchData() {
  110. this.listLoading = true
  111. getCanalClusters(this.listQuery).then(res => {
  112. this.list = res.data
  113. }).finally(() => {
  114. this.listLoading = false
  115. })
  116. },
  117. resetModel() {
  118. this.canalCluster = {
  119. id: null,
  120. name: null,
  121. zkHosts: null
  122. }
  123. },
  124. handleCreate() {
  125. this.resetModel()
  126. this.dialogStatus = 'create'
  127. this.dialogFormVisible = true
  128. this.$nextTick(() => {
  129. this.$refs['dataForm'].clearValidate()
  130. })
  131. },
  132. dataOperation() {
  133. this.$refs['dataForm'].validate((valid) => {
  134. if (valid) {
  135. if (this.dialogStatus === 'create') {
  136. addCanalCluster(this.canalCluster).then(res => {
  137. this.operationRes(res)
  138. })
  139. }
  140. if (this.dialogStatus === 'update') {
  141. updateCanalCluster(this.canalCluster).then(res => {
  142. this.operationRes(res)
  143. })
  144. }
  145. }
  146. })
  147. },
  148. operationRes(res) {
  149. if (res.data === 'success') {
  150. this.fetchData()
  151. this.dialogFormVisible = false
  152. this.$message({
  153. message: this.textMap[this.dialogStatus] + '成功',
  154. type: 'success'
  155. })
  156. } else {
  157. this.$message({
  158. message: this.textMap[this.dialogStatus] + '失败',
  159. type: 'error'
  160. })
  161. }
  162. },
  163. handleView(row) {
  164. this.$router.push('/canalServer/nodeServers?clusterId=' + row.id)
  165. },
  166. handleConfig(row) {
  167. this.$router.push('/canalServer/nodeServer/config?clusterId=' + row.id)
  168. },
  169. handleUpdate(row) {
  170. this.resetModel()
  171. this.canalCluster = Object.assign({}, row)
  172. this.dialogStatus = 'update'
  173. this.dialogFormVisible = true
  174. this.$nextTick(() => {
  175. this.$refs['dataForm'].clearValidate()
  176. })
  177. },
  178. handleDelete(row) {
  179. this.$confirm('删除集群信息会导致服务停止', '确定删除集群信息', {
  180. confirmButtonText: '确定',
  181. cancelButtonText: '取消',
  182. type: 'warning'
  183. }).then(() => {
  184. deleteCanalCluster(row.id).then((res) => {
  185. if (res.data === 'success') {
  186. this.fetchData()
  187. this.$message({
  188. message: '删除集群信息成功',
  189. type: 'success'
  190. })
  191. } else {
  192. this.$message({
  193. message: '删除集群信息失败',
  194. type: 'error'
  195. })
  196. }
  197. })
  198. })
  199. }
  200. }
  201. }
  202. </script>