0.1.18 • Published 2 months ago

@mnlm/element-plus v0.1.18

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

前言

mnlm 系列组件的基于 elment-plus 的实现

链接

element-plus

example

使用

  1. 声明实体类
// model/User.d.ts

/**
 * 用户
 */
export type User = {
  /**
   * uuid
   */
  uuid: string

  /**
   * 用户名
   */
  username: string

  /**
   * 密码
   */
  password: string

  /**
   * 性别
   */
  sex: string

  /**
   * 手机号
   */
  mobile: number

  /**
   * 年龄
   */
  age: number

  /**
   * 地区
   */
  areaCode: string

  areaName: string

  /**
   * 部门
   */
  deptUuid: string

  deptName: string

  /**
   * 岗位
   */
  postUuid: string

  postName: string

  /**
   * 数据权限
   */
  dataScope: string

  /**
   * 角色
   */
  roleUuid: string

  roleName: string

  /**
   * 入职时间
   */
  joinTime: string

  /**
   * 是否在职
   */
  inWork: boolean

  /**
   * 是否启用
   */
  state: boolean

  /**
   * 头像
   */
  avatar: string

  /**
   * 备注
   */
  remark: string
}
  1. 创建 schema
// schema/user.ts

import { WoodSchema } from '@mnlm/element-plus'
import type { User } from '../model/User'
import * as deptService from '../service/dept'
import * as postService from '../service/post'
import * as dictService from '../service/dict'
import * as areaService from '../service/area'
import * as roleService from '../service/role'

export const userSchema: WoodSchema<User>[] = [
  {
    dataIndex: 'uuid',
    valueType: 'text',
    title: 'uuid',
    colProps: {
      span: 8,
    },
  },
  {
    dataIndex: 'username',
    valueType: 'text',
    title: '用户名',
    colProps: {
      span: 8,
    },
  },
  {
    dataIndex: 'password',
    valueType: 'text',
    title: '密码',
    rule: [],
    colProps: {
      span: 8,
    },
    fieldProps: {
      type: 'password',
    },
  },
  {
    dataIndex: 'sex',
    valueType: 'select',
    title: '性别',
    valueEnum: [
      {
        value: 'M',
        label: '男',
      },
      {
        value: 'W',
        label: '女',
      },
    ],
  },
  {
    dataIndex: 'mobile',
    valueType: 'digit',
    title: '手机号',
    rule: [],
  },
  {
    dataIndex: 'age',
    valueType: 'digit',
    title: '年龄',
  },
  {
    dataIndex: 'areaCode',
    valueType: 'treeSelect',
    title: '地区',
    request: () => {
      return areaService.treeList()
    },
    tableColumnProps: {
      cellRender(grain) {
        return grain.areaName
      },
    },
  },
  {
    dataIndex: 'areaName',
    valueType: 'text',
    title: '地区',
    readonly: true,
    link: {
      areaCode(cattle) {
        const tempArea = cattle.getWood('areaCode')?.getTempValue()
        cattle.getWood('areaName')?.setInnerValue(tempArea?.name)
      },
    },
    formItemProps: {
      hidden: true,
    },
    tableColumnProps: {
      hidden: true,
    },
  },
  {
    dataIndex: 'deptUuid',
    valueType: 'select',
    title: '部门',
    request: deptService.list,
    tableColumnProps: {
      cellRender(grain) {
        return grain.deptName
      },
    },
  },
  {
    dataIndex: 'deptName',
    valueType: 'text',
    title: '部门名称',
    readonly: true,
    link: {
      deptUuid(cattle) {
        const tempDept = cattle.getWood('deptUuid')?.getTempValue()
        cattle.getWood('deptName')?.setInnerValue(tempDept?.label)
      },
    },
    formItemProps: {
      hidden: true,
    },
    tableColumnProps: {
      hidden: true,
    },
  },
  {
    dataIndex: 'postUuid',
    valueType: 'select',
    title: '岗位',
    request: (cattle) => postService.list(cattle.getInnerValue('deptUuid')),
    link: {
      deptUuid(cattle) {
        cattle.getWood('postUuid')?.clean()
      },
    },
    tableColumnProps: {
      cellRender(grain) {
        return grain.postName
      },
    },
  },
  {
    dataIndex: 'postName',
    valueType: 'text',
    title: '岗位名称',
    readonly: true,
    link: {
      postUuid(cattle) {
        const tempPost = cattle.getWood('postUuid')?.getTempValue()
        cattle.getWood('postName')?.setInnerValue(tempPost?.label)
      },
    },
    formItemProps: {
      hidden: true,
    },
    tableColumnProps: {
      hidden: true,
    },
  },
  {
    dataIndex: 'dataScope',
    valueType: 'select',
    title: '数据权限',
    request: dictService.dataScope,
  },
  {
    dataIndex: 'roleUuid',
    valueType: 'select',
    title: '角色',
    formItemProps: {
      hidden: true,
    },
  },
  {
    dataIndex: 'roleName',
    valueType: 'fuzzy',
    title: '角色名称',
    request: (_, { keyWord }) => {
      return roleService.list()
    },
  },
  {
    dataIndex: 'joinTime',
    valueType: 'date',
    title: '入职时间',
  },
  {
    dataIndex: 'inWork',
    valueType: 'switch',
    title: '是否在职',
  },
  {
    dataIndex: 'remark',
    valueType: 'textarea',
    title: '备注',
  },
]
  1. 创建(木牛)表单
