feat: permissions

This commit is contained in:
JaguarJack 2022-12-07 19:28:57 +08:00
parent a1d9468a91
commit 8c537e6656
45 changed files with 1030 additions and 372 deletions

View File

@ -32,4 +32,6 @@ interface ModuleRepositoryInterface
public function disOrEnable(string $name): bool|int;
public function getEnabled(): Collection;
public function enabled(string $moduleName): bool;
}

View File

@ -135,6 +135,18 @@ class DatabaseDriver implements ModuleRepositoryInterface
return $this->model->where('status', Status::Enable->value())->get();
}
/**
* enabled
*
* @param string $moduleName
* @return bool
*/
public function enabled(string $moduleName): bool
{
// TODO: Implement enabled() method.
return $this->getEnabled()->pluck('path')->contains($moduleName);
}
/**
*
* @param array $module

View File

@ -172,6 +172,17 @@ class FileDriver implements ModuleRepositoryInterface
return $this->all()->where('enable', true)->values();
}
/**
* enabled
* @param string $moduleName
* @return bool
*/
public function enabled(string $moduleName): bool
{
// TODO: Implement enabled() method.
return $this->getEnabled()->pluck('path')->contains($moduleName);
}
/**
*
* @param array $module

View File

@ -141,4 +141,15 @@ class ModuleRepository
// TODO: Implement getEnabled() method.
return $this->moduleRepository->getEnabled();
}
/**
* enabled
*
* @param string $moduleName
* @return bool
*/
public function enabled(string $moduleName): bool
{
return $this->moduleRepository->enabled($moduleName);
}
}

View File

@ -15,7 +15,9 @@ declare(strict_types=1);
namespace Catch\Traits\DB;
use Catch\Enums\Status;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Request;
/**
@ -27,6 +29,12 @@ trait BaseOperate
protected bool $sortDesc = true;
/**
* @var string
*/
protected string $parentId = 'parent_id';
/**
*
*
@ -178,7 +186,36 @@ trait BaseOperate
$model->{$field} = $model->{$field} == Status::Enable->value() ? Status::Disable->value() : Status::Enable->value();
return $model->save();
if ($model->save() && in_array($this->parentId, $this->getFillable())) {
$this->updateChildren($id, $field, $model->{$field});
}
return true;
}
/**
* 递归处理
*
* @param int|array $parentId
* @param string $field
* @param int $value
*/
public function updateChildren(mixed $parentId, string $field, mixed $value): void
{
if (! $parentId instanceof Arrayable) {
$parentId = Collection::make([$parentId]);
}
$childrenId = $this->whereIn('parent_id', $parentId)->pluck('id');
if ($childrenId->count()) {
if ($this->whereIn('parent_id', $parentId)->update([
$field => $value
])) {
$this->updateChildren($childrenId, $field, $value);
}
}
}
/**

View File

@ -64,6 +64,10 @@ class FrontTable extends Creator
*/
protected string $useList = '{useList}';
/**
* @var string
*/
protected string $tree = '{tree}';
/**
* @var array
@ -91,13 +95,14 @@ class FrontTable extends Creator
{
// TODO: Implement getContent() method.
return Str::of(File::get($this->getTableStub()))->replace([
$this->table, $this->search, $this->api, $this->paginate, $this->useList
$this->table, $this->search, $this->api, $this->paginate, $this->useList, $this->tree
], [
$this->getTableContent(),
$this->getSearchContent(),
$this->apiString,
$this->getPaginateStubContent(),
$this->getUseList()
$this->getUseList(),
$this->getTreeProps()
])->toString();
}
@ -230,6 +235,20 @@ HTML;
return 'const { data, query, search, reset, loading } = useGetList(api)';
}
/**
* get tree props
*
* @return string
*/
public function getTreeProps(): string
{
if (in_array('parent_id', array_column($this->structures, 'field'))) {
return ' row-key="id" default-expand-all :tree-props="{ children: \'children\' }"';
}
return ' ';
}
/**
* set structures
*

View File

@ -128,8 +128,11 @@ class Schema extends Creator
$column = $column->nullable($structure['nullable']);
if ($structure['default']) {
$column = $column->default($structure['default']);
if (is_null($structure['default'])) {
} else {
if (is_numeric($structure['default']) || mb_strlen($structure['default'])) {
$column = $column->default($structure['default']);
}
}
if ($structure['comment']) {
@ -206,6 +209,7 @@ class Schema extends Creator
})
->when(isset($structure['default']), function ($str, $default) {
if (is_numeric($default)) {
$default = intval($default);
return $str->append("->default({$default})");
}

View File

@ -16,7 +16,7 @@ class {controller} extends Controller
* @param Request $request
* @return mixed
*/
public function index(Request $request): mixed
public function index(): mixed
{
return $this->model->getList();
}

View File

