mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 14:41:29 +00:00
refactor:优化控制台菜单规则
This commit is contained in:
parent
5296fb231c
commit
14099230ce
@ -11,7 +11,7 @@ class Dashboard extends Backend
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
public function dashboard()
|
||||
public function index(): void
|
||||
{
|
||||
$this->success('', [
|
||||
'remark' => get_route_remark()
|
||||
|
69
database/migrations/20230905060702_version202.php
Normal file
69
database/migrations/20230905060702_version202.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Db;
|
||||
use think\migration\Migrator;
|
||||
|
||||
class Version202 extends Migrator
|
||||
{
|
||||
/**
|
||||
* 规范菜单规则
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
parent::up();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$dashboardId = Db::name('admin_rule')
|
||||
->where('name', 'dashboard/dashboard')
|
||||
->lock(true)
|
||||
->value('id');
|
||||
if ($dashboardId) {
|
||||
// 修改name
|
||||
Db::name('admin_rule')
|
||||
->where('name', 'dashboard/dashboard')
|
||||
->update([
|
||||
'name' => 'dashboard',
|
||||
]);
|
||||
|
||||
// 增加一个查看的权限节点
|
||||
$dashboardIndexId = Db::name('admin_rule')->insertGetId([
|
||||
'pid' => $dashboardId,
|
||||
'type' => 'button',
|
||||
'title' => '查看',
|
||||
'name' => 'dashboard/index',
|
||||
'update_time' => time(),
|
||||
'create_time' => time(),
|
||||
]);
|
||||
|
||||
// 原本有控制台权限的管理员,给予新增的查看权限
|
||||
$group = Db::name('admin_group')
|
||||
->where('rules', 'find in set', $dashboardId)
|
||||
->select();
|
||||
foreach ($group as $item) {
|
||||
|
||||
$newRules = trim($item['rules'], ',');
|
||||
$newRules = $newRules . ',' . $dashboardIndexId;
|
||||
|
||||
Db::name('admin_group')
|
||||
->where('id', $item['id'])
|
||||
->update([
|
||||
'rules' => $newRules
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 修改name
|
||||
Db::name('admin_rule')
|
||||
->where('name', 'buildadmin/buildadmin')
|
||||
->update([
|
||||
'name' => 'buildadmin',
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
} catch (Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@ import createAxios from '/@/utils/axios'
|
||||
|
||||
export const url = '/admin/Dashboard/'
|
||||
|
||||
export function dashboard() {
|
||||
export function index() {
|
||||
return createAxios({
|
||||
url: url + 'dashboard',
|
||||
url: url + 'index',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ import { CountUp } from 'countup.js'
|
||||
import * as echarts from 'echarts'
|
||||
import { useNavTabs } from '/@/stores/navTabs'
|
||||
import { useTemplateRefsList } from '@vueuse/core'
|
||||
import { dashboard } from '/@/api/backend/dashboard'
|
||||
import { index } from '/@/api/backend/dashboard'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { Local } from '/@/utils/storage'
|
||||
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||
@ -187,7 +187,7 @@ const state: {
|
||||
pauseWork: false,
|
||||
})
|
||||
|
||||
dashboard().then((res) => {
|
||||
index().then((res) => {
|
||||
state.remark = res.data.remark
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user