Compare commits
80 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
99a4c0fd6a | ||
![]() |
a2b55ab249 | ||
![]() |
4da569773a | ||
![]() |
162f99648f | ||
![]() |
8f157f03e1 | ||
![]() |
e115ca2a80 | ||
![]() |
5fe198a2b2 | ||
![]() |
dad0bf4444 | ||
![]() |
72c68507e5 | ||
![]() |
1d694a81c5 | ||
![]() |
51be5c648b | ||
![]() |
bc59731083 | ||
![]() |
eeb6fd4f41 | ||
![]() |
3c4ebb86e7 | ||
![]() |
dede7b0ba0 | ||
![]() |
d995a8ce0d | ||
![]() |
898ce1305d | ||
![]() |
7362bdd70f | ||
![]() |
4e104bfd47 | ||
![]() |
4700990507 | ||
![]() |
808dd7118d | ||
![]() |
0f2c2c644f | ||
![]() |
118fc1aaab | ||
![]() |
6de3edd4fc | ||
![]() |
de31bf23cd | ||
![]() |
817e8ea64d | ||
![]() |
8d97ff8867 | ||
![]() |
490c573e61 | ||
![]() |
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 |
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
|
41
README.md
41
README.md
@@ -2,13 +2,29 @@
|
|||||||
`CatchAdmin`是一款基于[Laravel](https://laravel.com)和[Element Plus](https://element-plus.org)二次开发而成后台管理系统。`Laravel` 社区也有许多非常优秀的后台管理系统,例如 `Nova`, 官方出品,当然是收费的,免费的有基于 `Livewire` 的 `Filament`,还有不得不说的 `Laravel Admin`。`CatchAdmin` 还是采用传统的前后端分离策略,`Laravel` 框架仅仅作为 `Api` 输出。将管理系统模块之间的耦合降到了最低限度。每个模块之间都有独立的控制器,路由,模型,数据表。在开发上尽可能将模块之间的影响降到最低,降低了开发上的难度。基于 `CatchAdmin `可以开发 `CMS`,`CRM`,`OA` 等 等系统。也封装了很多实用的工具,提升开发体验。
|
`CatchAdmin`是一款基于[Laravel](https://laravel.com)和[Element Plus](https://element-plus.org)二次开发而成后台管理系统。`Laravel` 社区也有许多非常优秀的后台管理系统,例如 `Nova`, 官方出品,当然是收费的,免费的有基于 `Livewire` 的 `Filament`,还有不得不说的 `Laravel Admin`。`CatchAdmin` 还是采用传统的前后端分离策略,`Laravel` 框架仅仅作为 `Api` 输出。将管理系统模块之间的耦合降到了最低限度。每个模块之间都有独立的控制器,路由,模型,数据表。在开发上尽可能将模块之间的影响降到最低,降低了开发上的难度。基于 `CatchAdmin `可以开发 `CMS`,`CRM`,`OA` 等 等系统。也封装了很多实用的工具,提升开发体验。
|
||||||
|
|
||||||
[中文](./README.md)|[英文](./README-en.md)
|
[中文](./README.md)|[英文](./README-en.md)
|
||||||
|
## 前后端完全分离版本
|
||||||
|
请使用 `server` 分支, 如果是新项目,请一定使用该完全分离分支。我们将在不久后会将项目分离出来
|
||||||
|
|
||||||
|
## 其他版本
|
||||||
|
- [tp8 新版本](https://gitee.com/catchamin/catchadmin-tp)
|
||||||
|
- [webman 高性能版本](https://gitee.com/catchamin/catchadmin-webman)
|
||||||
|
|
||||||
|
## 新功能
|
||||||
|
- [动态表单](https://catchadmin.com/docs/3.0/front/catch-form)
|
||||||
|
- [动态表格](https://catchadmin.com/docs/3.0/front/catch-table)
|
||||||
|
|
||||||
|
## 专业版
|
||||||
|
[专业版本官方地址](https://license.catchadmin.com)
|
||||||
|
|
||||||
|
首先感谢一直以来对 `CatchAdmin` 开源项目的支持和使用。作为一名开源工作者,我一直致力于开发出功能强大且易于使用的后台管理系统,以帮助您简化业务流程和提升工作效率。然而,由于某些原因,我不得不做出一些调整。为了能够继续开发和维护这个项目,我将推出一款付费的后台管理系统,以确保我能够持续为您提供高质量的服务和支持。
|
||||||
|
|
||||||
|
专业版本不会在开源版本做一些破坏性变更,所以当您从开源版本切换到专业版本,不会有任何开发心智负担。但是使用专业版本会有新的组件来配合您的工作。
|
||||||
|
|
||||||
|
我深信,付费后台管理系统将为您带来更多的价值和便利,帮助您提升工作效率
|
||||||
|
|
||||||
## ⚠️Thinkphp 用户注意
|
## ⚠️Thinkphp 用户注意
|
||||||
由于新版本使用 `Laravel` 开发,所以请使用 `thinkphp` 分支或者 tag2.6.2,thinkphp 版本已经非常稳定了。
|
由于新版本使用 `Laravel` 开发,所以请使用 `thinkphp` 分支或者 tag2.6.2,thinkphp 版本已经非常稳定了。
|
||||||
|
|
||||||
## 为什么是 Laravel
|
|
||||||
`V2` 版本使用`Thinkphp`,但从其社区来看,从我个人角度来看开发组的心思已经不在维护框架上,因为据观察,每一次小版本发布都会引发一些小问题,虽然不大,但给人一种不够稳定的感觉,所以思索再三,使用 `Laravel`。`Laravel` 社区非常繁荣,他们每周都会发布新版本,以及围绕`Laravel`构建的生态也非常完善,有 `Horizon` 队列管理工具, `Telescope` 调试工具,`Octane`(基于 `Swoole` 和 `RoadRunner` 提高性能)等等一系列的工具,而且都是免费的。
|
|
||||||
|
|
||||||
## 功能
|
## 功能
|
||||||
- [x] 用户管理 后台用户管理
|
- [x] 用户管理 后台用户管理
|
||||||
- [x] 部门管理 配置公司的部门结构,支持树形结构
|
- [x] 部门管理 配置公司的部门结构,支持树形结构
|
||||||
@@ -21,6 +37,14 @@
|
|||||||
- [x] Schema 管理 生成表结构
|
- [x] Schema 管理 生成表结构
|
||||||
- [x] 模块管理 系统模块管理
|
- [x] 模块管理 系统模块管理
|
||||||
|
|
||||||
|
|
||||||
|
## 讨论
|
||||||
|
- 可以提 `ISSUE`,请按照 `issue` 模板提问
|
||||||
|
- 加入 Q 群 `302266230` 暗号 `catchadmin`。
|
||||||
|
- 加微信入群,新建🆕
|
||||||
|
|
||||||
|
<img src="wechat.png" width="300"/>
|
||||||
|
|
||||||
## 额外模块
|
## 额外模块
|
||||||
- [CMS 模块](https://github.com/catch-admin/cms)
|
- [CMS 模块](https://github.com/catch-admin/cms)
|
||||||
|
|
||||||
@@ -45,11 +69,6 @@
|
|||||||
- [catchadmin 开发之模块创建](https://www.bilibili.com/video/BV1jP41127aW/)
|
- [catchadmin 开发之模块创建](https://www.bilibili.com/video/BV1jP41127aW/)
|
||||||
- [catchadmin 之快速开发](https://www.bilibili.com/video/BV1Qh4y1J7eB/)
|
- [catchadmin 之快速开发](https://www.bilibili.com/video/BV1Qh4y1J7eB/)
|
||||||
|
|
||||||
## 赞助
|
|
||||||
如果项目对你有帮助,或者在工作上帮你节省了开发时间。在力所能及的情况下,可以支持下`Catchadmin`项目, 非常感谢🙏
|
|
||||||
|
|
||||||
<img src="https://i.imgtg.com/2023/02/16/dAV0a.jpg" width = "200" alt="support"/>
|
|
||||||
|
|
||||||
## 规范
|
## 规范
|
||||||
### PHP
|
### PHP
|
||||||
使用 fixer 进行代码检查, 具体请查看根目录下 `.php-cs-fixer.dist.php` 文件的规范,还需要进行以下两步骤
|
使用 fixer 进行代码检查, 具体请查看根目录下 `.php-cs-fixer.dist.php` 文件的规范,还需要进行以下两步骤
|
||||||
@@ -68,12 +87,6 @@ composer cs
|
|||||||
composer cs-diff
|
composer cs-diff
|
||||||
```
|
```
|
||||||
|
|
||||||
## 讨论
|
|
||||||
- [论坛讨论](https://bbs.catchadmin.com)
|
|
||||||
- 可以提 `ISSUE`,请按照 `issue` 模板提问
|
|
||||||
- 加入 Q 群 `302266230` 暗号 `catchadmin`。
|
|
||||||
|
|
||||||
|
|
||||||
## 感谢🙏
|
## 感谢🙏
|
||||||
> 排名不分先后
|
> 排名不分先后
|
||||||
|
|
||||||
|
@@ -11,19 +11,18 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.2",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
"doctrine/dbal": "^3.4",
|
"guzzlehttp/guzzle": "^7.8.1",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"laravel/framework": "^11.0",
|
||||||
"laravel/framework": "^10.0",
|
"laravel/tinker": "^v2.9.0",
|
||||||
"laravel/tinker": "^2.8",
|
"catchadmin/core": "^0.3.4"
|
||||||
"catchadmin/core": "^0.1.12"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^v1.23.1",
|
||||||
"mockery/mockery": "^1.4.4",
|
"mockery/mockery": "^1.6.9",
|
||||||
"pestphp/pest": "^1.22"
|
"pestphp/pest": "^v2.34.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -42,7 +41,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"post-autoload-dump": [
|
"post-autoload-dump": [
|
||||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||||
"@php artisan package:discover --ansi"
|
"@php artisan package:discover --ansi",
|
||||||
|
"@composer dump-autoload --no-scripts"
|
||||||
],
|
],
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||||
|
@@ -185,7 +185,6 @@ return [
|
|||||||
/*
|
/*
|
||||||
* Package Service Providers...
|
* Package Service Providers...
|
||||||
*/
|
*/
|
||||||
\Catch\Providers\CatchAdminServiceProvider::class,
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Application Service Providers...
|
* Application Service Providers...
|
||||||
|
Submodule modules/Cms deleted from 36e9e66e38
@@ -20,6 +20,7 @@ class Components implements OptionInterface
|
|||||||
|
|
||||||
public function get(): array
|
public function get(): array
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
if ($module = request()->get('module')) {
|
if ($module = request()->get('module')) {
|
||||||
$components = File::glob(CatchAdmin::getModuleViewsPath($module) . '*' . DIRECTORY_SEPARATOR . '*.vue');
|
$components = File::glob(CatchAdmin::getModuleViewsPath($module) . '*' . DIRECTORY_SEPARATOR . '*.vue');
|
||||||
|
|
||||||
@@ -38,5 +39,8 @@ class Components implements OptionInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->components;
|
return $this->components;
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ use Catch\Base\CatchModel;
|
|||||||
use Catch\Enums\Status;
|
use Catch\Enums\Status;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Modules\Develop\Support\Generate\Create\Schema;
|
use Modules\Develop\Support\Generate\Create\Schema;
|
||||||
use Illuminate\Support\Facades\Schema as SchemaFacade;
|
use Illuminate\Support\Facades\Schema as SchemaFacade;
|
||||||
|
|
||||||
@@ -91,16 +90,13 @@ class Schemas extends CatchModel
|
|||||||
{
|
{
|
||||||
$schema = parent::firstBy($id);
|
$schema = parent::firstBy($id);
|
||||||
|
|
||||||
$columns = [];
|
foreach (SchemaFacade::getColumns($schema->name) as $column) {
|
||||||
|
|
||||||
foreach (getTableColumns($schema->name) as $columnString) {
|
|
||||||
$column = DB::connection()->getDoctrineColumn(DB::connection()->getTablePrefix().$schema->name, $columnString);
|
|
||||||
$columns[] = [
|
$columns[] = [
|
||||||
'name' => $column->getName(),
|
'name' => $column['name'],
|
||||||
'type' => $column->getType()->getName(),
|
'type' => $column['type_name'],
|
||||||
'nullable' => ! $column->getNotnull(),
|
'nullable' => $column['nullable'],
|
||||||
'default' => $column->getDefault(),
|
'default' => $column['default'],
|
||||||
'comment' => $column->getComment()
|
'comment' => $column['comment'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,22 +104,4 @@ class Schemas extends CatchModel
|
|||||||
|
|
||||||
return $schema;
|
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
|
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,6 +13,8 @@ return new class extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
if (Schema::hasTable('{table}')) { return; }
|
||||||
|
|
||||||
Schema::{method}('{table}', function (Blueprint $table) {
|
Schema::{method}('{table}', function (Blueprint $table) {
|
||||||
{content}
|
{content}
|
||||||
});
|
});
|
||||||
|
@@ -21,7 +21,7 @@ class {request} extends Request
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function message(): array
|
public function messages(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@@ -13,14 +13,14 @@ import { useShow } from '/admin/composables/curd/useShow'
|
|||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
primary: String | Number,
|
primary: [String, Number],
|
||||||
api: String,
|
api: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)
|
const { formData, form, loading, submitForm, close } = useCreate(props.api as string, props.primary)
|
||||||
|
|
||||||
if (props.primary) {
|
if (props.primary) {
|
||||||
useShow(props.api, props.primary, formData)
|
useShow(props.api as string, props.primary, formData)
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits(['close'])
|
const emit = defineEmits(['close'])
|
||||||
|
287
modules/Develop/views/dymaic/create.vue
Normal file
287
modules/Develop/views/dymaic/create.vue
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<CatchForm :schema="form" @onSubmit="submit"/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
const form = {
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
name: 'Grid_FhAuLh',
|
||||||
|
props: {
|
||||||
|
columns: 2
|
||||||
|
},
|
||||||
|
component: 'grid',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: 'Grid_qRvhpR',
|
||||||
|
props: {
|
||||||
|
columns: 1
|
||||||
|
},
|
||||||
|
component: 'grid',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
value: 1,
|
||||||
|
label: '目录'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 2,
|
||||||
|
label: '菜单'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 3,
|
||||||
|
label: '按钮'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
optionType: 'button'
|
||||||
|
},
|
||||||
|
label: '菜单类型',
|
||||||
|
component: 'radio',
|
||||||
|
class: 'mt-4',
|
||||||
|
initialValue: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'permission_name',
|
||||||
|
props: {
|
||||||
|
clearable: true
|
||||||
|
},
|
||||||
|
label: '菜单名称',
|
||||||
|
component: 'input',
|
||||||
|
class: 'mt-4',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'module',
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '权限管理',
|
||||||
|
value: 'permissions'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '动态表单',
|
||||||
|
value: 'test'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Testss',
|
||||||
|
value: 'tests'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
label: '所属模块',
|
||||||
|
component: 'select',
|
||||||
|
class: 'mt-4',
|
||||||
|
required: true,
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'route',
|
||||||
|
props: {
|
||||||
|
clearable: true
|
||||||
|
},
|
||||||
|
label: '路由Path',
|
||||||
|
component: 'input',
|
||||||
|
class: 'mt-4',
|
||||||
|
required: true,
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'redirect',
|
||||||
|
props: {
|
||||||
|
clearable: true
|
||||||
|
},
|
||||||
|
label: '重定向',
|
||||||
|
component: 'input',
|
||||||
|
class: 'mt-4',
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'sort',
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
min: 1,
|
||||||
|
max: 10000
|
||||||
|
},
|
||||||
|
label: '排序',
|
||||||
|
component: 'input_number',
|
||||||
|
class: 'mt-4',
|
||||||
|
initialValue: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Grid',
|
||||||
|
props: {
|
||||||
|
columns: 1
|
||||||
|
},
|
||||||
|
component: 'grid',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: 'parent_id',
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
parent_id: 0,
|
||||||
|
permission_name: '权限管理',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
parent_id: 1,
|
||||||
|
permission_name: '角色管理'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 8,
|
||||||
|
parent_id: 1,
|
||||||
|
permission_name: '菜单管理'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 15,
|
||||||
|
parent_id: 1,
|
||||||
|
permission_name: '岗位管理'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 22,
|
||||||
|
parent_id: 1,
|
||||||
|
permission_name: '部门管理'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 29,
|
||||||
|
parent_id: 1,
|
||||||
|
permission_name: '创建菜单'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 30,
|
||||||
|
parent_id: 0,
|
||||||
|
permission_name: '测试',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: 31,
|
||||||
|
parent_id: 30,
|
||||||
|
permission_name: '测试看看'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 37,
|
||||||
|
parent_id: 30,
|
||||||
|
permission_name: '创建'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
label: 'permission_name',
|
||||||
|
valueKey: 'id',
|
||||||
|
value: 'id',
|
||||||
|
'show-all-levels': false,
|
||||||
|
checkStrictly: true,
|
||||||
|
class: 'w-full'
|
||||||
|
},
|
||||||
|
label: '上级菜单',
|
||||||
|
component: 'cascader',
|
||||||
|
class: 'mt-4'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'permission_mark',
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
api: 'options/controllers',
|
||||||
|
query: {
|
||||||
|
module: '{{ $values.module }}'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
label: '权限标识',
|
||||||
|
component: '{{$values.type == 3 ? "input" : "select"}}',
|
||||||
|
class: 'mt-4',
|
||||||
|
hidden: '{{$values.type == 1}}',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'icon',
|
||||||
|
props: {
|
||||||
|
clearable: true
|
||||||
|
},
|
||||||
|
label: '图标',
|
||||||
|
component: 'icon_select',
|
||||||
|
class: 'mt-4',
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'component',
|
||||||
|
props: {
|
||||||
|
clearable: true,
|
||||||
|
"allow-create": true
|
||||||
|
},
|
||||||
|
label: '所属组件',
|
||||||
|
component: 'select',
|
||||||
|
class: 'mt-4',
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'hidden',
|
||||||
|
props: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
value: 1,
|
||||||
|
label: '是'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 2,
|
||||||
|
label: '否'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
label: '是否隐藏',
|
||||||
|
component: 'radio',
|
||||||
|
class: 'mt-4',
|
||||||
|
initialValue: 2,
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'keepalive',
|
||||||
|
props: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
value: 1,
|
||||||
|
label: '是'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 2,
|
||||||
|
label: '否'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
label: '是否缓存',
|
||||||
|
component: 'radio',
|
||||||
|
class: 'mt-4',
|
||||||
|
initialValue: 2,
|
||||||
|
hidden: '{{$values.type == 3}}'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
// @ts-nocheck
|
||||||
|
/**import { useCreate } from '@/form/composables/useCreate'
|
||||||
|
const props = defineProps({
|
||||||
|
primary: [String, Number],
|
||||||
|
api: String,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const { form } = useCreate(props.api, props.primary)
|
||||||
|
*/
|
||||||
|
const submit = (formData) => {
|
||||||
|
console.log(formData)
|
||||||
|
}
|
||||||
|
</script>
|
53
modules/Develop/views/dymaic/index.vue
Normal file
53
modules/Develop/views/dymaic/index.vue
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<catch-table
|
||||||
|
:columns="columns"
|
||||||
|
:api="api"
|
||||||
|
:search-form="search"
|
||||||
|
row-key="id"
|
||||||
|
:pagination="false"
|
||||||
|
>
|
||||||
|
<template #dialog="row">
|
||||||
|
<Create :primary="row?.id" :api="api"/>
|
||||||
|
</template>
|
||||||
|
</catch-table>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
// @ts-nocheck
|
||||||
|
import Create from './create.vue'
|
||||||
|
|
||||||
|
const api = 'permissions/roles'
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
label: '角色名称',
|
||||||
|
prop: 'role_name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '角色标识',
|
||||||
|
prop: 'description'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '角色描述',
|
||||||
|
prop: 'role_name'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '创建时间',
|
||||||
|
prop: 'created_at'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'operate',
|
||||||
|
label: '操作',
|
||||||
|
width: 200
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const search = [
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
label: '角色名称',
|
||||||
|
name: 'role_name'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
@@ -1,13 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<el-table :data="structures">
|
<el-table :data="structures">
|
||||||
<el-table-column prop="field" :label="$t('generate.schema.structure.field_name.name')" width="100px" />
|
<el-table-column prop="field" :label="$t('generate.schema.structure.field_name.name')" />
|
||||||
<el-table-column prop="label" :label="$t('generate.schema.structure.form_label')" width="150px">
|
<el-table-column prop="label" :label="$t('generate.schema.structure.form_label')">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-input v-model="scope.row.label" />
|
<el-input v-model="scope.row.label" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="label" :label="$t('generate.schema.structure.form_component')" width="110px">
|
<el-table-column prop="label" :label="$t('generate.schema.structure.form_component')" >
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-select v-model="scope.row.form_component" class="w-full" filterable>
|
<el-select v-model="scope.row.form_component" class="w-full" filterable>
|
||||||
<el-option v-for="component in formComponents" :key="component" :label="component" :value="component" />
|
<el-option v-for="component in formComponents" :key="component" :label="component" :value="component" />
|
||||||
@@ -29,14 +29,14 @@
|
|||||||
<el-switch v-model="scope.row.search" inline-prompt :active-text="$t('system.yes')" :inactive-text="$t('system.no')" width="45px" />
|
<el-switch v-model="scope.row.search" inline-prompt :active-text="$t('system.yes')" :inactive-text="$t('system.no')" width="45px" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="search_op" :label="$t('generate.schema.structure.search_op.name')" width="150px">
|
<el-table-column prop="search_op" :label="$t('generate.schema.structure.search_op.name')" >
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-select v-model="scope.row.search_op" :placeholder="$t('generate.schema.structure.search_op.placeholder')" class="w-full">
|
<el-select v-model="scope.row.search_op" :placeholder="$t('generate.schema.structure.search_op.placeholder')" class="w-full">
|
||||||
<el-option v-for="op in operates" :key="op" :label="op" :value="op" />
|
<el-option v-for="op in operates" :key="op" :label="op" :value="op" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="validates" :label="$t('generate.schema.structure.rules.name')" width="250px">
|
<el-table-column prop="validates" :label="$t('generate.schema.structure.rules.name')">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-select v-model="scope.row.validates" :placeholder="$t('generate.schema.structure.rules.placeholder')" multiple filterable allow-create clearable class="w-full">
|
<el-select v-model="scope.row.validates" :placeholder="$t('generate.schema.structure.rules.placeholder')" multiple filterable allow-create clearable class="w-full">
|
||||||
<el-option v-for="validate in validates" :key="validate" :label="validate" :value="validate" />
|
<el-option v-for="validate in validates" :key="validate" :label="validate" :value="validate" />
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<!--<el-table-column prop="comment" label="注释" />-->
|
<!--<el-table-column prop="comment" label="注释" />-->
|
||||||
<el-table-column prop="id" :label="$t('generate.schema.structure.operate')" width="120px">
|
<el-table-column prop="id" :label="$t('generate.schema.structure.operate')">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button type="danger" :icon="Delete" @click="deleteField(scope.row.field)" size="small" />
|
<el-button type="danger" :icon="Delete" @click="deleteField(scope.row.field)" size="small" />
|
||||||
</template>
|
</template>
|
||||||
@@ -60,6 +60,20 @@ import { Delete } from '@element-plus/icons-vue'
|
|||||||
const generateStore = useGenerateStore()
|
const generateStore = useGenerateStore()
|
||||||
|
|
||||||
const structures = computed(() => {
|
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
|
return generateStore.getStructures
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
<!-- 安装 -->
|
<!-- 安装 -->
|
||||||
<Dialog v-model="installVisible" title="安装模块" destroy-on-close>
|
<Dialog v-model="installVisible" title="安装模块" destroy-on-close>
|
||||||
<Install />
|
<Install @close="closeInstall" />
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -62,6 +62,9 @@ const { open, close, title, visible, id } = useOpen()
|
|||||||
|
|
||||||
const tableData = computed(() => data.value?.data)
|
const tableData = computed(() => data.value?.data)
|
||||||
const installVisible = ref<boolean>(false)
|
const installVisible = ref<boolean>(false)
|
||||||
|
const closeInstall = () => {
|
||||||
|
installVisible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
search()
|
search()
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
{ label: 'ZIP 安装', value: 2 },
|
{ label: 'ZIP 安装', value: 2 },
|
||||||
]"
|
]"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.value"
|
:value="item.value"
|
||||||
name="type"
|
name="type"
|
||||||
>{{ item.label }}
|
>{{ item.label }}
|
||||||
</el-radio-button>
|
</el-radio-button>
|
||||||
@@ -22,9 +22,21 @@
|
|||||||
required: true,
|
required: true,
|
||||||
message: '模块名称必须填写',
|
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>
|
||||||
<el-form-item label="上传 ZIP" prop="file" v-if="formData.type === 2">
|
<el-form-item label="上传 ZIP" prop="file" v-if="formData.type === 2">
|
||||||
<Upload action="module/upload" :limit="1" accept=".zip" :on-success="moduleUpload">
|
<Upload action="module/upload" :limit="1" accept=".zip" :on-success="moduleUpload">
|
||||||
@@ -63,4 +75,19 @@ const moduleUpload = (response, uploadFile) => {
|
|||||||
Message.error(response.message)
|
Message.error(response.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const modules = [
|
||||||
|
{
|
||||||
|
label: '权限管理',
|
||||||
|
value: 'permissions',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '内容管理',
|
||||||
|
value: 'cms',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '系统管理',
|
||||||
|
value: 'system',
|
||||||
|
},
|
||||||
|
]
|
||||||
</script>
|
</script>
|
||||||
|
@@ -25,6 +25,12 @@ const router: RouteRecordRaw[] = [
|
|||||||
meta: { title: '代码生成', hidden: true, active_menu: '/develop/schemas' },
|
meta: { title: '代码生成', hidden: true, active_menu: '/develop/schemas' },
|
||||||
component: () => import('./generate/index.vue'),
|
component: () => import('./generate/index.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'dymaic',
|
||||||
|
name: 'dymaic',
|
||||||
|
meta: { title: '动态表格' },
|
||||||
|
component: () => import('./dymaic/index.vue'),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@@ -64,7 +64,7 @@ const schemaVisible = ref<boolean>(false)
|
|||||||
const api = 'schema'
|
const api = 'schema'
|
||||||
|
|
||||||
const { data, query, search, reset, loading } = useGetList(api)
|
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 { open, close, title, visible, id } = useOpen()
|
||||||
|
|
||||||
const tableData = computed(() => data.value?.data)
|
const tableData = computed(() => data.value?.data)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<el-table :data="structures" class="draggable">
|
<VueDraggable v-model="structures" target=".el-table__body tbody" animation="150" @end="onEnd">
|
||||||
|
<el-table :data="structures" class="draggable" :lazy="false">
|
||||||
<el-table-column prop="field" :label="$t('generate.schema.structure.field_name.name')" />
|
<el-table-column prop="field" :label="$t('generate.schema.structure.field_name.name')" />
|
||||||
<el-table-column prop="type" :label="$t('generate.schema.structure.type.name')">
|
<el-table-column prop="type" :label="$t('generate.schema.structure.type.name')">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
</VueDraggable>
|
||||||
|
|
||||||
<div class="flex justify-end mt-4">
|
<div class="flex justify-end mt-4">
|
||||||
<el-button type="success" :icon="Plus" @click="addField">{{ $t('system.add') }}</el-button>
|
<el-button type="success" :icon="Plus" @click="addField">{{ $t('system.add') }}</el-button>
|
||||||
@@ -88,22 +90,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, onMounted, Ref, ref } from 'vue'
|
import { Ref, ref } from 'vue'
|
||||||
import { useSchemaStore, Structure } from '../store'
|
import { useSchemaStore, Structure } from '../store'
|
||||||
import { Delete, Plus, Edit } from '@element-plus/icons-vue'
|
import { Delete, Plus, Edit } from '@element-plus/icons-vue'
|
||||||
import type { FormInstance } from 'element-plus'
|
import type { FormInstance } from 'element-plus'
|
||||||
import Message from '/admin/support/message'
|
import Message from '/admin/support/message'
|
||||||
import http from '/admin/support/http'
|
import http from '/admin/support/http'
|
||||||
import { Code } from '/admin/enum/app'
|
import { Code } from '/admin/enum/app'
|
||||||
import Sortable from 'sortablejs'
|
import { VueDraggable } from 'vue-draggable-plus'
|
||||||
|
|
||||||
const schemaStore = useSchemaStore()
|
const schemaStore = useSchemaStore()
|
||||||
const emits = defineEmits(['prev', 'next'])
|
const emits = defineEmits(['prev', 'next'])
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
|
|
||||||
const structures = computed(() => {
|
// 初始化
|
||||||
return schemaStore.getStructures
|
const structures = ref(schemaStore.getStructures)
|
||||||
})
|
|
||||||
|
|
||||||
const structure: Ref<Structure> = ref(schemaStore.initStructure())
|
const structure: Ref<Structure> = ref(schemaStore.initStructure())
|
||||||
// structure
|
// structure
|
||||||
@@ -118,29 +119,10 @@ const updateField = (id: number) => {
|
|||||||
structure.value = s
|
structure.value = s
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
schemaStore.setStructures(structures.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 form = ref<FormInstance>()
|
||||||
const submitStructure = (formEl: FormInstance | undefined) => {
|
const submitStructure = (formEl: FormInstance | undefined) => {
|
||||||
if (!formEl) return
|
if (!formEl) return
|
||||||
@@ -156,7 +138,10 @@ const submitStructure = (formEl: FormInstance | undefined) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteField = (id: number) => {
|
const deleteField = (id: number) => {
|
||||||
schemaStore.filterStructures(id)
|
structures.value = structures.value.filter((s: Structure) => {
|
||||||
|
return !(s.id === id)
|
||||||
|
})
|
||||||
|
schemaStore.setStructures(structures.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
const next = () => {
|
const next = () => {
|
||||||
@@ -171,7 +156,10 @@ const next = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 调整数据结构
|
||||||
|
const onEnd = () => {
|
||||||
|
schemaStore.setStructures(structures.value)
|
||||||
|
}
|
||||||
const types: string[] = [
|
const types: string[] = [
|
||||||
'id',
|
'id',
|
||||||
'smallIncrements',
|
'smallIncrements',
|
||||||
@@ -223,7 +211,6 @@ const types: string[] = [
|
|||||||
'tinyIncrements',
|
'tinyIncrements',
|
||||||
'tinyInteger',
|
'tinyInteger',
|
||||||
'tinyText',
|
'tinyText',
|
||||||
'unsignedDecimal',
|
|
||||||
'uuid',
|
'uuid',
|
||||||
'year',
|
'year',
|
||||||
]
|
]
|
||||||
|
@@ -28,11 +28,13 @@ class PermissionsController extends Controller
|
|||||||
public function index(Request $request): mixed
|
public function index(Request $request): mixed
|
||||||
{
|
{
|
||||||
if ($request->get('from') == 'role') {
|
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) {
|
return $this->model->setBeforeGetList(function ($query) {
|
||||||
return $query->with('actions')->whereIn('type', [MenuType::Top->value(), MenuType::Menu->value()]);
|
return $query->with('actions')->whereIn('type', [MenuType::Top->value(), MenuType::Menu->value()])->orderByDesc('sort');
|
||||||
})->getList();
|
})->getList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@ namespace Modules\Permissions\Http\Controllers;
|
|||||||
|
|
||||||
use Catch\Base\CatchController as Controller;
|
use Catch\Base\CatchController as Controller;
|
||||||
use Catch\Exceptions\FailedException;
|
use Catch\Exceptions\FailedException;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Modules\Permissions\Enums\DataRange;
|
use Modules\Permissions\Enums\DataRange;
|
||||||
use Modules\Permissions\Models\Roles;
|
use Modules\Permissions\Models\Roles;
|
||||||
@@ -41,11 +42,13 @@ class RolesController extends Controller
|
|||||||
public function store(RoleRequest $request)
|
public function store(RoleRequest $request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
if (!isset($data['data_range'])) {
|
||||||
if ($request->get('data_range') && ! DataRange::Personal_Choose->assert($data['data_range'])) {
|
|
||||||
$data['departments'] = [];
|
|
||||||
} else {
|
|
||||||
$data['data_range'] = 0;
|
$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($data);
|
return $this->model->storeBy($data);
|
||||||
@@ -54,7 +57,8 @@ class RolesController extends Controller
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return \Illuminate\Database\Eloquent\Model|null
|
* @param Request $request
|
||||||
|
* @return Model|null
|
||||||
*/
|
*/
|
||||||
public function show($id, Request $request)
|
public function show($id, Request $request)
|
||||||
{
|
{
|
||||||
@@ -80,11 +84,9 @@ class RolesController extends Controller
|
|||||||
public function update($id, RoleRequest $request)
|
public function update($id, RoleRequest $request)
|
||||||
{
|
{
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
$data['data_range'] = (int) $data['data_range'];
|
||||||
if ($request->get('data_range') && ! DataRange::Personal_Choose->assert($data['data_range'])) {
|
if (!DataRange::Personal_Choose->assert($data['data_range'])) {
|
||||||
$data['departments'] = [];
|
$data['departments'] = [];
|
||||||
} else {
|
|
||||||
$data['data_range'] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->model->updateBy($id, $data);
|
return $this->model->updateBy($id, $data);
|
||||||
|
@@ -200,7 +200,9 @@ class Permissions extends Model
|
|||||||
$data['route'] = '/'.trim($data['route'], '/');
|
$data['route'] = '/'.trim($data['route'], '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($data['component'])) {
|
||||||
$data['component'] = Str::of($data['component'])->replace('\\', '/')->toString();
|
$data['component'] = Str::of($data['component'])->replace('\\', '/')->toString();
|
||||||
|
}
|
||||||
return parent::storeBy($data);
|
return parent::storeBy($data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -246,7 +248,9 @@ class Permissions extends Model
|
|||||||
$data['permission_mark'] = $parentMenu->permission_mark.'@'.$data['permission_mark'];
|
$data['permission_mark'] = $parentMenu->permission_mark.'@'.$data['permission_mark'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($data['component'])) {
|
||||||
$data['component'] = Str::of($data['component'])->replace('\\', '/')->toString();
|
$data['component'] = Str::of($data['component'])->replace('\\', '/')->toString();
|
||||||
|
}
|
||||||
return parent::updateBy($id, $data);
|
return parent::updateBy($id, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="状态" prop="status">
|
<el-form-item label="状态" prop="status">
|
||||||
<el-radio-group v-model="formData.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-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="排序" prop="sort">
|
<el-form-item label="排序" prop="sort">
|
||||||
@@ -30,7 +30,7 @@ import { useShow } from '/admin/composables/curd/useShow'
|
|||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
primary: String | Number,
|
primary: [Number, String],
|
||||||
api: String,
|
api: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
{ label: '按钮', value: 3 },
|
{ label: '按钮', value: 3 },
|
||||||
]"
|
]"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.value"
|
:value="item.value"
|
||||||
name="type"
|
name="type"
|
||||||
>{{ item.label }}
|
>{{ item.label }}
|
||||||
</el-radio-button>
|
</el-radio-button>
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
{ label: '隐藏', value: 2 },
|
{ label: '隐藏', value: 2 },
|
||||||
]"
|
]"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.value"
|
:value="item.value"
|
||||||
name="hidden"
|
name="hidden"
|
||||||
>{{ item.label }}</el-radio
|
>{{ item.label }}</el-radio
|
||||||
>
|
>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
{ label: '禁用', value: 2 },
|
{ label: '禁用', value: 2 },
|
||||||
]"
|
]"
|
||||||
:key="item.value"
|
:key="item.value"
|
||||||
:label="item.value"
|
:value="item.value"
|
||||||
name="keepalive"
|
name="keepalive"
|
||||||
>{{ item.label }}
|
>{{ item.label }}
|
||||||
</el-radio>
|
</el-radio>
|
||||||
@@ -110,7 +110,7 @@ import http from '/admin/support/http'
|
|||||||
import { MenuType } from '/admin/enum/app'
|
import { MenuType } from '/admin/enum/app'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
primary: String | Number,
|
primary: [String,Number],
|
||||||
api: String,
|
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>
|
<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>
|
||||||
<div v-else>
|
<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>
|
<template #reference>
|
||||||
<el-tag class="cursor-pointer w-8" v-if="scope.row.type === MenuType.PAGE_TYPE">
|
<el-tag class="cursor-pointer w-8">
|
||||||
<Icon name="cog-6-tooth" class="animate-spin w-5 h-5" v-if="actionLoading" />
|
<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 />
|
<Icon name="plus" className="w-4 h-4" v-else />
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
@@ -73,11 +73,18 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const actionLoading = ref<boolean>(false)
|
const actionLoading = ref<boolean>(false)
|
||||||
|
const generateId = ref<number>(0)
|
||||||
const actionGenerate = async (id: number) => {
|
const actionGenerate = async (id: number) => {
|
||||||
actionLoading.value = true
|
generateId.value = id
|
||||||
http.post(api, { parent_id: id, actions: true }).then(r => {
|
http
|
||||||
|
.post(api, { parent_id: id, actions: true })
|
||||||
|
.then(r => {
|
||||||
search()
|
search()
|
||||||
actionLoading.value = false
|
generateId.value = 0
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
generateId.value = 0
|
||||||
|
catchtable.value.reset()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@@ -220,4 +220,10 @@ const getParent = (parentId: any) => {
|
|||||||
:deep(.el-tree .el-tree__empty-block .el-tree__empty-text) {
|
:deep(.el-tree .el-tree__empty-block .el-tree__empty-text) {
|
||||||
@apply left-10 top-4;
|
@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>
|
</style>
|
||||||
|
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.
|
1
modules/System/README.md
Normal file
1
modules/System/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 系统模块
|
@@ -22,12 +22,18 @@ class AuthController extends Controller
|
|||||||
/* @var User $user */
|
/* @var User $user */
|
||||||
$user = User::query()->where('email', $request->get('email'))->first();
|
$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;
|
$token = $user->createToken('token')->plainTextToken;
|
||||||
return compact('token');
|
return compact('token');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw new FailedException('登录失败!请检查邮箱或者密码');
|
throw new FailedException('登录失败!请检查邮箱或者密码');
|
||||||
}
|
}
|
||||||
|
@@ -159,4 +159,16 @@ class UserController extends Controller
|
|||||||
return $builder;
|
return $builder;
|
||||||
})->getList();
|
})->getList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function export()
|
||||||
|
{
|
||||||
|
return User::query()
|
||||||
|
->select('id', 'username', 'email', 'created_at')
|
||||||
|
->without('roles')
|
||||||
|
->get()
|
||||||
|
->download(['id', '昵称', '邮箱', '创建时间']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -58,16 +58,16 @@ trait UserRelations
|
|||||||
|
|
||||||
/* @var Permissions $permissionsModel */
|
/* @var Permissions $permissionsModel */
|
||||||
$permissionsModel = app($this->getPermissionsModel());
|
$permissionsModel = app($this->getPermissionsModel());
|
||||||
|
|
||||||
if ($this->isSuperAdmin()) {
|
if ($this->isSuperAdmin()) {
|
||||||
$permissions = $permissionsModel->get();
|
$permissions = $permissionsModel->orderByDesc('sort')->get();
|
||||||
} else {
|
} else {
|
||||||
$permissions = Collection::make();
|
$permissionIds = Collection::make();
|
||||||
$this->roles()->with('permissions')->get()
|
$this->roles()->with('permissions')->get()
|
||||||
->each(function ($role) use (&$permissions) {
|
->each(function ($role) use (&$permissionIds) {
|
||||||
$permissions = $permissions->concat($role->permissions);
|
$permissionIds = $permissionIds->concat($role->permissions?->pluck('id'));
|
||||||
});
|
});
|
||||||
$permissions = $permissions->unique();
|
|
||||||
|
$permissions = $permissionsModel->whereIn('id', $permissionIds->unique())->orderByDesc('sort')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAttribute('permissions', $permissions->each(fn ($permission) => $permission->setAttribute('hidden', $permission->isHidden())));
|
$this->setAttribute('permissions', $permissions->each(fn ($permission) => $permission->setAttribute('hidden', $permission->isHidden())));
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Modules\User\Models;
|
namespace Modules\User\Models;
|
||||||
|
|
||||||
use Catch\Base\CatchModel as Model;
|
use Catch\Base\CatchModel as Model;
|
||||||
|
use Catch\Enums\Status;
|
||||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
@@ -37,7 +38,7 @@ class User extends Model implements AuthenticatableContract
|
|||||||
public array $searchable = [
|
public array $searchable = [
|
||||||
'username' => 'like',
|
'username' => 'like',
|
||||||
'email' => 'like',
|
'email' => 'like',
|
||||||
'status' => '='
|
'status' => '=',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,10 +97,16 @@ class User extends Model implements AuthenticatableContract
|
|||||||
*/
|
*/
|
||||||
public function updateBy($id, array $data): mixed
|
public function updateBy($id, array $data): mixed
|
||||||
{
|
{
|
||||||
if (isset($data['password']) && ! $data['password']) {
|
if (empty($data['password'])) {
|
||||||
unset($data['password']);
|
unset($data['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::updateBy($id, $data);
|
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::match(['post', 'get'], 'user/online', [UserController::class, 'online']);
|
||||||
Route::get('user/login/log', [UserController::class, 'loginLog']);
|
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/operate/log', [UserController::class, 'operateLog']);
|
||||||
|
Route::get('user/export', [UserController::class, 'export']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
<div class="table-default">
|
<div class="table-default">
|
||||||
<div class="w-full flex justify-end">
|
<div class="w-full flex justify-end">
|
||||||
<el-radio-group v-model="query.scope" size="small" @change="search">
|
<el-radio-group v-model="query.scope" size="small" @change="search">
|
||||||
<el-radio-button label="self">只看自己</el-radio-button>
|
<el-radio-button value="self">只看自己</el-radio-button>
|
||||||
<el-radio-button label="all">全部</el-radio-button>
|
<el-radio-button value="all">全部</el-radio-button>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</div>
|
</div>
|
||||||
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
<el-table :data="tableData" class="mt-3" v-loading="loading">
|
||||||
|
@@ -16,12 +16,17 @@
|
|||||||
</template>
|
</template>
|
||||||
</Search>
|
</Search>
|
||||||
<div class="table-default">
|
<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 :data="tableData" class="mt-3" v-loading="loading">
|
||||||
<el-table-column prop="username" label="用户名" width="150" />
|
<el-table-column prop="username" label="用户名" width="150" />
|
||||||
<el-table-column prop="avatar" label="头像">
|
<el-table-column prop="avatar" label="头像">
|
||||||
<template #default="scope">
|
<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>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="email" label="邮箱" />
|
<el-table-column prop="email" label="邮箱" />
|
||||||
@@ -50,6 +55,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
// @ts-nocheck
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import Create from './create.vue'
|
import Create from './create.vue'
|
||||||
import { useGetList } from '/admin/composables/curd/useGetList'
|
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 Department from './components/department.vue'
|
||||||
import { useUserStore } from '/admin/stores/modules/user'
|
import { useUserStore } from '/admin/stores/modules/user'
|
||||||
import { isUndefined } from '/admin/support/helper'
|
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 userStore = useUserStore()
|
||||||
|
|
||||||
const api = 'users'
|
const api = 'users'
|
||||||
|
|
||||||
const { data, query, search, reset, loading } = useGetList(api)
|
const { data, query, search, reset, loading } = useGetList(api)
|
||||||
const { destroy, deleted } = useDestroy()
|
const { destroy, deleted } = useDestroy()
|
||||||
const { open, close, title, visible, id } = useOpen()
|
const { open, close, title, visible, id } = useOpen()
|
||||||
|
const { download } = useExcelDownload()
|
||||||
|
|
||||||
const tableData = computed(() => data.value?.data)
|
const tableData = computed(() => data.value?.data)
|
||||||
|
|
||||||
@@ -74,9 +82,7 @@ const hasRoles = ref<boolean>(false)
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
search()
|
search()
|
||||||
|
|
||||||
deleted(reset)
|
deleted(reset)
|
||||||
|
|
||||||
hasRoles.value = !isUndefined(userStore.getRoles)
|
hasRoles.value = !isUndefined(userStore.getRoles)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
65
package.json
65
package.json
@@ -8,46 +8,49 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@heroicons/vue": "^2.0.18",
|
"@heroicons/vue": "^2.1.3",
|
||||||
"@tinymce/tinymce-vue": "^5.1.0",
|
"@tinymce/tinymce-vue": "^5.1.1",
|
||||||
"@vueuse/core": "^10.1.2",
|
"@vueuse/core": "^10.9.0",
|
||||||
"autoprefixer": "^10.4.13",
|
"element-plus": "^2.6.3",
|
||||||
"element-plus": "^2.3.4",
|
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"pinia": "^2.0.36",
|
"pinia": "^2.1.7",
|
||||||
"postcss": "^8.4.23",
|
"terser": "^5.29.2",
|
||||||
"tailwindcss": "^3.3.2",
|
"vue": "^3.4.21",
|
||||||
"terser": "^5.17.3",
|
"vue-draggable-plus": "^0.4.0",
|
||||||
"vue": "^3.2.47",
|
|
||||||
"vue-i18n": "9",
|
"vue-i18n": "9",
|
||||||
"vue-router": "4.1.6",
|
"vue-router": "4.3.0",
|
||||||
"vuedraggable": "^4.1.0"
|
"vuedraggable": "^2.24.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@iconify-json/logos": "^1.1.28",
|
"@iconify-json/logos": "^1.1.42",
|
||||||
"@rollup/plugin-alias": "^5.0.0",
|
"@rollup/plugin-alias": "^5.1.0",
|
||||||
"@types/mockjs": "^1.0.7",
|
"@types/mockjs": "^1.0.7",
|
||||||
"@types/node": "^20.1.1",
|
"@types/node": "^20.11.30",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
"@typescript-eslint/parser": "^5.59.5",
|
"@typescript-eslint/parser": "^6.21.0",
|
||||||
"@vitejs/plugin-vue": "^4.2.1",
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||||
"axios": "^1.4.0",
|
"autoprefixer": "^10.4.19",
|
||||||
"eslint": "^8.40.0",
|
"axios": "^1.6.8",
|
||||||
|
"eslint": "^8.57.0",
|
||||||
"eslint-config-standard": "^17.0.0",
|
"eslint-config-standard": "^17.0.0",
|
||||||
"eslint-plugin-import": "^2.27.5",
|
"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-promise": "^6.1.1",
|
||||||
"eslint-plugin-vue": "^9.11.1",
|
"eslint-plugin-vue": "^9.23.0",
|
||||||
"prettier": "2.8.4",
|
"mockjs": "^1.1.0",
|
||||||
"sass": "^1.62.1",
|
"postcss": "^8.4.38",
|
||||||
"typescript": "^5.0.4",
|
"prettier": "3.2.5",
|
||||||
"unplugin-auto-import": "^0.14.4",
|
"sass": "^1.72.0",
|
||||||
"unplugin-icons": "^0.16.1",
|
"tailwindcss": "^3.4.1",
|
||||||
"unplugin-vue-components": "^0.24.0",
|
"typescript": "^5.4.3",
|
||||||
"vite": "^4.3.5",
|
"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",
|
"vite-plugin-html": "^3.2.0",
|
||||||
"vue-tsc": "^1.6.4"
|
"vite-plugin-mock": "^3.0.0",
|
||||||
|
"vue-tsc": "^2.0.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<div class="pt-4">
|
||||||
<slot />
|
<slot />
|
||||||
|
</div>
|
||||||
<template #footer v-if="showFooter">
|
<template #footer v-if="showFooter">
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="close">{{ $t('system.cancel') }}</el-button>
|
<el-button @click="close">{{ $t('system.cancel') }}</el-button>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex justify-end pt-5">
|
<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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -14,12 +14,10 @@ const pageSizes = [10, 20, 30, 50]
|
|||||||
interface paginate {
|
interface paginate {
|
||||||
page: number
|
page: number
|
||||||
limit: number
|
limit: number
|
||||||
total: number
|
total: string
|
||||||
changePage: number
|
changePage: number
|
||||||
changeLimit: number
|
changeLimit: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const { page, limit, total, changePage, changeLimit } = inject('paginate') as paginate
|
const { page, limit, total, changePage, changeLimit } = inject('paginate') as paginate
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
@@ -30,4 +30,8 @@ defineProps({
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped>
|
||||||
|
:deep(.el-form-item) {
|
||||||
|
min-width: 240px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
158
resources/admin/components/catchForm/CatchForm.vue
Normal file
158
resources/admin/components/catchForm/CatchForm.vue
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<template>
|
||||||
|
<el-form :class="schema.class" :model="formValues" :label-width="schema.labelWidth || 100" :label-position="schema.labelAlign || 'right'" :size="schema.size || 'default'" :disabled="schema.disabled" :hide-required-asterisk="schema.hideRequiredAsterisk" ref="formRef" v-bind="$attrs">
|
||||||
|
<FormRender :formItems="formItems" />
|
||||||
|
<slot name="body"/>
|
||||||
|
<FormItem v-bind="footer" />
|
||||||
|
<slot name="footer"/>
|
||||||
|
</el-form>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, reactive, provide, watch, onMounted } from 'vue'
|
||||||
|
import type { FormInstance } from 'element-plus'
|
||||||
|
import { handleLinkages, deepParse, setDataByPath, getDataByPath } from '/admin/components/catchForm/support'
|
||||||
|
import FormRender from './FormRender.vue'
|
||||||
|
import FormItem from './FormItem.vue'
|
||||||
|
import { cloneDeep, merge } from 'lodash'
|
||||||
|
import type { anyObject, schemaType } from '/admin/components/catchForm/config/commonType'
|
||||||
|
import { $schema, $formValues, $selectData, $formEvents, $initialValues } from '/admin/components/catchForm/config/symbol'
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
Readonly<{
|
||||||
|
schema: schemaType
|
||||||
|
schemaContext?: anyObject
|
||||||
|
}>
|
||||||
|
>()
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
const emit = defineEmits<{
|
||||||
|
onChange: [values: anyObject]
|
||||||
|
onSubmit: [values: anyObject]
|
||||||
|
onSubmitFailed: [e: anyObject]
|
||||||
|
}>()
|
||||||
|
const formRef = ref<FormInstance>()
|
||||||
|
const selectData = reactive({})
|
||||||
|
const initialValues = reactive({})
|
||||||
|
const stateFormValues = ref({})
|
||||||
|
|
||||||
|
const formValues = computed({
|
||||||
|
get() {
|
||||||
|
return modelValue.value || stateFormValues.value
|
||||||
|
},
|
||||||
|
set(values) {
|
||||||
|
modelValue.value = values
|
||||||
|
stateFormValues.value = values
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const context = computed(() => ({
|
||||||
|
$values: formValues.value,
|
||||||
|
$selectData: selectData,
|
||||||
|
$initialValues: initialValues,
|
||||||
|
...props.schemaContext
|
||||||
|
}))
|
||||||
|
|
||||||
|
const formItems = computed(() => deepParse(props.schema.items || [], context.value))
|
||||||
|
|
||||||
|
// 保持schema的响应 传递给后代使用
|
||||||
|
const currentSchema = computed(() => props.schema)
|
||||||
|
|
||||||
|
// 表单底部
|
||||||
|
const defaultFooter = {
|
||||||
|
name: 'FormFooter',
|
||||||
|
props: {
|
||||||
|
class: 'flex justify-end mt-4'
|
||||||
|
},
|
||||||
|
component: 'inline',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: 'divider_xAlcpi',
|
||||||
|
props: {
|
||||||
|
name: '提交',
|
||||||
|
clickEvent: 'submitForm'
|
||||||
|
},
|
||||||
|
component: 'button',
|
||||||
|
style: 'margin-right:10px'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'divider_UktsYm',
|
||||||
|
props: {
|
||||||
|
name: '重置',
|
||||||
|
clickEvent: 'resetForm',
|
||||||
|
type: 'default'
|
||||||
|
},
|
||||||
|
component: 'button'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
const footer = computed(() => props.schema.footer || defaultFooter)
|
||||||
|
const validate = () => formRef.value?.validate()
|
||||||
|
|
||||||
|
const submit = async () => {
|
||||||
|
try {
|
||||||
|
await validate()
|
||||||
|
emit('onSubmit', formValues.value)
|
||||||
|
return formValues.value
|
||||||
|
} catch (e: any) {
|
||||||
|
emit('onSubmitFailed', e)
|
||||||
|
return Promise.reject(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getFormValues = () => ({ ...formValues.value })
|
||||||
|
const setFormValues = (values: anyObject) => {
|
||||||
|
formValues.value = { ...formValues.value, ...values }
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetFields = (names: string[]) => {
|
||||||
|
if (names) {
|
||||||
|
let temp = cloneDeep(formValues.value)
|
||||||
|
|
||||||
|
names.forEach(name => {
|
||||||
|
temp = setDataByPath(temp, name, getDataByPath(initialValues, name))
|
||||||
|
})
|
||||||
|
|
||||||
|
formValues.value = temp
|
||||||
|
|
||||||
|
} else {
|
||||||
|
formValues.value = initialValues
|
||||||
|
}
|
||||||
|
|
||||||
|
clearValidate();
|
||||||
|
}
|
||||||
|
// 这里做一个魔法操作,分栏操作,导致第二栏没有办法初始化,所以 resetFields 下
|
||||||
|
// 只有创建的时候进行该操作
|
||||||
|
onMounted(() => {
|
||||||
|
resetFields([]);
|
||||||
|
})
|
||||||
|
// const reset validates
|
||||||
|
const clearValidate = () => {
|
||||||
|
formRef.value?.clearValidate()
|
||||||
|
}
|
||||||
|
watch(
|
||||||
|
formValues,
|
||||||
|
(newVal, oldVal) => {
|
||||||
|
emit('onChange', newVal)
|
||||||
|
handleLinkages({ newVal, oldVal, formValues, formItems: formItems.value })
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(initialValues, newVal => {
|
||||||
|
formValues.value = merge(formValues.value, newVal)
|
||||||
|
})
|
||||||
|
|
||||||
|
provide($schema, currentSchema)
|
||||||
|
provide($formValues, {
|
||||||
|
formValues,
|
||||||
|
updateFormValues: (values: anyObject) => (formValues.value = values)
|
||||||
|
})
|
||||||
|
provide($selectData, selectData)
|
||||||
|
provide($formEvents, { submit, validate, getFormValues, setFormValues, resetFields })
|
||||||
|
provide($initialValues, {
|
||||||
|
initialValues,
|
||||||
|
updateInitialValues: (values: anyObject) => Object.assign(initialValues, values)
|
||||||
|
})
|
||||||
|
|
||||||
|
defineExpose({ submit, validate, getFormValues, setFormValues, resetFields, context })
|
||||||
|
</script>
|
30
resources/admin/components/catchForm/Disabled.vue
Normal file
30
resources/admin/components/catchForm/Disabled.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="disabled" v-bind="$attrs" class="disabled-wrapper">
|
||||||
|
<div class="mask"></div>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else> <slot /> </template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
disabled: Boolean
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.disabled-wrapper {
|
||||||
|
background-color: var(--el-disabled-bg-color);
|
||||||
|
position: relative;
|
||||||
|
.mask {
|
||||||
|
cursor: not-allowed;
|
||||||
|
position: absolute;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
193
resources/admin/components/catchForm/FormItem.vue
Normal file
193
resources/admin/components/catchForm/FormItem.vue
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
<!-- eslint-disable vue/no-multiple-template-root -->
|
||||||
|
<template>
|
||||||
|
<template v-if="!hidden">
|
||||||
|
<div v-if="config.type === 'layout'" :style="itemStyle" :class="thisProps.class">
|
||||||
|
<component :is="config.component" :name="name" :props="props" :children="children" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else-if="config.type === 'assist'" :style="itemStyle" :class="thisProps.class">
|
||||||
|
<component :is="config.component" v-bind="props" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-form-item v-else id="form-item" :style="itemStyle" :label="label" :key="name" :prop="name" :rules="computeRules" :class="thisProps.class">
|
||||||
|
<!--<template #label v-if="!hideLabel">
|
||||||
|
<div class="form-item-label">
|
||||||
|
<div >{{ label }}</div>
|
||||||
|
<div class="ico" v-if="help">
|
||||||
|
<el-tooltip class="box-item" effect="dark" :content="help">
|
||||||
|
<div><icon-render name="help" /></div>
|
||||||
|
</el-tooltip>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>-->
|
||||||
|
<component :is="config.component" :class="formItemProps.class" :disabled="schema.disabled" :size="schema.size" v-bind="formItemProps" v-model:[config.modelName]="value" />
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, inject, nextTick, onMounted, ref } from 'vue'
|
||||||
|
import { isArray, isString } from 'lodash'
|
||||||
|
import { isRegexString, getDataByPath, setDataByPath } from '/admin/components/catchForm/support'
|
||||||
|
import { $global, $schema, $formValues, $initialValues } from '/admin/components/catchForm/config/symbol'
|
||||||
|
import type { formItemType, changeItemType, schemaType, anyObject, $globalType } from '/admin/components/catchForm/config/commonType'
|
||||||
|
import defaultElements from '/admin/components/catchForm/components'
|
||||||
|
|
||||||
|
type FormItemProps = {
|
||||||
|
label?: string
|
||||||
|
name: string
|
||||||
|
component: string
|
||||||
|
required?: boolean
|
||||||
|
props?: object
|
||||||
|
initialValue?: any
|
||||||
|
help?: string
|
||||||
|
children?: formItemType[]
|
||||||
|
hidden?: boolean | string
|
||||||
|
hideLabel?: boolean
|
||||||
|
rules?: any[]
|
||||||
|
// eslint-disable-next-line vue/no-reserved-props
|
||||||
|
class?: string
|
||||||
|
// eslint-disable-next-line vue/no-reserved-props
|
||||||
|
style?: any
|
||||||
|
change?: changeItemType[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const thisProps = defineProps<FormItemProps>()
|
||||||
|
|
||||||
|
const { elements = {} } = inject<$globalType>($global, { elements: defaultElements })
|
||||||
|
|
||||||
|
const schema = inject<schemaType>($schema)
|
||||||
|
|
||||||
|
const { formValues, updateFormValues } = inject($formValues, {
|
||||||
|
formValues: ref({}),
|
||||||
|
updateFormValues: (values: anyObject) => {
|
||||||
|
console.log(values)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const { initialValues, updateInitialValues } = inject($initialValues, {
|
||||||
|
initialValues: {},
|
||||||
|
updateInitialValues: (values: anyObject) => {
|
||||||
|
console.log(values)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const value = computed({
|
||||||
|
get() {
|
||||||
|
return getDataByPath(formValues.value, thisProps.name)
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
const newValues = setDataByPath(formValues.value, thisProps.name, val)
|
||||||
|
|
||||||
|
updateFormValues(newValues)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const itemStyle = computed(() => ({
|
||||||
|
// marginBottom: thisProps.design ? 0 : '18px',
|
||||||
|
...thisProps.style
|
||||||
|
}))
|
||||||
|
|
||||||
|
const computeRules = computed(() => {
|
||||||
|
const { rules, required } = thisProps
|
||||||
|
|
||||||
|
const ruleData = []
|
||||||
|
|
||||||
|
if (required) {
|
||||||
|
ruleData.push({ required: true, message: '该字段是必填字段', trigger: 'blur' })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rules) {
|
||||||
|
const ruleParse = rules.map(({ type, message, trigger, customReg }) => {
|
||||||
|
const ruleDef = {
|
||||||
|
message,
|
||||||
|
trigger
|
||||||
|
}
|
||||||
|
if (['email', 'url'].includes(type)) {
|
||||||
|
return { ...ruleDef, type }
|
||||||
|
}
|
||||||
|
if (type === 'custom') {
|
||||||
|
return {
|
||||||
|
...ruleDef,
|
||||||
|
pattern: customReg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isRegexString(type)) {
|
||||||
|
return {
|
||||||
|
...ruleDef,
|
||||||
|
pattern: type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
})
|
||||||
|
return [...ruleData, ...ruleParse]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ruleData
|
||||||
|
})
|
||||||
|
|
||||||
|
const currentComponent = computed(() => {
|
||||||
|
if (isString(value.value) && /^{{\s*(.*?)\s*}}$/.test(value.value)) {
|
||||||
|
return 'input'
|
||||||
|
}
|
||||||
|
|
||||||
|
return thisProps.component
|
||||||
|
})
|
||||||
|
|
||||||
|
const config = computed(() => {
|
||||||
|
return elements[currentComponent.value] || {}
|
||||||
|
})
|
||||||
|
|
||||||
|
const formItemProps = computed(() => {
|
||||||
|
const initProps: anyObject = {
|
||||||
|
...thisProps.props,
|
||||||
|
name: thisProps.name
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisProps.children) {
|
||||||
|
initProps.children = thisProps.children
|
||||||
|
}
|
||||||
|
|
||||||
|
return initProps
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (thisProps.initialValue !== undefined) {
|
||||||
|
if (!value.value || (isArray(value.value) && value.value.length === 0)) {
|
||||||
|
const newInitialValues = setDataByPath(initialValues, thisProps.name, thisProps.initialValue)
|
||||||
|
updateInitialValues(newInitialValues)
|
||||||
|
// select array value
|
||||||
|
if (isArray(value.value)) {
|
||||||
|
nextTick(() => {
|
||||||
|
value.value = thisProps.initialValue
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
if (!value.value && thisProps.default !== undefined) {
|
||||||
|
const newInitialValues = setDataByPath(initialValues, thisProps.name, thisProps.default)
|
||||||
|
updateInitialValues(newInitialValues)
|
||||||
|
}*/
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
#form-item {
|
||||||
|
.form-item-label {
|
||||||
|
display: flex;
|
||||||
|
position: relative;
|
||||||
|
.ico {
|
||||||
|
margin-left: 3px;
|
||||||
|
font-size: 15px;
|
||||||
|
position: relative;
|
||||||
|
.el-tooltip__trigger {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
13
resources/admin/components/catchForm/FormRender.vue
Normal file
13
resources/admin/components/catchForm/FormRender.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!-- eslint-disable vue/no-multiple-template-root -->
|
||||||
|
<template>
|
||||||
|
<form-item v-for="item in formItems" :key="item.name" v-bind="item" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { formItemsType } from '/admin/components/catchForm/config/commonType'
|
||||||
|
import FormItem from './FormItem.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
formItems: formItemsType
|
||||||
|
}>()
|
||||||
|
</script>
|
@@ -0,0 +1,6 @@
|
|||||||
|
import { ElAlert } from 'element-plus'
|
||||||
|
export default {
|
||||||
|
name: 'alert',
|
||||||
|
component: ElAlert,
|
||||||
|
type: 'assist'
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
<template>
|
||||||
|
<el-button class="Button" v-bind="{ ...$attrs, ...props }" @click="onClick">{{ name }}</el-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { inject } from 'vue'
|
||||||
|
import { ElButton } from 'element-plus'
|
||||||
|
import { $formEvents } from '/admin/components/catchForm/config/symbol'
|
||||||
|
|
||||||
|
const formEvents = inject($formEvents)
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
name: String,
|
||||||
|
disabled: Boolean,
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'primary'
|
||||||
|
},
|
||||||
|
clickEvent: String,
|
||||||
|
customEvent: Function,
|
||||||
|
color: String
|
||||||
|
})
|
||||||
|
|
||||||
|
const onClick = () => {
|
||||||
|
if (props.clickEvent === 'submitForm') {
|
||||||
|
formEvents.submit()
|
||||||
|
}
|
||||||
|
if (props.clickEvent === 'resetForm') {
|
||||||
|
formEvents.resetFields()
|
||||||
|
}
|
||||||
|
if (props.clickEvent === 'custom') {
|
||||||
|
props.customEvent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.Button {
|
||||||
|
/* background-color: v-bind(color); */
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Button from './Button.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'button',
|
||||||
|
component: Button,
|
||||||
|
type: 'assist'
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
<template>
|
||||||
|
<ElCard v-bind="{ ...props, ...$attrs }">
|
||||||
|
<FormRender :formItems="children" />
|
||||||
|
</ElCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ElCard } from 'element-plus'
|
||||||
|
import FormRender from '/admin/components/catchForm/FormRender.vue'
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
props: Object,
|
||||||
|
children: Array,
|
||||||
|
design: Boolean
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.form-item-grid {
|
||||||
|
.el-form-item {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Card from './Card.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'card',
|
||||||
|
component: Card,
|
||||||
|
type: 'layout'
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
<template>
|
||||||
|
<el-cascader
|
||||||
|
v-model="modelValue"
|
||||||
|
:options="options"
|
||||||
|
:show-all-levels="!takeLastLevel"
|
||||||
|
:props="{
|
||||||
|
multiple,
|
||||||
|
value: valueKey,
|
||||||
|
label,
|
||||||
|
checkStrictly,
|
||||||
|
}"
|
||||||
|
v-bind="$attrs"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
checkStrictly: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: 'label'
|
||||||
|
},
|
||||||
|
valueKey: {
|
||||||
|
type: String,
|
||||||
|
default: 'value'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type:[String, Number, Array],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
api: Object,
|
||||||
|
name: String,
|
||||||
|
takeLastLevel: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const modelValue = defineModel()
|
||||||
|
onMounted(() => {
|
||||||
|
modelValue.value = props.value
|
||||||
|
})
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Cascader from './Cascader.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'cascader',
|
||||||
|
type: 'basic',
|
||||||
|
component: Cascader
|
||||||
|
}
|
@@ -0,0 +1,71 @@
|
|||||||
|
<template>
|
||||||
|
<div v-if="!options.length" style="font-size: 12px">暂无选项</div>
|
||||||
|
|
||||||
|
<el-checkbox-group v-bind="$attrs" v-model="modelValue" @change="selectChange">
|
||||||
|
<template v-if="optionType === 'circle' || optionType === 'border'">
|
||||||
|
<el-checkbox v-for="item in options" :key="item[valueKey]" :value="item[valueKey]" :border="optionType === 'border'" :disabled="item.disabled">{{ item[label] }}</el-checkbox>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-space v-if="optionType === 'button'" wrap :size="[space, space]">
|
||||||
|
<el-checkbox-button v-for="item in options" :key="item[valueKey]" :value="item[valueKey]" size="large" :disabled="item.disabled">{{ item[label] }}</el-checkbox-button>
|
||||||
|
</el-space>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'static'
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: 'label'
|
||||||
|
},
|
||||||
|
valueKey: {
|
||||||
|
type: String,
|
||||||
|
default: 'value'
|
||||||
|
},
|
||||||
|
autoSelectedFirst: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
api: Object,
|
||||||
|
name: String,
|
||||||
|
optionType: {
|
||||||
|
type: String,
|
||||||
|
default: 'circle'
|
||||||
|
},
|
||||||
|
space: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true // 不可更改
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Array,
|
||||||
|
default: []
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// const emits = defineEmits(['update:modelValue', 'onChangeSelect'])
|
||||||
|
const modelValue = defineModel()
|
||||||
|
const selectChange = value => {
|
||||||
|
modelValue.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
modelValue.value = props.value
|
||||||
|
})
|
||||||
|
// const { selectVal, currentOptions, selectChange, loading } = useSelect(props, emits)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped></style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Checkbox from './Checkbox.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'checkbox',
|
||||||
|
type: 'basic',
|
||||||
|
component: Checkbox
|
||||||
|
}
|
@@ -0,0 +1,34 @@
|
|||||||
|
<template>
|
||||||
|
<ElCollapse v-bind="{ ...props, ...$attrs }" v-model="activeKey">
|
||||||
|
<ElCollapseItem v-for="item in children" :key="item.name" :name="item.name">
|
||||||
|
<template #title>
|
||||||
|
<Title :title="item.title" italic type="h4" />
|
||||||
|
</template>
|
||||||
|
<FormRender :formItems="item.children" />
|
||||||
|
</ElCollapseItem>
|
||||||
|
</ElCollapse>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import FormRender from '/admin/components/catchForm/FormRender.vue'
|
||||||
|
import Title from '../Title/Title.vue'
|
||||||
|
const thisProps = defineProps({
|
||||||
|
props: Object,
|
||||||
|
children: Array
|
||||||
|
})
|
||||||
|
|
||||||
|
const activeKey = ref([])
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
activeKey.value = thisProps.children.filter(item => item.checked).map(item => item.name)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.form-item-grid {
|
||||||
|
.el-form-item {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Collapse from './Collapse.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'collapse',
|
||||||
|
component: Collapse,
|
||||||
|
type: 'layout'
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
modelValue.value = props.value
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<el-color-picker v-model="modelValue" v-bind="$attrs"/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
|
||||||
|
</style>
|
@@ -0,0 +1,6 @@
|
|||||||
|
import { ElColorPicker } from 'element-plus'
|
||||||
|
export default {
|
||||||
|
name: 'color_picker',
|
||||||
|
component: ElColorPicker,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,30 @@
|
|||||||
|
<template>
|
||||||
|
<span class="empty" v-if="!componentName">请输入全局注册得组件名</span>
|
||||||
|
<component v-else :is="componentName" v-model="value" v-bind="$attrs" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
componentName: String,
|
||||||
|
modelValue: null
|
||||||
|
})
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
|
||||||
|
const value = computed({
|
||||||
|
get() {
|
||||||
|
return modelValue.value
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
modelValue.value = val
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.empty {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,11 @@
|
|||||||
|
import Custom from './Custom.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'custom',
|
||||||
|
component: Custom,
|
||||||
|
initialValues: {
|
||||||
|
label: '自定义组件',
|
||||||
|
component: 'Custom',
|
||||||
|
props: {}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
import { ElDatePicker } from 'element-plus'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'date_picker',
|
||||||
|
component: ElDatePicker,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
<ElDivider v-bind="$attrs">{{ title }}</ElDivider>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ElDivider } from 'element-plus'
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
title: String
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style></style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Divider from './Divider.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'divider',
|
||||||
|
component: Divider,
|
||||||
|
type: 'assist'
|
||||||
|
}
|
@@ -0,0 +1,161 @@
|
|||||||
|
<template>
|
||||||
|
<div id="formList">
|
||||||
|
<div>
|
||||||
|
<template v-if="mode === 'inline'">
|
||||||
|
<el-form-item v-for="(item, index) in list" :key="item.key" class="list-item">
|
||||||
|
<div class="list-item-content">
|
||||||
|
<el-space>
|
||||||
|
<form-item v-for="field in fields(index)" v-bind="field" :key="field.label" :name="`${name}.${index}.${field.name}`" hideLabel />
|
||||||
|
</el-space>
|
||||||
|
|
||||||
|
<el-button v-if="allowReduce" @click="handleReduceItem(index)" circle size="small" :disabled="disabled">
|
||||||
|
<Icon name="minus"/>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="mode === 'card'">
|
||||||
|
<el-card v-for="(item, index) in list" :key="item.key" class="list-card">
|
||||||
|
<template #header>
|
||||||
|
<div class="card-header">
|
||||||
|
<span>{{ title + (index + 1) }}</span>
|
||||||
|
<el-button v-if="allowReduce" @click="handleReduceItem(index)" circle size="small" :disabled="disabled">
|
||||||
|
<Icon name="minus"/>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<form-item v-for="field in fields(index)" v-bind="field" :key="field.label" class="list-card-item" :name="`${name}.${index}.${field.name}`" />
|
||||||
|
</el-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-table v-if="mode === 'table' && list.length" :data="list" style="width: 100%">
|
||||||
|
<el-table-column :prop="item.name" :label="item.label" :key="item.name" v-for="item in children" :width="item.width" :formatter="(row, _, __, index) => formatter(item, row, index)" />
|
||||||
|
<el-table-column fixed="right" min-width="60">
|
||||||
|
<template #default="record">
|
||||||
|
<el-button v-if="allowReduce" @click="handleReduceItem(record.$index)" circle size="small" :disabled="disabled">
|
||||||
|
<Icon name="minus"/>
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<el-button v-if="allowAdd && !isMax" @click="handleAddItem" circle size="small" :disabled="disabled">
|
||||||
|
<Icon name="plus"/>
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, h } from 'vue'
|
||||||
|
import FormItem from '/admin/components/catchForm/FormItem.vue'
|
||||||
|
import { deepParse } from '/admin/components/catchForm/support'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: Array,
|
||||||
|
children: Array,
|
||||||
|
allowAdd: {
|
||||||
|
default: true,
|
||||||
|
type: Boolean
|
||||||
|
},
|
||||||
|
allowReduce: {
|
||||||
|
default: true,
|
||||||
|
type: Boolean
|
||||||
|
},
|
||||||
|
defaultLineCount: {
|
||||||
|
default: 0,
|
||||||
|
type: Number
|
||||||
|
},
|
||||||
|
maxLines: {
|
||||||
|
default: 999,
|
||||||
|
type: Number
|
||||||
|
},
|
||||||
|
mode: {
|
||||||
|
default: 'table',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
default: '卡片',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
newItemDefaults: {
|
||||||
|
type: Function,
|
||||||
|
default: () => ({})
|
||||||
|
},
|
||||||
|
name: String,
|
||||||
|
disabled: Boolean
|
||||||
|
})
|
||||||
|
|
||||||
|
const modelValue = defineModel();
|
||||||
|
|
||||||
|
const list = computed(() => {
|
||||||
|
return modelValue.value || []
|
||||||
|
})
|
||||||
|
|
||||||
|
const fields = computed(() => index => deepParse(props.children, { $item: list.value[index], $index: index }))
|
||||||
|
|
||||||
|
const isMax = computed(() => {
|
||||||
|
return list.value.length >= props.maxLines
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleAddItem = () => {
|
||||||
|
if (isMax.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
modelValue.value = [...list.value, props.newItemDefaults(list.value.length)]
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleReduceItem = index => {
|
||||||
|
const newData = list.value.filter((v, i) => i !== index)
|
||||||
|
|
||||||
|
modelValue.value = newData
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatter = (item, data, index) => {
|
||||||
|
return h(FormItem, {
|
||||||
|
...deepParse(item, { $item: list.value[index], $index: index }),
|
||||||
|
hideLabel: true,
|
||||||
|
style: { marginBottom: 0 },
|
||||||
|
name: `${props.name}.${index}.${item.name}`
|
||||||
|
})
|
||||||
|
// return (
|
||||||
|
// <FormItem
|
||||||
|
// {...deepParse(item, { $item: list.value[index], $index: index })}
|
||||||
|
// hideLabel
|
||||||
|
// style={{ marginBottom: 0 }}
|
||||||
|
// name={`${props.name}.${index}.${item.name}`}
|
||||||
|
// />
|
||||||
|
// )
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
#formList {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
.list-item {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
.list-item-content {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.list-card {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.list-card-item {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.list-btn {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import FormList from './FormList.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'form_list',
|
||||||
|
component: FormList,
|
||||||
|
type: 'high'
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<div class="form-item-grid">
|
||||||
|
<div :style="gridStyle">
|
||||||
|
<FormRender :formItems="children" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import FormRender from '/admin/components/catchForm/FormRender.vue'
|
||||||
|
|
||||||
|
const thisProps = defineProps({
|
||||||
|
name: String,
|
||||||
|
props: Object,
|
||||||
|
children: Array,
|
||||||
|
design: Boolean
|
||||||
|
})
|
||||||
|
const gridStyle = computed(() => ({
|
||||||
|
display: 'grid',
|
||||||
|
'grid-template-columns': `repeat(${thisProps.props.columns}, 1fr)`,
|
||||||
|
'row-gap': thisProps.props['row-gap'] + 'px',
|
||||||
|
'column-gap': thisProps.props['column-gap'] + 'px'
|
||||||
|
}))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.form-item-grid {
|
||||||
|
.el-form-item {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
.el-form-item__content {
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Grid from './Grid.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'grid',
|
||||||
|
type: 'layout',
|
||||||
|
component: Grid
|
||||||
|
}
|
@@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<el-popover placement="right" :width="400" trigger="click">
|
||||||
|
<template #reference>
|
||||||
|
<el-input v-model="iconModel" name="icon" clearable />
|
||||||
|
</template>
|
||||||
|
<div>
|
||||||
|
<Icons v-model="iconModel" @close="closeSelectIcon" />
|
||||||
|
</div>
|
||||||
|
</el-popover>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
const iconModel = defineModel()
|
||||||
|
// 选择 icon
|
||||||
|
const visible = ref(false)
|
||||||
|
// 关闭选择 icon
|
||||||
|
const closeSelectIcon = () => {
|
||||||
|
visible.value = false
|
||||||
|
}
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import IconSelect from './IconSelect.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'icon_select',
|
||||||
|
type: 'basic',
|
||||||
|
component: IconSelect
|
||||||
|
}
|
@@ -0,0 +1,20 @@
|
|||||||
|
<template>
|
||||||
|
<div class="form-item-inline">
|
||||||
|
<div :class="InlineStyle">
|
||||||
|
<FormRender :formItems="children" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import FormRender from '/admin/components/catchForm/FormRender.vue'
|
||||||
|
|
||||||
|
const thisProps = defineProps({
|
||||||
|
name: String,
|
||||||
|
props: Object,
|
||||||
|
children: Array,
|
||||||
|
class: String
|
||||||
|
})
|
||||||
|
const InlineStyle = computed(() => thisProps.props.class)
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Inline from './Inline.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'inline',
|
||||||
|
type: 'layout',
|
||||||
|
component: Inline
|
||||||
|
}
|
@@ -0,0 +1,8 @@
|
|||||||
|
import { ElInput } from 'element-plus'
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'input',
|
||||||
|
component: h(ElInput, { showWordLimit: true, autocomplete: 'off' }),
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,39 @@
|
|||||||
|
<template>
|
||||||
|
<span id="NumberInput">
|
||||||
|
<el-input-number v-bind="{ ...$attrs, ...props }" v-model="value" />
|
||||||
|
<span class="unit" v-if="unit">{{ unit }} </span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { ElInputNumber } from 'element-plus'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
unit: String,
|
||||||
|
min: { type: Number, default: 0 },
|
||||||
|
max: Number,
|
||||||
|
disabled: Boolean,
|
||||||
|
step: { type: Number, default: 1 }
|
||||||
|
})
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
|
||||||
|
const value = computed({
|
||||||
|
get() {
|
||||||
|
return modelValue.value
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
modelValue.value = val
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
#NumberInput {
|
||||||
|
position: relative;
|
||||||
|
.unit {
|
||||||
|
margin: 0 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import InputNumber from './InputNumber.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'input_number',
|
||||||
|
type: 'basic',
|
||||||
|
component: InputNumber
|
||||||
|
}
|
@@ -0,0 +1,8 @@
|
|||||||
|
import { ElInput } from 'element-plus'
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'password',
|
||||||
|
component: h(ElInput, { type: 'password', showWordLimit: true, autocomplete: 'off' }),
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,68 @@
|
|||||||
|
<!-- eslint-disable vue/no-multiple-template-root -->
|
||||||
|
<template>
|
||||||
|
<div v-if="!options.length" style="font-size: 12px">暂无选项</div>
|
||||||
|
<el-radio-group v-model="modelValue" @change="clickRadio" v-bind="$attrs">
|
||||||
|
<el-space wrap :direction="direction" :size="[space, space]" alignment="normal" v-if="space > 0">
|
||||||
|
<template v-if="optionType === 'circle' || optionType === 'border'">
|
||||||
|
<el-radio v-for="item in options" :key="item[value]" :value="item[value]" :border="optionType === 'border'">{{ item[label] }}</el-radio>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<el-radio-button v-for="item in options" :key="item[value]" :value="item[value]" :size="$attrs.size">{{ item[label] }} </el-radio-button>
|
||||||
|
</template>
|
||||||
|
</el-space>
|
||||||
|
<div v-else>
|
||||||
|
<template v-if="optionType === 'circle' || optionType === 'border'">
|
||||||
|
<el-radio v-for="item in options" :key="item[value]" :value="item[value]" :border="optionType === 'border'">{{ item[label] }}</el-radio>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<el-radio-button v-for="item in options" :key="item[value]" :value="item[value]" :size="$attrs.size">{{ item[label] }} </el-radio-button>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</el-radio-group>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
// import { defineEmits } from 'vue'
|
||||||
|
// import useSelect from '/admin/components/catchForm/hooks/useSelect'
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: 'label'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: String,
|
||||||
|
default: 'value'
|
||||||
|
},
|
||||||
|
autoSelectedFirst: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
api: Object,
|
||||||
|
name: String,
|
||||||
|
optionType: {
|
||||||
|
type: String,
|
||||||
|
default: 'circle'
|
||||||
|
},
|
||||||
|
|
||||||
|
direction: {
|
||||||
|
type: String,
|
||||||
|
default: 'horizontal'
|
||||||
|
},
|
||||||
|
space: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
const clickRadio = value => {
|
||||||
|
modelValue.value = value
|
||||||
|
}
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Radio from './Radio.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'radio',
|
||||||
|
type: 'basic',
|
||||||
|
component: Radio
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
import { ElRate } from 'element-plus'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'rate',
|
||||||
|
component: ElRate,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,84 @@
|
|||||||
|
<template>
|
||||||
|
<el-select v-bind="$attrs" class="w-full" clearable filterable :multiple="multiple" :value-key="valueKey" v-model="modelValue">
|
||||||
|
<template v-if="group">
|
||||||
|
<el-option-group v-for="group in elOptions" :key="group[label]" :label="group[label]">
|
||||||
|
<el-option v-for="item in group.options" :key="item[valueKey]" :label="item[label]" :value="item[valueKey]" />
|
||||||
|
</el-option-group>
|
||||||
|
</template>
|
||||||
|
<el-option v-for="option in elOptions" :key="option[valueKey]" :label="option[label]" :value="option[valueKey]" v-else>
|
||||||
|
<slot />
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { inject, ref, watch } from 'vue'
|
||||||
|
import { $global} from '/admin/components/catchForm/config/symbol'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
require: false,
|
||||||
|
default: () => {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: 'label'
|
||||||
|
},
|
||||||
|
valueKey: {
|
||||||
|
type: String,
|
||||||
|
default: 'value'
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
api: {
|
||||||
|
type: String,
|
||||||
|
require: false,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
group: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
query: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
interface Option {
|
||||||
|
label: string
|
||||||
|
value: string | number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GroupOption {
|
||||||
|
label: string
|
||||||
|
options: Array<Option>
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
|
||||||
|
const { http } = inject($global)
|
||||||
|
const getOptions = () => {
|
||||||
|
http.get(props.api, props.query).then(r => {
|
||||||
|
elOptions.value = r.data.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const elOptions: any = props.group ? ref<Array<GroupOption>>() : ref<Array<Option>>()
|
||||||
|
if (props.api) {
|
||||||
|
if (!props.query) {
|
||||||
|
getOptions()
|
||||||
|
} else {
|
||||||
|
watch(props, function () {
|
||||||
|
getOptions()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
elOptions.value = props.options
|
||||||
|
}
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Select from './Select.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'select',
|
||||||
|
type: 'basic',
|
||||||
|
component: Select
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
import { ElSlider } from 'element-plus'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'slider',
|
||||||
|
component: ElSlider,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
import { ElSwitch } from 'element-plus'
|
||||||
|
import cswitch from './index.vue'
|
||||||
|
export default {
|
||||||
|
name: 'switch',
|
||||||
|
component: cswitch,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
import { before } from 'node:test'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
value: {
|
||||||
|
type: [Boolean, String, Number],
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'cswitch'
|
||||||
|
})
|
||||||
|
|
||||||
|
const valueModel = defineModel()
|
||||||
|
onMounted(() => {
|
||||||
|
valueModel.value = props.value
|
||||||
|
})
|
||||||
|
|
||||||
|
const change = (val: any) => {
|
||||||
|
valueModel.value = val
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<el-switch @change="change" v-model="valueModel"/>
|
||||||
|
</template>
|
@@ -0,0 +1,8 @@
|
|||||||
|
import { ElInput } from 'element-plus'
|
||||||
|
import { h } from 'vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'textarea',
|
||||||
|
component: h(ElInput, { type: 'textarea', showWordLimit: true, autocomplete: 'off' }),
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,23 @@
|
|||||||
|
<template>
|
||||||
|
<component :is="type" :class="class" :style="{ fontStyle: italic ? 'italic' : 'normal' }">{{
|
||||||
|
title
|
||||||
|
}}</component>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: '这是一个标题'
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'h3'
|
||||||
|
},
|
||||||
|
class: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
italic: Boolean
|
||||||
|
})
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Title from './Title.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'title',
|
||||||
|
component: Title,
|
||||||
|
type: 'assist'
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
<template>
|
||||||
|
<Disabled :disabled="disabled"> <ElTransfer v-bind="$attrs" v-model="modelValue" :data="options" :props="{ label: props.label, key: props.valueKey }" /></Disabled>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ElTransfer } from 'element-plus'
|
||||||
|
import Disabled from '/admin/components/catchForm/Disabled.vue'
|
||||||
|
|
||||||
|
const modelValue = defineModel()
|
||||||
|
const props = defineProps({
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'static'
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: 'label'
|
||||||
|
},
|
||||||
|
valueKey: {
|
||||||
|
type: String,
|
||||||
|
default: 'value'
|
||||||
|
},
|
||||||
|
api: Object,
|
||||||
|
disabled: Boolean
|
||||||
|
})
|
||||||
|
|
||||||
|
// const emits = defineEmits(['update:modelValue', 'onChangeSelect'])
|
||||||
|
|
||||||
|
// const { selectVal, currentOptions, selectChange, loading } = useSelect(props, emits)
|
||||||
|
|
||||||
|
// watchEffect(() => {
|
||||||
|
// console.log(currentOptions.value)
|
||||||
|
// })
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Transfer from './Transfer.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'transfer',
|
||||||
|
type: 'basic',
|
||||||
|
component: Transfer
|
||||||
|
}
|
@@ -0,0 +1,86 @@
|
|||||||
|
<template>
|
||||||
|
<el-tree
|
||||||
|
ref="tree"
|
||||||
|
:data="data"
|
||||||
|
:node-key="valueKey"
|
||||||
|
:class="class"
|
||||||
|
:props="{ label }"
|
||||||
|
@check="selectPermissions"
|
||||||
|
@node-click="nodeClick"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, nextTick, onMounted, watch, inject } from 'vue'
|
||||||
|
import { isArray } from 'lodash'
|
||||||
|
import { $global} from '/admin/components/catchForm/config/symbol'
|
||||||
|
|
||||||
|
const tree = ref()
|
||||||
|
const modelValue = defineModel()
|
||||||
|
const currentCheckedKeys = ref<Array<number>|Array<string>|string|number>([])
|
||||||
|
const data = ref<any>([])
|
||||||
|
const { http } = inject($global)
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'static'
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: 'label'
|
||||||
|
},
|
||||||
|
valueKey: {
|
||||||
|
type: String,
|
||||||
|
default: 'id'
|
||||||
|
},
|
||||||
|
class: {
|
||||||
|
type: String,
|
||||||
|
default: 'w-full'
|
||||||
|
},
|
||||||
|
api: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (props.api) {
|
||||||
|
http.get(props.api).then((r:any) => {
|
||||||
|
data.value = r.data.data
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
data.value = props.options
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置已选权限
|
||||||
|
const selectPermissions = (checkedNodes: any, checkedKeys: any) => {
|
||||||
|
currentCheckedKeys.value = checkedKeys.checkedKeys.concat(checkedKeys.halfCheckedKeys).sort()
|
||||||
|
tree.value.setCheckedKeys(checkedKeys.checkedKeys)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
nextTick(() => {
|
||||||
|
if (tree.value) {
|
||||||
|
if (isArray(modelValue.value)) {
|
||||||
|
modelValue.value.forEach(id => {
|
||||||
|
tree.value.setChecked(id, true, false)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
tree.value.setCurrentKey(modelValue.value, true, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const nodeClick = (node:any) => {
|
||||||
|
currentCheckedKeys.value = node.id
|
||||||
|
}
|
||||||
|
// 监听选中的 checked
|
||||||
|
watch(() => currentCheckedKeys.value, (newValue) => {
|
||||||
|
modelValue.value = newValue
|
||||||
|
}, {deep: true})
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Tree from './Tree.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'tree',
|
||||||
|
type: 'basic',
|
||||||
|
component: Tree
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
<template>
|
||||||
|
<el-upload v-model:file-list="fileList" :action="action" :name="uploadKey" multiple :before-upload="beforeAvatarUpload" :limit="limit" :on-exceed="handleExceed" v-bind="$attrs">
|
||||||
|
<el-button type="primary">
|
||||||
|
<template #icon><IconRender name="upload" /></template>
|
||||||
|
{{ buttonText }}
|
||||||
|
</el-button>
|
||||||
|
</el-upload>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onBeforeMount, computed } from 'vue'
|
||||||
|
import { ElUpload, ElButton, ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
action: String,
|
||||||
|
height: Number,
|
||||||
|
width: Number,
|
||||||
|
fileTypes: { type: Array, default: () => [] },
|
||||||
|
size: Number,
|
||||||
|
dataPath: {
|
||||||
|
type: String,
|
||||||
|
default: 'data'
|
||||||
|
},
|
||||||
|
uploadKey: {
|
||||||
|
type: String,
|
||||||
|
default: 'file'
|
||||||
|
},
|
||||||
|
buttonText: {
|
||||||
|
type: String,
|
||||||
|
default: '点击上传'
|
||||||
|
},
|
||||||
|
limit: {
|
||||||
|
type: Number,
|
||||||
|
default: 2
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const modelValue = defineModel({
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
})
|
||||||
|
|
||||||
|
const fileList = computed({
|
||||||
|
get() {
|
||||||
|
return modelValue.value
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
modelValue.value = val
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const beforeAvatarUpload = rawFile => {
|
||||||
|
const [, type] = rawFile.type.split('/')
|
||||||
|
|
||||||
|
// if (!props.fileTypes.includes(type)) {
|
||||||
|
// ElMessage.error('不支持该图片格式!')
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (rawFile.size / 1024 / 1024 > props.size) {
|
||||||
|
ElMessage.error(`图片文件大小不能超过${props.size}MB!`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleExceed = () => {
|
||||||
|
ElMessage.warning(`上传数量限制为 ${props.limit} 个!`)
|
||||||
|
}
|
||||||
|
|
||||||
|
onBeforeMount(() => {
|
||||||
|
const { modelValue } = props
|
||||||
|
|
||||||
|
if (modelValue) {
|
||||||
|
imageUrl.value = modelValue
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import Upload from './Upload.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'upload',
|
||||||
|
component: Upload,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,79 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { watch } from 'vue'
|
||||||
|
import { uploadFile } from '/admin/composables/upload'
|
||||||
|
const props = defineProps({
|
||||||
|
action: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: 'image'
|
||||||
|
},
|
||||||
|
auto: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line vue/no-reserved-props
|
||||||
|
class: {
|
||||||
|
type: String,
|
||||||
|
default: 'w-24 h-24'
|
||||||
|
},
|
||||||
|
requestFrom: {
|
||||||
|
type: String,
|
||||||
|
default: 'Dashboard'
|
||||||
|
},
|
||||||
|
token:{
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
ext: {
|
||||||
|
type: Array,
|
||||||
|
default: () => {
|
||||||
|
return ['docx', 'pdf', 'txt', 'html', 'zip', 'tar', 'doc', 'css', 'csv', 'ppt', 'xlsx', 'xls', 'xml']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 定义文件 v-model
|
||||||
|
const fileModel = defineModel({
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
required: true
|
||||||
|
})
|
||||||
|
const { upload, beforeUpload, handleExceed, handleSuccess, file, filename} = uploadFile(props.action, props.ext)
|
||||||
|
// 更新 model 的 value
|
||||||
|
watch(
|
||||||
|
() => file.value,
|
||||||
|
(newValue, oldValue) => {
|
||||||
|
fileModel.value = newValue
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<el-upload
|
||||||
|
ref="upload"
|
||||||
|
:action="action"
|
||||||
|
:show-file-list="false"
|
||||||
|
:name="name"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
|
:auto-upload="auto"
|
||||||
|
:headers="{ authorization: token, 'Request-from': requestFrom }"
|
||||||
|
v-bind="$attrs"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
:on-success="handleSuccess"
|
||||||
|
:limit="1"
|
||||||
|
>
|
||||||
|
<div v-if="fileModel">
|
||||||
|
{{ filename }}
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div class="flex items-center justify-center w-24 h-12 text-[14px] border border-blue-100 border-dashed rounded">
|
||||||
|
<div>点击上传文件</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-upload>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
|
||||||
|
</style>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import UploadFile from './UploadFile.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'upload_file',
|
||||||
|
component: UploadFile,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,95 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
import { uploadFile } from '/admin/composables/upload'
|
||||||
|
import { getFilename } from '/admin/support/helper'
|
||||||
|
import { Plus, Delete } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
action: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: 'image'
|
||||||
|
},
|
||||||
|
auto: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line vue/no-reserved-props
|
||||||
|
class: {
|
||||||
|
type: String,
|
||||||
|
default: 'w-24 h-24'
|
||||||
|
},
|
||||||
|
requestFrom: {
|
||||||
|
type: String,
|
||||||
|
default: 'Dashboard'
|
||||||
|
},
|
||||||
|
token:{
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
ext: {
|
||||||
|
type: Array,
|
||||||
|
default: () => {
|
||||||
|
return ['docx', 'pdf', 'txt', 'html', 'zip', 'tar', 'doc', 'css', 'csv', 'ppt', 'xlsx', 'xls', 'xml']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 定义文件 v-model
|
||||||
|
const filesModel = defineModel({
|
||||||
|
type: Array,
|
||||||
|
default: [],
|
||||||
|
required: true
|
||||||
|
})
|
||||||
|
const files = ref([])
|
||||||
|
|
||||||
|
const { upload, beforeUpload, handleExceed, handleSuccess, file, filename} = uploadFile(props.action, props.ext)
|
||||||
|
const delFile = (key: number) => {
|
||||||
|
files.value = files.value.filter((item, index) => index !== key)
|
||||||
|
filesModel.value = files.value
|
||||||
|
}
|
||||||
|
// 更新 model 的 value
|
||||||
|
watch(
|
||||||
|
() => file.value,
|
||||||
|
(newValue, oldValue) => {
|
||||||
|
files.value.push(newValue)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(() => files.value, (newValue, oldValue) => {
|
||||||
|
filesModel.value = newValue
|
||||||
|
}, { deep: true, immediate: true })
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<el-upload
|
||||||
|
ref="upload"
|
||||||
|
:action="action"
|
||||||
|
multiple
|
||||||
|
:show-file-list="false"
|
||||||
|
:name="name"
|
||||||
|
:auto-upload="auto"
|
||||||
|
:headers="{ authorization: token, 'Request-from': requestFrom }"
|
||||||
|
v-bind="$attrs"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
:on-success="handleSuccess"
|
||||||
|
>
|
||||||
|
<div class="flex flex-col w-full">
|
||||||
|
<div>
|
||||||
|
<div class="flex items-center justify-center w-24 h-12 text-[14px] border border-blue-100 border-dashed rounded">
|
||||||
|
<div>点击上传文件</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full">
|
||||||
|
<div v-for="(item, key) in files" :key="key" class="flex justify-between w-full">
|
||||||
|
<div>{{ getFilename(item) }}</div>
|
||||||
|
<div class="h-8 flex items-center ml-4"><el-icon @click.stop="delFile(key)" class="cursor-pointer"><Delete /></el-icon></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-upload>
|
||||||
|
</template>
|
||||||
|
|
@@ -0,0 +1,7 @@
|
|||||||
|
import UploadFiles from './UploadFiles.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'upload_files',
|
||||||
|
component: UploadFiles,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,71 @@
|
|||||||
|
<template>
|
||||||
|
<el-upload
|
||||||
|
:action="action"
|
||||||
|
:show-file-list="false"
|
||||||
|
name="image"
|
||||||
|
:auto-upload="auto"
|
||||||
|
:headers="{ authorization: token, 'Request-from': requestFrom }"
|
||||||
|
ref="upload"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
|
:on-success="handleSuccess"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
:limit="1"
|
||||||
|
>
|
||||||
|
<img v-if="fileModel" :src="fileModel" :class="class" />
|
||||||
|
<div v-else>
|
||||||
|
<div class="flex items-center justify-center w-24 h-24 border border-collapse">
|
||||||
|
<el-icon><Plus /></el-icon>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-upload>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { watch } from 'vue'
|
||||||
|
import { uploadImage } from '/admin/composables/upload'
|
||||||
|
import { Plus } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
action: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: 'image'
|
||||||
|
},
|
||||||
|
auto: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line vue/no-reserved-props
|
||||||
|
class: {
|
||||||
|
type: String,
|
||||||
|
default: 'w-24 h-24'
|
||||||
|
},
|
||||||
|
requestFrom: {
|
||||||
|
type: String,
|
||||||
|
default: 'Dashboard'
|
||||||
|
},
|
||||||
|
token:{
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
ext: {
|
||||||
|
type: Array,
|
||||||
|
default: () => ['jpg', 'jpeg', 'png', 'bmp', 'gif']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 定义文件 v-model
|
||||||
|
const fileModel = defineModel({
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
required: true
|
||||||
|
})
|
||||||
|
const { upload, beforeUpload, handleExceed, handleSuccess, file } = uploadImage(props.action, props.ext)
|
||||||
|
// 更新 model 的 value
|
||||||
|
watch(
|
||||||
|
() => file.value,
|
||||||
|
(newValue, oldValue) => {
|
||||||
|
fileModel.value = newValue
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
@@ -0,0 +1,7 @@
|
|||||||
|
import UploadImage from './UploadImage.vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'upload_image',
|
||||||
|
component: UploadImage,
|
||||||
|
type: 'basic'
|
||||||
|
}
|
@@ -0,0 +1,95 @@
|
|||||||
|
<template>
|
||||||
|
<div class="grid grid-cols-4 gap-2">
|
||||||
|
<div v-for="(item, key) in images" :key="key" class="relative w-24 h-24 group">
|
||||||
|
<img :src="item" class="w-full h-full" />
|
||||||
|
<div class="w-full h-full absolute top-0 left-0 bg-black bg-opacity-50 z-10 hidden group-hover:block" >
|
||||||
|
</div>
|
||||||
|
<div class="absolute top-9 left-10 text-white z-50" >
|
||||||
|
<el-icon @click.prevent="delImage(key)" class="cursor-pointer"><Delete /></el-icon>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<el-upload
|
||||||
|
:action="action"
|
||||||
|
:show-file-list="false"
|
||||||
|
:name="name"
|
||||||
|
multiple
|
||||||
|
:headers="{ authorization: token, 'Request-from': requestFrom }"
|
||||||
|
ref="upload"
|
||||||
|
:on-exceed="handleExceed"
|
||||||
|
:on-success="handleSuccess"
|
||||||
|
:before-upload="beforeUpload"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-center w-24 h-24 border border-collapse">
|
||||||
|
<el-icon><Plus /></el-icon>
|
||||||
|
</div>
|
||||||
|
</el-upload>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
import { uploadImage } from '/admin/composables/upload'
|
||||||
|
import { Plus, Delete } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
action: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: 'image'
|
||||||
|
},
|
||||||
|
auto: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line vue/no-reserved-props
|
||||||
|
class: {
|
||||||
|
type: String,
|
||||||
|
default: 'w-24 h-24 p-2'
|
||||||
|
},
|
||||||
|
requestFrom: {
|
||||||
|
type: String,
|
||||||
|
default: 'Dashboard'
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
token:{
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
ext: {
|
||||||
|
type: Array,
|
||||||
|
default: () => ['jpg', 'jpeg', 'png', 'bmp', 'gif']
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 定义文件 v-model
|
||||||
|
const filesModel = defineModel({
|
||||||
|
type: Array<String>,
|
||||||
|
default: [],
|
||||||
|
required: true
|
||||||
|
})
|
||||||
|
const images = ref([])
|
||||||
|
const { upload, beforeUpload, handleExceed, handleSuccess, file } = uploadImage(props.action, props.ext)
|
||||||
|
const delImage = (key: number) => {
|
||||||
|
images.value = images.value.filter((item, index) => index !== key)
|
||||||
|
filesModel.value = images.value
|
||||||
|
}
|
||||||
|
// 更新 model 的 value
|
||||||
|
watch(
|
||||||
|
() => file.value,
|
||||||
|
(newValue, oldValue) => {
|
||||||
|
images.value.push(newValue)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(() => images.value, (newValue, oldValue) => {
|
||||||
|
filesModel.value = newValue
|
||||||
|
}, { deep: true, immediate: true })
|
||||||
|
</script>
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user