1.优化后台管理员管理页面的权限设置
This commit is contained in:
@@ -325,15 +325,6 @@ class Admin extends Backend
|
|||||||
$passwd = $data['password'] ?? '';
|
$passwd = $data['password'] ?? '';
|
||||||
$data = $this->excludeFields($data);
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
if (!$this->auth->isSuperAdmin()) {
|
|
||||||
$creatorChannelId = $this->getCreatorChannelId();
|
|
||||||
if ($creatorChannelId === null || $creatorChannelId === '') {
|
|
||||||
return $this->error(__('You have no permission'));
|
|
||||||
}
|
|
||||||
$data['channel_id'] = $creatorChannelId;
|
|
||||||
$data['parent_admin_id'] = $this->auth->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$parentErr = $this->normalizeParentAndShareFields($data, null, $data['group_arr'] ?? []);
|
$parentErr = $this->normalizeParentAndShareFields($data, null, $data['group_arr'] ?? []);
|
||||||
if ($parentErr !== null) {
|
if ($parentErr !== null) {
|
||||||
return $this->error($parentErr);
|
return $this->error($parentErr);
|
||||||
@@ -469,13 +460,6 @@ class Admin extends Backend
|
|||||||
$data = $this->excludeFields($data);
|
$data = $this->excludeFields($data);
|
||||||
unset($data['invite_code'], $data['group_arr'], $data['group_name_arr']);
|
unset($data['invite_code'], $data['group_arr'], $data['group_name_arr']);
|
||||||
if (!$isSelfEdit) {
|
if (!$isSelfEdit) {
|
||||||
if (!$this->auth->isSuperAdmin()) {
|
|
||||||
unset($data['parent_admin_id'], $data['channel_id']);
|
|
||||||
$creatorChannelId = $this->getCreatorChannelId();
|
|
||||||
if ($creatorChannelId !== null && $creatorChannelId !== '') {
|
|
||||||
$data['channel_id'] = $creatorChannelId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$parentErr = $this->normalizeParentAndShareFields($data, intval($id), $editGroupArr ?? []);
|
$parentErr = $this->normalizeParentAndShareFields($data, intval($id), $editGroupArr ?? []);
|
||||||
if ($parentErr !== null) {
|
if ($parentErr !== null) {
|
||||||
return $this->error($parentErr);
|
return $this->error($parentErr);
|
||||||
@@ -680,17 +664,18 @@ class Admin extends Backend
|
|||||||
return array_values(array_unique(array_merge($own, $children)));
|
return array_values(array_unique(array_merge($own, $children)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCreatorChannelId(): mixed
|
private function operatorMayAssignChannel(): bool
|
||||||
{
|
{
|
||||||
$currentAdmin = Db::name('admin')
|
if ($this->auth->isSuperAdmin()) {
|
||||||
->field(['id', 'channel_id'])
|
return true;
|
||||||
->where('id', $this->auth->id)
|
}
|
||||||
->find();
|
foreach (['channel/index', 'channel/Index', 'Channel/index', 'Channel/Index'] as $routePath) {
|
||||||
if ($currentAdmin && !empty($currentAdmin['channel_id'])) {
|
if ($this->auth->check($routePath)) {
|
||||||
return $currentAdmin['channel_id'];
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canManageAdminId(int $adminId): bool
|
private function canManageAdminId(int $adminId): bool
|
||||||
@@ -780,9 +765,15 @@ class Admin extends Backend
|
|||||||
if ($channelIdInt <= 0) {
|
if ($channelIdInt <= 0) {
|
||||||
$data['channel_id'] = null;
|
$data['channel_id'] = null;
|
||||||
$data['commission_share_rate'] = null;
|
$data['commission_share_rate'] = null;
|
||||||
|
if ($editAdminId === null && !$this->auth->isSuperAdmin() && !$this->operatorMayAssignChannel()) {
|
||||||
|
return (string) __('Please select a parent agent');
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!$this->auth->isSuperAdmin() && !$this->operatorMayAssignChannel()) {
|
||||||
|
return (string) __('You have no permission');
|
||||||
|
}
|
||||||
$exists = Db::name('channel')->where('id', $channelIdInt)->value('id');
|
$exists = Db::name('channel')->where('id', $channelIdInt)->value('id');
|
||||||
if (!$exists) {
|
if (!$exists) {
|
||||||
return (string) __('Record not found');
|
return (string) __('Record not found');
|
||||||
|
|||||||
@@ -98,4 +98,5 @@ return [
|
|||||||
'Group Name Arr' => 'Group Name Arr',
|
'Group Name Arr' => 'Group Name Arr',
|
||||||
'Document file not found' => 'Document file not found',
|
'Document file not found' => 'Document file not found',
|
||||||
'Failed to read document' => 'Failed to read document',
|
'Failed to read document' => 'Failed to read document',
|
||||||
|
'Please select a parent agent' => 'Please select a parent agent, or ask an administrator for channel assignment permission',
|
||||||
];
|
];
|
||||||
@@ -117,4 +117,5 @@ return [
|
|||||||
'Group Name Arr' => '分组名称数组',
|
'Group Name Arr' => '分组名称数组',
|
||||||
'Document file not found' => '文档文件不存在',
|
'Document file not found' => '文档文件不存在',
|
||||||
'Failed to read document' => '读取文档失败',
|
'Failed to read document' => '读取文档失败',
|
||||||
|
'Please select a parent agent' => '请选择上级代理,或联系管理员开通渠道分配权限',
|
||||||
];
|
];
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
remoteUrl: '/admin/auth.Admin/index',
|
remoteUrl: '/admin/auth.Admin/index',
|
||||||
field: 'username',
|
field: 'username',
|
||||||
pk: 'id',
|
pk: 'id',
|
||||||
disabled: isTopLevelGroup,
|
disabled: isTopLevelGroup || !hasGroupSelected,
|
||||||
pagination: false,
|
pagination: false,
|
||||||
params: parentSelectParams,
|
params: parentSelectParams,
|
||||||
placeholder: t('auth.admin.Parent admin placeholder'),
|
placeholder: t('auth.admin.Parent admin placeholder'),
|
||||||
@@ -191,6 +191,8 @@ import FormItem from '/@/components/formItem/index.vue'
|
|||||||
import { useAdminInfo } from '/@/stores/adminInfo'
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
import { useConfig } from '/@/stores/config'
|
import { useConfig } from '/@/stores/config'
|
||||||
import createAxios from '/@/utils/axios'
|
import createAxios from '/@/utils/axios'
|
||||||
|
import { auth } from '/@/utils/common'
|
||||||
|
|
||||||
const config = useConfig()
|
const config = useConfig()
|
||||||
const adminInfo = useAdminInfo()
|
const adminInfo = useAdminInfo()
|
||||||
const formRef = useTemplateRef('formRef')
|
const formRef = useTemplateRef('formRef')
|
||||||
@@ -204,13 +206,32 @@ const isTopLevelGroup = ref(false)
|
|||||||
|
|
||||||
const isSelfEdit = computed(() => baTable.form.operate === 'Edit' && adminInfo.id == baTable.form.items?.id)
|
const isSelfEdit = computed(() => baTable.form.operate === 'Edit' && adminInfo.id == baTable.form.items?.id)
|
||||||
|
|
||||||
|
const hasChannelIndexAuth = computed(
|
||||||
|
() =>
|
||||||
|
adminInfo.super ||
|
||||||
|
auth({ name: '/admin/channel', subNodeName: '/admin/channel/index' }) ||
|
||||||
|
auth({ name: '/admin/Channel', subNodeName: '/admin/Channel/index' })
|
||||||
|
)
|
||||||
|
|
||||||
|
const hasGroupSelected = computed(() => {
|
||||||
|
const group = baTable.form.items?.group_arr
|
||||||
|
if (Array.isArray(group)) {
|
||||||
|
return group.length > 0
|
||||||
|
}
|
||||||
|
return group !== null && group !== undefined && group !== ''
|
||||||
|
})
|
||||||
|
|
||||||
const hasParentAdmin = computed(() => {
|
const hasParentAdmin = computed(() => {
|
||||||
const pid = baTable.form.items?.parent_admin_id
|
const pid = baTable.form.items?.parent_admin_id
|
||||||
return pid !== null && pid !== undefined && pid !== '' && Number(pid) > 0
|
return pid !== null && pid !== undefined && pid !== '' && Number(pid) > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
const showChannelEditable = computed(
|
const showChannelEditable = computed(
|
||||||
() => adminInfo.super && !hasParentAdmin.value && !isSelfEdit.value
|
() =>
|
||||||
|
hasGroupSelected.value &&
|
||||||
|
!hasParentAdmin.value &&
|
||||||
|
!isSelfEdit.value &&
|
||||||
|
(adminInfo.super || hasChannelIndexAuth.value)
|
||||||
)
|
)
|
||||||
|
|
||||||
const channelDisplayName = computed(() => {
|
const channelDisplayName = computed(() => {
|
||||||
@@ -224,14 +245,13 @@ const channelDisplayName = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const showChannelReadonly = computed(() => {
|
const showChannelReadonly = computed(() => {
|
||||||
if (isSelfEdit.value) return false
|
if (isSelfEdit.value || !hasGroupSelected.value) return false
|
||||||
if (showChannelEditable.value) return false
|
if (showChannelEditable.value) return false
|
||||||
if (hasParentAdmin.value) return true
|
if (hasParentAdmin.value) return true
|
||||||
if (!adminInfo.super && baTable.form.operate === 'Add') return true
|
|
||||||
return channelDisplayName.value !== ''
|
return channelDisplayName.value !== ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const showParentField = computed(() => adminInfo.super && !isSelfEdit.value)
|
const showParentField = computed(() => !isSelfEdit.value)
|
||||||
|
|
||||||
const hasChannelForShare = computed(() => {
|
const hasChannelForShare = computed(() => {
|
||||||
const cid = baTable.form.items?.channel_id
|
const cid = baTable.form.items?.channel_id
|
||||||
@@ -239,10 +259,8 @@ const hasChannelForShare = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const showShareRateField = computed(() => {
|
const showShareRateField = computed(() => {
|
||||||
if (isSelfEdit.value) return false
|
if (isSelfEdit.value || !hasGroupSelected.value) return false
|
||||||
if (!hasChannelForShare.value) return false
|
return hasChannelForShare.value
|
||||||
if (hasParentAdmin.value) return true
|
|
||||||
return true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const parentSelectParams = computed(() => {
|
const parentSelectParams = computed(() => {
|
||||||
@@ -310,8 +328,10 @@ const loadParentChannelMeta = async (parentId: unknown) => {
|
|||||||
const items = baTable.form.items
|
const items = baTable.form.items
|
||||||
if (!items) return
|
if (!items) return
|
||||||
if (parentId === null || parentId === undefined || parentId === '' || Number(parentId) <= 0) {
|
if (parentId === null || parentId === undefined || parentId === '' || Number(parentId) <= 0) {
|
||||||
if (showChannelEditable.value) {
|
|
||||||
items['channel_name'] = ''
|
items['channel_name'] = ''
|
||||||
|
if (baTable.form.operate === 'Add') {
|
||||||
|
items.channel_id = null
|
||||||
|
items.commission_share_rate = null
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -374,10 +394,7 @@ const loadShareRemainder = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let parentId = baTable.form.items?.parent_admin_id
|
const parentId = baTable.form.items?.parent_admin_id
|
||||||
if (!adminInfo.super) {
|
|
||||||
parentId = adminInfo.id
|
|
||||||
}
|
|
||||||
if (!parentId || Number(parentId) <= 0) {
|
if (!parentId || Number(parentId) <= 0) {
|
||||||
shareHint.value = ''
|
shareHint.value = ''
|
||||||
return
|
return
|
||||||
@@ -493,11 +510,13 @@ watch(isTopLevelGroup, (topLevel) => {
|
|||||||
watch(
|
watch(
|
||||||
() => baTable.form.operate,
|
() => baTable.form.operate,
|
||||||
(operate) => {
|
(operate) => {
|
||||||
if (operate !== 'Add' || adminInfo.super || !baTable.form.items) {
|
if (operate !== 'Add' || !baTable.form.items) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
baTable.form.items.parent_admin_id = adminInfo.id
|
baTable.form.items.parent_admin_id = null
|
||||||
void loadParentChannelMeta(adminInfo.id)
|
baTable.form.items.channel_id = null
|
||||||
|
baTable.form.items['channel_name'] = ''
|
||||||
|
baTable.form.items.commission_share_rate = null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user