193 lines
4.9 KiB
JavaScript
193 lines
4.9 KiB
JavaScript
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
import {
|
||
TOKENNAME,
|
||
HTTP_REQUEST_URL
|
||
} from '../config/app.js';
|
||
|
||
export default {
|
||
/*
|
||
* 合并数组
|
||
*/
|
||
SplitArray(list, sp) {
|
||
if (typeof list != 'object') return [];
|
||
if (sp === undefined) sp = [];
|
||
for (var i = 0; i < list.length; i++) {
|
||
sp.push(list[i]);
|
||
}
|
||
return sp;
|
||
},
|
||
/**
|
||
* opt object | string
|
||
* to_url object | string
|
||
* 例:
|
||
* this.Tips('/pages/test/test'); 跳转不提示
|
||
* this.Tips({title:'提示'},'/pages/test/test'); 提示并跳转
|
||
* this.Tips({title:'提示'},{tab:1,url:'/pages/index/index'}); 提示并跳转值table上
|
||
* tab=1 一定时间后跳转至 table上
|
||
* tab=2 一定时间后跳转至非 table上
|
||
* tab=3 一定时间后返回上页面
|
||
* tab=4 关闭所有页面跳转至非table上
|
||
* tab=5 关闭当前页面跳转至table上
|
||
*/
|
||
Tips: function(opt, to_url) {
|
||
if (typeof opt == 'string') {
|
||
to_url = opt;
|
||
opt = {};
|
||
}
|
||
let title = opt.title || '',
|
||
icon = opt.icon || 'none',
|
||
endtime = opt.endtime || 2000,
|
||
success = opt.success;
|
||
if (title) uni.showToast({
|
||
title: title,
|
||
icon: icon,
|
||
duration: endtime,
|
||
success
|
||
})
|
||
if (to_url != undefined) {
|
||
if (typeof to_url == 'object') {
|
||
let tab = to_url.tab || 1,
|
||
url = to_url.url || '';
|
||
switch (tab) {
|
||
case 1:
|
||
//一定时间后跳转至 table
|
||
setTimeout(function() {
|
||
uni.switchTab({
|
||
url: url
|
||
})
|
||
}, endtime);
|
||
break;
|
||
case 2:
|
||
//跳转至非table页面
|
||
setTimeout(function() {
|
||
uni.navigateTo({
|
||
url: url,
|
||
})
|
||
}, endtime);
|
||
break;
|
||
case 3:
|
||
//返回上页面
|
||
setTimeout(function() {
|
||
// #ifndef H5
|
||
uni.navigateBack({
|
||
delta: parseInt(url),
|
||
})
|
||
// #endif
|
||
// #ifdef H5
|
||
history.back();
|
||
// #endif
|
||
}, endtime);
|
||
break;
|
||
case 4:
|
||
//关闭当前所有页面跳转至非table页面
|
||
setTimeout(function() {
|
||
uni.reLaunch({
|
||
url: url,
|
||
})
|
||
}, endtime);
|
||
break;
|
||
case 5:
|
||
//关闭当前页面跳转至非table页面
|
||
setTimeout(function() {
|
||
uni.redirectTo({
|
||
url: url,
|
||
})
|
||
}, endtime);
|
||
break;
|
||
}
|
||
|
||
} else if (typeof to_url == 'function') {
|
||
setTimeout(function() {
|
||
to_url && to_url();
|
||
}, endtime);
|
||
} else {
|
||
//没有提示时跳转不延迟
|
||
setTimeout(function() {
|
||
uni.navigateTo({
|
||
url: to_url,
|
||
})
|
||
}, title ? endtime : 0);
|
||
}
|
||
}
|
||
},
|
||
/*
|
||
* 单图上传
|
||
* @param object opt
|
||
* @param callable successCallback 成功执行方法 data
|
||
* @param callable errorCallback 失败执行方法
|
||
*/
|
||
uploadImageOne: function(opt, successCallback, errorCallback) {
|
||
let that = this;
|
||
if (typeof opt === 'string') {
|
||
let url = opt;
|
||
opt = {};
|
||
opt.url = url;
|
||
}
|
||
let count = opt.count || 1,
|
||
sizeType = opt.sizeType || ['compressed'],
|
||
sourceType = opt.sourceType || ['album', 'camera'],
|
||
is_load = opt.is_load || true,
|
||
uploadUrl = opt.url || '',
|
||
inputName = opt.name || 'field';
|
||
uni.chooseImage({
|
||
count: count, //最多可以选择的图片总数
|
||
sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有
|
||
sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有
|
||
success: function(res) {
|
||
//启动上传等待中...
|
||
uni.showLoading({
|
||
title: '图片上传中',
|
||
});
|
||
uni.uploadFile({
|
||
url: HTTP_REQUEST_URL + '/api/' + uploadUrl + '/' + inputName,
|
||
filePath: res.tempFilePaths[0],
|
||
name: inputName,
|
||
formData: {
|
||
'filename': inputName
|
||
},
|
||
header: {
|
||
// #ifdef MP
|
||
"Content-Type": "multipart/form-data",
|
||
// #endif
|
||
[TOKENNAME]: 'Bearer ' + uni.getStorageSync('APP_token')
|
||
},
|
||
success: function(res) {
|
||
uni.hideLoading();
|
||
if (res.statusCode == 403) {
|
||
that.Tips({
|
||
title: res.data
|
||
});
|
||
} else {
|
||
let data = res.data ? JSON.parse(res.data) : {};
|
||
if (data.status == 200) {
|
||
successCallback && successCallback(data)
|
||
} else {
|
||
errorCallback && errorCallback(data);
|
||
that.Tips({
|
||
title: data.message
|
||
});
|
||
}
|
||
}
|
||
},
|
||
fail: function(res) {
|
||
uni.hideLoading();
|
||
that.Tips({
|
||
title: '上传图片失败'
|
||
});
|
||
}
|
||
})
|
||
}
|
||
})
|
||
}
|
||
|
||
|
||
}
|