You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
2.5 KiB
138 lines
2.5 KiB
|
|
|
|
const _dTo = function(url) {
|
|
if (!_getSync('isLogin')) {
|
|
_gTo('/pages/login/index')
|
|
return;
|
|
}
|
|
uni.navigateTo({
|
|
url: url
|
|
});
|
|
}
|
|
const _gTo = function(url) {
|
|
uni.navigateTo({
|
|
url: url
|
|
});
|
|
}
|
|
const _getSync = (i) => {
|
|
return uni.getStorageSync(i);
|
|
}
|
|
const _removeSync = (i) => {
|
|
return uni.removeStorageSync(i);
|
|
}
|
|
const _setSync = (i, data) => {
|
|
return uni.setStorageSync(i, data);
|
|
}
|
|
const _alert = (txt, cb) => {
|
|
uni.showModal({
|
|
title: '温馨提示',
|
|
content: txt,
|
|
showCancel: false,
|
|
confirmColor: '#2979ff',
|
|
success: function() {
|
|
cb && cb();
|
|
}
|
|
});
|
|
}
|
|
|
|
const _confirm = function(txt, cb) {
|
|
uni.showModal({
|
|
title: '温馨提示',
|
|
content: txt,
|
|
showCancel: true,
|
|
confirmColor: '#2979ff',
|
|
success: function(res) {
|
|
if (res.confirm) {
|
|
cb && cb();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
const _toast = function(txt) {
|
|
uni.showToast({
|
|
title: txt,
|
|
icon: 'none',
|
|
duration: 1500
|
|
});
|
|
}
|
|
|
|
|
|
const _backT = function() {
|
|
uni.navigateBack();
|
|
}
|
|
const _call = function(tel) {
|
|
uni.makePhoneCall({
|
|
phoneNumber: tel
|
|
});
|
|
}
|
|
|
|
const _showLoading = (msg = '') => uni.showLoading({
|
|
mask: true,
|
|
title: msg
|
|
});
|
|
|
|
/**
|
|
* 关闭loading
|
|
*/
|
|
const _closeLoading = () => uni.hideLoading();
|
|
|
|
// 获取截图宽高
|
|
const _screenshot = function(fromWhere, widthProp, proportion) {
|
|
var width = 0,
|
|
height = 0;
|
|
uni.getSystemInfo({
|
|
//整个手机屏幕的高
|
|
success: function(res) {
|
|
width = parseInt(res.screenWidth * widthProp) //宽等于屏幕款*百分比
|
|
height = width * proportion
|
|
}
|
|
});
|
|
_gTo('../u-avatar-cropper/u-avatar-cropper?destWidth=' + (width * 2) + '&destHeight=' + (height * 2) +
|
|
'&rectWidth=' + width + '&rectHeight=' + height + '&fileType=jpg' + '&fromWhere=' +
|
|
fromWhere)
|
|
}
|
|
// 复制
|
|
const _copy = (data) => {
|
|
uni.setClipboardData({
|
|
data: data,
|
|
success: function() {
|
|
}
|
|
});
|
|
}
|
|
const _upLoad = function(tempFilePaths) {
|
|
return new Promise((resolve, reject) => {
|
|
uni.uploadFile({
|
|
url: import.meta.env.VITE_BASE_URL + '/common/upload', //仅为示例,非真实的接口地址
|
|
filePath: tempFilePaths,
|
|
name: 'file',
|
|
formData: {
|
|
'user': 'test'
|
|
},
|
|
header: { "Content-Type": "multipart/form-data", 'openId': uni.getStorageSync('openId') },
|
|
success: (uploadFileRes) => {
|
|
let item = JSON.parse(uploadFileRes.data.replace(/\ufeff/g, ""));
|
|
resolve(item)
|
|
},
|
|
fail(err) {
|
|
}
|
|
});
|
|
})
|
|
}
|
|
export {
|
|
_dTo,
|
|
_gTo,
|
|
_toast,
|
|
_backT,
|
|
_call,
|
|
_confirm,
|
|
_alert,
|
|
_getSync,
|
|
_setSync,
|
|
_removeSync,
|
|
_showLoading,
|
|
_closeLoading,
|
|
_screenshot,
|
|
_copy,
|
|
_upLoad
|
|
};
|
|
|