editDialog.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="sysLdap-container">
  3. <el-dialog v-model="isShowDialog" :width="800" draggable="">
  4. <template #header>
  5. <div style="color: #fff">
  6. <!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
  7. <span>{{ props.title }}</span>
  8. </div>
  9. </template>
  10. <el-form :model="ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
  11. <el-row :gutter="35">
  12. <el-form-item v-show="false">
  13. <el-input v-model="ruleForm.id" />
  14. </el-form-item>
  15. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  16. <el-form-item label="主机" prop="host">
  17. <el-input v-model="ruleForm.host" placeholder="请输入主机" maxlength="128" show-word-limit clearable />
  18. </el-form-item>
  19. </el-col>
  20. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  21. <el-form-item label="端口" prop="port">
  22. <el-input v-model="ruleForm.port" placeholder="请输入端口" maxlength="0" show-word-limit clearable />
  23. </el-form-item>
  24. </el-col>
  25. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  26. <el-form-item label="用户搜索基准" prop="baseDn">
  27. <el-input v-model="ruleForm.baseDn" placeholder="请输入用户搜索基准" maxlength="128" show-word-limit clearable />
  28. </el-form-item>
  29. </el-col>
  30. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  31. <el-form-item label="用户过滤规则" prop="authFilter">
  32. <el-input v-model="ruleForm.authFilter" placeholder="请输入用户过滤规则" maxlength="128" show-word-limit clearable />
  33. </el-form-item>
  34. </el-col>
  35. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  36. <el-form-item label="绑定DN" prop="bindDn">
  37. <el-input v-model="ruleForm.bindDn" placeholder="请输入有域管理权限的账户" maxlength="32" show-word-limit clearable />
  38. </el-form-item>
  39. </el-col>
  40. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  41. <el-form-item label="绑定密码" prop="bindPass">
  42. <el-input v-model="ruleForm.bindPass" placeholder="请输入有域管理权限的密码" maxlength="512" show-word-limit clearable />
  43. </el-form-item>
  44. </el-col>
  45. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  46. <el-form-item label="Ldap版本" prop="version">
  47. <el-input v-model="ruleForm.version" placeholder="请输入Ldap版本" maxlength="0" show-word-limit clearable />
  48. </el-form-item>
  49. </el-col>
  50. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
  51. <el-form-item label="状态" prop="status">
  52. <el-switch v-model="ruleForm.status" active-text="是" inactive-text="否" />
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. </el-form>
  57. <template #footer>
  58. <span class="dialog-footer">
  59. <el-button @click="cancel">取 消</el-button>
  60. <el-button type="primary" @click="submit">确 定</el-button>
  61. </span>
  62. </template>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <style scoped>
  67. :deep(.el-select),
  68. :deep(.el-input-number) {
  69. width: 100%;
  70. }
  71. </style>
  72. <script lang="ts" setup>
  73. import { ref,onMounted } from "vue";
  74. import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  75. import { ElMessage } from "element-plus";
  76. import type { FormRules } from "element-plus";
  77. import { addSysLdap, updateSysLdap, detailSysLdap } from "../../../../api/system/sysLdap";
  78. //父级传递来的参数
  79. var props = defineProps({
  80. title: {
  81. type: String,
  82. default: "",
  83. },
  84. });
  85. //父级传递来的函数,用于回调
  86. const emit = defineEmits(["reloadTable"]);
  87. const ruleFormRef = ref();
  88. const isShowDialog = ref(false);
  89. const ruleForm = ref<any>({});
  90. //自行添加其他规则
  91. const rules = ref<FormRules>({
  92. host: [{required: true, message: '请输入主机!', trigger: 'blur',},],
  93. port: [{required: true, message: '请输入端口!', trigger: 'blur',},],
  94. baseDn: [{required: true, message: '请输入用户搜索基准!', trigger: 'blur',},],
  95. bindDn: [{required: true, message: '请输入绑定DN!', trigger: 'blur',},],
  96. bindPass: [{required: true, message: '请输入绑定密码!', trigger: 'blur',},],
  97. authFilter: [{required: true, message: '请输入用户过滤规则!', trigger: 'blur',},],
  98. version: [{required: true, message: '请输入Ldap版本!', trigger: 'blur',},],
  99. });
  100. // 打开弹窗
  101. const openDialog = async (row: any) => {
  102. // ruleForm.value = JSON.parse(JSON.stringify(row));
  103. // 改用detail获取最新数据来编辑
  104. let rowData = JSON.parse(JSON.stringify(row));
  105. if (rowData.id)
  106. ruleForm.value = (await detailSysLdap(rowData.id)).data.result;
  107. else
  108. ruleForm.value = rowData;
  109. isShowDialog.value = true;
  110. };
  111. // 关闭弹窗
  112. const closeDialog = () => {
  113. emit("reloadTable");
  114. isShowDialog.value = false;
  115. };
  116. // 取消
  117. const cancel = () => {
  118. isShowDialog.value = false;
  119. };
  120. // 提交
  121. const submit = async () => {
  122. ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
  123. if (isValid) {
  124. let values = ruleForm.value;
  125. if (ruleForm.value.id == undefined || ruleForm.value.id == null || ruleForm.value.id == "" || ruleForm.value.id == 0) {
  126. await addSysLdap(values);
  127. } else {
  128. await updateSysLdap(values);
  129. }
  130. closeDialog();
  131. } else {
  132. ElMessage({
  133. message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
  134. type: "error",
  135. });
  136. }
  137. });
  138. };
  139. // 页面加载时
  140. onMounted(async () => {
  141. });
  142. //将属性或者函数暴露给父组件
  143. defineExpose({ openDialog });
  144. </script>