1.3.2 • Published 3 years ago

vue-curd v1.3.2

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

intrudoction

vue-curd is a component solution to quickly generate tables and forms, its based on vue.js 2.x and Element-Ui, it contains two components, one is CurdTable and the other is CurdForm, here is their introduction and basic usage.

install

yarn add vue-curd

useage example

import Vue from 'vue'
import VueCurd from 'vue-curd'

Vue.use(VueCurd)

FieldConfig

Curd uses FieldConfig to render the views of corresponding tables and forms. The following are the data rules of FieldConfig. Developers must define data according to this data specification. The following are the attributes supported by FieldConfig:

  • prop: String Field Name
  • label: String Field alias name
  • default: String Field default value
  • disabled: Boolean Is the form item corresponding to the field disabled
  • placeholder: String Filed form item placeholder
  • show: Boolean Whether the form item corresponding to the field is displayed
  • widget: String Specify the component to render the form item corresponding to the field. Widget refers to the registered name of Vue component
  • slot: String When the user-defined requirements cannot be realized by configuration, the corresponding user-defined content can be distributed to curd from the outside through slot. The default value of slot is empty, which means that the default component is used for rendering or the component specified by the widget is used for rendering. When the value of slot is set, it is rendered according to the customized content of the corresponding slot specified externally
  • width: StringField control width
  • minWidth: StringMinimum width of field control
  • colspan: NumberShare of field controls
  • privateEvents: Array Field control allows events to be dispatched externally. These events will finally be aggregated and dispatched externally through action events
  • privateProps: Object The private personalization property configuration of the field control depends on the specific control

CurdForm

The following is an example of CurdForm usage.

  <template>
    <curd-form
      :field-config="config"
      :label-width="labelWidth"
      :column-num="columnNum"
      @action="actionHandler"
      @update="updateHandler"
    >
    </curd-form>
  </template>
  <script>
    exoprt default {
      data: {
        config: [
          {
            colspan: 1
            default: ""
            disabled: true
            label: "userName"
            minWidth: 86
            placeholder: "please input user name"
            privateEvents: ['input', 'change']
            prop: "userName"
            show: true
            slot: ""
            widget: "ElInput"
          },
          {
            colspan: 1
            default: ""
            disabled: true
            label: "score"
            minWidth: 86
            privateEvents: ['change']
            prop: "score"
            show: true
            slot: ""
            widget: "ElRate"
          }
        ],
        labelWidth: '100px',
        columnNum: 4
      },
      methods: {
        actionHandler({eventType, field, model, data}) {
          // when the form has been operated do something
        },
        updateHandler(data) {
          // when the from data updated do something
        }
      }
    }
  </script>

CurdForm Propertys

propertyNametypedefaultdescription
fieldConfigFieldConfig--Form configuration information
labelWidthstring--Form item label width
rulesobject--Form verification rules
columnNumnumber6Form layout rules, specifying how many columns are distributed in one row

CurdForm Events

eventNameargumentsdescription
action{eventType,field,model,data}eventType:The type of event received, field: Field configuration information, model:Form bound data, data: The data passed through the event is organized in the form of an array
updatedataTriggered when the data bound by the form is updated to pass the latest data

CurdForm Methods

methodNameargumentsreturnValuedescription
getModel--The data of formget form data
setModeldatavoidSet form data
updateModeldatavoidUpdate or merge form data
resetModeldatavoidReset form data
validatecallbackvoidVerify the data of the form, and execute callback to call back the verification result after verification
resetFields--voidReset the verification status of the form

CurdTable

The following is an example of CurdTable usage.

<template>
  <curd-table
    width="500px"
    height="500px"
    :field-config="config"
    @row-click="rowClickHandler"
    @update="updateHandler"
  ></curd-table>
</template>
<script>
  exoprt default {
    data: {
      config: [
        {
          colspan: 1
          default: ""
          disabled: true
          label: "userName"
          minWidth: 86
          prop: "userName"
          show: true
          slot: ""
          widget: ""
        },
        {
          colspan: 1
          default: ""
          disabled: true
          label: "age"
          minWidth: 86
          prop: "age"
          show: true
          slot: ""
          widget: ""
        },
        {
          colspan: 1
          default: ""
          disabled: true
          label: "sex"
          minWidth: 86
          prop: "sex"
          show: true
          slot: ""
          widget: ""
        }
      ]
    },
    methods: {
      rowClickHandler(row, column, event}) {
        // When a table row is clicked do something
      },
      updateHandler(data) {
        // when the from data updated do something
      }
    }
  }
