config.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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="状态">
  158. <el-radio-group v-model="form.status">
  159. <el-radio
  160. v-for="dict in statusOptions"
  161. :key="dict.dictValue"
  162. :label="dict.dictValue"
  163. >{{dict.dictLabel}}</el-radio>
  164. </el-radio-group>
  165. </el-form-item>
  166. <el-form-item label="备注" prop="remark">
  167. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  168. </el-form-item>
  169. </el-form>
  170. <div slot="footer" class="dialog-footer">
  171. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  172. <el-button @click="cancel">取 消</el-button>
  173. </div>
  174. </el-dialog>
  175. </div>
  176. </template>
  177. <script>
  178. import {
  179. listOssConfig,
  180. getOssConfig,
  181. delOssConfig,
  182. addOssConfig,
  183. updateOssConfig,
  184. changeOssConfigStatus
  185. } from "@/api/system/ossConfig";
  186. export default {
  187. name: "OssConfig",
  188. data() {
  189. return {
  190. // 按钮loading
  191. buttonLoading: false,
  192. // 遮罩层
  193. loading: true,
  194. // 导出遮罩层
  195. exportLoading: false,
  196. // 选中数组
  197. ids: [],
  198. // 非单个禁用
  199. single: true,
  200. // 非多个禁用
  201. multiple: true,
  202. // 显示搜索条件
  203. showSearch: true,
  204. // 总条数
  205. total: 0,
  206. // 云存储配置表格数据
  207. ossConfigList: [],
  208. // configKeyOptions
  209. configKeyOptions: [],
  210. configKeyDatas: [
  211. { configKey: "minio", label: "Minio" },
  212. { configKey: "qiniu", label: "七牛云" },
  213. { configKey: "aliyun", label: "阿里云" },
  214. { configKey: "qcloud", label: "腾讯云" },
  215. ],
  216. // 弹出层标题
  217. title: "",
  218. // 是否显示弹出层
  219. open: false,
  220. // 是否https字典
  221. isHttpsOptions: [],
  222. // 状态(0正常 1停用)字典
  223. statusOptions: [],
  224. // 查询参数
  225. queryParams: {
  226. pageNum: 1,
  227. pageSize: 10,
  228. configKey: undefined,
  229. bucketName: undefined,
  230. status: undefined,
  231. },
  232. // 表单参数
  233. form: {},
  234. // 表单校验
  235. rules: {
  236. configKey: [
  237. { required: true, message: "configKey不能为空", trigger: "blur" },
  238. ],
  239. accessKey: [
  240. { required: true, message: "accessKey不能为空", trigger: "blur" },
  241. {
  242. min: 2,
  243. max: 200,
  244. message: "accessKey长度必须介于 2 和 100 之间",
  245. trigger: "blur",
  246. },
  247. ],
  248. secretKey: [
  249. { required: true, message: "secretKey不能为空", trigger: "blur" },
  250. {
  251. min: 2,
  252. max: 100,
  253. message: "secretKey长度必须介于 2 和 100 之间",
  254. trigger: "blur",
  255. },
  256. ],
  257. bucketName: [
  258. { required: true, message: "bucketName不能为空", trigger: "blur" },
  259. {
  260. min: 2,
  261. max: 100,
  262. message: "bucketName长度必须介于 2 和 100 之间",
  263. trigger: "blur",
  264. },
  265. ],
  266. endpoint: [
  267. { required: true, message: "endpoint不能为空", trigger: "blur" },
  268. {
  269. min: 2,
  270. max: 100,
  271. message: "endpoint名称长度必须介于 2 和 100 之间",
  272. trigger: "blur",
  273. },
  274. ],
  275. },
  276. };
  277. },
  278. created() {
  279. this.getList();
  280. this.getDicts("sys_yes_no").then(response => {
  281. this.isHttpsOptions = response.data;
  282. });
  283. this.getDicts("sys_normal_disable").then(response => {
  284. this.statusOptions = response.data;
  285. });
  286. this.configKeyOptions = this.configKeyDatas;
  287. },
  288. methods: {
  289. /** 查询云存储配置列表 */
  290. getList() {
  291. this.loading = true;
  292. listOssConfig(this.queryParams).then((response) => {
  293. this.ossConfigList = response.rows;
  294. this.total = response.total;
  295. this.loading = false;
  296. });
  297. },
  298. // 取消按钮
  299. cancel() {
  300. this.open = false;
  301. this.reset();
  302. },
  303. // 表单重置
  304. reset() {
  305. this.form = {
  306. ossConfigId: undefined,
  307. configKey: undefined,
  308. accessKey: undefined,
  309. secretKey: undefined,
  310. bucketName: undefined,
  311. prefix: undefined,
  312. endpoint: undefined,
  313. isHttps: "N",
  314. region: undefined,
  315. status: "1",
  316. remark: undefined,
  317. };
  318. this.resetForm("form");
  319. },
  320. /** 搜索按钮操作 */
  321. handleQuery() {
  322. this.queryParams.pageNum = 1;
  323. this.getList();
  324. },
  325. /** 重置按钮操作 */
  326. resetQuery() {
  327. this.resetForm("queryForm");
  328. this.handleQuery();
  329. },
  330. // 多选框选中数据
  331. handleSelectionChange(selection) {
  332. this.ids = selection.map(item => item.ossConfigId)
  333. this.single = selection.length!==1
  334. this.multiple = !selection.length
  335. },
  336. /** 新增按钮操作 */
  337. handleAdd() {
  338. this.reset();
  339. this.open = true;
  340. this.title = "添加云存储配置";
  341. },
  342. /** 修改按钮操作 */
  343. handleUpdate(row) {
  344. this.loading = true;
  345. this.reset();
  346. const ossConfigId = row.ossConfigId || this.ids;
  347. getOssConfig(ossConfigId).then((response) => {
  348. this.loading = false;
  349. this.form = response.data;
  350. this.open = true;
  351. this.title = "修改云存储配置";
  352. });
  353. },
  354. /** 提交按钮 */
  355. submitForm() {
  356. this.$refs["form"].validate(valid => {
  357. if (valid) {
  358. this.buttonLoading = true;
  359. if (this.form.ossConfigId != null) {
  360. updateOssConfig(this.form).then(response => {
  361. this.msgSuccess("修改成功");
  362. this.open = false;
  363. this.getList();
  364. }).finally(() => {
  365. this.buttonLoading = false;
  366. });
  367. } else {
  368. addOssConfig(this.form).then(response => {
  369. this.msgSuccess("新增成功");
  370. this.open = false;
  371. this.getList();
  372. }).finally(() => {
  373. this.buttonLoading = false;
  374. });
  375. }
  376. }
  377. });
  378. },
  379. /** 删除按钮操作 */
  380. handleDelete(row) {
  381. const ossConfigIds = row.ossConfigId || this.ids;
  382. this.$confirm('是否确认删除云存储配置编号为"' + ossConfigIds + '"的数据项?', "警告", {
  383. confirmButtonText: "确定",
  384. cancelButtonText: "取消",
  385. type: "warning"
  386. }).then(() => {
  387. this.loading = true;
  388. return delOssConfig(ossConfigIds);
  389. }).then(() => {
  390. this.loading = false;
  391. this.getList();
  392. this.msgSuccess("删除成功");
  393. }).finally(() => {
  394. this.loading = false;
  395. });
  396. },
  397. // 云存储配置状态修改
  398. handleStatusChange(row) {
  399. let text = row.status === "0" ? "启用" : "停用";
  400. this.$confirm(
  401. '确认要"' + text + '""' + row.configKey + '"配置吗?', "警告", {
  402. confirmButtonText: "确定",
  403. cancelButtonText: "取消",
  404. type: "warning",
  405. }).then(() => {
  406. return changeOssConfigStatus(row.ossConfigId, row.status, row.configKey);
  407. }).then(() => {
  408. this.getList()
  409. this.msgSuccess(text + "成功");
  410. }).catch(() => {
  411. row.status = row.status === "0" ? "1" : "0";
  412. })
  413. }
  414. }
  415. };
  416. </script>