index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="app-container">
  3. <el-card shadow="never" class="mb16 filter-card">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" size="small">
  5. <el-form-item label="配置名称" prop="configName">
  6. <el-input v-model="queryParams.configName" placeholder="配置名称" clearable @keyup.enter.native="handleQuery" />
  7. </el-form-item>
  8. <el-form-item label="状态" prop="status">
  9. <el-select v-model="queryParams.status" placeholder="全部" clearable style="width:120px">
  10. <el-option label="启用" :value="1" />
  11. <el-option label="禁用" :value="0" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
  16. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </el-card>
  20. <el-row :gutter="10" class="mb8">
  21. <el-col :span="1.5">
  22. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['admin:dbConfig:add']">新增配置</el-button>
  23. </el-col>
  24. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  25. </el-row>
  26. <el-table border v-loading="loading" :data="configList" size="small" style="width:100%">
  27. <el-table-column label="ID" prop="id" width="60" align="center" />
  28. <el-table-column label="配置名称" prop="configName" min-width="120" />
  29. <el-table-column label="数据库IP" prop="dbIp" width="140" align="center" />
  30. <el-table-column label="端口" prop="dbPort" width="80" align="center" />
  31. <el-table-column label="账号" prop="dbAccount" width="120" align="center" />
  32. <el-table-column label="密码" width="100" align="center">
  33. <template slot-scope="scope">
  34. <span>******</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="最大库数" prop="maxDbCount" width="90" align="center" />
  38. <el-table-column label="已用库数" prop="currentDbCount" width="90" align="center">
  39. <template slot-scope="scope">
  40. <span :style="{color: scope.row.currentDbCount >= scope.row.maxDbCount ? '#f5222d' : '#52c41a'}">{{ scope.row.currentDbCount || 0 }} / {{ scope.row.maxDbCount }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="状态" align="center" width="80">
  44. <template slot-scope="scope">
  45. <el-tag v-if="scope.row.status == 1" type="success" size="mini">启用</el-tag>
  46. <el-tag v-else type="danger" size="mini">禁用</el-tag>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="备注" prop="remark" min-width="120" show-overflow-tooltip />
  50. <el-table-column label="操作" align="center" width="150" fixed="right">
  51. <template slot-scope="scope">
  52. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
  53. <el-button size="mini" type="text" style="color:#f5222d" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  58. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="560px" append-to-body destroy-on-close>
  59. <el-form ref="form" :model="form" :rules="rules" label-width="100px" size="small">
  60. <el-form-item label="配置名称" prop="configName">
  61. <el-input v-model="form.configName" placeholder="如:主数据库服务器A" />
  62. </el-form-item>
  63. <el-form-item label="数据库IP" prop="dbIp">
  64. <el-input v-model="form.dbIp" placeholder="如:192.168.1.100" />
  65. </el-form-item>
  66. <el-form-item label="数据库端口" prop="dbPort">
  67. <el-input v-model="form.dbPort" placeholder="如:3306" />
  68. </el-form-item>
  69. <el-form-item label="数据库账号" prop="dbAccount">
  70. <el-input v-model="form.dbAccount" placeholder="如:root" />
  71. </el-form-item>
  72. <el-form-item label="数据库密码" prop="dbPwd">
  73. <el-input v-model="form.dbPwd" type="password" show-password placeholder="请输入数据库密码" />
  74. </el-form-item>
  75. <el-form-item label="最大库数" prop="maxDbCount">
  76. <el-input-number v-model="form.maxDbCount" :min="1" :max="9999" style="width:100%" />
  77. </el-form-item>
  78. <el-form-item label="状态" prop="status">
  79. <el-radio-group v-model="form.status">
  80. <el-radio :label="1">启用</el-radio>
  81. <el-radio :label="0">禁用</el-radio>
  82. </el-radio-group>
  83. </el-form-item>
  84. <el-form-item label="备注" prop="remark">
  85. <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注" />
  86. </el-form-item>
  87. </el-form>
  88. <div slot="footer">
  89. <el-button @click="dialogVisible = false">取 消</el-button>
  90. <el-button type="primary" :loading="submitLoading" @click="submitForm">确 定</el-button>
  91. </div>
  92. </el-dialog>
  93. </div>
  94. </template>
  95. <script>
  96. import { listDbConfig, getDbConfig, addDbConfig, updateDbConfig, delDbConfig } from '@/api/admin/dbConfig'
  97. export default {
  98. name: 'AdminDbConfig',
  99. data() {
  100. return {
  101. loading: true,
  102. showSearch: true,
  103. total: 0,
  104. configList: [],
  105. queryParams: {
  106. pageNum: 1,
  107. pageSize: 10,
  108. configName: null,
  109. status: null
  110. },
  111. dialogVisible: false,
  112. dialogTitle: '',
  113. submitLoading: false,
  114. form: {},
  115. rules: {
  116. configName: [{ required: true, message: '请输入配置名称', trigger: 'blur' }],
  117. dbIp: [{ required: true, message: '请输入数据库IP', trigger: 'blur' }],
  118. dbPort: [{ required: true, message: '请输入数据库端口', trigger: 'blur' }],
  119. dbAccount: [{ required: true, message: '请输入数据库账号', trigger: 'blur' }],
  120. dbPwd: [{ required: true, message: '请输入数据库密码', trigger: 'blur' }],
  121. maxDbCount: [{ required: true, message: '请输入最大库数', trigger: 'blur' }],
  122. status: [{ required: true, message: '请选择状态', trigger: 'change' }]
  123. }
  124. }
  125. },
  126. created() {
  127. this.getList()
  128. },
  129. methods: {
  130. getList() {
  131. this.loading = true
  132. listDbConfig(this.queryParams).then(response => {
  133. this.configList = response.rows
  134. this.total = response.total
  135. this.loading = false
  136. })
  137. },
  138. handleQuery() {
  139. this.queryParams.pageNum = 1
  140. this.getList()
  141. },
  142. resetQuery() {
  143. this.resetForm('queryForm')
  144. this.handleQuery()
  145. },
  146. resetFormFields() {
  147. this.form = {
  148. id: null,
  149. configName: '',
  150. dbIp: '',
  151. dbPort: '3306',
  152. dbAccount: '',
  153. dbPwd: '',
  154. maxDbCount: 50,
  155. currentDbCount: 0,
  156. status: 1,
  157. remark: ''
  158. }
  159. },
  160. handleAdd() {
  161. this.resetFormFields()
  162. this.dialogTitle = '新增DB配置'
  163. this.dialogVisible = true
  164. this.$nextTick(() => {
  165. if (this.$refs.form) this.$refs.form.clearValidate()
  166. })
  167. },
  168. handleEdit(row) {
  169. getDbConfig(row.id).then(response => {
  170. this.form = { ...response.data }
  171. if (!this.form.dbPwd) {
  172. this.form.dbPwd = ''
  173. }
  174. this.dialogTitle = '编辑DB配置'
  175. this.dialogVisible = true
  176. this.$nextTick(() => {
  177. if (this.$refs.form) this.$refs.form.clearValidate()
  178. })
  179. })
  180. },
  181. submitForm() {
  182. this.$refs['form'].validate(valid => {
  183. if (!valid) return
  184. this.submitLoading = true
  185. if (this.form.id) {
  186. updateDbConfig(this.form).then(() => {
  187. this.$message.success('修改成功')
  188. this.dialogVisible = false
  189. this.getList()
  190. }).finally(() => {
  191. this.submitLoading = false
  192. })
  193. } else {
  194. addDbConfig(this.form).then(() => {
  195. this.$message.success('新增成功')
  196. this.dialogVisible = false
  197. this.getList()
  198. }).finally(() => {
  199. this.submitLoading = false
  200. })
  201. }
  202. })
  203. },
  204. handleDelete(row) {
  205. this.$confirm('确定删除配置 [' + row.configName + '] 吗?', '提示', {
  206. confirmButtonText: '确定',
  207. cancelButtonText: '取消',
  208. type: 'warning'
  209. }).then(() => {
  210. delDbConfig(row.id).then(() => {
  211. this.$message.success('删除成功')
  212. this.getList()
  213. })
  214. })
  215. }
  216. }
  217. }
  218. </script>
  219. <style scoped>
  220. .mb8 { margin-bottom: 8px; }
  221. .mb16 { margin-bottom: 16px; }
  222. .filter-card { padding-bottom: 0; }
  223. </style>