feat: 分离前端列表
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Permissions\Enums;
|
||||
|
||||
use Catch\Enums\Enum;
|
||||
|
44
modules/Permissions/Http/Controllers/JobsController.php
Normal file
44
modules/Permissions/Http/Controllers/JobsController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Permissions\Http\Controllers;
|
||||
|
||||
use Catch\Base\CatchController as Controller;
|
||||
use Modules\Permissions\Models\JobsModel;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class JobsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly JobsModel $model
|
||||
){}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(Request $request): mixed
|
||||
{
|
||||
return $this->model->getList();
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $this->model->storeBy($request->all());
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return $this->model->firstBy($id);
|
||||
}
|
||||
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
return $this->model->updateBy($id, $request->all());
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return $this->model->deleteBy($id);
|
||||
}
|
||||
}
|
@@ -1,19 +1,19 @@
|
||||
<?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
|
||||
|
@@ -17,7 +17,7 @@ class RoleRequest extends FormRequest
|
||||
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')),
|
||||
'identify' => sprintf('required|alpha|unique:%s,%s,%s', RolesModel::class, 'role_name', $this->get('id')),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -41,4 +41,4 @@ class RoleRequest extends FormRequest
|
||||
'identify.unique' => '角色标识已存在',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
modules/Permissions/Models/JobsModel.php
Normal file
45
modules/Permissions/Models/JobsModel.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Permissions\Models;
|
||||
|
||||
use Catch\Base\CatchModel as Model;
|
||||
|
||||
/**
|
||||
* @property $id
|
||||
* @property $job_name
|
||||
* @property $coding
|
||||
* @property $status
|
||||
* @property $sort
|
||||
* @property $description
|
||||
* @property $creator_id
|
||||
* @property $created_at
|
||||
* @property $updated_at
|
||||
* @property $deleted_at
|
||||
*/
|
||||
class JobsModel extends Model
|
||||
{
|
||||
protected $table = 'jobs';
|
||||
|
||||
protected $fillable = [ 'id', 'job_name', 'coding', 'status', 'sort', 'description', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $fieldsInList = ['id','job_name','coding','status','sort','description','created_at','updated_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $form = ['job_name','coding','status','sort','description'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $searchable = [
|
||||
'job_name' => 'like'
|
||||
];
|
||||
|
||||
|
||||
}
|
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace Modules\Permissions\Models;
|
||||
|
||||
use Catch\Base\CatchModel as Model;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
/**
|
||||
* @property $role_name
|
||||
@@ -22,7 +21,7 @@ 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' ];
|
||||
protected $fillable = ['id', 'role_name', 'identify', 'parent_id', 'description', 'data_range', 'creator_id', 'created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@@ -49,5 +48,4 @@ class RolesModel extends Model
|
||||
{
|
||||
return self::query()->select($this->fieldsInList)->quickSearch()->get()->toTree();
|
||||
}
|
||||
|
||||
}
|
||||
|
42
modules/Permissions/Providers/Installer.php
Normal file
42
modules/Permissions/Providers/Installer.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Permissions\Providers;
|
||||
|
||||
use Catch\Support\Module\Installer as ModuleInstaller;
|
||||
|
||||
class Installer extends ModuleInstaller
|
||||
{
|
||||
protected function info(): array
|
||||
{
|
||||
// TODO: Implement info() method.
|
||||
return [
|
||||
'name' => '权限管理',
|
||||
'path' => 'Permissions',
|
||||
'keywords' => '权限, 角色, 部门',
|
||||
'description' => '权限管理模块',
|
||||
'provider' => PermissionsServiceProvider::class
|
||||
];
|
||||
}
|
||||
|
||||
protected function migration(): string
|
||||
{
|
||||
// TODO: Implement migration() method.
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function seeder(): string
|
||||
{
|
||||
// TODO: Implement seeder() method.
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function requirePackages(): void
|
||||
{
|
||||
// TODO: Implement requirePackages() method.
|
||||
}
|
||||
|
||||
protected function removePackages(): void
|
||||
{
|
||||
// TODO: Implement removePackages() method.
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?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('jobs', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('job_name', 50)->comment('岗位名称');
|
||||
$table->string('coding', 30)->nullable()->comment('创建人ID');
|
||||
$table->tinyInteger('status')->default('1')->comment('1 正常 2 停用');
|
||||
$table->integer('sort')->default('1')->comment('排序');
|
||||
$table->string('description', 1000)->nullable()->comment('岗位描述');
|
||||
$table->creatorId();
|
||||
$table->createdAt();
|
||||
$table->updatedAt();
|
||||
$table->deletedAt();
|
||||
|
||||
$table->engine='InnoDB';
|
||||
$table->comment('岗位表');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
}
|
||||
};
|
@@ -2,10 +2,12 @@
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Permissions\Http\Controllers\RolesController;
|
||||
use Modules\Permissions\Http\Controllers\JobsController;
|
||||
|
||||
Route::prefix('permissions')->group(function () {
|
||||
Route::apiResource('roles', RolesController::class);
|
||||
|
||||
Route::apiResource('roles', RolesController::class);
|
||||
Route::apiResource('jobs', JobsController::class);
|
||||
//next
|
||||
});
|
||||
|
||||
|
62
modules/Permissions/views/jobs/create.vue
Normal file
62
modules/Permissions/views/jobs/create.vue
Normal file
@@ -0,0 +1,62 @@
|
||||
<template>
|
||||
<el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
|
||||
<el-form-item label="岗位名称" prop="job_name" :rules="[{ required: true, message: '岗位名称必须填写' }]">
|
||||
<el-input v-model="formData.job_name" name="job_name" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="岗位编码" prop="coding">
|
||||
<el-input v-model="formData.coding" name="coding" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio v-for="item in options" :key="item.value" :label="item.value" name="status">{{ item.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number v-model="formData.sort" name="sort" :min="1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="岗位描述" prop="description">
|
||||
<el-input v-model="formData.description" name="description" clearable type="textarea" />
|
||||
</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, watch } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
primary: String | Number,
|
||||
api: String,
|
||||
})
|
||||
|
||||
const emit = defineEmits(['close'])
|
||||
|
||||
const { formData, form, loading, submitForm, isClose } = useCreate(props.api, props.primary)
|
||||
|
||||
formData.value.status = 1
|
||||
formData.value.sort = 1
|
||||
|
||||
watch(isClose, function (value) {
|
||||
if (value) {
|
||||
emit('close')
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (props.primary) {
|
||||
useShow(props.api, props.primary).then(r => {
|
||||
formData.value = r.data
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const options = [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
]
|
||||
</script>
|
68
modules/Permissions/views/jobs/index.vue
Normal file
68
modules/Permissions/views/jobs/index.vue
Normal file
@@ -0,0 +1,68 @@
|
||||
<template>
|
||||
<div>
|
||||
<Search :search="search" :reset="reset">
|
||||
<template v-slot:body>
|
||||
<el-form-item label="岗位名称" prop="job_name">
|
||||
<el-input v-model="query.job_name" name="job_name" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</Search>
|
||||
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4">
|
||||
<Operate :show="show" />
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
||||
<el-table-column prop="job_name" label="岗位名称" />
|
||||
<el-table-column prop="coding" label="岗位编码" />
|
||||
<el-table-column prop="status" label="状态" />
|
||||
<el-table-column prop="sort" label="排序" />
|
||||
<el-table-column prop="description" 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>
|
||||
<Paginate />
|
||||
</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 { t } from '/admin/support/helper'
|
||||
|
||||
const visible = ref<boolean>(false)
|
||||
const id = ref(null)
|
||||
const api = 'permissions/jobs'
|
||||
const title = ref<string>('')
|
||||
|
||||
// const { data, query, search, reset, loading } = useGetList(api)
|
||||
const { data, query, search, reset, loading } = useGetList(api)
|
||||
const { destroy, deleted } = useDestroy()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
search()
|
||||
|
||||
deleted(reset)
|
||||
})
|
||||
</script>
|
@@ -13,6 +13,12 @@ const router: RouteRecordRaw[] = [
|
||||
meta: { title: '角色管理', icon: 'home' },
|
||||
component: () => import('./roles/index.vue'),
|
||||
},
|
||||
{
|
||||
path: 'jobs',
|
||||
name: 'jobs',
|
||||
meta: { title: '岗位管理', icon: 'home' },
|
||||
component: () => import('./jobs/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
Reference in New Issue
Block a user