All Projects → doterlin → Vue Wxchat

doterlin / Vue Wxchat

❗❗ vue.js仿微信聊天界面展示组件(可滚动加载)。A WeChat chat display component.

Projects that are alternatives of or similar to Vue Wxchat

Mina Webpack
🍱 Mina single-file-component meets Webpack
Stars: ✭ 77 (-59.9%)
Mutual labels:  wechat, loader
React Redux Webpack Starter
Learning react
Stars: ✭ 189 (-1.56%)
Mutual labels:  loader
Gowechat
golang WeChat 封装,支持微信公众平台(订阅号,服务号)/微信商家平台/微信开放平台/微信企业号
Stars: ✭ 183 (-4.69%)
Mutual labels:  wechat
Wechat brain
知乎答题王(头脑王者)全自动答题辅助
Stars: ✭ 187 (-2.6%)
Mutual labels:  wechat
Ocskeleton
[OCSkeleton] - Make your loading view a little difference.
Stars: ✭ 184 (-4.17%)
Mutual labels:  loader
Weapp Mark
🔥 豆瓣类影视查询记录小程序,附学习笔记
Stars: ✭ 187 (-2.6%)
Mutual labels:  wechat
Purs Loader
PureScript loader for webpack
Stars: ✭ 182 (-5.21%)
Mutual labels:  loader
Pywavefront
Python library for importing Wavefront .obj files
Stars: ✭ 189 (-1.56%)
Mutual labels:  loader
Yii2 Easy Wechat
WeChat SDK for yii2 , based on overtrue/wechat.
Stars: ✭ 188 (-2.08%)
Mutual labels:  wechat
Vconsole
A lightweight, extendable front-end developer tool for mobile web page.
Stars: ✭ 14,017 (+7200.52%)
Mutual labels:  wechat
Wxpy
微信机器人 / 可能是最优雅的微信个人号 API ✨✨
Stars: ✭ 13,057 (+6700.52%)
Mutual labels:  wechat
Wechatvideocourse
《微信公众号+小程序快速开发》视频教程课件及代码
Stars: ✭ 185 (-3.65%)
Mutual labels:  wechat
Webpack2 Lessons
📖《webpack2 包教不包会》
Stars: ✭ 187 (-2.6%)
Mutual labels:  loader
Infinitescroll
Infinite Scroll (Endless Scrolling) for RecyclerView in Android
Stars: ✭ 183 (-4.69%)
Mutual labels:  scroll
React Indiana Drag Scroll
React component which implements scrolling via holding the mouse button or touch
Stars: ✭ 190 (-1.04%)
Mutual labels:  scroll
Tinyobjloader
Tiny but powerful single file wavefront obj loader
Stars: ✭ 2,363 (+1130.73%)
Mutual labels:  loader
Wechatminiprogram Shopping Mall
微信小程序的个体商店前端(以下面一个开源模板为基础)和Java后台(含mysql数据库文件)
Stars: ✭ 186 (-3.12%)
Mutual labels:  wechat
Wepy ios top
一款可以切换国家查看不同国家iOS应用排行榜的小程序
Stars: ✭ 187 (-2.6%)
Mutual labels:  wechat
Himalayan Lite
这是一个模仿喜马拉雅lite的微信小程序 - 简单易上手
Stars: ✭ 192 (+0%)
Mutual labels:  wechat
Enmicromsg.db Password Cracker
Crack the password of EnMicroMsg.db with brute-force attack.
Stars: ✭ 190 (-1.04%)
Mutual labels:  wechat

vue-wxchat

A WeChat front-end view component

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

For detailed explanation on how things work, consult the docs for vue-loader.

源码:https://github.com/doterlin/vue-wxChat 演示地址:https://doterlin.github.io/vue-wxChat/

演示截图

运行

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

介绍

  • 支持文本和图片的展示(后续将支持对语音类的展示)。
  • 支持滚动加载数据,其中滚动加载依赖我另外一个组件scrollLoader.vue(《Vue.js上下滚动加载组件》)。
  • 支持QQ表情,为了能使用表情请全局注册指令v-emotion,我在main.js做了实现;代码如下:
function toEmotion(text, isNoGif){
    var list = ['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴', '睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过', '酷', '冷汗', '抓狂', '吐', '偷笑', '愉快', '白眼', '傲慢', '饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂', '疑问', '嘘', '晕', '折磨', '衰', '骷髅', '敲打', '再见', '擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠', '鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', '可怜', '菜刀', '西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰', '凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀', '足球', '瓢虫', '便便', '月亮', '太阳', '礼物', '拥抱', '强', '弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你', 'NO', 'OK', '爱情', '飞吻', '跳跳', '发抖', '怄火', '转圈', '磕头', '回头', '跳绳', '挥手', '激动', '街舞', '献吻', '左太极', '右太极', '嘿哈', '捂脸', '奸笑', '机智', '皱眉', '耶', '红包', '鸡'];
    if (!text) {
        return text;
    }

    text = text.replace(/\[[\u4E00-\u9FA5]{1,3}\]/gi, function(word){
        var newWord = word.replace(/\[|\]/gi,'');
        var index = list.indexOf(newWord);
        var backgroundPositionX = -index * 24
        var imgHTML = '';
        if(index<0){
            return word;
        }

        if (isNoGif) {
            if(index>104){
                return word;
            }
            imgHTML = `<i class="static-emotion" style="background:url(https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/default218877.gif) ${backgroundPositionX}px 0;"></i>`
        } else {
            var path = index>104 ? '/img' : 'https://res.wx.qq.com/mpres/htmledition/images/icon';
            imgHTML = `![](${path}/emotion/${index}.gif)`
        }
        return imgHTML;
    });
    return text;
}


