index.vue 13.1 KB
Newer Older
sunhongwei's avatar
sunhongwei committed
1 2
<template>
  <div class="app-container">
Marcus's avatar
Marcus committed
3
    <doc-alert :title="$t('上传下载')" url="https://doc.iocoder.cn/file/" />
sunhongwei's avatar
sunhongwei committed
4 5
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
Marcus's avatar
Marcus committed
6 7
      <el-form-item :label="$t('配置名')" prop="name">
        <el-input v-model="queryParams.name" :placeholder="$t('请输入配置名')" clearable @keyup.enter.native="handleQuery"/>
sunhongwei's avatar
sunhongwei committed
8
      </el-form-item>
Marcus's avatar
Marcus committed
9 10
      <el-form-item :label="$t('存储器')" prop="storage">
        <el-select v-model="queryParams.storage" :placeholder="$t('请选择存储器')" clearable>
sunhongwei's avatar
sunhongwei committed
11 12 13 14
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_FILE_STORAGE)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
Marcus's avatar
Marcus committed
15
      <el-form-item :label="$t('创建时间')">
sunhongwei's avatar
sunhongwei committed
16 17 18 19
        <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
                        type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
Marcus's avatar
Marcus committed
20 21
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('重置') }}</el-button>
sunhongwei's avatar
sunhongwei committed
22 23 24 25 26 27 28
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
Marcus's avatar
Marcus committed
29
                   v-hasPermi="['infra:file-config:create']">{{ $t('新增') }}</el-button>
sunhongwei's avatar
sunhongwei committed
30 31 32 33 34 35
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
Marcus's avatar
Marcus committed
36 37 38
      <el-table-column :label="$t('编号')" align="center" prop="id" />
      <el-table-column :label="$t('配置名')" align="center" prop="name" />
      <el-table-column :label="$t('存储器')" align="center" prop="storage">
sunhongwei's avatar
sunhongwei committed
39 40 41 42
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.INFRA_FILE_STORAGE" :value="scope.row.storage" />
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
43 44
      <el-table-column :label="$t('备注')" align="center" prop="remark" />
      <el-table-column :label="$t('主配置')" align="center" prop="primary">
sunhongwei's avatar
sunhongwei committed
45 46 47 48
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.master" />
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
49
      <el-table-column :label="$t('创建时间')" align="center" prop="createTime" width="180">
sunhongwei's avatar
sunhongwei committed
50 51 52 53
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
Marcus's avatar
Marcus committed
54
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="240">
sunhongwei's avatar
sunhongwei committed
55 56
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
Marcus's avatar
Marcus committed
57
                     v-hasPermi="['infra:file-config:update']">{{ $t('修改') }}</el-button>
sunhongwei's avatar
sunhongwei committed
58
          <el-button size="mini" type="text" icon="el-icon-attract" @click="handleMaster(scope.row)"
Marcus's avatar
Marcus committed
59 60
                     :disabled="scope.row.master" v-hasPermi="['infra:file-config:update']">{{ $t('主配置') }}</el-button>
          <el-button size="mini" type="text" icon="el-icon-share" @click="handleTest(scope.row)">{{ $t('测试') }}</el-button>
sunhongwei's avatar
sunhongwei committed
61
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
Marcus's avatar
Marcus committed
62
                     v-hasPermi="['infra:file-config:delete']">{{ $t('删除') }}</el-button>
sunhongwei's avatar
sunhongwei committed
63 64 65 66 67 68 69 70 71 72
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
Marcus's avatar
Marcus committed
73 74
        <el-form-item :label="$t('配置名')" prop="name">
          <el-input v-model="form.name" :placeholder="$t('请输入配置名')" />
sunhongwei's avatar
sunhongwei committed
75
        </el-form-item>
Marcus's avatar
Marcus committed
76 77
        <el-form-item :label="$t('备注')" prop="remark">
          <el-input v-model="form.remark" :placeholder="$t('请输入备注')" />
