diff --git a/src/App.vue b/src/App.vue index 430980b..15b6237 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,8 +4,8 @@ import useQuestionStore from '@/jtools/store/question' //引入store export default { onLaunch: function () { useUserStore().queryVipList() + useQuestionStore().getOrderQuestion('1') if(useUserStore().isLogin) { - useQuestionStore().getOrderQuestion('1') useUserStore().getUserInfo() useUserStore().searchUserVip() } diff --git a/src/jtools/api/pay.js b/src/jtools/api/pay.js new file mode 100644 index 0000000..db41130 --- /dev/null +++ b/src/jtools/api/pay.js @@ -0,0 +1,9 @@ +import request from '../request/index.js'; + +export function prePay(data) { + return request({ + url: 'driver-api/applet/pay/prepay', + method: 'POST', + data, + }); +} \ No newline at end of file diff --git a/src/jtools/pay/index.js b/src/jtools/pay/index.js index be3afa3..7156f57 100644 --- a/src/jtools/pay/index.js +++ b/src/jtools/pay/index.js @@ -1,10 +1,10 @@ import request from '../request/index.js'; // #ifdef H5 -import wxsdk from '@/jtools/wechat/sdk' +// import wxsdk from '@/jtools/wechat/sdk' // #endif -import wechat from '@/jtools/wechat/wechat' +// import wechat from '@/jtools/wechat/wechat' import $platform from '@/jtools/platform'; - +import {prePay} from '@/jtools/api/pay' /** * 支付 * @@ -16,150 +16,142 @@ import $platform from '@/jtools/platform'; export default class JtoolsPay { - // wxOfficialAccount wxMiniProgram App H5 - // wechat 公众号JSSDK支付 小程序支付 微信开放平台支付 H5网页支付 - // alipay 复制网址 复制网址 支付宝开放平台支付 直接跳转链接 - // wallet v v v v - - - constructor(payment, order, orderType) { - this.payment = payment; - this.order = order; - this.orderType = orderType; - this.platform = $platform.get(); - let payMehod = this.getPayMethod(); - payMehod(); - - } - - getPayMethod() { - var payMethod = { - 'wxMiniProgram': { - 'wechat': () => { - this.wxMiniProgramPay() - }, - }, - 'App': { - 'wechat': () => { - this.wechatPay() - }, - 'alipay': () => { - this.aliPay() - }, - }, - } - return payMethod[this.platform][this.payment]; - } - - - - // 预支付 - prepay() { - let that = this; - return new Promise((resolve, reject) => { - const p = $platform.device() - const tradeInfoType = p == 'android' ? 'Android' : p == 'ios' ? 'iOS' : 'Wap' - let params = { - orderId: this.order.orderId, - orderPayType: this.order.orderPayType, - money: this.order.money, - microServiceName: this.order.microServiceName, - prepayParamUrl: this.order.prepayParamUrl, - paymentType: 'weChatPay', - payType: 'JSAPI', - tradeInfoType: tradeInfoType, - tenantId: '-1', - clientType: 'miniWx' - } - if (uni.getStorageSync('openId')) { - params.openId = uni.getStorageSync('openId'); - } - request({ - url: 'driver-api/applet/pay/prepay', - method: 'POST', - param, - }).then(res => { - if (res.code == 'SUCCESS') { + // wxOfficialAccount wxMiniProgram App H5 + // wechat 公众号JSSDK支付 小程序支付 微信开放平台支付 H5网页支付 + // alipay 复制网址 复制网址 支付宝开放平台支付 直接跳转链接 + // wallet v v v v + + + constructor(payment, order, orderType) { + this.payment = payment; + this.order = order; + this.orderType = orderType; + this.platform = $platform.get(); + let payMehod = this.getPayMethod(); + payMehod(); + + } + + getPayMethod() { + var payMethod = { + 'wxMiniProgram': { + 'wechat': () => { + this.wxMiniProgramPay() + }, + }, + 'App': { + 'wechat': () => { + this.wechatPay() + }, + 'alipay': () => { + this.aliPay() + }, + }, + } + return payMethod[this.platform][this.payment]; + } + + + + // 预支付 + prepay() { + let that = this; + return new Promise((resolve, reject) => { + const p = $platform.device() + const tradeInfoType = p == 'android' ? 'Android' : p == 'ios' ? 'iOS' : 'Wap' + let params = { + "code":this.order.code, + "description": this.order.description, + "money": this.order.money, + "outTradeNo": this.order.outTradeNo, + "userId": this.order.userId + } + if (uni.getStorageSync('openId')) { + params.openId = uni.getStorageSync('openId'); + } + prePay(params).then(res => { + if (res.code == '0000') { resolve(res); } }) - }); - } - - - // 微信小程序支付 - async wxMiniProgramPay() { - let that = this; - let result = await this.prepay(); - const params = result.data.jsApiResult - uni.requestPayment({ - provider: 'wxpay', - ...{ - appId: params.appId, //公众号名称,由商户传入 - timeStamp: params.timestamp, //时间戳,自1970年以来的秒数 - nonceStr: params.nonceStr, //随机串 - package: `prepay_id=${params.prepay_id}`, - signType: params.signType, //微信签名方式: - paySign: params.paySign, //微信签名 - }, - success: res => { - that.payResult('success', result.data.orderPayNo) - }, - fail: err => { - console.log('支付取消或者失败:', err); - err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') - } - }); - } - - - - // 支付宝支付 - async aliPay() { - let that = this; - let result = await this.prepay(); - if (result.code === 1) { - uni.requestPayment({ - provider: 'alipay', - orderInfo: result.data.pay_data, //支付宝订单数据 - success: res => { - that.payResult('success') - }, - fail: err => { - console.log('支付取消或者失败:', err); - err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') - } - }); - } - } - - // 微信支付 - async wechatPay() { - let that = this; - let result = await this.prepay(); - if (result.code === 1) { - uni.requestPayment({ - provider: 'wxpay', - orderInfo: JSON.parse(result.data.pay_data), //微信订单数据(官方说是string。实测为object) - success: res => { - that.payResult('success') - }, - fail: err => { - err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') - console.log('支付取消或者失败:', err); - } - }); - } - } - - - // 支付结果跳转,success:成功,fail:失败 - payResult(resultType, orderPayNo) { - const that = this; - let path = '' + }); + } + + + // 微信小程序支付 + async wxMiniProgramPay() { + let that = this; + let result = await this.prepay(); + const params = result.data + uni.requestPayment({ + provider: 'wxpay', + ...{ + appId: params.appId, //公众号名称,由商户传入 + timeStamp: params.timeStamp, //时间戳,自1970年以来的秒数 + nonceStr: params.nonceStr, //随机串 + package: params.packageVal, + signType: params.signType, //微信签名方式: + paySign: params.paySign, //微信签名 + }, + success: res => { + console.log(res); + that.payResult('success', result.data.orderPayNo) + }, + fail: err => { + console.log('支付取消或者失败:', err); + err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') + } + }); + } + + + + // 支付宝支付 + async aliPay() { + let that = this; + let result = await this.prepay(); + if (result.code === 1) { + uni.requestPayment({ + provider: 'alipay', + orderInfo: result.data.pay_data, //支付宝订单数据 + success: res => { + that.payResult('success') + }, + fail: err => { + err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') + } + }); + } + } + + // 微信支付 + async wechatPay() { + let that = this; + let result = await this.prepay(); + console.log('微信支付'); + if (result.code === 1) { + uni.requestPayment({ + provider: 'wxpay', + orderInfo: JSON.parse(result.data.pay_data), //微信订单数据(官方说是string。实测为object) + success: res => { + that.payResult('success') + }, + fail: err => { + err.errMsg !== "requestPayment:fail cancel" && that.payResult('fail') + console.log('支付取消或者失败:', err); + } + }); + } + } + + + // 支付结果跳转,success:成功,fail:失败 + payResult(resultType, orderPayNo) { + const that = this; + let path = 'paySuccess' uni.navigateTo({ - url:path + url: path }) - } + } -} +} \ No newline at end of file diff --git a/src/jtools/store/question.js b/src/jtools/store/question.js index 20ffec6..ac374c7 100644 --- a/src/jtools/store/question.js +++ b/src/jtools/store/question.js @@ -21,10 +21,27 @@ const question = defineStore({ getOrderQuestion(val) { queryQuestion({ carTypeId: this.currentCartype, - subject: val + subject: val, + // questionIdList:[10982,10983,10985,10986] }).then(res => { if (res.code == '0000') { this.orderQuestion = res.data + const falseList =storage.get(`wrongList_subject${val}`) || [] + const trueList =storage.get(`rightList_subject${val}`) || [] + const falseArr=[] + const rightArr=[] + this.orderQuestion.forEach(item=>{ + if(falseList.includes(item.questionId)){ + falseArr.push(item.questionId) + } + if(trueList.includes(item.questionId)){ + rightArr.push(item.questionId) + } + }) + console.log('falseArr',falseArr); + storage.set(`wrongList_subject${val}`,falseArr) + storage.set(`rightList_subject${val}`,rightArr) + console.log(storage.get(`wrongList_subject${val}`)); } }) }, diff --git a/src/jtools/wechat/wechat.js b/src/jtools/wechat/wechat.js new file mode 100644 index 0000000..c2f5cf4 --- /dev/null +++ b/src/jtools/wechat/wechat.js @@ -0,0 +1,261 @@ +/** + * Wechat v1.1.0 + * @Class Wechat + * @description jtools-wechat 1.1.0 wehcat第三方登录组件 + * @Author lidongtony + * @Date 2020-05-20 + * @Email lidongtony@qq.com + */ +import api from "@/jtools/request/index"; +import $platform from "@/jtools/platform"; +import store from "@/jtools/store"; +import { + API_URL +} from "@/env"; + +export default { + eventMap(event) { + let map = ""; + switch (event) { + case "login": + map = "登录中..."; + break; + case "refresh": + map = "更新中..."; + break; + case "bind": + map = "绑定中..."; + break; + } + return map; + }, + + async login() { + let token = ""; + // #ifdef MP-WEIXIN + token = await this.wxMiniProgramOauth("login"); + return token; + // #endif + // #ifdef H5 + this.wxOfficialAccountOauth("login"); + // #endif + // #ifdef APP-PLUS + token = await this.wxOpenPlatformOauth("login"); + return token; + // #endif + }, + async refresh() { + let token = ""; + // #ifdef MP-WEIXIN + token = await this.wxMiniProgramOauth("refresh"); + return token; + // #endif + // #ifdef H5 + this.wxOfficialAccountOauth("refresh"); + // #endif + // #ifdef APP-PLUS + token = await this.wxOpenPlatformOauth("refresh"); + return token; + // #endif + }, + async bind() { + let token = ""; + // #ifdef MP-WEIXIN + token = await this.wxMiniProgramOauth("bind"); + return token; + // #endif + // #ifdef H5 + this.wxOfficialAccountOauth("bind"); + // #endif + // #ifdef APP-PLUS + token = await this.wxOpenPlatformOauth("bind"); + return token; + // #endif + }, + + // #ifdef H5 + // 微信公众号网页登录&刷新头像昵称&绑定 + wxOfficialAccountOauth(event = "login") { + if ($platform.get() !== "wxOfficialAccount") { + uni.showToast({ + title: "请在微信浏览器中打开", + icon: "none" + }); + throw false; + } + let host = $platform.host(); + let payloadObject = { + host: host, + event, + token: (event !== "login" && store.getters.isLogin) ? uni.getStorageSync("token") : "" + }; + let payload = encodeURIComponent(JSON.stringify(payloadObject)); + let redirect_uri = encodeURIComponent(`${API_URL}user/wxOfficialAccountOauth?payload=${payload}`); + let oauthUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + store.getters.initWechat.appid + + `&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=1`; + uni.setStorageSync("lastPage", window.location.href); + window.location = oauthUrl; + }, + + // 微信公众号网页静默登录:临时登录获取OpenId 不入库不绑定用户 + wxOfficialAccountBaseLogin() { + let state = encodeURIComponent(window.location.href); + window.location = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + store.getters.initWechat.appid + + `&redirect_uri=${API_URL}user/wxOfficialAccountBaseLogin&response_type=code&scope=snsapi_base&state=${state}`; + throw "stop"; + }, + // #endif + + // #ifdef APP-PLUS + // 微信开放平台登录 + wxOpenPlatformOauth(event = "login") { + let that = this; + return new Promise((resolve, reject) => { + uni.login({ + provider: "weixin", + success: function(loginRes) { + if (loginRes.errMsg === "login:ok") { + let authResult = loginRes.authResult; + api("user.wxOpenPlatformOauth", { + authResult, + event + }, that.eventMap(event)).then(res => { + if (res.code === 1) { + resolve(res.data.token); + } else { + resolve(false); + } + }); + } + }, + fail: function(res) { + uni.showToast({ + title: "登录失败,请稍后再试" + }); + resolve(false); + api("common.debug", { + info: res + }); + }, + complete: function(res) {} + }); + }); + }, + // #endif + + // #ifdef MP-WEIXIN + // 微信小程序静默登录 + async getWxMiniProgramSessionKey(autoLogin = true) { + let sessionStatus = false; + let session_key = ""; + return new Promise((resolve, reject) => { + uni.checkSession({ + success(res) { + if (res.errMsg === "checkSession:ok") sessionStatus = true; + }, + complete() { + if (uni.getStorageSync("session_key") && sessionStatus && !autoLogin) { + resolve(uni.getStorageSync("session_key")); + } else { + uni.login({ + success: function(info) { + let code = info.code; + api("user.getWxMiniProgramSessionKey", { + code: code, + autoLogin: autoLogin + }).then(res => { + if (res.code === 1) { + uni.setStorageSync("session_key", res + .data.session_key); + if (autoLogin) { + if (res.data.token) { + resolve(res.data.token); + } else { + resolve(false); + } + } + resolve(res.data.session_key); + } else { + reject(res.msg); + } + }); + } + }); + } + } + }); + }); + }, + + // 微信小程序获取用户信息登录 + wxMiniProgramOauth(event = "login") { + let that = this; + let session_key = uni.getStorageSync("session_key"); + uni.showLoading({ + title: that.eventMap(event) + }); + return new Promise((resolve, reject) => { + uni.getUserProfile({ // 必须手动确认触发 + desc: "完善会员资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: res => { + if (res.errMsg === "getUserProfile:ok") { + api("user.wxMiniProgramOauth", { + event, + session_key, + encryptedData: res.encryptedData, + iv: res.iv, + signature: res.signature, + }).then(res => { + console.log(res) + if (res.code === 1) { + resolve(res.data.token); + } else { + uni.removeStorageSync("session_key"); + that.getWxMiniProgramSessionKey(false); + resolve(false); + } + }); + } + }, + complete: res => { + uni.hideLoading(); + } + }); + }); + + }, + + // 小程序更新 + checkMiniProgramUpdate() { + if (uni.canIUse("getUpdateManager")) { + const updateManager = uni.getUpdateManager(); + updateManager.onCheckForUpdate(function(res) { + // 请求完新版本信息的回调 + if (res.hasUpdate) { + updateManager.onUpdateReady(function() { + uni.showModal({ + title: "更新提示", + content: "新版本已经准备好,是否重启应用?", + success: function(res) { + if (res.confirm) { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate(); + } + } + }); + }); + updateManager.onUpdateFailed(function() { + // 新的版本下载失败 + uni.showModal({ + title: "已经有新版本了哟~", + content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~" + }); + }); + } + }); + } + }, + // #endif + + +}; diff --git a/src/pages.json b/src/pages.json index bd9bae1..efff1f5 100644 --- a/src/pages.json +++ b/src/pages.json @@ -131,6 +131,13 @@ "navigationBarTitleText": "考场实况", "enablePullDownRefresh": false } + }, + { + "path": "pages/index/paySuccess", + "style": { + "navigationBarTitleText": "支付结果", + "enablePullDownRefresh": false + } } ], diff --git a/src/pages/index/components/Subject1.vue b/src/pages/index/components/Subject1.vue index b5f4d22..d8241f0 100644 --- a/src/pages/index/components/Subject1.vue +++ b/src/pages/index/components/Subject1.vue @@ -8,7 +8,7 @@ 顺序练习 - {{rightList.length+wrongList.length}}/{{orderQuestion.length}} + {{getDoNum}}/{{orderQuestion.length}} @@ -103,20 +103,27 @@ props:{ subject:{ type:[String,Number], + }, + rightList:{ + type:Array + }, + wrongList:{ + type:Array } }, data() { return { - rightList:storage.get(`rightList_subject${this.subject}`) || [], - wrongList:storage.get(`wrongList_subject${this.subject}`) || [], allQuestionNum:0, } }, - onLoad(){ - // this.allQuestionNum=useQuestionStore().orderQuestion.length + mounted(){ + }, computed: { - ...mapState(useQuestionStore, ["orderQuestion"]) //映射函数,取出tagslist + ...mapState(useQuestionStore, ["orderQuestion"]) ,//映射函数,取出tagslist + getDoNum(){ + return this.rightList.length+this.wrongList.length + } }, methods: { toTestRoom(){ diff --git a/src/pages/index/components/Subject2.vue b/src/pages/index/components/Subject2.vue index 7fe8f7b..3c4ccc4 100644 --- a/src/pages/index/components/Subject2.vue +++ b/src/pages/index/components/Subject2.vue @@ -9,17 +9,17 @@ - 科二考试项目讲解 + 科{{subject=='2'?'二':'三'}}考试项目讲解 - {{diverTypeList[diverTypeIndex].configItemName}} + {{diverTypeList[diverTypeIndex]?.configItemName}} - {{item.description}} + {{item.description}} - - + + @@ -52,6 +52,7 @@ export default { diverTypeIndex:0, diverTypeList:[], videoIndex:0, + projectId:undefined, operateList:[] } }, @@ -59,17 +60,20 @@ export default { await this.getDiverType() }, methods:{ + toVideo(){ + uni.navigateTo({ + url:"/pages/questionBank/videoDetail?driveType="+this.diverTypeList[this.diverTypeIndex].configItemCode+"&subject="+this.subject+"&projectId="+this.projectId+"&type=1" + }) + }, getVideoList(){ - console.log('index',this.diverTypeIndex); - console.log(this.diverTypeList[this.diverTypeIndex]); queryProjectList({ "carTypeId": storage.get('carType') || '1001', "driveType": this.diverTypeList[this.diverTypeIndex].configItemCode, "subject": String(this.subject), - "projectId":'1001', "type": "1" }).then(resp=>{ this.operateList=resp.data + this.projectId=this.operateList[0]?.projectId }) }, getDiverType(){ @@ -86,6 +90,8 @@ export default { this.getVideoList() }, checkVideo(val){ + console.log(val); + this.projectId=this.operateList[val]?.projectId this.videoIndex=val }, toDetail(){ diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index e450db4..798d172 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -5,7 +5,7 @@ diff --git a/src/pages/questionBank/exclusiveExercise.vue b/src/pages/questionBank/exclusiveExercise.vue index 0da9802..e031414 100644 --- a/src/pages/questionBank/exclusiveExercise.vue +++ b/src/pages/questionBank/exclusiveExercise.vue @@ -31,9 +31,9 @@ 常见考点 - + {{index+1}} - {{item.label}} + {{item.configItemName}} @@ -44,6 +44,10 @@ import errorIcon from "../../static/image/practice/error_icon.png" import newRulesIcon from "../../static/image/practice/newRules_icon.png" import neverWriteIcon from "../../static/image/practice/neverWrite_icon.png" + import { + querySysConfigList, + } from '@/jtools/api/question'; + import storage from '@/jtools/storage'; export default { data() { return { @@ -75,23 +79,31 @@ subTitle:'392题', image:neverWriteIcon }], - testCenterList:[ - {label:'驾驶证申请相关'}, - {label:'驾驶证申请相关'}, - {label:'驾驶证登记处罚'}, - {label:'机动车强制报废'}, - {label:'其他考点'}, - {label:'驾驶证登记处罚'}, - {label:'机动车强制报废'}, - {label:'其他考点'}] + testCenterList:[] } }, + onLoad(){ + this.getExamPoint() + }, methods: { + getExamPoint(){ + const carTypeId=storage.get('carType') || '1001' + querySysConfigList(carTypeId,'ExamKeys').then(resp=>{ + if(resp.code==='0000'){ + this.testCenterList=resp.data + } + }) + }, toAnswer(title) { uni.navigateTo({ url:"/pages/questionBank/questionBank?navTitle="+title }) }, + toQuestionBank(val){ + uni.navigateTo({ + url:"/pages/questionBank/questionBank?navTitle="+val.configItemName+"&examKey="+val.configItemCode + }) + }, toIconSkill(){ uni.navigateTo({ url:"/pages/index/iconSkill" diff --git a/src/pages/questionBank/practiceResult.vue b/src/pages/questionBank/practiceResult.vue index 1b900f0..cca8dbd 100644 --- a/src/pages/questionBank/practiceResult.vue +++ b/src/pages/questionBank/practiceResult.vue @@ -5,8 +5,9 @@ - - 太棒了!正确率很高了! + + 太棒了!正确率很高了! + 继续努力吧,正确率有点低~ {{wrongList.length}}/{{allDoNum}} @@ -25,7 +26,7 @@ 累计练题 - 33题 + {{allRightList.length+allWrongList.length}}题 未做题{{getNotDoNum}}题 @@ -80,7 +81,7 @@ } if(op.wrongList){ this.wrongList=JSON.parse(op.wrongList) - this.rightPencent=((this.allDoNum-this.wrongList.length)/this.allDoNum).toFixed(2) + this.rightPencent=this.allDoNum>0?((this.allDoNum-this.wrongList.length)/this.allDoNum).toFixed(2):0 this.rightPencentDesc=(this.rightPencent*100).toFixed(0)+'%' } if(op.subject){ diff --git a/src/pages/questionBank/questionBank.vue b/src/pages/questionBank/questionBank.vue index 668d572..a489e5e 100644 --- a/src/pages/questionBank/questionBank.vue +++ b/src/pages/questionBank/questionBank.vue @@ -75,6 +75,9 @@ if(op.chapter){ param.chapter=op.chapter } + if(op.examKey){ + param.examKey=op.examKey + } queryQuestion(param).then(res => { if (res.code == '0000') { this.questionArr = res.data diff --git a/src/pages/questionBank/videoDetail.vue b/src/pages/questionBank/videoDetail.vue index a463c08..470b48c 100644 --- a/src/pages/questionBank/videoDetail.vue +++ b/src/pages/questionBank/videoDetail.vue @@ -1,13 +1,16 @@