Vue.directive('emotion', {
    bind: function (el, binding) {
        el.innerHTML = toEmotion(binding.value)
    }
});

##如何使用? 参数已经在组件中做了说明,并在App.vue中做了演示: 参数和说明: 微信聊天可视化组件 依赖scrollLoader组件, 依赖指令v-emotion(实现请查看main.js)

参数width 组件宽度,默认450 wrapBg 外层父元素背景颜色,默认#efefef maxHeight 展示窗口最高高度, 默认900 contactAvatarUrl 好友头像url ownerAvatarUrl 微信主人头像url ownerNickname 微信主人昵称 getUpperData (必需)当滚动到上方时加载数据的方法,返回值要为Promise对象,resolve的结构同data getUnderData (必需)当滚动到下方时加载数据的方法,返回值同上 data (必需)传入初始化数据, 结构如下:

[{
    direction: 2, //为2表示微信主人发出的消息,1表示联系人
    id: 1, //根据这个来排序消息
    type: 1, //1为文本,2为图片
    content: '你好!![呲牙]', //当type为1时这里是文本消息,当type2为2时这里要存放图片地址;后续会支持语音的显示
    ctime: new Date().toLocaleString() //显示当前消息的发送时间
},
{
    direction: 1,
    id: 2,
    type: 1,
    content: '你也好。[害羞]',
    ctime: new Date().toLocaleString()
}]

完整的使用实例

效果:https://doterlin.github.io/vue-wxChat/ 代码:

//主文件,对wxChat的用法做示例

<template>
<wxChat 
  :data="wxChatData"
  :showShade="false"
  contactNickname="简叔"
  :getUpperData="getUpperData"
  :getUnderData="getUnderData"
  :ownerAvatarUrl="ownerAvatarUrl"
  :contactAvatarUrl="contactAvatarUrl"
  :width="420">
</wxChat>
</template>

<script>
import wxChat from './components/wxChat.vue'

export default {
  name: 'app',
  data () {
    return {
      upperTimes: 0,
      underTimes: 0,
      upperId: 0,
      underId: 6,
      ownerAvatarUrl: './src/assets/avatar1.png',
      contactAvatarUrl: './src/assets/avatar2.png',
      wxChatData: [{
        direction: 2,
        id: 1,
        type: 1,
        content: '你好!![呲牙]',
        ctime: new Date().toLocaleString()
      },
      {
        direction: 1,
        id: 2,
        type: 1,
        content: '你也好。[害羞]',
        ctime: new Date().toLocaleString()
      },
      {
        direction: 2,
        id: 3,
        type: 1,
        content: '这是我的简历头像:',
        ctime: new Date().toLocaleString()
      },
      {
        direction: 2,
        id: 4,
        type: 2,
        content: './src/assets/wyz.jpg',
        ctime: new Date().toLocaleString()
      },
      {
        direction: 1,
        id: 5,
        type: 1,
        content: '你开心就好。[微笑]',
        ctime: new Date().toLocaleString()
      }]
    }
  },
  components:{wxChat},

  methods:{

    //向上滚动加载数据
    getUpperData(){
      var me = this;
      
      // 这里为模拟异步加载数据
      // 实际上你可能要这么写:
      // return axios.get('xxx').then(function(result){
      //     return result;  //result的格式需要类似下面resolve里面的数组
      // })
      return new Promise(function(resolve){
        setTimeout(function(){
           //模拟加载完毕
          if(me.upperTimes>3){
            return resolve([]);
          }
          
          //加载数据
          resolve([{
              direction: 2,
              id: me.upperId-1,
              type: 1,
              content: '向上滚动加载第 ' + me.upperTimes +' 条!',
              ctime: new Date().toLocaleString()
            },
            {
              direction: 1,
              id: me.upperId-2,
              type: 1,
              content: '向上滚动加载第 ' + me.upperTimes +' 条!',
              ctime: new Date().toLocaleString()
            }]
      
          )
        }, 1000);
        me.upperId= me.upperId+2;
        me.upperTimes++;
      })
    },

    getUnderData(){
      var me = this;

      //意义同getUpperData()
      return new Promise(function(resolve){
        setTimeout(function(){
          //模拟加载完毕
          if(me.underTimes>3){
            return resolve([]);
          }
          
          //加载数据
          resolve(
            [{
              direction: 1,
              id: me.underId+1,
              type: 1,
              content: '向下滚动加载第 ' + me.underTimes +' 条!',
              ctime: new Date().toLocaleString()
            },
            {
              direction: 2,
              id: me.underId+2,
              type: 1,
              content: '向下滚动加载第 ' + me.underTimes +' 条!',
              ctime: new Date().toLocaleString()
            }]
          )
        }, 1000);

        me.underId = me.underId+2;
        me.underTimes++;
      })
    }

  }
}
</script>

<style>
*{
  margin: 0;
  padding: 0;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
}

</style>

欢迎 start: https://github.com/doterlin/vue-wxChat

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].