客户端app
This commit is contained in:
213
im-uniapp/common/appUpgrade.js
Normal file
213
im-uniapp/common/appUpgrade.js
Normal file
@@ -0,0 +1,213 @@
|
||||
var _maskView, _contentView, _downloadTask, _loadingProgress, _screenHeight, _screenWidth, _config = {
|
||||
forceUpgrade: false,
|
||||
titleText: "版本更新",
|
||||
content: "",
|
||||
contentAlign: "left",
|
||||
loadingColor: "#329EEE",
|
||||
cancelText: "暂不升级",
|
||||
cancelColor: "#666",
|
||||
confirmText: "立即升级",
|
||||
confirmColor: "#329EEE",
|
||||
windowHeight: 380,
|
||||
packageUrl: "",
|
||||
browser: false,
|
||||
maskColor: "rgba(0,0,0,0.3)"
|
||||
},
|
||||
_calculatePosition = function() {
|
||||
return {
|
||||
top: (_screenHeight - _config.windowHeight) / 2,
|
||||
left: _screenWidth * .05,
|
||||
width: _screenWidth * .9,
|
||||
right: _screenWidth * .05,
|
||||
height: _config.windowHeight
|
||||
}
|
||||
},
|
||||
_createMask = function() {
|
||||
_maskView = new plus.nativeObj.View("maskView", {
|
||||
top: "0px",
|
||||
left: "0px",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
backgroundColor: _config.maskColor
|
||||
})
|
||||
},
|
||||
_createContentView = function() {
|
||||
var calculatePosition = _calculatePosition();
|
||||
_contentView = new plus.nativeObj.View("contentView", {
|
||||
top: calculatePosition.top + "px",
|
||||
left: calculatePosition.left + "px",
|
||||
height: _config.windowHeight + "px",
|
||||
width: calculatePosition.width + "px",
|
||||
overflow: "auto"
|
||||
});
|
||||
_contentView.drawRect({
|
||||
color: "#ffffff",
|
||||
radius: "20px"
|
||||
}, {
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
}, "roundedRect");
|
||||
_contentView.drawText(_config.titleText, {
|
||||
top: "20px",
|
||||
height: "20px",
|
||||
}, {
|
||||
size: "16px",
|
||||
color: "#333",
|
||||
align: "center",
|
||||
}, "titleText");
|
||||
_contentView.drawText(_config.content, {
|
||||
top: "60px",
|
||||
left: "20px",
|
||||
right: "20px",
|
||||
height: _config.windowHeight - 120 + "px",
|
||||
}, {
|
||||
size: "16px",
|
||||
color: "#666",
|
||||
align: _config.contentAlign,
|
||||
verticalAlign: "top",
|
||||
whiteSpace: "normal",
|
||||
overflow: "ellipsis"
|
||||
}, "UpdaterContent");
|
||||
_createLoading(-2);
|
||||
var top = _config.windowHeight - 60 + 15;
|
||||
var fontSize = '16px';
|
||||
if (!_config.forceUpgrade) {
|
||||
_contentView.drawRichText("<font style=\"font-size:" + fontSize + ";\" color=\"" + _config.cancelColor +
|
||||
"\">" + _config
|
||||
.cancelText + "</font>", {
|
||||
width: "50%",
|
||||
top: top + "px",
|
||||
left: "0px"
|
||||
}, {
|
||||
align: "center",
|
||||
onClick: function() {
|
||||
close()
|
||||
}
|
||||
}, "cancel");
|
||||
_contentView.drawRichText("<font color=\"" + _config.confirmColor +
|
||||
"\" style=\"font-size:" + fontSize + ";\">" +
|
||||
_config.confirmText + "</font>", {
|
||||
width: "50%",
|
||||
right: "0px",
|
||||
top: top + "px"
|
||||
}, {
|
||||
align: "center",
|
||||
onClick: function() {
|
||||
_config.packageUrl ? "android" === plus.os.name.toLowerCase() ? _config.browser ? (plus
|
||||
.runtime.openURL(_config.packageUrl)) : _createTask() : plus.runtime.openURL(
|
||||
_config.packageUrl) : uni.showToast({
|
||||
title: "安装包地址为空",
|
||||
icon: "none"
|
||||
})
|
||||
}
|
||||
}, "submit")
|
||||
} else {
|
||||
_contentView.drawRichText("<font color=\"" + _config.confirmColor + "\" style=\"font-size:" + fontSize +
|
||||
";\">" +
|
||||
_config.confirmText + "</font>", {
|
||||
width: "100%",
|
||||
right: "0px",
|
||||
top: top + "px"
|
||||
}, {
|
||||
align: "center",
|
||||
onClick: function() {
|
||||
_config.packageUrl ? "android" === plus.os.name.toLowerCase() ? _config.browser ? (plus
|
||||
.runtime.openURL(_config.packageUrl)) : _createTask() : plus.runtime.openURL(
|
||||
_config.packageUrl) : uni.showToast({
|
||||
title: "安装包地址为空",
|
||||
icon: "none"
|
||||
})
|
||||
}
|
||||
}, "submit")
|
||||
}
|
||||
},
|
||||
_createLoading = function(progress) {
|
||||
var calculatePosition = _calculatePosition();
|
||||
var top = _config.windowHeight - 65;
|
||||
var width = 0 <= progress ? (calculatePosition.width - 100) / 100 * progress : 0;
|
||||
width = parseInt(width);
|
||||
var text = 100 <= progress ? "下载完成" : "下载中...";
|
||||
var loadingText = "";
|
||||
loadingText = -1 == progress ? "资源加载中..." : 0 <= progress ? text + "(" + progress + "%)" : "";
|
||||
_contentView.drawRect({
|
||||
color: _config.loadingColor
|
||||
}, {
|
||||
width: width + "px",
|
||||
height: "3px",
|
||||
left: "20px",
|
||||
top: top + "px"
|
||||
}, "loading");
|
||||
_contentView.drawRichText("<font color=\"" + _config.loadingColor + "\">" + loadingText + "</font>", {
|
||||
width: "100px",
|
||||
top: top + "px",
|
||||
left: width + "px"
|
||||
}, {
|
||||
align: "center"
|
||||
}, "loadingText")
|
||||
},
|
||||
_createTask = function() {
|
||||
return _downloadTask ? void console.log("正在下载中") : void(_createLoading(-1),
|
||||
_downloadTask =
|
||||
uni.downloadFile({
|
||||
url: _config.packageUrl,
|
||||
success: function(res) {
|
||||
if (200 === res.statusCode) {
|
||||
var tempFilePath = res.tempFilePath;
|
||||
uni.saveFile({
|
||||
tempFilePath: tempFilePath,
|
||||
success: function(res) {
|
||||
plus.runtime.install(res.savedFilePath, {
|
||||
force: true
|
||||
}, function(res) {
|
||||
console.log('安装包信息' + JSON.stringify(res))
|
||||
}, function(res) {
|
||||
uni.showToast({
|
||||
title: '安装失败,请检查下载链接',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
});
|
||||
close();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}), _downloadTask.onProgressUpdate(function(res) {
|
||||
_loadingProgress != res.progress && (_loadingProgress = res.progress, _createLoading(res
|
||||
.progress));
|
||||
}))
|
||||
},
|
||||
init = function(option) {
|
||||
_screenHeight = plus.screen.resolutionHeight;
|
||||
_screenWidth = plus.screen.resolutionWidth;
|
||||
_downloadTask = null;
|
||||
option.titleText && (_config.titleText = option.titleText);
|
||||
option.windowHeight && (_config.windowHeight = option.windowHeight);
|
||||
option.forceUpgrade && (_config.forceUpgrade = option.forceUpgrade);
|
||||
option.content && (_config.content = option.content);
|
||||
option.contentAlign && (_config.contentAlign = option.contentAlign);
|
||||
option.loadingColor && (_config.loadingColor = option.loadingColor);
|
||||
option.cancelText && (_config.cancelText = option.cancelText);
|
||||
option.cancelColor && (_config.cancelColor = option.cancelColor);
|
||||
option.confirmText && (_config.confirmText = option.confirmText);
|
||||
option.confirmColor && (_config.confirmColor = option.confirmColor);
|
||||
option.packageUrl && (_config.packageUrl = option.packageUrl);
|
||||
option.browser && (_config.browser = option.browser);
|
||||
option.maskColor && (_config.maskColor = option.maskColor);
|
||||
_createMask();
|
||||
_createContentView();
|
||||
},
|
||||
show = function() {
|
||||
_maskView && _maskView.show();
|
||||
_contentView && _contentView.show();
|
||||
},
|
||||
close = function() {
|
||||
_downloadTask && (_downloadTask.abort(), _downloadTask = null, _createLoading(-2));
|
||||
_maskView && _maskView.hide();
|
||||
_contentView && _contentView.hide();
|
||||
};
|
||||
export default {
|
||||
init: init,
|
||||
show: show,
|
||||
close: close
|
||||
}
|
||||
210
im-uniapp/common/browser.js
Normal file
210
im-uniapp/common/browser.js
Normal file
@@ -0,0 +1,210 @@
|
||||
export default {
|
||||
init: function(options) {
|
||||
this.initWebview(options)
|
||||
this.handleEvent()
|
||||
return this
|
||||
},
|
||||
initWebview: function(options) {
|
||||
var hh=plus.screen.height-44
|
||||
var _self = this
|
||||
_self.webview = plus.webview.create('', 'browser', {
|
||||
scalable:true,
|
||||
height:hh+'px',
|
||||
bottom:'44px',
|
||||
background:'#ff5500',
|
||||
titleNView: {
|
||||
backgroundColor: '#FFFFFF',
|
||||
progress: { //进度条
|
||||
color: '#4678e7',
|
||||
height: '3px'
|
||||
},
|
||||
splitLine: { //底部分割线
|
||||
color: '#cccccc',
|
||||
height: '1px'
|
||||
},
|
||||
buttons: [{ //关闭按钮
|
||||
'float': 'left',
|
||||
fontSrc: '/static/uni.ttf',
|
||||
text: '\ue460',
|
||||
onclick: _self.close.bind(_self)
|
||||
}, { //更多按钮
|
||||
'float': 'right',
|
||||
fontSrc: '/static/uni.ttf',
|
||||
text: '\ue507',
|
||||
onclick: _self.more.bind(_self)
|
||||
}]
|
||||
},
|
||||
additionalHttpHeaders: options.headers || {}
|
||||
})
|
||||
// 配置下拉刷新
|
||||
_self.webview.setPullToRefresh({
|
||||
support: true
|
||||
}, function() {
|
||||
_self.reload()
|
||||
var titleUpdate = function() {
|
||||
setTimeout(function() {
|
||||
_self.webview.endPullToRefresh()
|
||||
_self.webview.removeEventListener('titleUpdate', titleUpdate)
|
||||
}, 300)
|
||||
};
|
||||
_self.webview.addEventListener('titleUpdate', titleUpdate)
|
||||
})
|
||||
|
||||
//绘制返回前进按钮
|
||||
this.navBottom = new plus.nativeObj.View("navBottom", {
|
||||
bottom: '0px',
|
||||
left: '0px',
|
||||
height: '44px',
|
||||
width: '100%',
|
||||
backgroundColor: 'rgb(255,255,255)'
|
||||
})
|
||||
var screenWidth = plus.screen.resolutionWidth
|
||||
var left = screenWidth / 4
|
||||
this.navBottom.draw([{
|
||||
tag: 'font',
|
||||
id: 'back',
|
||||
text: '\ue471',
|
||||
textStyles: {
|
||||
fontSrc: '/static/uni.ttf',
|
||||
size: '24px',
|
||||
color: '#000000'
|
||||
},
|
||||
position: {
|
||||
right: left+48,
|
||||
height: '100%',
|
||||
}
|
||||
},
|
||||
{
|
||||
tag: 'font',
|
||||
id: 'forward',
|
||||
text: '\ue470',
|
||||
textStyles: {
|
||||
fontSrc: '/static/uni.ttf',
|
||||
size: '24px',
|
||||
color: '#000000'
|
||||
},
|
||||
position: {
|
||||
left: left,
|
||||
height: '100%',
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
//点击前进或后退
|
||||
this.navBottom.addEventListener("click", (e) => {
|
||||
if (e.clientX > left && e.clientX < (left + 24)) {
|
||||
_self.back()
|
||||
}
|
||||
if (e.clientX > (screenWidth - left - 12) && e.clientX < (screenWidth - left + 12)) {
|
||||
_self.forward()
|
||||
}
|
||||
})
|
||||
|
||||
//监听页面变化
|
||||
_self.webview.addEventListener('loaded', function() {
|
||||
_self.webview.canBack(function(event) {
|
||||
var canBack = false
|
||||
if (event.canBack) {
|
||||
canBack = true
|
||||
_self.navBottom.show()
|
||||
} else {
|
||||
canBack = false
|
||||
}
|
||||
_self.webview.canForward(function(event) {
|
||||
if (event.canForward) {
|
||||
_self.navBottom.drawText('\ue470', {
|
||||
left: left,
|
||||
height: '100%'
|
||||
}, {
|
||||
color: '#000000',
|
||||
fontSrc: '/static/uni.ttf',
|
||||
size: '24px'
|
||||
}, 'forward')
|
||||
} else {
|
||||
_self.navBottom.drawText('\ue470', {
|
||||
left: left,
|
||||
height: '100%'
|
||||
}, {
|
||||
color: '#EEEEEE',
|
||||
fontSrc: '/static/uni.ttf',
|
||||
size: '24px'
|
||||
}, 'forward')
|
||||
}
|
||||
if (!canBack && !event.canForward) {
|
||||
// _self.navBottom.hide()
|
||||
}
|
||||
})
|
||||
})
|
||||
_self.navBottom.show()
|
||||
}, false)
|
||||
},
|
||||
handleEvent: function(url) {
|
||||
var _self = this
|
||||
plus.key.addEventListener('backbutton', function() {
|
||||
_self.close()
|
||||
return
|
||||
var topWebview = plus.webview.getTopWebview()
|
||||
// 不等于浏览器窗口
|
||||
if (topWebview.id !== 'browser') {
|
||||
// 这里除了浏览器窗口就是首页了,直接退出了;
|
||||
plus.runtime.quit()
|
||||
} else {
|
||||
_self.back()
|
||||
}
|
||||
})
|
||||
},
|
||||
show: function(url) {
|
||||
url = url || 'https://www.baidu.com'
|
||||
this.webview.loadURL(url)
|
||||
this.webview.show('slide-in-right')
|
||||
},
|
||||
more: function() {
|
||||
var _self = this
|
||||
uni.showActionSheet({
|
||||
itemList: ['刷新', '浏览器打开'],
|
||||
success: function(res) {
|
||||
if (res.tapIndex == 0) {
|
||||
_self.reload()
|
||||
} else if (res.tapIndex == 1) {
|
||||
plus.runtime.openURL(_self.webview.getURL())
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
reload: function() {
|
||||
// 刷新
|
||||
this.webview.reload(true)
|
||||
},
|
||||
back: function() {
|
||||
//后退
|
||||
var _self = this
|
||||
_self.webview.canBack(function(event) {
|
||||
if (event.canBack) {
|
||||
_self.webview.back()
|
||||
} else {
|
||||
_self.close()
|
||||
}
|
||||
})
|
||||
},
|
||||
forward: function() {
|
||||
//前进
|
||||
var _self = this
|
||||
_self.webview.canForward(function(event) {
|
||||
if (event.canForward) {
|
||||
_self.webview.forward();
|
||||
} else {
|
||||
plus.nativeUI.toast('没有可前进的地址')
|
||||
}
|
||||
})
|
||||
},
|
||||
close: function() {
|
||||
//关闭
|
||||
// this.navBottom.hide()
|
||||
this.navBottom.close()
|
||||
this.navBottom=null;
|
||||
this.webview.close('browser', 'slide-out-right')
|
||||
this.webview.clear()
|
||||
plus.key.removeEventListener("backbutton", function() {
|
||||
});
|
||||
}
|
||||
}
|
||||
30165
im-uniapp/common/city.js
Normal file
30165
im-uniapp/common/city.js
Normal file
File diff suppressed because it is too large
Load Diff
3
im-uniapp/common/consoleImgs.js
Normal file
3
im-uniapp/common/consoleImgs.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
fz:' ......................阿弥陀佛......................\n' + ' _oo0oo_ \n' + ' o8888888o \n' + ' 88" . "88 \n' + ' (| -_- |) \n' + ' 0\\ = /0 \n' + ' ___/‘---’\\___ \n' + " .' \\| |/ '. \n" + ' / \\\\||| : |||// \\ \n' + ' / _||||| -卍-|||||_ \\ \n' + ' | | \\\\\\ - /// | | \n' + " | \\_| ''\\---/'' |_/ | \n" + " \\ .-\\__ '-' ___/-. / \n" + " ___'. .' /--.--\\ '. .'___ \n" + ' ."" ‘< ‘.___\\_<|>_/___.’>’ "". \n' + ' | | : ‘- \\‘.;‘\\ _ /’;.’/ - ’ : | | \n' + ' \\ \\ ‘_. \\_ __\\ /__ _/ .-’ / / \n' + ' =====‘-.____‘.___ \\_____/___.-’___.-’===== \n' + ' ‘=---=’ \n' + ' \n' + '....................佛祖保佑 ,永无BUG...................'
|
||||
}
|
||||
2
im-uniapp/common/imSdk/lim-sdk.js
Normal file
2
im-uniapp/common/imSdk/lim-sdk.js
Normal file
File diff suppressed because one or more lines are too long
1
im-uniapp/common/imSdk/lim-sdk.js.map
Normal file
1
im-uniapp/common/imSdk/lim-sdk.js.map
Normal file
File diff suppressed because one or more lines are too long
17
im-uniapp/common/imSdk/sdk-bridge.js
Normal file
17
im-uniapp/common/imSdk/sdk-bridge.js
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
function getIM(){
|
||||
// UNIAPP 环境
|
||||
if(typeof uni !== 'undefined'){
|
||||
return {im:uni['im'], im_webtoolkit:uni['im_webtoolkit']};
|
||||
}
|
||||
throw Error(" Couldn't not fetch lim.");
|
||||
}
|
||||
|
||||
|
||||
const lim = {
|
||||
im: getIM().im,
|
||||
};
|
||||
|
||||
export default {
|
||||
lim
|
||||
}
|
||||
259
im-uniapp/common/md5.js
Normal file
259
im-uniapp/common/md5.js
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
|
||||
* Digest Algorithm, as defined in RFC 1321.
|
||||
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for more info.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configurable variables. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
*/
|
||||
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
|
||||
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
|
||||
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
|
||||
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
|
||||
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
|
||||
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function md5_vm_test()
|
||||
{
|
||||
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the MD5 of an array of little-endian words, and a bit length
|
||||
*/
|
||||
function core_md5(x, len)
|
||||
{
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << ((len) % 32);
|
||||
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
||||
|
||||
var a = 1732584193;
|
||||
var b = -271733879;
|
||||
var c = -1732584194;
|
||||
var d = 271733878;
|
||||
|
||||
for(var i = 0; i < x.length; i += 16)
|
||||
{
|
||||
var olda = a;
|
||||
var oldb = b;
|
||||
var oldc = c;
|
||||
var oldd = d;
|
||||
|
||||
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
|
||||
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
|
||||
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
|
||||
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
|
||||
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
|
||||
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
|
||||
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
|
||||
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
|
||||
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
|
||||
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
|
||||
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
|
||||
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
|
||||
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
|
||||
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
|
||||
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
|
||||
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
|
||||
|
||||
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
|
||||
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
|
||||
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
|
||||
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
|
||||
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
|
||||
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
|
||||
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
|
||||
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
|
||||
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
|
||||
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
|
||||
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
|
||||
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
|
||||
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
|
||||
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
|
||||
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
|
||||
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
|
||||
|
||||
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
|
||||
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
|
||||
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
|
||||
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
|
||||
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
|
||||
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
|
||||
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
|
||||
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
|
||||
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
|
||||
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
|
||||
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
|
||||
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
|
||||
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
|
||||
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
|
||||
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
|
||||
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
|
||||
|
||||
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
|
||||
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
|
||||
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
|
||||
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
|
||||
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
|
||||
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
|
||||
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
|
||||
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
|
||||
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
|
||||
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
|
||||
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
|
||||
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
|
||||
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
|
||||
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
|
||||
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
|
||||
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
}
|
||||
return Array(a, b, c, d);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions implement the four basic operations the algorithm uses.
|
||||
*/
|
||||
function md5_cmn(q, a, b, x, s, t)
|
||||
{
|
||||
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
|
||||
}
|
||||
function md5_ff(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
|
||||
}
|
||||
function md5_gg(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
|
||||
}
|
||||
function md5_hh(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
|
||||
}
|
||||
function md5_ii(a, b, c, d, x, s, t)
|
||||
{
|
||||
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-MD5, of a key and some data
|
||||
*/
|
||||
function core_hmac_md5(key, data)
|
||||
{
|
||||
var bkey = str2binl(key);
|
||||
if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
|
||||
|
||||
var ipad = Array(16), opad = Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
{
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
|
||||
return core_md5(opad.concat(hash), 512 + 128);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y)
|
||||
{
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function bit_rol(num, cnt)
|
||||
{
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string to an array of little-endian words
|
||||
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
|
||||
*/
|
||||
function str2binl(str)
|
||||
{
|
||||
var bin = Array();
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < str.length * chrsz; i += chrsz)
|
||||
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a string
|
||||
*/
|
||||
function binl2str(bin)
|
||||
{
|
||||
var str = "";
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < bin.length * 32; i += chrsz)
|
||||
str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a hex string.
|
||||
*/
|
||||
function binl2hex(binarray)
|
||||
{
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i++)
|
||||
{
|
||||
str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
|
||||
hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a base-64 string
|
||||
*/
|
||||
function binl2b64(binarray)
|
||||
{
|
||||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i += 3)
|
||||
{
|
||||
var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)
|
||||
| (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
|
||||
| ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
|
||||
for(var j = 0; j < 4; j++)
|
||||
{
|
||||
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
|
||||
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
export default {
|
||||
hex_md5
|
||||
}
|
||||
245
im-uniapp/common/permission.js
Normal file
245
im-uniapp/common/permission.js
Normal file
@@ -0,0 +1,245 @@
|
||||
/// null = 未请求,1 = 已允许,0 = 拒绝|受限, 2 = 系统未开启
|
||||
|
||||
var isIOS
|
||||
|
||||
function album() {
|
||||
var result = 0;
|
||||
var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
|
||||
var authStatus = PHPhotoLibrary.authorizationStatus();
|
||||
if (authStatus === 0) {
|
||||
result = null;
|
||||
} else if (authStatus == 3) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(PHPhotoLibrary);
|
||||
return result;
|
||||
}
|
||||
|
||||
function camera() {
|
||||
var result = 0;
|
||||
var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
|
||||
var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
|
||||
if (authStatus === 0) {
|
||||
result = null;
|
||||
} else if (authStatus == 3) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(AVCaptureDevice);
|
||||
return result;
|
||||
}
|
||||
|
||||
function location() {
|
||||
var result = 0;
|
||||
var cllocationManger = plus.ios.import("CLLocationManager");
|
||||
var enable = cllocationManger.locationServicesEnabled();
|
||||
var status = cllocationManger.authorizationStatus();
|
||||
if (!enable) {
|
||||
result = 2;
|
||||
} else if (status === 0) {
|
||||
result = null;
|
||||
} else if (status === 3 || status === 4) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(cllocationManger);
|
||||
return result;
|
||||
}
|
||||
|
||||
function push() {
|
||||
var result = 0;
|
||||
var UIApplication = plus.ios.import("UIApplication");
|
||||
var app = UIApplication.sharedApplication();
|
||||
var enabledTypes = 0;
|
||||
if (app.currentUserNotificationSettings) {
|
||||
var settings = app.currentUserNotificationSettings();
|
||||
enabledTypes = settings.plusGetAttribute("types");
|
||||
if (enabledTypes == 0) {
|
||||
result = 0;
|
||||
console.log("推送权限没有开启");
|
||||
} else {
|
||||
result = 1;
|
||||
console.log("已经开启推送功能!")
|
||||
}
|
||||
plus.ios.deleteObject(settings);
|
||||
} else {
|
||||
enabledTypes = app.enabledRemoteNotificationTypes();
|
||||
if (enabledTypes == 0) {
|
||||
result = 3;
|
||||
console.log("推送权限没有开启!");
|
||||
} else {
|
||||
result = 4;
|
||||
console.log("已经开启推送功能!")
|
||||
}
|
||||
}
|
||||
plus.ios.deleteObject(app);
|
||||
plus.ios.deleteObject(UIApplication);
|
||||
return result;
|
||||
}
|
||||
|
||||
function contact() {
|
||||
var result = 0;
|
||||
var CNContactStore = plus.ios.import("CNContactStore");
|
||||
var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
|
||||
if (cnAuthStatus === 0) {
|
||||
result = null;
|
||||
} else if (cnAuthStatus == 3) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(CNContactStore);
|
||||
return result;
|
||||
}
|
||||
|
||||
function record() {
|
||||
var result = null;
|
||||
var avaudiosession = plus.ios.import("AVAudioSession");
|
||||
var avaudio = avaudiosession.sharedInstance();
|
||||
var status = avaudio.recordPermission();
|
||||
console.log("permissionStatus:" + status);
|
||||
if (status === 1970168948) {
|
||||
result = null;
|
||||
} else if (status === 1735552628) {
|
||||
result = 1;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
plus.ios.deleteObject(avaudiosession);
|
||||
return result;
|
||||
}
|
||||
|
||||
function calendar() {
|
||||
var result = null;
|
||||
var EKEventStore = plus.ios.import("EKEventStore");
|
||||
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
|
||||
if (ekAuthStatus == 3) {
|
||||
result = 1;
|
||||
console.log("日历权限已经开启");
|
||||
} else {
|
||||
console.log("日历权限没有开启");
|
||||
}
|
||||
plus.ios.deleteObject(EKEventStore);
|
||||
return result;
|
||||
}
|
||||
|
||||
function memo() {
|
||||
var result = null;
|
||||
var EKEventStore = plus.ios.import("EKEventStore");
|
||||
var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
|
||||
if (ekAuthStatus == 3) {
|
||||
result = 1;
|
||||
console.log("备忘录权限已经开启");
|
||||
} else {
|
||||
console.log("备忘录权限没有开启");
|
||||
}
|
||||
plus.ios.deleteObject(EKEventStore);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function requestIOS(permissionID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
switch (permissionID) {
|
||||
case "push":
|
||||
resolve(push());
|
||||
break;
|
||||
case "location":
|
||||
resolve(location());
|
||||
break;
|
||||
case "record":
|
||||
resolve(record());
|
||||
break;
|
||||
case "camera":
|
||||
resolve(camera());
|
||||
break;
|
||||
case "album":
|
||||
resolve(album());
|
||||
break;
|
||||
case "contact":
|
||||
resolve(contact());
|
||||
break;
|
||||
case "calendar":
|
||||
resolve(calendar());
|
||||
break;
|
||||
case "memo":
|
||||
resolve(memo());
|
||||
break;
|
||||
default:
|
||||
resolve(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function requestAndroid(permissionID) {
|
||||
return new Promise((resolve, reject) => {
|
||||
plus.android.requestPermissions(
|
||||
[permissionID],
|
||||
function(resultObj) {
|
||||
var result = 0;
|
||||
for (var i = 0; i < resultObj.granted.length; i++) {
|
||||
var grantedPermission = resultObj.granted[i];
|
||||
console.log('已获取的权限:' + grantedPermission);
|
||||
result = 1
|
||||
}
|
||||
for (var i = 0; i < resultObj.deniedPresent.length; i++) {
|
||||
var deniedPresentPermission = resultObj.deniedPresent[i];
|
||||
console.log('拒绝本次申请的权限:' + deniedPresentPermission);
|
||||
result = 0
|
||||
}
|
||||
for (var i = 0; i < resultObj.deniedAlways.length; i++) {
|
||||
var deniedAlwaysPermission = resultObj.deniedAlways[i];
|
||||
console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
|
||||
result = -1
|
||||
}
|
||||
resolve(result);
|
||||
},
|
||||
function(error) {
|
||||
console.log('result error: ' + error.message)
|
||||
resolve({
|
||||
code: error.code,
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function gotoAppPermissionSetting() {
|
||||
if (permission.isIOS) {
|
||||
var UIApplication = plus.ios.import("UIApplication");
|
||||
var application2 = UIApplication.sharedApplication();
|
||||
var NSURL2 = plus.ios.import("NSURL");
|
||||
var setting2 = NSURL2.URLWithString("app-settings:");
|
||||
application2.openURL(setting2);
|
||||
plus.ios.deleteObject(setting2);
|
||||
plus.ios.deleteObject(NSURL2);
|
||||
plus.ios.deleteObject(application2);
|
||||
} else {
|
||||
var Intent = plus.android.importClass("android.content.Intent");
|
||||
var Settings = plus.android.importClass("android.provider.Settings");
|
||||
var Uri = plus.android.importClass("android.net.Uri");
|
||||
var mainActivity = plus.android.runtimeMainActivity();
|
||||
var intent = new Intent();
|
||||
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
mainActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
const permission = {
|
||||
get isIOS(){
|
||||
return typeof isIOS === 'boolean' ? isIOS : (isIOS = uni.getSystemInfoSync().platform === 'ios')
|
||||
},
|
||||
requestIOS: requestIOS,
|
||||
requestAndroid: requestAndroid,
|
||||
gotoAppSetting: gotoAppPermissionSetting
|
||||
}
|
||||
|
||||
export default permission
|
||||
142
im-uniapp/common/pinyin.js
Normal file
142
im-uniapp/common/pinyin.js
Normal file
File diff suppressed because one or more lines are too long
999
im-uniapp/common/publicFc.js
Normal file
999
im-uniapp/common/publicFc.js
Normal file
@@ -0,0 +1,999 @@
|
||||
import http from '@/common/request'
|
||||
import browser from '@/common/browser'
|
||||
import store from '../store'
|
||||
import pinyin from '@/common/pinyin.js';
|
||||
export default {
|
||||
// 获取字典
|
||||
getdict(dict) {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.request({
|
||||
url: '/system/dict/data/type/' + dict,
|
||||
success: (res) => {
|
||||
if (res.data.code == 200) {
|
||||
var data = res.data.data
|
||||
var arr = []
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
arr.push({
|
||||
label: data[i].dictLabel,
|
||||
value: data[i].dictValue
|
||||
})
|
||||
}
|
||||
// return arr
|
||||
resolve(arr);
|
||||
} else {
|
||||
reject(res);
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
reject(new Error(res.errMsg));
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
//文本转json
|
||||
returnParse(txt) {
|
||||
return JSON.parse(txt);
|
||||
},
|
||||
//字典翻译
|
||||
findLabel(arr, text) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if (arr[i].value == text) {
|
||||
return arr[i].label
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
//判断按钮权限
|
||||
permissions(permissions) {
|
||||
var data = store.state.permissions
|
||||
var have = data.indexOf(permissions)
|
||||
if (have !== -1) {
|
||||
return true
|
||||
}
|
||||
},
|
||||
//判断单个角色权限
|
||||
hasRole(Role) {
|
||||
var data = store.state.userRole
|
||||
var have = data.indexOf(Role)
|
||||
if (have !== -1) {
|
||||
return true
|
||||
}
|
||||
},
|
||||
//判断多个角色权限
|
||||
hasRoles(Roles) {
|
||||
var data = store.state.userRole
|
||||
|
||||
function fidrole(Roles) {
|
||||
for (var i = 0; i < Roles.length; i++) {
|
||||
var have = data.indexOf(Roles[i])
|
||||
if (have !== -1) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return fidrole(Roles)
|
||||
},
|
||||
//预览单张图片
|
||||
previewImagesolo(File) {
|
||||
uni.previewImage({
|
||||
urls: [File],
|
||||
});
|
||||
},
|
||||
//预览一组图片(图片组,图片索引)
|
||||
previewImages(FilePaths, current) {
|
||||
uni.previewImage({
|
||||
urls: FilePaths,
|
||||
current: current
|
||||
});
|
||||
},
|
||||
//根据后缀判断文件类型
|
||||
getFileType(fileName) {
|
||||
// 后缀获取
|
||||
let suffix = '';
|
||||
// 获取类型结果
|
||||
let result = '';
|
||||
try {
|
||||
const flieArr = fileName.split('.');
|
||||
suffix = flieArr[flieArr.length - 1];
|
||||
} catch (err) {
|
||||
suffix = '';
|
||||
}
|
||||
// fileName无后缀返回 false
|
||||
if (!suffix) {
|
||||
return false;
|
||||
}
|
||||
suffix = suffix.toLocaleLowerCase();
|
||||
// 图片格式
|
||||
const imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
|
||||
// 进行图片匹配
|
||||
result = imglist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'image';
|
||||
}
|
||||
// 匹配txt
|
||||
const txtlist = ['txt'];
|
||||
result = txtlist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'txt';
|
||||
}
|
||||
// 匹配 excel
|
||||
const excelist = ['xls', 'xlsx'];
|
||||
result = excelist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'excel';
|
||||
}
|
||||
// 匹配 word
|
||||
const wordlist = ['doc', 'docx'];
|
||||
result = wordlist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'word';
|
||||
}
|
||||
// 匹配 pdf
|
||||
const pdflist = ['pdf'];
|
||||
result = pdflist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'pdf';
|
||||
}
|
||||
// 匹配 ppt
|
||||
const pptlist = ['ppt', 'pptx'];
|
||||
result = pptlist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'ppt';
|
||||
}
|
||||
// 匹配 视频
|
||||
const videolist = ['mp4', 'm2v', 'mkv', 'rmvb', 'wmv', 'avi', 'flv', 'mov', 'm4v'];
|
||||
result = videolist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'video';
|
||||
}
|
||||
// 匹配 音频
|
||||
const radiolist = ['mp3', 'wav', 'wmv'];
|
||||
result = radiolist.find(item => item === suffix);
|
||||
if (result) {
|
||||
return 'radio';
|
||||
}
|
||||
// 其他 文件类型
|
||||
return 'other';
|
||||
},
|
||||
//新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx
|
||||
onOpenDoc(e) {
|
||||
uni.downloadFile({
|
||||
url: e,
|
||||
success: function(res) {
|
||||
var filePath = res.tempFilePath;
|
||||
uni.openDocument({
|
||||
filePath: filePath,
|
||||
success: function(res) {
|
||||
console.log('打开文档成功');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
//模拟浏览器打开第三方链接
|
||||
openWebView(url) {
|
||||
// #ifndef APP-PLUS
|
||||
uni.showToast({
|
||||
title: '仅手机端可打开',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
// #endif
|
||||
var options = { // 自定义头部参数
|
||||
}
|
||||
browser.init(options)
|
||||
browser.show(url)
|
||||
},
|
||||
//获取时间format
|
||||
getNewDate(format, add0,datetime) {
|
||||
//获取当前时间
|
||||
function addZero(val) {
|
||||
//补零
|
||||
if (add0) {
|
||||
return val <= 9 ? '0' + val : val;
|
||||
} else {
|
||||
return val
|
||||
}
|
||||
}
|
||||
var date = new Date()
|
||||
if(datetime){
|
||||
date=Date.parse(new Date(datetime))
|
||||
}
|
||||
|
||||
var year = date.getFullYear(),
|
||||
month = addZero(date.getMonth() + 1),
|
||||
strDate = addZero(date.getDate()),
|
||||
hours = addZero(date.getHours()),
|
||||
minutes = addZero(date.getMinutes()),
|
||||
seconds = addZero(date.getSeconds());
|
||||
switch (format) {
|
||||
case 'y':
|
||||
return year;
|
||||
break;
|
||||
case 'm':
|
||||
return month;
|
||||
break;
|
||||
case 'd':
|
||||
return strDate;
|
||||
break;
|
||||
case 'h':
|
||||
return hours;
|
||||
break;
|
||||
case 'mm':
|
||||
return minutes;
|
||||
break;
|
||||
case 'ss':
|
||||
return seconds;
|
||||
break;
|
||||
case 'ymd':
|
||||
return year + '/' + month + '/' + strDate;
|
||||
break;
|
||||
case 'hmmss':
|
||||
return hours + ':' + minutes + ':' + seconds;
|
||||
break;
|
||||
default:
|
||||
return year + '/' + month + '/' + strDate + ' ' + hours + ':' + minutes + ':' + seconds;
|
||||
break;
|
||||
}
|
||||
},
|
||||
//获取本地存储object/初始化
|
||||
getKeyObjectStorage(keyname) {
|
||||
try {
|
||||
var chatData = uni.getStorageSync(keyname);
|
||||
if (chatData) {
|
||||
chatData = JSON.parse(chatData)
|
||||
return chatData
|
||||
} else {
|
||||
chatData = new Object()
|
||||
return chatData
|
||||
uni.setStorageSync(keyname, JSON.stringify(chatData));
|
||||
}
|
||||
} catch (e) {
|
||||
return new Object()
|
||||
}
|
||||
},
|
||||
loadMore({
|
||||
url='xxx/list/',
|
||||
queryParams={
|
||||
refreshing:false,
|
||||
pageNum:1,
|
||||
status: 'more',//more loading前 loading loading中 noMore 没有更多了
|
||||
pageSize:10
|
||||
},
|
||||
status='0'//0无更多数据 1持续加载 2重新加载 3无数据+清空数据
|
||||
}){
|
||||
return new Promise((resolve, reject) => {
|
||||
http.request({
|
||||
url:url+'&pageNum='+(queryParams.refreshing ? 1 : queryParams.pageNum) +'&pageSize=' +queryParams.pageSize,
|
||||
success: res => {
|
||||
if (res.data.code == 200) {
|
||||
let list = [];
|
||||
let data = res.data.rows;
|
||||
if (queryParams.refreshing&&res.data.rows == ''||queryParams.refreshing&&res.data.rows.length==0) {
|
||||
queryParams.status='noMore'
|
||||
resolve({
|
||||
queryParams:queryParams,
|
||||
list:list,
|
||||
status:'3'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (res.data.rows == ''||res.data.rows.length==0) {
|
||||
queryParams.status='noMore'
|
||||
resolve({
|
||||
queryParams:queryParams,
|
||||
list:list,
|
||||
status:'0'
|
||||
})
|
||||
return
|
||||
}
|
||||
for (let i = 0, length = data.length; i < length; i++) {
|
||||
var item = data[i];
|
||||
list.push(item);
|
||||
}
|
||||
if (queryParams.refreshing) {
|
||||
queryParams.refreshing = false;
|
||||
queryParams.pageNum = 2;
|
||||
queryParams.status='more'
|
||||
resolve({
|
||||
queryParams:queryParams,
|
||||
list:list,
|
||||
status:'2'
|
||||
})
|
||||
} else {
|
||||
queryParams.pageNum += 1;
|
||||
queryParams.status='more'
|
||||
resolve({
|
||||
queryParams:queryParams,
|
||||
list:list,
|
||||
status:'1'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
reject(res);
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
reject(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
//接收推送消息
|
||||
getPush(resbody) {
|
||||
console.log(resbody)
|
||||
var pushType = resbody.pushType //推送类型
|
||||
if (pushType == 'MSG') {
|
||||
if(resbody.msgContent.msgType=='TRTC_VOICE_START'||resbody.msgContent.msgType=='TRTC_VIDEO_START'){
|
||||
//音视频开始拦截
|
||||
return
|
||||
}
|
||||
var userId=resbody.fromInfo.userId
|
||||
var windowType='SINGLE'
|
||||
if(resbody.groupInfo.userId){
|
||||
userId=resbody.groupInfo.userId
|
||||
windowType='GROUP'
|
||||
}
|
||||
this.pushInMsg({
|
||||
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
||||
msgContent: resbody.msgContent.content, //msg内容
|
||||
msgType: resbody.msgContent.msgType, //msgType信息类型
|
||||
windowType: windowType, //聊天室类型 SINGLE GROUP
|
||||
time: resbody.createTime, //时间
|
||||
fromInfo:resbody.fromInfo,//来源信息
|
||||
groupInfo:resbody.groupInfo,//群信息
|
||||
userId: userId,//talktoId
|
||||
personId:resbody.fromInfo.userId,
|
||||
msgId:resbody.msgId,//消息Id
|
||||
disturb:resbody.msgContent.disturb,//是否静默消息
|
||||
top:resbody.msgContent.top//是否置顶
|
||||
})
|
||||
return
|
||||
}
|
||||
if (pushType == 'NOTICE') {//红点通知等
|
||||
if(resbody.msgContent.topicReply.count){
|
||||
store.commit('update_topicReply',resbody.msgContent.topicReply)
|
||||
}
|
||||
if(resbody.msgContent.topicRed.portrait){
|
||||
store.commit('update_topicRed',resbody.msgContent.topicRed)
|
||||
}
|
||||
if(resbody.msgContent.friendApply.count){
|
||||
store.commit('update_friendApply',resbody.msgContent.friendApply)
|
||||
}
|
||||
}
|
||||
if (pushType == 'BIG') {//大消息
|
||||
var bigId=resbody.msgContent.content
|
||||
http.request({
|
||||
url: '/chat/getBigMsg/'+bigId,
|
||||
success: (res) => {
|
||||
if (res.data.code == 200) {
|
||||
var resbody=res.data.data
|
||||
var userId=resbody.fromInfo.userId
|
||||
var windowType='SINGLE'
|
||||
if(resbody.groupInfo.userId){
|
||||
userId=resbody.groupInfo.userId
|
||||
windowType='GROUP'
|
||||
}
|
||||
this.pushInMsg({
|
||||
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
||||
msgContent: resbody.msgContent.content, //msg内容
|
||||
msgType: resbody.msgContent.msgType, //msgType信息类型
|
||||
windowType: windowType, //聊天室类型 SINGLE GROUP
|
||||
time: resbody.createTime, //时间
|
||||
fromInfo:resbody.fromInfo,//来源信息
|
||||
groupInfo:resbody.groupInfo,//群信息
|
||||
userId: userId,//talktoId
|
||||
personId:resbody.fromInfo.userId,
|
||||
msgId:resbody.msgId,//消息Id
|
||||
disturb:resbody.msgContent.disturb,//是否静默消息
|
||||
top:resbody.msgContent.top//是否置顶
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
return
|
||||
}
|
||||
},
|
||||
// 接收到的聊天推送
|
||||
pushInMsg({
|
||||
msgId,//消息Id
|
||||
msgContent,//内容
|
||||
msgType,//消息类型
|
||||
windowType,//聊天室类型 SINGLE GROUP
|
||||
userId,//聊天对象ID
|
||||
personId,//发送人ID
|
||||
time,//时间
|
||||
type,//显示类型 1左侧 2右侧 3中间
|
||||
fromInfo,//来源
|
||||
groupInfo,//群信息
|
||||
disturb,//是否静默消息
|
||||
top//是否置顶
|
||||
}) {
|
||||
var msgTypeLabel = ''; //消息类型
|
||||
if (msgType == 'TEXT') {
|
||||
msgTypeLabel = msgContent;
|
||||
}
|
||||
if (msgType == 'ALERT') {
|
||||
msgTypeLabel = msgContent;
|
||||
}
|
||||
if (msgType == 'IMAGE') {
|
||||
msgTypeLabel = '[图片]';
|
||||
}
|
||||
if (msgType == 'VOICE') {
|
||||
msgTypeLabel = '[语音]';
|
||||
}
|
||||
if (msgType == 'VIDEO') {
|
||||
msgTypeLabel = '[视频]';
|
||||
}
|
||||
if (msgType == 'LOCATION') {
|
||||
msgTypeLabel = '[位置]';
|
||||
}
|
||||
if (msgType == 'COLLECTION') {
|
||||
msgTypeLabel = '[收藏]';
|
||||
}
|
||||
if (msgType == 'CARD') {
|
||||
msgTypeLabel = '[名片]';
|
||||
}
|
||||
if (msgType == 'FILE') {
|
||||
msgTypeLabel = '[文件]';
|
||||
}
|
||||
if (msgType == 'TRTC_VOICE_END') {
|
||||
msgTypeLabel = '[语音通话]'
|
||||
}
|
||||
if (msgType == 'TRTC_VIDEO_END') {
|
||||
msgTypeLabel = '[视频通话]'
|
||||
}
|
||||
store.dispatch('createChatObj',{
|
||||
userId:userId,
|
||||
windowType:windowType,
|
||||
}).then(res=>{
|
||||
var localData=res.data
|
||||
store.dispatch('getchatDatalist');
|
||||
store.dispatch('getChatList');
|
||||
var chatWindowData = store.state.chatDatalist[userId].list
|
||||
var chatListInfo = store.state.chatlist[userId]
|
||||
// 找到数组中对象属性值一样的对象并返回
|
||||
function arrfindobject({arr,object,key}){
|
||||
var result=arr.find(item =>{
|
||||
return item[key] == object[key]
|
||||
});
|
||||
return result
|
||||
}
|
||||
var same=arrfindobject({arr:chatWindowData,object:{
|
||||
msgId:msgId
|
||||
},key:'msgId'})
|
||||
if(same){
|
||||
return
|
||||
}
|
||||
//离线消息体
|
||||
var msgOffline = {
|
||||
userId: userId,
|
||||
personId: personId,
|
||||
nickName: fromInfo.nickName,
|
||||
portrait: fromInfo.portrait,
|
||||
msgType: msgType,
|
||||
content: msgContent,
|
||||
time: time,
|
||||
type: type,
|
||||
msgId:msgId,
|
||||
windowType: windowType
|
||||
}
|
||||
|
||||
// 聊天记录体
|
||||
var msgList = {}
|
||||
if(windowType=='SINGLE'){
|
||||
msgList = {
|
||||
userId: userId,
|
||||
personId: personId,
|
||||
nickName: fromInfo.nickName,
|
||||
portrait: fromInfo.portrait,
|
||||
content: msgTypeLabel,
|
||||
time: time,
|
||||
num: disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
||||
windowType: windowType,
|
||||
disturb:disturb,//是否静默消息
|
||||
top:top,//是否置顶
|
||||
userType:fromInfo.userType
|
||||
}
|
||||
}
|
||||
if(windowType=='GROUP'){
|
||||
msgList = {
|
||||
userId: userId,
|
||||
personId: personId,
|
||||
nickName: groupInfo.nickName,
|
||||
portrait: groupInfo.portrait,
|
||||
content: msgTypeLabel,
|
||||
time: time,
|
||||
num: disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num + 1 : 1),
|
||||
windowType: windowType,
|
||||
disturb:disturb,//是否静默消息
|
||||
top:top,//是否置顶
|
||||
userType:'GROUP'
|
||||
}
|
||||
}
|
||||
chatWindowData.push(msgOffline)
|
||||
store.dispatch('updateChatById', {
|
||||
userId: userId,
|
||||
data: chatWindowData
|
||||
})
|
||||
store.dispatch('updateChatListInfoById', {
|
||||
userId: userId,
|
||||
data: msgList
|
||||
})
|
||||
store.dispatch('tabBarpull')
|
||||
store.dispatch('updateChatDataState',userId);
|
||||
});
|
||||
},
|
||||
//发送消息
|
||||
pushOutMsg({
|
||||
msgContent, //内容
|
||||
msgType, //消息类型
|
||||
windowType, //聊天室类型SINGLE GROUP
|
||||
userId
|
||||
}) {
|
||||
var msgTypeLabel = ''; //消息类型
|
||||
if (msgType == 'TEXT') {
|
||||
msgTypeLabel = msgContent;
|
||||
}
|
||||
if (msgType == 'ALERT') {
|
||||
msgTypeLabel = msgContent;
|
||||
}
|
||||
if (msgType == 'IMAGE') {
|
||||
msgTypeLabel = '[图片]';
|
||||
}
|
||||
if (msgType == 'VOICE') {
|
||||
msgTypeLabel = '[语音]';
|
||||
}
|
||||
if (msgType == 'VIDEO') {
|
||||
msgTypeLabel = '[视频]';
|
||||
}
|
||||
if (msgType == 'LOCATION') {
|
||||
msgTypeLabel = '[位置]';
|
||||
}
|
||||
if (msgType == 'COLLECTION') {
|
||||
msgTypeLabel = '[收藏]';
|
||||
}
|
||||
if (msgType == 'CARD') {
|
||||
msgTypeLabel = '[名片]';
|
||||
}
|
||||
if (msgType == 'FILE') {
|
||||
msgTypeLabel = '[文件]';
|
||||
}
|
||||
if (msgType == 'TRTC_VOICE_END') {
|
||||
msgTypeLabel = '[语音通话]'
|
||||
}
|
||||
if (msgType == 'TRTC_VIDEO_END') {
|
||||
msgTypeLabel = '[视频通话]'
|
||||
}
|
||||
var userInfo = store.state.userInfo;
|
||||
store.dispatch('createChatObj',{
|
||||
userId:userId,
|
||||
windowType:windowType,
|
||||
}).then(res=>{
|
||||
var localData=res.data
|
||||
store.dispatch('getchatDatalist');
|
||||
store.dispatch('getChatList');
|
||||
var chatWindowData = store.state.chatDatalist[userId].list
|
||||
var chatListInfo = store.state.chatlist[userId]
|
||||
var time = this.getNewDate('format',true)
|
||||
//在线消息体
|
||||
var msgOnlie={}
|
||||
//聊天记录
|
||||
var msgList={}
|
||||
var url=''
|
||||
if(windowType=='SINGLE'){
|
||||
msgOnlie = {
|
||||
userId: userId,
|
||||
msgType: msgType,
|
||||
content: msgContent
|
||||
}
|
||||
url='/chat/sendMsg'
|
||||
msgList = {
|
||||
userId: userId,
|
||||
personId: userInfo.userId,
|
||||
nickName: localData.fromInfo.nickName,
|
||||
portrait: localData.fromInfo.portrait,
|
||||
content: msgTypeLabel,
|
||||
time: time,
|
||||
num: chatListInfo.disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num : 0),
|
||||
windowType: windowType,
|
||||
disturb:chatListInfo.disturb ? chatListInfo.disturb : 'N',//是否静默消息
|
||||
top:chatListInfo.top ? chatListInfo.top : 'N',//是否置顶
|
||||
userType:localData.fromInfo.userType
|
||||
}
|
||||
}
|
||||
if(windowType=='GROUP'){
|
||||
msgOnlie = {
|
||||
groupId: userId,
|
||||
msgType: msgType,
|
||||
content: msgContent
|
||||
}
|
||||
url='/group/sendMsg'
|
||||
msgList = {
|
||||
userId: userId,
|
||||
personId: userInfo.userId,
|
||||
nickName: localData.groupInfo.nickName,
|
||||
portrait: localData.groupInfo.portrait,
|
||||
content: msgTypeLabel,
|
||||
time: time,
|
||||
num: chatListInfo.disturb=='Y' ? 'dot' : (chatListInfo.num ? chatListInfo.num : 0),
|
||||
windowType: windowType,
|
||||
disturb:chatListInfo.disturb ? chatListInfo.disturb : 'N',//是否静默消息
|
||||
top:chatListInfo.top ? chatListInfo.top : 'N',//是否置顶
|
||||
userType:'GROUP'
|
||||
}
|
||||
}
|
||||
//离线消息体 自己的消息
|
||||
var msgOffline = {
|
||||
userId: userInfo.userId,
|
||||
personId: userInfo.userId,
|
||||
nickName: userInfo.nickName,
|
||||
portrait: userInfo.portrait,
|
||||
msgType: msgType,
|
||||
content: msgContent,
|
||||
time: time,
|
||||
type: 2,
|
||||
msgId:'local',
|
||||
windowType: windowType
|
||||
};
|
||||
//离线/发送失败错误消息体
|
||||
var msgNotSend = {
|
||||
userId: userInfo.userId,
|
||||
portrait: userInfo.portrait,
|
||||
msgType: msgType,
|
||||
content: msgContent,
|
||||
type: 3
|
||||
};
|
||||
var msgSendType = 'wating';
|
||||
http.request({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
data: JSON.stringify(msgOnlie),
|
||||
success: res => {
|
||||
if (res.data.code == 200) {
|
||||
if (res.data.data.status !== '0') {
|
||||
msgSendType = 'error';
|
||||
msgOffline.sendtype = msgSendType;
|
||||
msgOffline.msgId=res.data.data.msgId
|
||||
msgNotSend.content = res.data.data.statusLabel;
|
||||
msgList.content = res.data.data.statusLabel;
|
||||
} else {
|
||||
msgSendType = 'success';
|
||||
}
|
||||
} else {
|
||||
msgSendType = 'error';
|
||||
msgOffline.sendtype = msgSendType;
|
||||
msgNotSend.content = res.data.msg;
|
||||
}
|
||||
chatWindowData.push(msgOffline);
|
||||
if (msgSendType == 'error') {
|
||||
chatWindowData.push(msgNotSend);
|
||||
}
|
||||
store.dispatch('updateChatById', {
|
||||
userId: userId,
|
||||
data: chatWindowData
|
||||
});
|
||||
store.dispatch('updateChatListInfoById', {
|
||||
userId: userId,
|
||||
data: msgList
|
||||
});
|
||||
store.dispatch('tabBarpull');
|
||||
store.dispatch('updateChatDataState',userId);
|
||||
},
|
||||
fail: res => {
|
||||
msgSendType = 'error';
|
||||
msgOffline.sendtype = msgSendType;
|
||||
msgNotSend.content = '发送失败,请检查网络';
|
||||
chatWindowData.push(msgOffline);
|
||||
chatWindowData.push(msgNotSend);
|
||||
store.dispatch('updateChatById', {
|
||||
userId: userId,
|
||||
data: chatWindowData
|
||||
});
|
||||
store.dispatch('updateChatListInfoById', {
|
||||
userId: userId,
|
||||
data: msgList
|
||||
});
|
||||
store.dispatch('tabBarpull');
|
||||
store.dispatch('updateChatDataState',userId);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
//H5保存base64图片
|
||||
h5SaveBase64Img({
|
||||
base64
|
||||
}) {
|
||||
var arr = base64.split(',');
|
||||
var bytes = atob(arr[1]);
|
||||
let ab = new ArrayBuffer(bytes.length);
|
||||
let ia = new Uint8Array(ab);
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
ia[i] = bytes.charCodeAt(i);
|
||||
}
|
||||
var blob = new Blob([ab], {
|
||||
type: 'application/octet-stream'
|
||||
});
|
||||
var url = URL.createObjectURL(blob);
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = new Date().getTime() + ".png";
|
||||
var e = document.createEvent('MouseEvents');
|
||||
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
a.dispatchEvent(e);
|
||||
URL.revokeObjectURL(url);
|
||||
},
|
||||
//APP保存base64图片
|
||||
plusSaveBase64Img({
|
||||
base64
|
||||
}) {
|
||||
const bitmap = new plus.nativeObj.Bitmap("test");
|
||||
bitmap.loadBase64Data(base64, function() {
|
||||
const url = new Date().getTime() + ".png"; // url为时间戳命名方式
|
||||
bitmap.save(url, {
|
||||
overwrite: true, // 是否覆盖
|
||||
}, (i) => {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: url,
|
||||
success: function() {
|
||||
uni.showToast({
|
||||
title: '图片保存成功',
|
||||
icon: 'none'
|
||||
})
|
||||
bitmap.clear()
|
||||
}
|
||||
});
|
||||
}, (e) => {
|
||||
uni.showToast({
|
||||
title: '图片保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
bitmap.clear()
|
||||
});
|
||||
}, (e) => {
|
||||
uni.showToast({
|
||||
title: '图片保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
bitmap.clear()
|
||||
});
|
||||
},
|
||||
// 寻找数组中的对象中的key对应值的对象
|
||||
arrFindkey({
|
||||
arr, //数组[{id:'1'}]
|
||||
key, //key键值'id'
|
||||
val //值 '1'
|
||||
}) {
|
||||
var item = arr.find(function(obj, i, arr) {
|
||||
return obj[key] === val
|
||||
})
|
||||
var index = arr.findIndex(function(obj, i, arr) {
|
||||
return obj[key] === val
|
||||
})
|
||||
return {
|
||||
item: item,
|
||||
index: index
|
||||
}
|
||||
},
|
||||
//APP下载文件
|
||||
plusDownload({
|
||||
onlinePath,
|
||||
savePath = 'file://storage/emulated/0/Documents/weiliao/'
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// #ifdef H5
|
||||
reject('下载失败,H5不支持plus')
|
||||
return
|
||||
// #endif
|
||||
var fname = onlinePath.split("/").pop()
|
||||
var localPath = savePath + fname
|
||||
plus.io.resolveLocalFileSystemURL( //检测本地是否存在
|
||||
localPath,
|
||||
(entry) => {
|
||||
console.log('文件已存在' + entry.name)
|
||||
resolve(entry.fullPath)
|
||||
},
|
||||
(e) => {
|
||||
console.log('文件不存在:' + e.message);
|
||||
uni.showLoading({
|
||||
title: '加载中'
|
||||
})
|
||||
createDownload(onlinePath)
|
||||
}
|
||||
);
|
||||
|
||||
function createDownload(e) {
|
||||
let downloadOptions = {
|
||||
method: "GET",
|
||||
timeout: 120,
|
||||
retryInterval: 10,
|
||||
filename: savePath
|
||||
};
|
||||
// https://www.html5plus.org/doc/zh_cn/downloader.html#plus.downloader.Download
|
||||
var dtask = plus.downloader.createDownload(e, downloadOptions, function(download, status) {
|
||||
uni.hideLoading()
|
||||
// 下载完成
|
||||
if (status == 200) {
|
||||
resolve(download.filename)
|
||||
} else {
|
||||
reject({
|
||||
status: status,
|
||||
msg: '下载失败'
|
||||
})
|
||||
}
|
||||
});
|
||||
dtask.start();
|
||||
}
|
||||
})
|
||||
},
|
||||
//APP打开文件
|
||||
plusOpenFile({
|
||||
filePath
|
||||
}) {
|
||||
|
||||
let system = uni.getSystemInfoSync().platform;
|
||||
if (system == 'ios') {
|
||||
filePath = encodeURI(filePath);
|
||||
}
|
||||
uni.openDocument({
|
||||
filePath,
|
||||
success: res => {
|
||||
// console.log('打开文件成功');
|
||||
},
|
||||
fail: res => {
|
||||
console.log(res);
|
||||
}
|
||||
});
|
||||
},
|
||||
// 汉字拼音A-Z排序
|
||||
sortList({
|
||||
list,
|
||||
key
|
||||
}) {
|
||||
var sortKey = [] //字母
|
||||
list.forEach(item => {
|
||||
let firstChar = ''
|
||||
item[key] = item[key] ? item[key].trim() : ""
|
||||
if (item[key]) { // 如传入空字符串,getCamelFistChar错误地返回Y
|
||||
firstChar = pinyin.getCamelFistChar(item[key]).toUpperCase() // 如字母开头,将返回字母且保留原大小写;一律改为大写
|
||||
var reg = /^\d+$/;
|
||||
if (reg.test(firstChar)) {
|
||||
firstChar = 'Z#'
|
||||
}
|
||||
item.sort = firstChar
|
||||
sortKey.push(firstChar)
|
||||
}
|
||||
})
|
||||
sortKey = [...new Set(sortKey)]
|
||||
list.sort((a, b) => a.sort.localeCompare(b.sort, 'zh')) //排序
|
||||
sortKey.sort((a, b) => a.localeCompare(b, 'zh')) //排序
|
||||
var sortlist = []
|
||||
for (var i = 0; i < sortKey.length; i++) {
|
||||
var sort = sortKey[i]
|
||||
if (sort == 'Z#') {
|
||||
sort = '#'
|
||||
}
|
||||
sortlist.push({
|
||||
letter: sort,
|
||||
data: []
|
||||
})
|
||||
for (var j = 0; j < list.length; j++) {
|
||||
var item = list[j]
|
||||
if (item.sort == 'Z#') {
|
||||
item.sort = '#'
|
||||
}
|
||||
if (item.sort == sort) {
|
||||
sortlist[i].data.push(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sortlist
|
||||
},
|
||||
saoyisao(){//扫一扫
|
||||
// #ifdef APP-PLUS
|
||||
uni.scanCode({
|
||||
success: (res)=> {
|
||||
var result=res.result
|
||||
var data=res.result.split(':')
|
||||
var type=data[0]
|
||||
var value=data[1]
|
||||
switch (type){
|
||||
case 'group':
|
||||
uni.navigateTo({
|
||||
url:'../../wx/groupInfo/scanCodeDetail?param='+result
|
||||
})
|
||||
break;
|
||||
case 'user':
|
||||
uni.navigateTo({
|
||||
url:'../../wx/personInfo/detail?param='+value+'&source=1'
|
||||
})
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifndef APP-PLUS
|
||||
uni.showToast({
|
||||
title:'扫一扫',
|
||||
icon:'none'
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
// 设置原生titleNView导航文字
|
||||
setTitleNViewBtns(index,text){
|
||||
let pages = getCurrentPages();
|
||||
let page = pages[pages.length - 1];
|
||||
// #ifdef APP-PLUS
|
||||
let currentWebview = page.$getAppWebview();
|
||||
let titleObj = currentWebview.getStyle().titleNView;
|
||||
if (!titleObj.buttons) {
|
||||
return;
|
||||
}
|
||||
titleObj.buttons[index].text = text;
|
||||
currentWebview.setStyle({
|
||||
titleNView: titleObj
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
debounce(func, wait = 1000, immediate = true){
|
||||
/**
|
||||
* @desc 函数防抖
|
||||
* @param func 目标函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param immediate true - 立即执行, false - 延迟执行
|
||||
*/
|
||||
let timer;
|
||||
return function() {
|
||||
let args = arguments;
|
||||
if (timer) {
|
||||
console.log('拦截')
|
||||
clearTimeout(timer);
|
||||
}
|
||||
if (immediate) {
|
||||
let callNow = !timer;
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
}, wait);
|
||||
if (callNow){
|
||||
func.apply(this, args);
|
||||
}
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
func.apply(this, args);
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
},
|
||||
throttle (func, wait = 1000, type = 1) {
|
||||
/**
|
||||
* @desc 函数节流
|
||||
* @param func 函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发
|
||||
*/
|
||||
let previous = 0;
|
||||
let timeout;
|
||||
return function() {
|
||||
let context = this;
|
||||
let args = arguments;
|
||||
if (type === 1) {
|
||||
let now = Date.now();
|
||||
|
||||
if (now - previous > wait) {
|
||||
func.apply(context, args);
|
||||
previous = now;
|
||||
}
|
||||
} else if (type === 2) {
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
func.apply(context, args)
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
294
im-uniapp/common/request.js
Normal file
294
im-uniapp/common/request.js
Normal file
@@ -0,0 +1,294 @@
|
||||
// #ifdef APP-PLUS
|
||||
import appUpgrade from '@/common/appUpgrade.js';
|
||||
// #endif
|
||||
let http = {
|
||||
'setBaseUrl': (url) => {
|
||||
if (url.charAt(url.length - 1) === "/") {
|
||||
url = url.substr(0, url.length - 1)
|
||||
}
|
||||
http.baseUrl = url;
|
||||
},
|
||||
'header': {},
|
||||
'beforeRequestFilter': (config) => {
|
||||
return config
|
||||
},
|
||||
'beforeResponseFilter': (res) => {
|
||||
return res
|
||||
},
|
||||
'afterResponseFilter': (successResult) => {},
|
||||
'get': get,
|
||||
'delete': deletE,
|
||||
'post': post,
|
||||
'put': put,
|
||||
'request': request,
|
||||
'uploadFile': uploadFile,
|
||||
'downloadFile': downloadFile
|
||||
}
|
||||
|
||||
|
||||
function init(con) {
|
||||
//url
|
||||
let url = http.baseUrl;
|
||||
if (url && con.url && !con.url.match(/^(http|https):\/\/([\w.]+\/?)\S*$/)) {
|
||||
if (con.url.charAt(0) !== "/") {
|
||||
con.url = "/" + con.url;
|
||||
}
|
||||
con.url = url.concat(con.url);
|
||||
}
|
||||
//header
|
||||
if (http.header != undefined && http.header != null) {
|
||||
if (!con.header) {
|
||||
con.header = http.header;
|
||||
} else {
|
||||
Object.keys(http.header).forEach(function(key) {
|
||||
con.header[key] = http.header[key]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function request(con) {
|
||||
init(con);
|
||||
let config = { //判断是否有以下属性没有就赋予默认值
|
||||
url: con.url ? con.url : http.baseUrl,
|
||||
data: con.data,
|
||||
header: con.header,
|
||||
method: con.method ? con.method : 'GET',
|
||||
dataType: con.dataType ? con.dataType : 'json',
|
||||
responseType: con.responseType ? con.responseType : 'text',
|
||||
success: con.success ? (res) => {
|
||||
http.afterResponseFilter(con.success(http.beforeResponseFilter(res)));
|
||||
} : null,
|
||||
fail: con.fail ? (res) => {
|
||||
con.fail(res);
|
||||
} : () => {
|
||||
uni.showToast({
|
||||
title: '请检查网络',
|
||||
icon: 'none'
|
||||
});
|
||||
uni.hideLoading();
|
||||
},
|
||||
complete: con.complete ? (res) => {
|
||||
con.complete(res);
|
||||
} : (res) => {
|
||||
if (!res.statusCode) {
|
||||
uni.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none'
|
||||
});
|
||||
uni.hideLoading();
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
uni.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none'
|
||||
});
|
||||
uni.hideLoading();
|
||||
}
|
||||
if (res.statusCode == 200) {
|
||||
if (res.data.code == 401) { //登录过期
|
||||
// uni.showToast({
|
||||
// title: '登录已过期,请重新登录',
|
||||
// icon: 'none'
|
||||
// });
|
||||
// uni.hideLoading();
|
||||
// uni.reLaunch({
|
||||
// url:'/pages/wxindex/index'
|
||||
// })
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
if (res.data.code == 601) { //强制拉起升级
|
||||
request({
|
||||
url: '/common/getVersion',
|
||||
success: (res) => {
|
||||
appUpgrade.init({
|
||||
titleText: '版本更新'+res.data.data.version,
|
||||
packageUrl:res.data.data.url,
|
||||
content: res.data.data.content,
|
||||
forceUpgrade:true
|
||||
});
|
||||
appUpgrade.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
else if (res.data.code && res.data.code !== 200) { //这里code是自己的服务器正确标识
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
position:'top'
|
||||
});
|
||||
}
|
||||
uni.hideLoading();
|
||||
}
|
||||
uni.stopPullDownRefresh();
|
||||
}
|
||||
}
|
||||
const AUTH_TOKEN = ["Authorization","device","version"];
|
||||
for (var i = 0; i < AUTH_TOKEN.length; i++) {
|
||||
if (uni.getStorageSync(AUTH_TOKEN[i])) {
|
||||
http.header[AUTH_TOKEN[i]] = uni.getStorageSync(AUTH_TOKEN[i]);
|
||||
}
|
||||
}
|
||||
return uni.request(http.beforeRequestFilter(config));
|
||||
}
|
||||
|
||||
function get(url, con, success) {
|
||||
let conf = {};
|
||||
if (con && typeof con == 'function') {
|
||||
if (success && typeof success == 'object') {
|
||||
conf = success;
|
||||
}
|
||||
conf.success = con
|
||||
} else {
|
||||
if (con && typeof con == 'object') {
|
||||
conf = con;
|
||||
}
|
||||
conf.success = success;
|
||||
}
|
||||
|
||||
if (url) {
|
||||
conf.url = url
|
||||
}
|
||||
conf.method = "GET";
|
||||
return request(conf);
|
||||
}
|
||||
|
||||
function deletE(url, con, success) {
|
||||
let conf = {};
|
||||
if (con && typeof con == 'function') {
|
||||
if (success && typeof success == 'object') {
|
||||
conf = success;
|
||||
}
|
||||
conf.success = con
|
||||
} else {
|
||||
if (con && typeof con == 'object') {
|
||||
conf = con;
|
||||
}
|
||||
conf.success = success;
|
||||
}
|
||||
|
||||
if (url) {
|
||||
conf.url = url
|
||||
}
|
||||
conf.method = "DELETE";
|
||||
return request(conf);
|
||||
}
|
||||
|
||||
function post(url, data, con, success) {
|
||||
let conf = {};
|
||||
if (con && typeof con == 'function') {
|
||||
if (success && typeof success == 'object') {
|
||||
conf = success
|
||||
}
|
||||
conf.success = con;
|
||||
} else {
|
||||
if (con && typeof con == 'object') {
|
||||
conf = con;
|
||||
}
|
||||
conf.success = success;
|
||||
}
|
||||
if (url) {
|
||||
conf.url = url
|
||||
}
|
||||
if (data) {
|
||||
conf.data = data
|
||||
}
|
||||
conf.method = "POST";
|
||||
return request(conf);
|
||||
}
|
||||
|
||||
function put(url, data, con, success) {
|
||||
let conf = {};
|
||||
if (con && typeof con == 'function') {
|
||||
if (success && typeof success == 'object') {
|
||||
conf = success
|
||||
}
|
||||
conf.success = con;
|
||||
} else {
|
||||
if (con && typeof con == 'object') {
|
||||
conf = con;
|
||||
}
|
||||
conf.success = success;
|
||||
}
|
||||
if (url) {
|
||||
conf.url = url
|
||||
}
|
||||
if (data) {
|
||||
conf.data = data
|
||||
}
|
||||
conf.method = "PUT";
|
||||
return request(conf);
|
||||
}
|
||||
|
||||
function uploadFile(con) {
|
||||
init(con);
|
||||
let config = {
|
||||
url: con.url ? con.url : http.baseUrl,
|
||||
files: con.files,
|
||||
filesType: con.filesType,
|
||||
filePath: con.filePath,
|
||||
name: con.name,
|
||||
header: con.header,
|
||||
formData: con.formData,
|
||||
success: con.success ? (res) => {
|
||||
http.afterResponseFilter(con.success(http.beforeResponseFilter(res)));
|
||||
} : null,
|
||||
fail: con.fail ? (res) => {
|
||||
con.fail(res);
|
||||
} : null,
|
||||
complete: con.complete ? (res) => {
|
||||
con.complete(res);
|
||||
} : null
|
||||
}
|
||||
const AUTH_TOKEN = ["Authorization","device","version"];
|
||||
for (var i = 0; i < AUTH_TOKEN.length; i++) {
|
||||
if (uni.getStorageSync(AUTH_TOKEN[i])) {
|
||||
http.header[AUTH_TOKEN[i]] = uni.getStorageSync(AUTH_TOKEN[i]);
|
||||
}
|
||||
}
|
||||
return uni.uploadFile(http.beforeRequestFilter(config));
|
||||
}
|
||||
|
||||
function downloadFile(con) {
|
||||
init(con);
|
||||
let config = {
|
||||
url: con.url ? con.url : http.baseUrl,
|
||||
header: con.header,
|
||||
success: con.success ? (res) => {
|
||||
http.afterResponseFilter(con.success(http.beforeResponseFilter(res)));
|
||||
} : null,
|
||||
fail: con.fail ? (res) => {
|
||||
con.fail(res);
|
||||
} : null,
|
||||
complete: con.complete ? (res) => {
|
||||
con.complete(res);
|
||||
} : null
|
||||
}
|
||||
return uni.downloadFile(http.beforeRequestFilter(config));
|
||||
}
|
||||
// 使用
|
||||
//POST
|
||||
// this.$http.request({
|
||||
// url: '/xxx',
|
||||
// method: 'POST',
|
||||
// data:JSON.stringify({id:111}),
|
||||
// success: (res) => {
|
||||
// if (res.data.code == 200) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//GET
|
||||
// this.$http.request({
|
||||
// url: '/xxx?id=111',
|
||||
// success: (res) => {
|
||||
// if (res.data.code == 200) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// 地址及配置
|
||||
http.setBaseUrl("http://localhost:8989"); //在线服务器
|
||||
// http.setBaseUrl("http://192.168.0.105:8080"); //离线服务器
|
||||
export default http
|
||||
70
im-uniapp/common/socketTask.js
Normal file
70
im-uniapp/common/socketTask.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import fc from '@/common/publicFc.js'
|
||||
let timer=null
|
||||
let retimer=null
|
||||
export default {
|
||||
socketTask:null,
|
||||
// 连接WebSocket
|
||||
connectSocket() {
|
||||
this.socketTask=uni.connectSocket({
|
||||
url: 'wss://im-api.q3z3.com/ws?Authorization=' + uni.getStorageSync('Authorization'),
|
||||
complete: () => {}
|
||||
});
|
||||
this.socketTask.onOpen(res => {
|
||||
console.log('WebSocket连接已打开!');
|
||||
// 设置心跳
|
||||
timer=setInterval(()=>{
|
||||
uni.sendSocketMessage({
|
||||
data:'isConnact',
|
||||
success:res=>{
|
||||
if(res.errMsg=='sendSocketMessage:ok'){
|
||||
console.log('WebSocket已连接')
|
||||
}else{
|
||||
this.connectSocket()
|
||||
}
|
||||
}
|
||||
})
|
||||
},5000)
|
||||
})
|
||||
// 监听接收
|
||||
this.socketTask.onMessage(res => {
|
||||
if(res.data=='ok'){
|
||||
return
|
||||
}
|
||||
var data = JSON.parse(res.data);
|
||||
fc.getPush(data);
|
||||
console.log('WebSocket接收消息!');
|
||||
})
|
||||
// 监听关闭
|
||||
this.socketTask.onClose(res => {
|
||||
console.log('WebSocket连接已关闭!');
|
||||
let token= uni.getStorageSync('Authorization');
|
||||
if(this.socketTask&&token){
|
||||
this.socketTaskClose()
|
||||
retimer=setTimeout(()=>{
|
||||
this.connectSocket()
|
||||
},5000)
|
||||
}
|
||||
})
|
||||
// 监听异常
|
||||
this.socketTask.onError(res => {
|
||||
console.log('WebSocket连接打开失败,正在尝试重新打开!');
|
||||
if(this.socketTask){
|
||||
this.socketTaskClose()
|
||||
retimer=setTimeout(()=>{
|
||||
this.connectSocket()
|
||||
},5000)
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
// 关闭WebSocket
|
||||
socketTaskClose() {
|
||||
if(this.socketTask){
|
||||
this.socketTask.close()
|
||||
clearInterval(timer)
|
||||
clearTimeout(retimer)
|
||||
console.log('关闭WebSocket!');
|
||||
}
|
||||
},
|
||||
}
|
||||
75
im-uniapp/common/zmmFormCheck.js
Normal file
75
im-uniapp/common/zmmFormCheck.js
Normal file
@@ -0,0 +1,75 @@
|
||||
// 表单验证
|
||||
// zmm2113@qq.com
|
||||
/**
|
||||
* @property {Object} formData 表单
|
||||
* @property {Object} rules 验证规则
|
||||
**/
|
||||
export default {
|
||||
error: '',
|
||||
check: function(formData, rules) {
|
||||
var formDataKeys = Object.keys(formData)
|
||||
for (var i = 0; i < formDataKeys.length; i++) {
|
||||
var key = formDataKeys[i]
|
||||
if (rules[key]) {
|
||||
var itemRules = rules[key].rules
|
||||
var itemValue = formData[key]
|
||||
for (var j = 0; j < itemRules.length; j++) {
|
||||
var rule = itemRules[j]
|
||||
switch (rule.checkType){
|
||||
case 'required'://必填项
|
||||
if(!itemValue) {this.error = rule.errorMsg; return false;}
|
||||
break;
|
||||
|
||||
case 'phone'://手机号码验证
|
||||
var reg = /^1[0-9]{10,10}$/;
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'email'://邮箱验证
|
||||
var reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'idcard'://15-18位身份证验证
|
||||
var reg = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'url'://网址验证
|
||||
var reg = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'reg'://正则验证 checkRule必填
|
||||
if(!rule.checkRule){
|
||||
this.error=key+' 校验失败'
|
||||
console.warn(key+' checkRule规则未填写')
|
||||
return false;
|
||||
}
|
||||
var reg = rule.checkRule;
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'number'://数字
|
||||
var reg = /^\d+$/;
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'same'://是否相同 checkRule必填
|
||||
if(!rule.checkRule){
|
||||
this.error=key+' 校验失败'
|
||||
console.warn(key+' checkRule规则未填写')
|
||||
return false;
|
||||
}
|
||||
if (itemValue!==formData[rule.checkRule]) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
case 'string'://字符串 checkRule必填
|
||||
if(!rule.checkRule){
|
||||
this.error=key+' 校验失败'
|
||||
console.warn(key+' checkRule规则未填写')
|
||||
return false;
|
||||
}
|
||||
var reg = new RegExp('^.{' + rule.checkRule + '}$');
|
||||
if (!reg.test(itemValue)) { this.error = rule.errorMsg; return false; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user