修复用户微信扫码进入小程序无法跳转及登录问题,修改会员卡解绑接口
| | |
| | | export function removeCardApi(cardNumber){ |
| | | return request(`/waterCard/remove?cardNumber=${cardNumber}`,{},'GET') |
| | | } |
| | | //会员卡解绑 |
| | | export function removeBindingApi(cardNumber){ |
| | | return request(`/waterCard/removeBinding?cardNumber=${cardNumber}`,{},'GET') |
| | | } |
| | | //故障上报 |
| | | export function infoBreakdownApi(data){ |
| | | return request('/waterFacilityMalfunction/create',data,'POST') |
| | |
| | | <script setup> |
| | | import { onMounted, ref } from "vue"; |
| | | import { BASE_URL } from '../../config/baseUrl'; |
| | | import { getVipInfoApi,getUserInfo,reportLossApi,removeCardApi,buyWaterApi } from '../../api/index.js' |
| | | import { getVipInfoApi,getUserInfo,reportLossApi,removeBindingApi,buyWaterApi } from '../../api/index.js' |
| | | import { onShow,getCurrentPages } from '@dcloudio/uni-app' |
| | | //状态栏高度 |
| | | const topHeight = ref(0) |
| | |
| | | cardInfo.value.userPhone = res.data.userInfo.userPhone |
| | | cardInfo.value.id = res.data.userInfo.id |
| | | await getVipInfo() |
| | | console.log('00000',cardInfo.value) |
| | | console.log('用户信息响应',res) |
| | | console.log('用户信息',cardInfo.value) |
| | | uni.setStorageSync('userInfo',JSON.stringify(cardInfo.value)) |
| | | } |
| | | }) |
| | |
| | | * 功能列表相关 |
| | | */ |
| | | const functionList = ref([ |
| | | //isUrl:1:页面跳转,2:弹窗功能,3:弹窗功能,4:未开发 |
| | | {text:'余额记录',icon:'../../static/images/index/icon31.png',bgColor:'#16b387',url:'/pages/functionList/balanceRecord/index',isUrl:1}, |
| | | {text:'消费记录',icon:'../../static/images/index/icon32.png',bgColor:'#329ae8',url:'/pages/functionList/paymentRecord/index',isUrl:1}, |
| | | {text:'充值记录',icon:'../../static/images/index/icon33.png',bgColor:'#f0a50e',url:'/pages/functionList/rechargeRecord/index',isUrl:1}, |
| | |
| | | } |
| | | }else if(isUrl == 3){ |
| | | if(cardInfo.value.waterCardNumber){ |
| | | //判断是否是分享卡:分享卡不许注销 |
| | | if(!isShareCard.value){ |
| | | uni.showModal({ |
| | | title: '会员卡注销', |
| | | content: '确认注销会员卡?', |
| | | success: async function(res) { |
| | | if (res.confirm) { |
| | | await removeCardApi(cardInfo.value.waterCardNumber).then(async(res) =>{ |
| | | await removeBindingApi(cardInfo.value.waterCardNumber).then(async(res) =>{ |
| | | if(res.code == 200){ |
| | | uni.showToast({ |
| | | title: '已注销', |
| | |
| | | </block> |
| | | </view> |
| | | </view> |
| | | <!-- <view @click="navTo('/pages/wxScanWater/index')">测试扫码取水</view> --> |
| | | <!-- 积分商城 --> |
| | | <view class="advertisement-box" @click="navTo('/pagesPoints/pointsMall/index')"> |
| | | <view class="point-advert"> |
| | |
| | | }else{ |
| | | uni.showToast({ |
| | | title:'登录失败', |
| | | icon:'none' |
| | | icon:'none', |
| | | |
| | | }) |
| | | } |
| | | }) |
| | |
| | | <image class="top-bg" :src="baseUrl + '/upload' + '/qingYuan/images/20241126/2f56a2a7ecfd2544dec5978d2687383e.png'" mode="widthFix"></image> |
| | | <view class="top--title"> |
| | | <image class="logo" src="../../static/images/login/logo.png "></image> |
| | | <view class="text">清源直饮水运维平台</view> |
| | | <view class="text">慧物通直饮水</view> |
| | | </view> |
| | | </view> |
| | | <view class="login-text"> |
| | |
| | | const facilityCode = ref() |
| | | onLoad((option) =>{ |
| | | facilityCode.value = option.facilityCode |
| | | console.log('小程序扫码取水','option.facilityCode',option.facilityCode,'facilityCode',facilityCode.value) |
| | | console.log('小程序扫码取水','option.facilityCode',option.facilityCode,'设备SN',facilityCode.value) |
| | | }) |
| | | //设置水价及支付方式 |
| | | //设置水价,设置支付方式,用户未绑定会员卡不显示余额支付选项 |
| | | async function getWaterPrice(){ |
| | | await getPriceBySnApi(facilityCode.value).then((res) =>{ |
| | | moneyList.value.forEach((item,index) =>{ |
| | |
| | | item.volume = ((index + 1) * res.data.yield).toFixed(1) |
| | | }) |
| | | choosedMoney.value = res.data.price |
| | | console.log('水价设置回调',res,'传参',facilityCode.value) |
| | | console.log('水价设置回调',res,'传参',facilityCode.value,'水价列表',choosedMoney.value) |
| | | }) |
| | | let waterCardNumber = JSON.parse(uni.getStorageSync('userInfo')).waterCardNumber |
| | | let waterCardNumber = (uni.getStorageSync('userInfo') && JSON.parse(uni.getStorageSync('userInfo')).waterCardNumber ) |
| | | console.log('用户水卡信息',uni.getStorageSync('userInfo')) |
| | | if(!waterCardNumber){ |
| | | payList.value.splice(1,1) |
| | | } |
| | |
| | | <script setup> |
| | | import{ ref ,onMounted} from 'vue' |
| | | import { wxPayApi,buyWaterApi,getPriceBySnApi,getVipInfoApi } from '../../api/index.js' |
| | | import { wxPayApi,buyWaterApi,getPriceBySnApi,getVipInfoApi,wxLoginApi } from '../../api/index.js' |
| | | import { onLoad } from "@dcloudio/uni-app" |
| | | //选中金额 |
| | | const choosedMoney = ref(1) |
| | |
| | | cardNumber:'', |
| | | cardBalance:'', |
| | | }) |
| | | //获取用户会员卡信息,判断是否有余额 |
| | | async function setPayMethod(){ |
| | | await getVipInfoApi().then((res) =>{ |
| | | console.log('获取会员卡返回响应-微信扫码取水页',res) |
| | | console.log('会员卡信息响应-微信扫码取水',res) |
| | | if(res.code == 200 && res.data.id){ |
| | | cardInfo.value.cardNumber = res.data.cardNumber |
| | | cardInfo.value.cardBalance = res.data.balance |
| | | }else{ |
| | | console.log('未绑定会员卡') |
| | | payList.value.splice(1,1) |
| | | console.log('未绑定会员卡','支付方式',payList.value) |
| | | } |
| | | }) |
| | | } |
| | |
| | | }) |
| | | } |
| | | } |
| | | const facilityCode = ref() |
| | | const facilityCode = ref('') |
| | | onLoad((query) =>{ |
| | | let url = decodeURIComponent(query.q) |
| | | // let url = 'https://www.huiwuyuntong.com/miniapp/paywater?facilitycode=1060003979' |
| | | facilityCode.value = url.split('=')[1] |
| | | console.log('微信扫码取水','url',url,'facilityCode',facilityCode.value) |
| | | console.log('微信扫码取水','url',url,'设备SN',facilityCode.value) |
| | | }) |
| | | //设置水价 |
| | | async function getWaterPrice(){ |
| | |
| | | item.volume = ((index + 1) * res.data.yield).toFixed(1) |
| | | }) |
| | | choosedMoney.value = res.data.price |
| | | console.log('水价设置回调',res,'传参',facilityCode.value) |
| | | console.log('水价设置响应',res,'传参设备SN',facilityCode.value,'水价显示列表',choosedMoney.value) |
| | | }) |
| | | } |
| | | function navTo(){ |
| | |
| | | url:'/pages/index/index' |
| | | }) |
| | | } |
| | | |
| | | //用户通过微信外部扫描二维码进入页面,默认微信登录授权 |
| | | async function wxLogin() { |
| | | if (!uni.getStorageSync('openId') || !uni.getStorageSync('token')) { |
| | | try { |
| | | const res1 = await new Promise((resolve, reject) => { |
| | | wx.login({ |
| | | success: (result) => resolve(result), |
| | | fail: (error) => reject(error) |
| | | }); |
| | | }); |
| | | |
| | | uni.setStorageSync('code', res1.code); |
| | | |
| | | const res2 = await wxLoginApi({ code: res1.code }); |
| | | console.log('微信登录响应', res2); |
| | | |
| | | if (res2.code == 200) { |
| | | uni.setStorageSync('openId', res2.data.userId); |
| | | uni.setStorageSync('token', res2.data.token); |
| | | } else { |
| | | uni.showToast({ |
| | | title: '登录失败', |
| | | icon: 'none' |
| | | }); |
| | | throw new Error('登录失败'); // 抛出错误,以便在调用 wxLogin 的地方可以捕获 |
| | | } |
| | | } catch (error) { |
| | | uni.showToast({ |
| | | title: '微信登录失败,请退出重试!', |
| | | duration: 2000, |
| | | icon: 'fail' |
| | | }); |
| | | throw error; // 抛出错误,以便在调用 wxLogin 的地方可以捕获 |
| | | } |
| | | } |
| | | } |
| | | |
| | | onMounted(async() =>{ |
| | | await getWaterPrice() |
| | | await setPayMethod() |
| | | }) |
| | | try { |
| | | await wxLogin(); |
| | | await getWaterPrice(); |
| | | await setPayMethod(); |
| | | } catch (error) { |
| | | console.error('在登录或初始化过程中发生错误:', error); |
| | | // 可以在这里处理错误,比如显示错误消息给用户 |
| | | } |
| | | }); |
| | | |
| | | </script> |
| | | <template> |
| | |
| | | function reportLossApi(cardNumber) { |
| | | return util_request.request(`/waterCard/reportLoss?cardNumber=${cardNumber}`, {}, "GET"); |
| | | } |
| | | function removeCardApi(cardNumber) { |
| | | return util_request.request(`/waterCard/remove?cardNumber=${cardNumber}`, {}, "GET"); |
| | | function removeBindingApi(cardNumber) { |
| | | return util_request.request(`/waterCard/removeBinding?cardNumber=${cardNumber}`, {}, "GET"); |
| | | } |
| | | function infoBreakdownApi(data) { |
| | | return util_request.request("/waterFacilityMalfunction/create", data, "POST"); |
| | |
| | | exports.pointsSearchApi = pointsSearchApi; |
| | | exports.rechargeApi = rechargeApi; |
| | | exports.rechargeChangeApi = rechargeChangeApi; |
| | | exports.removeCardApi = removeCardApi; |
| | | exports.removeBindingApi = removeBindingApi; |
| | | exports.reportLossApi = reportLossApi; |
| | | exports.searchAddress = searchAddress; |
| | | exports.searchBreakdownApi = searchBreakdownApi; |
| | |
| | | cardInfo.value.userPhone = res.data.userInfo.userPhone; |
| | | cardInfo.value.id = res.data.userInfo.id; |
| | | await getVipInfo(); |
| | | console.log("00000", cardInfo.value); |
| | | console.log("用户信息响应", res); |
| | | console.log("用户信息", cardInfo.value); |
| | | common_vendor.index.setStorageSync("userInfo", JSON.stringify(cardInfo.value)); |
| | | } |
| | | }); |
| | |
| | | }); |
| | | } |
| | | const functionList = common_vendor.ref([ |
| | | //isUrl:1:页面跳转,2:弹窗功能,3:弹窗功能,4:未开发 |
| | | { text: "余额记录", icon: "../../static/images/index/icon31.png", bgColor: "#16b387", url: "/pages/functionList/balanceRecord/index", isUrl: 1 }, |
| | | { text: "消费记录", icon: "../../static/images/index/icon32.png", bgColor: "#329ae8", url: "/pages/functionList/paymentRecord/index", isUrl: 1 }, |
| | | { text: "充值记录", icon: "../../static/images/index/icon33.png", bgColor: "#f0a50e", url: "/pages/functionList/rechargeRecord/index", isUrl: 1 }, |
| | |
| | | content: "确认注销会员卡?", |
| | | success: async function(res) { |
| | | if (res.confirm) { |
| | | await api_index.removeCardApi(cardInfo.value.waterCardNumber).then(async (res2) => { |
| | | await api_index.removeBindingApi(cardInfo.value.waterCardNumber).then(async (res2) => { |
| | | if (res2.code == 200) { |
| | | common_vendor.index.showToast({ |
| | | title: "已注销", |
| | |
| | | } |
| | | }, |
| | | "compileType": "miniprogram", |
| | | "libVersion": "3.3.5", |
| | | "libVersion": "", |
| | | "appid": "wxe86c40810c2c0e98", |
| | | "projectname": "water-drinking-uniapp", |
| | | "condition": {}, |
| | |
| | | { |
| | | "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", |
| | | "projectname": "water-drinking-uniapp", |
| | | 0、- "setting": { |
| | | "compileHotReLoad": true |
| | | } |
| | | "libVersion": "3.6.6" |
| | | } |