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

ha-comment

v1.3.7

Published

## Project setup ``` npm install ```

Downloads

9

Readme

ha-comment

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Lints and fixes files

npm run lint

Customize configuration

See Configuration Reference.

discription

//版本1.3.4为增加更多表情选择。后续更新会根据实际业务需要做迭代;


npm install [email protected]

import HaComment from 'ha-comment';

Vue.use(HaComment)

//组件配置说明:
         :total="total"//总条数
        :img="img" //发表评论的头像
        :list="treeList" //数据
        :love="true"   //点赞功能
        :isonlysecond="true"  //是否开启,true二级树展示,和当前抖音,知乎展示一样。 false为多级树展示。数据结构会有所改变
        user="陈雨"   //当前用户
        @operate="handleOperate"   //操作后调用接口处理逻辑
            ],
            pparentid:''          
        };
    },
        computed:{
            total(){
            
                const total= this.handleTotal(this.treeList);
                return  total
            }
        },
   
      methods: {
          /* pdf,word组件渲染完毕 */
        rendered() {
            // this.loading = false;
          },
          /* pdf,word组件渲染出错 */
        HandlError() {
          
            // this.loading = false;
          },
        uuidv4() {
            let d = new Date().getTime(); //Timestamp
            let d2 = (performance && performance.now && (performance.now()*1000)) || 0; 
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
                var r = Math.random() * 16; //random number between 0 and 16
                if(d > 0) { //Use timestamp until depleted
                    r = (d + r)%16 | 0;
                    d = Math.floor(d/16);
                } else { //Use microseconds since page-load if supported
                    r = (d2 + r)%16 | 0;
                    d2 = Math.floor(d2/16);
                }
                return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
            });
        },
        handleTotal(tlist){
          const arr1=[]
            if (tlist && Array.isArray(tlist)) {
                const forFn = (arr) => {
                    for (let i = 0; i < arr.length; i++) {
                        const item = arr[i];
                        arr1.push(item)
                        if (item && Array.isArray(item.children)) {
                            forFn(item.children);
                        }
                    }
                };
                forFn(tlist);
            }
            return arr1.length
        },
        handRefreshList (tlist) {
            if (tlist && Array.isArray(tlist)) {
                const forFn = (arr) => {
                    for (let i = 0; i < arr.length; i++) {
                        const item = arr[i];
                        item.inputContent = '';
                        item.commentItemVisible = false;
                        item.Recall = false;
                        if (item && Array.isArray(item.children)) {
                            forFn(item.children);
                        }
                    }
                };
                forFn(tlist);
            }
            return tlist
        },
        handleTreeFind (tlist, id) {
            if (tlist && Array.isArray(tlist)) {
                const forFn = (arr) => {
                    for (let i = 0; i < arr.length; i++) {
                        const item = arr[i];
                        if (item.id == id) {
                            if (item.count && Array.isArray(item.children) && item.children.length == 0) {
                                item.count = 0
                            }
                        }
                        if (item && Array.isArray(item.children)) {
                            forFn(item.children);
                        }
                    }
                };
                forFn(tlist);
            }
            return tlist
        },
        handleDeleteTreeList (tlist, id) { // 删除评论,数据重组
            if (tlist && Array.isArray(tlist)) {
                const forFn = (arr) => {
                    for (let i = 0; i < arr.length; i++) {
                        const item = arr[i];

                        if (item.id == id) {
                            arr.splice(i--, 1)

                            if (arr.length > 0) {
                                arr[arr.length - 1].showMuch = false;
                            }
                            return false;
                        }
                        if (item && Array.isArray(item.children)) {
                            forFn(item.children);
                        }
                    }
                };
                forFn(tlist);
            }
            return tlist
        },
        handleInsertTreeList (tlist, id, childs) { // 插入数据
            if (tlist && Array.isArray(tlist)) {
                const forFn = (arr) => {
                    for (let i = 0; i < arr.length; i++) {
                        const item = arr[i];

                        if (item.id == id) {
                            item.children.push(...childs)

                            return false;
                        }
                        if (item && Array.isArray(item.children)) {
                            forFn(item.children);
                        }
                    }
                };
                forFn(tlist);
            }
            return tlist
        },
        handleInsertMiddle(list,item,Index){
            list.splice(Index+1, 0, item);
            return this.treeList
        },
        handleHasOnlysecond(item){//二级树展示
          if (!item.isHead && item.type == 'add') { // 新增子级评论
                    if(item.pid==-1){
                      this.pparentid=item.id;
                    }else{
                      this.pparentid= item.pparentid
                    }

                    const uuid = this.uuidv4()
                    const o = {
                        userName: '曾程',
                        imgUrl: require('@/img/avtar.png'),
                        message: item.inputContent,
                        placeholder: '回复曾程',
                        parentName: item.userName,
                        inputContent: '',
                        id: 'sive' + uuid,
                        pid: item.id,
                        hour: '2小时前',
                        pparentid:this.pparentid,
                        children: [],
                        likeList: [],
                        count: 1
                    }
               
                    
                    if (item.pid==-1&& Array.isArray(item.children)) {
                        item.children.unshift(o)
                    }else if(item.pid!=-1){
                      const Index=  this.treeList.findIndex(val=>val.id==this.pparentid);
                      if(this.treeList[Index]&&Array.isArray(this.treeList[Index].children)){
                        if(this.treeList[Index].children.length==0){
                          this.treeList[Index].children.push(o);
                          this.treeList=_.cloneDeep(this.treeList);
                        }else{
                          const cout=this.treeList[Index].children.findIndex(val=>val.id==item.id)
                          this.treeList=this.handleInsertMiddle(this.treeList[Index].children,o,cout);//插入数据

                        }
                      } 
                    }

                     this.$check.flag = true;// 接口加载时候使用设为true即可
            }


            if (item.type == 'much') { // 加载更多

              const uuid = this.uuidv4()
                const inputObj = {
                    userName: '陈雨',
                    imgUrl: require('@/img/avtar.png'),
                    message: 'fsdjfksdlfjs',
                    inputContent: '',
                    placeholder: '回复陈雨',
                    parentName: item.pid != -1 ? item.parentName : '',
                    id: uuid,
                    pid: item.pid,
                    pparentid:item.pparentid,
                    hour: '1分钟前',
                    children: [],
                    likeList: []
                }

              if (item.pid == -1) {
                      this.treeList.push(inputObj);
                  }else if(item.pid!=-1){
                      const Index=  this.treeList.findIndex(val=>val.id==item.pparentid);
                      if(this.treeList[Index]&&Array.isArray(this.treeList[Index].children)){
                          this.treeList[Index].children.push(inputObj);
                          this.treeList=_.cloneDeep(this.treeList);
                        
                      } 
                }   
            }

            if (item.type == 'display') { // 展开收起
                const uuid = this.uuidv4()
                if(item.pid==-1){
                  this.pparentid=item.id;
                }
                const o = {
                    userName: '曾程',
                    imgUrl: require('@/img/avtar.png'),
                    message: '我很相信你,你是真的good very',
                    parentName: item.userName,
                    placeholder: '回复曾程',
                    inputContent: '',
                    pparentid:this.pparentid,
                    id: uuid,
                    pid: item.id,
                    hour: '2小时前',
                    children: [],
                    likeList: [],
                    count: 1
                }


                if (item.pid==-1&& Array.isArray(item.children)&&item.children.length==0) {
                    item.children.unshift(o)
                }

                if (item.display) { // 模拟
                    this.$check.flag = true;// 接口加载时候使用设为true即可
                } else {
                    this.$check.flag = true;// 接口加载时候使用设为true即可
                }

           }  
        },
        handleNoOnlysecond(item){//非二级树展示
          if (!item.isHead && item.type == 'add') { // 新增子级评论
                //不开启二级树加载时候
                    console.log('子级评论')
                    const uuid = this.uuidv4()
                    const inputObj = {
                        userName: '陈雨',
                        imgUrl: require('@/img/avtar.png'),
                        message: item.inputContent,
                        parentName: item.userName,
                        inputContent: '',
                        placeholder: '回复陈雨',
                        id: uuid,
                        pid: item.id,
                        hour: '1分钟前',
                        children: [],
                        likeList: []
                    }
                    const o = {
                        userName: '曾程',
                        imgUrl: require('@/img/avtar.png'),
                        message: '我很相信你,你是真的good very',
                        placeholder: '回复曾程',
                        parentName: item.userName,
                        inputContent: '',
                        id: 'sive' + uuid,
                        pid: item.id,
                        hour: '2小时前',
                        children: [],
                        likeList: [],
                        count: 1
                    }
                    // 存在count>0  ,children==0 时候加载数据

                    if (item.count && (Array.isArray(item.children) && item.children.length == 0)) { // 表示之前有一条数据
                        item.children.push(o)
                    }

                    if (Array.isArray(item.children)) {
                        item.children.unshift(inputObj)
                    }

                     this.$check.flag = true;// 接口加载时候使用设为true即可
            }
          if (item.type == 'much') { // 加载更多

            const uuid = this.uuidv4()
                const inputObj = {
                    userName: '陈雨',
                    imgUrl: require('@/img/avtar.png'),
                    message: 'fsdjfksdlfjs',
                    inputContent: '',
                    placeholder: '回复陈雨',
                    parentName: item.pid != -1 ? item.parentName : '',
                    id: uuid,
                    pid: item.pid,
                    pparentid:item.pparentid,
                    hour: '1分钟前',
                    children: [],
                    likeList: []
                }

            if (item.pid == -1) {
                this.treeList.push(inputObj);
            } else {
                // 为children寻找同级
                this.handleInsertTreeList(this.treeList, item.pid, [
                    inputObj
                ])
            }     
          }
          if (item.type == 'display') { // 展开收起
            const uuid = this.uuidv4()
                if(item.pid==-1){
                  this.pparentid=item.id;
                }
                const o = {
                    userName: '曾程',
                    imgUrl: require('@/img/avtar.png'),
                    message: '我很相信你,你是真的good very',
                    parentName: item.userName,
                    placeholder: '回复曾程',
                    inputContent: '',
                    pparentid:this.pparentid,
                    id: uuid,
                    pid: item.id,
                    hour: '2小时前',
                    children: [],
                    likeList: [],
                    count: 1
                }
                // 存在count>0  ,children==0 时候加载数据
                if (item.count && (Array.isArray(item.children) && item.children.length == 0)) {
                     item.children.push(o)
                }

                if (item.display) { // 模拟
                    this.$check.flag = true;// 接口加载时候使用设为true即可
                } else {
                    this.$check.flag = true;// 接口加载时候使用设为true即可
                }
          }
        },
        handleOperate (item) {
            this.$check.flag = false;// 接口加载时候使用设为true即可
            if (item.isHead && item.type == 'add') { // 首级发表评论
                console.log('首级发表评论')
                const uuid = this.uuidv4()
                const inputObj = {
                    userName: '陈雨',
                    imgUrl: require('@/img/avtar.png'),
                    message: item.message,
                    inputContent: '',
                    placeholder: '回复陈雨',
                    id: uuid,
                    pid: item.pid,
                    hour: '1分钟前',
                    children: [],
                    likeList: []
                }

                this.treeList.unshift(inputObj);
                this.$check.flag = true;// 接口加载时候使用设为true即可
            }
            if (!item.isHead && item.type == 'add') { // 新增子级评论
                if(this.$check.isonlysecond){//如果开启只能为二级树
                   this.handleHasOnlysecond(item)
                  }else{//不开启二级树加载时候
                   this.handleNoOnlysecond(item)
               }
            }

            if (item.type == 'refresh') { // 刷新评论
              this.treeList= this.handRefreshList(this.treeList);
                this.$check.flag = true;

                console.log('刷新评论')
            }
            if (item.type == 'delete') { // 删评论
                const pid = item.pid;
                this.handleDeleteTreeList(this.treeList, item.id);
                this.handleTreeFind(this.treeList, pid);

                this.$check.flag = true;// 接口加载时候使用设为true即可
            }
            if (item.type == 'much') { // 加载更多
                if(!this.$check.isonlysecond){//存在多级加载
                  this.handleNoOnlysecond(item)
                }else{//只存在二级
                   this.handleHasOnlysecond(item)
                }

                this.$check.flag = true;// 接口加载时候使用设为true即可
            }
            if (item.type == 'display') { // 展开收起
           
                if(!this.$check.isonlysecond) {//可以多级
                  this.handleNoOnlysecond(item)
                }else{//只存在二级
                 this.handleHasOnlysecond(item)
                }
             
            
                console.log(item.display + 'display')
            }

            if (item.type == 'like') { // 点赞操作
                this.$check.flag = true;// 接口加载时候使用设为true即可
            }
        }
    }
};