Repository navigation
feat: system scan login permission #7783
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import dingtalkLogo from '@/assets/logo/logo_dingtalk.svg' | |
| import enterpriseWechatLogo from '@/assets/logo/logo_enterprise-wechat.svg' | ||
| import larkLogo from '@/assets/logo/logo_lark.svg' | ||
| import EditSCANDrawer from '../EditSCANDrawer.vue' | ||
| import perm from '@/permission' | ||
|
|
||
| interface QrLoginPlatformView extends QrLoginPlatformPayload { | ||
| isValid: boolean | ||
|
|
@@ -88,12 +89,12 @@ onMounted(loadQrPlatforms) | |
|
|
||
| <div class="flex-align-center gap-4"> | ||
| <!-- 配置扫码登录平台 --> | ||
| <el-button plain @click.stop="handleEditPlatform(platform)">{{ platform.isValid ? '配置' : '未配置' }}</el-button> | ||
| <el-button :disabled="!perm.system.loginAuth.edit()" plain @click.stop="handleEditPlatform(platform)">{{ platform.isValid ? '配置' : '未配置' }}</el-button> | ||
| <template v-if="platform.isValid"> | ||
| <el-divider direction="vertical" /> | ||
| <!-- 启停扫码登录,阻止点击打开配置 --> | ||
| <span class="inline-flex" @click.stop> | ||
| <el-switch v-model="platform.isActive" @change="handlePlatformStatusChange(platform)" /> | ||
| <el-switch :disabled="!perm.system.loginAuth.edit()" v-model="platform.isActive" @change="handlePlatformStatusChange(platform)" /> | ||
| </span> | ||
| </template> | ||
| </div> | ||
|
Contributor
Author
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 review of the provided code diff with potential issues and optimization suggestions: 1. Naming Convention & Readability
2. Performance / Reactivity
3. Code Duplication
4. Type Safety / API Contract
5. Accessibility / UX
✅ Recommended Refactored Code Snippet// Script setup section
<script setup lang="ts">
import { computed } from 'vue'
// Assuming '@/permission' defaults export an object or named exports.
// Adjust import based on your actual module structure.
import permissionApi from '@/permission'
// Extract permission state to a computed property for better readability and caching
const canEditLoginAuth = computed(() => {
// Safely access nested properties if necessary
return !!permissionApi?.system?.loginAuth?.edit?.()
})
</script>
<template>
<div class="flex-align-center gap-4">
<!-- Configuration Button -->
<el-button
:disabled="!canEditLoginAuth"
plain
@click.stop="handleEditPlatform(platform)"
>
{{ platform.isValid ? '配置' : '未配置' }}
</el-button>
<template v-if="platform.isValid">
<el-divider direction="vertical" />
<!-- Status Switch -->
<span class="inline-flex" @click.stop>
<el-switch
:disabled="!canEditLoginAuth"
v-model="platform.isActive"
@change="handlePlatformStatusChange(platform)"
<!-- Optional: Add tooltip for accessibility when disabled -->
:title="!canEditLoginAuth ? '权限不足,无法启停平台' : ''"
/>
</span>
</template>
</div>
</template>This approach improves maintainability, reduces redundant logic, and provides clearer intent. |
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here is an analysis of the provided code diff:
✅ Positive Aspects
perm.system.chatAuth.edit()checks to both theel-buttonand theel-switch, which is good for security and UX consistency.1. Performance: Repeated Function Calls in Template
Issue: You are calling
!perm.system.chatAuth.edit()directly in the template for every platform item in av-forloop (implied by the context).Risk: If the list of platforms is long, this function might be called excessively during re-renders, causing unnecessary computation.
Suggestion: Compute the permission once before rendering.
2. Logic Redundancy / Edge Case
Issue: The
el-switchhas@click.stopon its wrapper span (<span class="inline-flex" @click.stop>). Whendisabledis true, Element Plus usually handles interaction prevention internally. However, relying solely on visual disable without ensuring the underlying logic respects the permission in the event handler (handlePlatformStatusChange) can be risky if someone bypasses UI restrictions (e.g., via console or API).Suggestion: Ensure
handleEditPlatformandhandlePlatformStatusChangealso check permissions internally, even if the UI is disabled.3. Import Path & Naming Convention
Issue:
import perm from '@/permission'suggests a default export. Ensure this aligns with your project’s convention. Also,chatAuthshould ideally reflect a clear domain boundary.4. Accessibility (a11y)
Issue: Disabled buttons don’t communicate why they are disabled.
Suggestion: Consider adding a tooltip or note when the button is disabled due to lack of permission.
💡 Optimized Code Suggestion
Summary of Recommendations
computedproperty (canEditChatAuth) to cache the permission result.handleEditPlatformandhandlePlatformStatusChangefunctions, not just in the UI.