1.0.2-alpha.3 • Published 5 years ago

chat-vue v1.0.2-alpha.3

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

chat-vue

一、使用指南

1.install(安装)

yarn add chat-vue / npm i chat-vue

2.import(引入)

在vue项目中main.js写入

import 'chat-vue/dist/chat.css';

3.use(使用)

在使用chat-vue的组件中写入

<template>
  // ...
  <chat :messageList="messageList" @onMessagePost="postHandler" >
    <template v-slot:slotName="{message}">
      <div>{{message.id}}</div>
    </template>
  </chat>
  // ...
</template>
// ...
import chat from "chat-vue";
export default {
  components: {
    chat
  },
  data() {
    return {
      messageList: [{
        id: 0,
        content: "您好!欢迎使用chat-vue"
      }, {
        id: 1,
        type: 'html',
        content: '<div>...</div>
      }, {
        id: 2,
        type: 'guess',
        content: '...',
        replyList: [{
          title: '...',
          value: '...'
        }]
      }, {
        id: 3,
        type: 'replyList',
        replyList: [{
          title: '...',
          value: '...'
        }]
      }, {
        id: 4,
        type: 'img',
        src: '...'
      }, {
        id: 5,
        type: 'video',
        src: '...'
      }, {
        id: 6,
        type: 'link',
        title: '...',
        desc: '...',
        url: '...'
      }, {
        id: 7,
        slot: 'slotName'
      }]
    }
  },
  methods: {
    postHandler(userInput) {
      this.messageList.push({
        id: Math.random(),
        role: 'user',
        content: userInput
      })
      setTimeout(() => {
        this.messageList.push({
          id: Math.random(),
          content: `为您找到问题'${userInput}'的解决方案是...` 
        })
      }, 1000);
    }
  }
}

4. 属性和事件补充说明

4.1 属性