sunhongwei's avatar
sunhongwei committed
78
        </el-form-item>
Marcus's avatar
Marcus committed
79 80
        <el-form-item :label="$t('存储器')" prop="storage">
          <el-select v-model="form.storage" :placeholder="$t('请选择存储器')" :disabled="form.id">
sunhongwei's avatar
sunhongwei committed
81 82 83 84 85 86
            <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_FILE_STORAGE)"
                       :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
          </el-select>
        </el-form-item>
        <!-- DB -->
        <!-- Local / FTP / SFTP -->
Marcus's avatar
Marcus committed
87 88
        <el-form-item v-if="form.storage >= 10 && form.storage <= 12" :label="$t('基础路径')" prop="config.basePath">
          <el-input v-model="form.config.basePath" :placeholder="$t('请输入基础路径')" />
sunhongwei's avatar
sunhongwei committed
89
        </el-form-item>
Marcus's avatar
Marcus committed
90 91
        <el-form-item v-if="form.storage >= 11 && form.storage <= 12" :label="$t('主机地址')" prop="config.host">
          <el-input v-model="form.config.host" :placeholder="$t('请输入主机地址')" />
sunhongwei's avatar
sunhongwei committed
92
        </el-form-item>
Marcus's avatar
Marcus committed
93 94
        <el-form-item v-if="form.storage >= 11 && form.storage <= 12" :label="$t('主机端口')" prop="config.port">
          <el-input-number min="0" v-model="form.config.port" :placeholder="$t('请输入主机端口')" />
sunhongwei's avatar
sunhongwei committed
95
        </el-form-item>
Marcus's avatar
Marcus committed
96 97
        <el-form-item v-if="form.storage >= 11 && form.storage <= 12" :label="$t('用户名')" prop="config.username">
          <el-input v-model="form.config.username" :placeholder="$t('请输入密码')" />
sunhongwei's avatar
sunhongwei committed
98
        </el-form-item>
Marcus's avatar
Marcus committed
99 100
        <el-form-item v-if="form.storage >= 11 && form.storage <= 12" :label="$t('密码')" prop="config.password">
          <el-input v-model="form.config.password" :placeholder="$t('请输入密码')" />
sunhongwei's avatar
sunhongwei committed
101
        </el-form-item>
Marcus's avatar
Marcus committed
102
        <el-form-item v-if="form.storage === 11" :label="$t('连接模式')" prop="config.mode">
sunhongwei's avatar
sunhongwei committed
103
          <el-radio-group v-model="form.config.mode">
Marcus's avatar
Marcus committed
104 105
            <el-radio key="Active" label="Active">{{ $t('主动模式') }}</el-radio>
            <el-radio key="Passive" label="Passive">{{ $t('主动模式') }}</el-radio>
sunhongwei's avatar
sunhongwei committed
106 107 108
          </el-radio-group>
        </el-form-item>
        <!-- S3 -->
Marcus's avatar
Marcus committed
109 110
        <el-form-item v-if="form.storage === 20" :label="$t('节点地址')" prop="config.endpoint">
          <el-input v-model="form.config.endpoint" :placeholder="$t('请输入节点地址')" />
sunhongwei's avatar
sunhongwei committed
111 112 113 114 115 116 117 118 119 120 121
        </el-form-item>
        <el-form-item v-if="form.storage === 20" label="存储 bucket" prop="config.bucket">
          <el-input v-model="form.config.bucket" placeholder="请输入 bucket" />
        </el-form-item>
        <el-form-item v-if="form.storage === 20" label="accessKey" prop="config.accessKey">
          <el-input v-model="form.config.accessKey" placeholder="请输入 accessKey" />
        </el-form-item>
        <el-form-item v-if="form.storage === 20" label="accessSecret" prop="config.accessSecret">
          <el-input v-model="form.config.accessSecret" placeholder="请输入 accessSecret" />
        </el-form-item>
        <!-- 通用 -->
