refactor:优化控制台菜单规则

This commit is contained in:
妙码生花 2023-09-05 15:51:17 +08:00
parent 5296fb231c
commit 14099230ce
4 changed files with 74 additions and 5 deletions

View File

@ -11,7 +11,7 @@ class Dashboard extends Backend
parent::initialize(); parent::initialize();
} }
public function dashboard() public function index(): void
{ {
$this->success('', [ $this->success('', [
'remark' => get_route_remark() 'remark' => get_route_remark()

View 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;
}
}
}

View File

@ -2,9 +2,9 @@ import createAxios from '/@/utils/axios'
export const url = '/admin/Dashboard/' export const url = '/admin/Dashboard/'
export function dashboard() { export function index() {
return createAxios({ return createAxios({
url: url + 'dashboard', url: url + 'index',
method: 'get', method: 'get',
}) })
} }

View File

@ -156,7 +156,7 @@ import { CountUp } from 'countup.js'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { useNavTabs } from '/@/stores/navTabs' import { useNavTabs } from '/@/stores/navTabs'
import { useTemplateRefsList } from '@vueuse/core' import { useTemplateRefsList } from '@vueuse/core'
import { dashboard } from '/@/api/backend/dashboard' import { index } from '/@/api/backend/dashboard'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { Local } from '/@/utils/storage' import { Local } from '/@/utils/storage'
import { useAdminInfo } from '/@/stores/adminInfo' import { useAdminInfo } from '/@/stores/adminInfo'
@ -187,7 +187,7 @@ const state: {
pauseWork: false, pauseWork: false,
}) })
dashboard().then((res) => { index().then((res) => {
state.remark = res.data.remark state.remark = res.data.remark
}) })