config.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="配置key" prop="configKey">
  5. <el-select v-model="queryParams.configKey" placeholder="请选择配置key" clearable size="small">
  6. <el-option
  7. v-for="configKey in configKeyOptions"
  8. :key="configKey.configKey"
  9. :label="configKey.label"
  10. :value="configKey.configKey"
  11. />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="桶名称" prop="bucketName">
  15. <el-input
  16. v-model="queryParams.bucketName"
  17. placeholder="请输入桶名称"
  18. clearable
  19. size="small"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item label="状态" prop="status">
  24. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  25. <el-option
  26. v-for="dict in statusOptions"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="dict.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. plain
  43. icon="el-icon-plus"
  44. size="mini"
  45. @click="handleAdd"
  46. v-hasPermi="['system:oss:add']"
  47. >新增</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['system:oss:edit']"
  58. >修改</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="danger"
  63. plain
  64. icon="el-icon-delete"
  65. size="mini"
  66. :disabled="multiple"
  67. @click="handleDelete"
  68. v-hasPermi="['system:oss:remove']"
  69. >删除</el-button>
  70. </el-col>
  71. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  72. </el-row>
  73. <el-table v-loading="loading" :data="ossConfigList" @selection-change="handleSelectionChange">
  74. <el-table-column type="selection" width="55" align="center" />
  75. <el-table-column label="主建" align="center" prop="ossConfigId" v-if="false"/>
  76. <el-table-column label="配置key" align="center" prop="configKey" />
  77. <el-table-column label="访问站点" align="center" prop="endpoint" width="200" />
  78. <el-table-column label="桶名称" align="center" prop="bucketName" />
  79. <el-table-column label="前缀" align="center" prop="prefix" />
  80. <el-table-column label="域" align="center" prop="region" />
  81. <el-table-column label="状态" align="center" prop="status">
  82. <template slot-scope="scope">
  83. <el-switch
  84. v-model="scope.row.status"
  85. active-value="0"
  86. inactive-value="1"
  87. @change="handleStatusChange(scope.row)"
  88. ></el-switch>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  92. <template slot-scope="scope">
  93. <el-button
  94. size="mini"
  95. type="text"
  96. icon="el-icon-edit"
  97. @click="handleUpdate(scope.row)"
  98. v-hasPermi="['system:oss:edit']"
  99. >修改</el-button>
  100. <el-button
  101. size="mini"
  102. type="text"
  103. icon="el-icon-delete"
  104. @click="handleDelete(scope.row)"
  105. v-hasPermi="['system:oss:remove']"
  106. >删除</el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <pagination
  111. v-show="total > 0"
  112. :total="total"
  113. :page.sync="queryParams.pageNum"
  114. :limit.sync="queryParams.pageSize"
  115. @pagination="getList"
  116. />
  117. <!-- 添加或修改云存储配置对话框 -->
  118. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  119. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  120. <el-form-item label="配置key" prop="configKey">
  121. <el-select v-model="form.configKey" placeholder="请选择配置key">
  122. <el-option
  123. v-for="configKey in configKeyOptions"
  124. :key="configKey.configKey"
  125. :label="configKey.label"
  126. :value="configKey.configKey"
  127. />
  128. </el-select>
  129. </el-form-item>
  130. <el-form-item label="访问站点" prop="endpoint">
  131. <el-input v-model="form.endpoint" placeholder="请输入访问站点" />
  132. </el-form-item>
  133. <el-form-item label="accessKey" prop="accessKey">
  134. <el-input v-model="form.accessKey" placeholder="请输入accessKey" />
  135. </el-form-item>
  136. <el-form-item label="secretKey" prop="secretKey">
  137. <el-input v-model="form.secretKey" placeholder="请输入秘钥" show-password />
  138. </el-form-item>
  139. <el-form-item label="桶名称" prop="bucketName">
  140. <el-input v-model="form.bucketName" placeholder="请输入桶名称" />
  141. </el-form-item>
  142. <el-form-item label="前缀" prop="prefix">
  143. <el-input v-model="form.prefix" placeholder="请输入前缀" />
  144. </el-form-item>
  145. <el-form-item label="是否HTTPS">
  146. <el-radio-group v-model="form.isHttps">
  147. <el-radio
  148. v-for="dict in isHttpsOptions"
  149. :key="dict.dictValue"
  150. :label="dict.dictValue"
  151. >{{dict.dictLabel}}</el-radio>
  152. </el-radio-group>
  153. </el-form-item>
  154. <el-form-item label="域" prop="region">
  155. <el-input v-model="form.region" placeholder="请输入域" />
  156. </el-form-item>
  157. <el-form-item label="备注" prop="remark">
  158. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  159. </el-form-item>
  160. </el-form>
  161. <div slot="footer" class="dialog-footer">
  162. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  163. <el-button @click="cancel">取 消</el-button>
  164. </div>
  165. </el-dialog>
  166. </div>
  167. </template>
  168. <script>
  169. import {
  170. listOssConfig,
  171. getOssConfig,
  172. delOssConfig,
  173. addOssConfig,
  174. updateOssConfig,
  175. changeOssConfigStatus
  176. } from "@/api/system/ossConfig";
  177. export default {
  178. name: "OssConfig",
  179. data() {
  180. return {
  181. // 按钮loading
  182. buttonLoading: false,
  183. // 遮罩层
  184. loading: true,
  185. // 导出遮罩层
  186. exportLoading: false,
  187. // 选中数组
  188. ids: [],
  189. // 非单个禁用
  190. single: true,
  191. // 非多个禁用
  192. multiple: true,
  193. // 显示搜索条件
  194. showSearch: true,
  195. // 总条数
  196. total: 0,
  197. // 云存储配置表格数据
  198. ossConfigList: [],
  199. // configKeyOptions
  200. configKeyOptions: [],
  201. configKeyDatas: [
  202. { configKey: "minio", label: "Minio" },
  203. { configKey: "qiniu", label: "七牛云" },
  204. { configKey: "aliyun", label: "阿里云" },
  205. { configKey: "qcloud", label: "腾讯云" },
  206. ],
  207. // 弹出层标题
  208. title: "",
  209. // 是否显示弹出层
  210. open: false,
  211. // 是否https字典
  212. isHttpsOptions: [],
  213. // 状态(0正常 1停用)字典
  214. statusOptions: [],
  215. // 查询参数
  216. queryParams: {
  217. pageNum: 1,
  218. pageSize: 10,
  219. reasonable: true,
  220. configKey: undefined,
  221. bucketName: undefined,
  222. status: undefined,
  223. },
  224. // 表单参数
  225. form: {},
  226. // 表单校验
  227. rules: {
  228. configKey: [
  229. { required: true, message: "configKey不能为空", trigger: "blur" },
  230. ],
  231. accessKey: [
  232. { required: true, message: "accessKey不能为空", trigger: "blur" },
  233. {
  234. min: 2,
  235. max: 200,
  236. message: "accessKey长度必须介于 2 和 100 之间",
  237. trigger: "blur",
  238. },
  239. ],
  240. secretKey: [
  241. { required: true, message: "secretKey不能为空", trigger: "blur" },
  242. {
  243. min: 2,
  244. max: 100,
  245. message: "secretKey长度必须介于 2 和 100 之间",
  246. trigger: "blur",
  247. },
  248. ],
  249. bucketName: [
  250. { required: true, message: "bucketName不能为空", trigger: "blur" },
  251. {
  252. min: 2,
  253. max: 100,
  254. message: "bucketName长度必须介于 2 和 100 之间",
  255. trigger: "blur",
  256. },
  257. ],
  258. endpoint: [
  259. { required: true, message: "endpoint不能为空", trigger: "blur" },
  260. {
  261. min: 2,
  262. max: 100,
  263. message: "endpoint名称长度必须介于 2 和 100 之间",
  264. trigger: "blur",
  265. },
  266. ],
  267. },
  268. };
  269. },
  270. created() {
  271. this.getList();
  272. this.getDicts("sys_yes_no").then(response => {
  273. this.isHttpsOptions = response.data;
  274. });
  275. this.getDicts("sys_normal_disable").then(response => {
  276. this.statusOptions = response.data;
  277. });
  278. this.configKeyOptions = this.configKeyDatas;
  279. },
  280. methods: {
  281. /** 查询云存储配置列表 */
  282. getList() {
  283. this.loading = true;
  284. listOssConfig(this.queryParams).then((response) => {
  285. this.ossConfigList = response.rows;
  286. this.total = response.total;
  287. this.loading = false;
  288. });
  289. },
  290. // 取消按钮
  291. cancel() {
  292. this.open = false;
  293. this.reset();
  294. },
  295. // 表单重置
  296. reset() {
  297. this.form = {
  298. ossConfigId: undefined,
  299. configKey: undefined,
  300. accessKey: undefined,
  301. secretKey: undefined,
  302. bucketName: undefined,
  303. prefix: undefined,
  304. endpoint: undefined,
  305. isHttps: "N",
  306. region: undefined,
  307. status: "1",
  308. remark: undefined,
  309. };
  310. this.resetForm("form");
  311. },
  312. /** 搜索按钮操作 */
  313. handleQuery() {
  314. this.queryParams.pageNum = 1;
  315. this.getList();
  316. },
  317. /** 重置按钮操作 */
  318. resetQuery() {
  319. this.resetForm("queryForm");
  320. this.handleQuery();
  321. },
  322. // 多选框选中数据
  323. handleSelectionChange(selection) {
  324. this.ids = selection.map(item => item.ossConfigId)
  325. this.single = selection.length!==1
  326. this.multiple = !selection.length
  327. },
  328. /** 新增按钮操作 */
  329. handleAdd() {
  330. this.reset();
  331. this.open = true;
  332. this.title = "添加云存储配置";
  333. },
  334. /** 修改按钮操作 */
  335. handleUpdate(row) {
  336. this.loading = true;
  337. this.reset();
  338. const ossConfigId = row.ossConfigId || this.ids;
  339. getOssConfig(ossConfigId).then((response) => {
  340. this.loading = false;
  341. this.form = response.data;
  342. this.open = true;
  343. this.title = "修改云存储配置";
  344. });
  345. },
  346. /** 提交按钮 */
  347. submitForm() {
  348. this.$refs["form"].validate(valid => {
  349. if (valid) {
  350. this.buttonLoading = true;
  351. if (this.form.ossConfigId != null) {
  352. updateOssConfig(this.form).then(response => {
  353. this.msgSuccess("修改成功");
  354. this.open = false;
  355. this.getList();
  356. }).finally(() => {
  357. this.buttonLoading = false;
  358. });
  359. } else {
  360. addOssConfig(this.form).then(response => {
  361. this.msgSuccess("新增成功");
  362. this.open = false;
  363. this.getList();
  364. }).finally(() => {
  365. this.buttonLoading = false;
  366. });
  367. }
  368. }
  369. });
  370. },
  371. /** 删除按钮操作 */
  372. handleDelete(row) {
  373. const ossConfigIds = row.ossConfigId || this.ids;
  374. this.$confirm('是否确认删除云存储配置编号为"' + ossConfigIds + '"的数据项?', "警告", {
  375. confirmButtonText: "确定",
  376. cancelButtonText: "取消",
  377. type: "warning"
  378. }).then(() => {
  379. this.loading = true;
  380. return delOssConfig(ossConfigIds);
  381. }).then(() => {
  382. this.loading = false;
  383. this.getList();
  384. this.msgSuccess("删除成功");
  385. }).finally(() => {
  386. this.loading = false;
  387. });
  388. },
  389. // 云存储配置状态修改
  390. handleStatusChange(row) {
  391. let text = row.status === "0" ? "启用" : "停用";
  392. this.$confirm(
  393. '确认要"' + text + '""' + row.configKey + '"配置吗?', "警告", {
  394. confirmButtonText: "确定",
  395. cancelButtonText: "取消",
  396. type: "warning",
  397. }).then(() => {
  398. return changeOssConfigStatus(row.ossConfigId, row.status, row.configKey);
  399. }).then(() => {
  400. this.getList()
  401. this.msgSuccess(text + "成功");
  402. }).catch(() => {
  403. row.status = row.status === "0" ? "1" : "0";
  404. })
  405. }
  406. }
  407. };
  408. </script>