</script>

CurdTtable Propertys

propertyNametypedefaultdescription
fieldConfigFieldConfig--Table configuration information
fetchMethodFunction({page,pageSize, resolve})--Method of loading data, it must return a promise object
widthString,Number100%width of table
heightString,Number100%height of table
showSummaryBooleantrueShow statistics column of table
summaryMethodFunction({columns, data})--Methods for statistical data
spanMethodFunction({ row, column, rowIndex, columnIndex })--How to merge cells
rowStyleFunction({row, rowIndex})/Object--How to style within a table row
cellStyleFunction({row, column, rowIndex, columnIndex})/Object--How to style within a table cell
rowClassNameFunction({row, rowIndex})/String--How to set table row style class
cellClassNameFunction({row, column, rowIndex, columnIndex})/String--How to set table row cell class
pageAbleBooleantrueWhether to open pagination in the table
indexAbleBooleanfalseWhether to open sequential index for table
selectAbleBooleanfalseWhether the multi selection function is enabled for the table
stripleBooleantrueDraw border for table
selectOnClickRowBooleanfalseSelect the row when click it
highlightCurrentRowBooleantruecurrent row is hightlight
editTypeStringstright-editEdit type of table, These types are supported: stright-edit、inline-edit、dialog-edit、no-edit
saveMethodFunction(data)--The save data callback method will return the data to be saved for use
fetchDictionaryMethodFunction(dicFieldName)--Method of querying dictionary
transformDictionaryMethodFunction(value, dicData)--Methods of dictionary translation
valueArray--Data passed into table, Effective when requesttype is outside
requestTypeStringinsideRoute of incoming data, Value takes effect when requesttype is outside, and fetchmethod takes effect when requesttype is inside

CurdTable Events

eventNameargumentsdescription
page-changepageNumTriggered when turning pages
selection-changeselectionTriggered when the selection status changes
row-clickrow, column, eventTriggered when you left-click a row
row-dblclickrow, column, eventTriggered when a row is double clicked
cell-clickrow, column, cell, eventTriggered when a cell is clicked
cell-dblclickrow, column, cell, eventTriggered when a cell is double clicked
row-contextmenurow, column, eventTriggered when the menu is right clicked
header-clickcolumn, eventTriggered when the header is clicked
header-contextmenucolumn, eventTriggered when you right-click the header
current-changecurrentRow, oldCurrentRowTriggered when the selected row changes
sort-change{ column, prop, order }Triggered when the sort changes
filter-changefiltersTriggered when the filter condition changes
expand-changerow, expandedRows, expandedTriggered when a row is expanded
selectselection, rowTriggered on manual selection
select-allselectionTriggered when manually selecting all

CurdTable Methods

methodNameargumentsreturnValuedescription
getPage--The page info of tableget page info
editData--voidEdit table data in corresponding forms according to different edittypes
insertRowrow,argvoidInsert a new row into the table. The row defaults to empty row data. Arg can be Boolean or numeric. When arg is true, it means inserting at the head, when arg is false, it means inserting at the tail, and when arg is a specified number, it means inserting at the specified index position
removeRowargvoidTo delete a specified row in a table, Arg can be transferred to a number or a data object. If it is transferred to a number, it means to delete the specified index row. If it is transferred to a data object, it means to delete the specified data row
getSelection--selectionGets the selected data row
removeSelectionRow--voidDelete the selected data row. It takes effect when selectable is true
exportExcelfilenamevoidExport tabular data to excel file
request--voidRequest data of the table
refresh--voidRefresh tabular data to excel file
setDatadatavoidSet data for table
clearData--voidClear table data
getData--dataGet table data
clearSelection--viodClear selected status
toggleRowSelectionrow, checkedviodToggles the selected state of the table row
toggleRowSelectionrow, checkedviodToggles the selected state of the table row
toggleAllSelection--viodToggle select all status
toggleRowExpansionrow, expandedviodToggles the expanded state of rows
setCurrentRowrowviodSets the currently selected row
clearSort--viodClear sort status
clearFilter--viodClear filter status
doLayout--viodTable redrawing and rearrangement
sortprop, orderviodSort the data in the table
validatecallbackviodAfter verifying the data in the table, callback will be called to transfer out the verification status
1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.2.1

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago