ibiz-template-plugin.es.js 10.4 KB
Newer Older
zhujiamin's avatar
zhujiamin committed
1 2 3 4
var A = Object.defineProperty;
var E = (e, i, n) => i in e ? A(e, i, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[i] = n;
var P = (e, i, n) => (E(e, typeof i != "symbol" ? i + "" : i, n), n);
import { PluginStaticResource as O } from "@ibiz-template/runtime";
zhujiamin's avatar
zhujiamin committed
5
import { GridModel as I } from "@ibiz-template/model";
zhujiamin's avatar
zhujiamin committed
6 7 8 9 10
import { useNamespace as S, useControlController as M, usePropsWatch as U } from "@ibiz-template/vue-util";
import { ref as w, computed as b, defineComponent as G, h as c, getCurrentInstance as H, watch as T, onUnmounted as L } from "vue";
import { GridController as $, GridRowController as j, GridNotifyState as F } from "@ibiz-template/controller";
const q = new O(import.meta.url);
class B {
zhujiamin's avatar
zhujiamin committed
11
  constructor() {
zhujiamin's avatar
zhujiamin committed
12
    P(this, "component", "RfpgGridControl");
zhujiamin's avatar
zhujiamin committed
13 14 15
  }
}
function z(e, i) {
zhujiamin's avatar
zhujiamin committed
16 17
  var o;
  const n = [];
zhujiamin's avatar
zhujiamin committed
18
  e.source.columnType === "GROUPGRIDCOLUMN" && e.children.forEach((s) => {
zhujiamin's avatar
zhujiamin committed
19
    n.push(z(s, i));
zhujiamin's avatar
zhujiamin committed
20 21 22 23 24
  });
  const t = {
    title: e.title,
    width: e.source.widthUnit === "STAR" ? void 0 : e.width,
    minWidth: e.width,
zhujiamin's avatar
zhujiamin committed
25
    align: ((o = e.source.align) == null ? void 0 : o.toLowerCase()) || "center",
zhujiamin's avatar
zhujiamin committed
26 27 28 29 30 31 32 33 34 35 36 37
    slot: e.codeName,
    key: e.codeName,
    fieldName: e.deFieldName,
    ellipsis: !0,
    tooltip: !1,
    // todo 表格提示用title
    resizable: !0,
    sortable: !i.noSort && e.source.enableSort ? "custom" : !1,
    columnType: e.source.columnType,
    tree: e.id === "pfzbname",
    className: e.id === "pfzbname" ? "pfzbname" : ""
  };
zhujiamin's avatar
zhujiamin committed
38
  return n.length > 0 && Object.assign(t, { children: n }), t;
zhujiamin's avatar
zhujiamin committed
39 40
}
function _(e) {
zhujiamin's avatar
zhujiamin committed
41 42 43 44 45
  const i = e.model, n = [], t = i.columns.map((o) => z(o, e));
  return i.children.forEach((o) => {
    const s = t.find((r) => r.key === o.codeName);
    s && o.id !== "lb" && n.push(s);
  }), e.singleSelect || n.splice(0, 0, { type: "selection", width: 60 }), n;
zhujiamin's avatar
zhujiamin committed
46 47
}
function V(e) {
zhujiamin's avatar
zhujiamin committed
48
  const i = w([]);
zhujiamin's avatar
zhujiamin committed
49 50
  return e.nerve.self.evt.on("created", () => {
    i.value = _(e);
zhujiamin's avatar
zhujiamin committed
51
  }), [b(() => {
zhujiamin's avatar
zhujiamin committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65
    const t = [...i.value];
    if (!t.find((r) => !r.width)) {
      let r = t.length - 1;
      t[r].key === "rowEdit" && (r -= 1), t[r] = {
        ...t[r],
        width: void 0
      };
    }
    const s = t.find((r) => r.columnType === "UAGRIDCOLUMN");
    return s && (s.fixed = "right"), t;
  }), i];
}
function W(e) {
  const i = (r) => e.items.find((a) => a.srfkey === r.srfkey);
zhujiamin's avatar
zhujiamin committed
66
  function n(r) {
zhujiamin's avatar
zhujiamin committed
67 68 69 70 71 72
    const a = i(r);
    e.singleSelect && e.onSelectionChange([a]), e.onRowClick(a);
  }
  function t(r) {
    e.onDbRowClick(i(r));
  }
zhujiamin's avatar
zhujiamin committed
73
  function o(r) {
zhujiamin's avatar
zhujiamin committed
74 75
    if (!e.singleSelect) {
      const a = [];
zhujiamin's avatar
zhujiamin committed
76 77 78
      r.forEach((d) => {
        const f = i(d);
        f && a.push(f);
zhujiamin's avatar
zhujiamin committed
79 80 81 82
      }), e.onSelectionChange(a);
    }
  }
  function s(r) {
zhujiamin's avatar
zhujiamin committed
83 84
    const { column: a, order: d } = r, f = d === "asc" || d === "desc" ? d : void 0;
    e.setSort(a.fieldName, f), e.load();
zhujiamin's avatar
zhujiamin committed
85
  }
zhujiamin's avatar
zhujiamin committed
86
  return { onRowClick: n, onDbRowClick: t, onSelectionChange: o, onSortChange: s };
zhujiamin's avatar
zhujiamin committed
87 88
}
function J(e) {
zhujiamin's avatar
zhujiamin committed
89 90
  function i(o) {
    !o || o === e.curPage || (e.curPage = o, e.load());
zhujiamin's avatar
zhujiamin committed
91
  }
zhujiamin's avatar
zhujiamin committed
92 93
  function n(o) {
    !o || o === e.size || (e.size = o, e.curPage === 1 && e.load());
zhujiamin's avatar
zhujiamin committed
94 95 96 97
  }
  function t() {
    e.curPage = 1, e.load();
  }
zhujiamin's avatar
zhujiamin committed
98
  return { onPageChange: i, onPageSizeChange: n, onPageReset: t };
zhujiamin's avatar
zhujiamin committed
99
}
zhujiamin's avatar
zhujiamin committed
100
const K = G({
zhujiamin's avatar
zhujiamin committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  name: "AppGridPagination",
  props: {
    total: {
      type: Number,
      required: !0
    },
    curPage: {
      type: Number,
      required: !0
    },
    size: {
      type: Number,
      required: !0
    }
  },
  setup(e) {
zhujiamin's avatar
zhujiamin committed
117
    const i = S("grid-page"), n = b(() => (e.curPage - 1) * e.size + 1), t = b(() => e.curPage * e.size);
zhujiamin's avatar
zhujiamin committed
118 119
    return {
      ns: i,
zhujiamin's avatar
zhujiamin committed
120
      start: n,
zhujiamin's avatar
zhujiamin committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
      end: t
    };
  },
  methods: {
    onPageChange(e) {
      this.$emit("change", e);
    },
    onPageSizeChange(e) {
      this.$emit("page-size-change", e);
    },
    pageReset() {
      this.$emit("page-reset");
    }
  },
  render() {
zhujiamin's avatar
zhujiamin committed
136
    return c("div", {
zhujiamin's avatar
zhujiamin committed
137
      class: this.ns.b()
zhujiamin's avatar
zhujiamin committed
138
    }, [c("i-page", {
zhujiamin's avatar
zhujiamin committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152
      attrs: {
        transfer: !0,
        total: this.total,
        "show-sizer": !0,
        "show-elevator": !0,
        current: this.curPage,
        "page-size": this.size,
        "page-size-opts": [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
        "show-total": !0
      },
      on: {
        "on-change": this.onPageChange,
        "on-page-size-change": this.onPageSizeChange
      }
zhujiamin's avatar
zhujiamin committed
153
    }, [c("span", {
zhujiamin's avatar
zhujiamin committed
154
      class: this.ns.b("btn")
zhujiamin's avatar
zhujiamin committed
155
    }, [c("i-button", {
zhujiamin's avatar
zhujiamin committed
156 157 158 159 160 161 162
      attrs: {
        icon: "md-refresh",
        title: "刷新"
      },
      on: {
        click: this.pageReset
      }
zhujiamin's avatar
zhujiamin committed
163
    })]), c("span", ["显示 ", this.start, " - ", this.end, " 条,共 ", this.total, " 条数据"])])]);
zhujiamin's avatar
zhujiamin committed
164 165 166 167 168 169 170 171 172 173 174
  }
});
class Q extends $ {
  constructor() {
    super(...arguments);
    /**
     * 分组数据
     * @return {*}
     * @author: zhujiamin
     * @Date: 2023-10-09 14:00:38
     */
zhujiamin's avatar
zhujiamin committed
175
    P(this, "groups", []);
zhujiamin's avatar
zhujiamin committed
176 177 178 179 180 181 182
  }
  /**
   * 部件加载后处理
   *
   * @author lxm
   * @date 2022-08-19 14:08:50
   */
zhujiamin's avatar
zhujiamin committed
183
  async afterLoad(n) {
zhujiamin's avatar
zhujiamin committed
184 185 186 187
    return await Promise.allSettled(
      Object.values(this.fieldColumns).map(async (t) => {
        await t.loadCodeList();
      })
zhujiamin's avatar
zhujiamin committed
188 189 190 191
    ), this.rows = n.map((t) => {
      const o = new j(t, this);
      return this.gridStateNotify(o, F.LOAD), o;
    }), this.handleGroup(n), n;
zhujiamin's avatar
zhujiamin committed
192 193 194 195 196 197 198 199
  }
  /**
   * 处理分组数据
   * @param {ControlVO} items
   * @return {*}
   * @author: zhujiamin
   * @Date: 2023-10-09 14:03:17
   */
zhujiamin's avatar
zhujiamin committed
200
  handleGroup(n) {
zhujiamin's avatar
zhujiamin committed
201
    const t = /* @__PURE__ */ new Map();
zhujiamin's avatar
zhujiamin committed
202 203 204 205
    n.forEach((o) => {
      const s = o.lb;
      t.has(s) || t.set(s, []), t.has(s) && t.get(s).push(o);
    }), this.groups = [], t.forEach((o, s) => {
zhujiamin's avatar
zhujiamin committed
206 207 208
      this.groups.push({
        caption: `${s}`,
        key: s,
zhujiamin's avatar
zhujiamin committed
209
        children: o
zhujiamin's avatar
zhujiamin committed
210
      });
zhujiamin's avatar
zhujiamin committed
211
    });
zhujiamin's avatar
zhujiamin committed
212 213
  }
}
zhujiamin's avatar
zhujiamin committed
214
function X(e, i, n, t = {}) {
zhujiamin's avatar
zhujiamin committed
215
  return M(e, () => {
zhujiamin's avatar
zhujiamin committed
216 217
    const o = new Q(i, n, t);
    return U(e, "gridRowActiveMode", o.setGridRowActiveMode.bind(o)), o;
zhujiamin's avatar
zhujiamin committed
218 219
  });
}
zhujiamin's avatar
zhujiamin committed
220
const Y = G({
zhujiamin's avatar
zhujiamin committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
  props: {
    modelData: I,
    context: {
      type: Object,
      required: !0
    },
    params: {
      type: Object,
      default: () => ({})
    },
    /**
     * 表格行数据默认激活模式
     * - 0 不激活
     * - 1 单击激活
     * - 2 双击激活(默认值)
     *
     * @type {(number | 0 | 1 | 2)}
     */
    gridRowActiveMode: {
      type: Number,
      default: 2
    },
    modal: {
      type: Object
    }
  },
  setup(e) {
    const {
      proxy: i
zhujiamin's avatar
zhujiamin committed
250
    } = H(), n = S("grid"), t = X(i, e.modelData, e.context, e.params), [o] = V(t), {
zhujiamin's avatar
zhujiamin committed
251 252 253
      onRowClick: s,
      onDbRowClick: r,
      onSelectionChange: a,
zhujiamin's avatar
zhujiamin committed
254
      onSortChange: d
zhujiamin's avatar
zhujiamin committed
255
    } = W(t), {
zhujiamin's avatar
zhujiamin committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269
      onPageChange: f,
      onPageReset: k,
      onPageSizeChange: D
    } = J(t), N = (u, l) => {
      const h = i.$refs.grid;
      h && (h.toggleSelect && h.toggleSelect(l), h.highlightCurrentRow && h.highlightCurrentRow(l)), s(u);
    }, p = w(0), g = w(null), R = w(null);
    let m = null, y = 0;
    const v = () => {
      var u;
      if (g.value && ((u = e.modal) == null ? void 0 : u.mode) !== "EMBED")
        if (t.model.source.enablePagingBar && R.value) {
          const l = R.value.$el, h = l.offsetHeight + parseFloat(window.getComputedStyle(l).paddingTop);
          p.value = g.value.offsetHeight - h;
zhujiamin's avatar
zhujiamin committed
270
        } else
zhujiamin's avatar
zhujiamin committed
271
          p.value = g.value.offsetHeight;
zhujiamin's avatar
zhujiamin committed
272 273
      t.model.source.height > 0 && (p.value = t.model.source.height);
    };
zhujiamin's avatar
zhujiamin committed
274 275 276 277 278
    T(g, (u, l) => {
      u && u !== l && (v(), window.ResizeObserver && g.value && (m = new ResizeObserver((h) => {
        const C = h[0].contentRect.height;
        C !== y && (v(), y = C);
      }), m.observe(g.value)));
zhujiamin's avatar
zhujiamin committed
279 280 281
    }), L(() => {
      m && m.disconnect();
    });
zhujiamin's avatar
zhujiamin committed
282 283 284 285
    const x = b(() => {
      const u = [];
      return t.groups.forEach((l) => {
        if (!l.children.length)
zhujiamin's avatar
zhujiamin committed
286
          return;
zhujiamin's avatar
zhujiamin committed
287 288 289
        const C = [...l.children].shift();
        u.push({
          srfkey: l.caption,
zhujiamin's avatar
zhujiamin committed
290 291
          isGroupData: !0,
          first: C,
zhujiamin's avatar
zhujiamin committed
292
          children: l.children,
zhujiamin's avatar
zhujiamin committed
293 294
          _showChildren: !0
        });
zhujiamin's avatar
zhujiamin committed
295
      }), u;
zhujiamin's avatar
zhujiamin committed
296 297 298
    });
    return {
      c: t,
zhujiamin's avatar
zhujiamin committed
299 300 301
      ns: n,
      columns: o,
      tableData: x,
zhujiamin's avatar
zhujiamin committed
302
      onDbRowClick: r,
zhujiamin's avatar
zhujiamin committed
303
      onUIRowClick: N,
zhujiamin's avatar
zhujiamin committed
304
      onSelectionChange: a,
zhujiamin's avatar
zhujiamin committed
305 306 307 308
      onSortChange: d,
      onPageChange: f,
      onPageSizeChange: D,
      onPageReset: k,
zhujiamin's avatar
zhujiamin committed
309
      tableHeight: p,
zhujiamin's avatar
zhujiamin committed
310 311
      gridRef: g,
      girdPaginationRef: R
zhujiamin's avatar
zhujiamin committed
312 313 314 315 316 317 318 319 320
    };
  },
  render() {
    if (!this.c.complete)
      return;
    const e = {};
    return this.c.model.columns.forEach((i) => {
      if (i.source.columnType === "GROUPGRIDCOLUMN")
        return;
zhujiamin's avatar
zhujiamin committed
321 322
      const n = i.codeName;
      e[n] = (t) => {
zhujiamin's avatar
zhujiamin committed
323
        const {
zhujiamin's avatar
zhujiamin committed
324
          row: o,
zhujiamin's avatar
zhujiamin committed
325 326
          column: s
        } = t;
zhujiamin's avatar
zhujiamin committed
327
        if (o.isGroupData && s._index === 0)
zhujiamin's avatar
zhujiamin committed
328
          return c("div", {
zhujiamin's avatar
zhujiamin committed
329 330
            class: this.ns.b("sum"),
            attrs: {
zhujiamin's avatar
zhujiamin committed
331
              title: o.first.lb
zhujiamin's avatar
zhujiamin committed
332
            }
zhujiamin's avatar
zhujiamin committed
333 334
          }, [c("span", [o.first.lb])]);
        const r = this.c.rows.find((a) => a.data.srfkey === o.srfkey);
zhujiamin's avatar
zhujiamin committed
335
        if (r)
zhujiamin's avatar
zhujiamin committed
336
          return c(this.c.providers[n].component, {
zhujiamin's avatar
zhujiamin committed
337
            props: {
zhujiamin's avatar
zhujiamin committed
338
              controller: this.c.columns[n],
zhujiamin's avatar
zhujiamin committed
339 340
              row: r
            },
zhujiamin's avatar
zhujiamin committed
341
            key: o.srfkey + n
zhujiamin's avatar
zhujiamin committed
342 343
          });
      };
zhujiamin's avatar
zhujiamin committed
344
    }), c("control-layout", {
zhujiamin's avatar
zhujiamin committed
345 346 347
      attrs: {
        modelData: this.c.model
      }
zhujiamin's avatar
zhujiamin committed
348
    }, [c("div", {
zhujiamin's avatar
zhujiamin committed
349 350
      ref: "gridRef",
      class: [this.ns.b(), this.ns.b("rfpg-grid"), this.ns.is("show-header", !this.c.model.source.hideHeader), this.ns.is("enable-page", this.c.model.source.enablePagingBar)]
zhujiamin's avatar
zhujiamin committed
351
    }, [this.c.groups.length > 0 && c("i-table", {
zhujiamin's avatar
zhujiamin committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
      ref: "grid",
      attrs: {
        height: this.tableHeight,
        "show-header": !this.c.model.source.hideHeader,
        "highlight-row": !0,
        data: this.tableData,
        columns: this.columns,
        "row-key": "srfkey"
      },
      class: this.ns.b("content"),
      on: {
        "on-row-click": this.onUIRowClick,
        "on-row-dblclick": this.onDbRowClick,
        "on-selection-change": this.onSelectionChange,
        "on-sort-change": this.onSortChange
      },
      scopedSlots: e
zhujiamin's avatar
zhujiamin committed
369
    }), this.c.model.source.enablePagingBar && c(K, {
zhujiamin's avatar
zhujiamin committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
      ref: "girdPaginationRef",
      attrs: {
        total: this.c.total,
        curPage: this.c.curPage,
        size: this.c.size
      },
      on: {
        change: this.onPageChange,
        "page-size-change": this.onPageSizeChange,
        "page-reset": this.onPageReset
      }
    })])]);
  }
}), re = {
  mateUrl: import.meta.url,
  install(e) {
zhujiamin's avatar
zhujiamin committed
386
    q.loadStyle(["/style.css"]), e.component("RfpgGridControl", Y), ibiz.register.control.register(
zhujiamin's avatar
zhujiamin committed
387
      "GRID_RENDER_RfpgGird",
zhujiamin's avatar
zhujiamin committed
388
      new B()
zhujiamin's avatar
zhujiamin committed
389 390 391 392 393 394
    );
  }
};
export {
  re as default
};