优化第一次
This commit is contained in:
1 parent
3a4e81a070
commit
459339719d
83 files changed
+7001
-1767
No files matched your search
@@ -0,0 +1,262 @@
|
||||
<template>
|
||||
<div class="kingdee-bind-panel" :class="{ embedded: embedded }">
|
||||
<div v-if="loadError" class="inline-alert danger" role="alert">
|
||||
<b>!</b><span>{{ loadError }}</span>
|
||||
<button class="btn small" type="button" @click="load">重试</button>
|
||||
</div>
|
||||
|
||||
<div class="card fill-list-card primary-list-card" :class="{ 'panel-card': embedded }">
|
||||
<div class="filter-bar">
|
||||
<label v-if="canViewAll" class="filter-search">
|
||||
<span aria-hidden="true">🔍</span>
|
||||
<input v-model="search" type="search" placeholder="搜索姓名、工号或金蝶账号" aria-label="搜索财务人员">
|
||||
</label>
|
||||
<span v-else class="filter-hint">当前权限:仅查看本人</span>
|
||||
<span class="filter-spacer"></span>
|
||||
<span class="tag info">{{ filtered.length }} 人</span>
|
||||
<span class="tag" :class="boundCount ? 'success' : 'neutral'">已绑定 {{ boundCount }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="load-wrap" role="status">
|
||||
<span class="loader" aria-hidden="true"></span><span>正在加载绑定列表…</span>
|
||||
</div>
|
||||
<div v-else-if="!loadError && filtered.length" class="table-wrap" tabindex="0" role="region" aria-label="金蝶账号绑定列表">
|
||||
<table class="data-table responsive-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>财务人员</th>
|
||||
<th>工号</th>
|
||||
<th>金蝶账号</th>
|
||||
<th>绑定状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in paginatedItems" :key="item.userId">
|
||||
<td data-label="财务人员">
|
||||
<strong>{{ item.realName }}</strong>
|
||||
<small v-if="item.userId === meId" class="self-mark">本人</small>
|
||||
</td>
|
||||
<td data-label="工号"><small>{{ item.employeeNo || '—' }}</small></td>
|
||||
<td data-label="金蝶账号"><small>{{ item.kingdeeUsername || '—' }}</small></td>
|
||||
<td data-label="绑定状态">
|
||||
<span class="tag" :class="item.bound ? 'success' : 'neutral'">{{ item.bound ? '已绑定' : '未绑定' }}</span>
|
||||
</td>
|
||||
<td data-label="操作" class="actions-cell">
|
||||
<button v-if="canBindRow(item)" class="table-action" type="button" @click="openBind(item)">
|
||||
{{ item.bound ? '重新绑定' : '绑定' }}
|
||||
</button>
|
||||
<button v-if="canBindRow(item) && item.bound" class="table-action" type="button" :disabled="testingId === item.userId" @click="testBinding(item)">
|
||||
{{ testingId === item.userId ? '验证中…' : '验证' }}
|
||||
</button>
|
||||
<button v-if="canUnbindRow(item) && item.bound" class="table-action danger-action" type="button" @click="unbind(item)">解绑</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-else-if="!loading && !loadError" class="empty-state">
|
||||
<strong>{{ canViewAll ? '暂无财务人员' : '暂无本人记录' }}</strong>
|
||||
<span>{{ canViewAll ? '请先为用户分配「财务」角色,或授予「变更金蝶财务单据」权限。' : '当前账号不在可绑定范围内,或尚无权限。' }}</span>
|
||||
</div>
|
||||
<AppListPagination
|
||||
v-if="!loading && !loadError && filtered.length && canViewAll"
|
||||
v-model:page="page"
|
||||
v-model:page-size="pageSize"
|
||||
:total="filtered.length"
|
||||
aria-label="金蝶账号绑定列表分页"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<dialog ref="bindDialog" v-dialog-drag class="app-dialog" aria-labelledby="kingdee-bind-title" @cancel.prevent="closeBind">
|
||||
<form @submit.prevent="saveBind">
|
||||
<div class="modal-head" data-dialog-drag-handle>
|
||||
<div>
|
||||
<span class="eyebrow">BIND KINGDEE ACCOUNT</span>
|
||||
<h2 id="kingdee-bind-title">绑定金蝶账号 · {{ editing?.realName }}</h2>
|
||||
<p>填写该人员在金蝶云星空的登录用户名与密码;保存前默认验证登录。</p>
|
||||
</div>
|
||||
<button class="modal-close" type="button" aria-label="关闭" :disabled="saving" @click="closeBind">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-grid">
|
||||
<div class="field">
|
||||
<label for="kingdee-username">金蝶用户名 <em>*</em></label>
|
||||
<input id="kingdee-username" v-model.trim="form.kingdeeUsername" required autocomplete="username" :disabled="saving">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="kingdee-password">金蝶密码 <em>*</em></label>
|
||||
<input id="kingdee-password" v-model="form.kingdeePassword" type="password" required autocomplete="new-password" :disabled="saving" :placeholder="editing?.bound ? '请重新输入密码' : '请输入金蝶密码'">
|
||||
</div>
|
||||
<label class="check-option full">
|
||||
<input v-model="form.verifyLogin" type="checkbox" :disabled="saving">
|
||||
<span>保存前验证金蝶登录</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button class="btn" type="button" :disabled="saving" @click="closeBind">取消</button>
|
||||
<button class="btn primary" type="submit" :disabled="saving">{{ saving ? '保存中…' : '保存绑定' }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import AppListPagination from '@/components/common/AppListPagination.vue'
|
||||
import { useListPagination } from '@/composables/useListPagination'
|
||||
import { kingdeeAccountsApi, type KingdeeAccountBinding } from '@/api/kingdeeAccounts'
|
||||
import { useUserStore } from '@/store/user'
|
||||
|
||||
defineProps<{ embedded?: boolean }>()
|
||||
|
||||
const userStore = useUserStore()
|
||||
const meId = computed(() => Number(userStore.userInfo?.id || 0) || null)
|
||||
const canViewAll = computed(() => userStore.canRead('finance.kingdee.account.view-all'))
|
||||
const canBindAll = computed(() => userStore.canEdit('finance.kingdee.account.bind'))
|
||||
const canBindOwn = computed(() => userStore.canEdit('finance.kingdee.account.bind-own'))
|
||||
const canUnbindAll = computed(() => userStore.canEdit('finance.kingdee.account.unbind'))
|
||||
const canUnbindOwn = computed(() => userStore.canEdit('finance.kingdee.account.unbind-own'))
|
||||
|
||||
const canBindRow = (item: KingdeeAccountBinding) =>
|
||||
canBindAll.value || (canBindOwn.value && item.userId === meId.value)
|
||||
const canUnbindRow = (item: KingdeeAccountBinding) =>
|
||||
canUnbindAll.value || (canUnbindOwn.value && item.userId === meId.value)
|
||||
|
||||
const items = ref<KingdeeAccountBinding[]>([])
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
const search = ref('')
|
||||
const saving = ref(false)
|
||||
const testingId = ref<number | null>(null)
|
||||
const bindDialog = ref<HTMLDialogElement | null>(null)
|
||||
const editing = ref<KingdeeAccountBinding | null>(null)
|
||||
const form = reactive({ kingdeeUsername: '', kingdeePassword: '', verifyLogin: true })
|
||||
|
||||
const errorText = (error: unknown) => {
|
||||
const responseMessage = (error as { response?: { data?: { message?: unknown } } })?.response?.data?.message
|
||||
if (typeof responseMessage === 'string' && responseMessage.trim()) return responseMessage
|
||||
return error instanceof Error && error.message ? error.message : '请求失败,请稍后重试。'
|
||||
}
|
||||
|
||||
const filtered = computed(() => {
|
||||
const q = search.value.trim().toLowerCase()
|
||||
if (!q) return items.value
|
||||
return items.value.filter(item =>
|
||||
[item.realName, item.employeeNo, item.kingdeeUsername]
|
||||
.some(value => String(value || '').toLowerCase().includes(q)))
|
||||
})
|
||||
const boundCount = computed(() => items.value.filter(item => item.bound).length)
|
||||
const { page, pageSize, paginatedItems } = useListPagination(filtered, { resetSources: [search] })
|
||||
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
await userStore.loadPermissions()
|
||||
items.value = await kingdeeAccountsApi.list() || []
|
||||
} catch (error) {
|
||||
loadError.value = errorText(error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openBind = async (item: KingdeeAccountBinding) => {
|
||||
if (!canBindRow(item)) return
|
||||
editing.value = item
|
||||
form.kingdeeUsername = item.kingdeeUsername || ''
|
||||
form.kingdeePassword = ''
|
||||
form.verifyLogin = true
|
||||
await nextTick()
|
||||
bindDialog.value?.showModal()
|
||||
}
|
||||
|
||||
const closeBind = () => {
|
||||
if (saving.value) return
|
||||
bindDialog.value?.close()
|
||||
editing.value = null
|
||||
}
|
||||
|
||||
const saveBind = async () => {
|
||||
if (!editing.value || !canBindRow(editing.value) || saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
const saved = await kingdeeAccountsApi.bind(editing.value.userId, {
|
||||
kingdeeUsername: form.kingdeeUsername,
|
||||
kingdeePassword: form.kingdeePassword,
|
||||
verifyLogin: form.verifyLogin,
|
||||
})
|
||||
const index = items.value.findIndex(item => item.userId === saved.userId)
|
||||
if (index >= 0) items.value[index] = saved
|
||||
else items.value.push(saved)
|
||||
ElMessage.success('金蝶账号已绑定')
|
||||
closeBind()
|
||||
} catch (error) {
|
||||
ElMessage.error(`绑定失败:${errorText(error)}`)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const testBinding = async (item: KingdeeAccountBinding) => {
|
||||
if (!canBindRow(item) || testingId.value != null) return
|
||||
testingId.value = item.userId
|
||||
try {
|
||||
const result = await kingdeeAccountsApi.test(item.userId)
|
||||
if (result?.success) ElMessage.success(result.message || '验证成功')
|
||||
else ElMessage.error(result?.message || '验证失败')
|
||||
} catch (error) {
|
||||
ElMessage.error(`验证失败:${errorText(error)}`)
|
||||
} finally {
|
||||
testingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const unbind = async (item: KingdeeAccountBinding) => {
|
||||
if (!canUnbindRow(item)) return
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认解绑 ${item.realName} 的金蝶账号?解绑后该员工将无法变更金蝶财务单据。`, '解绑确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '解绑',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await kingdeeAccountsApi.unbind(item.userId)
|
||||
const index = items.value.findIndex(row => row.userId === item.userId)
|
||||
if (index >= 0) {
|
||||
items.value[index] = {
|
||||
...items.value[index],
|
||||
bound: false,
|
||||
kingdeeUsername: null,
|
||||
boundAt: null,
|
||||
updatedAt: null,
|
||||
boundBy: null,
|
||||
}
|
||||
}
|
||||
ElMessage.success('已解绑')
|
||||
} catch (error) {
|
||||
ElMessage.error(`解绑失败:${errorText(error)}`)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => { void load() })
|
||||
|
||||
defineExpose({ reload: load })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.kingdee-bind-panel.embedded .panel-card {
|
||||
box-shadow: none;
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
.filter-hint { color: var(--muted); font-size: 12px; }
|
||||
.self-mark { margin-left: 6px; color: var(--muted); font-size: 11px; }
|
||||
.check-option.full { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 4px; }
|
||||
</style>
|
||||