Rap 原分销系统代码Web
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

230 строки
7.5KB

  1. <template>
  2. <div class="app-container">
  3. <!--工具栏-->
  4. <div class="head-container">
  5. <div v-if="crud.props.searchToggle">
  6. <!-- 搜索 -->
  7. <el-input v-model="query.appName" clearable placeholder="输入应用名称查询" style="width: 200px" class="filter-item" @keyup.enter.native="crud.toQuery" />
  8. <date-range-picker v-model="query.createTime" class="date-item" />
  9. <rrOperation />
  10. </div>
  11. <crudOperation :permission="permission">
  12. <template slot="right">
  13. <el-button
  14. v-permission="['admin','deploy:add']"
  15. :disabled="!selectIndex"
  16. class="filter-item"
  17. size="mini"
  18. type="primary"
  19. icon="el-icon-upload"
  20. @click="sysRestore"
  21. >系统还原
  22. </el-button>
  23. <el-button
  24. v-permission="['admin','deploy:add']"
  25. :disabled="!selectIndex"
  26. class="filter-item"
  27. size="mini"
  28. type="primary"
  29. icon="el-icon-upload"
  30. @click="serverStatus"
  31. >状态查询
  32. </el-button>
  33. <el-button
  34. v-permission="['admin','deploy:add']"
  35. :disabled="!selectIndex"
  36. class="filter-item"
  37. size="mini"
  38. type="success"
  39. icon="el-icon-upload"
  40. @click="startServer"
  41. >启动
  42. </el-button>
  43. <el-button
  44. v-permission="['admin','deploy:add']"
  45. :disabled="!selectIndex"
  46. class="filter-item"
  47. size="mini"
  48. type="danger"
  49. icon="el-icon-upload"
  50. @click="stopServer"
  51. >停止
  52. </el-button>
  53. <el-button
  54. v-permission="['admin','deploy:add']"
  55. :disabled="!selectIndex"
  56. class="filter-item"
  57. size="mini"
  58. type="warning"
  59. icon="el-icon-upload"
  60. @click="deploy"
  61. >一键部署
  62. </el-button>
  63. </template>
  64. </crudOperation>
  65. </div>
  66. <!--表单组件-->
  67. <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
  68. <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
  69. <el-form-item label="应用" prop="app.id">
  70. <el-select v-model.number="form.app.id" placeholder="请选择" style="width: 370px">
  71. <el-option v-for="item in apps" :key="item.id" :label="item.name" :value="item.id" />
  72. </el-select>
  73. </el-form-item>
  74. <el-form-item label="服务器" prop="deploys">
  75. <el-select v-model="form.deploys" multiple placeholder="请选择" style="width: 370px">
  76. <el-option v-for="item in servers" :key="item.id" :label="item.name" :value="item.id" />
  77. </el-select>
  78. </el-form-item>
  79. </el-form>
  80. <div slot="footer" class="dialog-footer">
  81. <el-button type="text" @click="crud.cancelCU">取消</el-button>
  82. <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
  83. </div>
  84. </el-dialog>
  85. <!--统还原组件-->
  86. <fForm ref="sysRestore" :key="times" :app-name="appName" />
  87. <dForm ref="deploy" />
  88. <!--表格渲染-->
  89. <el-table ref="table" v-loading="crud.loading" :data="crud.data" highlight-current-row stripe style="width: 100%" @selection-change="handleCurrentChange">
  90. <el-table-column type="selection" width="55" />
  91. <el-table-column prop="app.name" label="应用名称" />
  92. <el-table-column prop="servers" label="服务器列表" />
  93. <el-table-column prop="createTime" label="部署日期" />
  94. <el-table-column v-if="checkPer(['admin','deploy:edit','deploy:del'])" label="操作" width="150px" align="center">
  95. <template slot-scope="scope">
  96. <udOperation
  97. :data="scope.row"
  98. :permission="permission"
  99. />
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <!--分页组件-->
  104. <pagination />
  105. </div>
  106. </template>
  107. <script>
  108. import crudDeploy from '@/api/mnt/deploy'
  109. import dForm from './deploy'
  110. import fForm from './sysRestore'
  111. import CRUD, { presenter, header, form, crud } from '@crud/crud'
  112. import rrOperation from '@crud/RR.operation'
  113. import crudOperation from '@crud/CRUD.operation'
  114. import udOperation from '@crud/UD.operation'
  115. import pagination from '@crud/Pagination'
  116. import DateRangePicker from '@/components/DateRangePicker'
  117. const defaultForm = { id: null, app: { id: null }, deploys: [] }
  118. export default {
  119. name: 'Deploy',
  120. components: { dForm, fForm, pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  121. cruds() {
  122. return CRUD({ title: '部署', url: 'api/deploy', crudMethod: { ...crudDeploy }})
  123. },
  124. mixins: [presenter(), header(), form(defaultForm), crud()],
  125. data() {
  126. return {
  127. currentRow: {}, selectIndex: '', appName: '', urlHistory: '',
  128. times: 0, appId: '', deployId: '', apps: [], servers: [],
  129. permission: {
  130. add: ['admin', 'deploy:add'],
  131. edit: ['admin', 'deploy:edit'],
  132. del: ['admin', 'deploy:del']
  133. },
  134. rules: {
  135. 'app.id': [
  136. { required: true, message: '应用不能为空', trigger: 'blur', type: 'number' }
  137. ],
  138. deploys: [
  139. { required: true, message: '服务器不能为空', trigger: 'blur' }
  140. ]
  141. }
  142. }
  143. },
  144. methods: {
  145. [CRUD.HOOK.beforeRefresh]() {
  146. this.selectIndex = ''
  147. return true
  148. },
  149. // 新增编辑前做的操作
  150. [CRUD.HOOK.beforeToCU](crud, form) {
  151. this.initSelect()
  152. const deploys = []
  153. form.deploys.forEach(function(deploy, index) {
  154. deploys.push(deploy.id)
  155. })
  156. this.form.deploys = deploys
  157. },
  158. // 提交前
  159. [CRUD.HOOK.beforeSubmit]() {
  160. const deploys = []
  161. this.form.deploys.forEach(function(data, index) {
  162. const deploy = { id: data }
  163. deploys.push(deploy)
  164. })
  165. this.form.deploys = deploys
  166. return true
  167. },
  168. deploy() {
  169. this.$refs.deploy.dialog = true
  170. this.$refs.deploy.deployInfo = this.currentRow
  171. },
  172. sysRestore() {
  173. this.$refs.sysRestore.dialog = true
  174. },
  175. handleCurrentChange(selection) {
  176. this.crud.selections = selection
  177. if (selection.length === 1) {
  178. const row = selection[0]
  179. this.selectIndex = row.id
  180. this.currentRow = row
  181. this.appName = row.app.name
  182. this.times = this.times + 1
  183. this.appId = row.appId
  184. this.deployId = row.id
  185. } else {
  186. this.currentRow = {}
  187. this.selectIndex = ''
  188. }
  189. },
  190. startServer() {
  191. crudDeploy.startServer(JSON.stringify(this.currentRow))
  192. .then(res => {
  193. })
  194. .catch(err => {
  195. console.log('error:' + err.response.data.message)
  196. })
  197. },
  198. stopServer() {
  199. crudDeploy.stopServer(JSON.stringify(this.currentRow))
  200. .then(res => {
  201. })
  202. .catch(err => {
  203. console.log('error:' + err.response.data.message)
  204. })
  205. },
  206. serverStatus() {
  207. crudDeploy.serverStatus(JSON.stringify(this.currentRow))
  208. .then(res => {
  209. })
  210. .catch(err => {
  211. console.log('error:' + err.response.data.message)
  212. })
  213. },
  214. initSelect() {
  215. crudDeploy.getApps().then(res => {
  216. this.apps = res.content
  217. })
  218. crudDeploy.getServers().then(res => {
  219. this.servers = res.content
  220. })
  221. }
  222. }
  223. }
  224. </script>
  225. <style scoped>
  226. </style>