index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <!--
  2. @Modular:表格组件
  3. @Author: zouwf
  4. @Date: 2019-03-23
  5. -->
  6. <template>
  7. <dg-table
  8. border
  9. :auto-page="h => h * 0.6"
  10. :expand-row-keys="expands"
  11. overflow="tooltip"
  12. @change-current="handleChangeCurrent"
  13. @change-size="handleChangeSize"
  14. @selection-change="handleSelectionChange"
  15. @expand-change="handleExpandChange"
  16. @row-click="handleRowClick"
  17. @cell-click="handleCellClick"
  18. ref="grid"
  19. row-key="id"
  20. :url="url"
  21. :condition="condition"
  22. :pagination="pagination"
  23. :pagination-props="paginationProps"
  24. :mapping="mapping"
  25. stripe
  26. :lazyLoad="lazyLoad"
  27. highlight-current-row
  28. :before-search="_beforeSearch"
  29. :before-quest="beforeQuest"
  30. >
  31. <!--序号-->
  32. <dg-table-column type="index" width="70" label="序号" align="center" fixed="left" />
  33. <!--复选框情况-->
  34. <dg-table-column type="selection" width="55" v-if="selection" />
  35. <slot name="expand" />
  36. <template v-for="(item, indexs) in headerData">
  37. <dg-table-column :key="indexs" v-bind="item" align="center">
  38. <template slot-scope="scope">
  39. <slot v-if="item.custom" v-bind:row="scope.row" :name="item.prop"></slot>
  40. <span v-if="item.state">{{ converterText(scope.row, item) }}</span>
  41. <span v-if="item.timestamp">{{ formatTimestamp(scope.row, item) }}</span>
  42. <span v-if="item.adminAudit">{{ transformText(scope.row, item) }}</span>
  43. <span v-if="item.transOperateType">{{ transformOperateType(scope.row, item) }}</span>
  44. <!-- <span v-if="item.tranformBusiness">{{ tranformBusinessText(scope.row, item) }}</span> -->
  45. </template>
  46. </dg-table-column>
  47. </template>
  48. <!--操作栏-->
  49. <slot></slot>
  50. </dg-table>
  51. </template>
  52. <script>
  53. import moment from "moment";
  54. import * as dd from "@/api/dd";
  55. import * as roleAuthApi from "@/api/role-auth-info";
  56. export default {
  57. name: "Ltable",
  58. props: {
  59. lazyLoad: {
  60. type: Boolean,
  61. default: false
  62. },
  63. data: {
  64. type: Array,
  65. default: () => []
  66. },
  67. // 表头配置
  68. headerData: {
  69. type: Array,
  70. default: () => []
  71. },
  72. // 开启复选
  73. selection: {
  74. type: Boolean,
  75. default: false
  76. },
  77. // 开启复选
  78. url: {
  79. type: String,
  80. default: "",
  81. require: true
  82. },
  83. // 表格查询参数
  84. condition: {
  85. type: Object,
  86. default: () => {}
  87. },
  88. // 是否开启分页
  89. pagination: {
  90. type: Boolean,
  91. default: true
  92. },
  93. // 分页选项
  94. paginationProps: {
  95. type: Object,
  96. default: () => {
  97. return {
  98. currentPage: 1,
  99. pageSizes: [10, 20, 30],
  100. pageSize: 10,
  101. layout: "total, sizes, prev, pager, next, jumper"
  102. };
  103. }
  104. },
  105. // 最大高度
  106. maxheight: {
  107. type: [Number, String],
  108. default: ""
  109. },
  110. converter: Function,
  111. beforeSearch: {
  112. type: Function,
  113. default: conditions => conditions
  114. },
  115. tableName: {
  116. type: String,
  117. default: "表格"
  118. }
  119. },
  120. // 页面数据绑定
  121. data() {
  122. return {
  123. expands: [],
  124. mapping: {
  125. list: "content",
  126. total: "totalPages"
  127. }
  128. };
  129. },
  130. mounted() {},
  131. // 方法
  132. methods: {
  133. _beforeSearch(conditions) {
  134. conditions = this.beforeSearch(conditions);
  135. let tmpCond = JSON.parse(conditions.searchCondition);
  136. let result = [];
  137. tmpCond.map((item, i) => {
  138. if (item.op === "between") {
  139. if (item.value[0]) {
  140. // tmpCond.splice(i, 1);
  141. result.push({ ...item, op: ">=", value: item.value[0] });
  142. result.push({ ...item, op: "<=", value: item.value[1] });
  143. }
  144. } else {
  145. result.push(item);
  146. }
  147. });
  148. conditions.searchCondition = JSON.stringify(result);
  149. return conditions;
  150. },
  151. /**
  152. * 页码切换
  153. * @current 切换值
  154. * */
  155. handleChangeCurrent(current) {
  156. this.$emit("handleChangeCurrent", current);
  157. },
  158. /**
  159. * 页面切换
  160. * @current 切换值
  161. * */
  162. handleChangeSize(size) {
  163. this.$emit("handleChangeSize", size);
  164. },
  165. /**
  166. * 页码切换
  167. * @data 选中数据数组
  168. * */
  169. handleSelectionChange(data) {
  170. this.$emit("handleSelectionChange", data);
  171. },
  172. handleExpandChange(row, expanded) {
  173. const that = this;
  174. if (expanded.length) {
  175. that.expands = [];
  176. if (row) {
  177. that.expands.push(row.id);
  178. this.$emit("expand", row, expanded);
  179. }
  180. } else {
  181. that.expands = [];
  182. }
  183. },
  184. /**
  185. * 查询
  186. * */
  187. handleSearchClick() {
  188. this.$refs.grid.searchForm();
  189. },
  190. /**
  191. * 表格某行被点击
  192. * */
  193. handleRowClick(row, column, event) {
  194. this.$refs.grid.setCurrentRow(row);
  195. this.$emit("handleRowClick", { row, column });
  196. },
  197. // 某单元格被点击
  198. handleCellClick(row, column, cell, event) {
  199. this.$emit("handleCellClick", { row, column });
  200. },
  201. /**
  202. * 文案转换状态
  203. * */
  204. converterText(rowData, item) {
  205. const prop = item.prop || { label: "label", value: "value" };
  206. let resultItem = item.state.find(val => val["value"] == rowData[item.prop]);
  207. if (resultItem) {
  208. return resultItem["label"];
  209. } else {
  210. return moment(rowData[item.prop]).format("YYYY-MM-DD");
  211. }
  212. // return resultItem ? resultItem["label"] : rowData[item.prop];
  213. },
  214. /**
  215. * 时间戳转换
  216. * */
  217. formatTimestamp(rowData, item) {
  218. let str = "";
  219. const type = item.format || "YYYY-MM-DD";
  220. if (rowData[item.prop]) {
  221. return moment(parseInt(rowData[item.prop])).format(type);
  222. }
  223. },
  224. /**
  225. * 管理员表格 文案转换
  226. * */
  227. transformText(rowData, item) {
  228. const user = dd.adminAuditsLabel.user;
  229. const org = dd.adminAuditsLabel.org;
  230. const admin = dd.adminAuditsLabel.admin;
  231. let transformString = "";
  232. if (rowData.auditType == "user_audit") {
  233. for (let i = 0; i < user.length; i++) {
  234. if (rowData[item.prop] == user[i].value) {
  235. transformString = user[i].label;
  236. break;
  237. }
  238. }
  239. } else if (rowData.auditType == "org_audit") {
  240. transformString = org[0].label;
  241. } else {
  242. for (let i = 0; i < admin.length; i++) {
  243. if (rowData[item.prop] == admin[i].value) {
  244. transformString = admin[i].label;
  245. break;
  246. }
  247. }
  248. }
  249. return transformString;
  250. },
  251. /**
  252. * 管理员审计 文案转换
  253. * 操作内容
  254. * */
  255. transformOperateType(rowData, item) {
  256. let transformString = "";
  257. if (rowData.auditType == "user_audit") {
  258. if (rowData.operateType == "10") {
  259. transformString = "新增";
  260. } else if (rowData.operateType == "20") {
  261. transformString = "修改";
  262. } else if (rowData.operateType == "30") {
  263. transformString = "删除";
  264. } else if (rowData.operateType == "40") {
  265. transformString = "审批通过";
  266. } else if (rowData.operateType == "41") {
  267. transformString = "审批不通过";
  268. } else if (rowData.operateType == "50") {
  269. transformString = "启用";
  270. } else if (rowData.operateType == "51") {
  271. transformString = "停用";
  272. } else if (rowData.operateType == "61") {
  273. transformString = "入职";
  274. } else if (rowData.objectType == "62") {
  275. transformString = "离职";
  276. } else {
  277. transformString = "";
  278. }
  279. }
  280. if (rowData.auditType == "org_audit") {
  281. if (rowData.operateType == "10") {
  282. transformString = "新增机构";
  283. } else if (rowData.operateType == "20") {
  284. transformString = "修改机构";
  285. } else if (rowData.operateType == "30") {
  286. transformString = "删除机构";
  287. } else if (rowData.operateType == "40") {
  288. transformString = "调离机构";
  289. } else if (rowData.operateType == "50") {
  290. transformString = "合并机构";
  291. } else {
  292. transformString = "";
  293. }
  294. } else {
  295. if (rowData.operateType == "10") {
  296. transformString = "管理员创建";
  297. } else if (rowData.operateType == "11") {
  298. transformString = "管理员删除";
  299. } else if (rowData.operateType == "20") {
  300. transformString = "平台菜单权限新增";
  301. } else if (rowData.operateType == "21") {
  302. transformString = "平台菜单权限移除";
  303. } else if (rowData.operateType == "30") {
  304. transformString = "机构管理范围新增";
  305. } else if (rowData.operateType == "31") {
  306. transformString = "机构管理范围变更";
  307. } else if (rowData.operateType == "40") {
  308. transformString = "用户管理范围新增";
  309. } else if (rowData.operateType == "41") {
  310. transformString = "用户管理范围变更";
  311. } else if (rowData.objectType == "50") {
  312. transformString = "授权管理范围新增";
  313. } else if (rowData.objectType == "51") {
  314. transformString = "授权管理范围变更";
  315. } else if (rowData.objectType == "60") {
  316. transformString = "管理员管理范围新增";
  317. } else if (rowData.objectType == "61") {
  318. transformString = "管理员管理范围变更";
  319. } else {
  320. transformString = "";
  321. }
  322. }
  323. return transformString;
  324. },
  325. /**
  326. * 转换业务域
  327. * */
  328. tranformBusinessText(row, item) {},
  329. /*
  330. * 切换勾选状态
  331. * */
  332. toggleRowSelection(row, bool = false) {
  333. return this.$refs.grid.toggleRowSelection(row, bool);
  334. },
  335. getReqSearchCondition() {
  336. return this.$refs.grid.getReqSearchCondition();
  337. },
  338. beforeQuest(res) {
  339. const { content, totalElements } = res.data;
  340. const result = {
  341. data: {
  342. content,
  343. totalElements
  344. }
  345. };
  346. this.$emit("getTotalElements", { totalElements, tableName: this.tableName });
  347. return result;
  348. }
  349. },
  350. created() {}
  351. };
  352. </script>
  353. <style scoped lang="scss">
  354. .el-table__body tr.current-row > td {
  355.   background-color: #f5f7fa !important;
  356. }
  357. </style>