@ -10,29 +10,21 @@
<script lang="ts" setup>
import { useCreate } from '/admin/composables/curd/useCreate'
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted, watch } from 'vue'
import { onMounted } from 'vue'
const props = defineProps({
primary: String | Number,
api: String,
})
const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)
if (props.primary) {
useShow(props.api, props.primary, formData)
}
const emit = defineEmits(['close'])
const { formData, form, loading, submitForm, isClose } = useCreate(props.api, props.primary)
watch(isClose, function (value) {
if (value) {
emit('close')
}
})
onMounted(() => {
if (props.primary) {
useShow(props.api, props.primary).then(r => {
formData.value = r.data
})
}
close(() => emit('close'))
})
</script>

View File

@ -1,5 +1,5 @@
<el-form-item label="{label}" prop="{prop}">
<el-select v-model="{model-value}" placeholder="请选择" clearable ${multiple}>
<el-select v-model="{model-value}" placeholder="请选择" clearable multiple>
<el-option
v-for="item in options"
:key="item.value"

View File

@ -5,13 +5,13 @@
{search}
</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">
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-10">
<Operate :show="open" />
<el-table :data="tableData" class="mt-3" v-loading="loading"{tree}>
{table}
<el-table-column label="操作" width="200">
<template #default="scope">
<Update @click="show(scope.row.id)" />
<Update @click="open(scope.row.id)" />
<Destroy @click="destroy(api, scope.row.id)" />
</template>
</el-table-column>
@ -20,43 +20,28 @@
</div>
<Dialog v-model="visible" :title="title" destroy-on-close>
<Create @close="close" :primary="id" :api="api" />
<Create @close="close(reset)" :primary="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted } 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'
import { useOpen } from '/admin/composables/curd/useOpen'
const visible = ref<boolean>(false)
const id = ref(null)
const api = '{api}'
const title = ref<string>('')
// const { data, query, search, reset, loading } = useGetList(api)
{useList}
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()
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>

View File

@ -48,7 +48,7 @@
import { useCreate } from '/admin/composables/curd/useCreate'
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted, watch } from 'vue'
import { computed, onMounted, watch } from 'vue'
const props = defineProps({
primary: String | Number,
@ -79,11 +79,7 @@ watch(isClose, function (value) {
}
})
onMounted(() => {
if (props.primary) {
useShow(props.api, props.primary).then(r => {
formData.value = r.data
})
}
})
if (props.primary) {
useShow(props.api, props.primary, formData)
}
</script>

View File

@ -1,26 +1,14 @@
<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">
<Search :search="search" :reset="reset">
<template v-slot:body>
<el-form-item label="模块名称">
<el-input v-model="query.name" name="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">
<div class="pt-5 pl-2">
<Add @click="show(null)" />
</div>
</template>
</Search>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
<Operate :show="open" />
<el-table :data="tableData" class="mt-3" v-loading="loading">
<el-table-column prop="name" label="模块名称" width="180" />
<el-table-column prop="path" label="模块目录" width="180" />
@ -31,31 +19,17 @@
</el-table-column>
<el-table-column prop="enable" label="模块状态">
<template #default="scope">
<el-switch v-model="scope.row.enable" @change="enabled(api, scope.row.name)" />
<Status v-model="scope.row.status" :id="scope.row.id" :api="api" />
</template>
</el-table-column>
<el-table-column label="操作" width="300">
<template #default="scope">
<Update @click="show(scope.row.name)" />
<Update @click="open(scope.row.name)" />
<Destroy @click="destroy(api, scope.row.name)" />
</template>
</el-table-column>
</el-table>
<div class="pt-2 pb-2 flex justify-end">
<el-pagination
background
layout="total,sizes,prev, pager,next"
:current-page="query.page"
:page-size="query.limit"
@current-change="changePage"
@size-change="changeLimit"
:total="total"
:page-sizes="[10, 20, 30, 50]"
/>
</div>
</div>
<Dialog v-model="visible" :title="title" destroy-on-close>
<Create @close="close" :primary="id" :api="api" />
</Dialog>
@ -63,41 +37,23 @@
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted } 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'
import Sortable from 'sortablejs'
import { useOpen } from '/admin/composables/curd/useOpen'
const visible = ref<boolean>(false)
const id = ref(null)
const api = 'module'
const title = ref<string>('')
const { data, query, search, reset, changePage, changeLimit, loading } = useGetList(api)
const { destroy, isDeleted } = useDestroy('确认删除吗? ⚠️将会删除模块下所有文件')
const { enabled } = useEnabled()
onMounted(() => search())
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy('确认删除吗? ⚠️将会删除模块下所有文件')
const { open, close, title, visible, id } = useOpen()
const tableData = computed(() => data.value?.data)
const total = computed(() => data.value?.total)
const close = () => {
visible.value = false
reset()
}
onMounted(() => {
search()
const show = primary => {
title.value = primary ? t('system.edit') : t('system.add')
id.value = primary
visible.value = true
}
watch(isDeleted, function () {
isDeleted.value = false
reset()
deleted()
})
</script>

View File

@ -18,7 +18,7 @@ const next = () => {
active.value = 2
}
}
console.log(123)
const prev = () => {
if (active.value-- === 1) {
active.value = 1
@ -26,10 +26,12 @@ const prev = () => {
}
const emit = defineEmits(['close'])
watch(() => schemaStore.getFinished, function (value){
if (value) {
emit('close')
}
})
watch(
() => schemaStore.getFinished,
function (value) {
if (value) {
emit('close')
}
},
)
</script>

View File

@ -1,35 +1,23 @@
<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">
<Search :search="search" :reset="reset">
<template v-slot:body>
<el-form-item label="模块名称">
<el-input v-model="query.module" name="module" clearable />
</el-form-item>
<el-form-item label="Schema 名称">
<el-input v-model="query.name" name="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">
<div class="pt-5 pl-2">
<Add @click="add(null)" />
</div>
</template>
</Search>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
<Operate :show="open" />
<el-table :data="tableData" class="mt-3" v-loading="loading">
<el-table-column prop="module" label="所属模块" />
<el-table-column prop="name" label="schema 名称" />
<el-table-column prop="columns" label="字段">
<template #default="scope">
<el-button size="small" type="success" @click="show(scope.row.id)"><Icon name="eye" class="w-3 mr-1" /> 查看</el-button>
<el-button size="small" type="success" @click="view(scope.row.id)"><Icon name="eye" class="w-3 mr-1" /> 查看</el-button>
</template>
</el-table-column>
<el-table-column prop="is_soft_delete" label="?软删">
@ -48,73 +36,48 @@
</template>
</el-table-column>
</el-table>
<div class="pt-2 pb-2 flex justify-end">
<el-pagination
background
layout="total,sizes,prev, pager,next"
:current-page="query.page"
:page-size="query.limit"
@current-change="changePage"
@size-change="changeLimit"
:total="total"
:page-sizes="[10, 20, 30, 50]"
/>
</div>
<Paginate />
</div>
<!-- schema 创建 -->
<Dialog v-model="visible" :title="$t('generate.schema.title')" width="650px" destroy-on-close>
<Create @close="close" :primary="id" :api="api" />
<Dialog v-model="visible" :title="title" width="650px" destroy-on-close>
<Create @close="close(reset)" :api="api" />
</Dialog>
<!-- schema 表结构 -->
<Dialog v-model="showVisible" title="Schema 结构" width="650px" destroy-on-close>
<Dialog v-model="schemaVisible" title="Schema 结构" width="650px" destroy-on-close>
<Show :id="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted, ref } from 'vue'
import Create from './create.vue'
import Show from './show.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
const visible = ref<boolean>(false)
const showVisible = ref<boolean>(false)
const schemaVisible = ref<boolean>(false)
const id = ref<number>()
const api = 'schema'
const title = ref<string>('')
const { data, query, search, reset, changePage, changeLimit, loading } = useGetList(api)
const { destroy, isDeleted } = useDestroy('确认删除吗? 将会删除数据库的 Schema请提前做好备份一旦删除将无法恢复!')
onMounted(() => search())
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy('确认删除吗? 将会删除数据库的 Schema请提前做好备份一旦删除将无法恢复!')
const { open, close, title, visible, id } = useOpen()
const tableData = computed(() => data.value?.data)
const total = computed(() => data.value?.total)
const close = () => {
visible.value = false
reset()
}
const add = () => {
visible.value = true
}
const show = primaryId => {
showVisible.value = true
const view = primaryId => {
schemaVisible.value = true
id.value = primaryId
}
watch(isDeleted, function () {
isDeleted.value = false
reset()
onMounted(() => {
search()
deleted(reset)
})
</script>

View File

@ -1,5 +1,5 @@
<template>
<el-table :data="data" class="mt-3" v-loading="loading">
<el-table :data="data?.columns" class="mt-3" v-loading="loading">
<el-table-column prop="name" label="字段名称" />
<el-table-column prop="type" label="类型" />
<el-table-column prop="nullable" label="nullable">
@ -17,8 +17,6 @@
<script lang="ts" setup>
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted } from 'vue'
import { ref } from 'vue'
const props = defineProps({
id: {
type: Number,
@ -26,13 +24,8 @@ const props = defineProps({
},
})
const data = ref<Array<object>>()
onMounted(() => {
useShow('schema', props.id).then(r => {
data.value = r.data.columns
})
})
// const data = ref<Array<object>>()
const { data, loading } = useShow('schema', props.id)
</script>
<style scoped></style>

View File

@ -75,7 +75,7 @@ schemaStore.start()
const emits = defineEmits(['prev', 'next'])
const schema = reactive(schemaStore.getSchema)
const schema = ref(schemaStore.getSchema)
const form = ref<FormInstance>()
const submitCreateTable = (formEl: FormInstance | undefined) => {
if (!formEl) return

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Modules\Permissions\Http\Controllers;
use Catch\Base\CatchController as Controller;
use Modules\Permissions\Models\DepartmentsModel;
use Illuminate\Http\Request;
class DepartmentsController extends Controller
{
public function __construct(
protected readonly DepartmentsModel $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);
}
public function enable($id)
{
return $this->model->disOrEnable($id);
}
}

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Modules\Permissions\Http\Controllers;
@ -11,7 +12,8 @@ class JobsController extends Controller
{
public function __construct(
protected readonly JobsModel $model
){}
) {
}
/**
* @param Request $request
@ -41,4 +43,9 @@ class JobsController extends Controller
{
return $this->model->deleteBy($id);
}
public function enable($id)
{
return $this->model->disOrEnable($id);
}
}

View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Modules\Permissions\Http\Controllers;
use Catch\Base\CatchController as Controller;
use Modules\Permissions\Models\PermissionsModel;
use Illuminate\Http\Request;
class PermissionsController extends Controller
{
public function __construct(
protected readonly PermissionsModel $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);
}
}

View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Modules\Permissions\Models;
use Catch\Base\CatchModel as Model;
/**
* @property $id
* @property $parent_id
* @property $department_name
* @property $principal
* @property $mobile
* @property $email
* @property $status
* @property $sort
* @property $creator_id
* @property $created_at
* @property $updated_at
* @property $deleted_at
*/
class DepartmentsModel extends Model
{
protected $table = 'departments';
protected $fillable = ['id', 'parent_id', 'department_name', 'principal', 'mobile', 'email', 'status', 'sort', 'creator_id', 'created_at', 'updated_at', 'deleted_at'];
/**
* @var array
*/
protected array $fieldsInList = ['id','parent_id','department_name','status','sort','created_at'];
/**
* @var array
*/
protected array $form = ['parent_id','department_name','principal','mobile','email','sort'];
/**
* @var array
*/
public array $searchable = [
'department_name' => 'like',
'status' => '=',
];
public function getList(): mixed
{
return self::query()->select($this->fieldsInList)->quickSearch()->get()->toTree();
}
}

View File

@ -22,7 +22,7 @@ class JobsModel extends Model
{
protected $table = 'jobs';
protected $fillable = [ 'id', 'job_name', 'coding', 'status', 'sort', 'description', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];
protected $fillable = ['id', 'job_name', 'coding', 'status', 'sort', 'description', 'creator_id', 'created_at', 'updated_at', 'deleted_at'];
/**
* @var array
@ -40,6 +40,4 @@ class JobsModel extends Model
public array $searchable = [
'job_name' => 'like'
];
}

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Modules\Permissions\Models;
use Catch\Base\CatchModel as Model;
/**
* @property $id
* @property $parent_id
* @property $permission_name
* @property $route
* @property $icon
* @property $module
* @property $permission_mark
* @property $component
* @property $redirect
* @property $keepalive
* @property $type
* @property $hidden
* @property $sort
* @property $creator_id
* @property $created_at
* @property $updated_at
* @property $deleted_at
*/
class PermissionsModel extends Model
{
protected $table = 'permissions';
protected $fillable = ['id', 'parent_id', 'permission_name', 'route', 'icon', 'module', 'permission_mark', 'component', 'redirect', 'keepalive', 'type', 'hidden', 'sort', 'creator_id', 'created_at', 'updated_at', 'deleted_at'];
/**
* @var array
*/
protected array $fieldsInList = ['id','parent_id','permission_name','route','icon','module','permission_mark','component','redirect','keepalive','type','hidden','sort','created_at','updated_at'];
/**
* @var array
*/
protected array $form = ['parent_id','permission_name','route','icon','module','permission_mark','component','redirect','keepalive','type','hidden','sort'];
/**
* @var array
*/
public array $searchable = [
'permission_name' => 'like',
];
/**
* @return mixed
*/
public function getList(): mixed
{
return self::query()->select($this->fieldsInList)->quickSearch()->get()->toTree();
}
}

View File

@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*
@ -15,18 +14,18 @@ return new class extends Migration
{
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->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('岗位表');
$table->engine = 'InnoDB';
$table->comment('岗位表');
});
}

View File

@ -0,0 +1,43 @@
<?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('departments', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')->default(0)->comment('父级ID');
$table->string('department_name')->comment('部门名称');
$table->string('principal')->nullable()->comment('负责人');
$table->string('mobile', 30)->nullable()->comment('负责人联系方式');
$table->string('email', 50)->nullable()->comment('邮箱');
$table->smallInteger('status')->default(1)->comment('1 正常 2 停用');
$table->integer('sort')->default(1)->comment('排序');
$table->creatorId();
$table->createdAt();
$table->updatedAt();
$table->deletedAt();
$table->engine = 'InnoDB';
$table->comment('部门表');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('departments');
}
};

View File

@ -0,0 +1,48 @@
<?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('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('permission_name', 30)->comment('菜单名称');
$table->integer('parent_id')->default('1')->comment('父级菜单');
$table->string('route', 50)->comment('路由');
$table->string('icon', 50)->comment('菜单 icon');
$table->string('module', 50)->comment('所属模块');
$table->string('permission_mark')->comment('权限标识');
$table->string('component')->comment('组件');
$table->string('redirect')->comment('组件跳转');
$table->tinyInteger('keepalive')->default('1')->comment('1 缓存 2 不缓存');
$table->tinyInteger('type')->default('1')->comment('1 菜单 2 按钮');
$table->tinyInteger('hidden')->default('1')->comment('1 显示 2 隐藏');
$table->integer('sort')->default('1')->comment('排序');
$table->creatorId();
$table->createdAt();
$table->updatedAt();
$table->deletedAt();
$table->engine = 'InnoDB';
$table->comment('权限模块');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permissions');
}
};

View File

@ -0,0 +1,48 @@
<?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('permissions', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id')->default(0)->comment('父级菜单');
$table->string('permission_name', 50)->comment('菜单名称');
$table->string('route', 50)->comment('前端路由');
$table->string('icon', 50)->comment('菜单 icon');
$table->string('module', 50)->comment('所属模块');
$table->string('permission_mark', 100)->comment('权限标识,使用 @ 分割');
$table->string('component')->comment('组件');
$table->string('redirect')->nullable()->comment('跳转地址');
$table->tinyInteger('keepalive')->default('1')->comment('1 缓存 2 不缓存');
$table->tinyInteger('type')->default('1')->comment('1 目录 2 菜单 3 按钮');
$table->tinyInteger('hidden')->default('1')->comment('1 显示 2 隐藏');
$table->integer('sort')->default('1')->comment('排序');
$table->creatorId();
$table->createdAt();
$table->updatedAt();
$table->deletedAt();
$table->engine = 'InnoDB';
$table->comment('权限表');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permissions');
}
};

View File

@ -3,11 +3,18 @@
use Illuminate\Support\Facades\Route;
use Modules\Permissions\Http\Controllers\RolesController;
use Modules\Permissions\Http\Controllers\JobsController;
use Modules\Permissions\Http\Controllers\DepartmentsController;
use Modules\Permissions\Http\Controllers\PermissionsController;
Route::prefix('permissions')->group(function () {
Route::apiResource('roles', RolesController::class);
Route::apiResource('jobs', JobsController::class);
//next
});
Route::apiResource('jobs', JobsController::class);
Route::put('jobs/enable/{id}', [JobsController::class, 'enable']);
Route::apiResource('departments', DepartmentsController::class);
Route::put('departments/enable/{id}', [DepartmentsController::class, 'enable']);
Route::apiResource('permissions', PermissionsController::class);
//next
});

View File

@ -0,0 +1,79 @@
<template>
<el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
<el-form-item label="父级部门" prop="parent_id">
<el-cascader :options="departments" name="parent_id" v-model="formData.parent_id" clearable :props="{ value: 'id', label: 'department_name', checkStrictly: true }" class="w-full" />
</el-form-item>
<el-form-item label="部门名称" prop="department_name" :rules="[{ required: true, message: '部门名称必须填写' }]">
<el-input v-model="formData.department_name" name="department_name" clearable />
</el-form-item>
<el-form-item label="部门联系人" prop="principal">
<el-input v-model="formData.principal" name="principal" clearable />
</el-form-item>
<el-form-item label="手机号" prop="mobile">
<el-input v-model="formData.mobile" name="mobile" clearable />
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="formData.email" name="email" clearable />
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input-number v-model="formData.sort" name="sort" :min="1" />
</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 http from '/admin/support/http'
import { onMounted, ref, unref } from 'vue'
const props = defineProps({
primary: String | Number,
api: String,
})
const { formData, form, loading, submitForm, close, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
formData.value.sort = 1
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]
}
if (props.primary) {
const { afterShow } = useShow(props.api, props.primary, formData)
afterShow.value = formData => {
const data = unref(formData)
data.parent_id = data.parent_id ? [data.parent_id] : 0
if (!data.data_range) {
data.data_range = null
}
formData.value = data
}
}
const emit = defineEmits(['close'])
const departments = ref()
onMounted(() => {
http.get(props.api).then(r => {
departments.value = r.data.data
})
close(() => {
emit('close')
})
})
</script>

