first commit
This commit is contained in:
38
modules/Permissions/Enums/DataRange.php
Normal file
38
modules/Permissions/Enums/DataRange.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Modules\Permissions\Enums;
|
||||
|
||||
use Catch\Enums\Enum;
|
||||
|
||||
enum DataRange: int implements Enum
|
||||
{
|
||||
case All_Data = 1; // 全部数据
|
||||
case Personal_Choose = 2; // 自定义数据
|
||||
case Personal_Data = 3; // 本人数据
|
||||
case Department_Data = 4; // 部门数据
|
||||
case Department_DOWN_Data = 5; // 部门及以下数据
|
||||
|
||||
|
||||
public function value(): int
|
||||
{
|
||||
// TODO: Implement value() method.
|
||||
return match ($this) {
|
||||
self::All_Data => 1,
|
||||
self::Personal_Choose => 2,
|
||||
self::Personal_Data => 3,
|
||||
self::Department_Data => 4,
|
||||
self::Department_DOWN_Data => 5,
|
||||
};
|
||||
}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
// TODO: Implement name() method.
|
||||
return match ($this) {
|
||||
self::All_Data => '全部数据',
|
||||
self::Personal_Choose => '自定义数据',
|
||||
self::Personal_Data => '本人数据',
|
||||
self::Department_Data => '部门数据',
|
||||
self::Department_DOWN_Data => '部门及以下数据',
|
||||
};
|
||||
}
|
||||
}
|
45
modules/Permissions/Http/Controllers/RolesController.php
Normal file
45
modules/Permissions/Http/Controllers/RolesController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Permissions\Http\Controllers;
|
||||
|
||||
use Catch\Base\CatchController as Controller;
|
||||
use Modules\Permissions\Models\RolesModel;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Permissions\Http\Requests\RoleRequest;
|
||||
|
||||
|
||||
class RolesController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly RolesModel $model
|
||||
){}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(): mixed
|
||||
{
|
||||
return $this->model->getList();
|
||||
}
|
||||
|
||||
public function store(RoleRequest $request)
|
||||
{
|
||||
return $this->model->storeBy($request->all());
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return $this->model->firstBy($id);
|
||||
}
|
||||
|
||||
public function update($id, RoleRequest $request)
|
||||
{
|
||||
return $this->model->updateBy($id, $request->all());
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return $this->model->deleteBy($id);
|
||||
}
|
||||
}
|
44
modules/Permissions/Http/Requests/RoleRequest.php
Normal file
44
modules/Permissions/Http/Requests/RoleRequest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Permissions\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\Permissions\Models\RolesModel;
|
||||
|
||||
class RoleRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'role_name' => sprintf('required|unique:%s,%s,%s', RolesModel::class, 'role_name', $this->get('id')),
|
||||
|
||||
'identify' => sprintf('required|alpha|unique:%s,%s,%s', RolesModel::class, 'role_name', $this->get('id')),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* messages
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'role_name.required' => '角色名称必须填写',
|
||||
|
||||
'role_name.unique' => '角色名称已存在',
|
||||
|
||||
'identify.required' => '角色标识必须填写',
|
||||
|
||||
'identify.alpha' => '角色名称只允许字母组成',
|
||||
|
||||
'identify.unique' => '角色标识已存在',
|
||||
];
|
||||
}
|
||||
}
|
53
modules/Permissions/Models/RolesModel.php
Normal file
53
modules/Permissions/Models/RolesModel.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Permissions\Models;
|
||||
|
||||
use Catch\Base\CatchModel as Model;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
/**
|
||||
* @property $role_name
|
||||
* @property $identify
|
||||
* @property $parent_id
|
||||
* @property $description
|
||||
* @property $data_range
|
||||
* @property $creator_id
|
||||
* @property $created_at
|
||||
* @property $updated_at
|
||||
* @property $deleted_at
|
||||
*/
|
||||
class RolesModel extends Model
|
||||
{
|
||||
protected $table = 'roles';
|
||||
|
||||
protected $fillable = [ 'id', 'role_name', 'identify', 'parent_id', 'description', 'data_range', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $fieldsInList = ['id', 'role_name','identify','parent_id','description','data_range', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $form = ['role_name','identify','parent_id','description','data_range'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $searchable = [
|
||||
'role_name' => 'like',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(): mixed
|
||||
{
|
||||
return self::query()->select($this->fieldsInList)->quickSearch()->get()->toTree();
|
||||
}
|
||||
|
||||
}
|
20
modules/Permissions/Providers/PermissionsServiceProvider.php
Normal file
20
modules/Permissions/Providers/PermissionsServiceProvider.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Permissions\Providers;
|
||||
|
||||
use Catch\CatchAdmin;
|
||||
use Catch\Providers\CatchModuleServiceProvider;
|
||||
|
||||
class PermissionsServiceProvider extends CatchModuleServiceProvider
|
||||
{
|
||||
/**
|
||||
* route path
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function routePath(): string|array
|
||||
{
|
||||
// TODO: Implement path() method.
|
||||
return CatchAdmin::getModuleRoutePath('Permissions');
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('roles', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('role_name', 30)->comment('角色名称');
|
||||
$table->string('identify', 30)->nullable()->comment('角色的标识,用英文表示');
|
||||
$table->integer('parent_id')->default(0)->comment('父级ID');
|
||||
$table->string('description')->nullable()->comment('角色描述');
|
||||
$table->smallInteger('data_range')->default(0)->comment('1 全部数据 2 自定义数据 3 仅本人数据 4 部门数据 5 部门及以下数据');
|
||||
$table->creatorId();
|
||||
$table->createdAt();
|
||||
$table->updatedAt();
|
||||
$table->deletedAt();
|
||||
|
||||
$table->engine = 'InnoDB';
|
||||
$table->comment('角色表');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
11
modules/Permissions/route.php
Normal file
11
modules/Permissions/route.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Permissions\Http\Controllers\RolesController;
|
||||
|
||||
Route::prefix('permissions')->group(function () {
|
||||
|
||||
Route::apiResource('roles', RolesController::class);
|
||||
//next
|
||||
});
|
||||
|
95
modules/Permissions/views/roles/create.vue
Normal file
95
modules/Permissions/views/roles/create.vue
Normal file
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-6">
|
||||
<el-form-item label="上级角色" prop="parent_id">
|
||||
<el-cascader :options="roles" name="parent_id" v-model="formData.parent_id" clearable :props="{ value: 'id', label: 'role_name', checkStrictly: true }" class="w-full" />
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="角色名称"
|
||||
prop="role_name"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
message: '角色名称必须填写',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input v-model="formData.role_name" name="role_name" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="角色标识"
|
||||
prop="identify"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
message: '角色标识必须填写',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input v-model="formData.identify" name="identify" clearable />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="角色描述" prop="description">
|
||||
<el-input v-model="formData.description" name="description" clearable type="textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="数据权限" prop="data_range">
|
||||
<Select v-model="formData.data_range" name="data_range" clearable api="dataRange" class="w-full" />
|
||||
</el-form-item>
|
||||
<div class="flex justify-end">
|
||||
<el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useCreate } from '/admin/composables/curd/useCreate'
|
||||
import { useShow } from '/admin/composables/curd/useShow'
|
||||
import { onMounted, ref, watch } from 'vue'
|
||||
import http from '/admin/support/http'
|
||||
|
||||
const props = defineProps({
|
||||
primary: String | Number,
|
||||
api: String,
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close'])
|
||||
|
||||
const { formData, form, loading, submitForm, isClose, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
|
||||
|
||||
beforeCreate.value = () => {
|
||||
formData.value.parent_id = getParent(formData.value.parent_id)
|
||||
}
|
||||
|
||||
beforeUpdate.value = () => {
|
||||
formData.value.parent_id = getParent(formData.value.parent_id)
|
||||
}
|
||||
|
||||
const getParent = (parentId: any) => {
|
||||
return typeof parentId === 'undefined' ? 0 : parentId[parentId.length - 1]
|
||||
}
|
||||
|
||||
watch(isClose, function (value) {
|
||||
if (value) {
|
||||
emit('close')
|
||||
}
|
||||
})
|
||||
|
||||
const roles = ref()
|
||||
|
||||
onMounted(() => {
|
||||
if (props.primary) {
|
||||
useShow(props.api, props.primary).then(r => {
|
||||
r.data.parent_id = r.data.parent_id ? [r.data.parent_id ] : 0;
|
||||
|
||||
formData.value = r.data
|
||||
|
||||
if (!formData.value.data_range) {
|
||||
formData.value.data_range = null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
http.get(props.api).then(r => {
|
||||
roles.value = r.data.data
|
||||
})
|
||||
})
|
||||
</script>
|
80
modules/Permissions/views/roles/index.vue
Normal file
80
modules/Permissions/views/roles/index.vue
Normal file
@@ -0,0 +1,80 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="w-full min-h-0 bg-white dark:bg-regal-dark pl-5 pt-5 pr-5 rounded-lg">
|
||||
<el-form :inline="true">
|
||||
<el-form-item label="角色名称" prop="role_name">
|
||||
<el-input v-model="query.role_name" name="role_name" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search()">
|
||||
<Icon name="magnifying-glass" class="w-4 mr-1 -ml-1" />
|
||||
搜索
|
||||
</el-button>
|
||||
<el-button @click="reset()">
|
||||
<Icon name="arrow-path" class="w-4 mr-1 -ml-1" />
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-10">
|
||||
<div class="pt-5 pl-2">
|
||||
<Add @click="show(null)" />
|
||||
</div>
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }">
|
||||
<el-table-column prop="role_name" label="角色名称" />
|
||||
<el-table-column prop="identify" label="角色标识" />
|
||||
<el-table-column prop="description" label="角色描述" />
|
||||
<el-table-column prop="created_at" label="创建时间" />
|
||||
<el-table-column label="操作" width="200">
|
||||
<template #default="scope">
|
||||
<Update @click="show(scope.row.id)" />
|
||||
<Destroy @click="destroy(api, scope.row.id)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<Dialog v-model="visible" :title="title" destroy-on-close>
|
||||
<Create @close="close" :primary="id" :api="api" />
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import Create from './create.vue'
|
||||
import { useGetList } from '/admin/composables/curd/useGetList'
|
||||
import { useDestroy } from '/admin/composables/curd/useDestroy'
|
||||
import { useEnabled } from '/admin/composables/curd/useEnabled'
|
||||
import { t } from '/admin/support/helper'
|
||||
|
||||
const visible = ref<boolean>(false)
|
||||
const id = ref(null)
|
||||
const api = 'permissions/roles'
|
||||
const title = ref<string>('')
|
||||
|
||||
const { data, query, search, reset, loading } = useGetList(api)
|
||||
|
||||
const { destroy, isDeleted } = useDestroy()
|
||||
|
||||
onMounted(() => search())
|
||||
|
||||
const tableData = computed(() => data.value?.data)
|
||||
|
||||
const close = () => {
|
||||
visible.value = false
|
||||
reset()
|
||||
}
|
||||
|
||||
const show = primary => {
|
||||
title.value = primary ? t('system.edit') : t('system.add')
|
||||
id.value = primary
|
||||
visible.value = true
|
||||
}
|
||||
|
||||
watch(isDeleted, function () {
|
||||
// change origin status
|
||||
isDeleted.value = false
|
||||
reset()
|
||||
})
|
||||
</script>
|
20
modules/Permissions/views/router.ts
Normal file
20
modules/Permissions/views/router.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
// @ts-ignore
|
||||
const router: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/permission',
|
||||
component: () => import('/admin/layout/index.vue'),
|
||||
meta: { title: '权限管理', icon: 'user' },
|
||||
children: [
|
||||
{
|
||||
path: 'roles',
|
||||
name: 'roles',
|
||||
meta: { title: '角色管理', icon: 'home' },
|
||||
component: () => import('./roles/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export default router
|
Reference in New Issue
Block a user