[微信小程序]聊天对话(文本,图片)的功能(完整代码附效果图)
废话不多说, 先上图:
- <!--pages/index/to_news/to_news.wxml-->
- <view class='tab'>
- <view class='lan'>{{tabdata.title}}</view>
- <view class='tent'>
- <text>{{tabdata.attribute_attribute}}</text>
- <text class='fl_r '>{{tabdata.num}}</text>
- </view>
- <view class='xiahuaxian1'></view>
- <view>
- <text class='fabu'>发布时间: {{tabdata.time_agree}}</text>
- </view>
- </view>
- <view class='news'>
- <view class='xiahuaxian1 xiahuaxia'></view>
- <view class='new_top_txt'>您正在与{{tabdata.nickname}}进行沟通</view>
- <view class="historycon">
- <scroll-view scroll-y="true" scroll-top="{{scrollTop}}" class="history" wx:for="{{centendata}}" wx:key=''>
- <view>
- <text class='time'>{{item.time}}</text>
- </view>
- <block wx:if="{{item.is_show_right ==1}}">
- <view class='my_right'>
- <view class='page_row'>
- <text wx:if='{{!item.is_img}}' class='new_txt'>{{item.content}}</text>
- <image wx:if='{{item.is_img}}' src='http://sz800800.cn/Uploads/{{item.content}}' class='new_imgtent'></image>
- <view wx:if='{{!item.is_img}}' class='sanjiao my'></view>
- <image class='new_img' wx:if='{{item.show_rignt == "是自己的内容,显示在右边,右边渲染 nickname_owner,head_owner"}}' src='{{item.head_owner}}'></image>
- <image class='new_img' wx:if='{{item.show_rignt == "是自己的内容,显示在右边,右边渲染 nickname_open,head_open"}}' src='{{item.head_open}}'></image>
- </view>
- </view>
- </block>
- <block wx:else>
- <view class='you_left'>
- <view class='page_row'>
- <image class='new_img' wx:if='{{item.show_rignt == "不是自己的内容,显示在左边,左边渲染 nickname_owner,head_owner"}}' src='{{item.head_owner}}'></image>
- <image class='new_img' wx:if='{{item.show_rignt == "不是自己的内容,显示在左边,左边渲染 nickname_open,head_open"}}' src='{{item.head_open}}'></image>
- <view wx:if='{{!item.is_img}}' class='sanjiao you'></view>
- <text wx:if='{{!item.is_img}}' class='new_txt'>{{item.content}}</text>
- <image wx:if='{{item.is_img}}' src='http://sz800800.cn/Uploads/{{item.content}}' class='new_imgtent'></image>
- </view>
- </view>
- </block>
- </scroll-view>
- </view>
- </view>
- <view class='hei' id="hei"></view>
- <view class="sendmessage">
- <input type="emoji" bindinput="bindChange" confirm-type="done" value='{{news_input_val}}' placeholder="" />
- <button catchtap="add">发送</button>
- <input style='display:none' type="" bindinput="bindChange" confirm-type="done" placeholder="" />
- <image bindtap="upimg1" class='jia_img' src='../../../images/jia_img.png'></image>
- </view>
- // pages/index/to_news/to_news.js
- var app = getApp();
- var util = require("../../../utils/util.js")
- var message = '';
- var text = '';
- var user = {};
- var length;
- var zx_info_id;
- var openid_talk;
- Page({
- data: {
- news: '',
- scrollTop: 0,
- message: '',
- text: text,
- centendata: '',
- nickName: '',
- avatarUrl: '',
- news_input_val:'',
- tabdata: ''
- },
- bindChange: function (e) {
- message = e.detail.value
- },
- //事件处理函数
- add: function (e) {
- var that = this
- var data = {
- program_id: app.jtappid,
- openid: app._openid,
- zx_info_id: zx_info_id,
- content: message,
- openid_talk:openid_talk
- }
- util.request('pg.php/ZXinfo/session_submit', 'post', data, '正在加载数据', function (res) {
- if (res.data.state == 1) {
- var a = true;
- that.loaddata(a);
- that.setData({
- news_input_val:''
- })
- message = ''
- } else {
- wx.showToast({
- title: '网络错误,请稍后',
- })
- }
- })
- },
- onLoad: function (options) {
- openid_talk = options.openid_talk;
- zx_info_id = options.zx_info_id;
- console.log(openid_talk)
- //调用应用实例的方法获取全局数据
- this.setData({
- zx_info_id: zx_info_id,
- nickName: app.nickName,
- avatarUrl: app.avatarUrl,
- });
- this.loaddata()
- },
- // 页面加载
- loaddata: function (a) {
- var that = this;
- var is_img = true;
- var data = {
- program_id: app.jtappid,
- openid: app._openid,
- zx_info_id: zx_info_id,
- openid_talk: openid_talk
- }
- util.request('pg.php/ZXinfo/session_page', 'post', data, '', function (res) {
- if (res.data.k1) {
- res.data.k1.time_agree = util.js_date_time(res.data.k1.time_agree)
- }
- for (var i = 0; i < res.data.k2.length; i++) {
- res.data.k2[i].time = util.js_date_time(res.data.k2[i].time)
- var n = res.data.k2[i].content.charAt(res.data.k2[i].content.length - 1);
- switch (n) {
- case 'g':
- res.data.k2[i].is_img = is_img
- break;
- default:
- }
- }
- that.setData({
- tabdata: res.data.k1,
- centendata: res.data.k2.reverse()
- })
- wx.setNavigationBarTitle({ title: that.data.tabdata.nickname });
- if (a) {
- setTimeout(function () {
- that.bottom()
- }, 500);
- }
- })
- setTimeout(function () {
- if (that.data.centendata.length != length) {
- length = that.data.centendata.length
- }
- that.loaddata()
- }, 3000);
- },
- // 获取hei的id节点然后屏幕焦点调转到这个节点
- bottom: function () {
- var query = wx.createSelectorQuery()
- query.select('#hei').boundingClientRect()
- query.selectViewport().scrollOffset()
- query.exec(function (res) {
- wx.pageScrollTo({
- scrollTop: res[0].bottom // #the-id节点的下边界坐标
- })
- res[1].scrollTop // 显示区域的竖直滚动位置
- })
- },
- // 选择图片并把图片保存
- upimg1: function () {
- var that = this;
- wx.chooseImage({
- success: function (res) {
- var data = {
- program_id: app.jtappid,
- openid: app._openid,
- zx_info_id: zx_info_id,
- }
- var tempFilePaths = res.tempFilePaths
- wx.uploadFile({
- url: 'pg.php/ZXinfo/session_submit', //提交信息至后台
- filePath: tempFilePaths[0],
- name: 'content', //文件对应的参数名字(key)
- formData: data, //其它的表单信息
- success: function (res) {
- var a = true;
- that.loaddata(a);
- message = ''
- }
- })
- }
- })
- }
- })
- /* pages/index/to_news/to_news.wxss */
- page {
- background-color: #f7f7f7;
- }
- .tab {
- padding: 20rpx 20rpx 40rpx 50rpx;
- height: 20%;
- background-color: white;
- }
- .tab .tent {
- font-size: 33rpx;
- margin-bottom: 30rpx;
- }
- .jia_img{
- height: 80rpx;
- width: 90rpx;
- }
- .new_imgtent{
- height: 180rpx;
- width: 190rpx;
- }
- .tab .fabu {
- font-size: 33rpx;
- margin-top: 30rpx;
- margin-bottom: 30rpx;
- }
- .xiahuaxia {
- width: 80%;
- text-align: center;
- margin: 0 auto;
- position: relative;
- top: 60rpx;
- }
- .time {
- text-align: center;
- padding: 5rpx 20rpx 5rpx 20rpx;
- width: 200rpx;
- font-size: 26rpx;
- background-color: #E8E8E8;
- }
- .new_top_txt {
- width: 50%;
- position: relative;
- top: 38rpx;
- text-align: center;
- margin: 0 auto;
- font-size: 30rpx;
- color: #787878;
- background-color: #f7f7f7;
- }
- /* 聊天内容 */
- .news {
- margin-top: 30rpx;
- text-align: center;
- margin-bottom: 150rpx;
- }
- .img_null {
- height: 60rpx;
- }
- .l {
- height: 5rpx;
- width: 20%;
- margin-top: 30rpx;
- color: #000;
- }
- /* 聊天 */
- .my_right {
- float: right;
- position: relative;
- right: 40rpx;
- }
- .you_left {
- float: left;
- position: relative;
- left: 5rpx;
- }
- .new_img {
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- }
- .new_txt {
- width: 380rpx;
- border-radius: 7px;
- background-color: #95d4ff;
- padding: 0rpx 30rpx 0rpx 30rpx;
- }
- .sanjiao {
- top: 20rpx;
- position: relative;
- width: 0px;
- height: 0px;
- border-width: 10px;
- border-style: solid;
- }
- .my {
- border-color: transparent transparent transparent #95d4ff;
- }
- .you {
- border-color: transparent #95d4ff transparent transparent;
- }
- .sendmessage {
- background-color: white;
- width: 100%;
- position: fixed;
- bottom: 0rpx;
- display: flex;
- flex-direction: row;
- }
- .sendmessage input {
- width: 80%;
- height: 40px;
- background-color: white;
- line-height: 40px;
- font-size: 14px;
- border: 1px solid #d0d0d0;
- padding-left: 10px;
- }
- .sendmessage button {
- border: 1px solid white;
- width: 18%;
- height: 40px;
- background: #fff;
- color: #000;
- line-height: 40px;
- font-size: 14px;
- }
- .historycon {
- height: 90%;
- width: 100%;
- flex-direction: column;
- display: flex;
- margin-top: 100rpx;
- border-top: 0px;
- }
- .hei{
- margin-top: 50px;
- height: 20rpx;
- }
- .history {
- height: 100%;
- margin-top: 15px;
- margin: 10px;
- font-size: 14px;
- line-height: 40px;
- word-break: break-all;
- }
[微信小程序]聊天对话(文本,图片)的功能(完整代码附效果图)的更多相关文章
- 微信小程序左右滑动切换图片酷炫效果(附效果)
开门见山,先上效果吧!感觉可以的用的上的再往下看. 心动吗?那就继续往下看! 先上页面结构吧,也就是wxml文件,其实可以理解成微信自己封装过的html,这个不多说了,不懂也没必要往下看了. < ...
- 微信小程序--聊天室小程序(云开发)
微信小程序 -- 聊天室小程序(云开发) 从微信小程序开发社区更新watch接口之后,一直在构思这个项目.项目已经完成很久,但是一直都没有空写一篇博客记录展示一下. 开源地址 wx-cloud-im: ...
- 微信小程序--canvas画布实现图片的编辑
技术:微信小程序 概述 上传图片,编辑图片大小,添加文字,改变文字颜色等 详细 代码下载:http://www.demodashi.com/demo/14789.html 概述 微信小程序--ca ...
- 微信小程序:本地资源图片无法通过 WXSS 获取,可以使用网络图片或者 base64或者使用image标签
微信小程序:本地资源图片无法通过 WXSS 获取,可以使用网络图片或者 base64或者使用image标签 一.问题 报错信息: VM696:2 pages/user/user.wxss 中的本地资源 ...
- 微信小程序-显示外链图片 bug
微信小程序-显示外链图片 bug 显示外链图片 bug 403 bug 禁止外链,未授权 https://httpstatuses.com/403 image component 图片.支持 JPG. ...
- 微信小程序0.11.122100版本新功能解析
微信小程序0.11.122100版本新功能解析 新版本就不再吐槽了,整的自己跟个愤青似的.人老了,喷不动了,把机会留给年轻人吧.下午随着新版本开放,微信居然破天荒的开放了开发者论坛.我很是担心官方 ...
- 微信小程序调用用百度地图天气功能
#小程序之调用百度地图天气功能 本篇博客主要介绍小程序在百度地图中获取天气信息,如有不全请指出.下面先上效果图 主要内容 百度地图API的个人密钥,也就是AK 请求百度地图API接口数据 获取到的信息 ...
- (干货)微信小程序之上传图片和图片预览
这几天一直负责做微信小程序这一块,也可以说是边做边学习吧,把自己做的微信小程序的一些功能分享出来,与大家探讨一下,相互学习相互进步. 先看下效果图 只写了一下效果样式的话希望大家不要太在意,下面马路杀 ...
- 微信小程序开发之多图片上传+服务端接收
前言: 业务需求,这次需要做一个小程序同时选中三张图片一起上传到服务端,后端使用的.NET WEBAPI接收数据保存. 使用技术: 在这章中将会使用到微信小程序wx.uploadFile(Object ...
随机推荐
- Python3 循环_break和continue语句及循环中的else子句
break和continue语句及循环中的else子句break语句可以跳出for和while的循环体.如果你从for或while循环中终止,任何对应的循环else块将不执行. continue语句被 ...
- CentOS8 缺少 libglade2 安装包的回避方法
某些gtk2应用程序需要libglade2安装包,但不知为何CentOS的yum仓库里没有此包, 经测试,可手动安装CentOS7的rpm包安装解决. 更新:使用下面一行即可.sudo yum ins ...
- Python multiprocess模块(中)
主要内容: 一. 锁 二. 信号量 三. 事件 通过event来完成红绿灯模型 四. 队列(重点) 队列实现进程间的通信 五. 生产者消费者模型 1. 初始版本(程序会阻塞住) 2. 升级版本一(通过 ...
- 利用canvas对图片进行切割
使用input标签选择一张图片, 然后利用canvas对图片进行切割, 可以设置切割的行数和列数 这是html代码 ... <input type="file" id=&qu ...
- Django:(02)项目配置
上一篇我们创建了一个Django项目,并且让它运行了起来了. 当是,我们还没有使用到我们创建的应用,以及templates模版目录. 需求: 在此之前我们根据需要对我们的项目进行配置修改. 在项目开发 ...
- 快速搭建WordPress博客
博主在看了朋友的博客后 决定也搭建一个wordPress 博客 思路 1.购买服务器 2.Cenots环境配置 3.安装wordpress 工具 推荐使用 Xshell 6,当然也可以用其他 服务器推 ...
- 【机器学习】ICA 原理以及相关概率论,信息论知识简介
看完了sparse coding,开始看ICA模型,本来ng的教程上面就只有一个简短的介绍,怎奈自己有强迫症,爱钻牛角尖,于是乎就搜索了一些ICA的介绍文章(都是从百度文库中搜来的),看完之后感觉这个 ...
- 版权动态日记页脚 JS
关键代码如下 <script>document.write(new Date().getFullYear())</script> js方法 new Date() //实例化Da ...
- 小菜鸟之Phyhon
# print("输入成绩",end="") # src=input() # print("成绩",end=src)#成绩 # print( ...
- SQLSERVER2008 内存占用高的处理方式
原文:SQLSERVER2008 内存占用高的处理方式 方法一: 方法二: 使用以下语句查找出什么语句占内存最高,针对占内存高的语句进行优化SELECT SS.SUM_EXECUTION_COUNT, ...