const tabBarUrls = [ '/pages/tabBar/deal/deal', '/pages/tabBar/home/home', '/pages/tabBar/mine/mine', '/pages/tabBar/order/order' ] 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) } const setClipboardData = (val)=> { uni.setClipboardData({ data: val, success: () => { showToast('复制成功') }, }) } const showToast = (val)=> { uni.showToast({ title: val, icon: 'none' }) } 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: '加载中' }); } const scanCode = ()=> { return new Promise((resolve, reject)=> { uni.scanCode({ onlyFromCamera: false, success: resolve, fail: reject }) }) } const makePhoneCall = (phoneNumber)=> { uni.makePhoneCall({ phoneNumber: phoneNumber }); } 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) } }); }) } export { reLaunch, goto, goBack, setClipboardData, confirmModal, showLoading, showToast, scanCode, makePhoneCall, downloadFile }