Rap 原分销系统代码Web
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

d54a3bba4ba4b5eae66eded7a009de40f0d1e65d.svn-base 4.4KB

5 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <el-dialog append-to-body :close-on-click-modal="false" :visible.sync="dialog" title="应用部署" width="400px">
  3. <el-form ref="form" :model="form" :rules="rules" size="small">
  4. <el-upload
  5. :action="deployUploadApi"
  6. :data="deployInfo"
  7. :headers="headers"
  8. :on-success="handleSuccess"
  9. :on-error="handleError"
  10. class="upload-demo"
  11. drag
  12. >
  13. <i class="el-icon-upload" />
  14. <div class="el-upload__text">
  15. 将文件拖到此处,或
  16. <em>点击上传</em>
  17. </div>
  18. <div slot="tip" class="el-upload__tip">多个应用上传文件名称为all.zip,数据库更新脚本扩展名为.sql,上传成功后系统自动部署系统。</div>
  19. </el-upload>
  20. </el-form>
  21. <div slot="footer" class="dialog-footer">
  22. <el-button type="primary" @click="cancel">关闭</el-button>
  23. </div>
  24. </el-dialog>
  25. </template>
  26. <script>
  27. import { add, edit, getApps, getServers } from '@/api/mnt/deploy'
  28. import { mapGetters } from 'vuex'
  29. import { getToken } from '@/utils/auth'
  30. export default {
  31. props: {},
  32. data() {
  33. return {
  34. loading: false,
  35. dialog: false,
  36. apps: [],
  37. servers: [],
  38. headers: {
  39. Authorization: getToken()
  40. },
  41. deployInfo: {},
  42. form: {
  43. id: '',
  44. appId: '',
  45. ip: '',
  46. selectIp: []
  47. },
  48. rules: {}
  49. }
  50. },
  51. computed: {
  52. ...mapGetters(['deployUploadApi'])
  53. },
  54. created() {
  55. this.initWebSocket()
  56. },
  57. mounted() {
  58. this.initSelect()
  59. },
  60. methods: {
  61. cancel() {
  62. this.resetForm()
  63. },
  64. doSubmit() {
  65. this.loading = true
  66. if (this.isAdd) {
  67. this.doAdd()
  68. } else {
  69. this.doEdit()
  70. }
  71. },
  72. joinIp() {
  73. this.form.ip = ''
  74. this.form.selectIp.forEach(ip => {
  75. if (this.form.ip !== '') {
  76. this.form.ip += ','
  77. }
  78. this.form.ip += ip
  79. })
  80. },
  81. doAdd() {
  82. this.joinIp()
  83. add(this.form)
  84. .then(res => {
  85. this.resetForm()
  86. this.$notify({
  87. title: '添加成功',
  88. type: 'success',
  89. duration: 2500
  90. })
  91. this.loading = false
  92. this.$parent.init()
  93. })
  94. .catch(err => {
  95. this.loading = false
  96. console.log(err.response.data.message)
  97. })
  98. },
  99. doEdit() {
  100. this.joinIp()
  101. edit(this.form)
  102. .then(res => {
  103. this.resetForm()
  104. this.$notify({
  105. title: '修改成功',
  106. type: 'success',
  107. duration: 2500
  108. })
  109. this.loading = false
  110. this.$parent.init()
  111. })
  112. .catch(err => {
  113. this.loading = false
  114. console.log(err.response.data.message)
  115. })
  116. },
  117. resetForm() {
  118. this.dialog = false
  119. this.$refs['form'].resetFields()
  120. this.form = {
  121. id: '',
  122. appId: '',
  123. ip: '',
  124. selectIp: []
  125. }
  126. },
  127. initSelect() {
  128. getApps().then(res => {
  129. this.apps = res.content
  130. })
  131. getServers().then(res => {
  132. this.servers = res.content
  133. })
  134. },
  135. handleSuccess(response, file, fileList) {
  136. this.cancel()
  137. },
  138. // 监听上传失败
  139. handleError(e, file, fileList) {
  140. const msg = JSON.parse(e.message)
  141. this.$notify({
  142. title: msg.message,
  143. type: 'error',
  144. duration: 2500
  145. })
  146. },
  147. initWebSocket() {
  148. const wsUri = (process.env.VUE_APP_WS_API === '/' ? '/' : (process.env.VUE_APP_WS_API + '/')) + 'webSocket/deploy'
  149. this.websock = new WebSocket(wsUri)
  150. this.websock.onerror = this.webSocketOnError
  151. this.websock.onmessage = this.webSocketOnMessage
  152. },
  153. webSocketOnError(e) {
  154. this.$notify({
  155. title: 'WebSocket连接发生错误',
  156. type: 'error',
  157. duration: 0
  158. })
  159. },
  160. webSocketOnMessage(e) {
  161. const data = JSON.parse(e.data)
  162. if (data.msgType === 'INFO') {
  163. this.$notify({
  164. title: '',
  165. message: data.msg,
  166. type: 'success',
  167. dangerouslyUseHTMLString: true,
  168. duration: 5500
  169. })
  170. } else if (data.msgType === 'ERROR') {
  171. this.$notify({
  172. title: '',
  173. message: data.msg,
  174. dangerouslyUseHTMLString: true,
  175. type: 'error',
  176. duration: 0
  177. })
  178. }
  179. },
  180. webSocketSend(agentData) {
  181. this.websock.send(agentData)
  182. }
  183. }
  184. }
  185. </script>
  186. <style scoped>
  187. </style>