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.

180 lines
4.4 KiB

  1. ## mdp-table
  2. #### 简单使用
  3. 后端必须是该系统的后端项目
  4. ```vue
  5. <mdp-table :crud-apis="crudApis" :visible="true" :column-cfgs="columnConfigs" ></mdp-table>
  6. ```
  7. ```js
  8. data() {
  9. return {
  10. crudApis: {
  11. // list: params => {
  12. // return axios.get(``, {params});
  13. // }
  14. list: params => {
  15. config.params = params
  16. return axios.request(config)
  17. }
  18. },
  19. columnConfigs: [
  20. // {property: 【需要显示的数据,返回的单个数据的key】, label: 【表头】, isCommon: 【是否可查询】},
  21. {property: 'rolename', label: 'rolename', isCommon: true},
  22. {property: 'branchId', label: 'branchId', isCommon: true},
  23. {property: 'dataLvl', label: 'dataLvl', isCommon: true},
  24. // 可以根据需要添加其他列配置
  25. ]
  26. }
  27. ```
  28. config配置文件是 [体验环境](https://maimengcloud.com/lcode/m1/) 中的角色管理页的接口
  29. 返回的单个`数据格式`:
  30. ```json
  31. {
  32. "branchId": "",
  33. "roleend": null,
  34. "roleid": "",
  35. "rolename": "",
  36. "sortOrder": null,
  37. "crdate": null,
  38. "deptid": "",
  39. "remark": "",
  40. "roletype": "",
  41. "dataLvl": 5,
  42. "enabled": "",
  43. "rolebeg": null
  44. }
  45. ```
  46. ```js
  47. const axios = require('axios');
  48. let config = {
  49. method: 'get',
  50. maxBodyLength: Infinity,
  51. url: 'https://maimengcloud.com/api/m1/lcode/mdp/sys/role/list',
  52. headers: {
  53. .....
  54. },
  55. };
  56. export default config
  57. ```
  58. <img src="/Users/mengdanai/Library/Application Support/typora-user-images/image-20240113175843075.png" alt="image-20240113175843075" style="zoom:50%;" />
  59. <img src="/Users/mengdanai/Library/Application Support/typora-user-images/image-20240113175907878.png" alt="image-20240113175907878" style="zoom:50%;" />
  60. 模糊查询
  61. <img src="/Users/mengdanai/Library/Application Support/typora-user-images/image-20240113180009654.png" alt="image-20240113180009654" style="zoom:50%;" />
  62. 支持>、<、 >=、<=、!=、*陈*、$IS NULL、$IN 1,2,3、between 1,5等操作符
  63. -----
  64. #### 自定义
  65. 测试接口:https://reqres.in/api/users
  66. 接口首页: https://reqres.in
  67. 响应数据:
  68. ```json
  69. {
  70. "page":1,
  71. "per_page":6,
  72. "total":12,
  73. "total_pages":2,
  74. "data":[
  75. {
  76. "id":1,
  77. "email":"george.bluth@reqres.in",
  78. "first_name":"George",
  79. "last_name":"Bluth",
  80. "avatar":"https://reqres.in/img/faces/1-image.jpg"
  81. }
  82. ]
  83. ```
  84. Mdp-table:
  85. ```js
  86. preQueryParamCheck(params) {
  87. //处理参数以满足调用后台接口
  88. params.per_page = params.pageSize;
  89. params.page = params.pageNum;
  90. let arr = ['pageSize', 'pageNum', 'total', 'count'] // 需要删除内部实现的分页
  91. for (let item in params) {
  92. if (params[item] === undefined || params[item] === '' || arr.includes(item)) { // 判断查询条件是否存在
  93. delete params[item]
  94. }
  95. }
  96. if (!isNaN(params.id)) {
  97. params.id = parseInt(params.id, 10);
  98. } else {
  99. delete params.id
  100. }
  101. return true;
  102. },
  103. ```
  104. Mdp-table:
  105. ```js
  106. getResult(res, apiName) {
  107. // 请求结果处理
  108. let data = res.data
  109. if (res.status === 200) {
  110. this.pageInfo.total = data.total;
  111. this.pageInfo.pageNum = data.page;
  112. this.pageInfo.pageSize = data.per_page;
  113. let tableDatas = Array.isArray(data.data) ? data.data : new Array(data.data);
  114. this.tableDatas = tableDatas
  115. this.parseExpand(tableDatas, this.expandFieldName)
  116. this.afterList(tableDatas, res.status, apiName)
  117. } else {
  118. this.$notify({title: data.support.url, message: data.support.text, type: 'success',});
  119. }
  120. },
  121. ```
  122. 父组件:
  123. ```vue
  124. <mdp-table :crud-apis="crudApis" :visible="true" :column-cfgs="columnConfigs" :multiple="true"/>
  125. ```
  126. ```js
  127. data() {
  128. return {
  129. crudApis: {
  130. list: params => {
  131. return axios.get(`https://reqres.in/api/users`, {params});
  132. }
  133. },
  134. columnConfigs: [
  135. {property: 'avatar', label: '头像', isCommon: false},
  136. {property: 'email', label: '邮箱', isCommon: false},
  137. {property: 'first_name', label: '名字', isCommon: false},
  138. {property: 'last_name', label: '姓', isCommon: false},
  139. {property: 'id', label: 'Id', isCommon: true},
  140. // 可以根据需要添加其他列配置
  141. ]
  142. }
  143. }
  144. ```
  145. <img src="/Users/mengdanai/Library/Application Support/typora-user-images/image-20240113184113330.png" alt="image-20240113184113330" style="zoom:50%;" />