Skip to content

Commit

Permalink
refactor: menu_rule 表名改为 admin_rule,因为会员规则表名为 user_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
build-admin committed Jun 24, 2023
1 parent f90b774 commit bf88323
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 106 deletions.
8 changes: 4 additions & 4 deletions app/admin/controller/auth/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use ba\Tree;
use Throwable;
use think\facade\Db;
use app\admin\model\MenuRule;
use app\admin\model\AdminRule;
use app\admin\model\AdminGroup;
use app\common\controller\Backend;

Expand Down Expand Up @@ -184,7 +184,7 @@ public function edit(string $id = null): void
}

// 读取所有pid,全部从节点数组移除,父级选择状态由子级决定
$pidArr = MenuRule::field('pid')
$pidArr = AdminRule::field('pid')
->distinct(true)
->where('id', 'in', $row->rules)
->select()->toArray();
Expand Down Expand Up @@ -269,7 +269,7 @@ public function select(): void
public function handleRules(array &$data): array
{
if (!empty($data['rules']) && is_array($data['rules'])) {
$rules = MenuRule::select();
$rules = AdminRule::select();
$superAdmin = true;
foreach ($rules as $rule) {
if (!in_array($rule['id'], $data['rules'])) {
Expand Down Expand Up @@ -332,7 +332,7 @@ public function getGroups(array $where = []): array
} else {
$rules = explode(',', $datum['rules']);
if ($rules) {
$rulesFirstTitle = MenuRule::where('id', $rules[0])->value('title');
$rulesFirstTitle = AdminRule::where('id', $rules[0])->value('title');
$datum['rules'] = count($rules) == 1 ? $rulesFirstTitle : $rulesFirstTitle . '' . count($rules) . '';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

use ba\Tree;
use Throwable;
use app\admin\model\MenuRule;
use app\admin\model\AdminRule;
use app\common\controller\Backend;

class Menu extends Backend
class Rule extends Backend
{
protected string|array $preExcludeFields = ['create_time', 'update_time'];

protected string|array $quickSearchField = 'title';

/**
* @var object
* @phpstan-var MenuRule
* @phpstan-var AdminRule
*/
protected object $model;

Expand Down Expand Up @@ -51,7 +51,7 @@ class Menu extends Backend
public function initialize(): void
{
parent::initialize();
$this->model = new MenuRule();
$this->model = new AdminRule();
$this->tree = Tree::instance();

$isTree = $this->request->param('isTree', true);
Expand Down
12 changes: 6 additions & 6 deletions app/admin/library/crud/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use think\Exception;
use think\facade\Db;
use app\common\library\Menu;
use app\admin\model\MenuRule;
use app\admin\model\AdminRule;
use app\admin\model\CrudLog;

class Helper
Expand All @@ -30,7 +30,7 @@ class Helper
'admin' => ['auth', 'admin'],
'admin_group' => ['auth', 'group'],
'attachment' => ['routine', 'attachment'],
'menu_rule' => ['auth', 'menu'],
'admin_rule' => ['auth', 'rule'],
],
'model' => [],
'validate' => [],
Expand Down Expand Up @@ -201,7 +201,7 @@ class Helper
'admin' => ['auth', 'admin'],
'admin_group' => ['auth', 'group'],
'attachment' => ['routine', 'attachment'],
'menu_rule' => ['auth', 'menu'],
'admin_rule' => ['auth', 'rule'],
],
];

Expand Down Expand Up @@ -649,10 +649,10 @@ protected static function isMatchSuffix(string $field, string|array $suffixArr):
public static function createMenu($webViewsDir, $tableComment): void
{
$menuName = self::getMenuName($webViewsDir);
if (!MenuRule::where('name', $menuName)->value('id')) {
if (!AdminRule::where('name', $menuName)->value('id')) {
$pid = 0;
foreach ($webViewsDir['path'] as $item) {
$pMenu = MenuRule::where('name', $item)->value('id');
$pMenu = AdminRule::where('name', $item)->value('id');
if ($pMenu) {
$pid = $pMenu;
continue;
Expand All @@ -664,7 +664,7 @@ public static function createMenu($webViewsDir, $tableComment): void
'name' => $item,
'path' => $item,
];
$menu = MenuRule::create($menu);
$menu = AdminRule::create($menu);
$pid = $menu->id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use think\Model;

/**
* MenuRule 模型
* @controllerUrl 'authMenu'
* AdminRule 模型
*/
class MenuRule extends Model
class AdminRule extends Model
{
protected $autoWriteTimestamp = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use think\Validate;

class MenuRule extends Validate
class AdminRule extends Validate
{
protected $failException = true;

protected $rule = [
'type' => 'require',
'title' => 'require',
'name' => 'require|unique:menu_rule',
'name' => 'require|unique:admin_rule',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion app/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function get_route_remark(): string
$actionName = request()->action(true);
$path = str_replace('.', '/', $controllerName);

$remark = Db::name('menu_rule')
$remark = Db::name('admin_rule')
->where('name', $path)
->whereOr('name', $path . '/' . $actionName)
->value('remark');
Expand Down
10 changes: 5 additions & 5 deletions app/common/library/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace app\common\library;

use app\admin\model\MenuRule;
use app\admin\model\AdminRule;
use app\admin\model\UserRule;
use think\db\exception\DbException;
use think\db\exception\DataNotFoundException;
Expand All @@ -25,7 +25,7 @@ class Menu
public static function create(array $menu, $parent = 0, string $mode = 'cover', string $position = 'backend')
{
$pid = 0;
$model = $position == 'backend' ? new MenuRule() : new UserRule();
$model = $position == 'backend' ? new AdminRule() : new UserRule();
$parentRule = $model->where((is_numeric($parent) ? 'id' : 'name'), $parent)->find();
if ($parentRule) {
$pid = $parentRule['id'];
Expand Down Expand Up @@ -78,7 +78,7 @@ public static function delete($id, bool $recursion = false, string $position = '
if (!$id) {
return true;
}
$model = $position == 'backend' ? new MenuRule() : new UserRule();
$model = $position == 'backend' ? new AdminRule() : new UserRule();
$menuRule = $model->where((is_numeric($id) ? 'id' : 'name'), $id)->find();
if (!$menuRule) {
return true;
Expand Down Expand Up @@ -109,7 +109,7 @@ public static function delete($id, bool $recursion = false, string $position = '
*/
public static function enable($id, string $position = 'backend'): bool
{
$model = $position == 'backend' ? new MenuRule() : new UserRule();
$model = $position == 'backend' ? new AdminRule() : new UserRule();
$menuRule = $model->where((is_numeric($id) ? 'id' : 'name'), $id)->find();
if (!$menuRule) {
return false;
Expand All @@ -130,7 +130,7 @@ public static function enable($id, string $position = 'backend'): bool
*/
public static function disable($id, string $position = 'backend'): bool
{
$model = $position == 'backend' ? new MenuRule() : new UserRule();
$model = $position == 'backend' ? new AdminRule() : new UserRule();
$menuRule = $model->where((is_numeric($id) ? 'id' : 'name'), $id)->find();
if (!$menuRule) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions database/migrations/20230622221507_version200.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use think\facade\Db;
use think\migration\Migrator;

class Version200 extends Migrator
Expand Down Expand Up @@ -60,6 +61,19 @@ public function up()
->changeColumn('update_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
->changeColumn('create_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
->save();
$menuRule->rename('admin_rule')->save();
Db::name('admin_rule')
->where('name', 'auth/menu')
->update([
'name' => 'auth/rule',
'path' => 'auth/rule',
'component' => '/src/views/backend/auth/rule/index.vue',
]);
Db::name('admin_rule')->where('name', 'auth/menu/index')->update(['name' => 'auth/rule/index']);
Db::name('admin_rule')->where('name', 'auth/menu/add')->update(['name' => 'auth/rule/add']);
Db::name('admin_rule')->where('name', 'auth/menu/edit')->update(['name' => 'auth/rule/edit']);
Db::name('admin_rule')->where('name', 'auth/menu/del')->update(['name' => 'auth/rule/del']);
Db::name('admin_rule')->where('name', 'auth/menu/sortable')->update(['name' => 'auth/rule/sortable']);
}

$securityDataRecycle = $this->table('security_data_recycle');
Expand Down
2 changes: 1 addition & 1 deletion extend/ba/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Auth
protected $config = [
'auth_group' => 'admin_group', // 用户组数据表名
'auth_group_access' => 'admin_group_access', // 用户-用户组关系表
'auth_rule' => 'menu_rule', // 权限规则表
'auth_rule' => 'admin_rule', // 权限规则表
];

/**
Expand Down
6 changes: 3 additions & 3 deletions web/src/api/backend/auth/group.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import createAxios from '/@/utils/axios'
import { authMenu } from '/@/api/controllerUrls'
import { adminRule } from '/@/api/controllerUrls'

export function getMenuRules() {
export function getAdminRules() {
return createAxios({
url: authMenu + 'index',
url: adminRule + 'index',
method: 'get',
})
}
2 changes: 1 addition & 1 deletion web/src/api/controllerUrls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* 通常将表格的控制器URL定义在此处
*/
export const authMenu = '/admin/auth.menu/'
export const adminRule = '/admin/auth.rule/'
export const authAdmin = '/admin/auth.admin/'
export const authAdminLog = '/admin/auth.adminLog/'
export const authGroup = '/admin/auth.group/'
Expand Down
2 changes: 1 addition & 1 deletion web/src/lang/autoload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export default {
'/': ['./frontend/${lang}/index.ts'],
'/admin/moduleStore': ['./backend/${lang}/module.ts'],
'/admin/user/rule': ['./backend/${lang}/auth/menu.ts'],
'/admin/user/rule': ['./backend/${lang}/auth/rule.ts'],
'/admin/user/scoreLog': ['./backend/${lang}/user/moneyLog.ts'],
'/admin/crud/crud': ['./backend/${lang}/crud/log.ts', './backend/${lang}/crud/state.ts'],
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions web/src/views/backend/auth/group/popupForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import { reactive, ref, watch, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import { getMenuRules } from '/@/api/backend/auth/group'
import { getAdminRules } from '/@/api/backend/auth/group'
import type { ElForm, ElTree, FormItemRule } from 'element-plus'
import { uuid } from '/@/utils/random'
import { buildValidatorData } from '/@/utils/validate'
Expand Down Expand Up @@ -142,7 +142,7 @@ const rules: Partial<Record<string, FormItemRule[]>> = reactive({
],
})
getMenuRules().then((res) => {
getAdminRules().then((res) => {
state.menuRules = res.data.list
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- 表格顶部菜单 -->
<TableHeader
:buttons="['refresh', 'add', 'edit', 'delete', 'unfold', 'quickSearch', 'columnDisplay']"
:quick-search-placeholder="t('quick Search Placeholder', { fields: t('auth.menu.title') })"
:quick-search-placeholder="t('quick Search Placeholder', { fields: t('auth.rule.title') })"
/>
<!-- 表格 -->
<!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
Expand All @@ -18,7 +18,7 @@

<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import { authMenu } from '/@/api/controllerUrls'
import { adminRule } from '/@/api/controllerUrls'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
Expand All @@ -30,24 +30,24 @@ import baTableClass from '/@/utils/baTable'
const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
new baTableApi(authMenu),
new baTableApi(adminRule),
{
expandAll: false,
dblClickNotEditColumn: [undefined, 'keepalive', 'status'],
column: [
{ type: 'selection', align: 'center' },
{ label: t('auth.menu.title'), prop: 'title', align: 'left', width: '200' },
{ label: t('auth.menu.Icon'), prop: 'icon', align: 'center', width: '60', render: 'icon', default: 'el-icon-Minus' },
{ label: t('auth.menu.name'), prop: 'name', align: 'center', 'show-overflow-tooltip': true },
{ label: t('auth.rule.title'), prop: 'title', align: 'left', width: '200' },
{ label: t('auth.rule.Icon'), prop: 'icon', align: 'center', width: '60', render: 'icon', default: 'el-icon-Minus' },
{ label: t('auth.rule.name'), prop: 'name', align: 'center', 'show-overflow-tooltip': true },
{
label: t('auth.menu.type'),
label: t('auth.rule.type'),
prop: 'type',
align: 'center',
render: 'tag',
custom: { menu: 'danger', menu_dir: 'success', button: 'info' },
replaceValue: { menu: t('auth.menu.type menu'), menu_dir: t('auth.menu.type menu_dir'), button: t('auth.menu.type button') },
replaceValue: { menu: t('auth.rule.type menu'), menu_dir: t('auth.rule.type menu_dir'), button: t('auth.rule.type button') },
},
{ label: t('auth.menu.cache'), prop: 'keepalive', align: 'center', width: '80', render: 'switch' },
{ label: t('auth.rule.cache'), prop: 'keepalive', align: 'center', width: '80', render: 'switch' },
{ label: t('state'), prop: 'status', align: 'center', width: '80', render: 'switch' },
{ label: t('updatetime'), prop: 'update_time', align: 'center', width: '160', render: 'datetime' },
{
Expand Down Expand Up @@ -95,7 +95,7 @@ onMounted(() => {
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'auth/menu',
name: 'auth/rule',
})
</script>

Expand Down
Loading

0 comments on commit bf88323

Please sign in to comment.