123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <!--
- @Modular:表格组件
- @Author: zouwf
- @Date: 2019-03-23
- -->
- <template>
- <dg-table
- border
- :auto-page="h => h * 0.6"
- :expand-row-keys="expands"
- overflow="tooltip"
- @change-current="handleChangeCurrent"
- @change-size="handleChangeSize"
- @selection-change="handleSelectionChange"
- @expand-change="handleExpandChange"
- @row-click="handleRowClick"
- @cell-click="handleCellClick"
- ref="grid"
- row-key="id"
- :url="url"
- :condition="condition"
- :pagination="pagination"
- :pagination-props="paginationProps"
- :mapping="mapping"
- stripe
- :lazyLoad="lazyLoad"
- highlight-current-row
- :before-search="_beforeSearch"
- :before-quest="beforeQuest"
- >
- <!--序号-->
- <dg-table-column type="index" width="70" label="序号" align="center" fixed="left" />
- <!--复选框情况-->
- <dg-table-column type="selection" width="55" v-if="selection" />
- <slot name="expand" />
- <template v-for="(item, indexs) in headerData">
- <dg-table-column :key="indexs" v-bind="item" align="center">
- <template slot-scope="scope">
- <slot v-if="item.custom" v-bind:row="scope.row" :name="item.prop"></slot>
- <span v-if="item.state">{{ converterText(scope.row, item) }}</span>
- <span v-if="item.timestamp">{{ formatTimestamp(scope.row, item) }}</span>
- <span v-if="item.adminAudit">{{ transformText(scope.row, item) }}</span>
- <span v-if="item.transOperateType">{{ transformOperateType(scope.row, item) }}</span>
- <!-- <span v-if="item.tranformBusiness">{{ tranformBusinessText(scope.row, item) }}</span> -->
- </template>
- </dg-table-column>
- </template>
- <!--操作栏-->
- <slot></slot>
- </dg-table>
- </template>
- <script>
- import moment from "moment";
- import * as dd from "@/api/dd";
- import * as roleAuthApi from "@/api/role-auth-info";
- export default {
- name: "Ltable",
- props: {
- lazyLoad: {
- type: Boolean,
- default: false
- },
- data: {
- type: Array,
- default: () => []
- },
- // 表头配置
- headerData: {
- type: Array,
- default: () => []
- },
- // 开启复选
- selection: {
- type: Boolean,
- default: false
- },
- // 开启复选
- url: {
- type: String,
- default: "",
- require: true
- },
- // 表格查询参数
- condition: {
- type: Object,
- default: () => {}
- },
- // 是否开启分页
- pagination: {
- type: Boolean,
- default: true
- },
- // 分页选项
- paginationProps: {
- type: Object,
- default: () => {
- return {
- currentPage: 1,
- pageSizes: [10, 20, 30],
- pageSize: 10,
- layout: "total, sizes, prev, pager, next, jumper"
- };
- }
- },
- // 最大高度
- maxheight: {
- type: [Number, String],
- default: ""
- },
- converter: Function,
- beforeSearch: {
- type: Function,
- default: conditions => conditions
- },
- tableName: {
- type: String,
- default: "表格"
- }
- },
- // 页面数据绑定
- data() {
- return {
- expands: [],
- mapping: {
- list: "content",
- total: "totalPages"
- }
- };
- },
- mounted() {},
- // 方法
- methods: {
- _beforeSearch(conditions) {
- conditions = this.beforeSearch(conditions);
- let tmpCond = JSON.parse(conditions.searchCondition);
- let result = [];
- tmpCond.map((item, i) => {
- if (item.op === "between") {
- if (item.value[0]) {
- // tmpCond.splice(i, 1);
- result.push({ ...item, op: ">=", value: item.value[0] });
- result.push({ ...item, op: "<=", value: item.value[1] });
- }
- } else {
- result.push(item);
- }
- });
- conditions.searchCondition = JSON.stringify(result);
- return conditions;
- },
- /**
- * 页码切换
- * @current 切换值
- * */
- handleChangeCurrent(current) {
- this.$emit("handleChangeCurrent", current);
- },
- /**
- * 页面切换
- * @current 切换值
- * */
- handleChangeSize(size) {
- this.$emit("handleChangeSize", size);
- },
- /**
- * 页码切换
- * @data 选中数据数组
- * */
- handleSelectionChange(data) {
- this.$emit("handleSelectionChange", data);
- },
- handleExpandChange(row, expanded) {
- const that = this;
- if (expanded.length) {
- that.expands = [];
- if (row) {
- that.expands.push(row.id);
- this.$emit("expand", row, expanded);
- }
- } else {
- that.expands = [];
- }
- },
- /**
- * 查询
- * */
- handleSearchClick() {
- this.$refs.grid.searchForm();
- },
- /**
- * 表格某行被点击
- * */
- handleRowClick(row, column, event) {
- this.$refs.grid.setCurrentRow(row);
- this.$emit("handleRowClick", { row, column });
- },
- // 某单元格被点击
- handleCellClick(row, column, cell, event) {
- this.$emit("handleCellClick", { row, column });
- },
- /**
- * 文案转换状态
- * */
- converterText(rowData, item) {
- const prop = item.prop || { label: "label", value: "value" };
- let resultItem = item.state.find(val => val["value"] == rowData[item.prop]);
- if (resultItem) {
- return resultItem["label"];
- } else {
- return moment(rowData[item.prop]).format("YYYY-MM-DD");
- }
- // return resultItem ? resultItem["label"] : rowData[item.prop];
- },
- /**
- * 时间戳转换
- * */
- formatTimestamp(rowData, item) {
- let str = "";
- const type = item.format || "YYYY-MM-DD";
- if (rowData[item.prop]) {
- return moment(parseInt(rowData[item.prop])).format(type);
- }
- },
- /**
- * 管理员表格 文案转换
- * */
- transformText(rowData, item) {
- const user = dd.adminAuditsLabel.user;
- const org = dd.adminAuditsLabel.org;
- const admin = dd.adminAuditsLabel.admin;
- let transformString = "";
- if (rowData.auditType == "user_audit") {
- for (let i = 0; i < user.length; i++) {
- if (rowData[item.prop] == user[i].value) {
- transformString = user[i].label;
- break;
- }
- }
- } else if (rowData.auditType == "org_audit") {
- transformString = org[0].label;
- } else {
- for (let i = 0; i < admin.length; i++) {
- if (rowData[item.prop] == admin[i].value) {
- transformString = admin[i].label;
- break;
- }
- }
- }
- return transformString;
- },
- /**
- * 管理员审计 文案转换
- * 操作内容
- * */
- transformOperateType(rowData, item) {
- let transformString = "";
- if (rowData.auditType == "user_audit") {
- if (rowData.operateType == "10") {
- transformString = "新增";
- } else if (rowData.operateType == "20") {
- transformString = "修改";
- } else if (rowData.operateType == "30") {
- transformString = "删除";
- } else if (rowData.operateType == "40") {
- transformString = "审批通过";
- } else if (rowData.operateType == "41") {
- transformString = "审批不通过";
- } else if (rowData.operateType == "50") {
- transformString = "启用";
- } else if (rowData.operateType == "51") {
- transformString = "停用";
- } else if (rowData.operateType == "61") {
- transformString = "入职";
- } else if (rowData.objectType == "62") {
- transformString = "离职";
- } else {
- transformString = "";
- }
- }
- if (rowData.auditType == "org_audit") {
- if (rowData.operateType == "10") {
- transformString = "新增机构";
- } else if (rowData.operateType == "20") {
- transformString = "修改机构";
- } else if (rowData.operateType == "30") {
- transformString = "删除机构";
- } else if (rowData.operateType == "40") {
- transformString = "调离机构";
- } else if (rowData.operateType == "50") {
- transformString = "合并机构";
- } else {
- transformString = "";
- }
- } else {
- if (rowData.operateType == "10") {
- transformString = "管理员创建";
- } else if (rowData.operateType == "11") {
- transformString = "管理员删除";
- } else if (rowData.operateType == "20") {
- transformString = "平台菜单权限新增";
- } else if (rowData.operateType == "21") {
- transformString = "平台菜单权限移除";
- } else if (rowData.operateType == "30") {
- transformString = "机构管理范围新增";
- } else if (rowData.operateType == "31") {
- transformString = "机构管理范围变更";
- } else if (rowData.operateType == "40") {
- transformString = "用户管理范围新增";
- } else if (rowData.operateType == "41") {
- transformString = "用户管理范围变更";
- } else if (rowData.objectType == "50") {
- transformString = "授权管理范围新增";
- } else if (rowData.objectType == "51") {
- transformString = "授权管理范围变更";
- } else if (rowData.objectType == "60") {
- transformString = "管理员管理范围新增";
- } else if (rowData.objectType == "61") {
- transformString = "管理员管理范围变更";
- } else {
- transformString = "";
- }
- }
- return transformString;
- },
- /**
- * 转换业务域
- * */
- tranformBusinessText(row, item) {},
- /*
- * 切换勾选状态
- * */
- toggleRowSelection(row, bool = false) {
- return this.$refs.grid.toggleRowSelection(row, bool);
- },
- getReqSearchCondition() {
- return this.$refs.grid.getReqSearchCondition();
- },
- beforeQuest(res) {
- const { content, totalElements } = res.data;
- const result = {
- data: {
- content,
- totalElements
- }
- };
- this.$emit("getTotalElements", { totalElements, tableName: this.tableName });
- return result;
- }
- },
- created() {}
- };
- </script>
- <style scoped lang="scss">
- .el-table__body tr.current-row > td {
- background-color: #f5f7fa !important;
- }
- </style>
|