游戏-用户管理-优化表格和表单样式
This commit is contained in:
@@ -32,6 +32,91 @@ class Channel extends Backend
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渠道-管理员树(父级=渠道,子级=管理员,仅可选择子级)
|
||||
*/
|
||||
public function adminTree(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
$channels = Db::name('game_channel')
|
||||
->field(['id', 'name', 'admin_group_id'])
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$groupChildrenCache = [];
|
||||
$getGroupChildren = function ($groupId) use (&$getGroupChildren, &$groupChildrenCache) {
|
||||
if ($groupId === null || $groupId === '') return [];
|
||||
if (array_key_exists($groupId, $groupChildrenCache)) return $groupChildrenCache[$groupId];
|
||||
$children = Db::name('admin_group')
|
||||
->where('pid', $groupId)
|
||||
->where('status', 1)
|
||||
->column('id');
|
||||
$all = [];
|
||||
foreach ($children as $cid) {
|
||||
$all[] = $cid;
|
||||
foreach ($getGroupChildren($cid) as $cc) {
|
||||
$all[] = $cc;
|
||||
}
|
||||
}
|
||||
$groupChildrenCache[$groupId] = $all;
|
||||
return $all;
|
||||
};
|
||||
|
||||
$tree = [];
|
||||
foreach ($channels as $ch) {
|
||||
$groupId = $ch['admin_group_id'] ?? null;
|
||||
$groupIds = [];
|
||||
if ($groupId !== null && $groupId !== '') {
|
||||
$groupIds[] = $groupId;
|
||||
foreach ($getGroupChildren($groupId) as $gid) {
|
||||
$groupIds[] = $gid;
|
||||
}
|
||||
}
|
||||
|
||||
$adminIds = [];
|
||||
if ($groupIds) {
|
||||
$adminIds = Db::name('admin_group_access')
|
||||
->where('group_id', 'in', array_unique($groupIds))
|
||||
->column('uid');
|
||||
}
|
||||
$adminIds = array_values(array_unique($adminIds));
|
||||
|
||||
$admins = [];
|
||||
if ($adminIds) {
|
||||
$admins = Db::name('admin')
|
||||
->field(['id', 'username'])
|
||||
->where('id', 'in', $adminIds)
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$children = [];
|
||||
foreach ($admins as $a) {
|
||||
$children[] = [
|
||||
'value' => (string) $a['id'],
|
||||
'label' => $a['username'],
|
||||
'channel_id' => $ch['id'],
|
||||
'is_leaf' => true,
|
||||
];
|
||||
}
|
||||
|
||||
$tree[] = [
|
||||
'value' => 'channel_' . $ch['id'],
|
||||
'label' => $ch['name'],
|
||||
'disabled' => true,
|
||||
'children' => $children,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $tree,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加(重写:管理员只选顶级组;admin_group_id 后端自动写入)
|
||||
* @throws Throwable
|
||||
|
||||
@@ -75,22 +75,19 @@
|
||||
prop="status"
|
||||
:input-attr="{ content: { '0': t('game.user.status 0'), '1': t('game.user.status 1') } }"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('game.user.game_channel_id')"
|
||||
type="remoteSelect"
|
||||
v-model="baTable.form.items!.game_channel_id"
|
||||
prop="game_channel_id"
|
||||
:input-attr="{ pk: 'game_channel.id', field: 'name', remoteUrl: '/admin/game.Channel/index' }"
|
||||
:placeholder="t('Please select field', { field: t('game.user.game_channel_id') })"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('game.user.admin_id')"
|
||||
type="remoteSelect"
|
||||
<el-form-item :label="t('game.user.game_channel_id')" prop="admin_id">
|
||||
<el-tree-select
|
||||
v-model="baTable.form.items!.admin_id"
|
||||
prop="admin_id"
|
||||
:input-attr="{ pk: 'admin.id', field: 'username', remoteUrl: '/admin/auth.Admin/index' }"
|
||||
class="w100"
|
||||
clearable
|
||||
filterable
|
||||
:data="channelAdminTree"
|
||||
:props="treeProps"
|
||||
:render-after-expand="false"
|
||||
:placeholder="t('Please select field', { field: t('game.user.admin_id') })"
|
||||
@change="onAdminTreeChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
@@ -107,12 +104,13 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { FormItemRule } from 'element-plus'
|
||||
import { inject, reactive, useTemplateRef } from 'vue'
|
||||
import { inject, onMounted, reactive, ref, useTemplateRef, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import FormItem from '/@/components/formItem/index.vue'
|
||||
import { useConfig } from '/@/stores/config'
|
||||
import type baTableClass from '/@/utils/baTable'
|
||||
import { buildValidatorData } from '/@/utils/validate'
|
||||
import { buildValidatorData, regularPassword } from '/@/utils/validate'
|
||||
import createAxios from '/@/utils/axios'
|
||||
|
||||
const config = useConfig()
|
||||
const formRef = useTemplateRef('formRef')
|
||||
@@ -120,15 +118,92 @@ const baTable = inject('baTable') as baTableClass
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
type TreeNode = {
|
||||
value: string
|
||||
label: string
|
||||
disabled?: boolean
|
||||
children?: TreeNode[]
|
||||
channel_id?: number
|
||||
is_leaf?: boolean
|
||||
}
|
||||
|
||||
const channelAdminTree = ref<TreeNode[]>([])
|
||||
const adminIdToChannelId = ref<Record<string, number>>({})
|
||||
|
||||
const treeProps = {
|
||||
value: 'value',
|
||||
label: 'label',
|
||||
children: 'children',
|
||||
disabled: 'disabled',
|
||||
}
|
||||
|
||||
const loadChannelAdminTree = async () => {
|
||||
const res = await createAxios({
|
||||
url: '/admin/game.Channel/adminTree',
|
||||
method: 'get',
|
||||
})
|
||||
const list = (res.data?.list ?? []) as TreeNode[]
|
||||
channelAdminTree.value = list
|
||||
|
||||
const map: Record<string, number> = {}
|
||||
const walk = (nodes: TreeNode[]) => {
|
||||
for (const n of nodes) {
|
||||
if (n.children && n.children.length) {
|
||||
walk(n.children)
|
||||
} else if (n.is_leaf && n.channel_id !== undefined) {
|
||||
map[n.value] = n.channel_id
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(list)
|
||||
adminIdToChannelId.value = map
|
||||
}
|
||||
|
||||
const onAdminTreeChange = (val: string | number | null) => {
|
||||
if (val === null || val === undefined || val === '') {
|
||||
return
|
||||
}
|
||||
const key = typeof val === 'number' ? String(val) : val
|
||||
const channelId = adminIdToChannelId.value[key]
|
||||
if (channelId !== undefined) {
|
||||
baTable.form.items!.game_channel_id = channelId
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadChannelAdminTree()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => baTable.form.items?.admin_id,
|
||||
(val) => {
|
||||
if (val === undefined || val === null || val === '') return
|
||||
onAdminTreeChange(val as any)
|
||||
}
|
||||
)
|
||||
|
||||
const validatorGameUserPassword = (rule: any, val: string, callback: (error?: Error) => void) => {
|
||||
const operate = baTable.form.operate
|
||||
const v = typeof val === 'string' ? val.trim() : ''
|
||||
|
||||
// 新增:必填
|
||||
if (operate === 'Add') {
|
||||
if (!v) return callback(new Error(t('Please input field', { field: t('game.user.password') })))
|
||||
if (!regularPassword(v)) return callback(new Error(t('validate.Please enter the correct password')))
|
||||
return callback()
|
||||
}
|
||||
|
||||
// 编辑:可空;非空则校验格式
|
||||
if (!v) return callback()
|
||||
if (!regularPassword(v)) return callback(new Error(t('validate.Please enter the correct password')))
|
||||
return callback()
|
||||
}
|
||||
|
||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||
username: [buildValidatorData({ name: 'required', title: t('game.user.username') })],
|
||||
password: [
|
||||
buildValidatorData({ name: 'password', title: t('game.user.password') }),
|
||||
buildValidatorData({ name: 'required', title: t('game.user.password') }),
|
||||
],
|
||||
password: [{ validator: validatorGameUserPassword, trigger: 'blur' }],
|
||||
phone: [buildValidatorData({ name: 'required', title: t('game.user.phone') })],
|
||||
coin: [buildValidatorData({ name: 'number', title: t('game.user.coin') })],
|
||||
game_channel_id: [buildValidatorData({ name: 'required', title: t('game.user.game_channel_id') })],
|
||||
admin_id: [buildValidatorData({ name: 'required', title: t('game.user.admin_id') })],
|
||||
create_time: [buildValidatorData({ name: 'date', title: t('game.user.create_time') })],
|
||||
update_time: [buildValidatorData({ name: 'date', title: t('game.user.update_time') })],
|
||||
|
||||
Reference in New Issue
Block a user