Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
施宇
/
icsalesProgram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8d410c00
authored
Aug 06, 2019
by
施宇
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
111
parent
60f42551
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
462 additions
and
264 deletions
app.js
pages/detail/chat/index.wxss
pages/search/index/index.js
pages/search/index/index.wxml
pages/tab/good/good.js
pages/tab/home/home.js
pages/tab/home/home.wxml
pages/tab/me/me.js
pages/tab/message/message.js
pages/tab/price/price.js
utils/api.js
utils/chat.js
utils/util.js
app.js
View file @
8d410c00
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
View file @
8d410c00
/* pages/detail/chat/index.wxss */
page{
background-color: #fff;
height:auto;
}
\ No newline at end of file
pages/search/index/index.js
View file @
8d410c00
// 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
pages/search/index/index.wxml
View file @
8d410c00
...
...
@@ -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
View file @
8d410c00
// 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
View file @
8d410c00
// 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
pages/tab/home/home.wxml
View file @
8d410c00
...
...
@@ -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>
...
...
pages/tab/me/me.js
View file @
8d410c00
...
...
@@ -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
View file @
8d410c00
// 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
View file @
8d410c00
// 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
()
{
},
/**
...
...
utils/api.js
View file @
8d410c00
...
...
@@ -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'
,
}
...
...
utils/chat.js
View file @
8d410c00
...
...
@@ -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
().
addChatMember
Storage
(
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
().
addChatMember
Storage
(
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
().
addChatMember
Storage
(
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
})
}
},
});
};
...
...
utils/util.js
View file @
8d410c00
//数据请求(get,post)
const
getData
=
(
url
,
type
,
param
,
callBack
,
loading
,
isheader
,
istoken
)
=>
{
wx
.
showNavigationBarLoading
();
var
token
,
header
;
//获取token
token
=
wx
.
getStorageSync
(
'access_token'
);
//参数字段追加来源字段,token字段
if
(
istoken
)
{
var
params
=
Object
.
assign
({},
param
,
{
source
:
1
,
token
:
token
});
}
else
{
var
params
=
Object
.
assign
({},
param
,
{
source
:
1
});
}
//是否启用loading加载效果
if
(
loading
)
{
wx
.
showLoading
();
}
//是否启用请求头token
if
(
isheader
)
{
header
=
{
"Content-Type"
:
"applciation/json"
,
"Authorization"
:
'Bearer '
+
token
}
}
else
{
header
=
{
"Content-Type"
:
"applciation/json"
}
}
wx
.
request
({
url
:
url
,
data
:
params
,
header
:
header
,
method
:
type
,
success
:
(
res
)
=>
{
//处理token失效的情况
if
(
res
.
data
.
hasOwnProperty
(
'data'
))
{
if
(
res
.
data
.
data
.
err_code
===
501
||
res
.
data
.
data
.
errcode
===
501
)
{
wx
.
navigateTo
({
url
:
'/pages/person/login/index'
});
}
else
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
}
}
else
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
}
wx
.
hideNavigationBarLoading
();
if
(
loading
)
{
wx
.
hideLoading
();
}
},
fail
:
(
err
)
=>
{
typeof
callBack
==
"function"
&&
callBack
(
null
,
err
.
errMsg
);
console
.
log
(
err
);
wx
.
hideNavigationBarLoading
();
if
(
loading
)
{
wx
.
hideLoading
();
}
}
})
wx
.
showNavigationBarLoading
();
var
token
,
header
;
//获取token
token
=
wx
.
getStorageSync
(
'access_token'
);
//参数字段追加来源字段,token字段
if
(
istoken
)
{
var
params
=
Object
.
assign
({},
param
,
{
source
:
1
,
token
:
token
});
}
else
{
var
params
=
Object
.
assign
({},
param
,
{
source
:
1
});
}
//是否启用loading加载效果
if
(
loading
)
{
wx
.
showLoading
();
}
//是否启用请求头token
if
(
isheader
)
{
header
=
{
"Content-Type"
:
"applciation/json"
,
"Authorization"
:
'Bearer '
+
token
}
}
else
{
header
=
{
"Content-Type"
:
"applciation/json"
}
}
wx
.
request
({
url
:
url
,
data
:
params
,
header
:
header
,
method
:
type
,
success
:
(
res
)
=>
{
//处理token失效的情况
if
(
res
.
data
.
hasOwnProperty
(
'data'
))
{
if
(
res
.
data
.
data
.
err_code
===
501
||
res
.
data
.
data
.
errcode
===
501
)
{
wx
.
navigateTo
({
url
:
'/pages/person/login/index'
});
}
else
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
}
}
else
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
}
wx
.
hideNavigationBarLoading
();
if
(
loading
)
{
wx
.
hideLoading
();
}
},
fail
:
(
err
)
=>
{
typeof
callBack
==
"function"
&&
callBack
(
null
,
err
.
errMsg
);
console
.
log
(
err
);
wx
.
hideNavigationBarLoading
();
if
(
loading
)
{
wx
.
hideLoading
();
}
}
})
};
//上传文件
const
uploadFile
=
(
url
,
paths
,
callBack
)
=>
{
wx
.
showLoading
({
title
:
'上传中'
,
mask
:
true
})
for
(
var
i
=
0
;
i
<
paths
.
length
;
i
++
)
{
wx
.
uploadFile
({
url
:
url
,
filePath
:
paths
[
i
],
name
:
'upload'
,
formData
:
{
token
:
wx
.
getStorageSync
(
'access_token'
),
source
:
2
},
header
:
{
"Content-Type"
:
"multipart/form-data"
},
success
:
(
res
)
=>
{
var
data
=
JSON
.
parse
(
res
.
data
);
if
(
data
.
errcode
==
103200
)
{
callBack
(
data
.
data
[
0
])
}
else
{
wx
.
showToast
({
title
:
'上传失败'
,
icon
:
'none'
,
duration
:
2000
});
}
},
fail
:
(
e
)
=>
{
console
.
log
(
e
)
wx
.
showToast
({
title
:
'上传失败'
,
icon
:
'none'
,
duration
:
2000
});
},
complete
:
()
=>
{
wx
.
hideLoading
();
}
})
}
wx
.
showLoading
({
title
:
'上传中'
,
mask
:
true
})
for
(
var
i
=
0
;
i
<
paths
.
length
;
i
++
)
{
wx
.
uploadFile
({
url
:
url
,
filePath
:
paths
[
i
],
name
:
'upload'
,
formData
:
{
token
:
wx
.
getStorageSync
(
'access_token'
),
source
:
2
},
header
:
{
"Content-Type"
:
"multipart/form-data"
},
success
:
(
res
)
=>
{
var
data
=
JSON
.
parse
(
res
.
data
);
if
(
data
.
errcode
==
103200
)
{
callBack
(
data
.
data
[
0
])
}
else
{
wx
.
showToast
({
title
:
'上传失败'
,
icon
:
'none'
,
duration
:
2000
});
}
},
fail
:
(
e
)
=>
{
console
.
log
(
e
)
wx
.
showToast
({
title
:
'上传失败'
,
icon
:
'none'
,
duration
:
2000
});
},
complete
:
()
=>
{
wx
.
hideLoading
();
}
})
}
};
const
chooseImg
=
(
url
,
num
,
callback
)
=>
{
wx
.
chooseImage
({
count
:
num
,
sizeType
:
[
'original'
,
'compressed'
],
sourceType
:
[
'album'
,
'camera'
],
success
:
(
res
)
=>
{
uploadFile
(
url
,
res
.
tempFilePaths
,
(
rtn
)
=>
{
callback
(
rtn
)
})
}
})
wx
.
chooseImage
({
count
:
num
,
sizeType
:
[
'original'
,
'compressed'
],
sourceType
:
[
'album'
,
'camera'
],
success
:
(
res
)
=>
{
uploadFile
(
url
,
res
.
tempFilePaths
,
(
rtn
)
=>
{
callback
(
rtn
)
})
}
})
};
const
tips
=
(
text
)
=>
{
wx
.
showToast
({
...
...
@@ -144,19 +144,127 @@ const tips = (text) => {
duration
:
2000
});
}
const
changeTime
=
(
str
)
=>
{
var
date
=
new
Date
(
str
);
var
Hours
=
date
.
getHours
();
var
Minutes
=
date
.
getMinutes
();
var
Seconds
=
date
.
getSeconds
();
var
Month
=
date
.
getMonth
()
+
1
;
var
Day
=
date
.
getDate
();
var
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
);
return
time
;}
const
changeTime
=
(
str
)
=>
{
let
date
=
new
Date
(
str
);
let
Hours
=
date
.
getHours
();
let
Minutes
=
date
.
getMinutes
();
let
Seconds
=
date
.
getSeconds
();
let
Month
=
date
.
getMonth
()
+
1
;
let
Day
=
date
.
getDate
();
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
);
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
=
{
getData
:
getData
,
getData
:
getData
,
chooseImg
:
chooseImg
,
tips
:
tips
,
changeTime
:
changeTime
tips
:
tips
,
changeTime
:
changeTime
,
dataEncryption
:
dataEncryption
,
judgeToken
:
judgeToken
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment