UNPKG

@antmjs/vantui

Version:

一套适用于Taro3及React的vantui组件库

109 lines 3.5 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /* eslint-disable */ import react from 'react'; import { View } from '@tarojs/components'; import { Table } from '@antmjs/vantui'; import { jsx as _jsx } from "react/jsx-runtime"; var columns = [{ title: '姓名', dataIndex: 'name', fixed: 'left', render: function render(val) { return /*#__PURE__*/_jsx(View, { style: { color: '#2196F3' }, children: val }); } }, { title: '年龄', dataIndex: 'age', align: 'center', sort: true }, { title: '账户', dataIndex: 'account', sort: true }, { title: '住址', dataIndex: 'address' }, { title: '爱好', dataIndex: 'hobby' }]; export default function Demo() { var _react$useState = react.useState({ dataSource: [], loading: false }), _react$useState2 = _slicedToArray(_react$useState, 2), state = _react$useState2[0], changeState = _react$useState2[1]; var setState = function setState(stateNew) { changeState(_objectSpread(_objectSpread({}, state), stateNew)); }; react.useEffect(function () { setState({ loading: true }); setTimeout(function () { setState({ loading: false, dataSource: [{ key: '1', name: '胡彦斌', age: 37, account: 20000, address: '西湖区湖底公园1号', hobby: '唱歌跳舞唱歌跳舞' }, { key: '2', name: '吴亦凡', age: 32, account: 50000, address: '朝阳区派出所', hobby: '嗨嗨啊嗨嗨嗨啊嗨' }, { key: '36', name: '王宝强', age: 31, account: 40000, address: '嘟嘟嘟嘟一号', width: 200, hobby: '休息♨️休息♨️休息♨️休息♨️休息♨️' }] }); }, 2000); }, []); var sortAction = function sortAction(col) { var sortOrder = col.sortOrder, dataIndex = col.dataIndex; var dataSource = state.dataSource; if (sortOrder !== 'descend') { dataSource.sort(function (a, b) { return a[dataIndex] - b[dataIndex]; }); } else { dataSource.sort(function (a, b) { return b[dataIndex] - a[dataIndex]; }); } setState({ dataSource: dataSource }); }; return /*#__PURE__*/_jsx(Table, { columns: columns, dataSource: state.dataSource, sortChange: sortAction, loading: state.loading, scroll: { x: 500 }, rowKey: "title" }); }