小程序扫码进行页面跳转,思路:在需要跳转的页面发请求
封装的接口
export async function mataReading(params) {
try {
return await http.post('/Expense/v1/E_ExpenseSortRelation/GetTheData', params, {
loading: true
});
} catch (e) {
return e;
//TODO handle the exception
}
}
引入
import { mataReading } from '@/api/statics.api';
发请求
<script>
function scanner() {
// #ifdef APP-PLUS
uni.scanCode({
autoDecodeCharSet: true, //
scanType: ['qrCode'], //二维码类型
success(res) { //成功后 再发起接口
const { result } = res;
//拿到的数据是字符串,转换成对象
const { Text, Types } = JSON.parse(res.result);
mataReading({ id: Text }).then(r => {
const { Success, Data, Msg } = r;
if (Success) {
const { FloorId, ExpenseSortId, HouseId } = Data; //解构赋值
//判断 Types的类型
switch (Types) {
case 4: //Types为4
uni.redirectTo({
url: '/pages/task_details/task_details'
});
break;
case 6:
uni.redirectTo({
url:`/pages/meter_reading_tab/meter_reading_tabFloorId=${FloorId}&ExpenseSortId=${ExpenseSortId}&HouseId=${HouseId}&LevelName=1` //跳转携带参数
});
break;
}
}
});
},
fail() {
console.log('err');
},
complete() {
console.log('complete');
}
});
</script>