1.js中定义Promise

export function wxLogin() {
	let pResult = new Promise((resolve, reject) => {
		uni.login({
			provider: 'weixin',
			success: (res) => {
				console.log('login success:', res);
				// return res;
				setTimeout(function() {
					resolve(res);
				}, 3000);
			},
			fail: (err) => {
				console.log('login fail:', err);
				reject(err);
			}
		});
	}).catch(res => {
		console.log(666, res);
	})
	return pResult;
}

2.vue文件中使用

	import {login,wxLogin} from '@/common/login.js'
	
			(async () => {
				//获取授权状态
				console.log(1111,"111")
				let aaa = await wxLogin();
				console.log(3333,"3333");
				console.log(4444,aaa);
			})()

3.另外一种写法

(async () => {
    //获取授权状态
    console.log(22222)
    await getNextAppoverFun();
    console.log(44444);
})()

// console.log(55555);
//下一环节处理人
async function getNextAppoverFun() {
    const { headers: { 'x-csrf-token': csrfToken } } = await getFodXsrfToken();
    let resHeaders = { "x-csrf-token": csrfToken }

    let params = {
        "I_PROCODE": currentInstance.proxy.$businessCode,
        "I_STEP_NO": "0", //创建时传0
        "I_SKEY": "3008", //公司id
        "I_CURRENCY": "",
        "I_APPRAMT": "0",
        "I_DEPARTMENTID": "123", //部门id
        "I_USER": "567", //用户id
        "E_RETURN": { "E_SUBRC": "" },
        "IT_APPRCODE": [],
        "ET_PATH": []
    };
    await getNextAppover(resHeaders, params).then(res => {
        console.log(33333, res);
    }).catch(error => {
    }).finally(() => {
    });
}

Logo

前往低代码交流专区

更多推荐