AppNginxManage.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div class="app-nginx-manange">
  3. <el-dialog
  4. class="page-dialog config-nginx-dialog"
  5. :visible.sync="modalIsShow"
  6. :title="title"
  7. width="1000px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. fullscreen
  12. @opened="visibleChange"
  13. >
  14. <div class="part-box part-box-filter part-box-flex">
  15. <el-form
  16. ref="FilterForm"
  17. label-position="left"
  18. label-width="80px"
  19. :model="filter"
  20. :rules="rules"
  21. inline
  22. >
  23. <el-form-item prop="envId" label="环境">
  24. <env-select
  25. ref="EnvSelect"
  26. v-model="filter.envId"
  27. :app-id="filter.appId"
  28. :clearable="false"
  29. manual-fetch
  30. select-default
  31. @change="envChange"
  32. ></env-select>
  33. </el-form-item>
  34. <el-form-item prop="moduleId" label="模块">
  35. <module-select
  36. ref="ModuleSelect"
  37. v-model="filter.moduleId"
  38. :app-id="filter.appId"
  39. ></module-select>
  40. </el-form-item>
  41. <el-form-item label-width="0px">
  42. <el-button type="primary" icon="ios-search" @click="search"
  43. >查询</el-button
  44. >
  45. </el-form-item>
  46. </el-form>
  47. <div
  48. v-if="checkPrivilege('app_config_nginx_edit') || IS_MAINTAINER"
  49. class="part-box-action"
  50. >
  51. <el-button
  52. :type="isEdit ? 'success' : 'default'"
  53. @click="isEdit = !isEdit"
  54. >编辑</el-button
  55. >
  56. <el-button type="primary" :loading="loading" @click="confirm"
  57. >提交</el-button
  58. >
  59. </div>
  60. </div>
  61. <div class="part-box part-box-pad nginx-body">
  62. <div
  63. v-if="!isEdit"
  64. :class="['nginx-body-cont', { 'is-none': !nginxContent }]"
  65. >
  66. {{ nginxContent || "暂无内容" }}
  67. </div>
  68. <div v-else class="nginx-body-edit">
  69. <el-input v-model="nginxContent" type="textarea"></el-input>
  70. </div>
  71. </div>
  72. </el-dialog>
  73. </div>
  74. </template>
  75. <script>
  76. import { appNginxConfig, appNginxConfigUpdate } from "../api";
  77. export default {
  78. name: "app-nginx-manange",
  79. props: {
  80. app: {
  81. type: Object,
  82. default() {
  83. return {};
  84. }
  85. }
  86. },
  87. data() {
  88. return {
  89. modalIsShow: false,
  90. filter: {
  91. appId: "",
  92. moduleId: null,
  93. envId: null
  94. },
  95. searchFilter: {},
  96. rules: {
  97. envId: [
  98. {
  99. required: true,
  100. type: "number",
  101. message: "请选择环境",
  102. triggr: "change"
  103. }
  104. ]
  105. },
  106. nginxContent: "",
  107. isEdit: false,
  108. loading: false,
  109. curSelectEnv: {},
  110. curSearchEnv: {},
  111. user: {}
  112. };
  113. },
  114. computed: {
  115. title() {
  116. return `应用nginx配置-${this.app.name}`;
  117. },
  118. IS_MAINTAINER() {
  119. return (
  120. this.curSearchEnv.user && this.curSearchEnv.user.id === this.user.id
  121. );
  122. }
  123. },
  124. created() {
  125. this.user = this.$ls.get("user", {});
  126. },
  127. methods: {
  128. visibleChange() {
  129. this.isEdit = false;
  130. this.nginxContent = "";
  131. this.filter = {
  132. appId: this.app.id,
  133. moduleId: null,
  134. envId: null
  135. };
  136. this.$nextTick(async () => {
  137. await this.$refs.EnvSelect.search();
  138. this.search();
  139. });
  140. },
  141. cancel() {
  142. this.modalIsShow = false;
  143. },
  144. open() {
  145. this.modalIsShow = true;
  146. },
  147. envChange(val) {
  148. this.curSelectEnv = val || {};
  149. },
  150. async search() {
  151. const valid = await this.$refs.FilterForm.validate().catch(() => {});
  152. if (!valid) return;
  153. this.searchFilter = { ...this.filter };
  154. const data = await appNginxConfig(this.searchFilter);
  155. this.nginxContent = data.content || "";
  156. this.curSearchEnv = { ...this.curSelectEnv };
  157. },
  158. async confirm() {
  159. if (!this.checkPrivilege("app_config_nginx_edit") && !this.IS_MAINTAINER)
  160. return;
  161. if (!this.nginxContent) {
  162. this.$message.error("请输入配置内容!");
  163. return;
  164. }
  165. if (this.nginxContent.length > 9999) {
  166. this.$message.error("请输入配置内容过长!");
  167. return;
  168. }
  169. if (this.loading) return;
  170. this.loading = true;
  171. const res = await appNginxConfigUpdate({
  172. ...this.filter,
  173. content: this.nginxContent
  174. }).catch(() => {});
  175. this.loading = false;
  176. if (!res) return;
  177. this.$message.success("保存成功!");
  178. }
  179. }
  180. };
  181. </script>