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

@vinojs/pharos-organization-pc

v1.0.4

Published

- 类钉钉组织架构组件 - 支持选择人员,部门 - 支持多选,单选 - 支持异步加载数据

Downloads

4

Readme

@hjxz/pharos-organization-pc

  • 类钉钉组织架构组件
  • 支持选择人员,部门
  • 支持多选,单选
  • 支持异步加载数据

Useage

install

pnpm i @hjxz/pharos-organization-pc
<script lang="ts" setup>
import { Button } from 'ant-design-vue'
import { ref, unref } from 'vue'
import type { OrganizationItem } from '@hjxz/pharos-organization-pc'
import { PharosOrganizationPc, useOrganization } from '@hjxz/pharos-organization-pc'
import '@hjxz/pharos-organization-pc/dist/style.css'

import { data } from './mockData.json'

async function getData() {
  // 模拟请求
  return await new Promise<Array<any>>((resolve) => {
    setTimeout(() => {
      resolve(data)
    }, 4000)
  })
}
const checkedList = ref<Array<OrganizationItem>>([])
const [register, { open, setCheckedList }] = useOrganization({
  api: getData,
  beforeClose: async () => {
    return await new Promise<boolean>((resolve) => {
      setTimeout(() => {
        resolve(true)
      }, 3000)
    })
  },
})
const handleSuccess = (data: Array<OrganizationItem>) => {
  checkedList.value = data
}

const handleOpen = () => {
  open(() => setCheckedList(unref(checkedList).map(i => i.id)))
}
</script>

<template>
  <PharosOrganizationPc @register="register" @success="handleSuccess">
    <Button @click="handleOpen">
      open
    </Button>
  </PharosOrganizationPc>
</template>

Tips: 接口返回的数据以下字段是必须的

interface Item {
  id: string
  parentId: string
  name: string
  type: 0 | 1
}

当然也可以使用系统内置的节点类型

export interface OrganizationItem {
  id: string
  name: string
  parentId: string
  type: 0 | 1 // 区分时部门还是人员
  avatar?: string
  checked: boolean
  hasChildren: boolean
  searchStr: string
  disabled: boolean
}

props

api

数据源接口

  api: {
    type: Function as PropType<(arg?: any) => Promise<Record<string, any>[]>>,
    default: null,
  },
mode

选择模式

  // mode 选人模式,选部门模式,选人和部门模式。默认选人和部门模式
  mode: {
    type: String as PropType<'user' | 'dept' | 'default'>,
    default: 'default',
  }
checked

传入的已选择的Id数组

  checked: {
    type: Array as PropType<Array<string>>,
    default: () => [],
  },
disabled

禁止的Id 数组

  disabled: {
    type: Array as PropType<Array<string>>,
    default: () => [],
  },
single

是否单选

  // single 是否单选
  single: {
    type: Boolean,
    default: false,
  },
beforeClose

关闭前的钩子函数,返回 false 则不关闭 。用于处理异步接口操作

  beforeClose: {
    type: Function as PropType<() => Promise<boolean>>,
    default: null,
  },

useOrganization hook

const [register,action] = useOrganization(props)
Action
export interface PharosOrganizationPcAction {
  // 打开组织架构
  open: (fn: () => void) => void
  // 清空已选
  clearAllChecked: () => void
  // 获取已选
  getCheckedList: () => Array<OrganizationItem>
  // 设置已选
  setCheckedList: (list: string[]) => void
}