Marcus's avatar
Marcus committed
122 123
        <el-form-item v-if="form.storage === 20" :label="$t('自定义域名')"> <!-- 无需参数校验,所以去掉 prop -->
          <el-input v-model="form.config.domain" :placeholder="$t('请输入自定义域名')" />
sunhongwei's avatar
sunhongwei committed
124
        </el-form-item>
Marcus's avatar
Marcus committed
125 126
        <el-form-item v-else-if="form.storage" :label="$t('自定义域名')" prop="config.domain">
          <el-input v-model="form.config.domain" :placeholder="$t('请输入自定义域名')" />
sunhongwei's avatar
sunhongwei committed
127 128 129
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
Marcus's avatar
Marcus committed
130 131
        <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
        <el-button @click="cancel">{{ $t('取 消') }}</el-button>
sunhongwei's avatar
sunhongwei committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  createFileConfig,
  updateFileConfig,
  deleteFileConfig,
  getFileConfig,
  getFileConfigPage,
  testFileConfig, updateFileConfigMaster
} from "@/api/infra/fileConfig";

export default {
  name: "FileConfig",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文件配置列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        name: null,
        storage: null,
      },
      // 表单参数
      form: {
        storage: undefined,
        config: {}
      },
      // 表单校验
      rules: {
Marcus's avatar
Marcus committed
180 181
        name: [{ required: true, message: this.$t("配置名不能为空"), trigger: "blur" }],
        storage: [{ required: true, message: this.$t("存储器不能为空"), trigger: "change" }],
sunhongwei's avatar
sunhongwei committed
182
        config: {
Marcus's avatar
Marcus committed
183 184 185 186 187 188 189
          basePath: [{ required: true, message: this.$t("基础路径不能为空"), trigger: "blur" }],
          host: [{ required: true, message: this.$t("主机地址不能为空"), trigger: "blur" }],
          port: [{ required: true, message: this.$t("主机端口不能为空"), trigger: "blur" }],
          username: [{ required: true, message: this.$t("用户名不能为空"), trigger: "blur" }],
          password: [{ required: true, message: this.$t("密码不能为空"), trigger: "blur" }],
          mode: [{ required: true, message: this.$t("连接模式不能为空"), trigger: "change" }],
          endpoint: [{ required: true, message: this.$t("节点地址不能为空"), trigger: "blur" }],
sunhongwei's avatar
sunhongwei committed
190 191 192
          bucket: [{ required: true, message: "存储 bucket 不能为空", trigger: "blur" }],
          accessKey: [{ required: true, message: "accessKey 不能为空", trigger: "blur" }],
          accessSecret: [{ required: true, message: "accessSecret 不能为空", trigger: "blur" }],
Marcus's avatar
Marcus committed
193
          domain: [{ required: true, message: this.$t("自定义域名不能为空"), trigger: "blur" }],
sunhongwei's avatar
sunhongwei committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        },
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getFileConfigPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        storage: undefined,
        remark: undefined,
        config: {},
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
Marcus's avatar
Marcus committed
246
      this.title = this.$t("添加文件配置");
sunhongwei's avatar
sunhongwei committed
247 248 249 250 251 252 253 254
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getFileConfig(id).then(response => {
        this.form = response.data;
        this.open = true;
Marcus's avatar
Marcus committed
255
        this.title = this.$t("修改文件配置");
sunhongwei's avatar
sunhongwei committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateFileConfig(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createFileConfig(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除文件配置编号为"' + id + '"的数据项?').then(function() {
        return deleteFileConfig(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 主配置按钮操作 */
    handleMaster(row) {
      const id = row.id;
      this.$modal.confirm('是否确认修改配置编号为"' + id + '"的数据项为主配置?').then(function() {
        return updateFileConfigMaster(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("修改成功");
      }).catch(() => {});
    },
    /** 测试按钮操作 */
    handleTest(row) {
      testFileConfig(row.id).then((response) => {
        this.$modal.alert("测试通过,上传文件成功!访问地址:" + response.data);
      }).catch(() => {});
    },
  }
};
</script>