<template>
  <CattleForm ref="cattle" :schema="userSchema" />
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { CattleForm, CattleFormInstance } from '@mnlm/element-plus'
import { User } from '../model/User'
import { userSchema } from '../schema/user'

const cattle = ref<CattleFormInstance<User>>()
</script>
  1. 创建(流马)表格
// schema.ts

import { HorseSchema, Wood } from '@mnlm/element-plus'
import { User } from '../model/User'
import * as userService from '../service/user'
import { userSchema } from '../schema/user'
import { ElMessageBox } from 'element-plus'

const userCattle = Wood.group(userSchema, [
  'username',
  'sex',
  'age',
  'mobile',
  'areaCode',
  'areaName',
  'deptUuid',
  'deptName',
  'postUuid',
  'postName',
  'dataScope',
  'roleName',
  'joinTime',
  'inWork',
  'remark',
])

export const userHorseSchema: HorseSchema<User> = {
  grainKey: 'uuid',

  loadData: userService.list,

  editConfig: {
    enabled: true,
    single: true,
    trigger: 'click',
    mode: 'row',
    saveTrigger: 'blur',
    async execute({ horse, cattles }) {
      for (let i = 0; i < cattles?.length; i++) {
        await userService.update({
          ...cattles[i].getInitialValues(),
          ...cattles[i].getInnerValues(),
        })
      }
      horse.update()
    },
  },

  columns: userCattle,

  controls: [
    {
      text: '编辑',
      board: {
        title: '编辑',
        content: [
          {
            cattle: userCattle,
          },
        ],
        footer: [
          {
            title: '取消',
            closeBoard: true,
          },
          {
            title: '确定',
            closeBoard: true,
            updateHorse: true,
            validate: true,
            execute(board, record: User) {
              const user = board.firstData<User>()!
              user.uuid = record.uuid
              userService.update(user)
            },
          },
        ],
      },
    },
    {
      text: '删除',
      prepare(horse) {
        ElMessageBox.confirm('是否确认删除?', '删除', {
          confirmButtonText: '取人',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          userService.remove(horse.getCurrentRecord()?.uuid)
          horse.update()
        })
      },
    },
  ],

  toolbar: [
    {
      text: '添加',
      board: {
        title: '添加',
        content: [
          {
            cattle: userCattle,
          },
        ],
        footer: [
          {
            title: '取消',
            closeBoard: true,
          },
          {
            title: '确定',
            closeBoard: true,
            updateHorse: true,
            validate: true,
            execute(board) {
              const user = board.firstData<User>()!
              userService.insert(user)
            },
          },
        ],
      },
    },
  ],
}
<template>
  <HorsePlus ref="horse" :schema="userHorseSchema" />
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { Horse, HorsePlus, HorsePlusInstance } from '@mnlm/element-plus'
import { User } from '../model/User'
import { userHorseSchema } from './schema'

const horse = ref<HorsePlusInstance<User>>()
</script>
0.1.16

2 months ago

0.1.17

2 months ago

0.1.18

2 months ago

0.1.10

6 months ago

0.1.11

6 months ago

0.1.12

6 months ago

0.1.13

5 months ago

0.1.14

5 months ago

0.1.15

5 months ago

0.1.8

6 months ago

0.1.7

6 months ago

0.1.9

6 months ago

0.1.4

7 months ago

0.1.3

9 months ago

0.1.6

6 months ago

0.1.5

6 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.0.65

12 months ago

0.0.66

12 months ago

0.0.64

1 year ago

0.0.63

1 year ago

0.0.62

1 year ago

0.0.61

1 year ago

0.0.60

1 year ago

0.0.59

1 year ago

0.0.58

1 year ago

0.0.57

1 year ago

0.0.56

1 year ago

0.0.55

1 year ago

0.0.54

1 year ago

0.0.53

1 year ago

0.0.52

1 year ago

0.0.51

1 year ago

0.0.50

1 year ago

0.0.49

1 year ago

0.0.48

1 year ago

0.0.47

1 year ago

0.0.46

1 year ago

0.0.45

1 year ago

0.0.44

1 year ago

0.0.43

1 year ago

0.0.42

1 year ago

0.0.41

1 year ago

0.0.40

1 year ago

0.0.39

1 year ago

0.0.38

1 year ago

0.0.37

1 year ago

0.0.36

1 year ago

0.0.35

1 year ago

0.0.34

1 year ago

0.0.33

1 year ago

0.0.32

1 year ago

0.0.31

1 year ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago