diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..69326fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,120 @@ +gitCommand.txt + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +ossConfig.js +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +dist/ +other/ +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +/node_modules +coverage +*.log +npm-debug.log +.logs +logs +*.swp +run +*-run +.idea +.DS_Store +.tmp +docs/CONTRIBUTING.md +docs/node_modules +docs/README.md +docs/db.json +docs/source/release/index.md +docs/source/member_guide.md +docs/source/_data/versions.yml +docs/**/contributing.md +docs/public +docs/plugins.png + +package-lock.json +yarn.lock +!test/fixtures/apps/loader-plugin/node_modules +.editorconfig +*clinic-flame* +*clinic-doctor* +.nyc_output/ +test/fixtures/apps/app-ts/**/*.js +!test/fixtures/apps/app-ts/node_modules +!test/fixtures/apps/app-ts/node_modules/**/*.js +test/fixtures/apps/app-ts-esm/**/*.js +test/fixtures/apps/app-ts-type-check/**/*.js diff --git "a/cool-admin \345\211\215\345\220\216\347\253\257\351\205\215\345\220\210\344\275\277\347\224\250.md" "b/cool-admin \345\211\215\345\220\216\347\253\257\351\205\215\345\220\210\344\275\277\347\224\250.md" new file mode 100644 index 0000000..0078fc5 --- /dev/null +++ "b/cool-admin \345\211\215\345\220\216\347\253\257\351\205\215\345\220\210\344\275\277\347\224\250.md" @@ -0,0 +1,376 @@ +# cool-admin 前后端配合使用 + +作者: gifted + +QQ: 203118908 + +视频: https://www.bilibili.com/video/BV1N7411w7dj?from=search&seid=11800671574855141738 + +(备注: 代码中某行高亮使用一对单个反引号) + +## 后端 + + + +1. 编写表信息, 文件路径`app\entity\app\bannertest.ts` + + 文件内容 + + ```typescript + import { Entity, Column } from 'typeorm'; + import { BaseEntity } from 'egg-cool-entity'; + + /** + * 数据模型描述 + */ + @Entity({ name: 'app_banner_test' }) + export default class AppBannerTest extends BaseEntity { + // 标题 + @Column({length:20}) + title: string; + // 链接 + @Column({length:20, nullable:true}) + link: string; + // 图片 + @Column({length:20}) + pics: string; + } + ``` + + + +2. 编写控制器, 文件路径`app\controller\admin\app\bannertest.ts` + + 文件内容: + + ```typescript + import { BaseController } from 'egg-cool-controller'; + import router from 'egg-cool-router'; + + /** + * 控制器功能描述 + */ + @router.prefix('/admin/app/bannertest', ['add', 'delete', 'update', 'info', 'list', 'page']) + export default class AppBannerTestController extends BaseController { + init() { + this.setEntity(this.ctx.repo.app.Bannertest); + } + } + ``` + + + +## 前端 + +1. 编写测试页面, 文件路径 `app\bannertest\bannertest.vue`, 代码片段`cl-curd` + +2. 在测试页面的`onLoad`方法中, 设置服务 + + ```typescript + methods: { + onLoad({ ctx, app }) { + this.crud = app; + + `ctx.service(this.$service.app.bannertest)` + + .set('upsert', { + items: [ + { + prop: '', + label: '', + component: { + name: '' + } + } + ] + }) + .set('table', { + columns: [ + { + label: '', + prop: '', + align: '' + } + ] + }) + .done(); + + app.refresh(); + } + } + ``` + +3. 编写服务, 文件路径: `src\service\app\bannertest.js` + + ```typescript + import { BaseService, Service, Permission } from '@/cool'; + + @Service('app/bannertest') + export default class extends BaseService {} + + ``` + +4. 在`http://localhost:9000/sys/menu`中添加测试菜单, + + 名称: `测试轮播` + + 节点路由: `/app/bannertest` + + 文件路径: `views/app/bannertest/bannertest.vue` + +5. 给该测试菜单添加权限, `app/bannertest` + + 增: `add` + + 删: `delete` + + 改: `update info` + + 查: `page info` + +6. 查看页面效果`http://localhost:9000/app/bannertest` + +7. 开始写组件, 主要是表单类组件: table和form, + + 饿了吗`elementUI`, 网址: `https://element.eleme.cn/#/zh-CN/component/installation` + +8. 添加列名后, 查看效果`http://localhost:9000/app/bannertest` + + ```typescript + .set('table', { + columns: [ + { + label: '图片', + prop: 'pics', + align: 'center' + }, + { + label: '标题', + prop: 'title', + align: 'center' + }, + { + label: '链接', + prop: 'link', + align: 'center' + } + ] + }) + ``` + +9. 添加按钮的表单组件 + + 表单中包含三个组件: 图片, 标题, 链接 + + ```typescript + ctx.service(this.$service.app.bannertest) + .set('upsert', { + items: [ + { + prop: 'pics', + label: '图片', + component: { + name: 'cl-upload' + } + }, + { + prop: 'title', + label: '标题', + component: { + name: 'el-input' + } + }, + { + prop: 'link', + label: '链接', + component: { + name: 'el-input' + } + } + ] + }) + ``` + + + +10. 图片列现在是文字, 改为使用插槽, 插槽中是cl自定义组件``, 该组件所在文件: `src\cool\components\viewer\index.vue` + + 然后点击刷新按钮, 是***浏览器的刷新按钮*** + + + + ```vue + + + + + + + ``` + +11. 图片太大了, 给图片设定高度 height + +```vue + +``` + +12. 图片缩放, 阿里云文档 + + ``` + https://help.aliyun.com/document_detail/44688.html?spm=a2c4g.11174283.6.1367.727d7da2H8ebDp + ``` + +13. 图片预览的时候是小图片, 点击后才是大图片 + + ```vue + + ``` + +14. 表单校验, 请关注字段 `rules` + + ```vue + .set('upsert', { + items: [ + { + prop: 'pics', + label: '图片', + component: { + name: 'cl-upload' + }, + rules: [{ required: true, message: '请上传图片', trigger: 'change' }] + }, + { + prop: 'title', + label: '标题', + component: { + name: 'el-input' + }, + rules: [ + { required: true, message: '请输入标题', trigger: 'blur' }, + { + min: 3, + max: 20, + message: '长度在 3 到 20 个字符', + trigger: 'blur' + } + ] + }, + { + prop: 'link', + label: '链接', + component: { + name: 'el-input' + }, + rules: [ + { + pattern: '[a-zA-Z]+://[^s]*', + message: '请输入正确的链接地址', + trigger: 'blur' + } + ] + } + ] + }) + ``` + + + +15. 设置关键词搜索, 这是个**后端**的内容 + + 文件路径: `app\controller\admin\app\bannertest.ts` + + ```typescript + import { BaseController } from 'egg-cool-controller'; + import router from 'egg-cool-router'; + + /** + * 控制器功能描述 + */ + @router.prefix('/admin/app/bannertest', ['add', 'delete', 'update', 'info', 'list', 'page']) + export default class AppBannerTestController extends BaseController { + init() { + this.setEntity(this.ctx.repo.app.Bannertest); + this.setPageOption({ + keyWordLikeFields:['title'] + }) + } + } + ``` + + diff --git "a/cool-admin \345\211\215\347\253\257crud\346\225\231\347\250\213.md" "b/cool-admin \345\211\215\347\253\257crud\346\225\231\347\250\213.md" new file mode 100644 index 0000000..b5015f7 --- /dev/null +++ "b/cool-admin \345\211\215\347\253\257crud\346\225\231\347\250\213.md" @@ -0,0 +1,1606 @@ +# cool-admin 前端crud教程 + +作者: gifted + +QQ: 203118908 + +## 正文 + +1. 创建一个vue测试页面 + + 文件路径: `src\views\test\curd-test.vue` + + 代码片段: `cl-crud` + + @load ({ ctx, app }): `ctx 配置参数、事件` `app 处理参数、事件` + +2. 进入后台 `http://localhost:9000/` , 在`系统/权限管理/菜单列表`, 添加我们的测试页面 + + 1. 节点名称: `前端crud测试` + 2. 节点路由: `/crud-test` + 3. 文件路径: `views/test/crud-test.vue` + 4. 保存 + +3. 打开`http://localhost:9000/crud-test`, 查看效果 + +4. 打开饿了么elementUI `https://element.eleme.cn/#/zh-CN/component/table` + +5. 设置几个字段, 此时`src\views\test\crud-test.vue`文件内容如下 + + ```vue + + + + + + + ``` + +6. 增加序号和多选框, 也就是`index`和`selection` + + ```vue + ctx.set('table', { + columns: [ + { + type: 'index', + width: '60' + }, + { + type: 'selection', + width: '60' + }, + { + prop: 'name', + label: '名字', + width: 200, + align: 'center' + }, + { + prop: 'date', + label: '日期', + align: 'left' + } + ] + }).done(); + ``` + +7. 数据操作, 主要由service控制, + + 添加一些测试数据, 并且加上`app.refresh();` + + 数据在`ctx.service page()`中 + + ```vue + + + + + + + ``` + +8. 使用服务service: + + `http://localhost:9000/crud-test` 中会显示系统用户 + + + + ```vue + + + + + + + ``` + +9. options, 在table后面加一个op字段 + + option默认显示`编辑` `删除` 两个选项 + + ```vue + + + + + + + ``` + +10. 编辑table的option字段, 比如只显示一个编辑选项 + + ``` + op: { visible: true, layout: ['edit'] } + ``` + +11. options使用插槽slot, 插槽在`