View File

@ -0,0 +1,56 @@
<template>
<div>
<Search :search="search" :reset="reset">
<template v-slot:body>
<el-form-item label="部门名称" prop="department_name">
<el-input v-model="query.department_name" name="department_name" clearable />
</el-form-item>
</template>
</Search>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
<Operate :show="open" />
<el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }">
<el-table-column prop="department_name" label="部门名称" />
<el-table-column prop="sort" label="排序" />
<el-table-column prop="status" label="状态">
<template #default="scope">
<Status v-model="scope.row.status" :id="scope.row.id" :api="api" @refresh="search" />
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" />
<el-table-column label="操作" width="200">
<template #default="scope">
<Update @click="open(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(reset)" :primary="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
const api = 'permissions/departments'
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()
const tableData = computed(() => data.value?.data)
onMounted(() => {
search()
deleted(reset)
})
</script>

View File

@ -27,32 +27,25 @@
import { useCreate } from '/admin/composables/curd/useCreate'
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted, watch } from 'vue'
import { onMounted } 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)
const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)
formData.value.status = 1
formData.value.sort = 1
watch(isClose, function (value) {
if (value) {
emit('close')
}
})
if (props.primary) {
useShow(props.api, props.primary, formData)
}
const emit = defineEmits(['close'])
onMounted(() => {
if (props.primary) {
useShow(props.api, props.primary).then(r => {
formData.value = r.data
})
}
close(() => emit('close'))
})
const options = [

View File

@ -2,22 +2,26 @@
<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>
<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" />
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
<Operate :show="open" />
<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 prop="coding" label="岗位编码" />
<el-table-column prop="status" label="状态">
<template #default="scope">
<Status v-model="scope.row.status" :id="scope.row.id" :api="api" />
</template>
</el-table-column>
<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)" />
<Update @click="open(scope.row.id)" />
<Destroy @click="destroy(api, scope.row.id)" />
</template>
</el-table-column>
@ -26,39 +30,25 @@
</div>
<Dialog v-model="visible" :title="title" destroy-on-close>
<Create @close="close" :primary="id" :api="api" />
<Create @close="close(reset)" :primary="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted } 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'
import { useOpen } from '/admin/composables/curd/useOpen'
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
}
const { open, close, title, visible, id } = useOpen()
onMounted(() => {
search()

View File

@ -0,0 +1,128 @@
<template>
<el-form :model="formData" label-width="80px" ref="form" v-loading="loading" class="pr-4">
<div class="flex flex-row justify-between">
<div>
<el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="formData.type">
<el-radio-button
v-for="item in [
{ label: '目录', value: 1 },
{ label: '菜单', value: 2 },
{ label: '按钮', value: 3 },
]"
:key="item.value"
:label="item.value"
name="type"
>{{ item.label }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="菜单名称" prop="permission_name">
<el-input v-model="formData.permission_name" name="permission_name" clearable />
</el-form-item>
<el-form-item label="所属模块" prop="module">
<Select v-model="formData.module" clearable api="modules" class="w-full" filterable />
</el-form-item>
<el-form-item label="菜单路由" prop="route">
<el-input v-model="formData.route" name="route" clearable />
</el-form-item>
<el-form-item label="Redirect" prop="redirect">
<el-input v-model="formData.redirect" name="redirect" clearable />
</el-form-item>
<el-form-item label="Keepalive" prop="keepalive">
<el-radio-group v-model="formData.keepalive">
<el-radio
v-for="item in [
{ label: '启用', value: 1 },
{ label: '禁用', value: 2 },
]"
:key="item.value"
:label="item.value"
name="keepalive"
>{{ item.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</div>
<div>
<el-form-item label="父级菜单" prop="parent_id">
<el-cascader :options="permissions" name="parent_id" v-model="formData.parent_id" clearable :props="{ value: 'id', label: 'permission_name', checkStrictly: true }" class="w-full" />
</el-form-item>
<el-form-item label="权限标识" prop="permission_mark">
<el-input v-model="formData.permission_mark" name="permission_mark" clearable />
</el-form-item>
<el-form-item label="菜单Icon" prop="icon">
<el-input v-model="formData.icon" name="icon" clearable />
</el-form-item>
<el-form-item label="所属组件" prop="component">
<el-select v-model="formData.component" placeholder="请选择" clearable class="w-full" />
</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="Hidden" prop="hidden">
<el-radio-group v-model="formData.hidden">
<el-radio
v-for="item in [
{ label: '显示', value: 1 },
{ label: '隐藏', value: 2 },
]"
:key="item.value"
:label="item.value"
name="hidden"
>{{ item.label }}</el-radio
>
</el-radio-group>
</el-form-item>
</div>
</div>
<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 } from 'vue'
import http from '/admin/support/http'
const props = defineProps({
primary: String | Number,
api: String,
})
const { formData, form, loading, submitForm, close, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
formData.value.sort = 1
formData.value.keepalive = 1
formData.value.type = 1
formData.value.hidden = 1
if (props.primary) {
useShow(props.api, props.primary, formData)
}
const emit = defineEmits(['close'])
const permissions = ref()
onMounted(() => {
http.get(props.api).then(r => {
permissions.value = r.data.data
})
close(() => emit('close'))
})
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]
}
</script>

View File

@ -0,0 +1,52 @@
<template>
<div>
<Search :search="search" :reset="reset">
<template v-slot:body>
<el-form-item label="菜单名称" prop="permission_name">
<el-input v-model="query.permission_name" name="permission_name" clearable />
</el-form-item>
</template>
</Search>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-10">
<Operate :show="open" />
<el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }">
<el-table-column prop="permission_name" label="菜单名称" />
<el-table-column prop="route" label="菜单路由" />
<el-table-column prop="permission_mark" label="权限标识" />
<el-table-column prop="hidden" label="状态" />
<el-table-column prop="created_at" label="创建时间" />
<el-table-column label="操作" width="200">
<template #default="scope">
<Update @click="open(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(reset)" :primary="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, watch } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
const api = 'permissions/permissions'
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()
const tableData = computed(() => data.value?.data)
onMounted(() => {
search()
deleted(reset)
})
</script>

View File

@ -43,7 +43,7 @@
<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 { onMounted, ref, unref, watch } from 'vue'
import http from '/admin/support/http'
const props = defineProps({
@ -51,9 +51,7 @@ const props = defineProps({
api: String,
})
const emit = defineEmits(['close'])
const { formData, form, loading, submitForm, isClose, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
const { formData, form, loading, submitForm, close, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
beforeCreate.value = () => {
formData.value.parent_id = getParent(formData.value.parent_id)
@ -67,29 +65,28 @@ const getParent = (parentId: any) => {
return typeof parentId === 'undefined' ? 0 : parentId[parentId.length - 1]
}
watch(isClose, function (value) {
if (value) {
emit('close')
}
})
if (props.primary) {
const { afterShow } = useShow(props.api, props.primary, formData)
afterShow.value = formData => {
const data = unref(formData)
data.parent_id = data.parent_id ? [data.parent_id] : 0
if (!data.data_range) {
data.data_range = null
}
formData.value = data
}
}
const emit = defineEmits(['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
})
close(() => emit('close'))
})
</script>

View File

@ -1,25 +1,15 @@
<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">
<Search :search="search" :reset="reset">
<template v-slot:body>
<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">
</template>
</Search>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
<div class="pt-5 pl-2">
<Add @click="show(null)" />
<Add @click="open(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="角色名称" />
@ -28,53 +18,36 @@
<el-table-column prop="created_at" label="创建时间" />
<el-table-column label="操作" width="200">
<template #default="scope">
<Update @click="show(scope.row.id)" />
<Update @click="open(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" />
<Create @close="close(reset)" :primary="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted } 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'
import { useOpen } from '/admin/composables/curd/useOpen'
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 { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()
const tableData = computed(() => data.value?.data)
const close = () => {
visible.value = false
reset()
}
onMounted(() => {
search()
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()
deleted(reset)
})
</script>

View File

@ -13,12 +13,24 @@ const router: RouteRecordRaw[] = [
meta: { title: '角色管理', icon: 'home' },
component: () => import('./roles/index.vue'),
},
{
path: 'permissions',
name: 'permissions',
meta: { title: '菜单管理', icon: 'home' },
component: () => import('./permissions/index.vue'),
},
{
path: 'jobs',
name: 'jobs',
meta: { title: '岗位管理', icon: 'home' },
component: () => import('./jobs/index.vue'),
},
{
path: 'departments',
name: 'departments',
meta: { title: '部门管理', icon: 'home' },
component: () => import('./departments/index.vue'),
},
],
},
]

View File

@ -1,29 +1,17 @@
<template>
<div class="pt-2 pb-2 flex justify-end">
<el-pagination
background
:layout="layout"
:current-page="page"
:page-size="limit"
@current-change="changePage"
@size-change="changeLimit"
:total="total"
:page-sizes="pageSizes"
/>
</div>
<div class="flex justify-end pt-5">
<el-pagination background :layout="layout" :current-page="page" :page-size="limit" @current-change="changePage" @size-change="changeLimit" :total="total" :page-sizes="pageSizes" />
</div>
</template>
<script lang="ts" setup>
import {inject} from "vue";
import { inject } from 'vue'
const layout = 'total,sizes,prev, pager,next'
const pageSizes = [10, 20, 30, 50]
const {page, limit, total, changePage, changeLimit} = inject('paginate')
const { page, limit, total, changePage, changeLimit } = inject('paginate')
</script>
<style scoped>
</style>
<style scoped></style>

View File

@ -5,7 +5,6 @@
<script lang="ts" setup>
import { useEnabled } from '/admin/composables/curd/useEnabled'
import { Status } from '/admin/enum/app'
import { watch } from 'vue'
const props = defineProps({
modelValue: Boolean | Number | String,
@ -13,12 +12,15 @@ const props = defineProps({
id: Number | String,
})
const emits = defineEmits(['update:modelValue'])
const emits = defineEmits(['update:modelValue', 'refresh'])
const { enabled, success, loading } = useEnabled()
const { enabled, success, loading, afterEnabled } = useEnabled()
watch(success, function () {
success(() => {
emits('update:modelValue', props.modelValue === Status.ENABLE ? Status.DISABLE : Status.ENABLE)
success.value = false
})
afterEnabled.value = () => {
emits('refresh')
}
</script>

View File

@ -1,21 +1,17 @@
<template>
<div class="pt-5 pl-2">
<Add @click="show(showParams)" />
<slot name="operate"/>
</div>
<div class="pt-5 pl-2">
<Add @click="show(showParams)" />
<slot name="operate" />
</div>
</template>
<script lang="ts" setup>
defineProps({
show: {
type: Function,
required: true,
},
show: {
type: Function,
required: true,
},
showParams: null
showParams: null,
})
</script>
<style scoped>
</style>

View File

@ -1,5 +1,5 @@
import http from '/admin/support/http'
import { ref, unref } from 'vue'
import { ref, unref, watch } from 'vue'
import { Code } from '/admin/enum/app'
import Message from '/admin/support/message'
import { FormInstance } from 'element-plus'
@ -64,5 +64,13 @@ export function useCreate(path: string, id: string | number | null = null, _form
.then(() => {})
}
return { formData, loading, form, submitForm, isClose, beforeCreate, beforeUpdate }
const close = (func: Function) => {
watch(isClose, function (value) {
if (value && isFunction(func)) {
func()
}
})
}
return { formData, loading, form, submitForm, close, beforeCreate, beforeUpdate }
}

View File

@ -1,19 +1,24 @@
import http from '/admin/support/http'
import { Code } from '/admin/assets/enum/app'
import Message from '/admin/support/message'
import { ref } from 'vue'
import { ref, watch } from 'vue'
import { isFunction } from '/admin/support/helper'
export function useEnabled() {
const success = ref(false)
const isSuccess = ref(false)
const loading = ref<boolean>(false)
const afterEnabled = ref()
function enabled(path: string, id: string | number, data: object = {}) {
loading.value = true
http
.put(path + '/enable/' + id, data)
.then(r => {
if (r.data.code === Code.SUCCESS) {
success.value = true
isSuccess.value = true
Message.success(r.data.message)
if (isFunction(afterEnabled.value)) {
afterEnabled.value()
}
} else {
Message.error(r.data.message)
}
@ -23,5 +28,12 @@ export function useEnabled() {
})
}
return { enabled, success, loading }
const success = (func: Function) => {
watch(isSuccess, function () {
isSuccess.value = false
func()
})
}
return { enabled, success, loading, afterEnabled }
}

View File

@ -0,0 +1,21 @@
import { ref } from 'vue'
import { t } from '/admin/support/helper'
const visible = ref<boolean>(false)
const id = ref(null)
const title = ref<string>('')
export function useOpen() {
const open = (primary: any) => {
console.log(primary)
title.value = primary ? t('system.edit') : t('system.add')
id.value = primary
visible.value = true
}
const close = (func: Function) => {
visible.value = false
func()
}
return { open, close, title, visible, id }
}

View File

@ -1,14 +1,26 @@
import http from '/admin/support/http'
import { Ref, ref } from 'vue'
import { isFunction } from '../../support/helper'
export function useShow(path: string, id: string | number) {
return new Promise((resolve, reject) => {
http
.get(path + '/' + id)
.then(response => {
resolve(response.data)
})
.catch(e => {
reject(e)
})
const loading = ref<boolean>(true)
const data = ref<object>()
// 后置钩子
const afterShow = ref()
export function useShow(path: string, id: string | number, fillData: null | Ref = null) {
http.get(path + '/' + id).then(r => {
loading.value = false
data.value = r.data.data
if (fillData) {
fillData.value = r.data.data
if (isFunction(afterShow.value)) {
afterShow.value(fillData)
}
}
})
return { data, loading, afterShow }
}

View File

@ -28,7 +28,7 @@
<script setup lang="ts">
import { useAppStore } from '/admin/stores/modules/app'
import Notification from './notification.vue'
import MenuSearch from './menuSearch.vue.vue'
import MenuSearch from './menuSearch.vue'
const store = useAppStore()
</script>