import Taro from '@tarojs/taro'
import store from '../store/index'
// 1.错误提示
// 2.接口请求的加载中
// 3.数据请求成功 success===0000
// 4.错误信息的解析 状态码
export async function request (params) {
const {url,data,method,header,isLoading=true,isShowError=true,timeout=60000,...otherData} = params
if(isLoading){
Taro.showLoading({
title: ''
})
}
return await new Promise((resolve)=>{
return Taro.request({
data:data,
url:url,
method:method,
timeout:timeout,
header: {
'content-type': 'application/json;charset=UTF-8,text/plain,*/*',
'deerma_token':store.state.token || undefined,
...header
},
...otherData,
success: function (res) {
if(isLoading){
Taro.hideLoading();
}
if (res.data.code==='0000') {
resolve({success:true,data:res.data.data});
} else {
if(isShowError){
showErrorToast(res.data.msg)
}
resolve({data:res,success:false})
}
},
error(e) {
if(isLoading){
Taro.hideLoading();
}
if(isShowError){
showErrorToast(e)
}
// eslint-disable-next-line no-undef
resolve({data:e,success:false})
}
})
})
}
function showErrorToast(msg) {
Taro.showToast({
title: msg,
icon: 'none'
// image: '/static/images/icon_error.png'
})
}
import { loginIdm } from '../../api/request'
async toLogin(){
if(this.clickIt) return
const {success,data}=await loginIdm({loginAccount: this.accountVal ,loginPass: this.passworldVal})
if(success){
// 获取用户信息
this.$store.dispatch('getCurrentUser',data.token)
router.navigateTo({url:'/pages/index/index'})
}
}