Commit 8d410c00 by 施宇

111

parent 60f42551
const WebIM = require("utils/WebIM")["default"]; const WebIM = require("utils/WebIM")["default"];
let chat = require('utils/chat.js'); 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'; import { apis } from './utils/api.js';
App({ App({
globalData: { globalData: {
...@@ -64,8 +64,10 @@ App({ ...@@ -64,8 +64,10 @@ App({
}) })
} }
} }
}) });
if (judgeToken()){
this.getImUser(); this.getImUser();
}
chat.webimListen(); chat.webimListen();
this.checkIsIPhoneX(); this.checkIsIPhoneX();
}, },
......
/* pages/detail/chat/index.wxss */ /* pages/detail/chat/index.wxss */
page{ page{
background-color: #fff; background-color: #fff;
height:auto;
} }
\ No newline at end of file
// pages/search/index/index.js // pages/search/index/index.js
import {
getData,
dataEncryption
} from '../../../utils/util.js';
import {
apis
} from '../../../utils/api.js';
Page({ Page({
/** /**
...@@ -6,74 +13,99 @@ Page({ ...@@ -6,74 +13,99 @@ Page({
*/ */
data: { data: {
key: "", key: "",
historyList:[], historyList: [],
rmList:[] rmList: []
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function(options) {
this.getHotGoods()
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function () { onReady: function() {
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function() {
let storageKeys = wx.getStorageSync('storageKeys') || []; let storageKeys = wx.getStorageSync('storageKeys') || [];
this.setData({ 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({ this.setData({
key: e.detail.value key: e.detail.value
}) })
}, },
confirmTap: function () { confirmTap: function() {
let val = this.data.key; let val = this.data.key;
if (!val.length) { if (!val.length) {
wx.showToast({ wx.showToast({
...@@ -89,15 +121,21 @@ Page({ ...@@ -89,15 +121,21 @@ Page({
}); });
} else { } else {
wx.navigateTo({ wx.navigateTo({
url: "/pages/search/result/index?key="+val url: "/pages/search/result/index?key=" + val
}) })
} }
}, },
deleteHistory:function(){ deleteHistory: function() {
this.setData({ this.setData({
historyList: [] historyList: []
}); });
wx.removeStorageSync('storageKeys') 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 @@ ...@@ -7,12 +7,7 @@
<view class="rm_search" wx:if="{{rmList.length}}"> <view class="rm_search" wx:if="{{rmList.length}}">
<text class="title beforeLine">热门搜索</text> <text class="title beforeLine">热门搜索</text>
<view class="rm_ls_content row" > <view class="rm_ls_content row" >
<view class="search-item">LM358</view> <view class="search-item" wx:for="{{rmList}}" wx:key="*this" bindtap="toSearch" data-title="{{item.title}}">{{item.title}}</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> </view>
</view> </view>
<view class="ls_search" wx:if="{{historyList.length}}"> <view class="ls_search" wx:if="{{historyList.length}}">
...@@ -21,7 +16,7 @@ ...@@ -21,7 +16,7 @@
<text class="icon iconfont iconiconxiantiaoshouji7" bindtap="deleteHistory"></text> <text class="icon iconfont iconiconxiantiaoshouji7" bindtap="deleteHistory"></text>
</view> </view>
<view class="rm_ls_content row"> <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>
</view> </view>
......
// pages/tab/good/good.js // pages/tab/good/good.js
import { getData } from '../../../utils/util.js'; import { getData, judgeToken } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js'; import { apis } from '../../../utils/api.js';
Page({ Page({
...@@ -20,7 +20,9 @@ Page({ ...@@ -20,7 +20,9 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
this.getData() if (judgeToken(true)) {
this.getData();
}
}, },
bindKeyInput: function (e) { bindKeyInput: function (e) {
this.setData({ this.setData({
......
// pages/tab/home/home.js // pages/tab/home/home.js
import { getData } from '../../../utils/util.js'; import {
import { apis } from '../../../utils/api.js'; getData,
judgeToken
} from '../../../utils/util.js';
import {
apis
} from '../../../utils/api.js';
let timer = null;
Page({ Page({
/** /**
...@@ -12,26 +18,37 @@ Page({ ...@@ -12,26 +18,37 @@ Page({
animation: {}, animation: {},
translateY: 0, translateY: 0,
tabIndex: 1, tabIndex: 1,
xb: 1,//1表示询价 2表示报价 xb: 1, //1表示询价 2表示报价
limit: 10,//每页的条数 limit: 10, //每页的条数
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function(options) {
this.getTopData(); if (judgeToken()) {
this.getData(); this.getData();
} else {
wx.setStorageSync('homeToken', 1)
}
}, },
getTopData: function () { getTopData: function() {
let me = this; 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', { getData(apis.inquirySearch, 'get', {
"offset": 10, "offset": 10,
"p": 1, "p": 1,
"add_time/order": "desc", "add_time/order": "desc",
"token": token "token": token
}, function (res) { }, function(res) {
let newArr = []; let newArr = [];
if (res.errcode === 0) { if (res.errcode === 0) {
if (res.total == 0) { if (res.total == 0) {
...@@ -43,9 +60,9 @@ Page({ ...@@ -43,9 +60,9 @@ Page({
newArr.push(res.inquiry_list[key]) newArr.push(res.inquiry_list[key])
}; };
let nowDate = Date.parse(new Date()); let nowDate = Date.parse(new Date());
for(let i=0;i<newArr.length;i++){ for (let i = 0; i < newArr.length; i++) {
let etime = newArr[i].add_time*1000; let etime = newArr[i].add_time * 1000;
let usedTime = me.interval(nowDate-etime); let usedTime = me.interval(nowDate - etime);
newArr[i].usedTime = usedTime newArr[i].usedTime = usedTime
} }
me.setData({ me.setData({
...@@ -58,15 +75,10 @@ Page({ ...@@ -58,15 +75,10 @@ Page({
}) })
} else { } else {
let allHeight = (arrLen - 2) * 30; let allHeight = (arrLen - 2) * 30;
let interVal = setInterval(() => { timer = setInterval(() => {
let translateY = me.data.translateY; let translateY = me.data.translateY;
if (translateY + allHeight == 0) { 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({ me.setData({
// xjList:arr,
translateY: 0 translateY: 0
}) })
me.translateYAnimation(); me.translateYAnimation();
...@@ -89,7 +101,7 @@ Page({ ...@@ -89,7 +101,7 @@ Page({
} }
}, false) }, false)
}, },
getData: function () { getData: function() {
let me = this; let me = this;
let url, token = wx.getStorageSync('access_token') let url, token = wx.getStorageSync('access_token')
if (!token) { if (!token) {
...@@ -103,7 +115,11 @@ Page({ ...@@ -103,7 +115,11 @@ Page({
} else { } else {
url = apis.offerinfo 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) { if (res.errcode === 0) {
let newArr = []; let newArr = [];
if (me.data.xb == 1) { if (me.data.xb == 1) {
...@@ -124,7 +140,7 @@ Page({ ...@@ -124,7 +140,7 @@ Page({
}, true) }, true)
} }
}, },
interval: function (usedTime){ interval: function(usedTime) {
let days = Math.floor(usedTime / (24 * 3600 * 1000)); let days = Math.floor(usedTime / (24 * 3600 * 1000));
//计算出小时数 //计算出小时数
let leave1 = usedTime % (24 * 3600 * 1000); //计算天数后剩余的毫秒数 let leave1 = usedTime % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
...@@ -132,16 +148,16 @@ Page({ ...@@ -132,16 +148,16 @@ Page({
//计算相差分钟数 //计算相差分钟数
let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数 let leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
let minutes = Math.floor(leave2 / (60 * 1000)); let minutes = Math.floor(leave2 / (60 * 1000));
if(days){ if (days) {
return days + "天前"; return days + "天前";
}else{ } else {
if (hours){ if (hours) {
if(minutes){ if (minutes) {
return hours + "小时" + minutes + "分钟前"; return hours + "小时" + minutes + "分钟前";
}else{ } else {
return hours + "小时前"; return hours + "小时前";
} }
}else{ } else {
if (minutes) { if (minutes) {
return minutes + "分钟前"; return minutes + "分钟前";
} else { } else {
...@@ -153,7 +169,7 @@ Page({ ...@@ -153,7 +169,7 @@ Page({
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
translateYAnimation: function () { translateYAnimation: function() {
let animation = wx.createAnimation({ let animation = wx.createAnimation({
duration: 1000, duration: 1000,
timingFunction: 'ease', timingFunction: 'ease',
...@@ -164,52 +180,60 @@ Page({ ...@@ -164,52 +180,60 @@ Page({
animation: animation.export() 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; let i = e.currentTarget.dataset.index;
if (i == this.data.tabIndex) { if (i == this.data.tabIndex) {
return return
...@@ -233,24 +257,31 @@ Page({ ...@@ -233,24 +257,31 @@ Page({
}, },
toSearch: function () { toSearch: function() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/search/index/index', url: '/pages/search/index/index',
}) })
}, },
toXj: function () { toXj: function() {
if (judgeToken(true)) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/form/xj/index" url: "/pages/form/xj/index"
}) })
}
}, },
fbGood: function () { fbGood: function() {
if (judgeToken(true)) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/form/good/index", url: "/pages/form/good/index",
}) })
}
}, },
toQd: function () { toQd: function() {
if (judgeToken(true)) {
wx.navigateTo({ wx.navigateTo({
url: "/pages/list/qd/index" url: "/pages/list/qd/index"
}) })
} }
}
}) })
\ No newline at end of file
...@@ -60,10 +60,10 @@ ...@@ -60,10 +60,10 @@
</view> </view>
</view> </view>
<view class="price-content"> <view class="price-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata"> <view hidden="{{priceList&&priceList.length!=0}}" class="nodata">
<image src="/res/images/imgs/noxb.png" class="img" style="width:500rpx;"></image> <image src="/res/images/imgs/noxb.png" class="img"></image>
<view class="h3 bold">暂无询报价信息</view> <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> </view>
<priceItem price-list="{{priceList}}" wx:if="{{priceList&&priceList.length!==0}}" price-type="1" xb="{{xb}}"></priceItem> <priceItem price-list="{{priceList}}" wx:if="{{priceList&&priceList.length!==0}}" price-type="1" xb="{{xb}}"></priceItem>
</view> </view>
......
...@@ -25,7 +25,9 @@ Page({ ...@@ -25,7 +25,9 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
if (!http.judgeToken(true)){
return
}
//获取数量统计 //获取数量统计
http.getData(apis.countBusiness, 'GET', { http.getData(apis.countBusiness, 'GET', {
token: wx.getStorageSync('access_token') token: wx.getStorageSync('access_token')
......
// pages/tab/message/message.js // pages/tab/message/message.js
let disp = require("../../../utils/broadcast"); let disp = require("../../../utils/broadcast");
let WebIM = require("../../../utils/WebIM")["default"]; let WebIM = require("../../../utils/WebIM")["default"];
import { judgeToken } from '../../../utils/util.js';
Page({ Page({
/** /**
...@@ -18,10 +19,11 @@ Page({ ...@@ -18,10 +19,11 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function(options) { onLoad: function(options) {
if (judgeToken(true)) {
let me = this; let me = this;
let my = wx.getStorageSync("myUsername"); let my = wx.getStorageSync("myUsername");
//监听未读消息数 //监听未读消息数
disp.on("em.xmpp.unreadspot", function(message) { disp.on("em.xmpp.unreadspot", function (message) {
if (getApp().globalData.customerNum != my) { if (getApp().globalData.customerNum != my) {
me.getCustom() me.getCustom()
} }
...@@ -30,6 +32,8 @@ Page({ ...@@ -30,6 +32,8 @@ Page({
unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum, unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
}); });
}); });
}
}, },
getCustom: function() { getCustom: function() {
let my = wx.getStorageSync("myUsername"); let my = wx.getStorageSync("myUsername");
......
// pages/tab/price/price.js // pages/tab/price/price.js
import { getData} from '../../../utils/util.js'; import { getData, judgeToken} from '../../../utils/util.js';
import { apis } from '../../../utils/api.js'; import { apis } from '../../../utils/api.js';
Page({ Page({
...@@ -19,7 +19,9 @@ Page({ ...@@ -19,7 +19,9 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
if (judgeToken(true)) {
this.getData(); this.getData();
}
}, },
getData:function(){ getData:function(){
let me = this; let me = this;
......
...@@ -3,8 +3,7 @@ const so_url = 'http://soapi.icsales.cc'; ...@@ -3,8 +3,7 @@ const so_url = 'http://soapi.icsales.cc';
const offer_url = "http://offerapi.icsales.cc"; const offer_url = "http://offerapi.icsales.cc";
const user_url = 'http://userapi.icsales.cc'; const user_url = 'http://userapi.icsales.cc';
const goods_url = 'http://goodsapi.icsales.cc'; const goods_url = 'http://goodsapi.icsales.cc';
const inquiry_url = 'http://inquiryapi.icsales.cc'; const home_url = 'http://home.icsales.cc';
const index_url = 'http://www.icsales.cc';
const apis = { const apis = {
/** /**
...@@ -192,6 +191,11 @@ const apis = { ...@@ -192,6 +191,11 @@ const apis = {
* 环信通讯记录列表(最多显示30条最新的聊天记录) * 环信通讯记录列表(最多显示30条最新的聊天记录)
*/ */
listrecord: user_url + '/im/list/record', listrecord: user_url + '/im/list/record',
/***
* 获取热门搜索商品
*/
hotgoods: home_url + '/hotgoods',
} }
......
...@@ -12,10 +12,6 @@ let conn = { ...@@ -12,10 +12,6 @@ let conn = {
closed: false, closed: false,
curOpenOpt: {}, curOpenOpt: {},
open(opt) { open(opt) {
/* wx.showLoading({
title: '正在初始化客户端...',
mask: true
}) */
this.curOpenOpt = opt; this.curOpenOpt = opt;
WebIM.conn.open(opt); WebIM.conn.open(opt);
this.closed = false; this.closed = false;
...@@ -30,7 +26,7 @@ let conn = { ...@@ -30,7 +26,7 @@ let conn = {
const calcUnReadSpot = (message) => { const calcUnReadSpot = (message) => {
let myName = wx.getStorageSync("myUsername"); let myName = wx.getStorageSync("myUsername");
let allMembers = wx.getStorageSync("member") || []; //好友 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()) || []; let chatMsgs = wx.getStorageSync(curMember.toLowerCase() + myName.toLowerCase()) || [];
return result + chatMsgs.length; return result + chatMsgs.length;
}, 0); }, 0);
...@@ -51,7 +47,7 @@ const getImUser = () => { ...@@ -51,7 +47,7 @@ const getImUser = () => {
let token = wx.getStorageSync('access_token') || '' let token = wx.getStorageSync('access_token') || ''
getData(apis.authme, 'get', { getData(apis.authme, 'get', {
"token": token, "token": token,
}, function(res) { }, function (res) {
if (res.err_code == 0) { if (res.err_code == 0) {
wx.setStorageSync('user_id', res.data.user_id + ''); wx.setStorageSync('user_id', res.data.user_id + '');
wx.setStorageSync('avatar', res.data.avatar); wx.setStorageSync('avatar', res.data.avatar);
...@@ -76,10 +72,10 @@ const webimListen = () => { ...@@ -76,10 +72,10 @@ const webimListen = () => {
WebIM.conn.setPresence(); WebIM.conn.setPresence();
}, },
onReconnect() { onReconnect() {
wx.showToast({ // wx.showToast({
title: "重连中...", // title: "重连中...",
duration: 2000 // duration: 2000
}); // });
}, },
onSocketConnected() { onSocketConnected() {
/* wx.showToast({ /* wx.showToast({
...@@ -88,11 +84,11 @@ const webimListen = () => { ...@@ -88,11 +84,11 @@ const webimListen = () => {
}); */ }); */
}, },
onClosed() { onClosed() {
wx.showToast({ // wx.showToast({
title: "网络已断开", // title: "网络已断开",
icon: 'none', // icon: 'none',
duration: 2000 // duration: 2000
}); // });
me.conn.closed = true; me.conn.closed = true;
WebIM.conn.close(); WebIM.conn.close();
}, },
...@@ -106,11 +102,10 @@ const webimListen = () => { ...@@ -106,11 +102,10 @@ const webimListen = () => {
} }
}, },
onTextMessage(message) { onTextMessage(message) {
console.log('接受信息')
if (message) { if (message) {
if (onMessageError(message)) { if (onMessageError(message)) {
if (getApp().globalData.customerNum != message.from) { if (getApp().globalData.customerNum != message.from) {
getApp().addChatMember(message.from); getApp().addChatMemberStorage(message.from);
} }
msgStorage.saveReceiveMsg(message, msgType.TEXT); msgStorage.saveReceiveMsg(message, msgType.TEXT);
} }
...@@ -120,11 +115,10 @@ const webimListen = () => { ...@@ -120,11 +115,10 @@ const webimListen = () => {
}, },
onEmojiMessage(message) { onEmojiMessage(message) {
console.log("onEmojiMessage", message);
if (message) { if (message) {
if (onMessageError(message)) { if (onMessageError(message)) {
if (getApp().globalData.customerNum != message.from) { if (getApp().globalData.customerNum != message.from) {
getApp().addChatMember(message.from); getApp().addChatMemberStorage(message.from);
} }
msgStorage.saveReceiveMsg(message, msgType.EMOJI); msgStorage.saveReceiveMsg(message, msgType.EMOJI);
} }
...@@ -132,11 +126,10 @@ const webimListen = () => { ...@@ -132,11 +126,10 @@ const webimListen = () => {
} }
}, },
onPictureMessage(message) { onPictureMessage(message) {
console.log("onPictureMessage", message);
if (message) { if (message) {
if (onMessageError(message)) { if (onMessageError(message)) {
if (getApp().globalData.customerNum != message.from) { if (getApp().globalData.customerNum != message.from) {
getApp().addChatMember(message.from); getApp().addChatMemberStorage(message.from);
} }
msgStorage.saveReceiveMsg(message, msgType.IMAGE); msgStorage.saveReceiveMsg(message, msgType.IMAGE);
} }
...@@ -145,7 +138,19 @@ const webimListen = () => { ...@@ -145,7 +138,19 @@ const webimListen = () => {
}, },
// 各种异常 // 各种异常
onError(error) { onError(error) {
console.log(error) if (error.type == 8) {
wx.showModal({
title: '提示',
content: '您的聊天账号被迫下线!',
showCancel:false
})
} else {
wx.showModal({
title: '提示',
content: '聊天系统出现异常!',
showCancel: false
})
}
}, },
}); });
}; };
......
...@@ -11,7 +11,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => { ...@@ -11,7 +11,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => {
if (istoken) { if (istoken) {
var params = Object.assign({}, param, { var params = Object.assign({}, param, {
source: 1, source: 1,
token:token token: token
}); });
} else { } else {
var params = Object.assign({}, param, { var params = Object.assign({}, param, {
...@@ -145,18 +145,126 @@ const tips = (text) => { ...@@ -145,18 +145,126 @@ const tips = (text) => {
}); });
} }
const changeTime = (str) => { const changeTime = (str) => {
var date = new Date(str); let date = new Date(str);
var Hours = date.getHours(); let Hours = date.getHours();
var Minutes = date.getMinutes(); let Minutes = date.getMinutes();
var Seconds = date.getSeconds(); let Seconds = date.getSeconds();
var Month = date.getMonth() + 1; let Month = date.getMonth() + 1;
var Day = date.getDate(); let Day = date.getDate();
var time = date.getFullYear() + "-" + (Month < 10 ? "0" + Month : Month) + "-" + (Day < 10 ? "0" + Day : Day) + " " let time = date.getFullYear() + "-" + (Month < 10 ? "0" + Month : Month) + "-" + (Day < 10 ? "0" + Day : Day) + " " +
+ (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds); (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds);
return time;} return time;
}
const randomFun = () => {
let str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let newStr = "";
for (let i = 0; i < 8; i++) {
let randomNum = parseInt(Math.random() * ((str.length - 1) + 1), 10);
newStr += str.substr(randomNum, 1)
}
return newStr
}
const sort = (arr) => {
for (let j = 0; j < arr.length; j++) {
for (let i = 0; i < arr.length - 1 - j; i++) {
if (arr[i] > arr[i + 1]) {
[arr[i], arr[i + 1]] = [arr[i + 1], arr[i]]
}
}
}
return arr;
}
const encodeUTF8 = (s) => {
var i, r = [],
c, x;
for (i = 0; i < s.length; i++)
if ((c = s.charCodeAt(i)) < 0x80) r.push(c);
else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F));
else {
if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode
c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000,
r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F));
else r.push(0xE0 + (c >> 12 & 0xF));
r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
};
return r;
};
const sha1 = (s) => {
var data = new Uint8Array(encodeUTF8(s))
var i, j, t;
var l = ((data.length + 8) >>> 6 << 4) + 16,
s = new Uint8Array(l << 2);
s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer);
for (t = new DataView(s.buffer), i = 0; i < l; i++) s[i] = t.getUint32(i << 2);
s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8);
s[l - 1] = data.length << 3;
var w = [],
f = [
function() {
return m[1] & m[2] | ~m[1] & m[3];
},
function() {
return m[1] ^ m[2] ^ m[3];
},
function() {
return m[1] & m[2] | m[1] & m[3] | m[2] & m[3];
},
function() {
return m[1] ^ m[2] ^ m[3];
}
],
rol = function(n, c) {
return n << c | n >>> (32 - c);
},
k = [1518500249, 1859775393, -1894007588, -899497514],
m = [1732584193, -271733879, null, null, -1009589776];
m[2] = ~m[0], m[3] = ~m[1];
for (i = 0; i < s.length; i += 16) {
var o = m.slice(0);
for (j = 0; j < 80; j++)
w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1),
t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0,
m[1] = rol(m[1], 30), m.pop(), m.unshift(t);
for (j = 0; j < 5; j++) m[j] = m[j] + o[j] | 0;
};
t = new DataView(new Uint32Array(m).buffer);
for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2);
var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function(e) {
return (e < 16 ? "0" : "") + e.toString(16);
}).join("");
return hex;
};
const dataEncryption = () => {
let timestamp = Date.parse(new Date()) / 1000;
let randomStr = randomFun();
let token = 'zbPx8gDXDfIh3ZoJcO4EH';
let arr = [timestamp, randomStr, token];
let singnatrueStr = sha1(sort(arr).join('')).toUpperCase();
return {
randomStr: randomStr,
singnatrueStr: singnatrueStr,
timestampStr: timestamp
}
}
const judgeToken = (boolen) => {
let token = wx.getStorageSync('access_token');
if(token){
return true
}else{
if(boolen){
wx.redirectTo({
url: '/pages/person/login/index',
})
}
return false;
}
}
module.exports = { module.exports = {
getData: getData, getData: getData,
chooseImg: chooseImg, chooseImg: chooseImg,
tips:tips, tips: tips,
changeTime:changeTime changeTime: changeTime,
dataEncryption: dataEncryption,
judgeToken:judgeToken
} }
\ No newline at end of file
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