You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
6.4 KiB

3 years ago
  1. # cool-admin [vue2]
  2. <p align="center">
  3. <a href="https://show.cool-admin.com/" target="blank"><img src="https://admin.cool-js.com/logo.png" width="200" alt="cool-admin Logo" /></a>
  4. </p>
  5. <p align="center">cool-admin 一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发 CRUD,方便快速构建迭代后台管理系统, 到论坛 进一步了解</p>
  6. <p align="center">
  7. <a href="https://github.com/cool-team-official/cool-admin-vue/blob/master/LICENSE" target="_blank"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="GitHub license" />
  8. <a href=""><img src="https://img.shields.io/github/package-json/v/cool-team-official/cool-admin-vue?style=flat-square" alt="GitHub tag"></a>
  9. <img src="https://img.shields.io/github/last-commit/cool-team-official/cool-admin-vue?style=flat-square" alt="GitHub tag"></a>
  10. </p>
  11. ## 地址
  12. - [⚡️ vue2.x + element-ui](https://github.com/cool-team-official/cool-admin-vue)
  13. - [⚡️ vue3.x + element-plus + ts + webpack](https://github.com/cool-team-official/cool-admin-vue/tree/vue3-ts-webpack)
  14. - [📌 vue3.x + element-plus + ts + vite](https://github.com/cool-team-official/cool-admin-vue/tree/vue3-ts-vite)
  15. - [🌐 码云仓库地址](https://gitee.com/cool-team-official/cool-admin-vue)
  16. ## 演示
  17. [https://show.cool-admin.com](https://show.cool-admin.com)
  18. 账户:admin,密码:123456
  19. <img src="https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/home-mini.png" alt="Admin Home" ></a>
  20. ## 项目后端
  21. [https://github.com/cool-team-official/cool-admin-midway](https://github.com/cool-team-official/cool-admin-midway)
  22. ## 微信群
  23. <img width="260" src="https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/wechat.jpeg" alt="Admin Wechat"></a>
  24. ## 微信公众号
  25. <img width="260" src="https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/mp.jpg" alt="Admin Wechat"></a>
  26. ## 在线社区
  27. [https://bbs.cool-js.com/](https://bbs.cool-js.com/)
  28. ## 使用条件
  29. 请确保您的操作系统上安装了 Node.js(> = 8.9.0)、@vue/cli (> 3.0.0)。
  30. ## 安装项目依赖
  31. 推荐使用 `yarn`
  32. ```shell
  33. yarn
  34. ```
  35. 解决 `node-sass` 网络慢的方法:
  36. ```shell
  37. yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
  38. ```
  39. ## 运行应用程序
  40. 安装过程完成后,运行以下命令启动服务。您可以在浏览器中预览网站 [http://localhost:9000](http://localhost:9000)
  41. ```shell
  42. yarn serve
  43. ```
  44. ## 极速 CRUD
  45. 1. `vscode` 编辑器下输入关键字 `cl-crud`,会生成对应的模板代码:
  46. ```html
  47. <template>
  48. <cl-crud ref="crud" @load="onLoad">
  49. <el-row type="flex" align="middle">
  50. <!-- 刷新按钮 -->
  51. <cl-refresh-btn />
  52. <!-- 新增按钮 -->
  53. <cl-add-btn />
  54. <!-- 删除按钮 -->
  55. <cl-multi-delete-btn />
  56. <cl-flex1 />
  57. <!-- 关键字搜索 -->
  58. <cl-search-key />
  59. </el-row>
  60. <el-row>
  61. <!-- 数据表格 -->
  62. <cl-table v-bind="table"></cl-table>
  63. </el-row>
  64. <el-row type="flex">
  65. <cl-flex1 />
  66. <!-- 分页控件 -->
  67. <cl-pagination />
  68. </el-row>
  69. <!-- 新增、编辑 -->
  70. <cl-upsert ref="upsert" v-bind="upsert"></cl-upsert>
  71. </cl-crud>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. // 新增、编辑配置
  78. upsert: {
  79. items: []
  80. },
  81. // 表格配置
  82. table: {
  83. columns: []
  84. }
  85. };
  86. },
  87. methods: {
  88. onLoad({ ctx, app }) {
  89. // crud 配置
  90. ctx.service().done();
  91. // 发送 page 接口请求
  92. app.refresh();
  93. }
  94. }
  95. };
  96. </script>
  97. ```
  98. 2. 编辑数据表格 `cl-table`
  99. ```js
  100. {
  101. table: {
  102. // 参数与 el-table-column 一致,并支持许多骚操作
  103. columns: [
  104. // 多选列
  105. {
  106. type: "selection",
  107. width: 60
  108. },
  109. // 自定义列
  110. {
  111. label: "昵称",
  112. prop: "name"
  113. },
  114. {
  115. label: "账户",
  116. prop: "price",
  117. sortable: "custom" // 是否添加排序
  118. },
  119. {
  120. label: "状态",
  121. prop: "status",
  122. // 字典匹配,使用 el-tag 展示
  123. dict: [
  124. {
  125. label: "启用",
  126. value: 1,
  127. type: "primary"
  128. },
  129. {
  130. label: "禁用",
  131. value: 0,
  132. type: "danger"
  133. }
  134. ]
  135. },
  136. {
  137. label: "创建时间",
  138. prop: "createTime"
  139. },
  140. // 操作按钮列,默认包含:编辑、删除
  141. {
  142. type: "op"
  143. }
  144. ];
  145. }
  146. }
  147. ```
  148. 3. 编辑新增、编辑表单 `cl-upsert`
  149. ```js
  150. {
  151. upsert: {
  152. items: [
  153. {
  154. label: "昵称",
  155. prop: "name",
  156. // 参数与 el-form-item 一致
  157. props: {},
  158. value: "神仙都没用", // 昵称默认值
  159. // 渲染参数,支持 slot, 组件实例,jsx
  160. component: {
  161. name: "el-input", // 可以是任意已注册的组件名
  162. props: {}, // 组件的参数
  163. on: {} // 组件的回调事件
  164. },
  165. // 验证规则,与 el-form 一致
  166. rules: {
  167. required: true,
  168. message: "昵称不呢为空"
  169. }
  170. },
  171. {
  172. label: "存款",
  173. prop: "price",
  174. component: {
  175. name: "el-input-number",
  176. props: {
  177. min: 0,
  178. max: 10000
  179. }
  180. }
  181. },
  182. {
  183. label: "状态",
  184. prop: "status",
  185. value: 1,
  186. component: {
  187. name: "el-radio-group",
  188. options: [
  189. {
  190. label: "启用",
  191. value: 1
  192. },
  193. {
  194. label: "禁用",
  195. value: 0
  196. }
  197. ]
  198. }
  199. }
  200. ];
  201. }
  202. }
  203. ```
  204. 4. 绑定 `service`。在 `src/service/` 下新建文件 `test.js`,并编辑:
  205. ```js
  206. // src/service/test.js
  207. import { BaseService, Service, Permission } from "cl-admin";
  208. // 请求接口的路径
  209. @Service("test")
  210. class Test extends BaseService {
  211. // 继承 BaseService 后,拥有 page, list, add, delete, update, info 6个基本接口
  212. // 自定义其他接口
  213. @Permission("product") // 权限装饰器,可选
  214. product(id) {
  215. // this.request() 参数与 axios 一致
  216. return this.request({
  217. url: "/product",
  218. method: "POST",
  219. data: {
  220. id
  221. }
  222. });
  223. }
  224. }
  225. export default Test;
  226. ```
  227. `src/service/` 下的文件,框架会自动根据 `目录结构``文件名称` 格式化成对应的 `$service` 对象。你现在可以这么使用它:
  228. ```js
  229. this.$service.test.page({ page: 1 });
  230. this.$service.test.product(1);
  231. ```
  232. `service` 编写好后,我们把它绑定在 `crud` 上:
  233. ```js
  234. export default {
  235. methods: {
  236. onLoad({ ctx, app }) {
  237. // 绑定 service,这边指定到 test 即可
  238. ctx.service(this.$service.test).done();
  239. // 发起 page 请求
  240. app.refresh({
  241. // 请求默认参数
  242. });
  243. }
  244. }
  245. };
  246. ```
  247. 5. 效果预览
  248. ![](https://cool-show.oss-cn-shanghai.aliyuncs.com/admin/crud.png)