From 12793f06cc56840b99047ed3be39c416bbdc9092 Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 24 Jul 2024 15:15:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9h5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 252 ++++++++++++++-------------- common/common.js | 65 ++++++-- main.js | 333 +++++++++++++++++++++---------------- manifest.json | 8 +- package/mine/equity.vue | 2 +- pages.json | 10 +- pages/mall/index.vue | 7 +- pages/sangdai/sangdai.vue | 99 +++++++++-- pages/shouye/index.vue | 22 ++- pages/user/bangdingweb.vue | 178 ++++++++++++++++++++ pages/user/login.vue | 74 ++++++++- pages/user/tui-guang.vue | 69 +++++++- 12 files changed, 811 insertions(+), 308 deletions(-) create mode 100644 pages/user/bangdingweb.vue diff --git a/App.vue b/App.vue index 27b579f..b81fc25 100644 --- a/App.vue +++ b/App.vue @@ -1,146 +1,156 @@ + /deep/.mescroll-upwarp { + box-sizing: border-box; + min-height: 55px; + padding: 15px 0; + text-align: center; + clear: both; + } + + /deep/.cmd-progress-outer { + line-height: 0; + + .cmd-progress-bg { + margin: 0 !important; + } + } + + .uni-tabbar__bd { + height: 50px !important; + } + + .uni-tabbar__icon { + height: 50px !important; + } + \ No newline at end of file diff --git a/common/common.js b/common/common.js index 7bf154e..7cb60e3 100644 --- a/common/common.js +++ b/common/common.js @@ -117,6 +117,43 @@ export default { */ wxMpPay({ provider = 'weixin', data }) { console.log('wxdata', data) + // #ifdef H5 + console.log('进入h5支付', data) + return new Promise((resolve, reject) => { + WeixinJSBridge.invoke( + 'getBrandWCPayRequest', data, + function (res) { + console.log('支付回调', res); + if (res.errMsg == 'requestPayment:fail cancel') { + uni.showToast({ + title: '取消支付', + icon: 'none', + duration: 500, + success: () => { + /* 取消订单 */ + } + }) + resolve('cancel') + } + if (res.err_msg == "get_brand_wcpay_request:ok") { + // 使用以上方式判断前端返回,微信团队郑重提示: + //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 + uni.showToast({ + title: '支付成功', + icon: 'success', + duration: 500, + success: () => { + resolve('success') + } + }) + } + + }); + + }) + + // #endif + // #ifdef MP-WEIXIN return new Promise((resolve, reject) => { uni.requestPayment({ provider, @@ -154,6 +191,8 @@ export default { } }) }) + + // #endif }, /** @@ -367,24 +406,24 @@ export default { */ filterText(val) { if (val) { - var replaceLbael = val.replace(/<[^>]+>/g,'') - return replaceLbael.replace(/ /ig,'') + var replaceLbael = val.replace(/<[^>]+>/g, '') + return replaceLbael.replace(/ /ig, '') } else { return '' } }, // 返回上一页 $navBack(num = 1, time = 0) { - // 页面返回 - setTimeout(() => { - uni.navigateBack({ - delta: num, - fail: () => { - uni.reLaunch({ - url: '/pages/shouye/index' - }) - } - }) - }, time * 1000) + // 页面返回 + setTimeout(() => { + uni.navigateBack({ + delta: num, + fail: () => { + uni.reLaunch({ + url: '/pages/shouye/index' + }) + } + }) + }, time * 1000) }, } diff --git a/main.js b/main.js index 0984daa..a2b4e64 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,9 @@ import App from './App' import Mixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js' // import uView from "uview-ui" -import { gotopage } from '@/common/gotopage.js' +import { + gotopage +} from '@/common/gotopage.js' // 配置公共方法 Vue.prototype.gotoPage = gotopage @@ -11,154 +13,197 @@ Vue.prototype.gotoPage = gotopage // 配置公共方法 import common from '@/common/common.js' Vue.prototype.$noMultipleClicks = common.noMultipleClicks -Vue.prototype.$c = common +Vue.prototype.$c = common; +// var loginPage="http://api.zpc-xy.com/login.html"; +var loginPage="http://api.zpc-xy.com/login.html"; +// var loginPage="https://xinglanmh.shequtuangou.vip/login.html"; +Vue.prototype.$loginPage = loginPage; +Vue.prototype.$wxloginPage =`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0e33d80d35e4a3b1&redirect_uri=${escape(loginPage)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`; +Vue.prototype.req = function(param, backpage, backtype) { + uni.getNetworkType({ + success: function(res) { + if (res.networkType == 'none') { + uni.showToast({ + title: '网络连接异常,请检查网络', + icon: 'none' + }) + return + } + } + }) + var _self = this, + url = param.url, + method = 'POST', + header = {}, + data = param.data || {}, + Loading = param.Loading || false -Vue.prototype.req = function (param, backpage, backtype) { - uni.getNetworkType({ - success: function (res) { - if (res.networkType == 'none') { - uni.showToast({ - title: '网络连接异常,请检查网络', - icon: 'none' - }) - return - } - } - }) - var _self = this, - url = param.url, - method = 'POST', - header = {}, - data = param.data || {}, - Loading = param.Loading || false + var token = uni.getStorageSync('token') + // 我 + // var token = 'bf3dd927642ea5a7a9ad90f1e1d1faab4d61cd33'; + // 客户 + // var token = '801abe6ec37a36b3ff37ded44be13c7bf06b629e'; + var client = ""; + // #ifdef H5 + client = "h5"; + // #endif + //拼接完整请求地址 + var requestUrl = this.siteBaseUrl + url + if (method) { + method = method.toUpperCase() //小写改为大写 + // console.log(token,11) + if (method == 'POST') { + header = { + 'content-type': 'application/x-www-form-urlencoded', + client: client, + token: token, + adid: uni.getStorageSync('_ad_id'), + clickid: uni.getStorageSync('_click_id'), - var token = uni.getStorageSync('token') - // 我 - // var token = 'bf3dd927642ea5a7a9ad90f1e1d1faab4d61cd33'; - // 客户 - // var token = '801abe6ec37a36b3ff37ded44be13c7bf06b629e'; + } - //拼接完整请求地址 - var requestUrl = this.siteBaseUrl + url - if (method) { - method = method.toUpperCase() //小写改为大写 - // console.log(token,11) - if (method == 'POST') { - header = { - 'content-type': 'application/x-www-form-urlencoded', - token: token, - adid: uni.getStorageSync('_ad_id'), - clickid: uni.getStorageSync('_click_id') - } + // if (uni.getStorageSync('_ad_id')) { + // header.adid = uni.getStorageSync('_ad_id') + // } + // if (uni.getStorageSync('_click_id')) { + // header.clickid = uni.getStorageSync('_click_id') + // } + } else { + header = { + 'content-type': 'application/json' + } + } + } else { + method = 'GET' + header = { + 'content-type': 'application/json' + } + } + //用户交互:加载圈 + // console.log(!Loading) + if (!Loading) { + uni.showLoading({ + title: '加载中...' + }) + } + //网络请求 - // if (uni.getStorageSync('_ad_id')) { - // header.adid = uni.getStorageSync('_ad_id') - // } - // if (uni.getStorageSync('_click_id')) { - // header.clickid = uni.getStorageSync('_click_id') - // } - } else { - header = { - 'content-type': 'application/json' - } - } - } else { - method = 'GET' - header = { - 'content-type': 'application/json' - } - } - //用户交互:加载圈 - // console.log(!Loading) - if (!Loading) { - uni.showLoading({ - title: '加载中...' - }) - } - //网络请求 + uni.request({ + url: requestUrl, + method: method, + header: header, + data: data, + success: res => { + // if (requestUrl.indexOf('coupon_ling') != -1) { + // uni.showModal({ + // title: '提示', + // content: JSON.stringify(res), + // showCancel: true, + // success: ({ confirm, cancel }) => {} + // }) + // } - uni.request({ - url: requestUrl, - method: method, - header: header, - data: data, - success: res => { - // if (requestUrl.indexOf('coupon_ling') != -1) { - // uni.showModal({ - // title: '提示', - // content: JSON.stringify(res), - // showCancel: true, - // success: ({ confirm, cancel }) => {} - // }) - // } + console.log("res.data.status", res.data.status) + if (res.data.status == 1) { + //返回结果码code判断:1成功,-1错误 + // uni.showToast({ + // title: res.data.msg, + // icon: 'none', + // }) + } else if (res.data.status == 2222) {} else if (res.data.status == -9) { + let pages = getCurrentPages() + console.log(pages[pages.length - 1].route) + // uni.setStorageSync('page', pages[pages.length - 1].route) + setTimeout(() => { + uni.showToast({ + title: res.data.msg, + icon: 'none', + success() { + setTimeout(() => { + // #ifdef H5 + uni.navigateTo({ + url: '/pages/user/bangdingweb' + }) + // #endif + // #ifdef MP-WEIXIN + uni.navigateTo({ + url: '/pages/user/bangding' + }) + // #endif - console.log("res.data.status",res.data.status) - if (res.data.status == 1) { - //返回结果码code判断:1成功,-1错误 - // uni.showToast({ - // title: res.data.msg, - // icon: 'none', - // }) - } else if (res.data.status == 2222) { - } else if (res.data.status == -9) { - let pages = getCurrentPages() - console.log(pages[pages.length - 1].route) - // uni.setStorageSync('page', pages[pages.length - 1].route) - setTimeout(() => { - uni.showToast({ - title: res.data.msg, - icon: 'none', - success() { - setTimeout(() => { - uni.navigateTo({ - url: '/pages/user/bangding' - }) - }, 1500) - } - }) - }, 100) - } else if (res.data.status == 0) { - setTimeout(function () { - uni.showToast({ - title: res.data.msg, - icon: 'none' - }) - }, 100) - } else if (res.data.status < 0) { - var pages = getCurrentPages() - for (var a = 0; a < pages.length; a++) { - console.log(pages[a].route) - if (pages[a].route == 'pages/user/index') { - uni.setStorageSync('lgurl', pages[a].route) - uni.setStorageSync('lgurldata', JSON.stringify(pages[a].options)) - } - } - setTimeout(() => { - uni.showToast({ - title: '请先登录', - icon: 'none' - }) - }, 100) - uni.redirectTo({ - url: '/pages/user/login' - }) - } else { - return - } - typeof param.success == 'function' && param.success(res.data) - }, - fail: e => { - console.log('网络请求fail:' + JSON.stringify(e)) - typeof param.fail == 'function' && param.fail(e.data) - }, - complete: () => { - uni.hideLoading() - typeof param.complete == 'function' && param.complete() - return - } - }) + }, 1500) + } + }) + }, 100) + } else if (res.data.status == 0) { + setTimeout(function() { + uni.showToast({ + title: res.data.msg, + icon: 'none' + }) + }, 100) + } else if (res.data.status < 0) { + var pages = getCurrentPages() + for (var a = 0; a < pages.length; a++) { + console.log(pages[a].route) + if (pages[a].route == 'pages/user/index') { + uni.setStorageSync('lgurl', pages[a].route) + uni.setStorageSync('lgurldata', JSON.stringify(pages[a].options)) + } + } + setTimeout(() => { + uni.showToast({ + title: '请先登录', + icon: 'none' + }) + }, 100) + uni.redirectTo({ + url: '/pages/user/login' + }) + } else { + return + } + typeof param.success == 'function' && param.success(res.data) + }, + fail: e => { + console.log('网络请求fail:' + JSON.stringify(e)) + typeof param.fail == 'function' && param.fail(e.data) + }, + complete: () => { + uni.hideLoading() + typeof param.complete == 'function' && param.complete() + return + } + }) +} +function loadScript(url) { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + document.head.appendChild(script); } +loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js'); + +Vue.prototype.onBridgeReady = function(data) { + var x = { + "appId": "wx2421b1c4370ec43b", //公众号ID,由商户传入 + "timeStamp": "1395712654", //时间戳,自1970年以来的秒数 + "nonceStr": "e61463f8efa94090b1f366cccfbbb444", //随机串 + "package": "prepay_id=u802345jgfjsdfgsdg888", + "signType": "MD5", //微信签名方式: + "paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名 + }; + WeixinJSBridge.invoke( + 'getBrandWCPayRequest', data, + function(res) { + console.log(res); + if (res.err_msg == "get_brand_wcpay_request:ok") { + // 使用以上方式判断前端返回,微信团队郑重提示: + //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 + } + }); +} // 测试 // const baseUrl = '' const baseUrl = 'http://101.43.1.207' @@ -168,9 +213,10 @@ const baseUrl = 'http://101.43.1.207' Vue.prototype.siteBaseUrl = baseUrl + '/api/' Vue.prototype.$z_img2 = baseUrl + '/zcq/' +Vue.prototype.$baseUrl = baseUrl Vue.prototype.$img = url => baseUrl + '/static/web' + url // Vue.prototype.$img1 = url => baseUrl + '/static/web' + url -Vue.prototype.$img1 = url => baseUrl+'/static/web/static/'+ url +Vue.prototype.$img1 = url => baseUrl + '/static/web/static/' + url Vue.prototype.$sys = () => uni.getSystemInfoSync() @@ -179,6 +225,7 @@ Vue.mixin(Mixin) App.mpType = 'app' const app = new Vue({ - ...App + ...App }) app.$mount() + diff --git a/manifest.json b/manifest.json index dd14e09..b64f6c9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "枫岚云赏", - "appid" : "__UNI__B7E0990", + "appid" : "__UNI__46B4383", "description" : "", "versionName" : "1.0.1", "versionCode" : 101, @@ -168,14 +168,16 @@ }, "h5" : { "router" : { - "mode" : "history" + "mode" : "hash", + "base" : "/h5/" }, "uniStatistics" : { "enable" : false }, "devServer" : { "https" : false - } + }, + "template" : "" }, "vueVersion" : "2", "mp-kuaishou" : { diff --git a/package/mine/equity.vue b/package/mine/equity.vue index f68a9bb..8df8e40 100644 --- a/package/mine/equity.vue +++ b/package/mine/equity.vue @@ -73,7 +73,7 @@ - + 领取 diff --git a/pages.json b/pages.json index 3d4dedc..2f9668e 100644 --- a/pages.json +++ b/pages.json @@ -402,6 +402,13 @@ "enablePullDownRefresh": false, "navigationStyle": "custom" } + }, + { + "path" : "pages/user/bangdingweb", + "style" : + { + "navigationBarTitleText" : "绑定手机号" + } } ], "subPackages": [{ @@ -487,7 +494,8 @@ "selectedColor": "#FFFFFF", "borderStyle": "black", "backgroundColor": "#111111", - "iconWidth": "60px", + "iconWidth": "140rpx", + // "iconHeight": "100rpx", "list": [{ "pagePath": "pages/shouye/index", "iconPath": "static/tabbar/m1.png", diff --git a/pages/mall/index.vue b/pages/mall/index.vue index dda9dd5..00f46bc 100644 --- a/pages/mall/index.vue +++ b/pages/mall/index.vue @@ -300,16 +300,19 @@ if (type == 1) { that.close('pop') - if (res.data.status == 1) { + const status = await that.$c.wxMpPay({ data: res.data.res }) - if (status == 'success') { // that.getPrize(res.data.order_num) that.getData(); } + + + + } else { that.$c.toast({ title: res.msg, diff --git a/pages/sangdai/sangdai.vue b/pages/sangdai/sangdai.vue index 49a3590..8e54a78 100644 --- a/pages/sangdai/sangdai.vue +++ b/pages/sangdai/sangdai.vue @@ -114,7 +114,8 @@ @@ -251,16 +252,16 @@ - + - + 我已满18岁,阅读并同意 - + 《用户协议》 - + 《隐私政策》 @@ -404,8 +405,8 @@ } }, onLoad() { - this.$nextTick(()=>{ - this.$refs.mescrollRef.mescroll.optUp.empty.tip='~ 快来抽赏吧 ~' + this.$nextTick(() => { + this.$refs.mescrollRef.mescroll.optUp.empty.tip = '~ 快来抽赏吧 ~' }) }, computed: { @@ -518,7 +519,70 @@ chooseAdd() { this.canReload = false + + var that=this; + // #ifdef H5 + this.req({ + url: 'getAccessTokenOffiaccountSign', + data: { + // recovery_info: JSON.stringify(data) + url: location.href.split('#')[0] + }, + success: res => { + console.log(res); + if (res.status == 1) { + var _data = res.data; + wx.config({ + debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 + appId: _data.appId, + timestamp: _data.timestamp, + nonceStr: _data.noncestr, + signature: _data.signature, + jsApiList: [ + 'checkJsApi', + 'openAddress', + ] + }); + wx.ready(function() { + wx.checkJsApi({ + jsApiList: [ + 'openAddress', + ], + success: function(res) { + // alert(res); + // console.log(res); + wx.openAddress({ + success: function(res) { + console.log(res); + that.addData = res; + // var userName = res.userName; // 收货人姓名 + // var postalCode = res.postalCode; // 邮编 + // var provinceName = res + // .provinceName; // 国标收货地址第一级地址(省) + // var cityName = res.cityName; // 国标收货地址第二级地址(市) + // var countryName = res + // .countryName; // 国标收货地址第三级地址(国家) + // var detailInfo = res.detailInfo; // 详细收货地址信息 + // var nationalCode = res.nationalCode; // 收货地址国家码 + // var telNumber = res.telNumber; // 收货人手机号码 + } + }); + } + }); + + + }); + wx.error(function(res) { + // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 + console.log("出现错误", res); + }); + } + } + }) + // #endif + + // #ifdef MP-WEIXIN uni.chooseAddress({ success: res => { console.log(res) @@ -534,6 +598,8 @@ }, 500) } }) + // #endif + }, submitLock() { @@ -573,7 +639,7 @@ }, submitSend() { - if(!this.isAgree) { + if (!this.isAgree) { this.$c.toast({ title: '请阅读并同意《用户协议》《隐私政策》' }) @@ -1022,7 +1088,8 @@ font-weight: 400; color: #ffffff; } - .yu-tag{ + + .yu-tag { position: absolute; right: 10rpx; bottom: 30rpx; @@ -1214,7 +1281,8 @@ bottom: var(--window-bottom); // #endif // #ifdef MP - bottom: calc(var(--window-bottom) + 160rpx);; + bottom: calc(var(--window-bottom) + 160rpx); + ; // #endif width: 750rpx; box-sizing: border-box; @@ -1644,6 +1712,7 @@ } } } + .agree { display: flex; margin-top: 30rpx; @@ -1651,7 +1720,7 @@ font-weight: 400; color: #ffffff; line-height: 32rpx; - + .icon { width: 32rpx; height: 32rpx; @@ -1672,7 +1741,8 @@ justify-content: center; font-weight: 500; color: #7825DE; - >text:nth-child(1){ + + >text:nth-child(1) { font-size: 28rpx; margin-top: 32rpx; } @@ -1742,7 +1812,7 @@ height: 100vh; position: relative; background: url($imgurl+'common/yb.png') no-repeat 0 0 / 100% 100%; - + .res-pop-hd { width: 380rpx; height: 104rpx; @@ -1785,7 +1855,8 @@ margin: 112rpx auto 0; box-sizing: border-box; background: url($imgurl+'common/jixuchou.png') no-repeat 0 0 / 100% 100%; - >text{ + + >text { color: #7825DE; margin-top: 28rpx; } diff --git a/pages/shouye/index.vue b/pages/shouye/index.vue index 49fd0c3..ce6e3e4 100644 --- a/pages/shouye/index.vue +++ b/pages/shouye/index.vue @@ -10,8 +10,10 @@ - - + + @@ -19,9 +21,11 @@ - + - + @@ -162,11 +166,15 @@ id: 9, title: '枫岚赏' }, - + { id: 8, title: '领主赏' }, + { + id: 12, + title: '冲冲赏' + }, // { // id: 3, // title: '擂台赏' @@ -1101,8 +1109,8 @@ } .group-fixed { - width: 164rpx; - height: 164rpx; + width: 141rpx; + height: 50rpx; position: fixed; z-index: 10; right: 0; diff --git a/pages/user/bangdingweb.vue b/pages/user/bangdingweb.vue new file mode 100644 index 0000000..cb16f14 --- /dev/null +++ b/pages/user/bangdingweb.vue @@ -0,0 +1,178 @@ + + + + + \ No newline at end of file diff --git a/pages/user/login.vue b/pages/user/login.vue index 7174224..6003e1b 100644 --- a/pages/user/login.vue +++ b/pages/user/login.vue @@ -72,9 +72,16 @@ isAgree: false } }, - onLoad() { + onLoad(option) { //默认加载 // this.login(); + console.log(window.location.href, option); + if (option != null) { + if (option.code != null) { + //登录 + this.h5Login(option.code); + } + } }, methods: { //第一授权获取用户信息===》按钮触发 @@ -84,7 +91,16 @@ title: '请阅读并同意《用户协议》和《隐私政策》' }) } + // #ifdef H5 + this.h5UserProfile(); + // #endif + // #ifdef MP-WEIXIN + this.wxUserProfile(); + // #endif + + }, + wxUserProfile() { var that = this uni.getUserProfile({ desc: '用于向用户发送商品', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 @@ -136,7 +152,7 @@ }) }, complete: (e) => { - console.log(e,'登录'); + console.log(e, '登录'); } }) }, @@ -144,6 +160,60 @@ console.log(e, '用于向用户发送商品'); } }) + + }, + h5Login(code) { + var that = this; + that.req({ + url: 'h5login', + data: { + code: code, + pid: uni.getStorageSync('pid') + }, + success: function(res) { + if (res.status == 1) { + uni.setStorageSync('token', res.data) + var lgurl = uni.getStorageSync( + 'lgurl') //获取页面路径 + var lgdata = uni.getStorageSync( + 'lgurldata') //获取页面参数 + if (lgurl) { + lgdata = JSON.parse(lgdata) + // 拼接参数 + let param = '' + for (let key in lgdata) { + param += '&' + key + '=' + lgdata[ + key] + } + param = '/' + lgurl + param.replace( + '&', '?') + uni.setStorageSync('lgurl', '') + uni.setStorageSync('lgurldata', '') + console.log(param) + setTimeout(() => { + uni.reLaunch({ + url: param + }) + }, 1000) + } else { + uni.reLaunch({ + url: 'index' + }) + } + } + } + }) + }, + h5UserProfile() { + var that = this; + console.log('进入h5') + //http://api.zpc-xy.com/login.html + //http://192.168.195.30:8080/#/pages/user/login?code=021gjuFa1F8OOH0uLeJa1T5fMh4gjuFA&state=STATE + //http://192.168.195.30:8080/pages/user/login pages/user/wxlogin + + // var redirect_uri = escape(this.$loginPage); + window.location.href =this.$wxloginPage; + // `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0e33d80d35e4a3b1&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`; } } } diff --git a/pages/user/tui-guang.vue b/pages/user/tui-guang.vue index 29f78a0..0c3b2e9 100644 --- a/pages/user/tui-guang.vue +++ b/pages/user/tui-guang.vue @@ -35,7 +35,8 @@ - + + @@ -72,6 +73,10 @@