gi-component 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import { default as Descriptions } from './src/descriptions.vue';
2
+ export type DescriptionsInstance = InstanceType<typeof Descriptions>;
3
+ export * from './src/type';
4
+ export default Descriptions;
@@ -0,0 +1,23 @@
1
+ import { DescriptionsItem, DescriptionsProps } from './type';
2
+ declare function __VLS_template(): {
3
+ attrs: Partial<{}>;
4
+ slots: Partial<Record<string, (_: {
5
+ item: DescriptionsItem<any>;
6
+ value: any;
7
+ }) => any>> & {
8
+ default?(_: {}): any;
9
+ };
10
+ refs: {};
11
+ rootEl: any;
12
+ };
13
+ type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
14
+ declare const __VLS_component: import('vue').DefineComponent<DescriptionsProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<DescriptionsProps> & Readonly<{}>, {
15
+ columns: DescriptionsItem[];
16
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
17
+ declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
18
+ export default _default;
19
+ type __VLS_WithTemplateSlots<T, S> = T & {
20
+ new (): {
21
+ $slots: S;
22
+ };
23
+ };
@@ -0,0 +1,20 @@
1
+ import { DescriptionsProps as ElDescriptionsProps } from 'element-plus';
2
+ import { VNode } from 'vue';
3
+ import type * as El from 'element-plus';
4
+ export type DescriptionsItemType = 'text' | 'slot' | 'dict';
5
+ export interface DescriptionsItem<D = any> {
6
+ type?: DescriptionsItemType;
7
+ label?: string;
8
+ labelRender?: () => VNode;
9
+ field?: string;
10
+ span?: number;
11
+ props?: El.DescriptionsItemProps;
12
+ dictCode?: string;
13
+ dictValue?: string;
14
+ hide?: boolean | ((data: D) => boolean);
15
+ }
16
+ export interface DescriptionsProps extends /* @vue-ignore */ Partial<ElDescriptionsProps> {
17
+ data?: any;
18
+ columns?: DescriptionsItem[];
19
+ dictRequest?: (code: string) => Promise<any[]>;
20
+ }
@@ -26,9 +26,9 @@ declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps,
26
26
  "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
27
27
  }>, {
28
28
  footer: boolean | (() => VNode);
29
+ readonly width: string | number;
29
30
  readonly closeOnClickModal: boolean;
30
31
  readonly lockScroll: boolean;
31
- readonly width: string | number;
32
32
  readonly alignCenter: boolean;
33
33
  readonly showClose: boolean;
34
34
  okText: string;
@@ -1,4 +1,4 @@
1
1
  import { default as Table } from './src/table.vue';
2
- export type TableInstance = Parameters<NonNullable<Parameters<typeof Table>['2']>>['0'];
2
+ export type TableInstance = InstanceType<typeof Table>;
3
3
  export * from './src/type';
4
4
  export default Table;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { App } from 'vue';
2
2
  import { default as Button } from './components/button';
3
3
  import { default as Card } from './components/card';
4
+ import { default as Descriptions } from './components/descriptions';
4
5
  import { default as DialogComponent } from './components/dialog';
5
6
  import { default as Dot } from './components/dot';
6
7
  import { default as Drawer } from './components/drawer';
@@ -14,6 +15,7 @@ import { default as PageLayout } from './components/page-layout';
14
15
  import { default as Table } from './components/table';
15
16
  import { default as Tabs } from './components/tabs';
16
17
  import { default as TreeTransfer } from './components/tree-transfer';
18
+ export * from './components/descriptions';
17
19
  export * from './components/dialog';
18
20
  export * from './components/drawer';
19
21
  export * from './components/edit-table';
@@ -24,6 +26,7 @@ export * from './hooks';
24
26
  export * from './utils';
25
27
  export declare const GiButton: typeof Button;
26
28
  export declare const GiCard: typeof Card;
29
+ export declare const GiDescriptions: typeof Descriptions;
27
30
  export declare const GiDrawer: typeof Drawer;
28
31
  export declare const GiDot: typeof Dot;
29
32
  export declare const GiTabs: typeof Tabs;
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
- import { defineComponent, createElementBlock, openBlock, createElementVNode, getCurrentInstance, useAttrs, computed, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString, useSlots, normalizeClass, createCommentVNode, normalizeStyle, createVNode, mergeModels, useModel, ref, createSlots, resolveDynamicComponent, resolveComponent, h, createApp, Fragment, renderList, watch, onMounted, onUpdated, onUnmounted, inject, toRefs, watchEffect, reactive, provide, normalizeProps, guardReactiveProps, useTemplateRef } from "vue";
1
+ import { defineComponent, createElementBlock, openBlock, createElementVNode, getCurrentInstance, useAttrs, computed, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString, useSlots, normalizeClass, createCommentVNode, normalizeStyle, createVNode, ref, onMounted, Fragment, renderList, createSlots, resolveDynamicComponent, mergeModels, useModel, resolveComponent, h, createApp, watch, onUpdated, onUnmounted, inject, toRefs, watchEffect, reactive, provide, normalizeProps, guardReactiveProps, useTemplateRef } from "vue";
2
2
  import * as El from "element-plus";
3
- import El__default, { ElButton, ElSpace, ElDialog, ElDrawer, ElInput, ElForm, ElTable, ElTableColumn, ElFormItem, ElText, ElMessage, ElIcon, ElSplitter, ElSplitterPanel, ElRow, ElPagination, ElTabs, ElTabPane, ElCheckbox, ElScrollbar, ElTree, ElCheckboxGroup, ElEmpty } from "element-plus";
3
+ import El__default, { ElButton, ElSpace, ElDescriptions, ElDescriptionsItem, ElDialog, ElDrawer, ElInput, ElForm, ElTable, ElTableColumn, ElFormItem, ElText, ElMessage, ElIcon, ElSplitter, ElSplitterPanel, ElRow, ElPagination, ElTabs, ElTabPane, ElCheckbox, ElScrollbar, ElTree, ElCheckboxGroup, ElEmpty } from "element-plus";
4
4
  /*! Element Plus Icons Vue v2.3.2 */
5
5
  var _sfc_main6 = /* @__PURE__ */ defineComponent({
6
6
  name: "ArrowDown",
@@ -284,7 +284,7 @@ function useBemClass() {
284
284
  const b = (name = "") => `${prefix}-${name ? `${name}` : ""}`;
285
285
  return { b };
286
286
  }
287
- const _sfc_main$h = /* @__PURE__ */ defineComponent({
287
+ const _sfc_main$i = /* @__PURE__ */ defineComponent({
288
288
  __name: "button",
289
289
  props: {
290
290
  type: { default: "" },
@@ -349,7 +349,7 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
349
349
  };
350
350
  }
351
351
  });
352
- const _sfc_main$g = /* @__PURE__ */ defineComponent({
352
+ const _sfc_main$h = /* @__PURE__ */ defineComponent({
353
353
  __name: "card",
354
354
  props: {
355
355
  title: { default: "" },
@@ -434,7 +434,115 @@ const _export_sfc = (sfc, props) => {
434
434
  }
435
435
  return target;
436
436
  };
437
- const Card = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-0733140b"]]);
437
+ const Card = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["__scopeId", "data-v-0733140b"]]);
438
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
439
+ __name: "descriptions",
440
+ props: {
441
+ data: {},
442
+ columns: { default: () => [] },
443
+ dictRequest: {}
444
+ },
445
+ setup(__props) {
446
+ const props = __props;
447
+ const attrs = useAttrs();
448
+ const { b } = useBemClass();
449
+ const instance = getCurrentInstance();
450
+ const globalConfig = instance == null ? void 0 : instance.appContext.config.globalProperties.$config;
451
+ const dictData = ref({});
452
+ const loadDictData = async () => {
453
+ var _a;
454
+ const dictCodes = (_a = props.columns) == null ? void 0 : _a.filter((item) => item.dictCode).map((item) => item.dictCode).filter((code, index2, arr) => arr.indexOf(code) === index2);
455
+ if (!(dictCodes == null ? void 0 : dictCodes.length)) return;
456
+ const dictRequest = props.dictRequest || (globalConfig == null ? void 0 : globalConfig.dictRequest);
457
+ if (!dictRequest) {
458
+ return;
459
+ }
460
+ try {
461
+ const dictResponses = await Promise.all(
462
+ dictCodes.map(
463
+ (code) => dictRequest(code).then((response) => ({ code, response })).catch((error) => {
464
+ console.error(`获取字典 ${code} 失败:`, error);
465
+ return { code, response: [] };
466
+ })
467
+ )
468
+ );
469
+ dictResponses.forEach(({ code, response }) => {
470
+ dictData.value[code] = response;
471
+ });
472
+ } catch (error) {
473
+ console.error("获取字典数据失败:", error);
474
+ }
475
+ };
476
+ onMounted(() => {
477
+ loadDictData();
478
+ });
479
+ const filteredColumns = computed(() => {
480
+ return props.columns.filter((item) => {
481
+ if (typeof item.hide === "boolean") return !item.hide;
482
+ if (typeof item.hide === "function") return !item.hide(props.data);
483
+ return true;
484
+ });
485
+ });
486
+ const descriptionsProps = computed(() => {
487
+ const { data, columns, dictRequest, ...restProps } = props;
488
+ return { ...attrs, ...restProps };
489
+ });
490
+ const getClass = computed(() => {
491
+ return [b("descriptions")];
492
+ });
493
+ const getValue = (item) => {
494
+ if (!item.field || !props.data) return "";
495
+ return props.data[item.field] ?? "";
496
+ };
497
+ const getDictValue = (item) => {
498
+ var _a;
499
+ if (!item.dictCode || !item.field) return "";
500
+ const value = (_a = props.data) == null ? void 0 : _a[item.field];
501
+ const dictList = dictData.value[item.dictCode] || [];
502
+ const dictItem = dictList.find((d) => d.value === value || d.code === value);
503
+ return (dictItem == null ? void 0 : dictItem.label) ?? (dictItem == null ? void 0 : dictItem.name) ?? value ?? "";
504
+ };
505
+ return (_ctx, _cache) => {
506
+ return openBlock(), createBlock(unref(ElDescriptions), mergeProps({ class: getClass.value }, descriptionsProps.value), {
507
+ default: withCtx(() => [
508
+ (openBlock(true), createElementBlock(Fragment, null, renderList(filteredColumns.value, (item, index2) => {
509
+ return openBlock(), createBlock(unref(ElDescriptionsItem), mergeProps({
510
+ key: index2,
511
+ ref_for: true
512
+ }, item.props, {
513
+ label: item.label,
514
+ span: item.span
515
+ }), createSlots({
516
+ default: withCtx(() => [
517
+ item.type === "slot" ? renderSlot(_ctx.$slots, item.field, {
518
+ key: 0,
519
+ item,
520
+ value: getValue(item)
521
+ }, void 0, true) : item.type === "dict" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
522
+ createTextVNode(toDisplayString(getDictValue(item)), 1)
523
+ ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
524
+ createTextVNode(toDisplayString(getValue(item)), 1)
525
+ ], 64))
526
+ ]),
527
+ _: 2
528
+ }, [
529
+ (item == null ? void 0 : item.labelRender) ? {
530
+ name: "label",
531
+ fn: withCtx(() => [
532
+ (openBlock(), createBlock(resolveDynamicComponent(item.labelRender)))
533
+ ]),
534
+ key: "0"
535
+ } : void 0
536
+ ]), 1040, ["label", "span"]);
537
+ }), 128)),
538
+ renderSlot(_ctx.$slots, "default", {}, void 0, true)
539
+ ]),
540
+ _: 3
541
+ }, 16, ["class"]);
542
+ };
543
+ }
544
+ });
545
+ const Descriptions = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-621af6b6"]]);
438
546
  const _hoisted_1$4 = { key: 0 };
439
547
  const _sfc_main$f = /* @__PURE__ */ defineComponent({
440
548
  __name: "dialog",
@@ -8261,8 +8369,9 @@ const createSelectDialog = (params) => {
8261
8369
  };
8262
8370
  void [Dialog.info, Dialog.success, Dialog.warning, Dialog.error];
8263
8371
  const components = {
8264
- Button: _sfc_main$h,
8372
+ Button: _sfc_main$i,
8265
8373
  Card,
8374
+ Descriptions,
8266
8375
  Drawer: _sfc_main$c,
8267
8376
  Dot,
8268
8377
  Tabs,
@@ -8277,8 +8386,9 @@ const components = {
8277
8386
  Table,
8278
8387
  TreeTransfer
8279
8388
  };
8280
- const GiButton = _sfc_main$h;
8389
+ const GiButton = _sfc_main$i;
8281
8390
  const GiCard = Card;
8391
+ const GiDescriptions = Descriptions;
8282
8392
  const GiDrawer = _sfc_main$c;
8283
8393
  const GiDot = Dot;
8284
8394
  const GiTabs = Tabs;
@@ -8312,6 +8422,7 @@ export {
8312
8422
  Drawer,
8313
8423
  GiButton,
8314
8424
  GiCard,
8425
+ GiDescriptions,
8315
8426
  GiDialog,
8316
8427
  GiDot,
8317
8428
  GiDrawer,