欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

react+redux仿微信聊天界面

 更新時間:2019年06月21日 08:35:59   作者:xiaoyan2017  
這篇文章主要介紹了react+redux仿微信聊天IM實例|react仿微信界面 ,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

一、項目概況

基于react+react-dom+react-router-dom+redux+react-redux+webpack2.0+react-photoswipe+swiper等技術(shù)混合開發(fā)的手機(jī)端仿微信界面聊天室——reactChatRoom,實現(xiàn)了聊天記錄下拉刷新、發(fā)送消息、表情(動圖),圖片、視頻預(yù)覽,打賞、紅包等功能。

二、技術(shù)棧MVVM框架:

react / react-dom狀態(tài)管理:redux / react-redux頁面路由:react-router-dom彈窗插件:wcPop打包工具:webpack 2.0環(huán)境配置:node.js + cnpm圖片預(yù)覽:react-photoswipe輪播滑動:swiper

◆package.json依賴安裝:

{
 "name": "react-chatroom",
 "version": "0.1.0",
 "private": true,
 "author": "andy",
 "dependencies": {
  "react": "^16.8.6",
  "react-dom": "^16.8.6",
  "react-redux": "^7.0.3",
  "react-router-dom": "^5.0.0",
  "react-scripts": "0.9.x",
  "redux": "^4.0.1"
 },
 "devDependencies": {
  "jquery": "^2.2.3",
  "react-loadable": "^5.5.0",
  "react-photoswipe": "^1.3.0",
  "react-pullload": "^1.2.0",
  "redux-thunk": "^2.3.0",
  "swiper": "^4.5.0",
  "webpack": "^1.13.1",
  "webpack-dev-server": "^1.12.0"
 },
 "scripts": {
  "start": "set HOST=localhost&&set PORT=3003 && react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject"
 }
}

◆ 入口頁面index.js配置

/*
 * @desc 入口頁面index.js
 */
import React from 'react';
import ReactDOM from 'react-dom';
// import {HashRouter as Router, Route} from 'react-router-dom'
import App from './App';
// 引入狀態(tài)管理
import {Provider} from 'react-redux'
import {store} from './store'
// 導(dǎo)入公共樣式
import './assets/fonts/iconfont.css'
import './assets/css/reset.css'
import './assets/css/layout.css'
// 引入wcPop彈窗樣式
import './assets/js/wcPop/skin/wcPop.css'
// 引入js
import './assets/js/fontSize'
ReactDOM.render(
 <Provider store={store}>
  <App />
 </Provider>,
 document.getElementById('app')
);

◆ 頁面App.js主模板

import React, { Component } from 'react';
import {HashRouter as Router, Route, Switch, Redirect} from 'react-router-dom'
import {connect} from 'react-redux'
import $ from 'jquery'
// 引入wcPop彈窗插件
import { wcPop } from './assets/js/wcPop/wcPop'
// 引入地址路由
import routers from './router'
// 導(dǎo)入頂部、底部tabbar
import HeaderBar from './components/header'
import TabBar from './components/tabbar'
class App extends Component {
 constructor(props){
  super(props)
  console.log('App主頁面參數(shù):\n' + JSON.stringify(props, null, 2))
 }
 render() {
  let token = this.props.token
  return (
   <Router>
    <div className="weChatIM__panel clearfix">
     <div className="we__chatIM-wrapper flexbox flex__direction-column">
      {/* 頂部 */}
      <Switch>
       <HeaderBar />
      </Switch>
      {/* 主頁面 */}
      <div className="wcim__container flex1">
       {/* 路由容器 */}
       <Switch>
        {
         routers.map((item, index) => {
          return <Route key={index} path={item.path} exact render={props => (
           !item.meta || !item.meta.requireAuth ? (<item.component {...props} />) : (
            token ? <item.component {...props} /> : <Redirect to={{pathname: '/login', state: {from: props.location}}} />
           )
          )} />
         })
        }
        {/* 初始化頁面跳轉(zhuǎn) */}
        <Redirect push to="/index" />
       </Switch>
      </div>
      {/* 底部tabbar */}
      <Switch>
       <TabBar />
      </Switch>
     </div>
    </div>
   </Router>
  );
 }
}
const mapStateToProps = (state) =>{
 return {
  ...state.auth
 }
}
export default connect(mapStateToProps)(App);

◆ react登錄、注冊模塊 / react登錄注冊驗證

