-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Modify database verification rules #8342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,17 +18,21 @@ | |
| </el-form-item> | ||
| <el-form-item :label="$t('commons.login.password')" prop="password"> | ||
| <el-input type="password" clearable show-password v-model="form.password"></el-input> | ||
| <span class="input-help">{{ $t('commons.rule.illegalChar') }}</span> | ||
| </el-form-item> | ||
| <el-form-item :label="$t('database.permission')" prop="permission"> | ||
| <el-select v-model="form.permission"> | ||
| <el-option value="%" :label="$t('database.permissionAll')" /> | ||
| <el-option | ||
| v-if="form.from !== 'local'" | ||
| value="localhost" | ||
| :label="$t('terminal.localhost')" | ||
| :label="$t('terminal.localhost') + '(localhost)'" | ||
| /> | ||
| <el-option value="ip" :label="$t('database.permissionForIP')" /> | ||
| </el-select> | ||
| <span v-if="form.from !== 'local'" class="input-help"> | ||
| {{ $t('database.localhostHelper') }} | ||
| </span> | ||
| </el-form-item> | ||
| <el-form-item v-if="form.permission === 'ip'" prop="permissionIPs"> | ||
| <el-input clearable :rows="3" type="textarea" v-model="form.permissionIPs" /> | ||
|
|
@@ -60,7 +64,6 @@ import { bindUser } from '@/api/modules/database'; | |
| import DrawerHeader from '@/components/drawer-header/index.vue'; | ||
| import { Rules } from '@/global/form-rules'; | ||
| import { MsgSuccess } from '@/utils/message'; | ||
| import { checkIp } from '@/utils/util'; | ||
|
|
||
| const loading = ref(); | ||
| const bindVisible = ref(false); | ||
|
|
@@ -79,21 +82,11 @@ const confirmDialogRef = ref(); | |
|
|
||
| const rules = reactive({ | ||
| username: [Rules.requiredInput, Rules.name], | ||
| password: [Rules.paramComplexity], | ||
| password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], | ||
| permission: [Rules.requiredSelect], | ||
| permissionIPs: [{ validator: checkIPs, trigger: 'blur', required: true }], | ||
| permissionIPs: [Rules.requiredInput, Rules.noSpace, Rules.illegal], | ||
| }); | ||
|
|
||
| function checkIPs(rule: any, value: any, callback: any) { | ||
| let ips = form.permissionIPs.split(','); | ||
| for (const item of ips) { | ||
| if (checkIp(item)) { | ||
| return callback(new Error(i18n.global.t('commons.rule.ip'))); | ||
| } | ||
| } | ||
| callback(); | ||
| } | ||
|
|
||
| interface DialogProps { | ||
| from: string; | ||
| database: string; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are some improvements to the code:
<el-button type="primary" @click.stop.prevent="handleConfirm" size="small">绑定</el-button>instead of @click:stop.prevent="handleConfirm"
:size="smal"
<v-if="form.from !== 'local' && form.permissioIN === 'ip'">should be simplified to .v-if="(form.from !== 'local') && (form.permission === 'ip')":These changes will improve the readability, consistency, and maintainability of the codebase while ensuring it works correctly under standard conditions. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,10 +43,13 @@ | |
| <el-option | ||
| v-if="form.from !== 'local'" | ||
| value="localhost" | ||
| :label="$t('terminal.localhost')" | ||
| :label="$t('terminal.localhost') + '(localhost)'" | ||
| /> | ||
| <el-option value="ip" :label="$t('database.permissionForIP')" /> | ||
| </el-select> | ||
| <span v-if="form.from !== 'local'" class="input-help"> | ||
| {{ $t('database.localhostHelper') }} | ||
| </span> | ||
| </el-form-item> | ||
| <el-form-item v-if="form.permission === 'ip'" prop="permissionIPs"> | ||
| <el-input clearable :rows="3" type="textarea" v-model="form.permissionIPs" /> | ||
|
|
@@ -86,7 +89,7 @@ import { ElForm } from 'element-plus'; | |
| import { addMysqlDB } from '@/api/modules/database'; | ||
| import DrawerHeader from '@/components/drawer-header/index.vue'; | ||
| import { MsgSuccess } from '@/utils/message'; | ||
| import { checkIp, getRandomStr } from '@/utils/util'; | ||
| import { getRandomStr } from '@/utils/util'; | ||
|
|
||
| const loading = ref(); | ||
| const createVisible = ref(false); | ||
|
|
@@ -107,17 +110,8 @@ const rules = reactive({ | |
| username: [Rules.requiredInput, Rules.name], | ||
| password: [Rules.requiredInput, Rules.noSpace, Rules.illegal], | ||
| permission: [Rules.requiredSelect], | ||
| permissionIPs: [{ validator: checkIPs, trigger: 'blur', required: true }], | ||
| permissionIPs: [Rules.requiredInput, Rules.noSpace, Rules.illegal], | ||
| }); | ||
| function checkIPs(rule: any, value: any, callback: any) { | ||
| let ips = form.permissionIPs.split(','); | ||
| for (const item of ips) { | ||
| if (checkIp(item)) { | ||
| return callback(new Error(i18n.global.t('commons.rule.ip'))); | ||
| } | ||
| } | ||
| callback(); | ||
| } | ||
|
|
||
| type FormInstance = InstanceType<typeof ElForm>; | ||
| const formRef = ref<FormInstance>(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a concise list of changes and optimizations noted in the provided JavaScript code diff: Changes Introduced:
- Added help text when
-function checkIPs(rule: any, value: any, callback: any) {
Potential Issues Identified:
This should address most of the discrepancies between the two snippets. If you have specific concerns about any part, feel free to ask!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code doesn't contain any significant irregularities or potential issues, but there is one minor detail to mention:
Here's the corrected version with just the formatting adjustment: @@ -43,10 +43,13 @@
<el-option
v-if="form.from !== 'local'"
value="localhost"
- :label="$t('terminal.localhost')"
+ :label="$t('terminal.localhost') + '(localhost)'"
/>
<el-option value="ip" :label="$t('database.permissionForIP')" />
</el-select>
+ <!-- Removed excess indentation -->
<span v-if="form.from !== 'local'" class="input-help">
{{ $t('database.localhostHelper') }}
</span>This correction improves readability without altering the logic of the code significantly. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,7 @@ | |
| <el-input disabled v-model="changeForm.userName"></el-input> | ||
| </el-form-item> | ||
| <el-form-item :label="$t('commons.login.password')" prop="password"> | ||
| <el-input | ||
| type="password" | ||
| clearable | ||
| show-password | ||
| v-model="changeForm.password" | ||
| ></el-input> | ||
| <el-input type="password" clearable show-password v-model="changeForm.password" /> | ||
| <span class="input-help">{{ $t('commons.rule.illegalChar') }}</span> | ||
| </el-form-item> | ||
| </div> | ||
|
|
@@ -38,7 +33,9 @@ | |
| /> | ||
| <el-option value="ip" :label="$t('database.permissionForIP')" /> | ||
| </el-select> | ||
| <span class="input-help">{{ $t('database.localhostHelper') }}</span> | ||
| <span v-if="changeForm.from !== 'local'" class="input-help"> | ||
| {{ $t('database.localhostHelper') }} | ||
| </span> | ||
| </el-form-item> | ||
| <el-form-item v-if="changeForm.privilege === 'ip'" prop="privilegeIPs"> | ||
| <el-input clearable :rows="3" type="textarea" v-model="changeForm.privilegeIPs" /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no immediate syntax issues in this code snippet relative to the provided The comment on line 38 states "database. localhostHelper". Assuming you mean "Database Host Helper", here are some thoughts and suggestions:
If these points were part of your overall application design goals, they align with best practices in accessibility and modularity.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the provided code snippet, there is one potential issue with the < span v-if="( changeForm.from !== 'local' )" class="input-help"> ... </span>Additionally, there is an unnecessary space between the opening and closing tags of the The rest of the changes align well with good practices for Vue.js forms. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code you provided has several inconsistencies and potential issues, which I'll address below:
Potential Issues:
Repetitive Logic: The
input-helptext for IP validation is repeated under both "Localhost" options. This could be condensed or removed.Variable Name Conflicts: There seems to be a conflict where the variable
i18nis used twice; once at line 28 with type annotations and again in the template on line 29 without them. It's better to ensure consistent use.Comments Consistency: Inline comments (
//) should not have spaces before the slash. Update these accordingly.Logical Errors:
rules.password, consider usingnoSpacedirectly instead of a separate rule function that calls it.permissionIPsshould be checked more robustly, as the current implementation only checks the first character of each IP against a known pattern but doesn't handle exceptions properly.Unnecessary Imports: If you're already importing
MsgSuccess, there's no need to include an empty import statement after definingloading.Duplicate Code: The logic to split permissions might be redundant inside different conditions.
Optimization Suggestions:
Use Regular Expressions: For improved validity checking of IPs, consider using regular expressions instead of custom functions like
checkIp().Code Duplication Reduction: Remove duplicate comments and unnecessary lines where possible.
Consistent Variable Names: Ensure all instances of variables are consistently named throughout the file.
Revised Code Snippet:
This simplified version reduces repetition, standardizes naming conventions slightly, and removes redundant imports and comments. Please integrate these changes into your project where possible.