npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mnlm/element-plus

v0.1.18

Published

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

Downloads

9

Readme

前言

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>