Compare commits
70 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4ffd3eed52 | ||
![]() |
d47ccb586f | ||
![]() |
b81b9b66c8 | ||
![]() |
c3eb2443b6 | ||
![]() |
4696461d72 | ||
![]() |
aabaf99c1b | ||
![]() |
6f28c25a30 | ||
![]() |
667f6353d5 | ||
![]() |
e69cc0e147 | ||
![]() |
e5be0ca2f8 | ||
![]() |
4606f9c792 | ||
![]() |
604c17584f | ||
![]() |
8e63216e63 | ||
![]() |
4bf1658c2e | ||
![]() |
8e0ec2a6a9 | ||
![]() |
90ad443178 | ||
![]() |
324c974505 | ||
![]() |
d93275fa2d | ||
![]() |
832c65275e | ||
![]() |
4b15b2f01c | ||
![]() |
4814521198 | ||
![]() |
6058d1e7e0 | ||
![]() |
5fc2ad54c6 | ||
![]() |
601574f812 | ||
![]() |
e711546d02 | ||
![]() |
96aef3ce94 | ||
![]() |
558ad1271b | ||
![]() |
1d40dd9fe2 | ||
![]() |
07621425dc | ||
![]() |
4008ebdf7e | ||
![]() |
fd82aa75e1 | ||
![]() |
9775990379 | ||
![]() |
19fd75d171 | ||
![]() |
d5ed1dd461 | ||
![]() |
78c25497d6 | ||
![]() |
4a09a203c4 | ||
![]() |
164aa40738 | ||
![]() |
3bae9d7761 | ||
![]() |
759aa3fcdf | ||
![]() |
bb4422e36b | ||
![]() |
2c035c7441 | ||
![]() |
a36fa86d8d | ||
![]() |
66f19d8ef1 | ||
![]() |
560e1bab5b | ||
![]() |
be1307db94 | ||
![]() |
a6c879ce09 | ||
![]() |
ff14f46fe0 | ||
![]() |
03ea4759af | ||
![]() |
9abd62b801 | ||
![]() |
1849c85c39 | ||
![]() |
d02d56a6c0 | ||
![]() |
f819869cea | ||
![]() |
353da4e7f5 | ||
![]() |
d64cfc99d9 | ||
![]() |
3e51a72e3b | ||
![]() |
960576e286 | ||
![]() |
2772c3322f | ||
![]() |
8088787eee | ||
![]() |
2a6d65d4e7 | ||
![]() |
b8c4c90da7 | ||
![]() |
abd95877e1 | ||
![]() |
c48607c123 | ||
![]() |
035ba22f52 | ||
![]() |
403501b214 | ||
![]() |
c56a01df56 | ||
![]() |
ac5e0957b9 | ||
![]() |
948082f4ce | ||
![]() |
35622b164c | ||
![]() |
cbb3c156a6 | ||
![]() |
2d61786ec6 |
51
.workflow/branch-pipeline.yml
Normal file
51
.workflow/branch-pipeline.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
version: '1.0'
|
||||
name: branch-pipeline
|
||||
displayName: BranchPipeline
|
||||
stages:
|
||||
- stage:
|
||||
name: compile
|
||||
displayName: 编译
|
||||
steps:
|
||||
- step: build@php
|
||||
name: build_php
|
||||
displayName: PHP 构建
|
||||
# 支持5.0、7.0、7.1、7.2、7.3、7.4、8.0、8.1八个版本
|
||||
phpVersion: 8.0
|
||||
# 构建命令
|
||||
commands:
|
||||
- php --version
|
||||
# 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除
|
||||
artifacts:
|
||||
# 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
|
||||
- name: BUILD_ARTIFACT
|
||||
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
|
||||
path:
|
||||
- ./
|
||||
- step: publish@general_artifacts
|
||||
name: publish_general_artifacts
|
||||
displayName: 上传制品
|
||||
# 上游构建任务定义的产物名,默认BUILD_ARTIFACT
|
||||
dependArtifact: BUILD_ARTIFACT
|
||||
# 上传到制品库时的制品命名,默认output
|
||||
artifactName: output
|
||||
dependsOn: build_php
|
||||
- stage:
|
||||
name: release
|
||||
displayName: 发布
|
||||
steps:
|
||||
- step: publish@release_artifacts
|
||||
name: publish_release_artifacts
|
||||
displayName: '发布'
|
||||
# 上游上传制品任务的产出
|
||||
dependArtifact: output
|
||||
# 发布制品版本号
|
||||
version: '1.0.0.0'
|
||||
# 是否开启版本号自增,默认开启
|
||||
autoIncrement: true
|
||||
triggers:
|
||||
push:
|
||||
branches:
|
||||
exclude:
|
||||
- master
|
||||
include:
|
||||
- .*
|
49
.workflow/master-pipeline.yml
Normal file
49
.workflow/master-pipeline.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
version: '1.0'
|
||||
name: master-pipeline
|
||||
displayName: MasterPipeline
|
||||
stages:
|
||||
- stage:
|
||||
name: compile
|
||||
displayName: 编译
|
||||
steps:
|
||||
- step: build@php
|
||||
name: build_php
|
||||
displayName: PHP 构建
|
||||
# 支持5.0、7.0、7.1、7.2、7.3、7.4、8.0、8.1八个版本
|
||||
phpVersion: 8.0
|
||||
# 构建命令
|
||||
commands:
|
||||
- php --version
|
||||
# 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除
|
||||
artifacts:
|
||||
# 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
|
||||
- name: BUILD_ARTIFACT
|
||||
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
|
||||
path:
|
||||
- ./
|
||||
- step: publish@general_artifacts
|
||||
name: publish_general_artifacts
|
||||
displayName: 上传制品
|
||||
# 上游构建任务定义的产物名,默认BUILD_ARTIFACT
|
||||
dependArtifact: BUILD_ARTIFACT
|
||||
# 上传到制品库时的制品命名,默认output
|
||||
artifactName: output
|
||||
dependsOn: build_php
|
||||
- stage:
|
||||
name: release
|
||||
displayName: 发布
|
||||
steps:
|
||||
- step: publish@release_artifacts
|
||||
name: publish_release_artifacts
|
||||
displayName: '发布'
|
||||
# 上游上传制品任务的产出
|
||||
dependArtifact: output
|
||||
# 发布制品版本号
|
||||
version: '1.0.0.0'
|
||||
# 是否开启版本号自增,默认开启
|
||||
autoIncrement: true
|
||||
triggers:
|
||||
push:
|
||||
branches:
|
||||
include:
|
||||
- master
|
36
.workflow/pr-pipeline.yml
Normal file
36
.workflow/pr-pipeline.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
version: '1.0'
|
||||
name: pr-pipeline
|
||||
displayName: PRPipeline
|
||||
stages:
|
||||
- stage:
|
||||
name: compile
|
||||
displayName: 编译
|
||||
steps:
|
||||
- step: build@php
|
||||
name: build_php
|
||||
displayName: PHP 构建
|
||||
# 支持5.0、7.0、7.1、7.2、7.3、7.4、8.0、8.1八个版本
|
||||
phpVersion: 8.0
|
||||
# 构建命令
|
||||
commands:
|
||||
- php --version
|
||||
# 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除
|
||||
artifacts:
|
||||
# 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址
|
||||
- name: BUILD_ARTIFACT
|
||||
# 构建产物获取路径,是指代码编译完毕之后构建物的所在路径
|
||||
path:
|
||||
- ./
|
||||
- step: publish@general_artifacts
|
||||
name: publish_general_artifacts
|
||||
displayName: 上传制品
|
||||
# 上游构建任务定义的产物名,默认BUILD_ARTIFACT
|
||||
dependArtifact: BUILD_ARTIFACT
|
||||
# 上传到制品库时的制品命名,默认output
|
||||
artifactName: output
|
||||
dependsOn: build_php
|
||||
triggers:
|
||||
pr:
|
||||
branches:
|
||||
include:
|
||||
- master
|
33
README.md
33
README.md
@@ -3,11 +3,19 @@
|
||||
|
||||
[中文](./README.md)|[英文](./README-en.md)
|
||||
|
||||
## 专业版
|
||||
[专业版本官方地址](https://license.catchadmin.com)
|
||||
|
||||
首先感谢一直以来对 `CatchAdmin` 开源项目的支持和使用。作为一名开源工作者,我一直致力于开发出功能强大且易于使用的后台管理系统,以帮助您简化业务流程和提升工作效率。然而,由于某些原因,我不得不做出一些调整。为了能够继续开发和维护这个项目,我将推出一款付费的后台管理系统,以确保我能够持续为您提供高质量的服务和支持。
|
||||
|
||||
专业版本不会在开源版本做一些破坏性变更,所以当您从开源版本切换到专业版本,不会有任何开发心智负担。但是使用专业版本会有新的组件来配合您的工作。
|
||||
|
||||
我深信,付费后台管理系统将为您带来更多的价值和便利,帮助您提升工作效率
|
||||
|
||||
|
||||
## ⚠️Thinkphp 用户注意
|
||||
由于新版本使用 `Laravel` 开发,所以请使用 `thinkphp` 分支或者 tag2.6.2,thinkphp 版本已经非常稳定了。
|
||||
|
||||
## 为什么是 Laravel
|
||||
`V2` 版本使用`Thinkphp`,但从其社区来看,从我个人角度来看开发组的心思已经不在维护框架上,因为据观察,每一次小版本发布都会引发一些小问题,虽然不大,但给人一种不够稳定的感觉,所以思索再三,使用 `Laravel`。`Laravel` 社区非常繁荣,他们每周都会发布新版本,以及围绕`Laravel`构建的生态也非常完善,有 `Horizon` 队列管理工具, `Telescope` 调试工具,`Octane`(基于 `Swoole` 和 `RoadRunner` 提高性能)等等一系列的工具,而且都是免费的。
|
||||
[thinkphp 8.0 仓库,开发中...](https://gitee.com/catchamin/catchadmin-tp)
|
||||
|
||||
## 功能
|
||||
- [x] 用户管理 后台用户管理
|
||||
@@ -21,6 +29,14 @@
|
||||
- [x] Schema 管理 生成表结构
|
||||
- [x] 模块管理 系统模块管理
|
||||
|
||||
|
||||
## 讨论
|
||||
- 可以提 `ISSUE`,请按照 `issue` 模板提问
|
||||
- 加入 Q 群 `302266230` 暗号 `catchadmin`。
|
||||
- 加微信入群,新建🆕
|
||||
|
||||
<img src="wechat.png" width="300"/>
|
||||
|
||||
## 额外模块
|
||||
- [CMS 模块](https://github.com/catch-admin/cms)
|
||||
|
||||
@@ -45,11 +61,6 @@
|
||||
- [catchadmin 开发之模块创建](https://www.bilibili.com/video/BV1jP41127aW/)
|
||||
- [catchadmin 之快速开发](https://www.bilibili.com/video/BV1Qh4y1J7eB/)
|
||||
|
||||
## 赞助
|
||||
如果项目对你有帮助,或者在工作上帮你节省了开发时间。在力所能及的情况下,可以支持下`Catchadmin`项目, 非常感谢🙏
|
||||
|
||||
<img src="https://i.imgtg.com/2023/02/16/dAV0a.jpg" width = "200" alt="support"/>
|
||||
|
||||
## 规范
|
||||
### PHP
|
||||
使用 fixer 进行代码检查, 具体请查看根目录下 `.php-cs-fixer.dist.php` 文件的规范,还需要进行以下两步骤
|
||||
@@ -68,12 +79,6 @@ composer cs
|
||||
composer cs-diff
|
||||
```
|
||||
|
||||
## 讨论
|
||||
- [论坛讨论](https://bbs.catchadmin.com)
|
||||
- 可以提 `ISSUE`,请按照 `issue` 模板提问
|
||||
- 加入 Q 群 `302266230` 暗号 `catchadmin`。
|
||||
|
||||
|
||||
## 感谢🙏
|
||||
> 排名不分先后
|
||||
|
||||
|
@@ -18,7 +18,7 @@
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.0",
|
||||
"laravel/tinker": "^2.8",
|
||||
"catchadmin/core": "^0.1.12"
|
||||
"catchadmin/core": "^0.2.7"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
@@ -42,7 +42,8 @@
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
"@php artisan package:discover --ansi",
|
||||
"@composer dump-autoload --no-scripts"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
|
@@ -185,7 +185,6 @@ return [
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
\Catch\Providers\CatchAdminServiceProvider::class,
|
||||
|
||||
/*
|
||||
* Application Service Providers...
|
||||
|
@@ -20,6 +20,7 @@ class Components implements OptionInterface
|
||||
|
||||
public function get(): array
|
||||
{
|
||||
try {
|
||||
if ($module = request()->get('module')) {
|
||||
$components = File::glob(CatchAdmin::getModuleViewsPath($module) . '*' . DIRECTORY_SEPARATOR . '*.vue');
|
||||
|
||||
@@ -38,5 +39,8 @@ class Components implements OptionInterface
|
||||
}
|
||||
|
||||
return $this->components;
|
||||
} catch (\Throwable $exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ namespace Modules\Common\Support\Upload\Uses;
|
||||
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class LocalUpload extends Upload
|
||||
{
|
||||
@@ -25,7 +26,9 @@ class LocalUpload extends Upload
|
||||
*/
|
||||
protected function addUrl($path): mixed
|
||||
{
|
||||
$path['path'] = config('app.url') . '/'. $path['path'];
|
||||
$path['path'] = config('app.url') . '/'.
|
||||
|
||||
Str::of($path['path'])->replace('\\', '/')->toString();
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Develop\Support\Generate\Create\Schema;
|
||||
use Illuminate\Support\Facades\Schema as SchemaFacade;
|
||||
|
||||
class Schemas extends CatchModel
|
||||
{
|
||||
@@ -108,22 +107,4 @@ class Schemas extends CatchModel
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete
|
||||
*
|
||||
* @param $id
|
||||
* @param bool $force
|
||||
* @return bool|null
|
||||
*/
|
||||
public function deleteBy($id, bool $force = false): ?bool
|
||||
{
|
||||
$schema = parent::firstBy($id);
|
||||
|
||||
if ($schema->delete()) {
|
||||
SchemaFacade::dropIfExists($schema->name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -81,6 +81,13 @@ class Module
|
||||
*/
|
||||
protected function createRoute(): void
|
||||
{
|
||||
File::copy(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'route.stub', CatchAdmin::getModuleRoutePath($this->module));
|
||||
$content = Str::of(
|
||||
File::get(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'route.stub')
|
||||
)->replace(['{module}'], [lcfirst($this->module)]);
|
||||
|
||||
File::put(
|
||||
CatchAdmin::getModuleRoutePath($this->module),
|
||||
$content
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ class {controller} extends Controller
|
||||
){}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(): mixed
|
||||
|
@@ -13,6 +13,8 @@ return new class extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('{table}')) { return; }
|
||||
|
||||
Schema::{method}('{table}', function (Blueprint $table) {
|
||||
{content}
|
||||
});
|
||||
|
@@ -21,7 +21,7 @@ class {request} extends Request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function message(): array
|
||||
public function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
<el-form-item label="{label}" prop="{prop}">
|
||||
<el-input v-model="{model-value}" name="{prop}" type="textarea" clearable />
|
||||
</el-form-item>
|
@@ -0,0 +1,3 @@
|
||||
<el-form-item label="{label}" prop="{prop}">
|
||||
<Upload v-model="{model-value}" />
|
||||
</el-form-item>
|
@@ -60,6 +60,20 @@ import { Delete } from '@element-plus/icons-vue'
|
||||
const generateStore = useGenerateStore()
|
||||
|
||||
const structures = computed(() => {
|
||||
generateStore.getStructures.forEach(struct => {
|
||||
if (struct.field === 'id' || struct.field === 'created_at' || struct.field === 'updated_at') {
|
||||
struct.form = false
|
||||
}
|
||||
|
||||
if (struct.field === 'sort') {
|
||||
struct.form_component = 'input-number'
|
||||
}
|
||||
|
||||
if (struct.field === 'status') {
|
||||
struct.form_component = 'select'
|
||||
}
|
||||
})
|
||||
|
||||
return generateStore.getStructures
|
||||
})
|
||||
|
||||
@@ -95,5 +109,5 @@ const validates: string[] = [
|
||||
'prohibited',
|
||||
]
|
||||
|
||||
const formComponents: string[] = ['cascader', 'date', 'datetime', 'input', 'input-number', 'radio', 'rate', 'select', 'tree', 'tree-select']
|
||||
const formComponents: string[] = ['cascader', 'date', 'datetime', 'input', 'input-number', 'radio', 'rate', 'select', 'tree', 'tree-select', 'textarea', 'upload']
|
||||
</script>
|
||||
|
@@ -41,7 +41,7 @@
|
||||
|
||||
<!-- 安装 -->
|
||||
<Dialog v-model="installVisible" title="安装模块" destroy-on-close>
|
||||
<Install />
|
||||
<Install @close="closeInstall" />
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -62,6 +62,9 @@ const { open, close, title, visible, id } = useOpen()
|
||||
|
||||
const tableData = computed(() => data.value?.data)
|
||||
const installVisible = ref<boolean>(false)
|
||||
const closeInstall = () => {
|
||||
installVisible.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
search()
|
||||
|
@@ -8,7 +8,7 @@
|
||||
{ label: 'ZIP 安装', value: 2 },
|
||||
]"
|
||||
:key="item.value"
|
||||
:label="item.value"
|
||||
:value="item.value"
|
||||
name="type"
|
||||
>{{ item.label }}
|
||||
</el-radio-button>
|
||||
@@ -22,9 +22,21 @@
|
||||
required: true,
|
||||
message: '模块名称必须填写',
|
||||
},
|
||||
{
|
||||
validator: (rule: any, value: any, callback: any) => {
|
||||
if (! /^[A-Za-z]+$/.test(value)) {
|
||||
callback('模块名称只允许大小字母组合')
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'blur',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input v-model="formData.title" />
|
||||
<el-select v-model="formData.title" placeholder="选择安装模块">
|
||||
<el-option v-for="item in modules" :key="item.value" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="上传 ZIP" prop="file" v-if="formData.type === 2">
|
||||
<Upload action="module/upload" :limit="1" accept=".zip" :on-success="moduleUpload">
|
||||
@@ -63,4 +75,19 @@ const moduleUpload = (response, uploadFile) => {
|
||||
Message.error(response.message)
|
||||
}
|
||||
}
|
||||
|
||||
const modules = [
|
||||
{
|
||||
label: '权限管理',
|
||||
value: 'permissions',
|
||||
},
|
||||
{
|
||||
label: '内容管理',
|
||||
value: 'cms',
|
||||
},
|
||||
{
|
||||
label: '系统管理',
|
||||
value: 'system',
|
||||
},
|
||||
]
|
||||
</script>
|
||||
|
@@ -64,7 +64,7 @@ const schemaVisible = ref<boolean>(false)
|
||||
const api = 'schema'
|
||||
|
||||
const { data, query, search, reset, loading } = useGetList(api)
|
||||
const { destroy, deleted } = useDestroy('确认删除吗? 将会删除数据库的 Schema,请提前做好备份,一旦删除,将无法恢复!')
|
||||
const { destroy, deleted } = useDestroy('确认删除吗? 删除后数据表将会保留,如需删除相关表,请手动进行删除!')
|
||||
const { open, close, title, visible, id } = useOpen()
|
||||
|
||||
const tableData = computed(() => data.value?.data)
|
||||
|
@@ -88,14 +88,13 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, Ref, ref } from 'vue'
|
||||
import { computed, Ref, ref } from 'vue'
|
||||
import { useSchemaStore, Structure } from '../store'
|
||||
import { Delete, Plus, Edit } from '@element-plus/icons-vue'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import Message from '/admin/support/message'
|
||||
import http from '/admin/support/http'
|
||||
import { Code } from '/admin/enum/app'
|
||||
import Sortable from 'sortablejs'
|
||||
|
||||
const schemaStore = useSchemaStore()
|
||||
const emits = defineEmits(['prev', 'next'])
|
||||
@@ -120,27 +119,6 @@ const updateField = (id: number) => {
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const tbody = document.querySelector('.draggable .el-table__body-wrapper tbody')
|
||||
const structures = schemaStore.getStructures
|
||||
|
||||
Sortable.create(tbody, {
|
||||
draggable: 'tr',
|
||||
onEnd({ newIndex, oldIndex }) {
|
||||
const newStructures = []
|
||||
const s = structures.splice(oldIndex, newIndex - oldIndex)
|
||||
s.concat(structures).forEach(item => {
|
||||
newStructures.push(item)
|
||||
})
|
||||
schemaStore.setStructures(newStructures)
|
||||
|
||||
// console.log(structure)
|
||||
// structures[newIndex] = structures[oldIndex]
|
||||
// structures[oldIndex] = temp
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
const form = ref<FormInstance>()
|
||||
const submitStructure = (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return
|
||||
|
@@ -28,7 +28,9 @@ class PermissionsController extends Controller
|
||||
public function index(Request $request): mixed
|
||||
{
|
||||
if ($request->get('from') == 'role') {
|
||||
return $this->model->getList();
|
||||
return $this->model->setBeforeGetList(function ($query){
|
||||
return $query->orderByDesc('sort');
|
||||
})->getList();
|
||||
}
|
||||
|
||||
return $this->model->setBeforeGetList(function ($query) {
|
||||
|
@@ -6,6 +6,8 @@ namespace Modules\Permissions\Http\Controllers;
|
||||
|
||||
use Catch\Base\CatchController as Controller;
|
||||
use Catch\Exceptions\FailedException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Permissions\Enums\DataRange;
|
||||
use Modules\Permissions\Models\Roles;
|
||||
use Modules\Permissions\Http\Requests\RoleRequest;
|
||||
@@ -39,25 +41,34 @@ class RolesController extends Controller
|
||||
*/
|
||||
public function store(RoleRequest $request)
|
||||
{
|
||||
$dataRange = $request->get('data_range');
|
||||
|
||||
if ($dataRange && ! DataRange::Personal_Choose->assert($request->get('data_range'))) {
|
||||
$request['departments'] = [];
|
||||
$data = $request->all();
|
||||
if (!isset($data['data_range'])) {
|
||||
$data['data_range'] = 0;
|
||||
} else {
|
||||
$data['data_range'] = (int)$data['data_range'];
|
||||
if (!DataRange::Personal_Choose->assert($data['data_range'])) {
|
||||
$data['departments'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->model->storeBy($request->all());
|
||||
return $this->model->storeBy($data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $id
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
* @param Request $request
|
||||
* @return Model|null
|
||||
*/
|
||||
public function show($id)
|
||||
public function show($id, Request $request)
|
||||
{
|
||||
$role = $this->model->firstBy($id);
|
||||
|
||||
if ($request->has('from') && $request->get('from') == 'parent_role') {
|
||||
$role->setAttribute('permissions', $role->permissions()->get()->toTree());
|
||||
} else {
|
||||
$role->setAttribute('permissions', $role->permissions()->get()->pluck('id'));
|
||||
}
|
||||
|
||||
$role->setAttribute('departments', $role->departments()->pluck('id'));
|
||||
|
||||
@@ -73,8 +84,8 @@ class RolesController extends Controller
|
||||
public function update($id, RoleRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
if ($request->get('data_range') && ! DataRange::Personal_Choose->assert($data['data_range'])) {
|
||||
$data['data_range'] = (int) $data['data_range'];
|
||||
if (!DataRange::Personal_Choose->assert($data['data_range'])) {
|
||||
$data['departments'] = [];
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@ use Catch\Enums\Status;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Permissions\Enums\MenuStatus;
|
||||
use Modules\Permissions\Enums\MenuType;
|
||||
|
||||
@@ -199,6 +200,9 @@ class Permissions extends Model
|
||||
$data['route'] = '/'.trim($data['route'], '/');
|
||||
}
|
||||
|
||||
if (isset($data['component'])) {
|
||||
$data['component'] = Str::of($data['component'])->replace('\\', '/')->toString();
|
||||
}
|
||||
return parent::storeBy($data);
|
||||
});
|
||||
}
|
||||
@@ -244,6 +248,9 @@ class Permissions extends Model
|
||||
$data['permission_mark'] = $parentMenu->permission_mark.'@'.$data['permission_mark'];
|
||||
}
|
||||
|
||||
if (isset($data['component'])) {
|
||||
$data['component'] = Str::of($data['component'])->replace('\\', '/')->toString();
|
||||
}
|
||||
return parent::updateBy($id, $data);
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,9 @@ use Modules\Permissions\Models\Departments;
|
||||
use Modules\Permissions\Models\Roles;
|
||||
use Modules\Permissions\Enums\DataRange as DataRangeEnum;
|
||||
|
||||
/**
|
||||
* @method aliasField(string $field)
|
||||
*/
|
||||
trait DataRange
|
||||
{
|
||||
|
||||
@@ -28,7 +31,7 @@ trait DataRange
|
||||
|
||||
$userIds = $this->getDepartmentUserIdsBy($roles, $currenUser);
|
||||
|
||||
if (empty($userIds)) {
|
||||
if ($userIds->isEmpty()) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
</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 v-for="item in options" :key="item.value" :value="item.value" name="status">{{ item.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
@@ -30,7 +30,7 @@ import { useShow } from '/admin/composables/curd/useShow'
|
||||
import { onMounted } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
primary: String | Number,
|
||||
primary: [Number, String],
|
||||
api: String,
|
||||
})
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
{ label: '按钮', value: 3 },
|
||||
]"
|
||||
:key="item.value"
|
||||
:label="item.value"
|
||||
:value="item.value"
|
||||
name="type"
|
||||
>{{ item.label }}
|
||||
</el-radio-button>
|
||||
@@ -42,7 +42,14 @@
|
||||
<Select v-model="formData.permission_mark" allow-create placeholder="请选择" api="controllers" :query="{ module: formData.module }" v-else />
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单Icon" prop="icon" v-if="!isAction">
|
||||
<el-input v-model="formData.icon" name="icon" clearable @click="open" />
|
||||
<el-popover placement="right" :width="400" trigger="click">
|
||||
<template #reference>
|
||||
<el-input v-model="formData.icon" name="icon" clearable />
|
||||
</template>
|
||||
<div>
|
||||
<Icons v-model="formData.icon" @close="closeSelectIcon" />
|
||||
</div>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
<el-form-item label="所属组件" prop="component" v-if="!isAction">
|
||||
<Select v-model="formData.component" placeholder="请选择" allow-create api="components" :query="{ module: formData.module }" />
|
||||
@@ -56,7 +63,7 @@
|
||||
{ label: '隐藏', value: 2 },
|
||||
]"
|
||||
:key="item.value"
|
||||
:label="item.value"
|
||||
:value="item.value"
|
||||
name="hidden"
|
||||
>{{ item.label }}</el-radio
|
||||
>
|
||||
@@ -70,7 +77,7 @@
|
||||
{ label: '禁用', value: 2 },
|
||||
]"
|
||||
:key="item.value"
|
||||
:label="item.value"
|
||||
:value="item.value"
|
||||
name="keepalive"
|
||||
>{{ item.label }}
|
||||
</el-radio>
|
||||
@@ -92,10 +99,6 @@
|
||||
<el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
<Dialog v-model="visible" title="选择 Icon" width="1000px" destroy-on-close>
|
||||
<Icons v-model="formData.icon" @close="closeSelectIcon" />
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
@@ -107,7 +110,7 @@ import http from '/admin/support/http'
|
||||
import { MenuType } from '/admin/enum/app'
|
||||
|
||||
const props = defineProps({
|
||||
primary: String | Number,
|
||||
primary: [String,Number],
|
||||
api: String,
|
||||
})
|
||||
|
||||
|
@@ -18,10 +18,10 @@
|
||||
<el-tag v-for="action in scope.row.actions" class="cursor-pointer min-w-fit" @click="open(action.id)" closable @close="destroy(api, action.id)">{{ action.permission_name }}</el-tag>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-popconfirm confirm-button-text="确认" title="添加基础actions" @confirm="actionGenerate(scope.row.id)" placement="top">
|
||||
<el-popconfirm v-if="scope.row.type === MenuType.PAGE_TYPE" confirm-button-text="确认" title="添加基础actions" @confirm="actionGenerate(scope.row.id)" placement="top">
|
||||
<template #reference>
|
||||
<el-tag class="cursor-pointer w-8" v-if="scope.row.type === MenuType.PAGE_TYPE">
|
||||
<Icon name="cog-6-tooth" class="animate-spin w-5 h-5" v-if="actionLoading" />
|
||||
<el-tag class="cursor-pointer w-8">
|
||||
<Icon name="cog-6-tooth" class="animate-spin w-5 h-5" v-if="generateId === scope.row.id" />
|
||||
<Icon name="plus" className="w-4 h-4" v-else />
|
||||
</el-tag>
|
||||
</template>
|
||||
@@ -73,11 +73,18 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
const actionLoading = ref<boolean>(false)
|
||||
const generateId = ref<number>(0)
|
||||
const actionGenerate = async (id: number) => {
|
||||
actionLoading.value = true
|
||||
http.post(api, { parent_id: id, actions: true }).then(r => {
|
||||
generateId.value = id
|
||||
http
|
||||
.post(api, { parent_id: id, actions: true })
|
||||
.then(r => {
|
||||
search()
|
||||
actionLoading.value = false
|
||||
generateId.value = 0
|
||||
})
|
||||
.catch(e => {
|
||||
generateId.value = 0
|
||||
catchtable.value.reset()
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
@@ -105,7 +105,7 @@ const { formData, form, loading, submitForm, close, beforeCreate, beforeUpdate }
|
||||
|
||||
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
|
||||
@@ -115,6 +115,8 @@ if (props.primary) {
|
||||
}
|
||||
|
||||
formData.value = data
|
||||
// 这里需要获取角色的上级的权限以限制可用权限范围
|
||||
getPermissions(data.parent_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,9 +129,12 @@ const departments = ref()
|
||||
const showDepartments = ref<boolean>(false)
|
||||
|
||||
const permissionLoadingText = ref<string>('加载中...')
|
||||
|
||||
// 获取权限
|
||||
const getPermissions = async (value: number = 0) => {
|
||||
if (value) {
|
||||
http.get('permissions/roles/' + getParent(value)).then(r => {
|
||||
// 获取角色权限
|
||||
http.get('permissions/roles/' + getParent(value), { from: 'parent_role' }).then(r => {
|
||||
permissions.value = r.data.data.permissions
|
||||
setCheckedPermissions()
|
||||
})
|
||||
@@ -141,6 +146,7 @@ const getPermissions = async (value: number = 0) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 设置已选权限
|
||||
const setCheckedPermissions = () => {
|
||||
nextTick(() => {
|
||||
props.hasPermissions.forEach(p => {
|
||||
@@ -152,6 +158,8 @@ const setCheckedPermissions = () => {
|
||||
permissionLoadingText.value = '暂无数据'
|
||||
}
|
||||
}
|
||||
|
||||
// 获取角色信息
|
||||
const getRoles = () => {
|
||||
http.get(props.api, { id: props.primary ? props.primary : '' }).then(r => {
|
||||
roles.value = r.data.data
|
||||
@@ -163,9 +171,15 @@ const getDepartments = () => {
|
||||
departments.value = r.data.data
|
||||
})
|
||||
}
|
||||
|
||||
// 新增默认获取全部权限
|
||||
if (!props.primary) {
|
||||
getPermissions()
|
||||
}
|
||||
|
||||
// 页面挂载完成后
|
||||
onMounted(() => {
|
||||
getRoles()
|
||||
getPermissions()
|
||||
getDepartments()
|
||||
close(() => emit('close'))
|
||||
watch(
|
||||
@@ -206,4 +220,10 @@ const getParent = (parentId: any) => {
|
||||
:deep(.el-tree .el-tree__empty-block .el-tree__empty-text) {
|
||||
@apply left-10 top-4;
|
||||
}
|
||||
:deep(.el-tree-node .is-expanded .el-tree-node__children) {
|
||||
@apply flex flex-wrap pl-9;
|
||||
}
|
||||
:deep(.el-tree-node .is-expanded .el-tree-node__children .el-tree-node__content) {
|
||||
padding-left: 0 !important;
|
||||
}
|
||||
</style>
|
||||
|
72
modules/System/Http/Controllers/DictionaryController.php
Normal file
72
modules/System/Http/Controllers/DictionaryController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\System\Http\Controllers;
|
||||
|
||||
use Catch\Base\CatchController as Controller;
|
||||
use Modules\System\Models\Dictionary;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class DictionaryController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly Dictionary $model
|
||||
){}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(): mixed
|
||||
{
|
||||
return $this->model->getList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $this->model->storeBy($request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return $this->model->firstBy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
return $this->model->updateBy($id, $request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$dictionary = $this->model->find($id);
|
||||
|
||||
if ($this->model->deleteBy($id)) {
|
||||
return $dictionary->values()->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function enable($id)
|
||||
{
|
||||
return $this->model->toggleBy($id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\System\Http\Controllers;
|
||||
|
||||
use Catch\Base\CatchController as Controller;
|
||||
use Modules\System\Models\DictionaryValues;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class DictionaryValuesController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected readonly DictionaryValues $model
|
||||
){}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(): mixed
|
||||
{
|
||||
return $this->model->getList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
return $this->model->storeBy($request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return $this->model->firstBy($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
return $this->model->updateBy($id, $request->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
return $this->model->deleteBy($id);
|
||||
}
|
||||
|
||||
public function enable($id)
|
||||
{
|
||||
return $this->model->toggleBy($id);
|
||||
}
|
||||
}
|
32
modules/System/Installer.php
Normal file
32
modules/System/Installer.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\System;
|
||||
|
||||
use Catch\Support\Module\Installer as ModuleInstaller;
|
||||
use Modules\System\Providers\SystemServiceProvider;
|
||||
|
||||
class Installer extends ModuleInstaller
|
||||
{
|
||||
protected function info(): array
|
||||
{
|
||||
// TODO: Implement info() method.
|
||||
return [
|
||||
'title' => '系统管理',
|
||||
'name' => 'system',
|
||||
'path' => 'system',
|
||||
'keywords' => '系统管理, system',
|
||||
'description' => '系统管理模块',
|
||||
'provider' => SystemServiceProvider::class
|
||||
];
|
||||
}
|
||||
|
||||
protected function requirePackages(): void
|
||||
{
|
||||
// TODO: Implement requirePackages() method.
|
||||
}
|
||||
|
||||
protected function removePackages(): void
|
||||
{
|
||||
// TODO: Implement removePackages() method.
|
||||
}
|
||||
}
|
199
modules/System/LICENSE.txt
Normal file
199
modules/System/LICENSE.txt
Normal file
@@ -0,0 +1,199 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
56
modules/System/Models/Dictionary.php
Normal file
56
modules/System/Models/Dictionary.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\System\Models;
|
||||
|
||||
use Catch\Base\CatchModel as Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property $id
|
||||
* @property $name
|
||||
* @property $key
|
||||
* @property $status
|
||||
* @property $description
|
||||
* @property $creator_id
|
||||
* @property $created_at
|
||||
* @property $updated_at
|
||||
* @property $deleted_at
|
||||
*/
|
||||
class Dictionary extends Model
|
||||
{
|
||||
protected $table = 'system_dictionary';
|
||||
|
||||
protected $fillable = [ 'id', 'name', 'key', 'status', 'description', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $fields = ['id','name','key','status','description','created_at','updated_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $form = ['name','key','status','description'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $searchable = [
|
||||
'name' => 'like',
|
||||
'key' => 'like',
|
||||
'status' => '=',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 字典值集合
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function values(): HasMany
|
||||
{
|
||||
return $this->hasMany(DictionaryValues::class, 'dic_id', 'id');
|
||||
}
|
||||
}
|
46
modules/System/Models/DictionaryValues.php
Normal file
46
modules/System/Models/DictionaryValues.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\System\Models;
|
||||
|
||||
use Catch\Base\CatchModel as Model;
|
||||
|
||||
/**
|
||||
* @property $id
|
||||
* @property $dic_id
|
||||
* @property $label
|
||||
* @property $value
|
||||
* @property $sort
|
||||
* @property $status
|
||||
* @property $description
|
||||
* @property $creator_id
|
||||
* @property $created_at
|
||||
* @property $updated_at
|
||||
* @property $deleted_at
|
||||
*/
|
||||
class DictionaryValues extends Model
|
||||
{
|
||||
protected $table = 'system_dictionary_values';
|
||||
|
||||
protected $fillable = [ 'id', 'dic_id', 'label', 'value', 'sort', 'status', 'description', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $fields = ['id','label','value','sort','status','description','created_at','updated_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected array $form = ['dic_id', 'label','value','sort','description'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $searchable = [
|
||||
'dic_ids' => '=',
|
||||
'label' => 'like',
|
||||
'status' => '=',
|
||||
];
|
||||
}
|
20
modules/System/Providers/SystemServiceProvider.php
Normal file
20
modules/System/Providers/SystemServiceProvider.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\System\Providers;
|
||||
|
||||
use Catch\CatchAdmin;
|
||||
use Catch\Providers\CatchModuleServiceProvider;
|
||||
|
||||
class SystemServiceProvider extends CatchModuleServiceProvider
|
||||
{
|
||||
/**
|
||||
* route path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function moduleName(): string
|
||||
{
|
||||
// TODO: Implement path() method.
|
||||
return 'system';
|
||||
}
|
||||
}
|
1
modules/System/README.md
Normal file
1
modules/System/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 系统模块
|
@@ -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('system_dictionary', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 100)->comment('字典名称');
|
||||
$table->string('key')->comment('字典 key');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态 1 启用 2 禁用');
|
||||
$table->string('description', 1000)->comment('备注')->default('');
|
||||
$table->creatorId();
|
||||
$table->createdAt();
|
||||
$table->updatedAt();
|
||||
$table->deletedAt();
|
||||
|
||||
$table->engine='InnoDB';
|
||||
$table->comment('字段管理');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('system_dictionary');
|
||||
}
|
||||
};
|
@@ -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('system_dictionary_values', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('dic_id')->comment('字典ID');
|
||||
$table->string('label')->comment('值名称');
|
||||
$table->tinyInteger('value')->comment('对应值');
|
||||
$table->integer('sort')->default(0)->comment('排序');
|
||||
$table->tinyInteger('status')->default(1)->comment('状态 1 正常 2 禁用');
|
||||
$table->string('description', 1000)->comment('描述')->default('');
|
||||
$table->creatorId();
|
||||
$table->createdAt();
|
||||
$table->updatedAt();
|
||||
$table->deletedAt();
|
||||
|
||||
$table->engine='InnoDB';
|
||||
$table->comment('字典对应值');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('system_dictionary_values');
|
||||
}
|
||||
};
|
193
modules/System/database/seeder/SystemMenusSeeder.php
Normal file
193
modules/System/database/seeder/SystemMenusSeeder.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
return new class extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the seeder.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$menus = $this->menus();
|
||||
|
||||
importTreeData($menus, 'permissions');
|
||||
}
|
||||
|
||||
public function menus(): array
|
||||
{
|
||||
return array (
|
||||
0 =>
|
||||
array (
|
||||
'id' => 96,
|
||||
'parent_id' => 0,
|
||||
'permission_name' => '系统管理',
|
||||
'route' => '/system',
|
||||
'icon' => 'server-stack',
|
||||
'module' => 'system',
|
||||
'permission_mark' => '',
|
||||
'component' => '',
|
||||
'redirect' => NULL,
|
||||
'keepalive' => 1,
|
||||
'type' => 1,
|
||||
'hidden' => 1,
|
||||
'sort' => 1,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535826,
|
||||
'updated_at' => 1683535826,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'id' => 97,
|
||||
'parent_id' => 96,
|
||||
'permission_name' => '字典管理',
|
||||
'route' => 'dictionary',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionary',
|
||||
'component' => '/System/views/dictionary/index.vue',
|
||||
'redirect' => '',
|
||||
'keepalive' => 1,
|
||||
'type' => 2,
|
||||
'hidden' => 1,
|
||||
'sort' => 1,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535863,
|
||||
'updated_at' => 1683535874,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'id' => 103,
|
||||
'parent_id' => 97,
|
||||
'permission_name' => '删除',
|
||||
'route' => '',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionary@destroy',
|
||||
'component' => '',
|
||||
'redirect' => '',
|
||||
'keepalive' => 1,
|
||||
'type' => 3,
|
||||
'hidden' => 1,
|
||||
'sort' => 5,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535980,
|
||||
'updated_at' => 1683535980,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'id' => 99,
|
||||
'parent_id' => 97,
|
||||
'permission_name' => '列表',
|
||||
'route' => '',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionary@index',
|
||||
'component' => '',
|
||||
'redirect' => '',
|
||||
'keepalive' => 1,
|
||||
'type' => 3,
|
||||
'hidden' => 1,
|
||||
'sort' => 1,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535980,
|
||||
'updated_at' => 1683535980,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'id' => 101,
|
||||
'parent_id' => 97,
|
||||
'permission_name' => '读取',
|
||||
'route' => '',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionary@show',
|
||||
'component' => '',
|
||||
'redirect' => '',
|
||||
'keepalive' => 1,
|
||||
'type' => 3,
|
||||
'hidden' => 1,
|
||||
'sort' => 3,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535980,
|
||||
'updated_at' => 1683535980,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
5 =>
|
||||
array (
|
||||
'id' => 100,
|
||||
'parent_id' => 97,
|
||||
'permission_name' => '新增',
|
||||
'route' => '',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionary@store',
|
||||
'component' => '',
|
||||
'redirect' => '',
|
||||
'keepalive' => 1,
|
||||
'type' => 3,
|
||||
'hidden' => 1,
|
||||
'sort' => 2,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535980,
|
||||
'updated_at' => 1683535980,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
6 =>
|
||||
array (
|
||||
'id' => 102,
|
||||
'parent_id' => 97,
|
||||
'permission_name' => '更新',
|
||||
'route' => '',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionary@update',
|
||||
'component' => '',
|
||||
'redirect' => '',
|
||||
'keepalive' => 1,
|
||||
'type' => 3,
|
||||
'hidden' => 1,
|
||||
'sort' => 4,
|
||||
'active_menu' => '',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535980,
|
||||
'updated_at' => 1683535980,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
7 =>
|
||||
array (
|
||||
'id' => 98,
|
||||
'parent_id' => 96,
|
||||
'permission_name' => '字典值管理',
|
||||
'route' => 'dictionary/values/:id',
|
||||
'icon' => '',
|
||||
'module' => 'system',
|
||||
'permission_mark' => 'dictionaryValues',
|
||||
'component' => '/System/views/dictionaryValues/index.vue',
|
||||
'redirect' => '',
|
||||
'keepalive' => 2,
|
||||
'type' => 2,
|
||||
'hidden' => 2,
|
||||
'sort' => 1,
|
||||
'active_menu' => '/system/dictionary',
|
||||
'creator_id' => 1,
|
||||
'created_at' => 1683535961,
|
||||
'updated_at' => 1683593856,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
17
modules/System/routes/route.php
Normal file
17
modules/System/routes/route.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\System\Http\Controllers\DictionaryController;
|
||||
use Modules\System\Http\Controllers\DictionaryValuesController;
|
||||
|
||||
Route::prefix('system')->group(function(){
|
||||
|
||||
Route::apiResource('dictionary', DictionaryController::class);
|
||||
Route::put('dictionary/enable/{id}', [DictionaryController::class, 'enable']);
|
||||
|
||||
Route::apiResource('dic/values', DictionaryValuesController::class);
|
||||
Route::put('dic/values/enable/{id}', [DictionaryValuesController::class, 'enable']);
|
||||
|
||||
//next
|
||||
});
|
||||
|
56
modules/System/views/dictionary/create.vue
Normal file
56
modules/System/views/dictionary/create.vue
Normal file
@@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
|
||||
<el-form-item
|
||||
label="字典名称"
|
||||
prop="name"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
message: '字典名称必须填写',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input v-model="formData.name" name="name" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="字典键名"
|
||||
prop="key"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
message: '字典键名必须填写',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input v-model="formData.key" name="key" clearable />
|
||||
</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 } 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'])
|
||||
onMounted(() => {
|
||||
close(() => emit('close'))
|
||||
})
|
||||
</script>
|
73
modules/System/views/dictionary/index.vue
Normal file
73
modules/System/views/dictionary/index.vue
Normal file
@@ -0,0 +1,73 @@
|
||||
<template>
|
||||
<div>
|
||||
<Search :search="search" :reset="reset">
|
||||
<template v-slot:body>
|
||||
<el-form-item label="字典名称" prop="name">
|
||||
<el-input v-model="query.name" name="name" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="字典键名" prop="key">
|
||||
<el-input v-model="query.key" name="key" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="字典状态" prop="status">
|
||||
<el-input v-model="query.status" name="status" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</Search>
|
||||
|
||||
<div class="table-default">
|
||||
<Operate :show="open" />
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
||||
<el-table-column prop="id" label="ID" width="100" />
|
||||
<el-table-column prop="name" label="字典名称" />
|
||||
<el-table-column prop="key" label="字典键名">
|
||||
<template #default="scope">
|
||||
<router-link :to="{ path: '/system/dictionary/values/' + scope.row.id }">
|
||||
<el-text type="primary">{{ scope.row.key }}</el-text>
|
||||
</router-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<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="description" label="字典描述" />
|
||||
<el-table-column label="操作" width="300">
|
||||
<template #default="scope">
|
||||
<Update @click="open(scope.row.id)" />
|
||||
<Destroy @click="destroy(api, scope.row.id)" />
|
||||
<router-link :to="{ path: '/system/dictionary/values/' + scope.row.id }">
|
||||
<Show text="列表" class="ml-3" />
|
||||
</router-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<Paginate />
|
||||
</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 = 'system/dictionary'
|
||||
|
||||
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>
|
65
modules/System/views/dictionaryValues/create.vue
Normal file
65
modules/System/views/dictionaryValues/create.vue
Normal file
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
|
||||
<el-form-item
|
||||
label="字典值名"
|
||||
prop="label"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
message: '字典值名必须填写',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input v-model="formData.label" name="label" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label="字典键值"
|
||||
prop="value"
|
||||
:rules="[
|
||||
{
|
||||
required: true,
|
||||
message: '字典键值必须填写',
|
||||
},
|
||||
]"
|
||||
>
|
||||
<el-input-number v-model="formData.value" name="value" clearable :min="1" />
|
||||
</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 } from 'vue'
|
||||
import router from '/admin/router'
|
||||
|
||||
const props = defineProps({
|
||||
primary: String | Number,
|
||||
api: String,
|
||||
})
|
||||
|
||||
const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)
|
||||
|
||||
// 默认值
|
||||
formData.value.value = 1
|
||||
formData.value.sort = 1
|
||||
formData.value.dic_id = router.currentRoute.value.params.id
|
||||
|
||||
if (props.primary) {
|
||||
useShow(props.api, props.primary, formData)
|
||||
}
|
||||
|
||||
const emit = defineEmits(['close'])
|
||||
onMounted(() => {
|
||||
close(() => emit('close'))
|
||||
})
|
||||
</script>
|
64
modules/System/views/dictionaryValues/index.vue
Normal file
64
modules/System/views/dictionaryValues/index.vue
Normal file
@@ -0,0 +1,64 @@
|
||||
<template>
|
||||
<div>
|
||||
<Search :search="search" :reset="reset">
|
||||
<template v-slot:body>
|
||||
<el-form-item label="字典值名" prop="label">
|
||||
<el-input v-model="query.label" name="label" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-input v-model="query.status" name="status" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</Search>
|
||||
<div class="table-default">
|
||||
<Operate :show="open" />
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
||||
<el-table-column prop="id" label="ID" />
|
||||
<el-table-column prop="label" label="字典值名称" />
|
||||
<el-table-column prop="value" 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" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" 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>
|
||||
<Paginate />
|
||||
</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'
|
||||
import router from '/admin/router'
|
||||
|
||||
const api = 'system/dic/values'
|
||||
|
||||
const { data, query, search, reset, loading } = useGetList(api)
|
||||
query.value.dic_id = router.currentRoute.value.params.id
|
||||
|
||||
const { destroy, deleted } = useDestroy()
|
||||
const { open, close, title, visible, id } = useOpen()
|
||||
|
||||
const tableData = computed(() => data.value?.data)
|
||||
|
||||
onMounted(() => {
|
||||
search()
|
||||
deleted(reset)
|
||||
})
|
||||
</script>
|
@@ -22,12 +22,18 @@ class AuthController extends Controller
|
||||
/* @var User $user */
|
||||
$user = User::query()->where('email', $request->get('email'))->first();
|
||||
|
||||
Event::dispatch(new Login($request, $user));
|
||||
Event::dispatch(new Login($request, $user ? ($user->isDisabled() ? null : $user) : null));
|
||||
|
||||
if ($user && Hash::check($request->get('password'), $user->password)) {
|
||||
if ($user) {
|
||||
if ($user->isDisabled()) {
|
||||
throw new FailedException('账号被禁用,请联系管理员');
|
||||
}
|
||||
|
||||
if (Hash::check($request->get('password'), $user->password)) {
|
||||
$token = $user->createToken('token')->plainTextToken;
|
||||
return compact('token');
|
||||
}
|
||||
}
|
||||
|
||||
throw new FailedException('登录失败!请检查邮箱或者密码');
|
||||
}
|
||||
|
@@ -6,13 +6,14 @@ use Catch\Base\CatchController as Controller;
|
||||
use Catch\Support\Module\ModuleRepository;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Permissions\Models\Departments;
|
||||
use Modules\User\Models\LogLogin;
|
||||
use Modules\User\Models\LogOperate;
|
||||
use Modules\User\Models\User;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Modules\User\Http\Requests\UserRequest;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@@ -47,10 +48,10 @@ class UserController extends Controller
|
||||
/**
|
||||
* store
|
||||
*
|
||||
* @param Request $request
|
||||
* @param UserRequest $request
|
||||
* @return false|mixed
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(UserRequest $request)
|
||||
{
|
||||
return $this->user->storeBy($request->all());
|
||||
}
|
||||
@@ -80,10 +81,10 @@ class UserController extends Controller
|
||||
* update
|
||||
*
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @param UserRequest $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function update($id, Request $request)
|
||||
public function update($id, UserRequest $request)
|
||||
{
|
||||
return $this->user->updateBy($id, $request->all());
|
||||
}
|
||||
@@ -158,4 +159,16 @@ class UserController extends Controller
|
||||
return $builder;
|
||||
})->getList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
return User::query()
|
||||
->select('id', 'username', 'email', 'created_at')
|
||||
->without('roles')
|
||||
->get()
|
||||
->download(['id', '昵称', '邮箱', '创建时间']);
|
||||
}
|
||||
}
|
||||
|
44
modules/User/Http/Requests/UserRequest.php
Normal file
44
modules/User/Http/Requests/UserRequest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Permissions\Models\Roles;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => [
|
||||
'required',
|
||||
Rule::unique('users')->where(function ($query) {
|
||||
return $query->when($this->get('id'), function ($query){
|
||||
$query->where('id', '<>', $this->get('id'));
|
||||
})->where('deleted_at', 0);
|
||||
})
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* messages
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'email.required' => '邮箱必须填写',
|
||||
|
||||
'email.unique' => '邮箱已存在',
|
||||
];
|
||||
}
|
||||
}
|
@@ -58,23 +58,19 @@ trait UserRelations
|
||||
|
||||
/* @var Permissions $permissionsModel */
|
||||
$permissionsModel = app($this->getPermissionsModel());
|
||||
|
||||
if ($this->isSuperAdmin()) {
|
||||
$permissions = $permissionsModel->get();
|
||||
} else {
|
||||
$permissions = Collection::make();
|
||||
|
||||
app($this->getRolesModel())->with(['permissions'])->get()
|
||||
|
||||
->each(function ($role) use (&$permissions) {
|
||||
$permissions = $permissions->concat($role->permissions);
|
||||
$permissionIds = Collection::make();
|
||||
$this->roles()->with('permissions')->get()
|
||||
->each(function ($role) use (&$permissionIds) {
|
||||
$permissionIds = $permissionIds->concat($role->permissions?->pluck('id'));
|
||||
});
|
||||
|
||||
$permissions = $permissions->unique();
|
||||
$permissions = $permissionsModel->whereIn('id', $permissionIds->unique())->get();
|
||||
}
|
||||
|
||||
$this->setAttribute('permissions', $permissions->each(fn ($permission) => $permission->setAttribute('hidden', $permission->isHidden())));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -103,14 +99,15 @@ trait UserRelations
|
||||
if ($permission->isAction()) {
|
||||
[$controller, $action] = explode('@', $permission->permission_mark);
|
||||
|
||||
$actions->add(CatchAdmin::getModuleControllerNamespace($permission->module).$controller.'Controller@'.$action);
|
||||
$actions->add(CatchAdmin::getModuleControllerNamespace($permission->module). ucfirst($controller).'Controller@'.$action);
|
||||
}
|
||||
});
|
||||
|
||||
// 自定义权限判断
|
||||
if ($permission) {
|
||||
[$module, $controller, $action] = explode('@', $permission);
|
||||
|
||||
$permission = CatchAdmin::getModuleControllerNamespace($module).$controller.'Controller@'.$action;
|
||||
$permission = CatchAdmin::getModuleControllerNamespace($module). ucfirst($controller) .'Controller@'.$action;
|
||||
}
|
||||
|
||||
return $actions->contains($permission ?: Route::currentRouteAction());
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Modules\User\Models;
|
||||
|
||||
use Catch\Base\CatchModel as Model;
|
||||
use Catch\Enums\Status;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
@@ -37,7 +38,7 @@ class User extends Model implements AuthenticatableContract
|
||||
public array $searchable = [
|
||||
'username' => 'like',
|
||||
'email' => 'like',
|
||||
'status' => '='
|
||||
'status' => '=',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -73,7 +74,8 @@ class User extends Model implements AuthenticatableContract
|
||||
protected function DepartmentId(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value) => $value ? : null
|
||||
get: fn($value) => $value ? : null,
|
||||
set: fn($value) => $value ? : 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,10 +97,16 @@ class User extends Model implements AuthenticatableContract
|
||||
*/
|
||||
public function updateBy($id, array $data): mixed
|
||||
{
|
||||
if (isset($data['password']) && ! $data['password']) {
|
||||
if (empty($data['password'])) {
|
||||
unset($data['password']);
|
||||
}
|
||||
|
||||
return parent::updateBy($id, $data);
|
||||
}
|
||||
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
|
||||
return $this->status == Status::Disable->value;
|
||||
}
|
||||
}
|
||||
|
@@ -14,4 +14,8 @@ Route::put('users/enable/{id}', [UserController::class, 'enable']);
|
||||
Route::match(['post', 'get'], 'user/online', [UserController::class, 'online']);
|
||||
Route::get('user/login/log', [UserController::class, 'loginLog']);
|
||||
Route::get('user/operate/log', [UserController::class, 'operateLog']);
|
||||
Route::get('user/operate/log', [UserController::class, 'operateLog']);
|
||||
Route::get('user/export', [UserController::class, 'export']);
|
||||
|
||||
|
||||
|
||||
|
@@ -2,8 +2,8 @@
|
||||
<div class="table-default">
|
||||
<div class="w-full flex justify-end">
|
||||
<el-radio-group v-model="query.scope" size="small" @change="search">
|
||||
<el-radio-button label="self">只看自己</el-radio-button>
|
||||
<el-radio-button label="all">全部</el-radio-button>
|
||||
<el-radio-button value="self">只看自己</el-radio-button>
|
||||
<el-radio-button value="all">全部</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
||||
|
@@ -1,9 +1,6 @@
|
||||
<template>
|
||||
<el-form :model="profile" ref="form" v-loading="loading" label-position="top">
|
||||
<Upload class="w-28 h-28 rounded-full mx-auto" action="upload/image" :show-file-list="false" name="image" :on-success="uploadAvatar">
|
||||
<img :src="profile.avatar" class="h-28 rounded-full" v-if="profile.avatar" />
|
||||
<Icon name="plus" v-else />
|
||||
</Upload>
|
||||
<Upload imageClass="w-28 h-28 rounded-full mx-auto" v-model="profile.avatar" />
|
||||
<el-form-item
|
||||
label="昵称"
|
||||
prop="username"
|
||||
@@ -66,14 +63,12 @@ interface profile {
|
||||
password: string
|
||||
}
|
||||
|
||||
const profile = ref<profile>(
|
||||
Object.assign({
|
||||
const profile = ref<profile>({
|
||||
avatar: '',
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
}),
|
||||
)
|
||||
})
|
||||
const { form, loading, submitForm, afterCreate } = useCreate('user/online', null, profile)
|
||||
|
||||
const getUserInfo = () => {
|
||||
@@ -91,15 +86,6 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
const userStore = useUserStore()
|
||||
const uploadAvatar = (response, uploadFile) => {
|
||||
if (response.code === Code.SUCCESS) {
|
||||
form.value.avatar = response.data.path
|
||||
profile.value.avatar = response.data.path
|
||||
} else {
|
||||
Message.error(response.message)
|
||||
}
|
||||
}
|
||||
|
||||
afterCreate.value = () => {
|
||||
userStore.getUserInfo()
|
||||
}
|
||||
|
@@ -16,12 +16,17 @@
|
||||
</template>
|
||||
</Search>
|
||||
<div class="table-default">
|
||||
<Operate :show="open" />
|
||||
<Operate :show="open">
|
||||
<template #operate>
|
||||
<el-button @click="download('/user')">导出</el-button>
|
||||
</template>
|
||||
</Operate>
|
||||
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
||||
<el-table-column prop="username" label="用户名" width="150" />
|
||||
<el-table-column prop="avatar" label="头像">
|
||||
<template #default="scope">
|
||||
<el-avatar :src="scope.row.avatar" />
|
||||
<el-avatar :icon="UserFilled" v-if="!scope.row.avatar" />
|
||||
<el-avatar :src="scope.row.avatar" v-else />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="email" label="邮箱" />
|
||||
@@ -50,6 +55,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
// @ts-nocheck
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import Create from './create.vue'
|
||||
import { useGetList } from '/admin/composables/curd/useGetList'
|
||||
@@ -58,14 +64,16 @@ import { useOpen } from '/admin/composables/curd/useOpen'
|
||||
import Department from './components/department.vue'
|
||||
import { useUserStore } from '/admin/stores/modules/user'
|
||||
import { isUndefined } from '/admin/support/helper'
|
||||
import { UserFilled } from '@element-plus/icons-vue'
|
||||
import { useExcelDownload } from '/resources/admin/composables/curd/useExcelDownload'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const api = 'users'
|
||||
|
||||
const { data, query, search, reset, loading } = useGetList(api)
|
||||
const { destroy, deleted } = useDestroy()
|
||||
const { open, close, title, visible, id } = useOpen()
|
||||
const { download } = useExcelDownload()
|
||||
|
||||
const tableData = computed(() => data.value?.data)
|
||||
|
||||
@@ -74,9 +82,7 @@ const hasRoles = ref<boolean>(false)
|
||||
|
||||
onMounted(() => {
|
||||
search()
|
||||
|
||||
deleted(reset)
|
||||
|
||||
hasRoles.value = !isUndefined(userStore.getRoles)
|
||||
})
|
||||
</script>
|
||||
|
64
package.json
64
package.json
@@ -8,46 +8,48 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@heroicons/vue": "^2.0.14",
|
||||
"@tinymce/tinymce-vue": "^5.0.1",
|
||||
"@vueuse/core": "^9.12.0",
|
||||
"autoprefixer": "^10.4.13",
|
||||
"element-plus": "^2.2.33",
|
||||
"@heroicons/vue": "^2.1.3",
|
||||
"@tinymce/tinymce-vue": "^5.1.1",
|
||||
"@vueuse/core": "^10.9.0",
|
||||
"element-plus": "^2.6.2",
|
||||
"nprogress": "^0.2.0",
|
||||
"pinia": "^2.0.32",
|
||||
"postcss": "^8.4.21",
|
||||
"tailwindcss": "^3.2.2",
|
||||
"terser": "^5.16.5",
|
||||
"vue": "^3.2.47",
|
||||
"pinia": "^2.1.7",
|
||||
"terser": "^5.29.2",
|
||||
"vue": "^3.4.21",
|
||||
"vue-i18n": "9",
|
||||
"vue-router": "4.1.6",
|
||||
"vuedraggable": "^4.1.0"
|
||||
"vue-router": "4.3.0",
|
||||
"vuedraggable": "^2.24.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify-json/logos": "^1.1.22",
|
||||
"@rollup/plugin-alias": "^4.0.3",
|
||||
"@iconify-json/logos": "^1.1.42",
|
||||
"@rollup/plugin-alias": "^5.1.0",
|
||||
"@types/mockjs": "^1.0.7",
|
||||
"@types/node": "^18.14.6",
|
||||
"@types/node": "^20.11.30",
|
||||
"@types/nprogress": "^0.2.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"@vitejs/plugin-vue": "^4.0.0",
|
||||
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
||||
"axios": "^1.3.4",
|
||||
"eslint": "^8.35.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||
"@typescript-eslint/parser": "^6.21.0",
|
||||
"@vitejs/plugin-vue": "^5.0.4",
|
||||
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"axios": "^1.6.8",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-standard": "^17.0.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-n": "^15.6.0",
|
||||
"eslint-plugin-n": "^16.0.0",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-vue": "^9.9.0",
|
||||
"prettier": "2.8.4",
|
||||
"sass": "^1.58.0",
|
||||
"typescript": "^4.9.5",
|
||||
"unplugin-auto-import": "^0.14.4",
|
||||
"unplugin-icons": "^0.15.2",
|
||||
"unplugin-vue-components": "^0.24.0",
|
||||
"vite": "^4.1.4",
|
||||
"eslint-plugin-vue": "^9.23.0",
|
||||
"mockjs": "^1.1.0",
|
||||
"postcss": "^8.4.38",
|
||||
"prettier": "3.2.5",
|
||||
"sass": "^1.72.0",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"typescript": "^5.4.3",
|
||||
"unplugin-auto-import": "^0.17.5",
|
||||
"unplugin-icons": "^0.18.5",
|
||||
"unplugin-vue-components": "^0.26.0",
|
||||
"vite": "^5.2.3",
|
||||
"vite-plugin-html": "^3.2.0",
|
||||
"vue-tsc": "^1.2.0"
|
||||
"vite-plugin-mock": "^3.0.0",
|
||||
"vue-tsc": "^2.0.7"
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="pt-4">
|
||||
<slot />
|
||||
</div>
|
||||
<template #footer v-if="showFooter">
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="close">{{ $t('system.cancel') }}</el-button>
|
||||
|
@@ -1,20 +1,28 @@
|
||||
<template>
|
||||
<div :class="`grid ${grid} gap-y-6`">
|
||||
<div class="h-84 pl-2 pr-2">
|
||||
<div :class="`grid ${grid} gap-y-4 gap-x-4` + ' mt-3 h-72'">
|
||||
<div v-for="icon in icons" :key="icon" class="flex justify-center hover:cursor-pointer" @click="selectIcon(icon)">
|
||||
<div v-if="modelValue === icon">
|
||||
<div class="flex justify-center w-full text-violet-700"><Icon :name="icon" /></div>
|
||||
<div class="text-sm text-violet-700">{{ icon }}</div>
|
||||
<div class="flex justify-center w-full text-violet-700"><Icon :name="icon" className="w-5 h-5" /></div>
|
||||
<div class="text-[1px] text-violet-700">{{ icon }}</div>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div class="flex justify-center w-full"><Icon :name="icon" /></div>
|
||||
<div class="text-sm">{{ icon }}</div>
|
||||
<div class="flex justify-center w-full"><Icon :name="icon" className="w-5 h-5" /></div>
|
||||
<div class="text-[1px]">{{ icon }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center mt-6">
|
||||
<el-pagination layout="prev,next" :page-size="limit" :total="total" prev-text="上一页" next-text="下一页" @next-click="handleNext" @prev-click="handlePrev" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: String,
|
||||
@@ -22,18 +30,38 @@ const props = defineProps({
|
||||
},
|
||||
grid: {
|
||||
type: String,
|
||||
default: 'grid-cols-5',
|
||||
default: 'grid-cols-4',
|
||||
},
|
||||
})
|
||||
|
||||
const emits = defineEmits(['update:modelValue', 'close'])
|
||||
|
||||
const limit = ref<number>(16)
|
||||
const icons = ref<Array<string>>([])
|
||||
const total = ref<number>(0)
|
||||
function getIcons(page = 1) {
|
||||
const start = (page - 1) * limit.value
|
||||
const end = start + limit.value
|
||||
icons.value = constIcons.slice(start, end)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getIcons()
|
||||
total.value = constIcons.length
|
||||
})
|
||||
const handleNext = (value: number) => {
|
||||
getIcons(value)
|
||||
}
|
||||
|
||||
const handlePrev = (value: number) => {
|
||||
getIcons(value)
|
||||
}
|
||||
const selectIcon = (icon: string) => {
|
||||
emits('update:modelValue', icon)
|
||||
emits('close')
|
||||
}
|
||||
// icons
|
||||
const icons = [
|
||||
const constIcons = [
|
||||
'academic-cap',
|
||||
'adjustments-horizontal',
|
||||
'adjustments-vertical',
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<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" />
|
||||
<el-pagination background :layout="layout" :current-page="page" :page-size="limit" @current-change="changePage" @size-change="changeLimit" :total="parseInt(total)" :page-sizes="pageSizes" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -14,12 +14,10 @@ const pageSizes = [10, 20, 30, 50]
|
||||
interface paginate {
|
||||
page: number
|
||||
limit: number
|
||||
total: number
|
||||
total: string
|
||||
changePage: number
|
||||
changeLimit: number
|
||||
}
|
||||
|
||||
const { page, limit, total, changePage, changeLimit } = inject('paginate') as paginate
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@@ -1,8 +1,21 @@
|
||||
<template>
|
||||
<el-upload ref="upload" :action="actionApi" :auto-upload="auto" :headers="{ authorization: token, 'Request-from': 'Dashboard' }" v-bind="$attrs">
|
||||
<el-upload
|
||||
ref="upload"
|
||||
:action="actionApi"
|
||||
:show-file-list="false"
|
||||
name="image"
|
||||
:auto-upload="auto"
|
||||
:headers="{ authorization: token, 'Request-from': 'Dashboard' }"
|
||||
v-bind="$attrs"
|
||||
:on-success="handleSuccess"
|
||||
>
|
||||
<template v-for="(index, name) in $slots" v-slot:[name]>
|
||||
<slot :name="name"></slot>
|
||||
</template>
|
||||
<img :src="modelValue" v-if="modelValue" :class="imageClass" />
|
||||
<div v-else class="w-24 h-24 border-blue-100 border-dashed border rounded flex justify-center pt-8">
|
||||
<Icon name="plus" />
|
||||
</div>
|
||||
</el-upload>
|
||||
</template>
|
||||
|
||||
@@ -10,18 +23,30 @@
|
||||
import { ref } from 'vue'
|
||||
import { env } from '/admin/support/helper'
|
||||
import { getAuthToken } from '/admin/support/helper'
|
||||
import { Code } from '/admin/enum/app'
|
||||
import Message from '/admin/support/message'
|
||||
|
||||
const props = defineProps({
|
||||
action: {
|
||||
type: String,
|
||||
default: 'upload',
|
||||
default: 'upload/image',
|
||||
},
|
||||
auto: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: '',
|
||||
require: true,
|
||||
},
|
||||
imageClass: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
})
|
||||
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const baseURL = env('VITE_BASE_URL')
|
||||
|
||||
const actionApi = ref<string>('')
|
||||
@@ -30,4 +55,12 @@ actionApi.value = baseURL + props.action
|
||||
|
||||
const token = ref<string>()
|
||||
token.value = 'Bearer ' + getAuthToken()
|
||||
|
||||
const handleSuccess = (response: any) => {
|
||||
if (response.code === Code.SUCCESS) {
|
||||
emits('update:modelValue', response.data.path)
|
||||
} else {
|
||||
Message.error(response.message)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
50
resources/admin/composables/curd/useExcelDownload.ts
Normal file
50
resources/admin/composables/curd/useExcelDownload.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import Request from '/admin/support/request'
|
||||
import { ref, watch } from 'vue'
|
||||
import Message from '/admin/support/message'
|
||||
|
||||
export function useExcelDownload() {
|
||||
const http = new Request()
|
||||
const isSuccess = ref(false)
|
||||
const loading = ref<boolean>(false)
|
||||
const afterDownload = ref()
|
||||
function download(path: string, data: object = {}) {
|
||||
loading.value = true
|
||||
http
|
||||
.setResponseType('blob')
|
||||
.init()
|
||||
.get(path + '/export', data)
|
||||
.then(r => {
|
||||
if (r.headers['content-type'] === 'application/json') {
|
||||
const blob = new Blob([r.data], { type: r.headers['content-type'] })
|
||||
const blobReader = new Response(blob).json()
|
||||
blobReader.then(res => {
|
||||
if (res.code === 1e4) {
|
||||
Message.success(res.message)
|
||||
} else {
|
||||
Message.error(res.message)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const downloadLink = document.createElement('a')
|
||||
const blob = new Blob([r.data], { type: r.headers['content-type'] })
|
||||
downloadLink.href = URL.createObjectURL(blob)
|
||||
downloadLink.download = r.headers.filename
|
||||
document.body.appendChild(downloadLink)
|
||||
downloadLink.click()
|
||||
document.body.removeChild(downloadLink)
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
const success = (func: Function) => {
|
||||
watch(isSuccess, function () {
|
||||
isSuccess.value = false
|
||||
func()
|
||||
})
|
||||
}
|
||||
|
||||
return { download, success, loading, afterDownload }
|
||||
}
|
@@ -57,11 +57,7 @@ export function useGetList(path: string, isPaginate: boolean = true) {
|
||||
// reset
|
||||
function reset() {
|
||||
resetPage()
|
||||
|
||||
if (isPaginate) {
|
||||
query.value = Object.assign({ page: page.value, limit: limit.value })
|
||||
}
|
||||
|
||||
query.value = Object.assign(isPaginate ? { page: page.value, limit: limit.value } : {})
|
||||
getList()
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ function checkAction(el: any, action: any) {
|
||||
action = action.value.replace('@', '.').toLowerCase()
|
||||
const hasAction = permissions?.some(permission => {
|
||||
if (permission.type === MenuType.Button_Type) {
|
||||
const a: string = permission.module + '.' + permission.permission_mark.replace('@', '.')
|
||||
const a: string = permission.module + '.' + permission.permission_mark.replaceAll('@', '.')
|
||||
return action === a.toLowerCase()
|
||||
}
|
||||
})
|
||||
@@ -18,7 +18,7 @@ function checkAction(el: any, action: any) {
|
||||
el.parentNode && el.parentNode.removeChild(el)
|
||||
}
|
||||
} else {
|
||||
throw new Error(`need action! Like v-action="module.controller.action" || v-action="module@controller@action" `)
|
||||
throw new Error(`need action! Like v-action="module.controller.action"`)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<el-sub-menu :index="menu?.path" :class="subMenuClass" v-if="menu?.children?.length">
|
||||
<el-sub-menu :index="menu?.path" :class="subMenuClass" v-if="menu?.children?.length" :key="menu?.path">
|
||||
<template #title>
|
||||
<el-icon>
|
||||
<Icon :name="menu?.meta?.icon" v-if="menu?.meta?.icon" class="text-sm" />
|
||||
@@ -9,17 +9,20 @@
|
||||
<slot />
|
||||
</el-sub-menu>
|
||||
|
||||
<el-menu-item v-else class="ct-menu-item" :index="menu?.path" @click="isMiniScreen() && store.changeExpaned()">
|
||||
<el-menu-item v-else class="ct-menu-item" :index="menu?.path" @click="isMiniScreen() && store.changeExpaned()" :key="menu?.name">
|
||||
<el-icon>
|
||||
<Icon :name="menu?.meta?.icon" v-if="menu?.meta?.icon" class="text-sm" />
|
||||
</el-icon>
|
||||
<span>{{ menu?.meta?.title }}</span>
|
||||
<span v-if="menu?.path.indexOf('https://') !== -1 || menu?.path.indexOf('http://') !== -1">
|
||||
<span @click="openUrl(menu?.path as string)">{{ menu?.meta?.title }}</span>
|
||||
</span>
|
||||
<span v-else>{{ menu?.meta?.title }}</span>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="MenuItem" setup>
|
||||
<script lang="ts" setup>
|
||||
import { Menu } from '/admin/types/Menu'
|
||||
import { onMounted, PropType, ref } from 'vue'
|
||||
import { PropType } from 'vue'
|
||||
import { useAppStore } from '/admin/stores/modules/app'
|
||||
import { isMiniScreen } from '/admin/support/helper'
|
||||
|
||||
@@ -37,6 +40,12 @@ defineProps({
|
||||
require: true,
|
||||
},
|
||||
})
|
||||
|
||||
const openUrl = (path: string) => {
|
||||
const start = path.indexOf('https://') || path.indexOf('http://')
|
||||
window.open(path.substring(start))
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
@@ -7,22 +7,32 @@
|
||||
:collapse="!appStore.isExpand"
|
||||
:collapse-transition="false"
|
||||
:router="true"
|
||||
@select="selectMenu"
|
||||
:unique-opened="true"
|
||||
>
|
||||
<slot />
|
||||
</el-menu>
|
||||
</template>
|
||||
<script lang="ts" setup name="menus">
|
||||
<script lang="ts" setup>
|
||||
import { useAppStore } from '/admin/stores/modules/app'
|
||||
import { watch } from 'vue'
|
||||
import router from '/admin/router'
|
||||
import { useNavTabStore } from '/admin/stores/modules/tabs'
|
||||
|
||||
const appStore = useAppStore()
|
||||
|
||||
const selectMenu = (index: string) => {
|
||||
if (index.startsWith('http') || index.startsWith('https')) {
|
||||
window.open(index)
|
||||
const navTabStore = useNavTabStore()
|
||||
watch(() => router.currentRoute, (to, from) => {
|
||||
const tab: any = {
|
||||
name: to.value.name,
|
||||
fullPath: to.value.fullPath,
|
||||
path: to.value.path,
|
||||
is_active: true,
|
||||
meta: {
|
||||
title: to.value.meta.title,
|
||||
affix: false,
|
||||
}
|
||||
}
|
||||
navTabStore.addTabs(tab)
|
||||
}, {deep:true, immediate:true})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
70
resources/admin/layout/components/header/contextMenu.vue
Normal file
70
resources/admin/layout/components/header/contextMenu.vue
Normal file
@@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<div @contextmenu.prevent="handleContextMenu" class="flex gap-x-2">
|
||||
<slot></slot>
|
||||
<!-- 右击菜单 -->
|
||||
<div v-if="showMenu" class="absolute z-[1000] bg-white dark:bg-regal-dark shadow-xl rounded border border-gray-200" :style="{ top: `${position.y}px`, left: `${position.x}px` }">
|
||||
<ul class="w-20 text-center py-1">
|
||||
<li v-for="(item, index) in menuItems" :key="index" @click="item.action()" class="hover:bg-gray-50 px-2 py-1 hover:cursor-pointer text-[12px]">
|
||||
{{ item.label }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, onUnmounted } from 'vue';
|
||||
import { useNavTabStore } from '/admin/stores/modules/tabs';
|
||||
|
||||
const navTabStore = useNavTabStore();
|
||||
interface MenuItem {
|
||||
label: string;
|
||||
action: Function;
|
||||
}
|
||||
|
||||
const position = reactive({ x: 0, y: 0 });
|
||||
const showMenu = ref(false);
|
||||
const menuItems = ref<Array<MenuItem>>([
|
||||
{ label: '刷新', action: () => {
|
||||
navTabStore.refreshCurrentTab();
|
||||
}
|
||||
},
|
||||
{ label: '关闭', action: () => {
|
||||
navTabStore.removeCurrentTab();
|
||||
}
|
||||
},
|
||||
{ label: '关闭其他', action: () => { navTabStore.removeOtherTabs() } },
|
||||
{ label: '关闭所有', action: () => { navTabStore.removeAllTabs() } },
|
||||
]);
|
||||
|
||||
const handleContextMenu = (event: MouseEvent) => {
|
||||
event.preventDefault();
|
||||
position.x = event.clientX;
|
||||
position.y = event.clientY;
|
||||
showMenu.value = true;
|
||||
};
|
||||
|
||||
const handleClickOutside = () => {
|
||||
showMenu.value = false;
|
||||
};
|
||||
|
||||
window.addEventListener('click', handleClickOutside);
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('click', handleClickOutside);
|
||||
});
|
||||
|
||||
const handleMenuItemClick = (action: string) => {
|
||||
console.log('执行操作:', action);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.context-menu {
|
||||
position: absolute;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
|
||||
z-index: 1000;
|
||||
}
|
||||
</style>
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="flex flex-row h-16 w-full drop-shadow border-l dark:border-l-0 border-gray-200" style="background-color: var(--header-bg-color)">
|
||||
<div class="flex flex-row justify-between w-full">
|
||||
<div class="flex flex-row h-14 w-full drop-shadow border-l border-gray-200" style="background-color: var(--header-bg-color)">
|
||||
<div class="flex flex-row justify-between w-full h-14">
|
||||
<div class="flex flex-row min-w-[17rem]">
|
||||
<div class="h-full flex items-center w-8 ml-2 hover:cursor-pointer" @click="store.changeExpaned">
|
||||
<Icon name="list-bullet" class="w-6 h-8" />
|
||||
@@ -24,11 +24,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Tabs/>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { useAppStore } from '/admin/stores/modules/app'
|
||||
import Notification from './notification.vue'
|
||||
import MenuSearch from './menuSearch.vue'
|
||||
|
||||
import Tabs from './tabs.vue'
|
||||
const store = useAppStore()
|
||||
</script>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-3 hover:cursor-pointer">
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-2 hover:cursor-pointer">
|
||||
<div class="flex hover:cursor-pointer pl-1 pr-1">
|
||||
<el-dropdown size="large" class="flex items-center justify-center hover:cursor-pointer w-full" @command="selectLanguage">
|
||||
<Icon name="language" />
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-3 hover:cursor-pointer">
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-2 hover:cursor-pointer">
|
||||
<div class="flex flex-row w-96">
|
||||
<Icon name="magnifying-glass" class="hidden sm:block" @click="searchMenuVisiable = true" />
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<!-- 通知 -->
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-3 hover:cursor-pointer" ref="messageRef" v-click-outside="onClickOutside">
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-2 hover:cursor-pointer" ref="messageRef" v-click-outside="onClickOutside">
|
||||
<el-badge :value="3">
|
||||
<Icon name="bell" />
|
||||
</el-badge>
|
||||
|
29
resources/admin/layout/components/header/tabs.vue
Normal file
29
resources/admin/layout/components/header/tabs.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import { useNavTabStore } from '/admin/stores/modules/tabs'
|
||||
import ContextMenu from './contextMenu.vue'
|
||||
import { computed, ref, onMounted,onBeforeUnmount, watch } from 'vue'
|
||||
const navTabStore = useNavTabStore()
|
||||
const tabs = computed(() => navTabStore.getNavTabs)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-10 bg-white dark:bg-regal-dark px-1 sm:px-3 w-full flex gap-x-2" ref="container" v-if="tabs.length > 0">
|
||||
<ContextMenu>
|
||||
<el-tag
|
||||
class="mt-1.5 hover:cursor-pointer"
|
||||
v-for="(tag, index) in tabs" :key="index"
|
||||
:closable="!tag.meta.affix"
|
||||
:disable-transitions="false"
|
||||
:effect="tag.is_active ? 'dark' : 'plain'"
|
||||
@click.prevent="navTabStore.selectTab(tag)"
|
||||
@close="navTabStore.removeTab(index)"
|
||||
>
|
||||
{{ tag.meta.title }}
|
||||
</el-tag>
|
||||
</ContextMenu>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-3 hover:cursor-pointer">
|
||||
<div class="w-10 h-10 grid place-items-center rounded-full mt-2 hover:cursor-pointer">
|
||||
<Icon name="moon" @click="changeTheme()" v-if="isDark" />
|
||||
<Icon name="sun" @click="changeTheme()" v-else />
|
||||
</div>
|
||||
|
@@ -37,8 +37,7 @@ const guard = (router: Router) => {
|
||||
// 挂载路由(实际是从后端获取用户的权限)
|
||||
const permissionStore = usePermissionsStore()
|
||||
// 动态路由挂载
|
||||
const asyncRoutes = permissionStore.getAsyncMenusFrom(toRaw(userStore.getPermissions))
|
||||
console.log(asyncRoutes)
|
||||
const asyncRoutes = permissionStore.getAsyncMenusFrom(toRaw(userStore.getPermissions), true)
|
||||
asyncRoutes.forEach((route: Menu) => {
|
||||
router.addRoute(route as unknown as RouteRecordRaw)
|
||||
})
|
||||
|
124
resources/admin/stores/modules/tabs/index.ts
Normal file
124
resources/admin/stores/modules/tabs/index.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import router from '/admin/router'
|
||||
interface meta {
|
||||
title: string
|
||||
affix: boolean
|
||||
}
|
||||
interface tab {
|
||||
name: string
|
||||
fullPath: string
|
||||
path: string
|
||||
is_active:boolean,
|
||||
meta: meta
|
||||
}
|
||||
|
||||
const defaultTab: tab = {
|
||||
name: 'Dashboard',
|
||||
fullPath: '/dashboard',
|
||||
path: '/dashboard',
|
||||
is_active: true,
|
||||
meta: {
|
||||
title: 'Dashboard',
|
||||
affix: true,
|
||||
},
|
||||
}
|
||||
|
||||
export const useNavTabStore = defineStore('nav_tabs', {
|
||||
state: ()=> {
|
||||
return {
|
||||
tabs: [defaultTab] as Array<tab>,
|
||||
}
|
||||
},
|
||||
|
||||
getters: {
|
||||
getNavTabs(state): Array<tab> {
|
||||
return state.tabs
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
addTabs(Tab: tab): void {
|
||||
if (this.tabs.length >= 20) {
|
||||
console.log('最多添加 20 个 tab 标签');
|
||||
return;
|
||||
}
|
||||
|
||||
let isExist = false
|
||||
|
||||
this.tabs.map(t => {
|
||||
if (t.name === Tab.name) {
|
||||
isExist = true
|
||||
t.is_active = true
|
||||
} else {
|
||||
t.is_active = false
|
||||
}
|
||||
})
|
||||
|
||||
if (!isExist) {
|
||||
this.tabs.push(Tab)
|
||||
}
|
||||
},
|
||||
|
||||
getActiveTabIndex(): number|null {
|
||||
for (let i = 0; i < this.tabs.length; i++) {
|
||||
if (this.tabs[i].is_active) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
selectTab(tab: tab): void {
|
||||
this.tabs.map(t => {
|
||||
if (t.name === tab.name) {
|
||||
t.is_active = true
|
||||
} else {
|
||||
t.is_active = false
|
||||
}
|
||||
})
|
||||
|
||||
router.push(tab.fullPath)
|
||||
},
|
||||
|
||||
removeTab(index: number): void {
|
||||
const goPath = this.tabs[index - 1].fullPath
|
||||
this.tabs = this.tabs.filter((_, idx) => idx !== index);
|
||||
router.push(goPath)
|
||||
},
|
||||
|
||||
|
||||
// 右击菜单操作
|
||||
// 刷新
|
||||
refreshCurrentTab() {
|
||||
const index = this.getActiveTabIndex()
|
||||
if (index) {
|
||||
router.replace({ path: this.tabs[index].fullPath });
|
||||
|
||||
// router.push({ path: this.tabs[index].fullPath });
|
||||
}
|
||||
},
|
||||
// 关闭当前
|
||||
removeCurrentTab() {
|
||||
const index = this.getActiveTabIndex()
|
||||
if (index) {
|
||||
if (this.tabs[index].meta.affix) {
|
||||
return
|
||||
}
|
||||
this.removeTab(index)
|
||||
}
|
||||
},
|
||||
// 关闭所有
|
||||
removeAllTabs() {
|
||||
this.tabs = [defaultTab]
|
||||
router.push('/dashboard')
|
||||
},
|
||||
// 关闭其他
|
||||
removeOtherTabs() {
|
||||
const index = this.getActiveTabIndex()
|
||||
if (index) {
|
||||
this.tabs = this.tabs.filter((_, idx) => idx === index || idx === 0)
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
@@ -1,10 +1,10 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { User } from '/admin/types/user'
|
||||
import http from '/admin/support/http'
|
||||
import { rememberAuthToken, removeAuthToken } from '/admin/support/helper'
|
||||
import Message from '/admin/support/message'
|
||||
import router from '/admin/router'
|
||||
import { Permission } from '/admin/types/permission'
|
||||
import { User } from '/admin/types/User'
|
||||
import { Permission } from '/admin/types/Permission'
|
||||
|
||||
export const useUserStore = defineStore('UserStore', {
|
||||
state: (): User => {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { Permission } from '/admin/types/permission'
|
||||
import { Permission } from '/admin/types/Permission'
|
||||
import { MenuType } from '/admin/enum/app'
|
||||
import { Menu } from '/admin/types/Menu'
|
||||
import { constantRoutes } from '/admin/router'
|
||||
|
@@ -4,11 +4,14 @@ import App from '/admin/App.vue'
|
||||
import router, { bootstrapRouter } from '/admin/router'
|
||||
import ElementPlus from 'element-plus'
|
||||
import zh from 'element-plus/es/locale/lang/zh-cn'
|
||||
import en from 'element-plus/es/locale/lang/en'
|
||||
|
||||
import { bootstrapStore } from '/admin/stores'
|
||||
import Cache from './cache'
|
||||
import { bootstrapI18n } from '/admin/i18n'
|
||||
import guard from '/admin/router/guard'
|
||||
import { bootstrapDirectives } from '/admin/directives'
|
||||
import { Language } from 'element-plus/es/locale'
|
||||
|
||||
/**
|
||||
* catchadmin
|
||||
@@ -63,9 +66,13 @@ export default class CatchAdmin {
|
||||
* @returns
|
||||
*/
|
||||
protected useElementPlus(): CatchAdmin {
|
||||
// @ts-ignore
|
||||
const languages: Record<string, Language> = {
|
||||
zh, en
|
||||
}
|
||||
|
||||
const language = Cache.get('language') || 'zh'
|
||||
this.app.use(ElementPlus, {
|
||||
locale: Cache.get('language') === 'zh' && zh,
|
||||
locale: languages[language]
|
||||
})
|
||||
return this
|
||||
}
|
||||
|
@@ -1,216 +1,4 @@
|
||||
import { Code } from '/admin/enum/app'
|
||||
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
|
||||
import { getAuthToken, getBaseUrl, removeAuthToken } from './helper'
|
||||
import Message from './message'
|
||||
import router from '/admin/router'
|
||||
import ResponseData from '/admin/types/responseData'
|
||||
import Request from './request'
|
||||
|
||||
/**
|
||||
* http util
|
||||
*/
|
||||
class Http {
|
||||
/**
|
||||
* axios config
|
||||
* @protected
|
||||
*/
|
||||
protected config: AxiosRequestConfig = {}
|
||||
|
||||
/**
|
||||
* base url
|
||||
* @protected
|
||||
*/
|
||||
protected baseURL: string = ''
|
||||
|
||||
/**
|
||||
* http request timeout
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
protected timeout: number = 0
|
||||
|
||||
/**
|
||||
* http request headers
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
protected headers: { [k: string]: string } = {}
|
||||
|
||||
/**
|
||||
* axios instance
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
protected request: AxiosInstance
|
||||
|
||||
/**
|
||||
* instance
|
||||
*/
|
||||
constructor() {
|
||||
this.request = axios.create(this.getConfig())
|
||||
}
|
||||
|
||||
/**
|
||||
* get request
|
||||
*
|
||||
* @param path
|
||||
* @param params
|
||||
*/
|
||||
public get(path: string, params: object = {}) {
|
||||
return this.request.get(this.baseURL + path, {
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* post request
|
||||
*
|
||||
* @param path
|
||||
* @param data
|
||||
*/
|
||||
public post(path: string, data: object = {}) {
|
||||
return this.request.post(this.baseURL + path, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* put request
|
||||
*
|
||||
* @param path
|
||||
* @param data
|
||||
*/
|
||||
public put(path: string, data: object = {}) {
|
||||
return this.request.put(this.baseURL + path, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* delete request
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public delete(path: string) {
|
||||
return this.request.delete(this.baseURL + path)
|
||||
}
|
||||
|
||||
/**
|
||||
* set timeout
|
||||
*
|
||||
* @param timeout
|
||||
* @returns
|
||||
*/
|
||||
public setTimeout(timeout: number): Http {
|
||||
this.timeout = timeout
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* set baseurl
|
||||
*
|
||||
* @param url
|
||||
* @returns
|
||||
*/
|
||||
public setBaseUrl(url: string): Http {
|
||||
this.baseURL = url
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* set headers
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @returns
|
||||
*/
|
||||
public setHeader(key: string, value: string): Http {
|
||||
this.headers.key = value
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* get axios 配置
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
protected getConfig(): AxiosRequestConfig {
|
||||
// set base url
|
||||
this.config.baseURL = getBaseUrl()
|
||||
|
||||
// set timeout
|
||||
this.config.timeout = this.timeout ? this.timeout : 10000
|
||||
|
||||
// set ajax request
|
||||
this.headers['X-Requested-With'] = 'XMLHttpRequest'
|
||||
// set dashboard request
|
||||
this.headers['Request-from'] = 'Dashboard'
|
||||
this.config.headers = this.headers
|
||||
|
||||
return this.config
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加请求拦截器
|
||||
*
|
||||
*/
|
||||
public interceptorsOfRequest(): void {
|
||||
// @ts-ignore
|
||||
this.request.interceptors.request.use((config: AxiosRequestConfig) => {
|
||||
const token = getAuthToken()
|
||||
if (token) {
|
||||
if (!config.headers) {
|
||||
config.headers = {}
|
||||
}
|
||||
|
||||
config.headers.authorization = 'Bearer ' + token
|
||||
}
|
||||
|
||||
return config
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加响应拦截器
|
||||
*
|
||||
*/
|
||||
public interceptorsOfResponse(): void {
|
||||
this.request.interceptors.response.use(
|
||||
response => {
|
||||
const r: ResponseData = response.data
|
||||
const code = r.code
|
||||
const message = r.message
|
||||
if (code === 1e4) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (code === 10004) {
|
||||
Message.error(message || 'Error')
|
||||
} else if (code === Code.LOST_LOGIN || code === Code.LOGIN_EXPIRED) {
|
||||
// to re-login
|
||||
Message.confirm(message + ',需要重新登陆', function () {
|
||||
removeAuthToken()
|
||||
router.push('/login')
|
||||
})
|
||||
} else if (code === Code.LOGIN_BLACKLIST || code === Code.USER_FORBIDDEN) {
|
||||
Message.error(message || 'Error')
|
||||
removeAuthToken()
|
||||
// to login page
|
||||
router.push('/login')
|
||||
} else {
|
||||
Message.error(message || 'Error')
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(message || 'Error'))
|
||||
},
|
||||
error => {
|
||||
Message.error(error.message)
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const http = new Http()
|
||||
http.interceptorsOfRequest()
|
||||
|
||||
http.interceptorsOfResponse()
|
||||
const http = new Request()
|
||||
export default http
|
||||
|
235
resources/admin/support/request.ts
Normal file
235
resources/admin/support/request.ts
Normal file
@@ -0,0 +1,235 @@
|
||||
import { Code } from '/admin/enum/app'
|
||||
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
|
||||
import { getAuthToken, getBaseUrl, removeAuthToken } from './helper'
|
||||
import Message from './message'
|
||||
import router from '/admin/router'
|
||||
import ResponseData from '/admin/types/responseData'
|
||||
|
||||
type responseType = 'arraybuffer' | 'document' | 'json' | 'text' | 'stream' | 'blob'
|
||||
|
||||
/**
|
||||
* http util
|
||||
*/
|
||||
class Request {
|
||||
/**
|
||||
* axios config
|
||||
* @protected
|
||||
*/
|
||||
protected config: AxiosRequestConfig = {}
|
||||
|
||||
/**
|
||||
* base url
|
||||
* @protected
|
||||
*/
|
||||
protected baseURL: string = ''
|
||||
|
||||
/**
|
||||
* http request timeout
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
protected timeout: number = 0
|
||||
|
||||
/**
|
||||
* http request headers
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
protected headers: { [k: string]: string } = {}
|
||||
|
||||
/**
|
||||
* axios instance
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
// @ts-ignore
|
||||
protected request: AxiosInstance
|
||||
|
||||
/**
|
||||
* 响应结构
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
protected responseType: responseType = 'json'
|
||||
|
||||
public init() {
|
||||
this.request = axios.create(this.getConfig())
|
||||
this.interceptorsOfRequest()
|
||||
this.interceptorsOfResponse()
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* get request
|
||||
*
|
||||
* @param path
|
||||
* @param params
|
||||
*/
|
||||
public get(path: string, params: object = {}) {
|
||||
this.init()
|
||||
return this.request.get(this.baseURL + path, {
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* post request
|
||||
*
|
||||
* @param path
|
||||
* @param data
|
||||
*/
|
||||
public post(path: string, data: object = {}) {
|
||||
this.init()
|
||||
return this.request.post(this.baseURL + path, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* put request
|
||||
*
|
||||
* @param path
|
||||
* @param data
|
||||
*/
|
||||
public put(path: string, data: object = {}) {
|
||||
this.init()
|
||||
return this.request.put(this.baseURL + path, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* delete request
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public delete(path: string) {
|
||||
this.init()
|
||||
return this.request.delete(this.baseURL + path)
|
||||
}
|
||||
|
||||
/**
|
||||
* set timeout
|
||||
*
|
||||
* @param timeout
|
||||
* @returns
|
||||
*/
|
||||
public setTimeout(timeout: number): Request {
|
||||
this.timeout = timeout
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* set baseurl
|
||||
*
|
||||
* @param url
|
||||
* @returns
|
||||
*/
|
||||
public setBaseUrl(url: string): Request {
|
||||
this.baseURL = url
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* set headers
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @returns
|
||||
*/
|
||||
public setHeader(key: string, value: string): Request {
|
||||
this.headers.key = value
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* get axios 配置
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
protected getConfig(): AxiosRequestConfig {
|
||||
// set base url
|
||||
this.config.baseURL = getBaseUrl()
|
||||
//
|
||||
this.config.responseType = this.responseType
|
||||
// set timeout
|
||||
this.config.timeout = this.timeout ? this.timeout : 10000
|
||||
|
||||
// set ajax request
|
||||
this.headers['X-Requested-With'] = 'XMLHttpRequest'
|
||||
// set dashboard request
|
||||
this.headers['Request-from'] = 'Dashboard'
|
||||
this.config.headers = this.headers
|
||||
return this.config
|
||||
}
|
||||
|
||||
public setResponseType(type: responseType) {
|
||||
this.responseType = type
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加请求拦截器
|
||||
*
|
||||
*/
|
||||
public interceptorsOfRequest(): void {
|
||||
// @ts-ignore
|
||||
this.request.interceptors.request.use((config: AxiosRequestConfig) => {
|
||||
const token = getAuthToken()
|
||||
if (token) {
|
||||
if (!config.headers) {
|
||||
config.headers = {}
|
||||
}
|
||||
|
||||
config.headers.authorization = 'Bearer ' + token
|
||||
}
|
||||
|
||||
return config
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加响应拦截器
|
||||
*
|
||||
*/
|
||||
public interceptorsOfResponse(): void {
|
||||
this.request.interceptors.response.use(
|
||||
response => {
|
||||
// 如果是 blob response type, 直接返回 response
|
||||
if (response.request.responseType === 'blob') {
|
||||
return response
|
||||
}
|
||||
|
||||
const r: ResponseData = response.data
|
||||
const code = r.code
|
||||
const message = r.message
|
||||
if (code === 1e4) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (code === 10004) {
|
||||
Message.error(message || 'Error')
|
||||
} else if (code === Code.LOST_LOGIN || code === Code.LOGIN_EXPIRED) {
|
||||
// to re-login
|
||||
Message.confirm(message + ',需要重新登陆', function () {
|
||||
removeAuthToken()
|
||||
router.push('/login')
|
||||
})
|
||||
} else if (code === Code.LOGIN_BLACKLIST || code === Code.USER_FORBIDDEN) {
|
||||
Message.error(message || 'Error')
|
||||
removeAuthToken()
|
||||
// to login page
|
||||
router.push('/login')
|
||||
} else {
|
||||
Message.error(message || 'Error')
|
||||
}
|
||||
return Promise.reject(new Error(message || 'Error'))
|
||||
},
|
||||
error => {
|
||||
Message.error(error.message)
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
export default Request
|
@@ -1,6 +1,5 @@
|
||||
// login user type
|
||||
|
||||
import { Permission } from './permission'
|
||||
import { Permission } from './Permission'
|
||||
|
||||
export interface User {
|
||||
id: number
|
||||
|
BIN
wechat.png
Normal file
BIN
wechat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 91 KiB |
Reference in New Issue
Block a user