server.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div>
  3. <el-row class="handle-box" style="margin-bottom: 10px">
  4. <el-col :span="24">
  5. <el-input v-model="search.serverName" class="ch-input ch-input-size" placeholder="服务器名称" size="small" @keyup.enter.native="handleSearch()" />
  6. <el-select v-model="search.status" clearable filterable placeholder="状态" size="small" @change="handleSearch">
  7. <el-option v-for="item in dc_data.OPS_SERVER_STATUS" :key="item.value" :label="item.label" :value="item.value" />
  8. </el-select>
  9. <el-button class="ch-button-warning" size="small" @click="handleReset()"><i class="el-icon-search" />&nbsp;重置</el-button>
  10. <el-button class="ch-button" size="small" @click="handleSearch()"><i class="el-icon-search" />&nbsp;搜索</el-button>
  11. <el-button class="ch-button-export" size="small" @click="confirmOutput()"><i class="el-icon-download" />&nbsp;导出</el-button>
  12. <!--<el-button size="small" class="ch-button" style="float: right;margin-top: 4px" @click="handleAdd()"><i class="el-icon-menu" />&nbsp;新增</el-button>-->
  13. </el-col>
  14. </el-row>
  15. <el-row class="handle-box">
  16. <el-col :span="24">
  17. <el-table v-loading="loading" :data="AllData" row-class-name="g_table_row" stripe>
  18. <el-table-column type="index" width="60" />
  19. <el-table-column label="服务器IP" prop="serverIp" />
  20. <el-table-column label="服务器名称" prop="serverName" />
  21. <el-table-column label="状态" prop="status" />
  22. <el-table-column label="最近一次CPU状态" prop="currCpu" />
  23. <el-table-column label="最近一次内存状态" prop="currMemory" />
  24. <el-table-column label="最近上报时间" prop="lastReportAt" />
  25. <el-table-column align="center" header-align="center" label="操作" width="180">
  26. <template scope="scope">
  27. <!--<el-button size="mini" type="primary" @click="handleEdit(scope.row)">编辑</el-button>-->
  28. <!--<el-button size="mini" type="assistdanger" @click="handleDel(scope.row)">删除</el-button>-->
  29. <el-button plain size="mini" type="primary" @click="handleRecord(scope.row.id)">运行日志</el-button>
  30. </template>
  31. </el-table-column>
  32. </el-table>
  33. <div class="table-page">
  34. <el-pagination
  35. :current-page.sync="currentPage"
  36. :page-size="pageSize"
  37. :total="allpage"
  38. background
  39. layout="total, prev, pager, next"
  40. @current-change="handleCurrentChange"
  41. />
  42. </div>
  43. </el-col>
  44. </el-row>
  45. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" top="50px" width="75%" @open="dlgOpen">
  46. <el-form ref="form" :model="form" :rules="rules" style="width: 100%;padding: 5px">
  47. <el-row>
  48. <el-col style="padding-bottom: 10px">
  49. <span class="card_title">基本信息</span>
  50. <el-card shadow="always" style="padding: 15px 5px 5px 15px">
  51. <el-row>
  52. <el-col :span="3" class="col-txt"><span>服务器IP</span></el-col>
  53. <el-col :span="20" class="col-input">
  54. <el-form-item>
  55. <el-input v-model="form.serverIp" />
  56. </el-form-item>
  57. </el-col>
  58. </el-row>
  59. <el-row>
  60. <el-col :span="3" class="col-txt"><span>服务器名称</span></el-col>
  61. <el-col :span="20" class="col-input">
  62. <el-form-item>
  63. <el-input v-model="form.serverName" />
  64. </el-form-item>
  65. </el-col>
  66. </el-row>
  67. <el-row>
  68. <el-col :span="3" class="col-txt"><span>状态</span></el-col>
  69. <el-col :span="20" class="col-input">
  70. <el-form-item>
  71. <el-select v-model="form.status" clearable filterable placeholder="状态">
  72. <el-option
  73. v-for="item in dc_data.OPS_SERVER_STATUS"
  74. :key="item.value"
  75. :label="item.label"
  76. :value="item.value"
  77. />
  78. </el-select>
  79. </el-form-item>
  80. </el-col>
  81. </el-row>
  82. <el-row>
  83. <el-col :span="3" class="col-txt"><span>最近一次CPU状态</span></el-col>
  84. <el-col :span="20" class="col-input">
  85. <el-form-item>
  86. <el-input v-model="form.currCpu" />
  87. </el-form-item>
  88. </el-col>
  89. </el-row>
  90. <el-row>
  91. <el-col :span="3" class="col-txt"><span>最近一次内存状态</span></el-col>
  92. <el-col :span="20" class="col-input">
  93. <el-form-item>
  94. <el-input v-model="form.currMemory" />
  95. </el-form-item>
  96. </el-col>
  97. </el-row>
  98. <el-row>
  99. <el-col :span="3" class="col-txt"><span>最近上报时间</span></el-col>
  100. <el-col :span="20" class="col-input">
  101. <el-form-item>
  102. <el-date-picker
  103. v-model="form.lastReportAt"
  104. placeholder="最近上报时间"
  105. type="datetime"
  106. value-format="yyyy-MM-dd HH:mm:ss"
  107. />
  108. </el-form-item>
  109. </el-col>
  110. </el-row>
  111. </el-card>
  112. </el-col>
  113. </el-row>
  114. </el-form>
  115. <div slot="footer">
  116. <el-button @click="dialogVisible = false">取 消</el-button>
  117. <el-button type="primary" @click="confirmSubmit()">确 定</el-button>
  118. </div>
  119. </el-dialog>
  120. <el-dialog :visible.sync="dialogRecordVisible" title="服务器运行日志" top="50px" width="75%">
  121. <el-card>
  122. <record v-if="dialogRecordVisible" :server-id="form.id" />
  123. </el-card>
  124. <div slot="footer">
  125. <el-button @click="dialogRecordVisible = false">关闭</el-button>
  126. </div>
  127. </el-dialog>
  128. </div>
  129. </template>
  130. <script>
  131. import Base from '@/views/base/base'
  132. import BaseData from '@/views/base/baseData'
  133. import record from './record'
  134. export default {
  135. name: 'Server',
  136. components: { record },
  137. mixins: [Base, BaseData],
  138. data() {
  139. return {
  140. dc_key: ['OPS_SERVER_STATUS'],
  141. // 列表相关
  142. search: {
  143. serverName: '',
  144. status: ''
  145. },
  146. AllData: [],
  147. loading: false,
  148. // 弹框相关
  149. dialogVisible: false,
  150. dialogTitle: '新增',
  151. isAdd: true,
  152. form: this.initForm(),
  153. rules: {},
  154. // 日志记录
  155. dialogRecordVisible: false
  156. }
  157. },
  158. mounted() {
  159. this.initDict(this.dc_key).then((res) => {
  160. this.getData()
  161. })
  162. },
  163. methods: {
  164. getData: function() {
  165. const _this = this
  166. _this.loading = true
  167. _this.AllData = []
  168. this.search.pageNum = this.currentPage
  169. this.search.pageSize = this.pageSize
  170. this.baseRequest('list', this.search).then((res) => {
  171. if (res.data.rows) {
  172. res.data.rows.forEach(function(item) {
  173. const json = _this.getItemJson(item)
  174. _this.AllData.push(json)
  175. })
  176. _this.allpage = res.data.total
  177. }
  178. _this.loading = false
  179. }).catch(() => {
  180. })
  181. this.initOutData()
  182. },
  183. handleSearch: function() {
  184. this.getData()
  185. },
  186. handleReset: function() {
  187. for (const i in this.search) {
  188. if (i !== 'pageNum' && i !== 'pageSize') {
  189. this.search[i] = ''
  190. }
  191. }
  192. this.handleSearch()
  193. },
  194. initOutData: function() {
  195. const _this = this
  196. this.OutData = []
  197. const title = [' 服务器IP', ' 服务器名称', ' 状态', ' 最近一次CPU状态', ' 最近一次内存状态', ' 最近上报时间'
  198. ]
  199. this.OutData.push(title)
  200. this.baseRequest('listAll', this.search).then((res) => {
  201. if (res.data) {
  202. res.data.forEach(function(item) {
  203. const jsonMap = _this.getItemJson(item)
  204. const jsonArray = []
  205. jsonArray.push(jsonMap.serverIp)
  206. jsonArray.push(jsonMap.serverName)
  207. jsonArray.push(jsonMap.status)
  208. jsonArray.push(jsonMap.currCpu)
  209. jsonArray.push(jsonMap.currMemory)
  210. jsonArray.push(jsonMap.lastReportAt)
  211. _this.OutData.push(jsonArray)
  212. })
  213. }
  214. }).catch(() => {
  215. })
  216. },
  217. getItemJson: function(item) {
  218. item.status = this.dc_map.OPS_SERVER_STATUS[item.status]
  219. item.lastReportAt = this.$common.transDate(item.lastReportAt, this.$constant.DATE_PATTERN.DATE_TIME_s_h)
  220. return item
  221. },
  222. initForm: function() {
  223. return {
  224. id: '',
  225. serverIp: '',
  226. serverName: '',
  227. status: '',
  228. currCpu: '',
  229. currMemory: '',
  230. lastReportAt: ''
  231. }
  232. },
  233. confirmOutput() {
  234. const OutSize = [{ wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }
  235. ]
  236. const fileName = 'server导出 ' + new Date().Format('yyyyMMddhhmm')
  237. this.$outputXlsxFile(this.OutData, OutSize, fileName)
  238. },
  239. dlgOpen: function() {
  240. const _this = this
  241. if (_this.form.id !== '') {
  242. const postData = {
  243. id: _this.form.id
  244. }
  245. this.baseRequest('getById', postData).then((res) => {
  246. if (res.data) {
  247. _this.form = Object.assign({}, _this.form, res.data)
  248. _this.form.lastReportAt = _this.$common.transServDate(res.data.lastReportAt)
  249. }
  250. }).catch(() => {
  251. })
  252. }
  253. },
  254. /* 编辑*/
  255. handleEdit: function(val) {
  256. this.isAdd = false
  257. this.form.id = val.id
  258. this.dialogVisible = true
  259. this.dialogTitle = '编辑'
  260. },
  261. /* 新增*/
  262. handleAdd: function() {
  263. this.form = this.initForm()
  264. this.isAdd = true
  265. this.dialogVisible = true
  266. this.dialogTitle = '新增'
  267. },
  268. confirmSubmit: function() {
  269. const _this = this
  270. this.$refs.form.validate(valid => {
  271. if (valid) {
  272. let soaUrl = 'edit'
  273. const extraData = {}
  274. const postData = Object.assign({}, _this.form, extraData)
  275. if (this.isAdd) {
  276. soaUrl = 'add'
  277. }
  278. this.opRecord(postData, soaUrl)
  279. } else {
  280. //console.log('error submit!!')
  281. return false
  282. }
  283. })
  284. },
  285. /* 查看日志*/
  286. handleRecord: function(_id) {
  287. this.form.id = _id
  288. this.dialogRecordVisible = true
  289. },
  290. baseRequest(opUrl, postData) {
  291. return this.$channel.globeRequest('ServerMainController', opUrl, postData, 'project')
  292. }
  293. }
  294. }
  295. </script>
  296. <style scoped>
  297. .ch-input .el-input__inner {
  298. border-color: #32323A;
  299. }
  300. .ch-input-size {
  301. width: 150px;
  302. }
  303. .ch-button {
  304. border-color: #32323A;
  305. background-color: #32323A;
  306. color: #fff;
  307. }
  308. .ch-button-warning {
  309. margin-left: 10px;
  310. border-color: #E6A23C;
  311. background-color: #E6A23C;
  312. color: #fff;
  313. }
  314. .ch-button-export {
  315. margin-left: 10px;
  316. border-color: #98CC1F;
  317. background-color: #98CC1F;
  318. color: #fff;
  319. }
  320. /deep/.el-dialog__header {
  321. padding: 10px 20px;
  322. }
  323. /deep/.el-dialog__body {
  324. padding: 10px 20px;
  325. }
  326. </style>