config.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="ossConfigId" :request-api="listOssConfigApi">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['system:ossConfig:add']" icon="CirclePlus" @click="openDialog(1, '对象存储配置新增')"> 新增 </el-button>
  7. <el-button
  8. type="danger"
  9. v-auth="['system:ossConfig:remove']"
  10. icon="Delete"
  11. plain
  12. :disabled="!scope.isSelected"
  13. @click="batchDelete(scope.selectedListIds)"
  14. >
  15. 批量删除
  16. </el-button>
  17. </template>
  18. <!-- 表格操作 -->
  19. <template #operation="scope">
  20. <el-tooltip content="编辑" placement="top">
  21. <el-button type="primary" link icon="EditPen" v-auth="['system:ossConfig:edit']" @click="openDialog(2, '对象存储配置编辑', scope.row)">
  22. </el-button>
  23. </el-tooltip>
  24. <el-tooltip content="删除" placement="top">
  25. <el-button type="primary" link icon="Delete" v-auth="['system:ossConfig:remove']" @click="deleteOssConfig(scope.row)"> </el-button>
  26. </el-tooltip>
  27. </template>
  28. </ProTable>
  29. <FormDialog ref="formDialogRef" />
  30. <ImportExcel ref="dialogRef" />
  31. </div>
  32. </template>
  33. <script setup lang="tsx" name="OssConfig">
  34. import { ref, reactive } from 'vue'
  35. import { useHandleData } from '@/hooks/useHandleData'
  36. import ProTable from '@/components/ProTable/index.vue'
  37. import ImportExcel from '@/components/ImportExcel/index.vue'
  38. import FormDialog from '@/components/FormDialog/index.vue'
  39. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  40. import {
  41. listOssConfigApi,
  42. delOssConfigApi,
  43. addOssConfigApi,
  44. updateOssConfigApi,
  45. getOssConfigApi,
  46. changeOssConfigStatusApi
  47. } from '@/api/modules/system/ossConfig'
  48. import { getDictsApi } from '@/api/modules/system/dictData'
  49. import { OssConfigVO } from '@/api/interface/system/ossConfig'
  50. // ProTable 实例
  51. const proTable = ref<ProTableInstance>()
  52. // 删除对象存储配置信息
  53. const deleteOssConfig = async (params: any) => {
  54. await useHandleData(delOssConfigApi, params.ossConfigId, `删除【params.ossConfigId】对象存储配置`)
  55. proTable.value?.getTableList()
  56. }
  57. // 批量删除对象存储配置信息
  58. const batchDelete = async (ids: string[]) => {
  59. await useHandleData(delOssConfigApi, ids, '删除所选对象存储配置信息')
  60. proTable.value?.clearSelection()
  61. proTable.value?.getTableList()
  62. }
  63. // 切换用户状态
  64. const changeStatus = async (row: OssConfigVO) => {
  65. let text = row.status === '1' ? '启用' : '停用'
  66. await useHandleData(
  67. changeOssConfigStatusApi,
  68. { ossConfigId: row.ossConfigId, version: row.version, status: row.status == '1' ? 0 : 1, configKey: row.configKey },
  69. `'要${text}"${row.configKey}'"配置吗?`
  70. )
  71. proTable.value?.getTableList()
  72. }
  73. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  74. // 打开弹框的功能
  75. const openDialog = async (type: number, title: string, row?: any) => {
  76. let res = { data: {} }
  77. if (row?.ossConfigId) {
  78. res = await getOssConfigApi(row?.ossConfigId || null)
  79. }
  80. // 重置表单
  81. setItemsOptions()
  82. const params = {
  83. title,
  84. width: 680,
  85. top: '8vh',
  86. isEdit: type !== 3,
  87. itemsOptions: itemsOptions,
  88. model: type == 1 ? {} : res.data,
  89. api: type == 1 ? addOssConfigApi : updateOssConfigApi,
  90. getTableList: proTable.value?.getTableList
  91. }
  92. formDialogRef.value?.openDialog(params)
  93. }
  94. const types = [
  95. {
  96. label: 'private',
  97. value: '0'
  98. },
  99. {
  100. label: 'public',
  101. value: '1'
  102. },
  103. {
  104. label: 'custom',
  105. value: '2'
  106. }
  107. ]
  108. const statusTypes = [
  109. {
  110. label: '启用',
  111. value: '1'
  112. },
  113. {
  114. label: '停用',
  115. value: '0'
  116. }
  117. ]
  118. // 表格配置项
  119. const columns = reactive<ColumnProps<any>[]>([
  120. {
  121. prop: 'ossConfigId',
  122. label: '主建'
  123. },
  124. {
  125. prop: 'endpoint',
  126. label: '访问站点'
  127. },
  128. {
  129. prop: 'domainName',
  130. label: '自定义域名'
  131. },
  132. {
  133. prop: 'configKey',
  134. label: '配置key',
  135. search: {
  136. el: 'input'
  137. }
  138. },
  139. {
  140. prop: 'bucketName',
  141. label: '桶名称',
  142. search: {
  143. el: 'input'
  144. }
  145. },
  146. {
  147. prop: 'prefix',
  148. label: '前缀'
  149. },
  150. {
  151. prop: 'region',
  152. label: '域'
  153. },
  154. {
  155. prop: 'accessPolicy',
  156. label: '桶权限类型',
  157. tag: true,
  158. enum: types
  159. },
  160. {
  161. prop: 'status',
  162. label: '是否默认',
  163. enum: statusTypes,
  164. search: { el: 'tree-select' },
  165. render: scope => {
  166. return (
  167. <el-switch
  168. model-value={scope.row.status}
  169. active-text={scope.row.status === '1' ? '停用' : '启用'}
  170. active-value={'0'}
  171. inactive-value={'1'}
  172. onClick={() => changeStatus(scope.row)}
  173. />
  174. )
  175. }
  176. },
  177. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  178. ])
  179. // 表单配置项
  180. let itemsOptions: ProForm.ItemsOptions[] = []
  181. const setItemsOptions = () => {
  182. itemsOptions = [
  183. {
  184. label: '配置key',
  185. prop: 'configKey',
  186. rules: [{ required: true, message: '配置key不能为空', trigger: 'blur' }],
  187. compOptions: {
  188. placeholder: '请输入配置key'
  189. }
  190. },
  191. {
  192. label: '访问站点',
  193. prop: 'endpoint',
  194. rules: [
  195. { required: true, message: '访问站点不能为空', trigger: 'blur' },
  196. {
  197. min: 2,
  198. max: 100,
  199. message: '访问站点名称长度必须介于 2 和 100 之间',
  200. trigger: 'blur'
  201. }
  202. ],
  203. compOptions: {
  204. placeholder: '请输入访问站点'
  205. }
  206. },
  207. {
  208. label: '自定义域名',
  209. prop: 'domainName',
  210. compOptions: {
  211. placeholder: '请输入自定义域名'
  212. }
  213. },
  214. {
  215. label: 'accessKey',
  216. prop: 'accessKey',
  217. rules: [
  218. { required: true, message: 'accessKey不能为空', trigger: 'blur' },
  219. {
  220. min: 2,
  221. max: 200,
  222. message: 'accessKey长度必须介于 2 和 100 之间',
  223. trigger: 'blur'
  224. }
  225. ],
  226. compOptions: {
  227. placeholder: '请输入accessKey'
  228. }
  229. },
  230. {
  231. label: 'secretKey',
  232. prop: 'secretKey',
  233. rules: [
  234. { required: true, message: 'secretKey不能为空', trigger: 'blur' },
  235. {
  236. min: 2,
  237. max: 100,
  238. message: 'secretKey长度必须介于 2 和 100 之间',
  239. trigger: 'blur'
  240. }
  241. ],
  242. compOptions: {
  243. showPassword: true,
  244. placeholder: '请输入secretKey'
  245. }
  246. },
  247. {
  248. label: '桶名称',
  249. prop: 'bucketName',
  250. rules: [
  251. { required: true, message: '桶名称不能为空', trigger: 'blur' },
  252. {
  253. min: 2,
  254. max: 100,
  255. message: '桶名称长度必须介于 2 和 100 之间',
  256. trigger: 'blur'
  257. }
  258. ],
  259. compOptions: {
  260. placeholder: '请输入桶名称'
  261. }
  262. },
  263. {
  264. label: '前缀',
  265. prop: 'prefix',
  266. compOptions: {
  267. placeholder: '请输入前缀'
  268. }
  269. },
  270. {
  271. label: '是否https',
  272. prop: 'isHttps',
  273. compOptions: {
  274. elTagName: 'radio-group',
  275. enum: () => getDictsApi('sys_yes_no'),
  276. labelKey: 'dictLabel',
  277. valueKey: 'dictValue'
  278. }
  279. },
  280. {
  281. label: '桶权限类型',
  282. prop: 'accessPolicy',
  283. compOptions: {
  284. elTagName: 'radio-group',
  285. enum: types,
  286. placeholder: '请输入桶权限类型'
  287. }
  288. },
  289. {
  290. label: '域',
  291. prop: 'region',
  292. compOptions: {
  293. placeholder: '请输入域'
  294. }
  295. },
  296. {
  297. label: '备注',
  298. prop: 'remark',
  299. compOptions: {
  300. placeholder: '请输入备注'
  301. }
  302. }
  303. ]
  304. }
  305. </script>