废话不多说, 先上图:

  1. <!--pages/index/to_news/to_news.wxml-->
  2. <view class='tab'>
  3. <view class='lan'>{{tabdata.title}}</view>
  4. <view class='tent'>
  5. <text>{{tabdata.attribute_attribute}}</text>
  6. <text class='fl_r '>{{tabdata.num}}</text>
  7. </view>
  8. <view class='xiahuaxian1'></view>
  9. <view>
  10. <text class='fabu'>发布时间: {{tabdata.time_agree}}</text>
  11. </view>
  12. </view>
  13. <view class='news'>
  14. <view class='xiahuaxian1 xiahuaxia'></view>
  15. <view class='new_top_txt'>您正在与{{tabdata.nickname}}进行沟通</view>
  16. <view class="historycon">
  17. <scroll-view scroll-y="true" scroll-top="{{scrollTop}}" class="history" wx:for="{{centendata}}" wx:key=''>
  18. <view>
  19. <text class='time'>{{item.time}}</text>
  20. </view>
  21. <block wx:if="{{item.is_show_right ==1}}">
  22. <view class='my_right'>
  23. <view class='page_row'>
  24. <text wx:if='{{!item.is_img}}' class='new_txt'>{{item.content}}</text>
  25. <image wx:if='{{item.is_img}}' src='http://sz800800.cn/Uploads/{{item.content}}' class='new_imgtent'></image>
  26. <view wx:if='{{!item.is_img}}' class='sanjiao my'></view>
  27. <image class='new_img' wx:if='{{item.show_rignt == "是自己的内容,显示在右边,右边渲染 nickname_owner,head_owner"}}' src='{{item.head_owner}}'></image>
  28. <image class='new_img' wx:if='{{item.show_rignt == "是自己的内容,显示在右边,右边渲染 nickname_open,head_open"}}' src='{{item.head_open}}'></image>
  29. </view>
  30. </view>
  31. </block>
  32. <block wx:else>
  33. <view class='you_left'>
  34. <view class='page_row'>
  35. <image class='new_img' wx:if='{{item.show_rignt == "不是自己的内容,显示在左边,左边渲染 nickname_owner,head_owner"}}' src='{{item.head_owner}}'></image>
  36. <image class='new_img' wx:if='{{item.show_rignt == "不是自己的内容,显示在左边,左边渲染 nickname_open,head_open"}}' src='{{item.head_open}}'></image>
  37. <view wx:if='{{!item.is_img}}' class='sanjiao you'></view>
  38. <text wx:if='{{!item.is_img}}' class='new_txt'>{{item.content}}</text>
  39. <image wx:if='{{item.is_img}}' src='http://sz800800.cn/Uploads/{{item.content}}' class='new_imgtent'></image>
  40. </view>
  41. </view>
  42. </block>
  43. </scroll-view>
  44. </view>
  45. </view>
  46. <view class='hei' id="hei"></view>
  47. <view class="sendmessage">
  48. <input type="emoji" bindinput="bindChange" confirm-type="done" value='{{news_input_val}}' placeholder="" />
  49. <button catchtap="add">发送</button>
  50. <input style='display:none' type="" bindinput="bindChange" confirm-type="done" placeholder="" />
  51. <image bindtap="upimg1" class='jia_img' src='../../../images/jia_img.png'></image>
  52. </view>
  1. // pages/index/to_news/to_news.js
  2. var app = getApp();
  3. var util = require("../../../utils/util.js")
  4. var message = '';
  5. var text = '';
  6. var user = {};
  7. var length;
  8. var zx_info_id;
  9. var openid_talk;
  10. Page({
  11. data: {
  12. news: '',
  13. scrollTop: 0,
  14. message: '',
  15. text: text,
  16. centendata: '',
  17. nickName: '',
  18. avatarUrl: '',
  19. news_input_val:'',
  20. tabdata: ''
  21. },
  22. bindChange: function (e) {
  23. message = e.detail.value
  24. },
  25. //事件处理函数
  26. add: function (e) {
  27. var that = this
  28. var data = {
  29. program_id: app.jtappid,
  30. openid: app._openid,
  31. zx_info_id: zx_info_id,
  32. content: message,
  33. openid_talk:openid_talk
  34. }
  35. util.request('pg.php/ZXinfo/session_submit', 'post', data, '正在加载数据', function (res) {
  36. if (res.data.state == 1) {
  37. var a = true;
  38. that.loaddata(a);
  39. that.setData({
  40. news_input_val:''
  41. })
  42. message = ''
  43. } else {
  44. wx.showToast({
  45. title: '网络错误,请稍后',
  46. })
  47. }
  48. })
  49. },
  50. onLoad: function (options) {
  51. openid_talk = options.openid_talk;
  52. zx_info_id = options.zx_info_id;
  53. console.log(openid_talk)
  54. //调用应用实例的方法获取全局数据
  55. this.setData({
  56. zx_info_id: zx_info_id,
  57. nickName: app.nickName,
  58. avatarUrl: app.avatarUrl,
  59. });
  60. this.loaddata()
  61. },
  62. // 页面加载
  63. loaddata: function (a) {
  64. var that = this;
  65. var is_img = true;
  66. var data = {
  67. program_id: app.jtappid,
  68. openid: app._openid,
  69. zx_info_id: zx_info_id,
  70. openid_talk: openid_talk
  71. }
  72. util.request('pg.php/ZXinfo/session_page', 'post', data, '', function (res) {
  73. if (res.data.k1) {
  74. res.data.k1.time_agree = util.js_date_time(res.data.k1.time_agree)
  75. }
  76. for (var i = 0; i < res.data.k2.length; i++) {
  77. res.data.k2[i].time = util.js_date_time(res.data.k2[i].time)
  78. var n = res.data.k2[i].content.charAt(res.data.k2[i].content.length - 1);
  79. switch (n) {
  80. case 'g':
  81. res.data.k2[i].is_img = is_img
  82. break;
  83. default:
  84. }
  85. }
  86. that.setData({
  87. tabdata: res.data.k1,
  88. centendata: res.data.k2.reverse()
  89. })
  90. wx.setNavigationBarTitle({ title: that.data.tabdata.nickname });
  91. if (a) {
  92. setTimeout(function () {
  93. that.bottom()
  94. }, 500);
  95. }
  96. })
  97. setTimeout(function () {
  98. if (that.data.centendata.length != length) {
  99. length = that.data.centendata.length
  100. }
  101. that.loaddata()
  102. }, 3000);
  103. },
  104. // 获取hei的id节点然后屏幕焦点调转到这个节点
  105. bottom: function () {
  106. var query = wx.createSelectorQuery()
  107. query.select('#hei').boundingClientRect()
  108. query.selectViewport().scrollOffset()
  109. query.exec(function (res) {
  110. wx.pageScrollTo({
  111. scrollTop: res[0].bottom  // #the-id节点的下边界坐标
  112. })
  113. res[1].scrollTop // 显示区域的竖直滚动位置
  114. })
  115. },
  116. // 选择图片并把图片保存
  117. upimg1: function () {
  118. var that = this;
  119. wx.chooseImage({
  120. success: function (res) {
  121. var data = {
  122. program_id: app.jtappid,
  123. openid: app._openid,
  124. zx_info_id: zx_info_id,
  125. }
  126. var tempFilePaths = res.tempFilePaths
  127. wx.uploadFile({
  128. url: 'pg.php/ZXinfo/session_submit', //提交信息至后台
  129. filePath: tempFilePaths[0],
  130. name: 'content', //文件对应的参数名字(key)
  131. formData: data,  //其它的表单信息
  132. success: function (res) {
  133. var a = true;
  134. that.loaddata(a);
  135. message = ''
  136. }
  137. })
  138. }
  139. })
  140. }
  141. })
    1. /* pages/index/to_news/to_news.wxss */
    2. page {
    3. background-color: #f7f7f7;
    4. }
    5. .tab {
    6. padding: 20rpx 20rpx 40rpx 50rpx;
    7. height: 20%;
    8. background-color: white;
    9. }
    10. .tab .tent {
    11. font-size: 33rpx;
    12. margin-bottom: 30rpx;
    13. }
    14. .jia_img{
    15. height: 80rpx;
    16. width: 90rpx;
    17. }
    18. .new_imgtent{
    19. height: 180rpx;
    20. width: 190rpx;
    21. }
    22. .tab .fabu {
    23. font-size: 33rpx;
    24. margin-top: 30rpx;
    25. margin-bottom: 30rpx;
    26. }
    27. .xiahuaxia {
    28. width: 80%;
    29. text-align: center;
    30. margin: 0 auto;
    31. position: relative;
    32. top: 60rpx;
    33. }
    34. .time {
    35. text-align: center;
    36. padding: 5rpx 20rpx 5rpx 20rpx;
    37. width: 200rpx;
    38. font-size: 26rpx;
    39. background-color: #E8E8E8;
    40. }
    41. .new_top_txt {
    42. width: 50%;
    43. position: relative;
    44. top: 38rpx;
    45. text-align: center;
    46. margin: 0 auto;
    47. font-size: 30rpx;
    48. color: #787878;
    49. background-color: #f7f7f7;
    50. }
    51. /* 聊天内容 */
    52. .news {
    53. margin-top: 30rpx;
    54. text-align: center;
    55. margin-bottom: 150rpx;
    56. }
    57. .img_null {
    58. height: 60rpx;
    59. }
    60. .l {
    61. height: 5rpx;
    62. width: 20%;
    63. margin-top: 30rpx;
    64. color: #000;
    65. }
    66. /* 聊天 */
    67. .my_right {
    68. float: right;
    69. position: relative;
    70. right: 40rpx;
    71. }
    72. .you_left {
    73. float: left;
    74. position: relative;
    75. left: 5rpx;
    76. }
    77. .new_img {
    78. width: 100rpx;
    79. height: 100rpx;
    80. border-radius: 50%;
    81. }
    82. .new_txt {
    83. width: 380rpx;
    84. border-radius: 7px;
    85. background-color: #95d4ff;
    86. padding: 0rpx 30rpx 0rpx 30rpx;
    87. }
    88. .sanjiao {
    89. top: 20rpx;
    90. position: relative;
    91. width: 0px;
    92. height: 0px;
    93. border-width: 10px;
    94. border-style: solid;
    95. }
    96. .my {
    97. border-color: transparent transparent transparent #95d4ff;
    98. }
    99. .you {
    100. border-color: transparent #95d4ff transparent transparent;
    101. }
    102. .sendmessage {
    103. background-color: white;
    104. width: 100%;
    105. position: fixed;
    106. bottom: 0rpx;
    107. display: flex;
    108. flex-direction: row;
    109. }
    110. .sendmessage input {
    111. width: 80%;
    112. height: 40px;
    113. background-color: white;
    114. line-height: 40px;
    115. font-size: 14px;
    116. border: 1px solid #d0d0d0;
    117. padding-left: 10px;
    118. }
    119. .sendmessage button {
    120. border: 1px solid white;
    121. width: 18%;
    122. height: 40px;
    123. background: #fff;
    124. color: #000;
    125. line-height: 40px;
    126. font-size: 14px;
    127. }
    128. .historycon {
    129. height: 90%;
    130. width: 100%;
    131. flex-direction: column;
    132. display: flex;
    133. margin-top: 100rpx;
    134. border-top: 0px;
    135. }
    136. .hei{
    137. margin-top: 50px;
    138. height: 20rpx;
    139. }
    140. .history {
    141. height: 100%;
    142. margin-top: 15px;
    143. margin: 10px;
    144. font-size: 14px;
    145. line-height: 40px;
    146. word-break: break-all;
    147. }

