Commit 8d410c00 by 施宇

111

parent 60f42551
const WebIM = require("utils/WebIM")["default"];
let chat = require('utils/chat.js');
import { getData } from './utils/util.js';
import { getData, judgeToken } from './utils/util.js';
import { apis } from './utils/api.js';
App({
globalData: {
......@@ -64,8 +64,10 @@ App({
})
}
}
})
this.getImUser();
});
if (judgeToken()){
this.getImUser();
}
chat.webimListen();
this.checkIsIPhoneX();
},
......
/* pages/detail/chat/index.wxss */
page{
background-color: #fff;
height:auto;
}
\ No newline at end of file
// pages/search/index/index.js
import {
getData,
dataEncryption
} from '../../../utils/util.js';
import {
apis
} from '../../../utils/api.js';
Page({
/**
......@@ -6,74 +13,99 @@ Page({
*/
data: {
key: "",
historyList:[],
rmList:[]
historyList: [],
rmList: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: function(options) {
this.getHotGoods()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onShow: function() {
let storageKeys = wx.getStorageSync('storageKeys') || [];
this.setData({
historyList:storageKeys
historyList: storageKeys
})
},
getHotGoods: function() {
let obj = dataEncryption();
let me = this;
getData(apis.hotgoods, 'get', {
timestamp: obj.timestampStr,
random: obj.randomStr,
signature: obj.singnatrueStr
}, function(res) {
if (res.err_code === 0) {
if (res.data.length) {
me.setData({
rmList: res.data
})
} else {
me.setData({
rmList: []
})
}
} else {
me.setData({
rmList: []
})
}
}, true)
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
onShareAppMessage: function() {
},
bindKeyInput: function (e) {
bindKeyInput: function(e) {
this.setData({
key: e.detail.value
})
},
confirmTap: function () {
confirmTap: function() {
let val = this.data.key;
if (!val.length) {
wx.showToast({
......@@ -89,15 +121,21 @@ Page({
});
} else {
wx.navigateTo({
url: "/pages/search/result/index?key="+val
url: "/pages/search/result/index?key=" + val
})
}
},
deleteHistory:function(){
deleteHistory: function() {
this.setData({
historyList: []
});
wx.removeStorageSync('storageKeys')
},
toSearch:function(e){
let title = e.target.dataset.title;
wx.navigateTo({
url: "/pages/search/result/index?key=" + title
})
}
})
\ No newline at end of file
......@@ -7,12 +7,7 @@
<view class="rm_search" wx:if="{{rmList.length}}">
<text class="title beforeLine">热门搜索</text>
<view class="rm_ls_content row" >
<view class="search-item">LM358</view>
<view class="search-item">TJA1027</view>
<view class="search-item">贴片电阻330k</view>
<view class="search-item">PFB0824GHE</view>
<view class="search-item">T6738-4K</view>
<view class="search-item">ECW-FA2J155J</view>
<view class="search-item" wx:for="{{rmList}}" wx:key="*this" bindtap="toSearch" data-title="{{item.title}}">{{item.title}}</view>
</view>
</view>
<view class="ls_search" wx:if="{{historyList.length}}">
......@@ -21,7 +16,7 @@
<text class="icon iconfont iconiconxiantiaoshouji7" bindtap="deleteHistory"></text>
</view>
<view class="rm_ls_content row">
<view class="search-item" wx:for="{{historyList}}" wx:key="*this">{{item}}</view>
<view class="search-item" wx:for="{{historyList}}" wx:key="*this" bindtap="toSearch" data-title="{{item}}">{{item}}</view>
</view>
</view>
......
// pages/tab/good/good.js
import { getData } from '../../../utils/util.js';
import { getData, judgeToken } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
......@@ -20,7 +20,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getData()
if (judgeToken(true)) {
this.getData();
}
},
bindKeyInput: function (e) {
this.setData({
......
// pages/tab/home/home.js
import { getData } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
import {
getData,
judgeToken
} from '../../../utils/util.js';
import {
apis
} from '../../../utils/api.js';
let timer = null;
Page({
/**
......@@ -12,26 +18,37 @@ Page({
animation: {},
translateY: 0,
tabIndex: 1,
xb: 1,//1表示询价 2表示报价
limit: 10,//每页的条数
xb: 1, //1表示询价 2表示报价
limit: 10, //每页的条数
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getTopData();
this.getData();
onLoad: function(options) {
if (judgeToken()) {
this.getData();
} else {
wx.setStorageSync('homeToken', 1)
}
},
getTopData: function () {
getTopData: function() {
let me = this;
let token = wx.getStorageSync('access_token') || ''
let token = wx.getStorageSync('access_token') || '';
this.setData({
xjList: [],
translateY: 0,
animation: {},
})
if (timer) {
clearInterval(timer)
}
getData(apis.inquirySearch, 'get', {
"offset": 10,
"p": 1,
"add_time/order": "desc",
"token": token
}, function (res) {
}, function(res) {
let newArr = [];
if (res.errcode === 0) {
if (res.total == 0) {
......@@ -43,9 +60,9 @@ Page({
newArr.push(res.inquiry_list[key])
};
let nowDate = Date.parse(new Date());
for(let i=0;i<newArr.length;i++){
let etime = newArr[i].add_time*1000;
let usedTime = me.interval(nowDate-etime);
for (let i = 0; i < newArr.length; i++) {
let etime = newArr[i].add_time * 1000;
let usedTime = me.interval(nowDate - etime);
newArr[i].usedTime = usedTime
}
me.setData({
......@@ -58,15 +75,10 @@ Page({
})
} else {
let allHeight = (arrLen - 2) * 30;
let interVal = setInterval(() => {
timer = setInterval(() => {
let translateY = me.data.translateY;
if (translateY + allHeight == 0) {
// clearInterval(interVal);
// let arr = me.data.xjList.concat();
// let arr1 = arr.splice(arrLen-2,arrLen);
// arr = arr1.concat(arr);
me.setData({
// xjList:arr,
translateY: 0
})
me.translateYAnimation();
......@@ -89,7 +101,7 @@ Page({
}
}, false)
},
getData: function () {
getData: function() {
let me = this;
let url, token = wx.getStorageSync('access_token')
if (!token) {
......@@ -103,7 +115,11 @@ Page({
} else {
url = apis.offerinfo
}
getData(url, 'get', { offset: me.data.limit, p: 1, token: token }, function (res) {
getData(url, 'get', {
offset: me.data.limit,
p: 1,
token: token
}, function(res) {
if (res.errcode === 0) {
let newArr = [];
if (me.data.xb == 1) {
......@@ -124,24 +140,24 @@ Page({
}, true)
}
},
interval: function (usedTime){
interval: function(usedTime) {
let days = Math.floor(usedTime / (24 * 3600 * 1000));
//计算出小时数
let leave1 = usedTime % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
let leave1 = usedTime % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
let hours = Math.floor(leave1 / (3600 * 1000));
//计算相差分钟数
let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
let minutes = Math.floor(leave2 / (60 * 1000));
if(days){
if (days) {
return days + "天前";
}else{
if (hours){
if(minutes){
} else {
if (hours) {
if (minutes) {
return hours + "小时" + minutes + "分钟前";
}else{
} else {
return hours + "小时前";
}
}else{
} else {
if (minutes) {
return minutes + "分钟前";
} else {
......@@ -153,7 +169,7 @@ Page({
/**
* 生命周期函数--监听页面初次渲染完成
*/
translateYAnimation: function () {
translateYAnimation: function() {
let animation = wx.createAnimation({
duration: 1000,
timingFunction: 'ease',
......@@ -164,52 +180,60 @@ Page({
animation: animation.export()
});
},
onReady: function () {
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onShow: function() {
this.getTopData();
if (judgeToken()) {
if (wx.getStorageSync('homeToken')) {
this.getData();
wx.removeStorageSync('homeToken')
}
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
onShareAppMessage: function() {
},
switchTab: function (e) {
switchTab: function(e) {
let i = e.currentTarget.dataset.index;
if (i == this.data.tabIndex) {
return
......@@ -233,24 +257,31 @@ Page({
},
toSearch: function () {
toSearch: function() {
wx.navigateTo({
url: '/pages/search/index/index',
})
},
toXj: function () {
wx.navigateTo({
url: "/pages/form/xj/index"
})
toXj: function() {
if (judgeToken(true)) {
wx.navigateTo({
url: "/pages/form/xj/index"
})
}
},
fbGood: function () {
wx.navigateTo({
url: "/pages/form/good/index",
})
fbGood: function() {
if (judgeToken(true)) {
wx.navigateTo({
url: "/pages/form/good/index",
})
}
},
toQd: function () {
wx.navigateTo({
url: "/pages/list/qd/index"
})
toQd: function() {
if (judgeToken(true)) {
wx.navigateTo({
url: "/pages/list/qd/index"
})
}
}
})
\ No newline at end of file
......@@ -60,10 +60,10 @@
</view>
</view>
<view class="price-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<image src="/res/images/imgs/noxb.png" class="img" style="width:500rpx;"></image>
<view hidden="{{priceList&&priceList.length!=0}}" class="nodata">
<image src="/res/images/imgs/noxb.png" class="img"></image>
<view class="h3 bold">暂无询报价信息</view>
<view class="p" style="color:#61A0F2;padding-top:20rpx;">您还可以发布询价。</view>
<view class="p" style="color:#61A0F2;padding:20rpx 0;" bindtap="toXj">您还可以发布询价。</view>
</view>
<priceItem price-list="{{priceList}}" wx:if="{{priceList&&priceList.length!==0}}" price-type="1" xb="{{xb}}"></priceItem>
</view>
......
......@@ -25,7 +25,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (!http.judgeToken(true)){
return
}
//获取数量统计
http.getData(apis.countBusiness, 'GET', {
token: wx.getStorageSync('access_token')
......
// pages/tab/message/message.js
let disp = require("../../../utils/broadcast");
let WebIM = require("../../../utils/WebIM")["default"];
import { judgeToken } from '../../../utils/util.js';
Page({
/**
......@@ -18,18 +19,21 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
let me = this;
let my = wx.getStorageSync("myUsername");
//监听未读消息数
disp.on("em.xmpp.unreadspot", function(message) {
if (getApp().globalData.customerNum != my) {
me.getCustom()
}
me.setData({
arr: me.getChatList(),
unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
if (judgeToken(true)) {
let me = this;
let my = wx.getStorageSync("myUsername");
//监听未读消息数
disp.on("em.xmpp.unreadspot", function (message) {
if (getApp().globalData.customerNum != my) {
me.getCustom()
}
me.setData({
arr: me.getChatList(),
unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
});
});
});
}
},
getCustom: function() {
let my = wx.getStorageSync("myUsername");
......
// pages/tab/price/price.js
import { getData} from '../../../utils/util.js';
import { getData, judgeToken} from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
......@@ -19,7 +19,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getData();
if (judgeToken(true)) {
this.getData();
}
},
getData:function(){
let me = this;
......@@ -67,7 +69,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
......
......@@ -3,8 +3,7 @@ const so_url = 'http://soapi.icsales.cc';
const offer_url = "http://offerapi.icsales.cc";
const user_url = 'http://userapi.icsales.cc';
const goods_url = 'http://goodsapi.icsales.cc';
const inquiry_url = 'http://inquiryapi.icsales.cc';
const index_url = 'http://www.icsales.cc';
const home_url = 'http://home.icsales.cc';
const apis = {
/**
......@@ -192,6 +191,11 @@ const apis = {
* 环信通讯记录列表(最多显示30条最新的聊天记录)
*/
listrecord: user_url + '/im/list/record',
/***
* 获取热门搜索商品
*/
hotgoods: home_url + '/hotgoods',
}
......
......@@ -12,10 +12,6 @@ let conn = {
closed: false,
curOpenOpt: {},
open(opt) {
/* wx.showLoading({
title: '正在初始化客户端...',
mask: true
}) */
this.curOpenOpt = opt;
WebIM.conn.open(opt);
this.closed = false;
......@@ -30,7 +26,7 @@ let conn = {
const calcUnReadSpot = (message) => {
let myName = wx.getStorageSync("myUsername");
let allMembers = wx.getStorageSync("member") || []; //好友
let count = allMembers.reduce(function(result, curMember, idx) {
let count = allMembers.reduce(function (result, curMember, idx) {
let chatMsgs = wx.getStorageSync(curMember.toLowerCase() + myName.toLowerCase()) || [];
return result + chatMsgs.length;
}, 0);
......@@ -51,7 +47,7 @@ const getImUser = () => {
let token = wx.getStorageSync('access_token') || ''
getData(apis.authme, 'get', {
"token": token,
}, function(res) {
}, function (res) {
if (res.err_code == 0) {
wx.setStorageSync('user_id', res.data.user_id + '');
wx.setStorageSync('avatar', res.data.avatar);
......@@ -76,10 +72,10 @@ const webimListen = () => {
WebIM.conn.setPresence();
},
onReconnect() {
wx.showToast({
title: "重连中...",
duration: 2000
});
// wx.showToast({
// title: "重连中...",
// duration: 2000
// });
},
onSocketConnected() {
/* wx.showToast({
......@@ -88,11 +84,11 @@ const webimListen = () => {
}); */
},
onClosed() {
wx.showToast({
title: "网络已断开",
icon: 'none',
duration: 2000
});
// wx.showToast({
// title: "网络已断开",
// icon: 'none',
// duration: 2000
// });
me.conn.closed = true;
WebIM.conn.close();
},
......@@ -106,11 +102,10 @@ const webimListen = () => {
}
},
onTextMessage(message) {
console.log('接受信息')
if (message) {
if (onMessageError(message)) {
if (getApp().globalData.customerNum != message.from) {
getApp().addChatMember(message.from);
getApp().addChatMemberStorage(message.from);
}
msgStorage.saveReceiveMsg(message, msgType.TEXT);
}
......@@ -120,11 +115,10 @@ const webimListen = () => {
},
onEmojiMessage(message) {
console.log("onEmojiMessage", message);
if (message) {
if (onMessageError(message)) {
if (getApp().globalData.customerNum != message.from) {
getApp().addChatMember(message.from);
getApp().addChatMemberStorage(message.from);
}
msgStorage.saveReceiveMsg(message, msgType.EMOJI);
}
......@@ -132,11 +126,10 @@ const webimListen = () => {
}
},
onPictureMessage(message) {
console.log("onPictureMessage", message);
if (message) {
if (onMessageError(message)) {
if (getApp().globalData.customerNum != message.from) {
getApp().addChatMember(message.from);
getApp().addChatMemberStorage(message.from);
}
msgStorage.saveReceiveMsg(message, msgType.IMAGE);
}
......@@ -145,7 +138,19 @@ const webimListen = () => {
},
// 各种异常
onError(error) {
console.log(error)
if (error.type == 8) {
wx.showModal({
title: '提示',
content: '您的聊天账号被迫下线!',
showCancel:false
})
} else {
wx.showModal({
title: '提示',
content: '聊天系统出现异常!',
showCancel: false
})
}
},
});
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment