Compare commits
18 Commits
master-tes
...
c602c0d67d
| Author | SHA1 | Date | |
|---|---|---|---|
| c602c0d67d | |||
| 9786dab979 | |||
| 2e6e5105cf | |||
| 7fc9470f45 | |||
| 3438c711f0 | |||
| 2ee78b3239 | |||
| d8bcc4f4c4 | |||
| 165689bccf | |||
| 1d350ddb68 | |||
| 0429cf62c4 | |||
| effde58a53 | |||
| 2bb589c4e5 | |||
| 9058fa29fb | |||
| dc51b63e5e | |||
| e7dfb238e3 | |||
| f4233e751e | |||
| f0d1d46457 | |||
| 3502c299d1 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,8 +1,8 @@
|
|||||||
# 通过 Git 部署项目至线上时建议删除的忽略规则
|
# 通过 Git 部署项目至线上时建议删除的忽略规则
|
||||||
/vendor
|
/vendor
|
||||||
/modules
|
/modules
|
||||||
#/public/*.lock
|
/public/*.lock
|
||||||
#/public/index.html
|
/public/index.html
|
||||||
/public/assets
|
/public/assets
|
||||||
|
|
||||||
# 通过 Git 部署项目至线上时可以考虑删除的忽略规则
|
# 通过 Git 部署项目至线上时可以考虑删除的忽略规则
|
||||||
|
|||||||
@@ -180,9 +180,9 @@ php webman migrate
|
|||||||
```
|
```
|
||||||
|
|
||||||
3. **访问地址:**
|
3. **访问地址:**
|
||||||
- 安装向导:http://localhost:1818/install/
|
- 安装向导:http://localhost:1818/install/
|
||||||
- 前台地址:http://localhost:1818/index.html/#/
|
- 前台地址:http://localhost:1818/index.html/#/
|
||||||
- 后台地址:http://localhost:1818/index.html/#/admin
|
- 后台地址:http://localhost:1818/index.html/#/admin
|
||||||
|
|
||||||
> 注意:前端通过 Vite 代理将 `/api`、`/admin`、`/install` 转发到后端 8787 端口,请勿直接访问 8787 端口的前端页面,否则可能出现 404。
|
> 注意:前端通过 Vite 代理将 `/api`、`/admin`、`/install` 转发到后端 8787 端口,请勿直接访问 8787 端口的前端页面,否则可能出现 404。
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ location ^~ / {
|
|||||||
## 六、路由说明
|
## 六、路由说明
|
||||||
|
|
||||||
- **后台 API**:`/admin/{module}.{Controller}/{action}`
|
- **后台 API**:`/admin/{module}.{Controller}/{action}`
|
||||||
- 示例:`/admin/mall.Player/index` → `app\admin\controller\mall\Player::index`
|
- 示例:`/admin/mall.Player/index` → `app\admin\controller\mall\Player::index`
|
||||||
- **前台 API**:`/api/...`
|
- **前台 API**:`/api/...`
|
||||||
- **安装**:`/api/Install/...`
|
- **安装**:`/api/Install/...`
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -581,6 +581,13 @@ class Crud extends Backend
|
|||||||
|
|
||||||
private function parseModelMethods($field, &$modelData): void
|
private function parseModelMethods($field, &$modelData): void
|
||||||
{
|
{
|
||||||
|
// MySQL bigint/int 时间戳字段:显式声明为 integer,避免 ThinkORM 自动时间戳写入 'now' 字符串
|
||||||
|
if (in_array($field['name'] ?? '', ['create_time', 'update_time', 'createtime', 'updatetime'], true)
|
||||||
|
&& in_array($field['type'] ?? '', ['int', 'bigint'], true)
|
||||||
|
) {
|
||||||
|
$modelData['fieldType'][$field['name']] = 'integer';
|
||||||
|
}
|
||||||
|
|
||||||
if (($field['designType'] ?? '') == 'array') {
|
if (($field['designType'] ?? '') == 'array') {
|
||||||
$modelData['fieldType'][$field['name']] = 'json';
|
$modelData['fieldType'][$field['name']] = 'json';
|
||||||
} elseif (!in_array($field['name'], ['create_time', 'update_time', 'updatetime', 'createtime'])
|
} elseif (!in_array($field['name'], ['create_time', 'update_time', 'updatetime', 'createtime'])
|
||||||
|
|||||||
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 中对应的方法至此进行重写
|
||||||
|
*/
|
||||||
|
}
|
||||||
278
app/admin/controller/game/Config.php
Normal file
278
app/admin/controller/game/Config.php
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\game;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
use app\common\controller\Backend;
|
||||||
|
use support\Response;
|
||||||
|
use Webman\Http\Request as WebmanRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 游戏配置
|
||||||
|
*/
|
||||||
|
class Config extends Backend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* GameConfig模型对象
|
||||||
|
* @var object|null
|
||||||
|
* @phpstan-var \app\common\model\GameConfig|null
|
||||||
|
*/
|
||||||
|
protected ?object $model = null;
|
||||||
|
|
||||||
|
protected string|array $defaultSortField = 'group,desc';
|
||||||
|
|
||||||
|
protected array $withJoinTable = ['channel'];
|
||||||
|
|
||||||
|
protected array|string $preExcludeFields = ['create_time', 'update_time'];
|
||||||
|
|
||||||
|
protected string|array $quickSearchField = ['ID'];
|
||||||
|
|
||||||
|
/** 权重之和必须为 100 的配置标识 */
|
||||||
|
private const WEIGHT_SUM_100_NAMES = ['default_tier_weight', 'default_kill_score_weight'];
|
||||||
|
|
||||||
|
protected function initController(WebmanRequest $request): ?Response
|
||||||
|
{
|
||||||
|
$this->model = new \app\common\model\GameConfig();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
$err = $this->validateGameWeightPayload($data, null);
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->error($err);
|
||||||
|
}
|
||||||
|
|
||||||
|
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'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 (!$this->auth->isSuperAdmin()) {
|
||||||
|
$data['channel_id'] = $row['channel_id'];
|
||||||
|
$data['group'] = $row['group'];
|
||||||
|
$data['name'] = $row['name'];
|
||||||
|
$data['title'] = $row['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$err = $this->validateGameWeightPayload($data, $row['value'] ?? null);
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->error($err);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* game_weight:校验数值、键不可改(编辑)、和为 100(特定 name)
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $data
|
||||||
|
*/
|
||||||
|
private function validateGameWeightPayload(array $data, ?string $originalValue): ?string
|
||||||
|
{
|
||||||
|
$group = $data['group'] ?? '';
|
||||||
|
if ($group !== 'game_weight') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$name = $data['name'] ?? '';
|
||||||
|
$value = $data['value'] ?? '';
|
||||||
|
if (!is_string($value)) {
|
||||||
|
return __('Parameter error');
|
||||||
|
}
|
||||||
|
|
||||||
|
$decoded = json_decode($value, true);
|
||||||
|
if (!is_array($decoded)) {
|
||||||
|
return __('Parameter error');
|
||||||
|
}
|
||||||
|
|
||||||
|
$keys = [];
|
||||||
|
$numbers = [];
|
||||||
|
foreach ($decoded as $item) {
|
||||||
|
if (!is_array($item)) {
|
||||||
|
return __('Parameter error');
|
||||||
|
}
|
||||||
|
foreach ($item as $k => $v) {
|
||||||
|
$keys[] = $k;
|
||||||
|
if (!is_numeric($v)) {
|
||||||
|
return __('Game config weight value must be numeric');
|
||||||
|
}
|
||||||
|
$num = (float) $v;
|
||||||
|
if ($num > 100) {
|
||||||
|
return __('Game config weight each value must not exceed 100');
|
||||||
|
}
|
||||||
|
$numbers[] = $num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($numbers) === 0) {
|
||||||
|
return __('Parameter %s can not be empty', ['value']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($originalValue !== null && $originalValue !== '') {
|
||||||
|
$oldKeys = $this->extractGameWeightKeys($originalValue);
|
||||||
|
if ($oldKeys !== $keys) {
|
||||||
|
return __('Game config weight keys cannot be modified');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($name, self::WEIGHT_SUM_100_NAMES, true)) {
|
||||||
|
$sum = array_sum($numbers);
|
||||||
|
if (abs($sum - 100.0) > 0.000001) {
|
||||||
|
return __('Game config weight sum must equal 100');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function extractGameWeightKeys(string $value): array
|
||||||
|
{
|
||||||
|
$decoded = json_decode($value, true);
|
||||||
|
if (!is_array($decoded)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$keys = [];
|
||||||
|
foreach ($decoded as $item) {
|
||||||
|
if (!is_array($item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($item as $k => $_) {
|
||||||
|
$keys[] = $k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看
|
||||||
|
* @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(['channel' => ['name']])
|
||||||
|
->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 中对应的方法至此进行重写
|
||||||
|
*/
|
||||||
|
}
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\admin\controller\mall;
|
|
||||||
|
|
||||||
use app\common\controller\Backend;
|
|
||||||
use support\Response;
|
|
||||||
use Throwable;
|
|
||||||
use Webman\Http\Request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 积分商城用户
|
|
||||||
*/
|
|
||||||
class Player extends Backend
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Player模型对象
|
|
||||||
* @var object|null
|
|
||||||
* @phpstan-var \app\admin\model\mall\Player|null
|
|
||||||
*/
|
|
||||||
protected ?object $model = null;
|
|
||||||
|
|
||||||
protected array|string $preExcludeFields = ['id', 'create_time', 'update_time', 'password'];
|
|
||||||
|
|
||||||
protected string|array $quickSearchField = ['id'];
|
|
||||||
|
|
||||||
/** 列表不返回密码字段 */
|
|
||||||
protected string|array $indexField = ['id', 'username', 'create_time', 'update_time', 'score'];
|
|
||||||
|
|
||||||
public function initialize(): void
|
|
||||||
{
|
|
||||||
parent::initialize();
|
|
||||||
$this->model = new \app\admin\model\mall\Player();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加(重写以支持密码加密)
|
|
||||||
*/
|
|
||||||
public function add(Request $request): Response
|
|
||||||
{
|
|
||||||
$response = $this->initializeBackend($request);
|
|
||||||
if ($response instanceof Response) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->method() !== 'POST') {
|
|
||||||
$this->error(__('Parameter error'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $request->post();
|
|
||||||
if (!$data) {
|
|
||||||
$this->error(__('Parameter %s can not be empty', ['']));
|
|
||||||
}
|
|
||||||
|
|
||||||
$passwd = $data['password'] ?? '';
|
|
||||||
if (empty($passwd)) {
|
|
||||||
$this->error(__('Parameter %s can not be empty', [__('Password')]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->applyInputFilter($data);
|
|
||||||
$data = $this->excludeFields($data);
|
|
||||||
|
|
||||||
$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);
|
|
||||||
if ($result !== false && $passwd) {
|
|
||||||
$this->model->resetPassword((int) $this->model->id, $passwd);
|
|
||||||
}
|
|
||||||
$this->model->commit();
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
$this->model->rollback();
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$result !== false ? $this->success(__('Added successfully')) : $this->error(__('No rows were added'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑(重写以支持编辑时密码可选)
|
|
||||||
*/
|
|
||||||
public function edit(Request $request): Response
|
|
||||||
{
|
|
||||||
$response = $this->initializeBackend($request);
|
|
||||||
if ($response instanceof Response) {
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pk = $this->model->getPk();
|
|
||||||
$id = $request->post($pk) ?? $request->get($pk);
|
|
||||||
$row = $this->model->find($id);
|
|
||||||
if (!$row) {
|
|
||||||
$this->error(__('Record not found'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->method() === 'POST') {
|
|
||||||
$data = $request->post();
|
|
||||||
if (!$data) {
|
|
||||||
$this->error(__('Parameter %s can not be empty', ['']));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($data['password'])) {
|
|
||||||
$this->model->resetPassword((int) $row->id, $data['password']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->applyInputFilter($data);
|
|
||||||
$data = $this->excludeFields($data);
|
|
||||||
|
|
||||||
$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');
|
|
||||||
}
|
|
||||||
$validate->check(array_merge($data, [$pk => $row[$pk]]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$result = $row->save($data);
|
|
||||||
$this->model->commit();
|
|
||||||
} catch (Throwable $e) {
|
|
||||||
$this->model->rollback();
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result !== false ? $this->success(__('Update successful')) : $this->error(__('No rows updated'));
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($row['password']);
|
|
||||||
$row['password'] = '';
|
|
||||||
$this->success('', ['row' => $row]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 若需重写查看、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -95,4 +95,8 @@ return [
|
|||||||
'%d records and files have been deleted' => '%d records and files have been deleted',
|
'%d records and files have been deleted' => '%d records and files have been deleted',
|
||||||
'Please input correct username' => 'Please enter the correct username',
|
'Please input correct username' => 'Please enter the correct username',
|
||||||
'Group Name Arr' => 'Group Name Arr',
|
'Group Name Arr' => 'Group Name Arr',
|
||||||
|
'Game config weight keys cannot be modified' => 'Weight config keys cannot be modified',
|
||||||
|
'Game config weight value must be numeric' => 'Weight values must be numeric',
|
||||||
|
'Game config weight each value must not exceed 100' => 'Each weight value must not exceed 100',
|
||||||
|
'Game config weight sum must equal 100' => 'The sum of weights for default_tier_weight / default_kill_score_weight must equal 100',
|
||||||
];
|
];
|
||||||
@@ -114,4 +114,8 @@ return [
|
|||||||
'%d records and files have been deleted' => '已删除%d条记录和文件',
|
'%d records and files have been deleted' => '已删除%d条记录和文件',
|
||||||
'Please input correct username' => '请输入正确的用户名',
|
'Please input correct username' => '请输入正确的用户名',
|
||||||
'Group Name Arr' => '分组名称数组',
|
'Group Name Arr' => '分组名称数组',
|
||||||
|
'Game config weight keys cannot be modified' => '权重配置的键不可修改',
|
||||||
|
'Game config weight value must be numeric' => '权重值必须为数字',
|
||||||
|
'Game config weight each value must not exceed 100' => '每项权重不能超过100',
|
||||||
|
'Game config weight sum must equal 100' => 'default_tier_weight / default_kill_score_weight 的权重之和必须等于100',
|
||||||
];
|
];
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace {%namespace%};
|
namespace {%namespace%};
|
||||||
{%use%}
|
{%use%}
|
||||||
use app\common\controller\Backend;
|
use app\common\controller\Backend;
|
||||||
|
use support\Response;
|
||||||
|
use Webman\Http\Request as WebmanRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {%tableComment%}
|
* {%tableComment%}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
* 查看
|
* 查看
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function index(): void
|
protected function _index(): Response
|
||||||
{
|
{
|
||||||
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
||||||
if ($this->request->param('select')) {
|
if ($this->request && $this->request->get('select')) {
|
||||||
$this->select();
|
return $this->select($this->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,13 +18,14 @@
|
|||||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
$res = $this->model
|
$res = $this->model
|
||||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
|
->with($this->withJoinTable)
|
||||||
{%relationVisibleFields%}
|
{%relationVisibleFields%}
|
||||||
->alias($alias)
|
->alias($alias)
|
||||||
->where($where)
|
->where($where)
|
||||||
->order($order)
|
->order($order)
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
|
||||||
$this->success('', [
|
return $this->success('', [
|
||||||
'list' => $res->items(),
|
'list' => $res->items(),
|
||||||
'total' => $res->total(),
|
'total' => $res->total(),
|
||||||
'remark' => get_route_remark(),
|
'remark' => get_route_remark(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
public function initialize(): void
|
protected function initController(WebmanRequest $request): ?Response
|
||||||
{
|
{
|
||||||
parent::initialize();
|
|
||||||
$this->model = new \{%modelNamespace%}\{%modelName%}();{%filterRule%}
|
$this->model = new \{%modelNamespace%}\{%modelName%}();{%filterRule%}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
@@ -50,6 +50,7 @@ trait Backend
|
|||||||
$res = $this->model
|
$res = $this->model
|
||||||
->field($this->indexField)
|
->field($this->indexField)
|
||||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
|
->with($this->withJoinTable)
|
||||||
->alias($alias)
|
->alias($alias)
|
||||||
->where($where)
|
->where($where)
|
||||||
->order($order)
|
->order($order)
|
||||||
@@ -301,7 +302,40 @@ trait Backend
|
|||||||
/**
|
/**
|
||||||
* 加载为 select(远程下拉选择框)数据,子类可覆盖
|
* 加载为 select(远程下拉选择框)数据,子类可覆盖
|
||||||
*/
|
*/
|
||||||
protected function _select(): void
|
protected function _select(): Response
|
||||||
{
|
{
|
||||||
|
if (empty($this->model)) {
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => [],
|
||||||
|
'total' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
|
||||||
|
// 远程下拉只要求包含主键与可显示字段;这里尽量返回主键 + quickSearch 字段,避免全量字段带来性能问题
|
||||||
|
$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();
|
||||||
|
$res = $this->model
|
||||||
|
->field($fields)
|
||||||
|
->alias($alias)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\admin\model\mall;
|
|
||||||
|
|
||||||
use app\common\model\traits\TimestampInteger;
|
|
||||||
use support\think\Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Player
|
|
||||||
*/
|
|
||||||
class Player extends Model
|
|
||||||
{
|
|
||||||
use TimestampInteger;
|
|
||||||
|
|
||||||
// 表名
|
|
||||||
protected $name = 'mall_player';
|
|
||||||
|
|
||||||
// 自动写入时间戳字段
|
|
||||||
protected $autoWriteTimestamp = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重置密码
|
|
||||||
*/
|
|
||||||
public function resetPassword(int $id, string $newPassword): bool
|
|
||||||
{
|
|
||||||
return $this->where(['id' => $id])->update(['password' => hash_password($newPassword)]) !== false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,7 @@ use ba\Filesystem;
|
|||||||
use app\common\controller\Api;
|
use app\common\controller\Api;
|
||||||
use app\admin\model\Admin as AdminModel;
|
use app\admin\model\Admin as AdminModel;
|
||||||
use app\admin\model\User as UserModel;
|
use app\admin\model\User as UserModel;
|
||||||
|
use app\process\Monitor;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
use Webman\Http\Request;
|
use Webman\Http\Request;
|
||||||
use Phinx\Config\Config as PhinxConfig;
|
use Phinx\Config\Config as PhinxConfig;
|
||||||
@@ -428,6 +429,20 @@ class Install extends Api
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows 下 php windows.php 会每秒检测监控目录;写入 config/.env 等会触发 taskkill 整进程,导致 POST 被中断(ERR_CONNECTION_RESET)
|
||||||
|
Monitor::pause();
|
||||||
|
try {
|
||||||
|
return $this->baseConfigPost($request, $envOk, $rootPath, $migrateCommand);
|
||||||
|
} finally {
|
||||||
|
Monitor::resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统基础配置 POST:写入配置并执行迁移
|
||||||
|
*/
|
||||||
|
private function baseConfigPost(Request $request, bool $envOk, string $rootPath, string $migrateCommand): Response
|
||||||
|
{
|
||||||
$connectData = $databaseParam = $request->only(['hostname', 'username', 'password', 'hostport', 'database', 'prefix']);
|
$connectData = $databaseParam = $request->only(['hostname', 'username', 'password', 'hostport', 'database', 'prefix']);
|
||||||
|
|
||||||
// 数据库配置测试
|
// 数据库配置测试
|
||||||
@@ -455,6 +470,9 @@ class Install extends Api
|
|||||||
return "\$env('database.{$key}', '" . addslashes($value) . "')";
|
return "\$env('database.{$key}', '" . addslashes($value) . "')";
|
||||||
};
|
};
|
||||||
$dbConfigText = preg_replace_callback("/\\\$env\('database\.(hostname|database|username|password|hostport|prefix)',\s*'[^']*'\)/", $callback, $dbConfigContent);
|
$dbConfigText = preg_replace_callback("/\\\$env\('database\.(hostname|database|username|password|hostport|prefix)',\s*'[^']*'\)/", $callback, $dbConfigContent);
|
||||||
|
if ($dbConfigText === null) {
|
||||||
|
return $this->error(__('Failed to update database config file:%s', ['config/' . self::$dbConfigFileName]));
|
||||||
|
}
|
||||||
$result = @file_put_contents($dbConfigFile, $dbConfigText);
|
$result = @file_put_contents($dbConfigFile, $dbConfigText);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName]));
|
return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName]));
|
||||||
|
|||||||
@@ -214,9 +214,8 @@ class Backend extends Api
|
|||||||
public function select(WebmanRequest $request): Response
|
public function select(WebmanRequest $request): Response
|
||||||
{
|
{
|
||||||
$response = $this->initializeBackend($request);
|
$response = $this->initializeBackend($request);
|
||||||
if ($response !== null) return $response;
|
if ($response instanceof Response) return $response;
|
||||||
$this->_select();
|
return $this->_select();
|
||||||
return $this->success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/common/model/GameConfig.php
Normal file
32
app/common/model/GameConfig.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use support\think\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameConfig
|
||||||
|
*/
|
||||||
|
class GameConfig extends Model
|
||||||
|
{
|
||||||
|
// 表主键
|
||||||
|
protected $pk = 'ID';
|
||||||
|
|
||||||
|
// 表名
|
||||||
|
protected $name = 'game_config';
|
||||||
|
|
||||||
|
// 自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
|
// 字段类型转换
|
||||||
|
protected $type = [
|
||||||
|
'create_time' => 'integer',
|
||||||
|
'update_time' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function channel(): \think\model\relation\BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\common\model\GameChannel::class, 'channel_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');
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/common/validate/GameChannel.php
Normal file
31
app/common/validate/GameChannel.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class GameChannel extends Validate
|
||||||
|
{
|
||||||
|
protected $failException = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证规则
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示消息
|
||||||
|
*/
|
||||||
|
protected $message = [
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证场景
|
||||||
|
*/
|
||||||
|
protected $scene = [
|
||||||
|
'add' => [],
|
||||||
|
'edit' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\admin\validate\mall;
|
namespace app\common\validate;
|
||||||
|
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
class Player extends Validate
|
class GameConfig extends Validate
|
||||||
{
|
{
|
||||||
protected $failException = true;
|
protected $failException = true;
|
||||||
|
|
||||||
31
app/common/validate/GameUser.php
Normal file
31
app/common/validate/GameUser.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class GameUser extends Validate
|
||||||
|
{
|
||||||
|
protected $failException = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证规则
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示消息
|
||||||
|
*/
|
||||||
|
protected $message = [
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证场景
|
||||||
|
*/
|
||||||
|
protected $scene = [
|
||||||
|
'add' => [],
|
||||||
|
'edit' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
// 允许跨域访问的域名(* 表示任意;开发可用 *,生产建议填具体域名)
|
// 允许跨域访问的域名(* 表示任意;开发可用 *,生产建议填具体域名)
|
||||||
'cors_request_domain' => '*,test.zhenhui666.top',
|
'cors_request_domain' => '*',
|
||||||
// 是否开启会员登录验证码
|
// 是否开启会员登录验证码
|
||||||
'user_login_captcha' => true,
|
'user_login_captcha' => true,
|
||||||
// 是否开启管理员登录验证码
|
// 是否开启管理员登录验证码
|
||||||
|
|||||||
@@ -227,6 +227,8 @@ class Install extends AbstractMigration
|
|||||||
->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false])
|
->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false])
|
||||||
->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false])
|
->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false])
|
||||||
->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
|
->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
|
||||||
|
->addColumn('update_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
|
||||||
|
->addColumn('create_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
|
||||||
->addIndex(['name'], [
|
->addIndex(['name'], [
|
||||||
'unique' => true,
|
'unique' => true,
|
||||||
])
|
])
|
||||||
|
|||||||
55
database/migrations/20231111000000_add_config_timestamps.php
Normal file
55
database/migrations/20231111000000_add_config_timestamps.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* config 表在初始 install 中未含 create_time/update_time,而 Config 模型开启自动时间戳,
|
||||||
|
* Version205 等迁移使用 Model::save() 会生成对 update_time 的 UPDATE,导致 1054 错误。
|
||||||
|
* 本迁移在 Version205 之前执行,补齐字段。
|
||||||
|
*/
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
class AddConfigTimestamps extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (!$this->hasTable('config')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if (!$config->hasColumn('update_time')) {
|
||||||
|
$config->addColumn('update_time', 'biginteger', [
|
||||||
|
'limit' => 16,
|
||||||
|
'signed' => false,
|
||||||
|
'null' => true,
|
||||||
|
'default' => null,
|
||||||
|
'comment' => '更新时间',
|
||||||
|
'after' => 'weigh',
|
||||||
|
])->save();
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if (!$config->hasColumn('create_time')) {
|
||||||
|
$config->addColumn('create_time', 'biginteger', [
|
||||||
|
'limit' => 16,
|
||||||
|
'signed' => false,
|
||||||
|
'null' => true,
|
||||||
|
'default' => null,
|
||||||
|
'comment' => '创建时间',
|
||||||
|
'after' => 'update_time',
|
||||||
|
])->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if (!$this->hasTable('config')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if ($config->hasColumn('create_time')) {
|
||||||
|
$config->removeColumn('create_time')->save();
|
||||||
|
}
|
||||||
|
$config = $this->table('config');
|
||||||
|
if ($config->hasColumn('update_time')) {
|
||||||
|
$config->removeColumn('update_time')->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
docs/nginx.conf.example
Normal file
40
docs/nginx.conf.example
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# BuildAdmin Webman - Nginx 反向代理示例
|
||||||
|
# 将 server_name 和 root 改为实际值后,放入 nginx 的 conf.d 或 sites-available
|
||||||
|
|
||||||
|
upstream webman {
|
||||||
|
server 127.0.0.1:8787;
|
||||||
|
keepalive 10240;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
server_name 你的域名;
|
||||||
|
listen 80;
|
||||||
|
access_log off;
|
||||||
|
root /path/to/dafuweng-webman/public;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ @proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
location @proxy {
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Connection "";
|
||||||
|
proxy_pass http://webman;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ ^/\.well-known/ {
|
||||||
|
allow all;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /\. {
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,8 +42,27 @@ if (!function_exists('env')) {
|
|||||||
require $baseDir . '/vendor/workerman/webman-framework/src/support/helpers.php';
|
require $baseDir . '/vendor/workerman/webman-framework/src/support/helpers.php';
|
||||||
require $baseDir . '/app/functions.php';
|
require $baseDir . '/app/functions.php';
|
||||||
|
|
||||||
Webman\Config::load($baseDir . '/config', ['route', 'middleware', 'process', 'server', 'static']);
|
use Webman\Config;
|
||||||
$thinkorm = config('thinkorm', []);
|
|
||||||
|
Config::clear();
|
||||||
|
Config::load($baseDir . '/config', ['route', 'middleware', 'process', 'server', 'static']);
|
||||||
|
// 与 Webman\ThinkOrm\ThinkOrm::start() 一致,并与 phinx.php 中 $thinkorm 来源一致
|
||||||
|
$thinkorm = array_replace_recursive(config('thinkorm', []), config('think-orm', []));
|
||||||
if (!empty($thinkorm)) {
|
if (!empty($thinkorm)) {
|
||||||
support\think\Db::setConfig($thinkorm);
|
support\think\Db::setConfig($thinkorm);
|
||||||
|
// Webman DbManager 使用连接池且忽略 force;安装向导在同进程内迁移时若不清理,会沿用旧前缀连接,
|
||||||
|
// 导致 Phinx 已建带前缀表而 Db::name() 仍查无前缀表(如 menu_rule 不存在)。
|
||||||
|
if (class_exists(\Webman\ThinkOrm\DbManager::class)) {
|
||||||
|
$ref = new \ReflectionClass(\Webman\ThinkOrm\DbManager::class);
|
||||||
|
if ($ref->hasProperty('pools')) {
|
||||||
|
$poolsProp = $ref->getProperty('pools');
|
||||||
|
$poolsProp->setAccessible(true);
|
||||||
|
$poolsProp->setValue(null, []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (class_exists(\Webman\Context::class)) {
|
||||||
|
foreach (array_keys($thinkorm['connections'] ?? []) as $connName) {
|
||||||
|
\Webman\Context::set('think-orm.connections.' . $connName, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
phinx.php
15
phinx.php
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Phinx 数据库迁移配置
|
* Phinx 数据库迁移配置
|
||||||
* 从 config/thinkorm.php 读取数据库连接,用于 php vendor/bin/phinx migrate
|
* 与 Webman ThinkOrm 引导一致:Config 加载后合并 thinkorm + think-orm,供 phinx migrate 使用
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
@@ -36,7 +36,18 @@ if (!function_exists('env')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$thinkorm = require $baseDir . '/config/thinkorm.php';
|
if (!defined('BASE_PATH')) {
|
||||||
|
define('BASE_PATH', $baseDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
require $baseDir . '/vendor/workerman/webman-framework/src/support/helpers.php';
|
||||||
|
require $baseDir . '/app/functions.php';
|
||||||
|
|
||||||
|
use Webman\Config;
|
||||||
|
|
||||||
|
Config::clear();
|
||||||
|
Config::load($baseDir . '/config', ['route', 'middleware', 'process', 'server', 'static']);
|
||||||
|
$thinkorm = array_replace_recursive(config('thinkorm', []), config('think-orm', []));
|
||||||
$conn = $thinkorm['connections'][$thinkorm['default'] ?? 'mysql'] ?? [];
|
$conn = $thinkorm['connections'][$thinkorm['default'] ?? 'mysql'] ?? [];
|
||||||
$prefix = $conn['prefix'] ?? '';
|
$prefix = $conn['prefix'] ?? '';
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
|||||||
2026-03-18 11:17:18
|
|
||||||
@@ -11,6 +11,98 @@
|
|||||||
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() {
|
||||||
|
if (!urls.adminUrl && !urls.frontUrl) return;
|
||||||
|
if (document.getElementById('__ba_install_quick_urls__')) return;
|
||||||
|
var wrap = document.createElement('div');
|
||||||
|
wrap.id = '__ba_install_quick_urls__';
|
||||||
|
wrap.style.position = 'fixed';
|
||||||
|
wrap.style.right = '16px';
|
||||||
|
wrap.style.bottom = '16px';
|
||||||
|
wrap.style.zIndex = '99999';
|
||||||
|
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.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="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>' +
|
||||||
|
'<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 style="padding:12px;display:flex;flex-direction:column;gap:10px">' +
|
||||||
|
'<div>' +
|
||||||
|
'<div style="font-size:12px;color:#666;margin-bottom:6px">后台地址</div>' +
|
||||||
|
'<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>' +
|
||||||
|
'<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 style="font-size:12px;color:#666;margin-bottom:6px">前台地址</div>' +
|
||||||
|
'<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>' +
|
||||||
|
'<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 data-msg style="font-size:12px;color:#52c41a;min-height:16px"></div>' +
|
||||||
|
'</div>' +
|
||||||
|
'</div>';
|
||||||
|
document.body.appendChild(wrap);
|
||||||
|
|
||||||
|
var closeBtn = wrap.querySelector('button[aria-label="close"]');
|
||||||
|
if (closeBtn) closeBtn.addEventListener('click', function(){ wrap.remove(); });
|
||||||
|
|
||||||
|
function setLink(which, val) {
|
||||||
|
var a = wrap.querySelector('a[data-k="' + which + '"]');
|
||||||
|
if (!a) return;
|
||||||
|
a.textContent = val || '';
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
function applyUrls() {
|
function applyUrls() {
|
||||||
if (!urls.adminUrl && !urls.frontUrl) return;
|
if (!urls.adminUrl && !urls.frontUrl) return;
|
||||||
document.querySelectorAll('input[type="text"], input:not([type])').forEach(function(inp){
|
document.querySelectorAll('input[type="text"], input:not([type])').forEach(function(inp){
|
||||||
@@ -24,6 +116,7 @@
|
|||||||
document.querySelectorAll('a[href*="#/"]').forEach(function(a){
|
document.querySelectorAll('a[href*="#/"]').forEach(function(a){
|
||||||
if (urls.frontUrl && a.href.indexOf('#/admin') < 0) a.href = urls.frontUrl;
|
if (urls.frontUrl && a.href.indexOf('#/admin') < 0) a.href = urls.frontUrl;
|
||||||
});
|
});
|
||||||
|
ensureQuickPanel();
|
||||||
}
|
}
|
||||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function(){ setInterval(applyUrls, 800); });
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function(){ setInterval(applyUrls, 800); });
|
||||||
else setInterval(applyUrls, 800);
|
else setInterval(applyUrls, 800);
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ VITE_BASE_PATH = '/'
|
|||||||
VITE_OUT_DIR = 'dist'
|
VITE_OUT_DIR = 'dist'
|
||||||
|
|
||||||
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
|
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
|
||||||
VITE_AXIOS_BASE_URL = 'https://test-api.zhenhui666.top'
|
VITE_AXIOS_BASE_URL = 'getCurrentDomain'
|
||||||
|
|||||||
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',
|
||||||
|
}
|
||||||
21
web/src/lang/backend/en/game/config.ts
Normal file
21
web/src/lang/backend/en/game/config.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export default {
|
||||||
|
ID: 'ID',
|
||||||
|
channel_id: 'channel_id',
|
||||||
|
channel__name: 'name',
|
||||||
|
group: 'group',
|
||||||
|
name: 'name',
|
||||||
|
title: 'title',
|
||||||
|
value: 'value',
|
||||||
|
'weight key': 'Key',
|
||||||
|
'weight value': 'Value',
|
||||||
|
'weight sum must 100': 'The sum of weights for default_tier_weight / default_kill_score_weight must equal 100',
|
||||||
|
'weight each max 100': 'Each weight value must not exceed 100',
|
||||||
|
'weight value numeric': 'Weight values must be valid numbers',
|
||||||
|
sort: 'sort',
|
||||||
|
instantiation: 'instantiation',
|
||||||
|
'instantiation 0': 'instantiation 0',
|
||||||
|
'instantiation 1': 'instantiation 1',
|
||||||
|
create_time: 'create_time',
|
||||||
|
update_time: 'update_time',
|
||||||
|
'quick Search Fields': 'ID',
|
||||||
|
}
|
||||||
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',
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
export default {
|
|
||||||
id: 'id',
|
|
||||||
username: 'username',
|
|
||||||
password: 'password',
|
|
||||||
create_time: 'create_time',
|
|
||||||
update_time: 'update_time',
|
|
||||||
score: 'score',
|
|
||||||
quickSearchFields: 'id',
|
|
||||||
}
|
|
||||||
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、渠道标识、渠道名',
|
||||||
|
}
|
||||||
21
web/src/lang/backend/zh-cn/game/config.ts
Normal file
21
web/src/lang/backend/zh-cn/game/config.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export default {
|
||||||
|
ID: 'ID',
|
||||||
|
channel_id: '渠道id',
|
||||||
|
channel__name: '渠道名',
|
||||||
|
group: '分组',
|
||||||
|
name: '配置标识',
|
||||||
|
title: '配置名称',
|
||||||
|
value: '值',
|
||||||
|
'weight key': '键',
|
||||||
|
'weight value': '数值',
|
||||||
|
'weight sum must 100': 'default_tier_weight / default_kill_score_weight 的权重之和必须等于 100',
|
||||||
|
'weight each max 100': '每项权重不能超过 100',
|
||||||
|
'weight value numeric': '权重值必须为有效数字',
|
||||||
|
sort: '排序',
|
||||||
|
instantiation: '实例化',
|
||||||
|
'instantiation 0': '不需要',
|
||||||
|
'instantiation 1': '需要',
|
||||||
|
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、用户名、手机号',
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
export default {
|
|
||||||
id: 'ID',
|
|
||||||
username: '用户名',
|
|
||||||
password: '密码',
|
|
||||||
create_time: '创建时间',
|
|
||||||
update_time: '修改时间',
|
|
||||||
score: '积分',
|
|
||||||
quickSearchFields: 'ID',
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<!-- 自定义按钮请使用插槽,甚至公共搜索也可以使用具名插槽渲染,参见文档 -->
|
<!-- 自定义按钮请使用插槽,甚至公共搜索也可以使用具名插槽渲染,参见文档 -->
|
||||||
<TableHeader
|
<TableHeader
|
||||||
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
|
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
|
||||||
:quick-search-placeholder="t('Quick search placeholder', { fields: t('mall.player.quickSearchFields') })"
|
:quick-search-placeholder="t('Quick search placeholder', { fields: t('game.channel.quick Search Fields') })"
|
||||||
></TableHeader>
|
></TableHeader>
|
||||||
|
|
||||||
<!-- 表格 -->
|
<!-- 表格 -->
|
||||||
@@ -30,7 +30,7 @@ import Table from '/@/components/table/index.vue'
|
|||||||
import baTableClass from '/@/utils/baTable'
|
import baTableClass from '/@/utils/baTable'
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'mall/player',
|
name: 'game/channel',
|
||||||
})
|
})
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -41,22 +41,61 @@ const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
|
|||||||
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
||||||
*/
|
*/
|
||||||
const baTable = new baTableClass(
|
const baTable = new baTableClass(
|
||||||
new baTableApi('/admin/mall.Player/'),
|
new baTableApi('/admin/game.Channel/'),
|
||||||
{
|
{
|
||||||
pk: 'id',
|
pk: 'id',
|
||||||
column: [
|
column: [
|
||||||
{ type: 'selection', align: 'center', operator: false },
|
{ type: 'selection', align: 'center', operator: false },
|
||||||
{ label: t('mall.player.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
{ label: t('game.channel.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
||||||
{
|
{
|
||||||
label: t('mall.player.username'),
|
label: t('game.channel.code'),
|
||||||
prop: 'username',
|
prop: 'code',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
operatorPlaceholder: t('Fuzzy query'),
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
sortable: false,
|
sortable: false,
|
||||||
operator: 'LIKE',
|
operator: 'LIKE',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('mall.player.create_time'),
|
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',
|
prop: 'create_time',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: 'datetime',
|
render: 'datetime',
|
||||||
@@ -67,7 +106,7 @@ const baTable = new baTableClass(
|
|||||||
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('mall.player.update_time'),
|
label: t('game.channel.update_time'),
|
||||||
prop: 'update_time',
|
prop: 'update_time',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: 'datetime',
|
render: 'datetime',
|
||||||
@@ -77,13 +116,12 @@ const baTable = new baTableClass(
|
|||||||
width: 160,
|
width: 160,
|
||||||
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
},
|
},
|
||||||
{ label: t('mall.player.score'), prop: 'score', align: 'center', sortable: false, operator: 'RANGE' },
|
{ label: t('Operate'), align: 'center', width: 80, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right' },
|
||||||
{ label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
|
|
||||||
],
|
],
|
||||||
dblClickNotEditColumn: [undefined],
|
dblClickNotEditColumn: [undefined, 'status'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
defaultItems: {},
|
defaultItems: { status: '1' },
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,26 +30,43 @@
|
|||||||
:rules="rules"
|
:rules="rules"
|
||||||
>
|
>
|
||||||
<FormItem
|
<FormItem
|
||||||
:label="t('mall.player.username')"
|
:label="t('game.channel.code')"
|
||||||
type="string"
|
type="string"
|
||||||
v-model="baTable.form.items!.username"
|
v-model="baTable.form.items!.code"
|
||||||
prop="username"
|
prop="code"
|
||||||
:placeholder="t('Please input field', { field: t('mall.player.username') })"
|
:placeholder="t('Please input field', { field: t('game.channel.code') })"
|
||||||
/>
|
/>
|
||||||
<FormItem
|
<FormItem
|
||||||
:label="t('mall.player.password')"
|
:label="t('game.channel.name')"
|
||||||
type="password"
|
type="string"
|
||||||
v-model="baTable.form.items!.password"
|
v-model="baTable.form.items!.name"
|
||||||
prop="password"
|
prop="name"
|
||||||
:placeholder="t('Please input field', { field: t('mall.player.password') })"
|
:placeholder="t('Please input field', { field: t('game.channel.name') })"
|
||||||
/>
|
/>
|
||||||
<FormItem
|
<FormItem
|
||||||
:label="t('mall.player.score')"
|
:label="t('game.channel.status')"
|
||||||
type="number"
|
type="switch"
|
||||||
v-model="baTable.form.items!.score"
|
v-model="baTable.form.items!.status"
|
||||||
prop="score"
|
prop="status"
|
||||||
:input-attr="{ step: 1 }"
|
:input-attr="{ content: { '0': t('game.channel.status 0'), '1': t('game.channel.status 1') } }"
|
||||||
:placeholder="t('Please input field', { field: t('mall.player.score') })"
|
/>
|
||||||
|
<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>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
@@ -72,7 +89,7 @@ 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, regularPassword } from '/@/utils/validate'
|
import { buildValidatorData } from '/@/utils/validate'
|
||||||
|
|
||||||
const config = useConfig()
|
const config = useConfig()
|
||||||
const formRef = useTemplateRef('formRef')
|
const formRef = useTemplateRef('formRef')
|
||||||
@@ -81,28 +98,13 @@ const baTable = inject('baTable') as baTableClass
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
username: [buildValidatorData({ name: 'required', title: t('mall.player.username') })],
|
code: [buildValidatorData({ name: 'required', title: t('game.channel.code') })],
|
||||||
password: [
|
name: [buildValidatorData({ name: 'required', title: t('game.channel.name') })],
|
||||||
{
|
user_count: [buildValidatorData({ name: 'integer', title: t('game.channel.user_count') })],
|
||||||
validator: (_rule: unknown, val: string, callback: (error?: Error) => void) => {
|
profit_amount: [buildValidatorData({ name: 'float', title: t('game.channel.profit_amount') })],
|
||||||
if (baTable.form.operate === 'Add') {
|
admin_id: [buildValidatorData({ name: 'required', title: t('game.channel.admin_id') })],
|
||||||
if (!val) {
|
create_time: [buildValidatorData({ name: 'date', title: t('game.channel.create_time') })],
|
||||||
return callback(new Error(t('Please input field', { field: t('mall.player.password') })))
|
update_time: [buildValidatorData({ name: 'date', title: t('game.channel.update_time') })],
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!val) {
|
|
||||||
return callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!regularPassword(val)) {
|
|
||||||
return callback(new Error(t('validate.Please enter the correct password')))
|
|
||||||
}
|
|
||||||
return callback()
|
|
||||||
},
|
|
||||||
trigger: 'blur',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
score: [buildValidatorData({ name: 'number', title: t('mall.player.score') })],
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
93
web/src/views/backend/game/config/GameConfigValueCell.vue
Normal file
93
web/src/views/backend/game/config/GameConfigValueCell.vue
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="isGameWeight && weightTagLabels.length" class="game-config-value-tags">
|
||||||
|
<el-tag
|
||||||
|
v-for="(label, idx) in weightTagLabels"
|
||||||
|
:key="idx"
|
||||||
|
class="m-4"
|
||||||
|
effect="light"
|
||||||
|
type="primary"
|
||||||
|
size="default"
|
||||||
|
>
|
||||||
|
{{ label }}
|
||||||
|
</el-tag>
|
||||||
|
</div>
|
||||||
|
<span v-else class="game-config-value-plain">{{ plainText }}</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
renderRow: TableRow
|
||||||
|
renderField: TableColumn
|
||||||
|
renderValue: unknown
|
||||||
|
renderColumn: import('element-plus').TableColumnCtx<TableRow>
|
||||||
|
renderIndex: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const isGameWeight = computed(() => props.renderRow?.group === 'game_weight')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* value 形如 [{"T1":"5"},{"T2":"20"},...] 或同结构的 JSON 字符串
|
||||||
|
*/
|
||||||
|
function parseWeightTagLabels(raw: unknown): string[] {
|
||||||
|
if (raw === null || raw === undefined || raw === '') {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
let arr: unknown[] = []
|
||||||
|
if (typeof raw === 'string') {
|
||||||
|
const s = raw.trim()
|
||||||
|
if (!s) return []
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(s)
|
||||||
|
arr = Array.isArray(parsed) ? parsed : []
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(raw)) {
|
||||||
|
arr = raw
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const labels: string[] = []
|
||||||
|
for (const item of arr) {
|
||||||
|
if (item !== null && typeof item === 'object' && !Array.isArray(item)) {
|
||||||
|
for (const [k, v] of Object.entries(item as Record<string, unknown>)) {
|
||||||
|
labels.push(`${k}:${String(v)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return labels
|
||||||
|
}
|
||||||
|
|
||||||
|
const weightTagLabels = computed(() => parseWeightTagLabels(props.renderValue))
|
||||||
|
|
||||||
|
const plainText = computed(() => {
|
||||||
|
const v = props.renderValue
|
||||||
|
if (v === null || v === undefined) return ''
|
||||||
|
if (typeof v === 'object') {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(v)
|
||||||
|
} catch {
|
||||||
|
return String(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String(v)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.game-config-value-tags {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 4px 0;
|
||||||
|
}
|
||||||
|
.m-4 {
|
||||||
|
margin: 4px;
|
||||||
|
}
|
||||||
|
.game-config-value-plain {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
164
web/src/views/backend/game/config/index.vue
Normal file
164
web/src/views/backend/game/config/index.vue
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
<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.config.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 GameConfigValueCell from './GameConfigValueCell.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/config',
|
||||||
|
})
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const tableRef = useTemplateRef('tableRef')
|
||||||
|
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
||||||
|
*/
|
||||||
|
const baTable = new baTableClass(
|
||||||
|
new baTableApi('/admin/game.Config/'),
|
||||||
|
{
|
||||||
|
pk: 'ID',
|
||||||
|
column: [
|
||||||
|
{ type: 'selection', align: 'center', operator: false },
|
||||||
|
{ label: t('game.config.ID'), prop: 'ID', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
||||||
|
// {
|
||||||
|
// label: t('game.config.channel_id'),
|
||||||
|
// prop: 'channel_id',
|
||||||
|
// align: 'center',
|
||||||
|
// show: false,
|
||||||
|
// enableColumnDisplayControl: false,
|
||||||
|
// operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
// render: 'tags',
|
||||||
|
// operator: 'LIKE',
|
||||||
|
// comSearchRender: 'string',
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
label: t('game.config.channel__name'),
|
||||||
|
prop: 'channel.name',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 100,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tags',
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.config.group'),
|
||||||
|
prop: 'group',
|
||||||
|
align: 'center',
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.config.name'),
|
||||||
|
prop: 'name',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 180,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tag',
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.config.title'),
|
||||||
|
prop: 'title',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 85,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.config.value'),
|
||||||
|
prop: 'value',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 220,
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
render: 'customRender',
|
||||||
|
customRender: GameConfigValueCell,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.config.instantiation'),
|
||||||
|
prop: 'instantiation',
|
||||||
|
align: 'center',
|
||||||
|
operator: 'RANGE',
|
||||||
|
sortable: false,
|
||||||
|
render: 'tag',
|
||||||
|
replaceValue: { '0': t('game.config.instantiation 0'), '1': t('game.config.instantiation 1') },
|
||||||
|
},
|
||||||
|
{ label: t('game.config.sort'), prop: 'sort', align: 'center', sortable: false, operator: 'RANGE' },
|
||||||
|
{
|
||||||
|
label: t('game.config.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.config.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: 100, render: 'buttons', buttons: optButtons, operator: false },
|
||||||
|
],
|
||||||
|
dblClickNotEditColumn: [undefined, 'instantiation'],
|
||||||
|
defaultOrder: { prop: 'group', order: 'desc' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultItems: { sort: 100 },
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
provide('baTable', baTable)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
baTable.table.ref = tableRef.value
|
||||||
|
baTable.mount()
|
||||||
|
baTable.getData()?.then(() => {
|
||||||
|
baTable.initSort()
|
||||||
|
baTable.dragSort()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss"></style>
|
||||||
375
web/src/views/backend/game/config/popupForm.vue
Normal file
375
web/src/views/backend/game/config/popupForm.vue
Normal file
@@ -0,0 +1,375 @@
|
|||||||
|
<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.config.channel_id')"
|
||||||
|
type="remoteSelect"
|
||||||
|
v-model="baTable.form.items!.channel_id"
|
||||||
|
prop="channel_id"
|
||||||
|
:input-attr="{ ...channelRemoteAttr, disabled: metaFieldsDisabled }"
|
||||||
|
:placeholder="t('Please select field', { field: t('game.config.channel_id') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.config.group')"
|
||||||
|
type="select"
|
||||||
|
v-model="baTable.form.items!.group"
|
||||||
|
prop="group"
|
||||||
|
:input-attr="{ content: groupSelectContentFiltered, disabled: metaFieldsDisabled }"
|
||||||
|
:placeholder="t('Please select field', { field: t('game.config.group') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.config.name')"
|
||||||
|
type="string"
|
||||||
|
v-model="baTable.form.items!.name"
|
||||||
|
prop="name"
|
||||||
|
:input-attr="{ disabled: metaFieldsDisabled }"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.config.name') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.config.title')"
|
||||||
|
type="string"
|
||||||
|
v-model="baTable.form.items!.title"
|
||||||
|
prop="title"
|
||||||
|
:input-attr="{ disabled: metaFieldsDisabled }"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.config.title') })"
|
||||||
|
/>
|
||||||
|
<!-- game_weight:数组形式编辑,存库仍为 JSON 字符串 -->
|
||||||
|
<el-form-item v-if="isGameWeight" :label="t('game.config.value')" prop="value">
|
||||||
|
<div class="weight-value-editor">
|
||||||
|
<div v-for="(row, idx) in weightRows" :key="idx" class="weight-value-row">
|
||||||
|
<el-input
|
||||||
|
v-model="row.key"
|
||||||
|
class="weight-key"
|
||||||
|
:readonly="weightKeyReadonly"
|
||||||
|
:clearable="!weightKeyReadonly"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.config.weight key') })"
|
||||||
|
@input="onWeightRowChange"
|
||||||
|
/>
|
||||||
|
<span class="weight-sep">:</span>
|
||||||
|
<el-input
|
||||||
|
v-model="row.val"
|
||||||
|
class="weight-val"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.config.weight value') })"
|
||||||
|
clearable
|
||||||
|
@input="onWeightRowChange"
|
||||||
|
/>
|
||||||
|
<el-button v-if="canEditWeightStructure" type="danger" link @click="removeWeightRow(idx)">
|
||||||
|
{{ t('Delete') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
<el-button v-if="canEditWeightStructure" type="primary" link @click="addWeightRow">{{ t('Add') }}</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
<FormItem
|
||||||
|
v-else
|
||||||
|
:label="t('game.config.value')"
|
||||||
|
type="textarea"
|
||||||
|
v-model="baTable.form.items!.value"
|
||||||
|
prop="value"
|
||||||
|
:input-attr="{ rows: 3 }"
|
||||||
|
@keyup.enter.stop=""
|
||||||
|
@keyup.ctrl.enter="baTable.onSubmit(formRef)"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.config.value') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.config.sort')"
|
||||||
|
type="number"
|
||||||
|
v-model="baTable.form.items!.sort"
|
||||||
|
prop="sort"
|
||||||
|
:input-attr="{ step: 1 }"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.config.sort') })"
|
||||||
|
/>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.config.instantiation')"
|
||||||
|
type="switch"
|
||||||
|
v-model="baTable.form.items!.instantiation"
|
||||||
|
prop="instantiation"
|
||||||
|
:input-attr="{ content: { '0': t('game.config.instantiation 0'), '1': t('game.config.instantiation 1') } }"
|
||||||
|
/>
|
||||||
|
</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 { computed, inject, reactive, ref, useTemplateRef, watch } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import FormItem from '/@/components/formItem/index.vue'
|
||||||
|
import { useConfig } from '/@/stores/config'
|
||||||
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
|
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 adminInfo = useAdminInfo()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const isSuperAdmin = computed(() => adminInfo.super === true)
|
||||||
|
|
||||||
|
/** 编辑且非超级管理员:渠道、分组、配置标识、配置名称不可改 */
|
||||||
|
const metaFieldsDisabled = computed(() => !isSuperAdmin.value && baTable.form.operate === 'Edit')
|
||||||
|
|
||||||
|
const channelRemoteAttr = {
|
||||||
|
pk: 'game_channel.id',
|
||||||
|
field: 'name',
|
||||||
|
remoteUrl: '/admin/game.Channel/index',
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupSelectBase = {
|
||||||
|
game_config: 'game_config',
|
||||||
|
game_weight: 'game_weight',
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 非超级管理员新增时不可选 game_weight(需先由超级管理员建好键结构) */
|
||||||
|
const groupSelectContentFiltered = computed(() => {
|
||||||
|
if (!isSuperAdmin.value && baTable.form.operate === 'Add') {
|
||||||
|
return { game_config: groupSelectBase.game_config }
|
||||||
|
}
|
||||||
|
return groupSelectBase
|
||||||
|
})
|
||||||
|
|
||||||
|
/** game_weight:编辑或非超管时键只读;仅超管新增时可增删行、改键 */
|
||||||
|
const weightKeyReadonly = computed(() => {
|
||||||
|
if (!isGameWeight.value) return false
|
||||||
|
if (baTable.form.operate === 'Edit') return true
|
||||||
|
return !isSuperAdmin.value
|
||||||
|
})
|
||||||
|
|
||||||
|
const canEditWeightStructure = computed(() => isGameWeight.value && baTable.form.operate === 'Add' && isSuperAdmin.value)
|
||||||
|
|
||||||
|
type WeightRow = { key: string; val: string }
|
||||||
|
|
||||||
|
const weightRows = ref<WeightRow[]>([{ key: '', val: '' }])
|
||||||
|
|
||||||
|
const WEIGHT_SUM100_NAMES = ['default_tier_weight', 'default_kill_score_weight']
|
||||||
|
|
||||||
|
const isGameWeight = computed(() => baTable.form.items?.group === 'game_weight')
|
||||||
|
|
||||||
|
function parseValueToWeightRows(raw: unknown): WeightRow[] {
|
||||||
|
if (raw === null || raw === undefined || raw === '') {
|
||||||
|
return [{ key: '', val: '' }]
|
||||||
|
}
|
||||||
|
if (typeof raw === 'string') {
|
||||||
|
const s = raw.trim()
|
||||||
|
if (!s) return [{ key: '', val: '' }]
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(s)
|
||||||
|
return arrayToWeightRows(parsed)
|
||||||
|
} catch {
|
||||||
|
return [{ key: '', val: '' }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Array.isArray(raw)) {
|
||||||
|
return arrayToWeightRows(raw)
|
||||||
|
}
|
||||||
|
return [{ key: '', val: '' }]
|
||||||
|
}
|
||||||
|
|
||||||
|
function arrayToWeightRows(arr: unknown): WeightRow[] {
|
||||||
|
if (!Array.isArray(arr)) {
|
||||||
|
return [{ key: '', val: '' }]
|
||||||
|
}
|
||||||
|
const out: WeightRow[] = []
|
||||||
|
for (const item of arr) {
|
||||||
|
if (item !== null && typeof item === 'object' && !Array.isArray(item)) {
|
||||||
|
for (const [k, v] of Object.entries(item)) {
|
||||||
|
out.push({ key: k, val: v === null || v === undefined ? '' : String(v) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.length ? out : [{ key: '', val: '' }]
|
||||||
|
}
|
||||||
|
|
||||||
|
function weightRowsToJsonString(rows: WeightRow[]): string {
|
||||||
|
const pairs: Record<string, string>[] = []
|
||||||
|
for (const r of rows) {
|
||||||
|
const k = r.key.trim()
|
||||||
|
if (k === '') continue
|
||||||
|
const one: Record<string, string> = {}
|
||||||
|
one[k] = r.val
|
||||||
|
pairs.push(one)
|
||||||
|
}
|
||||||
|
return JSON.stringify(pairs)
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncWeightRowsToFormValue() {
|
||||||
|
const items = baTable.form.items
|
||||||
|
if (!items) return
|
||||||
|
items.value = weightRowsToJsonString(weightRows.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onWeightRowChange() {
|
||||||
|
if (isGameWeight.value) {
|
||||||
|
syncWeightRowsToFormValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addWeightRow() {
|
||||||
|
if (!canEditWeightStructure.value) return
|
||||||
|
weightRows.value.push({ key: '', val: '' })
|
||||||
|
syncWeightRowsToFormValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeWeightRow(idx: number) {
|
||||||
|
if (!canEditWeightStructure.value) return
|
||||||
|
if (weightRows.value.length <= 1) {
|
||||||
|
weightRows.value = [{ key: '', val: '' }]
|
||||||
|
} else {
|
||||||
|
weightRows.value.splice(idx, 1)
|
||||||
|
}
|
||||||
|
syncWeightRowsToFormValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
function hydrateWeightRowsFromForm() {
|
||||||
|
if (!isGameWeight.value) return
|
||||||
|
weightRows.value = parseValueToWeightRows(baTable.form.items?.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(isGameWeight, (gw) => {
|
||||||
|
if (gw) {
|
||||||
|
hydrateWeightRowsFromForm()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => baTable.form.loading,
|
||||||
|
(loading) => {
|
||||||
|
if (loading === false && baTable.form.items?.group === 'game_weight') {
|
||||||
|
hydrateWeightRowsFromForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => baTable.form.items?.group,
|
||||||
|
() => {
|
||||||
|
if (baTable.form.items?.group === 'game_weight') {
|
||||||
|
hydrateWeightRowsFromForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function validateGameWeightRules(): string | undefined {
|
||||||
|
if (baTable.form.items?.group !== 'game_weight') {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
const name = baTable.form.items?.name ?? ''
|
||||||
|
const nums: number[] = []
|
||||||
|
for (const r of weightRows.value) {
|
||||||
|
const k = r.key.trim()
|
||||||
|
if (k === '') continue
|
||||||
|
const vs = r.val.trim()
|
||||||
|
if (vs === '') {
|
||||||
|
return t('Please input field', { field: t('game.config.weight value') })
|
||||||
|
}
|
||||||
|
const n = Number(vs)
|
||||||
|
if (!Number.isFinite(n)) {
|
||||||
|
return t('game.config.weight value numeric')
|
||||||
|
}
|
||||||
|
if (n > 100) {
|
||||||
|
return t('game.config.weight each max 100')
|
||||||
|
}
|
||||||
|
nums.push(n)
|
||||||
|
}
|
||||||
|
if (nums.length === 0) {
|
||||||
|
return t('Please input field', { field: t('game.config.value') })
|
||||||
|
}
|
||||||
|
if (WEIGHT_SUM100_NAMES.includes(name)) {
|
||||||
|
let sum = 0
|
||||||
|
for (const x of nums) {
|
||||||
|
sum += x
|
||||||
|
}
|
||||||
|
if (Math.abs(sum - 100) > 0.000001) {
|
||||||
|
return t('game.config.weight sum must 100')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
|
group: [buildValidatorData({ name: 'required', title: t('game.config.group') })],
|
||||||
|
name: [buildValidatorData({ name: 'required', title: t('game.config.name') })],
|
||||||
|
title: [buildValidatorData({ name: 'required', title: t('game.config.title') })],
|
||||||
|
sort: [buildValidatorData({ name: 'number', title: t('game.config.sort') })],
|
||||||
|
instantiation: [buildValidatorData({ name: 'number', title: t('game.config.instantiation') })],
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
validator: (_rule, _val, callback) => {
|
||||||
|
const err = validateGameWeightRules()
|
||||||
|
if (err) {
|
||||||
|
callback(new Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
callback()
|
||||||
|
},
|
||||||
|
trigger: ['blur', 'change'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
create_time: [buildValidatorData({ name: 'date', title: t('game.config.create_time') })],
|
||||||
|
update_time: [buildValidatorData({ name: 'date', title: t('game.config.update_time') })],
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.weight-value-editor {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.weight-value-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.weight-key {
|
||||||
|
max-width: 140px;
|
||||||
|
}
|
||||||
|
.weight-val {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 80px;
|
||||||
|
}
|
||||||
|
.weight-sep {
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
</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