config.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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="请输入秘钥" />
  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. configKey: undefined,
  220. bucketName: undefined,
  221. status: undefined,
  222. },
  223. // 表单参数
  224. form: {},
  225. // 表单校验
  226. rules: {
  227. configKey: [
  228. { required: true, message: "configKey不能为空", trigger: "blur" },
  229. ],
  230. accessKey: [
  231. { required: true, message: "accessKey不能为空", trigger: "blur" },
  232. {
  233. min: 2,
  234. max: 200,
  235. message: "accessKey长度必须介于 2 和 100 之间",
  236. trigger: "blur",
  237. },
  238. ],
  239. secretKey: [
  240. { required: true, message: "secretKey不能为空", trigger: "blur" },
  241. {
  242. min: 2,
  243. max: 100,
  244. message: "secretKey长度必须介于 2 和 100 之间",
  245. trigger: "blur",
  246. },
  247. ],
  248. bucketName: [
  249. { required: true, message: "bucketName不能为空", trigger: "blur" },
  250. {
  251. min: 2,
  252. max: 100,
  253. message: "bucketName长度必须介于 2 和 100 之间",
  254. trigger: "blur",
  255. },
  256. ],
  257. endpoint: [
  258. { required: true, message: "endpoint不能为空", trigger: "blur" },
  259. {
  260. min: 2,
  261. max: 100,
  262. message: "endpoint名称长度必须介于 2 和 100 之间",
  263. trigger: "blur",
  264. },
  265. ],
  266. },
  267. };
  268. },
  269. created() {
  270. this.getList();
  271. this.getDicts("sys_yes_no").then(response => {
  272. this.isHttpsOptions = response.data;
  273. });
  274. this.getDicts("sys_normal_disable").then(response => {
  275. this.statusOptions = response.data;
  276. });
  277. this.configKeyOptions = this.configKeyDatas;
  278. },
  279. methods: {
  280. /** 查询云存储配置列表 */
  281. getList() {
  282. this.loading = true;
  283. listOssConfig(this.queryParams).then((response) => {
  284. this.ossConfigList = response.rows;
  285. this.total = response.total;
  286. this.loading = false;
  287. });
  288. },
  289. // 取消按钮
  290. cancel() {
  291. this.open = false;
  292. this.reset();
  293. },
  294. // 表单重置
  295. reset() {
  296. this.form = {
  297. ossConfigId: undefined,
  298. configKey: undefined,
  299. accessKey: undefined,
  300. secretKey: undefined,
  301. bucketName: undefined,
  302. prefix: undefined,
  303. endpoint: undefined,
  304. isHttps: "N",
  305. region: undefined,
  306. status: "1",
  307. remark: undefined,
  308. };
  309. this.resetForm("form");
  310. },
  311. /** 搜索按钮操作 */
  312. handleQuery() {
  313. this.queryParams.pageNum = 1;
  314. this.getList();
  315. },
  316. /** 重置按钮操作 */
  317. resetQuery() {
  318. this.resetForm("queryForm");
  319. this.handleQuery();
  320. },
  321. // 多选框选中数据
  322. handleSelectionChange(selection) {
  323. this.ids = selection.map(item => item.ossConfigId)
  324. this.single = selection.length!==1
  325. this.multiple = !selection.length
  326. },
  327. /** 新增按钮操作 */
  328. handleAdd() {
  329. this.reset();
  330. this.open = true;
  331. this.title = "添加云存储配置";
  332. },
  333. /** 修改按钮操作 */
  334. handleUpdate(row) {
  335. this.loading = true;
  336. this.reset();
  337. const ossConfigId = row.ossConfigId || this.ids;
  338. getOssConfig(ossConfigId).then((response) => {
  339. this.loading = false;
  340. this.form = response.data;
  341. this.open = true;
  342. this.title = "修改云存储配置";
  343. });
  344. },
  345. /** 提交按钮 */
  346. submitForm() {
  347. this.$refs["form"].validate(valid => {
  348. if (valid) {
  349. this.buttonLoading = true;
  350. if (this.form.ossConfigId != null) {
  351. updateOssConfig(this.form).then(response => {
  352. this.msgSuccess("修改成功");
  353. this.open = false;
  354. this.getList();
  355. }).finally(() => {
  356. this.buttonLoading = false;
  357. });
  358. } else {
  359. addOssConfig(this.form).then(response => {
  360. this.msgSuccess("新增成功");
  361. this.open = false;
  362. this.getList();
  363. }).finally(() => {
  364. this.buttonLoading = false;
  365. });
  366. }
  367. }
  368. });
  369. },
  370. /** 删除按钮操作 */
  371. handleDelete(row) {
  372. const ossConfigIds = row.ossConfigId || this.ids;
  373. this.$confirm('是否确认删除云存储配置编号为"' + ossConfigIds + '"的数据项?', "警告", {
  374. confirmButtonText: "确定",
  375. cancelButtonText: "取消",
  376. type: "warning"
  377. }).then(() => {
  378. this.loading = true;
  379. return delOssConfig(ossConfigIds);
  380. }).then(() => {
  381. this.loading = false;
  382. this.getList();
  383. this.msgSuccess("删除成功");
  384. }).finally(() => {
  385. this.loading = false;
  386. });
  387. },
  388. // 云存储配置状态修改
  389. handleStatusChange(row) {
  390. let text = row.status === "0" ? "启用" : "停用";
  391. this.$confirm(
  392. '确认要"' + text + '""' + row.configKey + '"配置吗?', "警告", {
  393. confirmButtonText: "确定",
  394. cancelButtonText: "取消",
  395. type: "warning",
  396. }).then(() => {
  397. return changeOssConfigStatus(row.ossConfigId, row.status, row.configKey);
  398. }).then(() => {
  399. this.getList()
  400. this.msgSuccess(text + "成功");
  401. }).catch(() => {
  402. row.status = row.status === "0" ? "1" : "0";
  403. })
  404. }
  405. }
  406. };
  407. </script>