补足用户切换功能
This commit is contained in:
@@ -35,6 +35,21 @@
|
||||
|
||||
<div class="sider-footer">
|
||||
<a-button block @click="router.push('/')">返回首页</a-button>
|
||||
<div class="mock-user-panel">
|
||||
<div class="mock-user-label">测试用户切换</div>
|
||||
<a-select
|
||||
v-model:value="selectedMockUserKey"
|
||||
class="mock-user-select"
|
||||
:options="mockUserOptions"
|
||||
:loading="mockUserLoading"
|
||||
placeholder="请选择测试用户"
|
||||
@change="handleMockUserChange"
|
||||
/>
|
||||
<div v-if="currentMockUser" class="mock-user-meta">
|
||||
{{ currentMockUser.systemType === 'manage' ? '管理端' : currentMockUser.systemType === 'business' ? '业务端' : '平台' }}
|
||||
· {{ currentMockUser.orgName }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a-layout-sider>
|
||||
|
||||
@@ -53,8 +68,14 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import {
|
||||
getCurrentMockUser,
|
||||
listMockUsers,
|
||||
} from '@/api/mockUser'
|
||||
import { getStoredMockUser, setStoredMockUser } from '@/utils/mockUserStorage'
|
||||
import {
|
||||
FileDoneOutlined,
|
||||
FileTextOutlined,
|
||||
@@ -65,6 +86,10 @@ import {
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const mockUserLoading = ref(false)
|
||||
const mockUserList = ref([])
|
||||
const currentMockUser = ref(null)
|
||||
const selectedMockUserKey = ref(getStoredMockUser())
|
||||
|
||||
const selectedKey = computed(() => {
|
||||
if (route.path.startsWith('/contract-console/sign')) {
|
||||
@@ -88,9 +113,49 @@ const selectedKey = computed(() => {
|
||||
|
||||
const currentTitle = computed(() => route.meta?.title || '合同管理')
|
||||
|
||||
const mockUserOptions = computed(() =>
|
||||
mockUserList.value.map((item) => ({
|
||||
label: `${item.displayName} (${item.orgId})`,
|
||||
value: item.key,
|
||||
})),
|
||||
)
|
||||
|
||||
function handleMenuClick({ key }) {
|
||||
router.push(key)
|
||||
}
|
||||
|
||||
async function loadMockUsers() {
|
||||
mockUserLoading.value = true
|
||||
try {
|
||||
mockUserList.value = await listMockUsers()
|
||||
const availableKeys = new Set(mockUserList.value.map((item) => item.key))
|
||||
if (!availableKeys.has(selectedMockUserKey.value) && mockUserList.value.length > 0) {
|
||||
selectedMockUserKey.value = mockUserList.value[0].key
|
||||
setStoredMockUser(selectedMockUserKey.value)
|
||||
}
|
||||
} finally {
|
||||
mockUserLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCurrentMockUser() {
|
||||
currentMockUser.value = await getCurrentMockUser()
|
||||
if (currentMockUser.value?.key) {
|
||||
selectedMockUserKey.value = currentMockUser.value.key
|
||||
setStoredMockUser(currentMockUser.value.key)
|
||||
}
|
||||
}
|
||||
|
||||
function handleMockUserChange(value) {
|
||||
setStoredMockUser(value)
|
||||
message.success('测试用户已切换,正在刷新页面数据')
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadMockUsers()
|
||||
await loadCurrentMockUser()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -149,6 +214,33 @@ function handleMenuClick({ key }) {
|
||||
padding: 16px 20px 20px;
|
||||
}
|
||||
|
||||
.mock-user-panel {
|
||||
margin-bottom: 12px;
|
||||
padding: 12px;
|
||||
border-radius: 14px;
|
||||
background: rgba(255, 255, 255, 0.78);
|
||||
border: 1px solid rgba(37, 99, 235, 0.12);
|
||||
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
|
||||
}
|
||||
|
||||
.mock-user-label {
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
color: #334155;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.mock-user-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mock-user-meta {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.contract-header {
|
||||
height: auto;
|
||||
background: rgba(255, 255, 255, 0.96);
|
||||
|
||||
Reference in New Issue
Block a user