import React, { Component } from 'react';
import { Link } from 'react-router-dom'
import { connect } from 'react-redux';
import * as actions from '../../store/action'
// 引入wcPop彈窗插件
import { wcPop } from '../../assets/js/wcPop/wcPop.js'
class Login extends Component {
  constructor(props) {
    super(props)
    this.state = {
      tel: '',
      pwd: '',
      vcode: '',
      vcodeText: '獲取驗證碼',
      disabled: false,
      time: 0
    }
  }
  componentDidMount(){
    if(this.props.token){
      this.props.history.push('/')
    }
  }
  render() {
    return (
      <div className="wcim__lgregWrapper flexbox flex__direction-column">
        ......
      </div>
    )
  }
  // 提交表單
  handleSubmit = (e) => {
    e.preventDefault();
    var that = this
    this.state.tel = this.refs.tel.value
    this.state.pwd = this.refs.pwd.value
    this.state.vcode = this.refs.vcode.value
    if (!this.state.tel) {
      wcPop({ content: '手機(jī)號不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!checkTel(this.state.tel)) {
      wcPop({ content: '手機(jī)號格式不正確!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!this.state.pwd) {
      wcPop({ content: '密碼不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!this.state.vcode) {
      wcPop({ content: '驗證碼不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else {
      // 獲取登錄之前的頁面地址
      let redirectUrl = this.props.location.state ? this.props.location.state.from.pathname : '/'
      // 設(shè)置token
      this.props.authToken(getToken())
      this.props.authUser(this.state.tel)
      wcPop({
        content: '注冊成功!', style: 'background:#41b883;color:#fff;', time: 2,
        end: function () {
          that.props.history.push(redirectUrl)
        }
      });
    }
  }
  // 60s倒計時
  handleVcode = (e) => {
    e.preventDefault();
    this.state.tel = this.refs.tel.value
    if (!this.state.tel) {
      wcPop({ content: '手機(jī)號不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!checkTel(this.state.tel)) {
      wcPop({ content: '手機(jī)號格式不正確!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else {
      this.state.time = 60
      this.state.disabled = true
      this.countDown();
    }
  }
  countDown = (e) => {
    if(this.state.time > 0){
      this.state.time--
      this.setState({
        vcodeText: '獲取驗證碼(' + this.state.time + ')'
      })
      // setTimeout(this.countDown, 1000);
      setTimeout(() => {
        this.countDown()
      }, 1000);
    }else{
      this.setState({
        time: 0,
        vcodeText: '獲取驗證碼',
        disabled: false
      })
    }
  }
}
const mapStateToProps = (state) => {
  return {
    ...state.auth
  }
}
export default connect(mapStateToProps, {
  authToken: actions.setToken,
  authUser: actions.setUser
})(Login)

總結(jié)

以上所述是小編給大家介紹的react+redux仿微信聊天界面,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!

相關(guān)文章

  • 在React中寫一個Animation組件為組件進(jìn)入和離開加上動畫/過度效果

    在React中寫一個Animation組件為組件進(jìn)入和離開加上動畫/過度效果

    這篇文章主要介紹了在React中寫一個Animation組件為組件進(jìn)入和離開加上動畫/過度效果,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06
  • 使用React-Router時出現(xiàn)的錯誤及解決

    使用React-Router時出現(xiàn)的錯誤及解決

    這篇文章主要介紹了使用React-Router時出現(xiàn)的錯誤及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • React項目搭建與Echarts工具使用詳解

    React項目搭建與Echarts工具使用詳解

    這篇文章主要介紹了React項目搭建與Echarts工具使用詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • react-router-dom?降低版本的兩種方法詳解

    react-router-dom?降低版本的兩種方法詳解

    這篇文章主要介紹了react-router-dom?降低版本的兩種方法,本篇文章就記錄下如何降低 react-router-dom 為 v5 版本的兩種方法,需要的朋友可以參考下
    2022-12-12
  • react中如何使用監(jiān)聽

    react中如何使用監(jiān)聽

    在 React 中,您可以使用?addEventListener?函數(shù)來監(jiān)聽事件,本文通過實例代碼給大家介紹react中如何使用監(jiān)聽,感興趣的朋友跟隨小編一起看看吧
    2023-10-10
  • react+typescript中使用echarts的實現(xiàn)步驟

    react+typescript中使用echarts的實現(xiàn)步驟

    本文主要介紹了react+typescript中使用echarts的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • 基于Cloud?Studio構(gòu)建React完成點餐H5頁面(騰訊云?Cloud?Studio?實戰(zhàn)訓(xùn)練營)

    基于Cloud?Studio構(gòu)建React完成點餐H5頁面(騰訊云?Cloud?Studio?實戰(zhàn)訓(xùn)練營)

    最近也是有機(jī)會參與到了騰訊云舉辦的騰訊云Cloud Studio實戰(zhàn)訓(xùn)練營,借此了解了騰訊云Cloud?Studio產(chǎn)品,下面就來使用騰訊云Cloud?Studio做一個實戰(zhàn)案例來深入了解該產(chǎn)品的優(yōu)越性吧,感興趣的朋友跟隨小編一起看看吧
    2023-08-08
  • React組件通信的實現(xiàn)示例

    React組件通信的實現(xiàn)示例

    在React中,組件通信是一個重要的概念,它允許不同組件之間進(jìn)行數(shù)據(jù)傳遞和交互,本文主要介紹了React組件通信的實現(xiàn)示例,感興趣的可以了解一下
    2023-11-11
  • React配置代理服務(wù)器的5種方法及使用場景

    React配置代理服務(wù)器的5種方法及使用場景

    這篇文章主要介紹了React配置代理服務(wù)器的5種方法,無論使用哪種方法,都需要確保代理服務(wù)器的地址和端口正確,并且在配置完成后重新啟動React開發(fā)服務(wù)器,使配置生效,需要的朋友可以參考下
    2023-08-08
  • React Hooks核心原理深入分析講解

    React Hooks核心原理深入分析講解

    這篇文章主要介紹了react hooks實現(xiàn)原理,文中給大家介紹了useState dispatch 函數(shù)如何與其使用的 Function Component 進(jìn)行綁定,節(jié)后實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12

最新評論