游戏-用户管理-优化表格和表单样式
This commit is contained in:
@@ -32,6 +32,91 @@ class Channel extends Backend
|
|||||||
return null;
|
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 后端自动写入)
|
* 添加(重写:管理员只选顶级组;admin_group_id 后端自动写入)
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
|||||||
@@ -75,22 +75,19 @@
|
|||||||
prop="status"
|
prop="status"
|
||||||
:input-attr="{ content: { '0': t('game.user.status 0'), '1': t('game.user.status 1') } }"
|
:input-attr="{ content: { '0': t('game.user.status 0'), '1': t('game.user.status 1') } }"
|
||||||
/>
|
/>
|
||||||
<FormItem
|
<el-form-item :label="t('game.user.game_channel_id')" prop="admin_id">
|
||||||
:label="t('game.user.game_channel_id')"
|
<el-tree-select
|
||||||
type="remoteSelect"
|
v-model="baTable.form.items!.admin_id"
|
||||||
v-model="baTable.form.items!.game_channel_id"
|
class="w100"
|
||||||
prop="game_channel_id"
|
clearable
|
||||||
:input-attr="{ pk: 'game_channel.id', field: 'name', remoteUrl: '/admin/game.Channel/index' }"
|
filterable
|
||||||
:placeholder="t('Please select field', { field: t('game.user.game_channel_id') })"
|
:data="channelAdminTree"
|
||||||
/>
|
:props="treeProps"
|
||||||
<FormItem
|
:render-after-expand="false"
|
||||||
:label="t('game.user.admin_id')"
|
:placeholder="t('Please select field', { field: t('game.user.admin_id') })"
|
||||||
type="remoteSelect"
|
@change="onAdminTreeChange"
|
||||||
v-model="baTable.form.items!.admin_id"
|
/>
|
||||||
prop="admin_id"
|
</el-form-item>
|
||||||
:input-attr="{ pk: 'admin.id', field: 'username', remoteUrl: '/admin/auth.Admin/index' }"
|
|
||||||
:placeholder="t('Please select field', { field: t('game.user.admin_id') })"
|
|
||||||
/>
|
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
@@ -107,12 +104,13 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { FormItemRule } from 'element-plus'
|
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 { useI18n } from 'vue-i18n'
|
||||||
import FormItem from '/@/components/formItem/index.vue'
|
import FormItem from '/@/components/formItem/index.vue'
|
||||||
import { useConfig } from '/@/stores/config'
|
import { useConfig } from '/@/stores/config'
|
||||||
import type baTableClass from '/@/utils/baTable'
|
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 config = useConfig()
|
||||||
const formRef = useTemplateRef('formRef')
|
const formRef = useTemplateRef('formRef')
|
||||||
@@ -120,15 +118,92 @@ const baTable = inject('baTable') as baTableClass
|
|||||||
|
|
||||||
const { t } = useI18n()
|
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({
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
username: [buildValidatorData({ name: 'required', title: t('game.user.username') })],
|
username: [buildValidatorData({ name: 'required', title: t('game.user.username') })],
|
||||||
password: [
|
password: [{ validator: validatorGameUserPassword, trigger: 'blur' }],
|
||||||
buildValidatorData({ name: 'password', title: t('game.user.password') }),
|
|
||||||
buildValidatorData({ name: 'required', title: t('game.user.password') }),
|
|
||||||
],
|
|
||||||
phone: [buildValidatorData({ name: 'required', title: t('game.user.phone') })],
|
phone: [buildValidatorData({ name: 'required', title: t('game.user.phone') })],
|
||||||
coin: [buildValidatorData({ name: 'number', title: t('game.user.coin') })],
|
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') })],
|
admin_id: [buildValidatorData({ name: 'required', title: t('game.user.admin_id') })],
|
||||||
create_time: [buildValidatorData({ name: 'date', title: t('game.user.create_time') })],
|
create_time: [buildValidatorData({ name: 'date', title: t('game.user.create_time') })],
|
||||||
update_time: [buildValidatorData({ name: 'date', title: t('game.user.update_time') })],
|
update_time: [buildValidatorData({ name: 'date', title: t('game.user.update_time') })],
|
||||||
|
|||||||
Reference in New Issue
Block a user