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.

435 lines
18 KiB

3 years ago
  1. ### 关于ivzone(交流群:616124620)
  2. 1. 首先此框架基于vite2+vue3+antdv2+vuex4+vuerouter4等最新技术
  3. 2. 大部分业务功能使用指令驱动减少80%的代码量, 比如新增功能只需一行代码
  4. `<FuncBtn func="add">新增</FuncBtn>`
  5. 3. 然后在此基础上又实现了一套后台管理常用功能(用户,角色,菜单,字典,机构,配置等)的实现
  6. 5. [项目预览地址](http://iot.iteaj.com/#/login) 以及配套的 [java后端项目](https://gitee.com/iteaj/iboot)
  7. #### 仓库目录说明
  8. | 目录 | 说明 | 典型 |
  9. |---|---|---|
  10. | src/components/basic | 常用的基础组件 | 暂无 |
  11. | src/components/directive | vue指令 | 权限控制指令 |
  12. | src/components/drawer | 可编辑的基础抽屉组件 | 暂无 |
  13. | src/components/modal | 可编辑的基础模态框组件 | 暂无 |
  14. | src/components/edit | 可编辑视图组件 | 编辑模态框和编辑抽屉视图组件 |
  15. | src/components/form | antdv表单组件封装 | 包含antdv2包含的可编辑组件 |
  16. | src/components/functional | vue functional组件 | 暂无 |
  17. | src/components/list | 列表视图组件 | 暂无 |
  18. | src/components/view | 页面视图相关组件 | UView |
  19. | src/event | 全局事件 | |
  20. | src/router | 路由信息 | |
  21. | src/store | vuex信息 | |
  22. | src/theme | 主题 | |
  23. | src/utils | 基础工具库 | |
  24. | src/views | 自定义的功能视图页 | 后台管理(用户、字典、角色、配置、组织等)视图 |
  25. #### 简洁的写法
  26. ```
  27. <template>
  28. <UView> // 基础视图页面
  29. <UViewSearch> // 基础搜索组件
  30. <UInputItem field="name" label="茶叶名称"/>
  31. <template #func>
  32. <UFuncBtn func='view' url='/product/list'>查询</UFuncBtn>&nbsp;
  33. <UFuncBtn func="add" url='/product/add'>新增</UFuncBtn>
  34. </template>
  35. </USearch> // 基础表组件
  36. <UViewTable :bordered="true" :columns="columns" :dataSource="dataSource" rowKey="id">
  37. <template #c_action="{record}">
  38. <UFuncTag func='edit' url='/product/edit'>修改</UFuncTag>
  39. <UFuncTag func="del" url='/product/del'>删除</UFuncTag>
  40. </template>
  41. </UTable>
  42. <UViewModal>// 基础模态框编辑组件
  43. <UInputItem field="name" label="茶叶名称"/>
  44. <template #title="{model}">
  45. {{model.id ? '编辑产品' : '新增产品'}}
  46. </template>
  47. <template #footer>
  48. <UFuncBtn func='cancel'>取消</UFuncBtn>
  49. <UFuncBtn func='submit' url='/product/add'>提交</UFuncBtn>
  50. <UFuncBtn func='reset'>重置</UFuncBtn>
  51. </template>
  52. </UFormModal>
  53. </UView>
  54. </template>
  55. <script>
  56. export default {
  57. name: "Demo",
  58. setup() {
  59. let columns = [
  60. {field: 'name', title: '产品名称'},
  61. {field: 'type', title: '产品类型'},
  62. {field: 'action', type:'action', title: '操作'},
  63. ]
  64. let dataSource = [
  65. {id: 1, name: '清香秋茶', type: '清香型'}
  66. ]
  67. return {columns, dataSource}
  68. }
  69. }
  70. </script>
  71. ```
  72. #### **核心思想**
  73. ##### 约定大于配置
  74. 1. 约定一个功能页面包含大于0 的增删改查组件,并将组件划分和关联
  75. 2. 约定每个页面可能包含 增、删、改、查、导入、导出、删除、重置、取消、展开、提交的某几个功能
  76. 3. 约定通用功能的实现逻辑具有通用性(比如提交表单的逻辑是先校验表单然后提交到后台,如果提交失败提示失败信息,如果成功关闭编辑框并且刷新列表)
  77. 4. 约定某些组件的层级关系, 比如组件UTable必须作为UView的子组件, 且UView必须做顶级组件
  78. ##### 灵活(只做增强不做限制)
  79. 1. api灵活:除了使用默认已经实现的api外,所有的功能都可以按照往常的方式开发
  80. 2. 布局灵活:可以对组件实现任意布局, 不会因为通用功能的存在而丧失布局的灵活性
  81. ### 核心功能
  82. 1. 是一套简易美观的基础功能框架(基于antd2的ui组件库),基本可以开箱即用
  83. 2. 提供一套增删改查组件,做了简单封装,使用简单灵活,代码量降低30%+
  84. 3. 支持动态路由即从后端生成路由信息,支持从菜单信息中动态生成功能点(增删改查,导入、导出以及其他自定义功能等)
  85. 4. 封装antd中table组件的不友好使用方式,可以自定义列的slot
  86. 5. 增强ATable组件功能,新增dict和url字段,使得table列可以将值转换成对应的标签(label)比如:使用字典和url
  87. 6. 增强options(select,checkbox,autocomplete,tree,radio)等组件,支持使用字典和url动态生成
  88. 7. 增强form表单功能, 支持自动根据字段动态生成model数据,支持路径嵌套(a.b)
  89. 8. 支持对第三方库独立打包,降低每次应用更新时浏览器缓存失效问题
  90. 9. 提供基于antd2ui库封装的其他业务组件库
  91. 10. 使用Mock对所有视图组件进行数据模拟
  92. 11. 不依赖于后台框架的使用语言(java, php, c#等), 友好的声明api接口和字段,可以方便的对接任何后台
  93. ### 组件使用教程
  94. #### 功能组件
  95. 1. 功能组件主要是用来拓展和简化功能的操作方式, 使用功能组件将提供一套默认的操作功能
  96. 2. 提供的功能包括[add, del, edit, query, import, export, reset, cancel, submit, expand]以及混合联动操作
  97. ##### UFuncBtn
  98. 功能按钮:用在搜索组件和编辑组件
  99. ```
  100. <UView>
  101. <UViewSearch>
  102. <template #func={model}>
  103. <UFuncBtn func='add'>新增</UFuncBtn> // 点击默认动作:将打开一个编辑框(UViewModal or UViewDrawer)
  104. <UFuncBtn func='query' url="/project/query">搜索</UFuncBtn> // 点击默认动作:重新刷新列表
  105. <UFuncBtn func='reset'>重置</UFuncBtn> // 点击默认动作:重置搜索表单, 并且重新刷新列表(和表格组件联动)
  106. </template>
  107. </UViewSearch>
  108. <UViewModal>
  109. <template #footer={model}>
  110. <UFuncBtn func='cancel'>取消</UFuncBtn> // 点击默认动作:关闭当前编辑框, 关闭提交动画关闭提交按钮动作
  111. // 点击默认动作:校验表单是否通过, 然后提交表单, 开启表单的提交动画, 开启提交按钮的提交动画(防止多次提交)
  112. <UFuncBtn func='submit' :url="model.id ? '/project/edit':'/project/add'">提交</UFuncBtn>
  113. <UFuncBtn func='reset'>重置</UFuncBtn> // 点击默认动作:重置编辑表单
  114. </tempalte>
  115. </UViewSearch>
  116. </UView>
  117. ```
  118. ##### UFuncTag
  119. 功能tag:用于表格操作
  120. ```
  121. <UView rowKey="id">
  122. <UViewTable>
  123. <template #c_action={record}>
  124. // 点击默认动作:打开编辑框, 并获取和渲染url对应的数据
  125. <UFuncBtn func='edit' :data="record" url="/project/edit">编辑</UFuncBtn>
  126. // 点击默认动作:弹出删除确认框, 确定之后调用url对应的接口删除数据, 提交的参数是数组格式:[record[rowKey]]
  127. <UFuncBtn func='del' :data="record" url="/project/del">删除</UFuncBtn>
  128. </template>
  129. </UViewSearch>
  130. </UView>
  131. ```
  132. ##### 误操作确认
  133. 有时候为了防止某些功能的误操作,将会在点击功能的时候弹框确认, 这时候可以使用:confirm属性
  134. ```
  135. <UFuncBtn func='demo' :data="record" url="/project/demo" confirm>容易误操作</UFuncBtn>
  136. ```
  137. ##### 与编辑框联动
  138. 主要用于点击功能按钮时弹出对应的编辑框
  139. 1. 打开其他的编辑框
  140. ```
  141. <UView rowKey="id">
  142. <UViewTable>
  143. <template #c_action={record}>
  144. // 默认动作:打开id="modPwd"的编辑框, 并且设置编辑框: model[rowKey]=record[rowKey]
  145. <UFuncBtn func='edit:modPwd' :data="record">修改密码</UFuncBtn>
  146. </template>
  147. </UViewSearch>
  148. // 修改密码编辑框
  149. <UFormModal id="modPwd" :rules="[自定义校验规则]">
  150. <IvzPassword label="密码" field="password" />
  151. <template #footer={model}>
  152. <UFuncBtn func='cancel'>取消</UFuncBtn> // 点击默认动作:关闭当前编辑框, 关闭提交动画关闭提交按钮动作
  153. // 默认动作:校验表单, 然后提交表单, 开启表单的提交动画, 开启提交按钮的提交动画(防止多次提交)
  154. <UFuncBtn func='submit' :url="model.id ? '/project/edit':'/project/add'">提交</UFuncBtn>
  155. <UFuncBtn func='reset'>重置</UFuncBtn> // 点击默认动作:重置编辑表单
  156. </tempalte>
  157. </USearch>
  158. </UView>
  159. ```
  160. 2. 新增子记录(树形结构格式)
  161. ```
  162. <UView rowKey="id">
  163. <UViewTable>
  164. <template #c_action={record}>
  165. // 打开新增的编辑框, 并且设置编辑框父id: model[pid]=record[rowKey]
  166. <UFuncBtn func='add:child' :data="record">新增子菜单</UFuncBtn>
  167. </template>
  168. </UViewSearch>
  169. </UView>
  170. ```
  171. #### 功能权限
  172. 功能权限主要是用来控制页面是否需要显示对应的功能
  173. ##### v-auth指令
  174. // 后台使用shiro做权限校验
  175. ```
  176. // 基础用法
  177. // 存在权限字符串就显示
  178. <AButton v-auth="'core:project:add'">新增</ABtton>
  179. // 高级用法
  180. // and参数, 必须满足数组里面的两个权限
  181. <AButton v-auth:and="['core:project:view', 'core:project:info']">详情</ABtton>
  182. // or参数, 只需满足数组里面的两个权限的任何一个
  183. <AButton v-auth:or="['core:project:view', 'core:project:info']">详情</ABtton>
  184. // and的简写
  185. <AButton v-auth="['core:project:view', 'core:project:info']">详情</ABtton>
  186. ```
  187. ##### 使用url做权限判断
  188. url的控制方式是通过后台是否有返回功能组件[UFuncBtn or UFuncTag]对应的url
  189. ```
  190. // 使用auth属性控制权限校验的开关
  191. // 比如回台返回的功能菜单包括 新增(/project/add)、编辑(/project/edit)、搜索(/project/query)
  192. <UView auth>
  193. <UViewSearch>
  194. <template #func>
  195. <UFuncBtn func='add' url='/project/add'>新增</UFuncBtn> // 显示
  196. <UFuncBtn func='import' url='/project/import'>导入</UFuncBtn> // 不显示
  197. </template>
  198. </UViewSearch>
  199. <UViewTable>
  200. <template #c_action={record}>
  201. <UFuncTag func='edit' url='/project/edit' :data="record">修改</UFuncTag > // 显示
  202. <UFuncTag func='del' url='/project/del' :data="record">删除</UFuncTag > // 不显示
  203. </template>
  204. </UViewSearch>
  205. </UView>
  206. ```
  207. ##### 编辑详情url
  208. ```
  209. // 此处的url是获取编辑详情数据的url,但是并没有指定参数,也无需指定参数
  210. <UFuncTag func='edit' url='/project/edit' :data="record">修改</UFuncTag >
  211. // 默认获取编辑地址url的方法如下:Context.js
  212. this.getEditUrl = function (model, editContext) {
  213. let rowKey = this.getRowKey();
  214. let editFunc = this.getTableFunc(FuncNameMeta.EDIT);
  215. if(editFunc && model) {
  216. return `${editFunc.getUrl()}?${rowKey}=${model[rowKey]}`;
  217. } else {
  218. console.warn('未指定编辑功能获取详情数据地址')
  219. return null;
  220. }
  221. }
  222. // 如果以上方法不能满足你获取url,可以在mount钩子里面覆盖掉此方法,重写
  223. ```
  224. #### 视图组件
  225. 视图组件是用来组织视图子组件的容器且必须作为.vue页面的顶级组件。再此容器内支持对所有的可联动的视图子组件做联动操作:比如点击搜索组件的查询按钮表格组件将发起查询接口获
  226. ##### UView
  227. ```
  228. <template>
  229. <UView>
  230. ...
  231. </UView>
  232. </template>
  233. <script>...</script>
  234. ```
  235. **使用url作为权限控制**
  236. ```
  237. <UView auth>...</UView>
  238. ```
  239. **指定功能的唯一键**
  240. ```
  241. <UView rowKey="id">...</UView>
  242. // 此属性将用来做表格、编辑与新增、新增子记录的判断
  243. ```
  244. #### 视图子组件
  245. 1. 以下的所有组件都只能用在页级组件(UView、IvzMenuView)的子组件,组成一个完整的功能页面
  246. 2. UViewModal、IvzVieDrawer、UViewTable视图组件只做功能增加,可以使用原生组件的任何属性, 少数不能用的属性会做说明
  247. ##### UViewSearch
  248. 1. 支持[AForm](https://2x.antdv.com/components/form-cn)的所有属性
  249. 2. 属于页面可联动的搜索组件
  250. ##### UViewModal
  251. 1. 支持[AForm组件](https://2x.antdv.com/components/form-cn)的所有属性
  252. 2. 支持[AModal组件](https://2x.antdv.com/components/modal-cn)的所有属性
  253. 3. 新增属性[span] 作为AForm组件的labelCol和wrapperCol的简写, 格式 [6, 18]
  254. 4. 属于页面可联动的编辑组件
  255. ##### UViewDrawer
  256. 1. 支持[AForm](https://2x.antdv.com/components/form-cn)的所有属性
  257. 2. 支持[ADrawerl](https://2x.antdv.com/components/drawer-cn)的所有属性
  258. 3. 新增属性[span] 作为AForm组件的labelCol和wrapperCol的简写, 格式 [6, 18]
  259. 4. 属于页面可联动编辑组件
  260. ##### UViewTable
  261. 1. 支持[ATable](https://2x.antdv.com/components/table-cn)的所有属性
  262. ##### UFormModal
  263. 1. 支持[AForm组件](https://2x.antdv.com/components/form-cn)的所有属性
  264. 2. 支持[AModal组件](https://2x.antdv.com/components/modal-cn)的所有属性
  265. 3. 新增属性[primary] 用来声明此组件是可联动的组件
  266. ##### UFormDrawer
  267. 1. 支持[AForm](https://2x.antdv.com/components/form-cn)的所有属性
  268. 2. 支持[ADrawerl](https://2x.antdv.com/components/drawer-cn)的所有属性
  269. 3. 新增属性[primary] 用来声明此组件是可联动的组件
  270. ### antd2组件扩展
  271. ##### <a href="https://2x.antdv.com/components/table-cn#API" target="_blank">增强ATable组件</a>
  272. antd的表格组件说实话如果没有去认证研究和实践真的很难看得懂,而且很多功能都要自己实现,比如单击和双击、表格和多选等等, 没有一定的使用经验确实会感觉难用,所以提供了IvzBaiscTable表格增强组件。UTable组件支持ATable组件的大部分属性,下面主要看一下不支持的属性和增强的功能
  273. ##### 1.不支持的属性
  274. 1. rowSelection 此属性是ATable用来描述表格多选框的一个对象,在UTable组件里面此对象直接放到columns属性里面,像这样:
  275. ```
  276. const columns = [
  277. // 支持rowSelection里面的多数属性
  278. // type不支持 默认:checkbox,不支持radio
  279. {type: 'selection', title: '多选'},
  280. {field: 'name', title: '菜单名称', align: 'left'}
  281. ]
  282. // onChange、onSelect、onSelectAll、onSelectInvert方法将直接支持在UTable组件上使用事件
  283. <UTable ref="tableRef" @selectChange="xx" @select="xx" @selectAll="xx" @selectInvert="xx"></UTable>
  284. // selectedRowKeys 不支持, 通过方法提供
  285. this.$refs['tableRef'].getSelectedRowKeys();
  286. ```
  287. 2. 其他的属性全部支持
  288. ##### 自定义列slot
  289. ```
  290. // columns列不支持customRender, 通过slot方式提供
  291. // 展示通过slot实现自定义此列
  292. const columns = [
  293. {field: 'name', title: '菜单名称', align: 'left'},
  294. {field: 'user.name', title: '用户名称', align: 'left'}
  295. ]
  296. // 插槽名称规则:前缀 c_ + 字段名 = c_name
  297. // 如果是a.b的格式将'.'换成'_'即:c_a_b
  298. <UTable rowKey="id">
  299. <template #c_name="{record}">
  300. <a>{{record.name}}</a>
  301. </template>
  302. <template #c_user_name="{record}">
  303. <a>{{record.user.name}}</a>
  304. </template>
  305. </UTable>
  306. ```
  307. ##### 字典和url
  308. 支持将value转成label 比如性别字段:数据库存的是值:man,表格需要展示:男
  309. ```
  310. // 通过本地变量sex
  311. const sex = [
  312. {label: '男', value: 'man'},{label: '女', value: 'woman'}
  313. ]
  314. const columns = [
  315. {field: 'sex', title: '性别', options: sex}
  316. ]
  317. // 通过字典, 提供的字典类型sex,必须可以返回options格式相同的数组
  318. const columns = [
  319. {field: 'sex', title: '性别', dict: 'sex'}
  320. ]
  321. // 通过url, 提供的url必须可以返回options格式相同的数组
  322. const columns = [
  323. {field: 'sex', title: '性别', url: '/core/getSex'}
  324. ]
  325. ```
  326. ##### 4.日期格式化
  327. 如果是日期列,会默认将日期进行安装指定的格式进行格式化,可以用默认格式也可以自定义格式
  328. ```
  329. // 通过指定type='date'
  330. const columns = [
  331. {field: 'createTime', title: '创建时间', type: 'date'}
  332. ]
  333. // 默认格式 {datetime: 'YYYY-MM-DD HH:mm:ss', date: 'YYYY-MM-DD', month: 'MM', week: 'E', time: 'HH:mm:ss'}
  334. // 通过picker指定具体类型,不指定则默认使用datetime格式
  335. const columns = [
  336. {field: 'createTime', title: '创建时间', type: 'date', picker: 'month'}
  337. ]
  338. ```
  339. ##### 5.操作列
  340. UTable组件支持使用两种方式定义操作列
  341. 第一 使用功能点列表
  342. ```
  343. // 使用type="action"声明此列是操作列
  344. const columns = [
  345. {field: 'action', title: '操作', type: 'action', funMetas: [
  346. {field:'Edit', '编辑',props: {onClick: (row) => {}}}, {field:'Del', '删除', props: {onClick: (row) => {}}}
  347. ]
  348. }
  349. ]
  350. ```
  351. 第二 使用自定义slot
  352. ```
  353. // template
  354. <template #c_action={record, column}>
  355. <a-button>编辑</a-button>
  356. <a-button>修改</a-button>
  357. </template>
  358. // js
  359. const columns = [
  360. {field: 'action', title: '操作', type: 'action'}
  361. ]
  362. ```
  363. ##### 6.数据格式化
  364. 除了上面的自定义slot,日期格式化,字典url,UTable组件还支持自定义格式化数据
  365. ```
  366. const columns = [
  367. {field: 'createTime', title: '创建时间', formatter: ({value,record,column}) => value}
  368. ]
  369. ```
  370. ### 安装教程
  371. 1. [安装node](https://nodejs.org/zh-cn/) >= 12.0.0。
  372. 2. clone项目或者使用ide直接导入
  373. ```
  374. git clone https://gitee.com/iteaj/ivzone.git
  375. ```
  376. 3. 安装package.json依赖
  377. ```
  378. // 进入项目目录然后执行命令
  379. npm install
  380. // 如果嫌国内速度慢可以切换到淘宝源
  381. npm install -g cnpm --registry=https://registry.npmmirror.com
  382. cnpm install
  383. ```
  384. 4. 开发环境运行
  385. ```
  386. vite dev
  387. ```
  388. 5. 正式环境打包
  389. ```
  390. vite build
  391. ```
  392. ### 使用说明
  393. 1. [请先下载并配置运行后端](https://gitee.com/iteaj/izone-sboot)
  394. 2. 配置后端代理地址
  395. ```
  396. // 修改文件 vite.config.js
  397. server: {
  398. proxy: {
  399. '^/api/.*': {
  400. changeOrigin: true,
  401. target: 'http://127.0.0.1:8085', // 后端地址
  402. rewrite: (path) => path.replace(/^\/api/, '')
  403. },
  404. }
  405. }
  406. // 也可以使用线上地址
  407. server: {
  408. proxy: {
  409. '^/api/.*': {
  410. changeOrigin: true,
  411. target: 'http://demo.iteaj.com', // 后端地址
  412. },
  413. }
  414. }
  415. ```
  416. 2.
  417. [vite2使用教程](https://cn.vitejs.dev/)
  418. 1. 如果使用过程有问题欢迎pr和提交bug
  419. 2. 交流群:97235681