123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <template>
- <div class="app-nginx-manange">
- <el-dialog
- class="page-dialog config-nginx-dialog"
- :visible.sync="modalIsShow"
- :title="title"
- width="1000px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- fullscreen
- @opened="visibleChange"
- >
- <div class="part-box part-box-filter part-box-flex">
- <el-form
- ref="FilterForm"
- label-position="left"
- label-width="80px"
- :model="filter"
- :rules="rules"
- inline
- >
- <el-form-item prop="envId" label="环境">
- <env-select
- ref="EnvSelect"
- v-model="filter.envId"
- :app-id="filter.appId"
- :clearable="false"
- manual-fetch
- select-default
- @change="envChange"
- ></env-select>
- </el-form-item>
- <el-form-item prop="moduleId" label="模块">
- <module-select
- ref="ModuleSelect"
- v-model="filter.moduleId"
- :app-id="filter.appId"
- ></module-select>
- </el-form-item>
- <el-form-item label-width="0px">
- <el-button type="primary" icon="ios-search" @click="search"
- >查询</el-button
- >
- </el-form-item>
- </el-form>
- <div
- v-if="checkPrivilege('app_config_nginx_edit') || IS_MAINTAINER"
- class="part-box-action"
- >
- <el-button
- :type="isEdit ? 'success' : 'default'"
- @click="isEdit = !isEdit"
- >编辑</el-button
- >
- <el-button type="primary" :loading="loading" @click="confirm"
- >提交</el-button
- >
- </div>
- </div>
- <div class="part-box part-box-pad nginx-body">
- <div
- v-if="!isEdit"
- :class="['nginx-body-cont', { 'is-none': !nginxContent }]"
- >
- {{ nginxContent || "暂无内容" }}
- </div>
- <div v-else class="nginx-body-edit">
- <el-input v-model="nginxContent" type="textarea"></el-input>
- </div>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { appNginxConfig, appNginxConfigUpdate } from "../api";
- export default {
- name: "app-nginx-manange",
- props: {
- app: {
- type: Object,
- default() {
- return {};
- }
- }
- },
- data() {
- return {
- modalIsShow: false,
- filter: {
- appId: "",
- moduleId: null,
- envId: null
- },
- searchFilter: {},
- rules: {
- envId: [
- {
- required: true,
- type: "number",
- message: "请选择环境",
- triggr: "change"
- }
- ]
- },
- nginxContent: "",
- isEdit: false,
- loading: false,
- curSelectEnv: {},
- curSearchEnv: {},
- user: {}
- };
- },
- computed: {
- title() {
- return `应用nginx配置-${this.app.name}`;
- },
- IS_MAINTAINER() {
- return (
- this.curSearchEnv.user && this.curSearchEnv.user.id === this.user.id
- );
- }
- },
- created() {
- this.user = this.$ls.get("user", {});
- },
- methods: {
- visibleChange() {
- this.isEdit = false;
- this.nginxContent = "";
- this.filter = {
- appId: this.app.id,
- moduleId: null,
- envId: null
- };
- this.$nextTick(async () => {
- await this.$refs.EnvSelect.search();
- this.search();
- });
- },
- cancel() {
- this.modalIsShow = false;
- },
- open() {
- this.modalIsShow = true;
- },
- envChange(val) {
- this.curSelectEnv = val || {};
- },
- async search() {
- const valid = await this.$refs.FilterForm.validate().catch(() => {});
- if (!valid) return;
- this.searchFilter = { ...this.filter };
- const data = await appNginxConfig(this.searchFilter);
- this.nginxContent = data.content || "";
- this.curSearchEnv = { ...this.curSelectEnv };
- },
- async confirm() {
- if (!this.checkPrivilege("app_config_nginx_edit") && !this.IS_MAINTAINER)
- return;
- if (!this.nginxContent) {
- this.$message.error("请输入配置内容!");
- return;
- }
- if (this.nginxContent.length > 9999) {
- this.$message.error("请输入配置内容过长!");
- return;
- }
- if (this.loading) return;
- this.loading = true;
- const res = await appNginxConfigUpdate({
- ...this.filter,
- content: this.nginxContent
- }).catch(() => {});
- this.loading = false;
- if (!res) return;
- this.$message.success("保存成功!");
- }
- }
- };
- </script>
|