AppStat.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <el-container>
  3. <el-header height="220">
  4. <h3>应用运行列表</h3>
  5. <el-row style="margin-top: 10px">
  6. <el-select
  7. v-model="queryInfo.env"
  8. clearable
  9. placeholder="环境"
  10. style="margin-left: 5px"
  11. @change="onSelectChange"
  12. >
  13. <el-option
  14. v-for="(item, index) in envList"
  15. :key="index"
  16. :label="item.label"
  17. :value="item.value"
  18. />
  19. </el-select>
  20. <el-select
  21. v-model="queryInfo.appType"
  22. clearable
  23. placeholder="类型"
  24. style="margin-left: 5px"
  25. @change="onSelectChange"
  26. >
  27. <el-option
  28. v-for="(item, index) in appTypeList"
  29. :key="index"
  30. :label="item.label"
  31. :value="item.value"
  32. />
  33. </el-select>
  34. </el-row>
  35. </el-header>
  36. <el-main>
  37. <el-table
  38. :data="dataList"
  39. border
  40. height="480"
  41. style="width: 100%"
  42. >
  43. <el-table-column
  44. prop="appName"
  45. label="应用"
  46. />
  47. <el-table-column
  48. prop="bindPorts"
  49. label="监听端口"
  50. />
  51. <el-table-column
  52. prop="packagePath"
  53. label="包路径"
  54. />
  55. <el-table-column
  56. prop="totalDeployed"
  57. label="部署数量/运行中/未运行"
  58. >
  59. <template slot-scope="scope">
  60. <el-tag disable-transitions style="margin-top: 5px; margin-left: 5px">
  61. {{ scope.row.totalDeployed }}
  62. </el-tag>
  63. <el-tag :type="'success'" disable-transitions style="margin-top: 5px; margin-left: 5px">
  64. {{ scope.row.totalRunning }}
  65. </el-tag>
  66. <el-tag :type="'danger'" disable-transitions style="margin-top: 5px; margin-left: 5px">
  67. {{ scope.row.totalStopped }}
  68. </el-tag>
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. fixed="right"
  73. label="详情"
  74. width="280"
  75. >
  76. <template slot-scope="scope">
  77. <el-button
  78. size="mini"
  79. @click="handleDetail(scope.$index, scope.row)"
  80. >查看</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <el-pagination
  85. background
  86. :small="screenWidth <= 768"
  87. layout="prev, pager, next"
  88. :page-size="pageSize"
  89. :current-page="currentPage"
  90. :total="totalSize"
  91. @current-change="handleCurrentChange"
  92. @prev-click="handleCurrentChange"
  93. @next-click="handleCurrentChange"
  94. />
  95. </el-main>
  96. <el-dialog
  97. title="应用状态列表"
  98. append-to-body
  99. :visible.sync="showStatDialog"
  100. width="70%"
  101. center
  102. >
  103. <template>
  104. <el-table
  105. :data="appStatList"
  106. border
  107. height="480"
  108. style="width: 100%"
  109. >
  110. <el-table-column
  111. prop="machineIpv4"
  112. label="机器地址"
  113. />
  114. <el-table-column
  115. prop="packagePath"
  116. label="包路径"
  117. />
  118. <el-table-column
  119. prop="status"
  120. label="运行状态"
  121. />
  122. <el-table-column
  123. prop="startTime"
  124. label="启动时间"
  125. />
  126. <el-table-column
  127. prop="pid"
  128. label="PID"
  129. />
  130. <el-table-column
  131. prop="lastCheck"
  132. label="上次检查"
  133. />
  134. <el-table-column
  135. fixed="right"
  136. label="操作"
  137. width="280"
  138. >
  139. <template slot-scope="scope">
  140. <el-button
  141. style="margin-top: 5px; margin-left: 5px"
  142. size="mini"
  143. type="danger"
  144. @click="handleRestart(scope.$index, scope.row)"
  145. >重启</el-button>
  146. <el-button
  147. style="margin-top: 5px; margin-left: 5px"
  148. size="mini"
  149. type="danger"
  150. @click="handleStop(scope.$index, scope.row)"
  151. >停止</el-button>
  152. <el-button
  153. style="margin-top: 5px; margin-left: 5px"
  154. size="mini"
  155. type="success"
  156. @click="handleStart(scope.$index, scope.row)"
  157. >启动</el-button>
  158. <el-button
  159. style="margin-top: 5px; margin-left: 5px"
  160. size="mini"
  161. @click="handleGetStat(scope.$index, scope.row)"
  162. >当前状态</el-button>
  163. </template>
  164. </el-table-column>
  165. </el-table>
  166. </template>
  167. </el-dialog>
  168. </el-container>
  169. </template>
  170. <script>
  171. import {
  172. getAppStat,
  173. getAppStatDeatil,
  174. getAppStatList,
  175. getEnvList,
  176. restartAppStat,
  177. startAppStat, stopAppStat
  178. } from '@/api/devops'
  179. export default {
  180. name: 'AppStat',
  181. data() {
  182. return {
  183. envList: [],
  184. appTypeList: [],
  185. queryInfo: {
  186. env: 'test',
  187. appType: '',
  188. pn: 1
  189. },
  190. // 屏幕宽度, 为了控制分页条的大小
  191. screenWidth: document.body.clientWidth,
  192. currentPage: 1,
  193. pageSize: 10,
  194. totalSize: 0,
  195. dataList: [],
  196. // **********************************************************************
  197. videoProp: null,
  198. showVideoResourceDialog: false,
  199. showEditScopeDialog: false,
  200. showStatDialog: false,
  201. appStatList: [],
  202. form: {
  203. videoId: null,
  204. scope: 1
  205. },
  206. videoResources: [],
  207. publishVideoDiaglog: false
  208. }
  209. },
  210. created() {
  211. getEnvList().then(resp => {
  212. if (resp.code === 0) {
  213. this.queryInfo.env = resp.data.userEnv
  214. this.queryInfo.appType = resp.data.userAppType
  215. this.envList = resp.data.envList
  216. this.appTypeList = resp.data.appTypeList
  217. const env = this.$route.query.env
  218. if (env !== undefined && env !== null) {
  219. this.queryInfo.env = env
  220. }
  221. const appType = this.$route.query.appType
  222. if (appType !== undefined && appType !== null) {
  223. this.queryInfo.appType = appType
  224. }
  225. const pageNumber = this.$route.query.pn
  226. if (pageNumber !== undefined && pageNumber !== null) {
  227. this.currentPage = parseInt(pageNumber)
  228. this.queryInfo.pn = parseInt(pageNumber)
  229. }
  230. this.getData()
  231. } else {
  232. this.$message.error(resp.msg)
  233. }
  234. }).catch(error => {
  235. this.$message.error(error.message)
  236. })
  237. document.title = '运行状态'
  238. },
  239. methods: {
  240. handleCurrentChange(pageNumber) {
  241. this.queryInfo.pn = pageNumber
  242. this.$router.push({
  243. path: '/bg/app/stat',
  244. query: this.queryInfo
  245. })
  246. this.getData()
  247. // 回到顶部
  248. scrollTo(0, 0)
  249. },
  250. getData() {
  251. this.dataList = []
  252. getAppStatList(this.queryInfo).then(resp => {
  253. if (resp.code === 0) {
  254. const respData = resp.data
  255. this.dataList = respData.list
  256. this.totalSize = respData.totalSize
  257. } else {
  258. this.$message.error(resp.msg)
  259. }
  260. }).catch(error => {
  261. this.$message.error(error.message)
  262. })
  263. },
  264. handleDetail(index, row) {
  265. getAppStatDeatil(row.appId).then(resp => {
  266. if (resp.code === 0) {
  267. this.appStatList = resp.data
  268. this.showStatDialog = true
  269. } else {
  270. this.$message.error(resp.msg)
  271. }
  272. }).catch(error => {
  273. this.$message.error(error.message)
  274. })
  275. },
  276. handleRestart(index, row) {
  277. const formData = new FormData()
  278. formData.append('appId', row.appId)
  279. formData.append('machineId', row.machineId)
  280. restartAppStat(formData).then(resp => {
  281. this.$message.info(resp.msg)
  282. }).catch(error => {
  283. this.$message.error(error.message)
  284. })
  285. },
  286. handleStop(index, row) {
  287. const formData = new FormData()
  288. formData.append('appId', row.appId)
  289. formData.append('machineId', row.machineId)
  290. stopAppStat(formData).then(resp => {
  291. this.$message.info(resp.msg)
  292. }).catch(error => {
  293. this.$message.error(error.message)
  294. })
  295. },
  296. handleStart(index, row) {
  297. const formData = new FormData()
  298. formData.append('appId', row.appId)
  299. formData.append('machineId', row.machineId)
  300. startAppStat(formData).then(resp => {
  301. this.$message.info(resp.msg)
  302. }).catch(error => {
  303. this.$message.error(error.message)
  304. })
  305. },
  306. handleGetStat(index, row) {
  307. const queryInfo = {}
  308. queryInfo.appId = row.appId
  309. queryInfo.machineId = row.machineId
  310. getAppStat(queryInfo).then(resp => {
  311. this.$message.info(resp.msg)
  312. }).catch(error => {
  313. this.$message.error(error.message())
  314. })
  315. },
  316. onSelectChange() {
  317. this.currentPage = 1
  318. this.queryInfo.pn = 1
  319. this.$router.push({
  320. path: '/bg/app/stat',
  321. query: this.queryInfo
  322. })
  323. this.getData()
  324. }
  325. }
  326. }
  327. </script>
  328. <style>
  329. </style>