T-ui-Plus Documentation

repository·master·Indexed 18 days ago

https://github.com/wocwin/t-ui-plus

A Vue 3 component library built on TypeScript and Element-Plus, providing enhanced, pre-configured components for administrative backends and complex management interfaces. Features include the TAdaptivePage layout component, TSelectTable with virtual scrolling, TButton with built-in debounce, and a TChart wrapper for Echarts.

Tokens
55.1K
Snippets
176
Records
274
Agent score
63%

What's inside @wocwin/t-ui-plus

  1. Overview of @wocwin/t-ui-plus

    master
    @wocwin/t-ui-plus is a collection of base components built on top of Vue 3, TypeScript, and Element-plus. It provides high-level abstractions for common UI patterns like adaptive layouts, query conditions, and complex tables to accelerate development.
  2. Overview of T-ui-plus

    master
    T-ui-plus is a collection of basic components for Vue 3, built as a secondary encapsulation (wrapper) of Element-plus. It is designed to provide an enhanced development experience using Vue 3 and Vite 3, allowing developers to use Vue components within Markdown and develop custom themes using Vue.
  3. Customize TCheckbox appearance and slots

    master

    TCheckbox supports several visual customizations:

    • Size: Use the size attribute with values 'large', 'default', or 'small'.
    • Button Style: Set type="button" to render checkboxes as buttons.
    • Border: Set border to true to render checkboxes with a border.
    • Slots:
      • Use the slot property within an option object to target a specific named slot.
      • Use the default slot to implement custom rendering for the checkbox items.
  4. Use `isDropDownSelectMore` to show extra conditions

    master

    When isDropDownSelectMore is set to true, additional conditions are hidden behind a dropdown menu. This is useful for complex forms to save space.

    Attributes for Dropdown Mode:

    ParameterDescriptionTypeDefault
    popoverAttrsConfiguration for el-popover and localized textobject{ showTxt: '更多', title: '所有条件', allTxt: '全选', reverseTxt: '反选', clearTxt: '清空', placement: 'bottom', width: 240, trigger: 'click' }
    moreCheckListData source for the dropdown itemsArray-

    moreCheckList item structure:

    • label: Title
    • comp: Component name/object
    • isSelfCom: If true, uses custom component without el-option
    • prop: Backend field name
    • bind: Component attributes (can be a function receiving form)
    • slotName: Custom input slot
    • span: Column span (1-4)
    • type: Element type (radio, checkbox, select-arr, select-obj)
    • list: Data source for el-select
  5. Customize labels with labelRender or slots

    master

    TForm provides two ways to render custom labels:

    1. labelRender (TSX/Function): Provide a function to the labelRender property in the field configuration. If labelRender is present, it takes precedence over the label property.
    2. labelSlotName (Slot): Use the labelSlotName property in the field configuration to specify a slot name, then provide the content via that slot in your template.
  6. Configure Multiple Selection (Checkbox) Mode

    master

    Enable multiple selection by setting the multiple prop to true.

    Key features:

    • Custom Selectability: Use the selectable prop (a function (row: any, index: number) => boolean) to determine if a checkbox can be checked.
    • Fixed Checkbox Column: multipleFixed (default true) keeps the checkbox column fixed.
    • Selection Event: Use @selectionChange to receive the selected items and the collection of their keywords.value identifiers.
    • Hide Delete Icon: Set multipleDisableDelete to true to hide the delete icon on selected tags. This is useful when switching pages or performing queries where previously selected data might not exist in the current view.
    • Restore Selection: When using pagination, you can assign values to state.defaultValue to show labels, but you must call the exposed selectTable.toggleRowSelection method to actually check the rows.
  7. Configure Single Selection (Radio) Mode

    master

    By default, TSelectTable operates in single selection mode.

    Common configurations:

    • Disable specific rows: Use the isRadioDisabled property (if applied to the table data) to prevent selection of certain rows.
    • Keyboard Navigation: Set isKeyup to true to enable up/down arrow selection and Enter to confirm. Note: max-height must be set for scrolling to work correctly.
    • Hide first column: Set isShowFirstColumn to false to hide the radio button column.
    • Row Click: rowClickRadio (default true) allows selecting a row by clicking anywhere on it.
    • Same item toggle: radioSameIsCancel (default true) allows clicking the same item again to deselect it.
  8. Global Registration of T-ui-Plus

    master

    To use T-ui-Plus globally in your Vue application, you must first ensure that element-plus is globally registered, as T-ui-Plus depends on it. Import the T-ui-Plus CSS and the library itself, then use app.use(TuiPlus) in your main entry file.

    When configuring locales, you can merge the element-plus locale with the @wocwin/t-ui-plus/locale locale to ensure both libraries are localized correctly.

    // main.ts
    import { createApp } from "vue"
    import App from "./App.vue"
    import ElementPlus from "element-plus"
    import "element-plus/dist/index.css"
    import "element-plus/theme-chalk/dark/css-vars.css"
    import zhCn from 'element-plus/es/locale/lang/zh-cn'
    import plusZhCn from '@wocwin/t-ui-plus/locale/zh-cn'
    import * as ElementPlusIconsVue from "@element-plus/icons-vue"
    import TuiPlus from "@wocwin/t-ui-plus"
    import "@wocwin/t-ui-plus/index.css"
    
    const app = createApp(App)
    
    // Register Element Plus icons
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
    
    // Register ElementPlus with merged locales
    app.use(ElementPlus, {
      locale: { ...zhCn, ...plusZhCn }
    })
    
    // Register TuiPlus
    app.use(TuiPlus)
    
    app.mount("#app")
  9. Use T-ui-Plus via CDN

    master

    You can include T-ui-Plus directly in your HTML using a CDN provider like unpkg or jsDelivr. This requires vue and element-plus to be loaded first.

    <!-- unpkg example -->
    <head>
      <link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
      <script src="//unpkg.com/vue@3"></script>
      <script src="//unpkg.com/element-plus"></script>
    
      <link rel="stylesheet" href="//unpkg.com/@wocwin/t-ui-plus/index.css" />
      <script src="//unpkg.com/@wocwin/t-ui-plus"></script>
    </head>
  10. Use the TStepWizard component

    master

    The TStepWizard component is a data-driven wrapper around Element-plus el-steps and el-step. It simplifies step management by allowing you to define steps via a stepData array rather than writing repetitive HTML. You can use named slots (e.g., #first, #second) to define the content of each step.

    Key features include:

    • Data-driven: Define steps, icons, descriptions, and buttons in a single array.
    • Custom Buttons: Each step can have its own array of buttons (btnArr) with custom titles, parameters, and event handlers.
    • Completion Flow: Supports a specialized final step with a success title and custom completion buttons (lastBtnArr).
    <t-step-wizard
      :stepData="stepData"
      :active="active"
      :successTitle="successTitle"
      @complete="complete"
    >
      <template #first>第一步骤</template>
      <!-- Additional step slots as needed -->
    </t-step-wizard>