属性名说明类型默认值
messageList消息数据(详情参考4.1.1Array[]
tagList推荐标签({value: '标签1', ...)Array[]
relationList输入联想问题列表Array[]
config配置集合(详情参考4.1.3Object{theme: "modern", placeholder: '请输入'}
4.1.1 messageList的元素
属性名说明类型默认值
id唯一标识NumberString
text文本内容String
html带有html的富文本内容String
type消息类型(可选值:text, html, replyList, guess, img, video, linkStringtext
role消息所属角色(user(用户, 右侧展示), service(客服,左侧展示))|StringString
replyList推荐问题列表{value: '问题1', ...}, ...Array
feedback赞、踩选中记录Number
noFeedback是否展示‘赞、踩’Boolean
metaInfo消息元数据(详情参考4.1.1.1)Object
src当type为'img'时才生效,图片地址String
src当type为'video'时才生效,视频地址String
title当type为'link'时才生效,链接标题String
desc当type为'link'时才生效,链接描述String
url当type为'link'时才生效,链接跳转地址String
slot当写入slot属性时,该条消息渲染模版会匹配插槽中的内容String
4.1.1.1 metaInfo的属性
属性名说明类型默认值
nickname昵称String
time时间String
4.1.2 config
属性名说明类型默认值
theme主题;可选值:modernbasicStringmodern
serviceIcon客服头像(为真值时展示客服头像)String
userIcon用户头像(为真值时展示用户头像)String
placeholder输入框占位内容String请输入
noScroll是否禁止滚动区自动滚动Boolean
pulldownConfig下拉加载配置(详情参考4.1.2.1Object
pullupConfig上拉加载配置(详情参考4.1.2.1Object
showFeedback是否需要“赞、踩功能”Boolean
4.1.2.1 config.pulldownConfig和config.pullupConfig
属性名说明类型默认值
disabled是否禁用功能Booleantrue
loadingIcon加载图标String
pullText拉动时的文字String
loadingText加载时的文字String
noMoreText没有更多时的文字String
noMoreData是否没有更多了Boolean
boundaryDistance触发加载的边界距离Number
callback加载时需要处理的回调函数(该函数需返回Promise)Function: Promise

4.2 事件

事件名说明参数
onMessagePost用户点击发送按钮或按下回车键后触发用户输入的文本
quickReply用户点击推荐问题列表中的问题后触发参数为推荐问题数组(replyList)中对应点击的元素
quickTag用户点击推荐标签列表中的标签后触发参数为推荐标签数组(tagList)中对应点击的元素
feedback用户点击消息下方的‘赞、踩’按钮参数1,2分别为消息id和反馈类型(0: 赞、1:踩)
onInputChanged输入框change触发,获取到输入框的value参数为输入框的value
onAssociationProblemSelect点击输入联想问题调用此函数,返回该问题对应的对象参数为联想问题数组(relationList)中对应点击的元素

其它示例

1 下拉加载(1. 将config传给chat组件;2. 在config中写入pulldownConfig对象;3. 在pulldownConfig配置callback函数)

<template>
  // ...
  <chat :messageList="messageList" :config="config" @onMessagePost="postHandler" />
  // ...
</template>
// ...
import chat from "chat-vue";
export default {
  components: {
    chat
  },
  data() {
    return {
      messageList: [{
        id: 0,
        content: "您好!欢迎使用chat-vue"
      }],
      config: {
        // 下拉加载的配置
        pulldownConfig: {
          callback: this.pulldownHandler
        }
      }
    }
  },
  methods: {
    postHandler(userInput) {
      this.messageList.push({
        role: 'user',
        content: userInput
      })
      setTimeout(() => {
        this.messageList.push({
          content: `为您找到问题'${userInput}'的解决方案是...` 
        })
      }, 1000);
    },
    // 下拉加载的回调函数
    pulldownHandler() {
      return new Promise(reslove => {
        setTimeout(() => {
          this.messageList.unshift({
            content: '下拉消息'
          })
          reslove()
        }, 1000);
      })
    }
  }
}
// ...

二、开发指南

规范

  1. 组件样式统一写入/src/less文件夹中的less文件,每个组件根元素声明一个类名来形成一个命名空间,统一使用cv-作为类名前缀
  2. 每个主题的样式对应/src/less/theme中的一个文件夹,由一个index.less引入该文件夹下所有子文件夹的index.less。应该最多包含这3个文件夹default、mobile、pc。每个子文件夹中的index.less引入该文件夹下的所有less文件

Project setup(运行、开发本项目)

yarn install

Compiles and hot-reloads for development

yarn serve

Compiles and minifies for production

yarn build

Lints and fixes files

yarn lint

Customize configuration

See Configuration Reference.

1.0.2-alpha.2

5 years ago

1.0.2-alpha.3

5 years ago

1.0.2-alpha.1

5 years ago

1.0.2-alpha.0

5 years ago

1.0.1-alpha.0

5 years ago

1.0.0

5 years ago

0.8.9-alpha.2

5 years ago

0.8.9-alpha.1

5 years ago

0.8.9-alpha.0

5 years ago

0.8.9

5 years ago

0.8.8

5 years ago

0.8.7

5 years ago

0.8.6-alpha.1

5 years ago

0.8.6-alpha.0

5 years ago

0.8.6

5 years ago

0.8.6-0

5 years ago

0.8.5

5 years ago

0.8.5-alpha.0

5 years ago

0.8.4

5 years ago

0.8.2-alpha.1

5 years ago

0.8.3

5 years ago

0.8.3-alpha.0

5 years ago

0.8.2

5 years ago

0.8.2-alpha.0

5 years ago

0.8.1

5 years ago

0.8.1-alpha.2

5 years ago

0.8.1-alpha.1

5 years ago

0.8.1-alpha.0

5 years ago

0.8.0

5 years ago

0.7.14-alpha.11

5 years ago

0.7.14-alpha.10

5 years ago

0.7.14-alpha.9

5 years ago

0.7.14-alpha.8

5 years ago

0.7.14-alpha.7

5 years ago

0.7.14-alpha.6

5 years ago

0.7.14-alpha.5

5 years ago

0.7.14-alpha.4

5 years ago

0.7.14-alpha.3

5 years ago

0.7.14-alpha.2

5 years ago

0.7.14-alpha.0

5 years ago

0.7.13

5 years ago

0.7.12

5 years ago

0.7.11

5 years ago

0.7.10

5 years ago

0.7.9

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

5 years ago

0.7.5

5 years ago

0.7.5-alpha.0

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1-alpha.3

5 years ago

0.7.1-alpha.2

5 years ago

0.7.1-alpha.1

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.3

5 years ago

0.6.1-alpha.3

5 years ago

0.6.2-alpha.0

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.1-alpha.2

5 years ago

0.6.1-alpha.1

5 years ago

0.6.1-alpha.0

5 years ago

0.6.0

5 years ago

0.5.3-alpha.0

5 years ago

0.5.0

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.4.1-alpha.4

5 years ago

0.4.1-alpha.3

5 years ago

0.4.2-alpha.0

5 years ago

0.4.1-alpha.2

5 years ago

0.4.1

5 years ago

0.4.1-alpha.3.0

5 years ago

0.4.1-alpha.2.0

5 years ago

0.4.1-alpha.1

5 years ago

0.4.1-alpha.0

5 years ago

0.4.0

5 years ago

0.3.18-alpha.3

5 years ago

0.3.20-alpha.0

5 years ago

0.3.18-alpha.2

5 years ago

0.3.18-alpha.0

5 years ago

0.3.19

5 years ago

0.3.18

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.13

5 years ago

0.3.12

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.0

5 years ago

0.3.1

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.3

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.0

5 years ago

0.2.2

5 years ago

0.1.33

5 years ago

0.1.31

5 years ago

0.1.32

5 years ago

0.1.30

5 years ago

0.1.29

5 years ago

0.1.28

5 years ago

0.1.27

5 years ago

0.1.26

5 years ago

0.1.25

5 years ago

0.1.23

5 years ago

0.1.24

5 years ago

0.1.20

5 years ago

0.1.21

5 years ago

0.1.22

5 years ago

0.1.17

5 years ago

0.1.18

5 years ago

0.1.19

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.4

5 years ago

0.1.5

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago