index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="p-2">
  3. <el-card shadow="hover">
  4. <template #header>
  5. <el-row :gutter="10" class="mb8">
  6. <el-col :span="1.5">
  7. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:platformConfig:add']">新增</el-button>
  8. </el-col>
  9. <el-col :span="1.5">
  10. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:platformConfig:remove']">删除</el-button>
  11. </el-col>
  12. </el-row>
  13. </template>
  14. <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
  15. <el-table-column type="selection" width="55" align="center" />
  16. <el-table-column label="配置键" prop="configKey" />
  17. <el-table-column label="配置名称" prop="name" />
  18. <el-table-column label="配置值" prop="value" show-overflow-tooltip />
  19. <el-table-column label="操作" width="150" align="center">
  20. <template #default="scope">
  21. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:platformConfig:edit']">修改</el-button>
  22. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:platformConfig:remove']">删除</el-button>
  23. </template>
  24. </el-table-column>
  25. </el-table>
  26. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  27. </el-card>
  28. <!-- 添加或修改对话框 -->
  29. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  30. <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
  31. <el-form-item label="配置键" prop="configKey">
  32. <el-input v-model="form.configKey" placeholder="请输入配置键" />
  33. </el-form-item>
  34. <el-form-item label="配置名称" prop="name">
  35. <el-input v-model="form.name" placeholder="请输入配置名称" />
  36. </el-form-item>
  37. <el-form-item label="配置值" prop="value">
  38. <el-input v-model="form.value" type="textarea" placeholder="请输入配置值" />
  39. </el-form-item>
  40. </el-form>
  41. <template #footer>
  42. <div class="dialog-footer">
  43. <el-button type="primary" @click="submitForm">确 定</el-button>
  44. <el-button @click="cancel">取 消</el-button>
  45. </div>
  46. </template>
  47. </el-dialog>
  48. </div>
  49. </template>
  50. <script setup name="LoginSetting" lang="ts">
  51. import { listPlatformConfig, getPlatformConfig, addPlatformConfig, updatePlatformConfig, delPlatformConfig } from '@/api/system/platformConfig';
  52. import { ComponentInternalInstance, getCurrentInstance, ref, reactive, toRefs } from 'vue';
  53. import { ElForm } from 'element-plus';
  54. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  55. const dataList = ref([]);
  56. const loading = ref(true);
  57. const ids = ref<Array<number | string>>([]);
  58. const single = ref(true);
  59. const multiple = ref(true);
  60. const total = ref(0);
  61. const formRef = ref(ElForm);
  62. const dialog = reactive({ visible: false, title: '' });
  63. const data = reactive({
  64. form: {} as any,
  65. queryParams: {
  66. pageNum: 1,
  67. pageSize: 10,
  68. configType: '1'
  69. },
  70. rules: {
  71. configKey: [{ required: true, message: '配置键不能为空', trigger: 'blur' }],
  72. name: [{ required: true, message: '配置名称不能为空', trigger: 'blur' }],
  73. value: [{ required: true, message: '配置值不能为空', trigger: 'blur' }]
  74. }
  75. });
  76. const { queryParams, form, rules } = toRefs(data);
  77. const getList = async () => {
  78. loading.value = true;
  79. const res = await listPlatformConfig(queryParams.value);
  80. dataList.value = res.rows;
  81. total.value = res.total;
  82. loading.value = false;
  83. };
  84. const handleSelectionChange = (selection: any[]) => {
  85. ids.value = selection.map(item => item.id);
  86. single.value = selection.length !== 1;
  87. multiple.value = !selection.length;
  88. };
  89. const reset = () => {
  90. form.value = {
  91. id: undefined,
  92. configType: '1',
  93. configKey: undefined,
  94. name: undefined,
  95. value: undefined
  96. };
  97. formRef.value?.resetFields();
  98. };
  99. const handleAdd = () => {
  100. reset();
  101. dialog.visible = true;
  102. dialog.title = '添加登录配置';
  103. };
  104. const handleUpdate = async (row: any) => {
  105. reset();
  106. const id = row.id || ids.value[0];
  107. const res = await getPlatformConfig(id);
  108. Object.assign(form.value, res.data);
  109. dialog.visible = true;
  110. dialog.title = '修改登录配置';
  111. };
  112. const submitForm = () => {
  113. formRef.value.validate(async (valid: boolean) => {
  114. if (valid) {
  115. if (form.value.id) {
  116. await updatePlatformConfig(form.value);
  117. proxy?.$modal.msgSuccess('修改成功');
  118. } else {
  119. await addPlatformConfig(form.value);
  120. proxy?.$modal.msgSuccess('新增成功');
  121. }
  122. dialog.visible = false;
  123. getList();
  124. }
  125. });
  126. };
  127. const handleDelete = async (row?: any) => {
  128. const deleteIds = row?.id || ids.value;
  129. await proxy?.$modal.confirm('是否确认删除?');
  130. await delPlatformConfig(deleteIds);
  131. proxy?.$modal.msgSuccess('删除成功');
  132. getList();
  133. };
  134. const cancel = () => {
  135. dialog.visible = false;
  136. reset();
  137. };
  138. getList();
  139. </script>