emis-sapp/common/untool.js

110 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-12-02 08:54:31 +00:00
const tabBarUrls = [
2023-12-12 16:51:07 +00:00
'/pages/tabBar/sending/sending',
'/pages/tabBar/search/search',
'/pages/tabBar/mine/mine'
2023-12-02 08:54:31 +00:00
]
const goto = (url, type = 1)=> {
url = `/pages/${url}`
if(tabBarUrls.indexOf(url) > -1) {
return uni.switchTab({
url
});
}
if (type == 1){
uni.navigateTo({
url
});
} else {
uni.redirectTo({
url
});
}
}
const goBack = (opt = {})=> {
uni.navigateBack(opt)
}
const reLaunch = (opt = {})=> {
uni.reLaunch(opt)
}
2023-12-04 08:14:24 +00:00
const setClipboardData = (val)=> {
uni.setClipboardData({
data: val,
success: () => {
2023-12-12 16:51:07 +00:00
showToast('复制成功')
2023-12-04 08:14:24 +00:00
},
})
}
2023-12-12 00:50:19 +00:00
const showToast = (val)=> {
uni.showToast({ title: val, icon: 'none' })
}
2023-12-04 08:14:24 +00:00
const confirmModal = (title) => {
return new Promise((resolve)=> {
uni.showModal({ content: title, confirmColor: '#B12D29' }).then((res)=> {
if(res.confirm) {
resolve()
}
})
})
}
const showLoading = ()=> {
uni.showLoading({
mask: true,
title: '加载中'
});
}
2023-12-13 04:27:01 +00:00
const scanCode = ()=> {
return new Promise((resolve, reject)=> {
uni.scanCode({
onlyFromCamera: false,
success: resolve,
fail: reject
})
})
}
2023-12-16 17:34:29 +00:00
const makePhoneCall = (phoneNumber)=> {
uni.makePhoneCall({
phoneNumber: phoneNumber
});
}
2023-12-17 15:28:03 +00:00
const downloadFile = (url)=> {
return new Promise((resolve, reject)=> {
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
console.log('下载成功');
resolve(true)
}
},
fail: (err)=>{
reject(err)
}
});
})
}
2023-12-16 17:34:29 +00:00
2023-12-02 08:54:31 +00:00
export {
reLaunch,
goto,
2023-12-04 08:14:24 +00:00
goBack,
setClipboardData,
confirmModal,
showLoading,
2023-12-13 04:27:01 +00:00
showToast,
2023-12-16 17:34:29 +00:00
scanCode,
2023-12-17 15:28:03 +00:00
makePhoneCall,
downloadFile
2023-12-02 08:54:31 +00:00
}