Compare commits
9 Commits
master
...
master-gam
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a1287d8ed | |||
| 2d14527da8 | |||
| 2e6e5105cf | |||
| 7fc9470f45 | |||
| 3438c711f0 | |||
| 2ee78b3239 | |||
| d8bcc4f4c4 | |||
| 165689bccf | |||
| 1d350ddb68 |
@@ -42,11 +42,23 @@ class Admin extends Backend
|
|||||||
}
|
}
|
||||||
|
|
||||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
$res = $this->model
|
$query = $this->model
|
||||||
->withoutField('login_failure,password,salt')
|
->withoutField('login_failure,password,salt')
|
||||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
->alias($alias)
|
->alias($alias)
|
||||||
->where($where)
|
->where($where);
|
||||||
|
|
||||||
|
// 仅返回“顶级角色组(pid=0)”下的管理员(用于远程下拉等场景)
|
||||||
|
$topGroup = $request->get('top_group') ?? $request->post('top_group');
|
||||||
|
if ($topGroup === '1' || $topGroup === 1 || $topGroup === true) {
|
||||||
|
$query = $query
|
||||||
|
->join('admin_group_access aga', $alias['admin'] . '.id = aga.uid')
|
||||||
|
->join('admin_group ag', 'aga.group_id = ag.id')
|
||||||
|
->where('ag.pid', 0)
|
||||||
|
->distinct(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $query
|
||||||
->order($order)
|
->order($order)
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
|
||||||
@@ -57,6 +69,76 @@ class Admin extends Backend
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 远程下拉(重写:支持 top_group=1 仅返回顶级组管理员)
|
||||||
|
*/
|
||||||
|
protected function _select(): Response
|
||||||
|
{
|
||||||
|
if (empty($this->model)) {
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => [],
|
||||||
|
'total' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
|
||||||
|
$fields = [$pk];
|
||||||
|
$quickSearchArr = is_array($this->quickSearchField) ? $this->quickSearchField : explode(',', (string) $this->quickSearchField);
|
||||||
|
foreach ($quickSearchArr as $f) {
|
||||||
|
$f = trim((string) $f);
|
||||||
|
if ($f === '') continue;
|
||||||
|
$f = str_contains($f, '.') ? substr($f, strrpos($f, '.') + 1) : $f;
|
||||||
|
if ($f !== '' && !in_array($f, $fields, true)) {
|
||||||
|
$fields[] = $f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
|
$modelTable = strtolower($this->model->getTable());
|
||||||
|
$mainAlias = ($alias[$modelTable] ?? $modelTable) . '.';
|
||||||
|
|
||||||
|
// 联表时避免字段歧义:主表字段统一 select 为 "admin.xxx as xxx"
|
||||||
|
$selectFields = [];
|
||||||
|
foreach ($fields as $f) {
|
||||||
|
$f = trim((string) $f);
|
||||||
|
if ($f === '') continue;
|
||||||
|
$selectFields[] = $mainAlias . $f . ' as ' . $f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 联表时避免排序字段歧义:无前缀的字段默认加主表前缀
|
||||||
|
$qualifiedOrder = [];
|
||||||
|
if (is_array($order)) {
|
||||||
|
foreach ($order as $k => $v) {
|
||||||
|
$k = (string) $k;
|
||||||
|
$qualifiedOrder[str_contains($k, '.') ? $k : ($mainAlias . $k)] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->model
|
||||||
|
->field($selectFields)
|
||||||
|
->alias($alias)
|
||||||
|
->where($where);
|
||||||
|
|
||||||
|
$topGroup = $this->request ? ($this->request->get('top_group') ?? $this->request->post('top_group')) : null;
|
||||||
|
if ($topGroup === '1' || $topGroup === 1 || $topGroup === true) {
|
||||||
|
$query = $query
|
||||||
|
->join('admin_group_access aga', $mainAlias . 'id = aga.uid')
|
||||||
|
->join('admin_group ag', 'aga.group_id = ag.id')
|
||||||
|
->where('ag.pid', 0)
|
||||||
|
->distinct(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $query
|
||||||
|
->order($qualifiedOrder ?: $order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function add(Request $request): Response
|
public function add(Request $request): Response
|
||||||
{
|
{
|
||||||
$response = $this->initializeBackend($request);
|
$response = $this->initializeBackend($request);
|
||||||
|
|||||||
303
app/admin/controller/game/Channel.php
Normal file
303
app/admin/controller/game/Channel.php
Normal file
@@ -0,0 +1,303 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\game;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
use app\common\controller\Backend;
|
||||||
|
use support\think\Db;
|
||||||
|
use support\Response;
|
||||||
|
use Webman\Http\Request as WebmanRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道管理
|
||||||
|
*/
|
||||||
|
class Channel extends Backend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* GameChannel模型对象
|
||||||
|
* @var object|null
|
||||||
|
* @phpstan-var \app\common\model\GameChannel|null
|
||||||
|
*/
|
||||||
|
protected ?object $model = null;
|
||||||
|
|
||||||
|
protected array|string $preExcludeFields = ['id', 'user_count', 'profit_amount', 'create_time', 'update_time'];
|
||||||
|
|
||||||
|
protected array $withJoinTable = ['adminGroup', 'admin'];
|
||||||
|
|
||||||
|
protected string|array $quickSearchField = ['id', 'code', 'name'];
|
||||||
|
|
||||||
|
protected function initController(WebmanRequest $request): ?Response
|
||||||
|
{
|
||||||
|
$this->model = new \app\common\model\GameChannel();
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
protected function _add(): Response
|
||||||
|
{
|
||||||
|
if ($this->request && $this->request->method() === 'POST') {
|
||||||
|
$data = $this->request->post();
|
||||||
|
if (!$data) {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->applyInputFilter($data);
|
||||||
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
|
$adminId = $data['admin_id'] ?? null;
|
||||||
|
if ($adminId === null || $adminId === '') {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['admin_id']));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不允许前端填写,统一后端根据管理员所属“顶级角色组(pid=0)”自动回填
|
||||||
|
if (array_key_exists('admin_group_id', $data)) {
|
||||||
|
unset($data['admin_group_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$topGroupId = Db::name('admin_group_access')
|
||||||
|
->alias('aga')
|
||||||
|
->join('admin_group ag', 'aga.group_id = ag.id')
|
||||||
|
->where('aga.uid', $adminId)
|
||||||
|
->where('ag.pid', 0)
|
||||||
|
->value('ag.id');
|
||||||
|
|
||||||
|
if ($topGroupId === null || $topGroupId === '') {
|
||||||
|
return $this->error(__('Record not found'));
|
||||||
|
}
|
||||||
|
$data['admin_group_id'] = $topGroupId;
|
||||||
|
|
||||||
|
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||||
|
$data[$this->dataLimitField] = $this->auth->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
$this->model->startTrans();
|
||||||
|
try {
|
||||||
|
if ($this->modelValidate) {
|
||||||
|
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||||
|
if (class_exists($validate)) {
|
||||||
|
$validate = new $validate();
|
||||||
|
if ($this->modelSceneValidate) {
|
||||||
|
$validate->scene('add');
|
||||||
|
}
|
||||||
|
$validate->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = $this->model->save($data);
|
||||||
|
$this->model->commit();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->model->rollback();
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($result !== false) {
|
||||||
|
return $this->success(__('Added successfully'));
|
||||||
|
}
|
||||||
|
return $this->error(__('No rows were added'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->error(__('Parameter error'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑(重写:管理员只选顶级组;admin_group_id 后端自动写入)
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _edit(): Response
|
||||||
|
{
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
$id = $this->request ? ($this->request->post($pk) ?? $this->request->get($pk)) : null;
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
if (!$row) {
|
||||||
|
return $this->error(__('Record not found'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$dataLimitAdminIds = $this->getDataLimitAdminIds();
|
||||||
|
if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
|
||||||
|
return $this->error(__('You have no permission'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request && $this->request->method() === 'POST') {
|
||||||
|
$data = $this->request->post();
|
||||||
|
if (!$data) {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->applyInputFilter($data);
|
||||||
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
|
// 不允许前端填写,统一后端根据管理员所属“顶级角色组(pid=0)”自动回填
|
||||||
|
if (array_key_exists('admin_group_id', $data)) {
|
||||||
|
unset($data['admin_group_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextAdminId = array_key_exists('admin_id', $data) ? $data['admin_id'] : ($row['admin_id'] ?? null);
|
||||||
|
if ($nextAdminId !== null && $nextAdminId !== '') {
|
||||||
|
$topGroupId = Db::name('admin_group_access')
|
||||||
|
->alias('aga')
|
||||||
|
->join('admin_group ag', 'aga.group_id = ag.id')
|
||||||
|
->where('aga.uid', $nextAdminId)
|
||||||
|
->where('ag.pid', 0)
|
||||||
|
->value('ag.id');
|
||||||
|
|
||||||
|
if ($topGroupId === null || $topGroupId === '') {
|
||||||
|
return $this->error(__('Record not found'));
|
||||||
|
}
|
||||||
|
$data['admin_group_id'] = $topGroupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
$this->model->startTrans();
|
||||||
|
try {
|
||||||
|
if ($this->modelValidate) {
|
||||||
|
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||||
|
if (class_exists($validate)) {
|
||||||
|
$validate = new $validate();
|
||||||
|
if ($this->modelSceneValidate) {
|
||||||
|
$validate->scene('edit');
|
||||||
|
}
|
||||||
|
$data[$pk] = $row[$pk];
|
||||||
|
$validate->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = $row->save($data);
|
||||||
|
$this->model->commit();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->model->rollback();
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($result !== false) {
|
||||||
|
return $this->success(__('Update successful'));
|
||||||
|
}
|
||||||
|
return $this->error(__('No rows updated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'row' => $row
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _index(): Response
|
||||||
|
{
|
||||||
|
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
||||||
|
if ($this->request && $this->request->get('select')) {
|
||||||
|
return $this->select($this->request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. withJoin 不可使用 alias 方法设置表别名,别名将自动使用关联模型名称(小写下划线命名规则)
|
||||||
|
* 2. 以下的别名设置了主表别名,同时便于拼接查询参数等
|
||||||
|
* 3. paginate 数据集可使用链式操作 each(function($item, $key) {}) 遍历处理
|
||||||
|
*/
|
||||||
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
|
$res = $this->model
|
||||||
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
|
->with($this->withJoinTable)
|
||||||
|
->visible(['adminGroup' => ['name'], 'admin' => ['username']])
|
||||||
|
->alias($alias)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
'remark' => get_route_remark(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
|
||||||
|
*/
|
||||||
|
}
|
||||||
213
app/admin/controller/game/User.php
Normal file
213
app/admin/controller/game/User.php
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\game;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
use app\common\controller\Backend;
|
||||||
|
use support\Response;
|
||||||
|
use Webman\Http\Request as WebmanRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户管理
|
||||||
|
*/
|
||||||
|
class User extends Backend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* GameUser模型对象
|
||||||
|
* @var object|null
|
||||||
|
* @phpstan-var \app\common\model\GameUser|null
|
||||||
|
*/
|
||||||
|
protected ?object $model = null;
|
||||||
|
|
||||||
|
protected array|string $preExcludeFields = ['id', 'uuid', 'create_time', 'update_time'];
|
||||||
|
|
||||||
|
protected array $withJoinTable = ['gameChannel', 'admin'];
|
||||||
|
|
||||||
|
protected string|array $quickSearchField = ['id', 'username', 'phone'];
|
||||||
|
|
||||||
|
protected function initController(WebmanRequest $request): ?Response
|
||||||
|
{
|
||||||
|
$this->model = new \app\common\model\GameUser();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加(重写:password 使用 Admin 同款加密;uuid 由 username+channel_id 生成)
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _add(): Response
|
||||||
|
{
|
||||||
|
if ($this->request && $this->request->method() === 'POST') {
|
||||||
|
$data = $this->request->post();
|
||||||
|
if (!$data) {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->applyInputFilter($data);
|
||||||
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
|
$password = $data['password'] ?? null;
|
||||||
|
if (!is_string($password) || trim($password) === '') {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['password']));
|
||||||
|
}
|
||||||
|
$data['password'] = hash_password($password);
|
||||||
|
|
||||||
|
$username = $data['username'] ?? '';
|
||||||
|
$channelId = $data['channel_id'] ?? ($data['game_channel_id'] ?? null);
|
||||||
|
if (!is_string($username) || trim($username) === '' || $channelId === null || $channelId === '') {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['username/channel_id']));
|
||||||
|
}
|
||||||
|
$data['uuid'] = md5(trim($username) . '|' . $channelId);
|
||||||
|
|
||||||
|
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||||
|
$data[$this->dataLimitField] = $this->auth->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
$this->model->startTrans();
|
||||||
|
try {
|
||||||
|
if ($this->modelValidate) {
|
||||||
|
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||||
|
if (class_exists($validate)) {
|
||||||
|
$validate = new $validate();
|
||||||
|
if ($this->modelSceneValidate) {
|
||||||
|
$validate->scene('add');
|
||||||
|
}
|
||||||
|
$validate->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = $this->model->save($data);
|
||||||
|
$this->model->commit();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->model->rollback();
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($result !== false) {
|
||||||
|
return $this->success(__('Added successfully'));
|
||||||
|
}
|
||||||
|
return $this->error(__('No rows were added'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->error(__('Parameter error'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑(重写:password 使用 Admin 同款加密;uuid 由 username+channel_id 生成)
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _edit(): Response
|
||||||
|
{
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
$id = $this->request ? ($this->request->post($pk) ?? $this->request->get($pk)) : null;
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
if (!$row) {
|
||||||
|
return $this->error(__('Record not found'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$dataLimitAdminIds = $this->getDataLimitAdminIds();
|
||||||
|
if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
|
||||||
|
return $this->error(__('You have no permission'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request && $this->request->method() === 'POST') {
|
||||||
|
$data = $this->request->post();
|
||||||
|
if (!$data) {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->applyInputFilter($data);
|
||||||
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
|
if (array_key_exists('password', $data)) {
|
||||||
|
$password = $data['password'];
|
||||||
|
if (!is_string($password) || trim($password) === '') {
|
||||||
|
unset($data['password']);
|
||||||
|
} else {
|
||||||
|
$data['password'] = hash_password($password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextUsername = array_key_exists('username', $data) ? $data['username'] : $row['username'];
|
||||||
|
$nextChannelId = null;
|
||||||
|
if (array_key_exists('channel_id', $data)) {
|
||||||
|
$nextChannelId = $data['channel_id'];
|
||||||
|
} elseif (array_key_exists('game_channel_id', $data)) {
|
||||||
|
$nextChannelId = $data['game_channel_id'];
|
||||||
|
} else {
|
||||||
|
$nextChannelId = $row['channel_id'] ?? $row['game_channel_id'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($nextUsername) && trim($nextUsername) !== '' && $nextChannelId !== null && $nextChannelId !== '') {
|
||||||
|
$data['uuid'] = md5(trim($nextUsername) . '|' . $nextChannelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
$this->model->startTrans();
|
||||||
|
try {
|
||||||
|
if ($this->modelValidate) {
|
||||||
|
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||||
|
if (class_exists($validate)) {
|
||||||
|
$validate = new $validate();
|
||||||
|
if ($this->modelSceneValidate) {
|
||||||
|
$validate->scene('edit');
|
||||||
|
}
|
||||||
|
$data[$pk] = $row[$pk];
|
||||||
|
$validate->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = $row->save($data);
|
||||||
|
$this->model->commit();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->model->rollback();
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($result !== false) {
|
||||||
|
return $this->success(__('Update successful'));
|
||||||
|
}
|
||||||
|
return $this->error(__('No rows updated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: 返回编辑数据时,剔除敏感字段
|
||||||
|
unset($row['password'], $row['salt'], $row['token'], $row['refresh_token']);
|
||||||
|
return $this->success('', [
|
||||||
|
'row' => $row
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _index(): Response
|
||||||
|
{
|
||||||
|
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
||||||
|
if ($this->request && $this->request->get('select')) {
|
||||||
|
return $this->select($this->request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. withJoin 不可使用 alias 方法设置表别名,别名将自动使用关联模型名称(小写下划线命名规则)
|
||||||
|
* 2. 以下的别名设置了主表别名,同时便于拼接查询参数等
|
||||||
|
* 3. paginate 数据集可使用链式操作 each(function($item, $key) {}) 遍历处理
|
||||||
|
*/
|
||||||
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
|
$res = $this->model
|
||||||
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
|
->with($this->withJoinTable)
|
||||||
|
->visible(['gameChannel' => ['name'], 'admin' => ['username']])
|
||||||
|
->alias($alias)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
'remark' => get_route_remark(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
|
||||||
|
*/
|
||||||
|
}
|
||||||
@@ -802,8 +802,8 @@ class Helper
|
|||||||
$indexVueData['defaultItems'] = self::getJsonFromArray($indexVueData['defaultItems'] ?? []);
|
$indexVueData['defaultItems'] = self::getJsonFromArray($indexVueData['defaultItems'] ?? []);
|
||||||
$indexVueData['tableColumn'] = self::buildTableColumn($indexVueData['tableColumn'] ?? []);
|
$indexVueData['tableColumn'] = self::buildTableColumn($indexVueData['tableColumn'] ?? []);
|
||||||
$indexVueData['dblClickNotEditColumn'] = self::buildSimpleArray($indexVueData['dblClickNotEditColumn'] ?? ['undefined']);
|
$indexVueData['dblClickNotEditColumn'] = self::buildSimpleArray($indexVueData['dblClickNotEditColumn'] ?? ['undefined']);
|
||||||
$controllerFile['path'][] = $controllerFile['originalLastName'];
|
$urlSegments = array_merge($controllerFile['path'], [$controllerFile['originalLastName']]);
|
||||||
$indexVueData['controllerUrl'] = '\'/admin/' . ($controllerFile['path'] ? implode('.', $controllerFile['path']) : '') . '/\'';
|
$indexVueData['controllerUrl'] = '\'/admin/' . ($urlSegments ? implode('.', array_map('strtolower', $urlSegments)) : '') . '/\'';
|
||||||
$indexVueData['componentName'] = ($webViewsDir['path'] ? implode('/', $webViewsDir['path']) . '/' : '') . $webViewsDir['originalLastName'];
|
$indexVueData['componentName'] = ($webViewsDir['path'] ? implode('/', $webViewsDir['path']) . '/' : '') . $webViewsDir['originalLastName'];
|
||||||
$indexVueContent = self::assembleStub('html/index', $indexVueData);
|
$indexVueContent = self::assembleStub('html/index', $indexVueData);
|
||||||
self::writeFile(root_path() . $webViewsDir['views'] . '/' . 'index.vue', $indexVueContent);
|
self::writeFile(root_path() . $webViewsDir['views'] . '/' . 'index.vue', $indexVueContent);
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\admin\validate\mall;
|
|
||||||
|
|
||||||
use think\Validate;
|
|
||||||
|
|
||||||
class Player extends Validate
|
|
||||||
{
|
|
||||||
protected $failException = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证规则
|
|
||||||
*/
|
|
||||||
protected $rule = [
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提示消息
|
|
||||||
*/
|
|
||||||
protected $message = [
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证场景
|
|
||||||
*/
|
|
||||||
protected $scene = [
|
|
||||||
'add' => [],
|
|
||||||
'edit' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -668,7 +668,7 @@ class Install extends Api
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取安装完成后的访问地址(根据请求来源区分 API 与前端开发模式)
|
* 获取安装完成后的访问地址(根据请求来源区分 API 与前端开发模式)
|
||||||
* - 通过 API 访问(8787):index.html#/admin、index.html#/
|
* - 通过 API 访问(8787):index#/admin、index#/(无 index 与 # 之间的斜杠)
|
||||||
* - 通过前端开发服务访问(1818):/#/admin、/#/
|
* - 通过前端开发服务访问(1818):/#/admin、/#/
|
||||||
*/
|
*/
|
||||||
public function accessUrls(Request $request): Response
|
public function accessUrls(Request $request): Response
|
||||||
@@ -680,7 +680,8 @@ class Install extends Api
|
|||||||
$port = substr($host, strrpos($host, ':') + 1);
|
$port = substr($host, strrpos($host, ':') + 1);
|
||||||
}
|
}
|
||||||
$scheme = $request->header('x-forwarded-proto', 'http');
|
$scheme = $request->header('x-forwarded-proto', 'http');
|
||||||
$base = rtrim($scheme . '://' . $host, '/');
|
$basePath = $request instanceof \support\Request ? $request->publicBasePath() : '';
|
||||||
|
$base = rtrim($scheme . '://' . $host, '/') . $basePath;
|
||||||
|
|
||||||
if ($port === '1818') {
|
if ($port === '1818') {
|
||||||
$adminUrl = $base . '/#/admin';
|
$adminUrl = $base . '/#/admin';
|
||||||
|
|||||||
@@ -142,9 +142,14 @@ class Backend extends Api
|
|||||||
|
|
||||||
if ($needLogin) {
|
if ($needLogin) {
|
||||||
if (!$this->auth->isLogin()) {
|
if (!$this->auth->isLogin()) {
|
||||||
|
if ($request->method() === 'GET' && !$this->expectsApiJsonResponse($request)) {
|
||||||
|
$location = $this->adminSpaLoginUrl($request);
|
||||||
|
return redirect($location);
|
||||||
|
}
|
||||||
|
// 必须使用 HTTP 200 返回 JSON:若用 HTTP 303,axios 会跟随重定向,拿不到 JSON,前端无法跳转登录
|
||||||
return $this->error(__('Please login first'), [
|
return $this->error(__('Please login first'), [
|
||||||
'type' => Auth::NEED_LOGIN,
|
'type' => Auth::NEED_LOGIN,
|
||||||
], 0, ['statusCode' => Auth::LOGIN_RESPONSE_CODE]);
|
], 0);
|
||||||
}
|
}
|
||||||
if ($needPermission) {
|
if ($needPermission) {
|
||||||
$controllerPath = $this->getControllerPath($request);
|
$controllerPath = $this->getControllerPath($request);
|
||||||
@@ -167,6 +172,37 @@ class Backend extends Api
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否应按 API 返回 JSON(前端 axios 会带 server: true;纯浏览器地址栏访问多为 HTML Accept)
|
||||||
|
*/
|
||||||
|
protected function expectsApiJsonResponse(WebmanRequest $request): bool
|
||||||
|
{
|
||||||
|
$server = $request->header('server', '');
|
||||||
|
if ($server === 'true' || $server === '1') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (strtolower($request->header('x-requested-with', '')) === 'xmlhttprequest') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$accept = strtolower($request->header('accept', ''));
|
||||||
|
if (str_contains($accept, 'application/json')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 浏览器地址栏/点击链接触发的主文档请求,优先 302 到前端登录(避免误判为 API)
|
||||||
|
if (strtolower((string) $request->header('sec-fetch-mode', '')) === 'navigate') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台 Vue 为 hash 路由时的登录页(相对路径,与 web/src/router 一致)
|
||||||
|
*/
|
||||||
|
protected function adminSpaLoginUrl(WebmanRequest $request): string
|
||||||
|
{
|
||||||
|
return '/#/admin/login';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子类可覆盖,用于初始化 model 等(替代原 initialize)
|
* 子类可覆盖,用于初始化 model 等(替代原 initialize)
|
||||||
* @return Response|null 需直接返回时返回 Response,否则 null
|
* @return Response|null 需直接返回时返回 Response,否则 null
|
||||||
|
|||||||
@@ -11,12 +11,15 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class TokenExpirationException extends Exception
|
class TokenExpirationException extends Exception
|
||||||
{
|
{
|
||||||
|
protected array $data = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected string $message = '',
|
string $message = '',
|
||||||
protected int $code = 409,
|
int $code = 409,
|
||||||
protected array $data = [],
|
array $data = [],
|
||||||
?\Throwable $previous = null
|
?\Throwable $previous = null
|
||||||
) {
|
) {
|
||||||
|
$this->data = $data;
|
||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
app/common/model/GameChannel.php
Normal file
39
app/common/model/GameChannel.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use support\think\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameChannel
|
||||||
|
*/
|
||||||
|
class GameChannel extends Model
|
||||||
|
{
|
||||||
|
// 表名
|
||||||
|
protected $name = 'game_channel';
|
||||||
|
|
||||||
|
// 自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
|
// 字段类型转换
|
||||||
|
protected $type = [
|
||||||
|
'create_time' => 'integer',
|
||||||
|
'update_time' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function getprofitAmountAttr($value): ?float
|
||||||
|
{
|
||||||
|
return is_null($value) ? null : (float)$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function adminGroup(): \think\model\relation\BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\admin\model\AdminGroup::class, 'admin_group_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function admin(): \think\model\relation\BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/common/model/GameUser.php
Normal file
39
app/common/model/GameUser.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use support\think\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameUser
|
||||||
|
*/
|
||||||
|
class GameUser extends Model
|
||||||
|
{
|
||||||
|
// 表名
|
||||||
|
protected $name = 'game_user';
|
||||||
|
|
||||||
|
// 自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
|
// 字段类型转换
|
||||||
|
protected $type = [
|
||||||
|
'create_time' => 'integer',
|
||||||
|
'update_time' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function getcoinAttr($value): ?float
|
||||||
|
{
|
||||||
|
return is_null($value) ? null : (float)$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function gameChannel(): \think\model\relation\BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\common\model\GameChannel::class, 'game_channel_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function admin(): \think\model\relation\BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\admin\model\Admin::class, 'admin_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace app\common\validate;
|
|||||||
|
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
class MallWalletRecord extends Validate
|
class GameChannel extends Validate
|
||||||
{
|
{
|
||||||
protected $failException = true;
|
protected $failException = true;
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ namespace app\common\validate;
|
|||||||
|
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
class MallItem extends Validate
|
class GameUser extends Validate
|
||||||
{
|
{
|
||||||
protected $failException = true;
|
protected $failException = true;
|
||||||
|
|
||||||
@@ -204,7 +204,24 @@ if (!function_exists('get_controller_path')) {
|
|||||||
if (count($parts) < 2) {
|
if (count($parts) < 2) {
|
||||||
return $parts[0] ?? null;
|
return $parts[0] ?? null;
|
||||||
}
|
}
|
||||||
return implode('/', array_slice($parts, 1, -1)) ?: $parts[1];
|
$segments = array_slice($parts, 1, -1);
|
||||||
|
if ($segments === []) {
|
||||||
|
return $parts[1] ?? null;
|
||||||
|
}
|
||||||
|
// ThinkPHP 风格段 game.Config -> game/config,与 $request->controller 解析结果一致(否则权限节点对不上)
|
||||||
|
$normalized = [];
|
||||||
|
foreach ($segments as $seg) {
|
||||||
|
if (str_contains($seg, '.')) {
|
||||||
|
$dotPos = strpos($seg, '.');
|
||||||
|
$mod = substr($seg, 0, $dotPos);
|
||||||
|
$ctrl = substr($seg, $dotPos + 1);
|
||||||
|
$normalized[] = strtolower($mod);
|
||||||
|
$normalized[] = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $ctrl));
|
||||||
|
} else {
|
||||||
|
$normalized[] = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $seg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return implode('/', $normalized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -245,6 +245,34 @@ Route::get('/admin/security/dataRecycleLog/index', [\app\admin\controller\securi
|
|||||||
Route::post('/admin/security/dataRecycleLog/restore', [\app\admin\controller\security\DataRecycleLog::class, 'restore']);
|
Route::post('/admin/security/dataRecycleLog/restore', [\app\admin\controller\security\DataRecycleLog::class, 'restore']);
|
||||||
Route::get('/admin/security/dataRecycleLog/info', [\app\admin\controller\security\DataRecycleLog::class, 'info']);
|
Route::get('/admin/security/dataRecycleLog/info', [\app\admin\controller\security\DataRecycleLog::class, 'info']);
|
||||||
|
|
||||||
|
// ==================== CRUD 生成的根级控制器(/admin/item/index 或 /admin/Item/index,无子目录、无点号) ====================
|
||||||
|
// 显式路由在上,此处作为兜底;与 /admin/module.controller/action 互补
|
||||||
|
Route::add(
|
||||||
|
['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'],
|
||||||
|
'/admin/{controller:[a-zA-Z][a-zA-Z0-9]*}/{action}',
|
||||||
|
function (\Webman\Http\Request $request, string $controller, string $action) {
|
||||||
|
$class = '\\app\\admin\\controller\\' . ucfirst(strtolower($controller));
|
||||||
|
if (!class_exists($class)) {
|
||||||
|
return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
if (!method_exists($class, $action)) {
|
||||||
|
return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
$request->controller = $class;
|
||||||
|
try {
|
||||||
|
$instance = new $class();
|
||||||
|
return $instance->$action($request);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return new Response(500, ['Content-Type' => 'application/json'], json_encode([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => $e->getMessage(),
|
||||||
|
'time' => time(),
|
||||||
|
'data' => null,
|
||||||
|
], JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// ==================== 兼容 ThinkPHP 风格 URL(module.Controller/action) ====================
|
// ==================== 兼容 ThinkPHP 风格 URL(module.Controller/action) ====================
|
||||||
// 前端使用 /admin/user.Rule/index 格式,需转换为控制器调用
|
// 前端使用 /admin/user.Rule/index 格式,需转换为控制器调用
|
||||||
Route::add(
|
Route::add(
|
||||||
|
|||||||
@@ -231,8 +231,17 @@ class InstallData extends AbstractMigration
|
|||||||
|
|
||||||
public function menuRule(): void
|
public function menuRule(): void
|
||||||
{
|
{
|
||||||
if (!$this->hasTable('menu_rule')) return;
|
// Install 迁移在已存在 admin_rule(旧版表名)时会跳过创建 menu_rule,此处需与之一致
|
||||||
$table = $this->table('menu_rule');
|
$ruleTable = null;
|
||||||
|
if ($this->hasTable('menu_rule')) {
|
||||||
|
$ruleTable = 'menu_rule';
|
||||||
|
} elseif ($this->hasTable('admin_rule')) {
|
||||||
|
$ruleTable = 'admin_rule';
|
||||||
|
}
|
||||||
|
if ($ruleTable === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$table = $this->table($ruleTable);
|
||||||
$rows = [
|
$rows = [
|
||||||
[
|
[
|
||||||
'id' => '1',
|
'id' => '1',
|
||||||
@@ -1155,7 +1164,7 @@ class InstallData extends AbstractMigration
|
|||||||
'createtime' => $this->nowTime,
|
'createtime' => $this->nowTime,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$exist = Db::name('menu_rule')->where('id', 1)->value('id');
|
$exist = Db::name($ruleTable)->where('id', 1)->value('id');
|
||||||
if (!$exist) {
|
if (!$exist) {
|
||||||
$table->insert($rows)->saveData();
|
$table->insert($rows)->saveData();
|
||||||
}
|
}
|
||||||
|
|||||||
867
database/webman-buildadmin-dafuweng_20260401171133_backup.sql
Normal file
867
database/webman-buildadmin-dafuweng_20260401171133_backup.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -13,11 +13,7 @@ if (!defined('BASE_PATH')) {
|
|||||||
require $baseDir . '/vendor/autoload.php';
|
require $baseDir . '/vendor/autoload.php';
|
||||||
|
|
||||||
if (class_exists('Dotenv\Dotenv') && is_file($baseDir . '/.env')) {
|
if (class_exists('Dotenv\Dotenv') && is_file($baseDir . '/.env')) {
|
||||||
if (method_exists('Dotenv\Dotenv', 'createUnsafeImmutable')) {
|
Dotenv\Dotenv::createMutable($baseDir)->load();
|
||||||
Dotenv\Dotenv::createUnsafeImmutable($baseDir)->load();
|
|
||||||
} else {
|
|
||||||
Dotenv\Dotenv::createMutable($baseDir)->load();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('env')) {
|
if (!function_exists('env')) {
|
||||||
|
|||||||
@@ -10,11 +10,8 @@ $baseDir = __DIR__;
|
|||||||
require $baseDir . '/vendor/autoload.php';
|
require $baseDir . '/vendor/autoload.php';
|
||||||
|
|
||||||
if (class_exists('Dotenv\Dotenv') && is_file($baseDir . '/.env')) {
|
if (class_exists('Dotenv\Dotenv') && is_file($baseDir . '/.env')) {
|
||||||
if (method_exists('Dotenv\Dotenv', 'createUnsafeImmutable')) {
|
// 必须用 Mutable:Webman Worker 已加载过时,Immutable 不会覆盖 $_ENV,会导致 Phinx 与 Db::name() 前缀/库名不一致
|
||||||
Dotenv\Dotenv::createUnsafeImmutable($baseDir)->load();
|
Dotenv\Dotenv::createMutable($baseDir)->load();
|
||||||
} else {
|
|
||||||
Dotenv\Dotenv::createMutable($baseDir)->load();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('env')) {
|
if (!function_exists('env')) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,147 +1,163 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" href="/install/favicon.ico" />
|
<link rel="icon" href="/install/favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>BuildAdmin-安装</title>
|
<title>BuildAdmin-安装</title>
|
||||||
<script>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
var urls = { adminUrl: '', frontUrl: '' };
|
var urls = { adminUrl: '', frontUrl: '' };
|
||||||
fetch('/api/install/accessUrls').then(function(r){return r.json();}).then(function(res){
|
fetch('/api/install/accessUrls').then(function(r){return r.json();}).then(function(res){
|
||||||
if (res && res.data) { urls.adminUrl = res.data.adminUrl || ''; urls.frontUrl = res.data.frontUrl || ''; }
|
if (res && res.data) { urls.adminUrl = res.data.adminUrl || ''; urls.frontUrl = res.data.frontUrl || ''; }
|
||||||
}).catch(function(){});
|
}).catch(function(){});
|
||||||
function ensureQuickPanel() {
|
function ensureQuickPanel() {
|
||||||
if (!urls.adminUrl && !urls.frontUrl) return;
|
if (!urls.adminUrl && !urls.frontUrl) return;
|
||||||
if (document.getElementById('__ba_install_quick_urls__')) return;
|
if (document.getElementById('__ba_install_quick_urls__')) return;
|
||||||
var wrap = document.createElement('div');
|
var wrap = document.createElement('div');
|
||||||
wrap.id = '__ba_install_quick_urls__';
|
wrap.id = '__ba_install_quick_urls__';
|
||||||
wrap.style.position = 'fixed';
|
wrap.style.position = 'fixed';
|
||||||
wrap.style.right = '16px';
|
wrap.style.right = '16px';
|
||||||
wrap.style.bottom = '16px';
|
wrap.style.bottom = '16px';
|
||||||
wrap.style.zIndex = '99999';
|
wrap.style.zIndex = '99999';
|
||||||
wrap.style.maxWidth = '560px';
|
wrap.style.maxWidth = '560px';
|
||||||
wrap.style.fontFamily = 'ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"';
|
wrap.style.fontFamily = 'ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji"';
|
||||||
wrap.innerHTML =
|
wrap.innerHTML =
|
||||||
'<div style="background:rgba(255,255,255,.96);border:1px solid rgba(0,0,0,.08);box-shadow:0 8px 24px rgba(0,0,0,.12);border-radius:12px;overflow:hidden">' +
|
'<div style="background:rgba(255,255,255,.96);border:1px solid rgba(0,0,0,.08);box-shadow:0 8px 24px rgba(0,0,0,.12);border-radius:12px;overflow:hidden">' +
|
||||||
'<div style="padding:10px 12px;border-bottom:1px solid rgba(0,0,0,.06);display:flex;gap:8px;align-items:center;justify-content:space-between">' +
|
'<div style="padding:10px 12px;border-bottom:1px solid rgba(0,0,0,.06);display:flex;gap:8px;align-items:center;justify-content:space-between">' +
|
||||||
'<div style="font-weight:600;color:#111">安装完成快捷入口</div>' +
|
'<div style="font-weight:600;color:#111">安装完成快捷入口</div>' +
|
||||||
'<button type="button" aria-label="close" style="border:0;background:transparent;cursor:pointer;font-size:16px;line-height:16px;color:#666;padding:4px 6px">×</button>' +
|
'<button type="button" aria-label="close" style="border:0;background:transparent;cursor:pointer;font-size:16px;line-height:16px;color:#666;padding:4px 6px">×</button>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<div style="padding:12px;display:flex;flex-direction:column;gap:10px">' +
|
'<div style="padding:12px;display:flex;flex-direction:column;gap:10px">' +
|
||||||
'<div>' +
|
'<div>' +
|
||||||
'<div style="font-size:12px;color:#666;margin-bottom:6px">后台地址</div>' +
|
'<div style="font-size:12px;color:#666;margin-bottom:6px">后台地址</div>' +
|
||||||
'<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">' +
|
'<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">' +
|
||||||
'<a data-k="admin" target="_blank" rel="noreferrer" style="color:#1677ff;text-decoration:none;word-break:break-all"></a>' +
|
'<a data-k="admin" target="_blank" rel="noreferrer" style="color:#1677ff;text-decoration:none;word-break:break-all"></a>' +
|
||||||
'<button data-copy="admin" type="button" style="border:1px solid rgba(0,0,0,.12);background:#fff;border-radius:8px;padding:6px 10px;cursor:pointer">复制</button>' +
|
'<button data-copy="admin" type="button" style="border:1px solid rgba(0,0,0,.12);background:#fff;border-radius:8px;padding:6px 10px;cursor:pointer">复制</button>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<div>' +
|
'<div>' +
|
||||||
'<div style="font-size:12px;color:#666;margin-bottom:6px">前台地址</div>' +
|
'<div style="font-size:12px;color:#666;margin-bottom:6px">前台地址</div>' +
|
||||||
'<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">' +
|
'<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">' +
|
||||||
'<a data-k="front" target="_blank" rel="noreferrer" style="color:#1677ff;text-decoration:none;word-break:break-all"></a>' +
|
'<a data-k="front" target="_blank" rel="noreferrer" style="color:#1677ff;text-decoration:none;word-break:break-all"></a>' +
|
||||||
'<button data-copy="front" type="button" style="border:1px solid rgba(0,0,0,.12);background:#fff;border-radius:8px;padding:6px 10px;cursor:pointer">复制</button>' +
|
'<button data-copy="front" type="button" style="border:1px solid rgba(0,0,0,.12);background:#fff;border-radius:8px;padding:6px 10px;cursor:pointer">复制</button>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<div data-msg style="font-size:12px;color:#52c41a;min-height:16px"></div>' +
|
'<div data-msg style="font-size:12px;color:#52c41a;min-height:16px"></div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
document.body.appendChild(wrap);
|
document.body.appendChild(wrap);
|
||||||
|
|
||||||
var closeBtn = wrap.querySelector('button[aria-label="close"]');
|
var closeBtn = wrap.querySelector('button[aria-label="close"]');
|
||||||
if (closeBtn) closeBtn.addEventListener('click', function(){ wrap.remove(); });
|
if (closeBtn) closeBtn.addEventListener('click', function(){ wrap.remove(); });
|
||||||
|
|
||||||
function setLink(which, val) {
|
function setLink(which, val) {
|
||||||
var a = wrap.querySelector('a[data-k="' + which + '"]');
|
var a = wrap.querySelector('a[data-k="' + which + '"]');
|
||||||
if (!a) return;
|
if (!a) return;
|
||||||
a.textContent = val || '';
|
a.textContent = val || '';
|
||||||
a.href = val || 'javascript:void(0)';
|
a.href = val || 'javascript:void(0)';
|
||||||
}
|
|
||||||
setLink('admin', urls.adminUrl);
|
|
||||||
setLink('front', urls.frontUrl);
|
|
||||||
|
|
||||||
function showMsg(text, ok) {
|
|
||||||
var el = wrap.querySelector('[data-msg]');
|
|
||||||
if (!el) return;
|
|
||||||
el.style.color = ok ? '#52c41a' : '#ff4d4f';
|
|
||||||
el.textContent = text;
|
|
||||||
window.clearTimeout(el.__t);
|
|
||||||
el.__t = window.setTimeout(function(){ el.textContent = ''; }, 1800);
|
|
||||||
}
|
|
||||||
function copyText(text) {
|
|
||||||
if (!text) return Promise.reject(new Error('empty'));
|
|
||||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
||||||
return navigator.clipboard.writeText(text);
|
|
||||||
}
|
|
||||||
return new Promise(function(resolve, reject){
|
|
||||||
try {
|
|
||||||
var ta = document.createElement('textarea');
|
|
||||||
ta.value = text;
|
|
||||||
ta.setAttribute('readonly', 'readonly');
|
|
||||||
ta.style.position = 'fixed';
|
|
||||||
ta.style.left = '-9999px';
|
|
||||||
document.body.appendChild(ta);
|
|
||||||
ta.select();
|
|
||||||
var ok = document.execCommand('copy');
|
|
||||||
document.body.removeChild(ta);
|
|
||||||
ok ? resolve() : reject(new Error('copy failed'));
|
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
}
|
||||||
});
|
setLink('admin', urls.adminUrl);
|
||||||
|
setLink('front', urls.frontUrl);
|
||||||
|
|
||||||
|
function showMsg(text, ok) {
|
||||||
|
var el = wrap.querySelector('[data-msg]');
|
||||||
|
if (!el) return;
|
||||||
|
el.style.color = ok ? '#52c41a' : '#ff4d4f';
|
||||||
|
el.textContent = text;
|
||||||
|
window.clearTimeout(el.__t);
|
||||||
|
el.__t = window.setTimeout(function(){ el.textContent = ''; }, 1800);
|
||||||
|
}
|
||||||
|
function copyText(text) {
|
||||||
|
if (!text) return Promise.reject(new Error('empty'));
|
||||||
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||||
|
return navigator.clipboard.writeText(text);
|
||||||
|
}
|
||||||
|
return new Promise(function(resolve, reject){
|
||||||
|
try {
|
||||||
|
var ta = document.createElement('textarea');
|
||||||
|
ta.value = text;
|
||||||
|
ta.setAttribute('readonly', 'readonly');
|
||||||
|
ta.style.position = 'fixed';
|
||||||
|
ta.style.left = '-9999px';
|
||||||
|
document.body.appendChild(ta);
|
||||||
|
ta.select();
|
||||||
|
var ok = document.execCommand('copy');
|
||||||
|
document.body.removeChild(ta);
|
||||||
|
ok ? resolve() : reject(new Error('copy failed'));
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
wrap.addEventListener('click', function(e){
|
||||||
|
var t = e.target;
|
||||||
|
if (!t || !t.getAttribute) return;
|
||||||
|
var which = t.getAttribute('data-copy');
|
||||||
|
if (!which) return;
|
||||||
|
var text = which === 'admin' ? urls.adminUrl : urls.frontUrl;
|
||||||
|
copyText(text).then(function(){
|
||||||
|
showMsg('已复制:' + text, true);
|
||||||
|
}).catch(function(){
|
||||||
|
showMsg('复制失败,请手动复制', false);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
wrap.addEventListener('click', function(e){
|
function applyUrls() {
|
||||||
var t = e.target;
|
if (!urls.adminUrl && !urls.frontUrl) return;
|
||||||
if (!t || !t.getAttribute) return;
|
document.querySelectorAll('input[type="text"], input:not([type])').forEach(function(inp){
|
||||||
var which = t.getAttribute('data-copy');
|
var v = (inp.value || '').trim();
|
||||||
if (!which) return;
|
if (v && (v.indexOf('#/admin') >= 0 || v.indexOf('index.html') >= 0 || v.indexOf('/index#') >= 0) && v.indexOf('#/') >= 0) {
|
||||||
var text = which === 'admin' ? urls.adminUrl : urls.frontUrl;
|
inp.value = urls.adminUrl;
|
||||||
copyText(text).then(function(){
|
inp.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
showMsg('已复制:' + text, true);
|
}
|
||||||
}).catch(function(){
|
});
|
||||||
showMsg('复制失败,请手动复制', false);
|
document.querySelectorAll('a[href*="#/admin"]').forEach(function(a){ if (urls.adminUrl) a.href = urls.adminUrl; });
|
||||||
});
|
document.querySelectorAll('a[href*="#/"]').forEach(function(a){
|
||||||
});
|
if (urls.frontUrl && a.href.indexOf('#/admin') < 0) a.href = urls.frontUrl;
|
||||||
}
|
});
|
||||||
function applyUrls() {
|
// index.html/#/ 会被当成路径 /index.html/ 导致 webman 404,统一为 index.html#/
|
||||||
if (!urls.adminUrl && !urls.frontUrl) return;
|
document.querySelectorAll('a[href*="index.html/#"]').forEach(function(a){
|
||||||
document.querySelectorAll('input[type="text"], input:not([type])').forEach(function(inp){
|
a.href = a.href.replace(/index\.html\/#\//g, 'index.html#/');
|
||||||
var v = (inp.value || '').trim();
|
});
|
||||||
if (v && (v.indexOf('#/admin') >= 0 || v.indexOf('index.html') >= 0) && v.indexOf('#/') >= 0) {
|
// 打包的 index.js 完成页用 protocol+host 拼 adminUrl,会漏掉 /index.php 等前缀;用接口结果覆盖展示与点击
|
||||||
inp.value = urls.adminUrl;
|
if (urls.adminUrl) {
|
||||||
inp.dispatchEvent(new Event('input', { bubbles: true }));
|
document.querySelectorAll('.admin-url').forEach(function(el){
|
||||||
}
|
el.textContent = urls.adminUrl;
|
||||||
});
|
el.style.cursor = 'pointer';
|
||||||
document.querySelectorAll('a[href*="#/admin"]').forEach(function(a){ if (urls.adminUrl) a.href = urls.adminUrl; });
|
el.onclick = function(ev){
|
||||||
document.querySelectorAll('a[href*="#/"]').forEach(function(a){
|
ev.preventDefault();
|
||||||
if (urls.frontUrl && a.href.indexOf('#/admin') < 0) a.href = urls.frontUrl;
|
ev.stopPropagation();
|
||||||
});
|
window.open(urls.adminUrl, '_blank', 'noreferrer');
|
||||||
ensureQuickPanel();
|
};
|
||||||
}
|
});
|
||||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function(){ setInterval(applyUrls, 800); });
|
}
|
||||||
else setInterval(applyUrls, 800);
|
ensureQuickPanel();
|
||||||
|
}
|
||||||
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function(){ setInterval(applyUrls, 800); });
|
||||||
|
else setInterval(applyUrls, 800);
|
||||||
})();
|
})();
|
||||||
(function(){
|
(function(){
|
||||||
function closeMigrateModal() {
|
function closeMigrateModal() {
|
||||||
if (!document.body) return;
|
if (!document.body) return;
|
||||||
var txt = document.body.innerText || document.body.textContent || '';
|
var txt = document.body.innerText || document.body.textContent || '';
|
||||||
if (txt.indexOf('数据表迁移失败') < 0 && txt.indexOf('数据表自动迁移失败') < 0) return;
|
if (txt.indexOf('数据表迁移失败') < 0 && txt.indexOf('数据表自动迁移失败') < 0) return;
|
||||||
var btns = document.body.querySelectorAll('button, [role="button"], .el-button');
|
var btns = document.body.querySelectorAll('button, [role="button"], .el-button');
|
||||||
for (var i = 0; i < btns.length; i++) {
|
for (var i = 0; i < btns.length; i++) {
|
||||||
var b = btns[i];
|
var b = btns[i];
|
||||||
if (b.textContent && b.textContent.indexOf('继续安装') >= 0) { b.click(); return; }
|
if (b.textContent && b.textContent.indexOf('继续安装') >= 0) { b.click(); return; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
var obs = new MutationObserver(closeMigrateModal);
|
||||||
var obs = new MutationObserver(closeMigrateModal);
|
function start() { if (document.body) { obs.observe(document.body, { childList: true, subtree: true }); closeMigrateModal(); } }
|
||||||
function start() { if (document.body) { obs.observe(document.body, { childList: true, subtree: true }); closeMigrateModal(); } }
|
if (document.body) start(); else document.addEventListener('DOMContentLoaded', start);
|
||||||
if (document.body) start(); else document.addEventListener('DOMContentLoaded', start);
|
setInterval(closeMigrateModal, 150);
|
||||||
setInterval(closeMigrateModal, 150);
|
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
<script type="module" crossorigin src="/install/assets/index.js"></script>
|
<script type="module" crossorigin src="/install/assets/index.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/install/assets/index.css">
|
<link rel="stylesheet" crossorigin href="/install/assets/index.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -35,6 +35,18 @@ class Request extends \Webman\Http\Request
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入口为 /index.php/... 时返回 /index.php,用于拼接后台/前台完整 URL(与路由 path() 剥离规则对应)
|
||||||
|
*/
|
||||||
|
public function publicBasePath(): string
|
||||||
|
{
|
||||||
|
$path = parent::path();
|
||||||
|
if (str_starts_with($path, '/index.php')) {
|
||||||
|
return '/index.php';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求参数(兼容 ThinkPHP param,合并 get/post,post 优先)
|
* 获取请求参数(兼容 ThinkPHP param,合并 get/post,post 优先)
|
||||||
* @param string|null $name 参数名,null 返回全部
|
* @param string|null $name 参数名,null 返回全部
|
||||||
|
|||||||
18
web/src/lang/backend/en/game/channel.ts
Normal file
18
web/src/lang/backend/en/game/channel.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
export default {
|
||||||
|
id: 'id',
|
||||||
|
code: 'code',
|
||||||
|
name: 'name',
|
||||||
|
user_count: 'user_count',
|
||||||
|
profit_amount: 'profit_amount',
|
||||||
|
status: 'status',
|
||||||
|
'status 0': 'status 0',
|
||||||
|
'status 1': 'status 1',
|
||||||
|
remark: 'remark',
|
||||||
|
admin_group_id: 'admin_group_id',
|
||||||
|
admingroup__name: 'name',
|
||||||
|
admin_id: 'admin_id',
|
||||||
|
admin__username: 'username',
|
||||||
|
create_time: 'create_time',
|
||||||
|
update_time: 'update_time',
|
||||||
|
'quick Search Fields': 'id,code,name',
|
||||||
|
}
|
||||||
19
web/src/lang/backend/en/game/user.ts
Normal file
19
web/src/lang/backend/en/game/user.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export default {
|
||||||
|
id: 'id',
|
||||||
|
username: 'username',
|
||||||
|
password: 'password',
|
||||||
|
uuid: 'uuid',
|
||||||
|
phone: 'phone',
|
||||||
|
remark: 'remark',
|
||||||
|
coin: 'coin',
|
||||||
|
status: 'status',
|
||||||
|
'status 0': 'status 0',
|
||||||
|
'status 1': 'status 1',
|
||||||
|
game_channel_id: 'game_channel_id',
|
||||||
|
gamechannel__name: 'name',
|
||||||
|
admin_id: 'admin_id',
|
||||||
|
admin__username: 'username',
|
||||||
|
create_time: 'create_time',
|
||||||
|
update_time: 'update_time',
|
||||||
|
'quick Search Fields': 'id,username,phone',
|
||||||
|
}
|
||||||
18
web/src/lang/backend/zh-cn/game/channel.ts
Normal file
18
web/src/lang/backend/zh-cn/game/channel.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
export default {
|
||||||
|
id: 'ID',
|
||||||
|
code: '渠道标识',
|
||||||
|
name: '渠道名',
|
||||||
|
user_count: '用户数',
|
||||||
|
profit_amount: '利润',
|
||||||
|
status: '状态',
|
||||||
|
'status 0': '禁用',
|
||||||
|
'status 1': '启用',
|
||||||
|
remark: '备注',
|
||||||
|
admin_group_id: '管理角色组',
|
||||||
|
admingroup__name: '组名',
|
||||||
|
admin_id: '管理员',
|
||||||
|
admin__username: '用户名',
|
||||||
|
create_time: '创建时间',
|
||||||
|
update_time: '修改时间',
|
||||||
|
'quick Search Fields': 'ID、渠道标识、渠道名',
|
||||||
|
}
|
||||||
19
web/src/lang/backend/zh-cn/game/user.ts
Normal file
19
web/src/lang/backend/zh-cn/game/user.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export default {
|
||||||
|
id: 'ID',
|
||||||
|
username: '用户名',
|
||||||
|
password: '密码',
|
||||||
|
uuid: '用户唯一标识',
|
||||||
|
phone: '手机号',
|
||||||
|
remark: '备注',
|
||||||
|
coin: '平台币',
|
||||||
|
status: '状态',
|
||||||
|
'status 0': '禁用',
|
||||||
|
'status 1': '启用',
|
||||||
|
game_channel_id: '所属渠道',
|
||||||
|
gamechannel__name: '渠道名',
|
||||||
|
admin_id: '所属管理员',
|
||||||
|
admin__username: '用户名',
|
||||||
|
create_time: '创建时间',
|
||||||
|
update_time: '修改时间',
|
||||||
|
'quick Search Fields': 'ID、用户名、手机号',
|
||||||
|
}
|
||||||
@@ -100,6 +100,16 @@ export const useTerminal = defineStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addTask(command: string, blockOnFailure = true, extend = '', callback: Function = () => {}) {
|
function addTask(command: string, blockOnFailure = true, extend = '', callback: Function = () => {}) {
|
||||||
|
const duplicatePending = state.taskList.some(
|
||||||
|
(item) =>
|
||||||
|
item.command === command &&
|
||||||
|
(item.status === taskStatus.Waiting ||
|
||||||
|
item.status === taskStatus.Connecting ||
|
||||||
|
item.status === taskStatus.Executing)
|
||||||
|
)
|
||||||
|
if (duplicatePending) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!state.show) toggleDot(true)
|
if (!state.show) toggleDot(true)
|
||||||
state.taskList = state.taskList.concat({
|
state.taskList = state.taskList.concat({
|
||||||
uuid: uuid(),
|
uuid: uuid(),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { AxiosRequestConfig, Method } from 'axios'
|
import type { AxiosRequestConfig, Method } from 'axios'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { ElLoading, ElNotification, type LoadingOptions } from 'element-plus'
|
import { ElLoading, ElNotification, type LoadingOptions } from 'element-plus'
|
||||||
|
import { nextTick } from 'vue'
|
||||||
import { refreshToken } from '/@/api/common'
|
import { refreshToken } from '/@/api/common'
|
||||||
import { i18n } from '/@/lang/index'
|
import { i18n } from '/@/lang/index'
|
||||||
import router from '/@/router/index'
|
import router from '/@/router/index'
|
||||||
@@ -20,6 +21,12 @@ const loadingInstance: LoadingInstance = {
|
|||||||
count: 0,
|
count: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 请求是否后台 /admin/ 接口(不依赖当前路由,避免 loading 等场景误判为前台) */
|
||||||
|
function isAdminBackendRequest(config: AxiosRequestConfig): boolean {
|
||||||
|
const u = `${config.baseURL ?? ''}${config.url ?? ''}`
|
||||||
|
return /\/admin\//i.test(u)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据运行环境获取基础请求URL
|
* 根据运行环境获取基础请求URL
|
||||||
*/
|
*/
|
||||||
@@ -112,6 +119,22 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
|
|||||||
|
|
||||||
if (response.config.responseType == 'json') {
|
if (response.config.responseType == 'json') {
|
||||||
if (response.data && response.data.code !== 1) {
|
if (response.data && response.data.code !== 1) {
|
||||||
|
const needLogin = response.data.data && typeof response.data.data === 'object' && response.data.data.type === 'need login'
|
||||||
|
if (needLogin) {
|
||||||
|
const isAdminAppFlag = isAdminApp() || isAdminBackendRequest(response.config)
|
||||||
|
if (isAdminAppFlag) {
|
||||||
|
adminInfo.removeToken()
|
||||||
|
} else {
|
||||||
|
userInfo.removeToken()
|
||||||
|
}
|
||||||
|
const loginRouteName = isAdminAppFlag ? 'adminLogin' : 'userLogin'
|
||||||
|
if (router.currentRoute.value.name !== loginRouteName) {
|
||||||
|
nextTick(() => {
|
||||||
|
void router.replace({ name: loginRouteName })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Promise.reject(response.data)
|
||||||
|
}
|
||||||
if (response.data.code == 409) {
|
if (response.data.code == 409) {
|
||||||
if (!window.tokenRefreshing) {
|
if (!window.tokenRefreshing) {
|
||||||
window.tokenRefreshing = true
|
window.tokenRefreshing = true
|
||||||
|
|||||||
140
web/src/views/backend/game/channel/index.vue
Normal file
140
web/src/views/backend/game/channel/index.vue
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<template>
|
||||||
|
<div class="default-main ba-table-box">
|
||||||
|
<el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
|
||||||
|
|
||||||
|
<!-- 表格顶部菜单 -->
|
||||||
|
<!-- 自定义按钮请使用插槽,甚至公共搜索也可以使用具名插槽渲染,参见文档 -->
|
||||||
|
<TableHeader
|
||||||
|
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
|
||||||
|
:quick-search-placeholder="t('Quick search placeholder', { fields: t('game.channel.quick Search Fields') })"
|
||||||
|
></TableHeader>
|
||||||
|
|
||||||
|
<!-- 表格 -->
|
||||||
|
<!-- 表格列有多种自定义渲染方式,比如自定义组件、具名插槽等,参见文档 -->
|
||||||
|
<!-- 要使用 el-table 组件原有的属性,直接加在 Table 标签上即可 -->
|
||||||
|
<Table ref="tableRef"></Table>
|
||||||
|
|
||||||
|
<!-- 表单 -->
|
||||||
|
<PopupForm />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, provide, useTemplateRef } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import PopupForm from './popupForm.vue'
|
||||||
|
import { baTableApi } from '/@/api/common'
|
||||||
|
import { defaultOptButtons } from '/@/components/table'
|
||||||
|
import TableHeader from '/@/components/table/header/index.vue'
|
||||||
|
import Table from '/@/components/table/index.vue'
|
||||||
|
import baTableClass from '/@/utils/baTable'
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'game/channel',
|
||||||
|
})
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const tableRef = useTemplateRef('tableRef')
|
||||||
|
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
||||||
|
*/
|
||||||
|
const baTable = new baTableClass(
|
||||||
|
new baTableApi('/admin/game.Channel/'),
|
||||||
|
{
|
||||||
|
pk: 'id',
|
||||||
|
column: [
|
||||||
|
{ type: 'selection', align: 'center', operator: false },
|
||||||
|
{ label: t('game.channel.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
||||||
|
{
|
||||||
|
label: t('game.channel.code'),
|
||||||
|
prop: 'code',
|
||||||
|
align: 'center',
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.channel.name'),
|
||||||
|
prop: 'name',
|
||||||
|
align: 'center',
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{ label: t('game.channel.user_count'), prop: 'user_count', align: 'center', sortable: false, operator: 'RANGE' },
|
||||||
|
{ label: t('game.channel.profit_amount'), prop: 'profit_amount', align: 'center', sortable: false, operator: 'RANGE' },
|
||||||
|
{
|
||||||
|
label: t('game.channel.status'),
|
||||||
|
prop: 'status',
|
||||||
|
align: 'center',
|
||||||
|
operator: 'eq',
|
||||||
|
sortable: false,
|
||||||
|
render: 'switch',
|
||||||
|
replaceValue: { '0': t('game.channel.status 0'), '1': t('game.channel.status 1') },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.channel.admingroup__name'),
|
||||||
|
prop: 'adminGroup.name',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 110,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tags',
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.channel.admin__username'),
|
||||||
|
prop: 'admin.username',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 90,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tags',
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.channel.create_time'),
|
||||||
|
prop: 'create_time',
|
||||||
|
align: 'center',
|
||||||
|
render: 'datetime',
|
||||||
|
operator: 'RANGE',
|
||||||
|
comSearchRender: 'datetime',
|
||||||
|
sortable: 'custom',
|
||||||
|
width: 160,
|
||||||
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.channel.update_time'),
|
||||||
|
prop: 'update_time',
|
||||||
|
align: 'center',
|
||||||
|
render: 'datetime',
|
||||||
|
operator: 'RANGE',
|
||||||
|
comSearchRender: 'datetime',
|
||||||
|
sortable: 'custom',
|
||||||
|
width: 160,
|
||||||
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
|
},
|
||||||
|
{ label: t('Operate'), align: 'center', width: 80, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right' },
|
||||||
|
],
|
||||||
|
dblClickNotEditColumn: [undefined, 'status'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultItems: { status: '1' },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
provide('baTable', baTable)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
baTable.table.ref = tableRef.value
|
||||||
|
baTable.mount()
|
||||||
|
baTable.getData()?.then(() => {
|
||||||
|
baTable.initSort()
|
||||||
|
baTable.dragSort()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss"></style>
|
||||||
111
web/src/views/backend/game/channel/popupForm.vue
Normal file
111
web/src/views/backend/game/channel/popupForm.vue
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 对话框表单 -->
|
||||||
|
<!-- 建议使用 Prettier 格式化代码 -->
|
||||||
|
<!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
|
||||||
|
<el-dialog
|
||||||
|
class="ba-operate-dialog"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
|
||||||
|
@close="baTable.toggleForm"
|
||||||
|
>
|
||||||
|
<template #header>
|
||||||
|
<div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
|
||||||
|
{{ baTable.form.operate ? t(baTable.form.operate) : '' }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
|
||||||
|
<div
|
||||||
|
class="ba-operate-form"
|
||||||
|
:class="'ba-' + baTable.form.operate + '-form'"
|
||||||
|
:style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
v-if="!baTable.form.loading"
|
||||||
|
ref="formRef"
|
||||||
|
@submit.prevent=""
|
||||||
|
@keyup.enter="baTable.onSubmit(formRef)"
|
||||||
|
:model="baTable.form.items"
|
||||||
|
:label-position="config.layout.shrink ? 'top' : 'right'"
|
||||||
|
:label-width="baTable.form.labelWidth + 'px'"
|
||||||
|
:rules="rules"
|
||||||
|
>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.channel.code')"
|
||||||
|
type="string"
|
||||||
|
v-model="baTable.form.items!.code"
|
||||||
|
prop="code"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.channel.code') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.channel.name')"
|
||||||
|
type="string"
|
||||||
|
v-model="baTable.form.items!.name"
|
||||||
|
prop="name"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.channel.name') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.channel.status')"
|
||||||
|
type="switch"
|
||||||
|
v-model="baTable.form.items!.status"
|
||||||
|
prop="status"
|
||||||
|
:input-attr="{ content: { '0': t('game.channel.status 0'), '1': t('game.channel.status 1') } }"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.channel.remark')"
|
||||||
|
type="textarea"
|
||||||
|
v-model="baTable.form.items!.remark"
|
||||||
|
prop="remark"
|
||||||
|
:input-attr="{ rows: 3 }"
|
||||||
|
@keyup.enter.stop=""
|
||||||
|
@keyup.ctrl.enter="baTable.onSubmit(formRef)"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.channel.remark') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.channel.admin_id')"
|
||||||
|
type="remoteSelect"
|
||||||
|
v-model="baTable.form.items!.admin_id"
|
||||||
|
prop="admin_id"
|
||||||
|
:input-attr="{ pk: 'admin.id', field: 'username', remoteUrl: '/admin/auth.Admin/index', params: { top_group: '1' } }"
|
||||||
|
:placeholder="t('Please select field', { field: t('game.channel.admin_id') })"
|
||||||
|
/>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</el-scrollbar>
|
||||||
|
<template #footer>
|
||||||
|
<div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
|
||||||
|
<el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
|
||||||
|
<el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
|
||||||
|
{{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { FormItemRule } from 'element-plus'
|
||||||
|
import { inject, reactive, useTemplateRef } 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'
|
||||||
|
|
||||||
|
const config = useConfig()
|
||||||
|
const formRef = useTemplateRef('formRef')
|
||||||
|
const baTable = inject('baTable') as baTableClass
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
|
code: [buildValidatorData({ name: 'required', title: t('game.channel.code') })],
|
||||||
|
name: [buildValidatorData({ name: 'required', title: t('game.channel.name') })],
|
||||||
|
user_count: [buildValidatorData({ name: 'integer', title: t('game.channel.user_count') })],
|
||||||
|
profit_amount: [buildValidatorData({ name: 'float', title: t('game.channel.profit_amount') })],
|
||||||
|
admin_id: [buildValidatorData({ name: 'required', title: t('game.channel.admin_id') })],
|
||||||
|
create_time: [buildValidatorData({ name: 'date', title: t('game.channel.create_time') })],
|
||||||
|
update_time: [buildValidatorData({ name: 'date', title: t('game.channel.update_time') })],
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss"></style>
|
||||||
157
web/src/views/backend/game/user/index.vue
Normal file
157
web/src/views/backend/game/user/index.vue
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
<template>
|
||||||
|
<div class="default-main ba-table-box">
|
||||||
|
<el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
|
||||||
|
|
||||||
|
<!-- 表格顶部菜单 -->
|
||||||
|
<!-- 自定义按钮请使用插槽,甚至公共搜索也可以使用具名插槽渲染,参见文档 -->
|
||||||
|
<TableHeader
|
||||||
|
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
|
||||||
|
:quick-search-placeholder="t('Quick search placeholder', { fields: t('game.user.quick Search Fields') })"
|
||||||
|
></TableHeader>
|
||||||
|
|
||||||
|
<!-- 表格 -->
|
||||||
|
<!-- 表格列有多种自定义渲染方式,比如自定义组件、具名插槽等,参见文档 -->
|
||||||
|
<!-- 要使用 el-table 组件原有的属性,直接加在 Table 标签上即可 -->
|
||||||
|
<Table ref="tableRef"></Table>
|
||||||
|
|
||||||
|
<!-- 表单 -->
|
||||||
|
<PopupForm />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, provide, useTemplateRef } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import PopupForm from './popupForm.vue'
|
||||||
|
import { baTableApi } from '/@/api/common'
|
||||||
|
import { defaultOptButtons } from '/@/components/table'
|
||||||
|
import TableHeader from '/@/components/table/header/index.vue'
|
||||||
|
import Table from '/@/components/table/index.vue'
|
||||||
|
import baTableClass from '/@/utils/baTable'
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'game/user',
|
||||||
|
})
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const tableRef = useTemplateRef('tableRef')
|
||||||
|
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
||||||
|
*/
|
||||||
|
const baTable = new baTableClass(
|
||||||
|
new baTableApi('/admin/game.User/'),
|
||||||
|
{
|
||||||
|
pk: 'id',
|
||||||
|
column: [
|
||||||
|
{ type: 'selection', align: 'center', operator: false },
|
||||||
|
{ label: t('game.user.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
||||||
|
{
|
||||||
|
label: t('game.user.username'),
|
||||||
|
prop: 'username',
|
||||||
|
align: 'center',
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.user.uuid'),
|
||||||
|
prop: 'uuid',
|
||||||
|
align: 'center',
|
||||||
|
showOverflowTooltip: true,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{ label: t('game.user.phone'), prop: 'phone', align: 'center', operatorPlaceholder: t('Fuzzy query'), sortable: false, operator: 'LIKE' },
|
||||||
|
{ label: t('game.user.coin'), prop: 'coin', align: 'center', sortable: false, operator: 'RANGE' },
|
||||||
|
{
|
||||||
|
label: t('game.user.status'),
|
||||||
|
prop: 'status',
|
||||||
|
align: 'center',
|
||||||
|
operator: 'eq',
|
||||||
|
sortable: false,
|
||||||
|
render: 'switch',
|
||||||
|
replaceValue: { '0': t('game.user.status 0'), '1': t('game.user.status 1') },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.user.gamechannel__name'),
|
||||||
|
prop: 'gameChannel.name',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 100,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tags',
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.user.admin__username'),
|
||||||
|
prop: 'admin.username',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 90,
|
||||||
|
effect: 'plain',
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tags',
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
//修改tag颜色
|
||||||
|
customRenderAttr: {
|
||||||
|
tag: () => ({
|
||||||
|
color: '#e8f3ff',
|
||||||
|
style: { color: '#1677ff', borderColor: '#91caff' },
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.user.remark'),
|
||||||
|
prop: 'remark',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 100,
|
||||||
|
showOverflowTooltip: true,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.user.create_time'),
|
||||||
|
prop: 'create_time',
|
||||||
|
align: 'center',
|
||||||
|
render: 'datetime',
|
||||||
|
operator: 'RANGE',
|
||||||
|
comSearchRender: 'datetime',
|
||||||
|
sortable: 'custom',
|
||||||
|
width: 160,
|
||||||
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.user.update_time'),
|
||||||
|
prop: 'update_time',
|
||||||
|
align: 'center',
|
||||||
|
render: 'datetime',
|
||||||
|
operator: 'RANGE',
|
||||||
|
comSearchRender: 'datetime',
|
||||||
|
sortable: 'custom',
|
||||||
|
width: 160,
|
||||||
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
|
},
|
||||||
|
{ label: t('Operate'), align: 'center', width: 80, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right' },
|
||||||
|
],
|
||||||
|
dblClickNotEditColumn: [undefined, 'status'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultItems: { status: '1' },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
provide('baTable', baTable)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
baTable.table.ref = tableRef.value
|
||||||
|
baTable.mount()
|
||||||
|
baTable.getData()?.then(() => {
|
||||||
|
baTable.initSort()
|
||||||
|
baTable.dragSort()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss"></style>
|
||||||
213
web/src/views/backend/game/user/popupForm.vue
Normal file
213
web/src/views/backend/game/user/popupForm.vue
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 对话框表单 -->
|
||||||
|
<!-- 建议使用 Prettier 格式化代码 -->
|
||||||
|
<!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
|
||||||
|
<el-dialog
|
||||||
|
class="ba-operate-dialog"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
|
||||||
|
@close="baTable.toggleForm"
|
||||||
|
>
|
||||||
|
<template #header>
|
||||||
|
<div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
|
||||||
|
{{ baTable.form.operate ? t(baTable.form.operate) : '' }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
|
||||||
|
<div
|
||||||
|
class="ba-operate-form"
|
||||||
|
:class="'ba-' + baTable.form.operate + '-form'"
|
||||||
|
:style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
v-if="!baTable.form.loading"
|
||||||
|
ref="formRef"
|
||||||
|
@submit.prevent=""
|
||||||
|
@keyup.enter="baTable.onSubmit(formRef)"
|
||||||
|
:model="baTable.form.items"
|
||||||
|
:label-position="config.layout.shrink ? 'top' : 'right'"
|
||||||
|
:label-width="baTable.form.labelWidth + 'px'"
|
||||||
|
:rules="rules"
|
||||||
|
>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.user.username')"
|
||||||
|
type="string"
|
||||||
|
v-model="baTable.form.items!.username"
|
||||||
|
prop="username"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.user.username') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.user.password')"
|
||||||
|
type="password"
|
||||||
|
v-model="baTable.form.items!.password"
|
||||||
|
prop="password"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.user.password') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.user.phone')"
|
||||||
|
type="string"
|
||||||
|
v-model="baTable.form.items!.phone"
|
||||||
|
prop="phone"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.user.phone') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.user.remark')"
|
||||||
|
type="textarea"
|
||||||
|
v-model="baTable.form.items!.remark"
|
||||||
|
prop="remark"
|
||||||
|
:input-attr="{ rows: 3 }"
|
||||||
|
@keyup.enter.stop=""
|
||||||
|
@keyup.ctrl.enter="baTable.onSubmit(formRef)"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.user.remark') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.user.coin')"
|
||||||
|
type="number"
|
||||||
|
v-model="baTable.form.items!.coin"
|
||||||
|
prop="coin"
|
||||||
|
:input-attr="{ step: 1 }"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.user.coin') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.user.status')"
|
||||||
|
type="switch"
|
||||||
|
v-model="baTable.form.items!.status"
|
||||||
|
prop="status"
|
||||||
|
:input-attr="{ content: { '0': t('game.user.status 0'), '1': t('game.user.status 1') } }"
|
||||||
|
/>
|
||||||
|
<el-form-item :label="t('game.user.game_channel_id')" prop="admin_id">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="baTable.form.items!.admin_id"
|
||||||
|
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>
|
||||||
|
<template #footer>
|
||||||
|
<div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
|
||||||
|
<el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
|
||||||
|
<el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
|
||||||
|
{{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { FormItemRule } from 'element-plus'
|
||||||
|
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, regularPassword } from '/@/utils/validate'
|
||||||
|
import createAxios from '/@/utils/axios'
|
||||||
|
|
||||||
|
const config = useConfig()
|
||||||
|
const formRef = useTemplateRef('formRef')
|
||||||
|
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: [{ validator: validatorGameUserPassword, trigger: 'blur' }],
|
||||||
|
phone: [buildValidatorData({ name: 'required', title: t('game.user.phone') })],
|
||||||
|
coin: [buildValidatorData({ name: 'number', title: t('game.user.coin') })],
|
||||||
|
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') })],
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss"></style>
|
||||||
Reference in New Issue
Block a user