[微信小程序]聊天对话(文本,图片)的功能(完整代码附效果图)的更多相关文章

  1. 微信小程序左右滑动切换图片酷炫效果(附效果)

    开门见山,先上效果吧!感觉可以的用的上的再往下看. 心动吗?那就继续往下看! 先上页面结构吧,也就是wxml文件,其实可以理解成微信自己封装过的html,这个不多说了,不懂也没必要往下看了. < ...

  2. 微信小程序--聊天室小程序(云开发)

    微信小程序 -- 聊天室小程序(云开发) 从微信小程序开发社区更新watch接口之后,一直在构思这个项目.项目已经完成很久,但是一直都没有空写一篇博客记录展示一下. 开源地址 wx-cloud-im: ...

  3. 微信小程序--canvas画布实现图片的编辑

    技术:微信小程序   概述 上传图片,编辑图片大小,添加文字,改变文字颜色等 详细 代码下载:http://www.demodashi.com/demo/14789.html 概述 微信小程序--ca ...

  4. 微信小程序:本地资源图片无法通过 WXSS 获取,可以使用网络图片或者 base64或者使用image标签

    微信小程序:本地资源图片无法通过 WXSS 获取,可以使用网络图片或者 base64或者使用image标签 一.问题 报错信息: VM696:2 pages/user/user.wxss 中的本地资源 ...

  5. 微信小程序-显示外链图片 bug

    微信小程序-显示外链图片 bug 显示外链图片 bug 403 bug 禁止外链,未授权 https://httpstatuses.com/403 image component 图片.支持 JPG. ...

  6. 微信小程序0.11.122100版本新功能解析

    微信小程序0.11.122100版本新功能解析   新版本就不再吐槽了,整的自己跟个愤青似的.人老了,喷不动了,把机会留给年轻人吧.下午随着新版本开放,微信居然破天荒的开放了开发者论坛.我很是担心官方 ...

  7. 微信小程序调用用百度地图天气功能

    #小程序之调用百度地图天气功能 本篇博客主要介绍小程序在百度地图中获取天气信息,如有不全请指出.下面先上效果图 主要内容 百度地图API的个人密钥,也就是AK 请求百度地图API接口数据 获取到的信息 ...

  8. (干货)微信小程序之上传图片和图片预览

    这几天一直负责做微信小程序这一块,也可以说是边做边学习吧,把自己做的微信小程序的一些功能分享出来,与大家探讨一下,相互学习相互进步. 先看下效果图 只写了一下效果样式的话希望大家不要太在意,下面马路杀 ...

  9. 微信小程序开发之多图片上传+服务端接收

    前言: 业务需求,这次需要做一个小程序同时选中三张图片一起上传到服务端,后端使用的.NET WEBAPI接收数据保存. 使用技术: 在这章中将会使用到微信小程序wx.uploadFile(Object ...

随机推荐

  1. COALESCE关键字的使用

    COALESCE是sql标准里面的一个关键字,我们可以和聚合函数sum,count,max等一起使用完成一些特殊的功能. 以下sql语句基于mysql 1.查询某一个列总和,如果没有数据或者NULL返 ...

  2. ElasticSearch——分词

    前言: 最近在使用elasticSearch中发现有些数据查不出来,于是研究了一下,发现是分词导致的,现梳理并总结一下. ElasticSearch 5.0以后,string类型有重大变更,移除了st ...

  3. View的介绍和运用 && FlexBox布局

    开始我们今天的项目学习啦~~~~~~ 1> 第一步当然是创建项目啦: 进入终端: 创建ViewDemo项目 命令如下啦,你看懂了对吧...嘻嘻!!! 2>View的介绍和运用 项目安装创建 ...

  4. c/c++编码规范(2)--作用域

    2. 作用域 静止使用class类型的静态或全局变量. 6. 命名约定 6.1. 函数名,变量名,文件名要有描述性,少用缩写. 6.2. 文件命名 6.2.1. 文件名要全部用小写.可使用“_”或&q ...

  5. linux 系统函数 basename和dirname

    在linux系统中有这样两个系统函数,basename 和  dirname 1.basename 用于 获取文件名, 1.1 当给定扩展名作为参数之后,甚至可以直接获取文件名 2.与basename ...

  6. 解MySQL基准测试和sysbench工具

    前言 作为一名后台开发,对数据库进行基准测试,以掌握数据库的性能情况是非常必要的.本文介绍了MySQL基准测试的基本概念,以及使用sysbench对MySQL进行基准测试的详细方法. 文章有疏漏之处, ...

  7. Base64encoder干什么用的

    https://baike.baidu.com/item/base64/8545775?fr=aladdin BASE64加密算法.用来给字符串加密的.已经不安全了. 一直以来Base64的加密解密都 ...

  8. go语言开启go module

    export GO111MODULE=on //linux .MAC set GO111MODULE=on //Windows

  9. 剑指offer6:旋转数组的最小数字

    1. 题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一 ...

  10. centos7 使用nginx + tornado + supervisor搭建服务

    如何在Linux下部署一个简单的基于Nginx+Tornado+Supervisor的Python web服务. Tornado:官方介绍,是使用Python编写出来的一个极轻量级.高可伸缩性和非阻塞 ...