diff --git a/App.vue b/App.vue index fc60e8b..7eb9ac2 100644 --- a/App.vue +++ b/App.vue @@ -22,7 +22,9 @@ } } import store from '@/store/index'; - import { HTTP_REQUEST_URL } from '@/config/app.js' + import { HTTP_REQUEST_URL } from '@/config/app.js' + import { mapMutations} from 'vuex' + import { spread } from '@/request/restaurant/index.js' export default { globalData: { // FPT上传地址 @@ -37,10 +39,9 @@ // } // }, parameters: {} - }, + }, + onLaunch: function(parameters = {}) { - - console.log(navigator.userAgent,'userAgent'); // 动态构建script标签,用于引入wxjs文件 var script = document.createElement('script'); script.src = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js"; @@ -48,7 +49,19 @@ // 为适配旧版本项目代码中的取参逻辑此处为迭代后新版本传参并整合为旧版本参数格式 let basurl = uri(decodeURIComponent(window.location.href)) let querys = basurl.query(true); - console.log(querys,'querys'); + if (querys.token) { + store.commit('SETTOKEN', 'Bearer ' + querys.token); + } + + // 锁粉?后的 + if (querys.spread) { + setTimeout(() => { + spread({ puid: querys.spread, code: 0 }).then(res => { + console.log(res) + }) + }, 1000) + }; + if(Object.keys(querys)['length'] > 0){ if(querys?.para){ // 获取URL参数 @@ -61,10 +74,8 @@ // 参数初始化处理 if (typeof _para == 'object' && _para['para'] != undefined) { - console.log('存在参数'); // URL参数 var URLpara = decodeURIComponent(getUrlParams(window.location.href)['para']); - console.log(JSON.parse(URLpara),'*****'); try{ // 转换过来的URL参数为一个JSON字符串其中存在一个#/字符,直接使用JSON.parse会报错,所以将#/截取出来 var _r = URLpara.substr(0, URLpara.lastIndexOf("#/")); @@ -88,16 +99,37 @@ console.log(JSON.stringify(this['globalData']['parameters'],null,10), 'App Launch'); - }else{ - for(let key in querys){ - console.log(querys); - querys[key] = JSON.parse(querys[key]) - }; - this['globalData']['parameters'] = { ...querys['userinfor'], ...querys['query'], timestamp:querys['timestamp']} - // 小程序首页会直接进入店铺首页,首页无赋值店铺信息逻辑所再次处进入之后赋值 - if(this['globalData']['parameters']?.brand_id && typeof this['globalData']['parameters']['brand_id'] != 'undefined' && typeof this['globalData']['parameters']['brand_id'] != undefined && this['globalData']['parameters']?.brand_name && typeof this['globalData']['parameters']['brand_name'] != 'undefined' && typeof this['globalData']['parameters']['brand_name'] != undefined){ - store.commit('shopping/SETBRANDINFOR', { brand_id: this['globalData']['parameters']['brand_id'], brand_name:decodeURIComponent(this['globalData']['parameters']['brand_name'])}); + }else{ + console.log('存在参数1997', !querys.token) + if (!querys.token) { + for(let key in querys){ + const value = querys[key]; + querys[key] = JSON.parse(value); + } + } + this['globalData']['parameters'] = { ...querys['userinfor'], ...querys['query'], timestamp:querys['timestamp']}; + + if (this['globalData']['parameters']['query']) { + store.commit('shopping/SETBRANDINFOR', { brand_id: this['globalData']['parameters']['query']['brand_id'], brand_name:decodeURIComponent(this['globalData']['parameters']['query']['brand_name'])}); + store.commit('shopping/SETSHOPDETAIL', { + city_name: this['globalData']['parameters'].cityInfor.city, + is_open: 1, + latitude: this['globalData']['parameters']['cityInfor'].lat, + longitude: this['globalData']['parameters']['cityInfor'].lng, + province_name: this['globalData']['parameters']['cityInfor'].province, + regoin_name: null, + restaurant_address: this['globalData']['parameters']['query'].restaurant_address, + restaurant_id: this['globalData']['parameters']['query'].restaurant_id, + restaurant_name: this['globalData']['parameters']['query'].restaurant_name, + special: false, + distance: this['globalData']['parameters']['query'].distance + }) + } + + // 小程序首页会直接进入店铺首页,首页无赋值店铺信息逻辑所再次处进入之后赋值 + if(this['globalData']['parameters']?.brand_id){ + store.commit('shopping/SETBRANDINFOR', { brand_id: this['globalData']['parameters']['brand_id'], brand_name:decodeURIComponent(this['globalData']['parameters']['brand_name'])}); // 设置店铺信息JIN store.commit('shopping/SETSHOPDETAIL', { city_name: this['globalData']['parameters'].cityInfor.city, @@ -113,11 +145,13 @@ special: false, distance: this['globalData']['parameters'].distance }) - }; + console.log(333333333333333333333333333333) + store.commit('SETTOKEN', this['globalData']['parameters']['token']); + }; } - }; - console.log(this['globalData']['parameters'],'测试取参'); + console.log(this['globalData']['parameters']['spread'],'测试取参'); + this.SETSPREAD(this['globalData']['parameters']['spread']); this.clearUrlParams(); return; @@ -142,54 +176,70 @@ }, methods: { + ...mapMutations({ + SETSPREAD:'SETSPREAD', + SETTOKEN: 'SETTOKEN' + }), + getParams(url) { + const searchParams = new URLSearchParams(url.split("?")[1]); + const params = {}; + for (const [key, value] of searchParams.entries()) { + params[key] = value; + } + return params; + }, clearUrlParams() { // 存储分享链接 - // let basurl = uri(decodeURIComponent(window.location.href)) - // let querys = basurl.query(true); - // for(let key in querys){ - // querys[key] = JSON.parse(querys[key]) - // }; - // let parameters = { ...querys['userinfor'], ...querys['query']}; - // parameters.token = ''; + let basurl = uri(decodeURIComponent(window.location.href)) + let querys = basurl.query(true); + if (querys.token) return; // 从分享进入的 - // const safeDecode = (value) => { - // if (value == null) return ''; // 默认空值 - // try { - // return typeof value === 'string' ? decodeURIComponent(value) : value; - // } catch { - // return value; // 解码失败返回原值 - // } - // }; - // const userinfor = { - // cityInfor: { - // lat: safeDecode(parameters.cityInfor.lat), - // lng: safeDecode(parameters.cityInfor.lng), - // city: safeDecode(parameters.cityInfor.address), - // province: safeDecode(parameters.cityInfor.province), - // adcode: safeDecode(parameters.cityInfor.adcode), - // }, - // isWechat: true, - // }; + for(let key in querys){ + querys[key] = JSON.parse(querys[key]) + } - // let query = `userinfor=${encodedUserInfor}×tamp=${Date.now()}`; + let parameters = { ...querys['userinfor'], ...querys['query']}; + parameters.token = ''; + console.log({...querys['query']}, '111111111111111111111111111111111111111') + const safeDecode = (value) => { + if (value == null) return ''; // 默认空值 + try { + return typeof value === 'string' ? decodeURIComponent(value) : value; + } catch { + return value; // 解码失败返回原值 + } + }; + const userinfor = { + cityInfor: { + lat: safeDecode(parameters.cityInfor.lat), + lng: safeDecode(parameters.cityInfor.lng), + city: safeDecode(parameters.cityInfor.address), + province: safeDecode(parameters.cityInfor.province), + adcode: safeDecode(parameters.cityInfor.adcode), + }, + isWechat: true, + query: {...querys['query']} + }; - // console.log(HTTP_REQUEST_URL+'?'+query, '分享链接'); - // uni.setStorageSync('SHARELINK', HTTP_REQUEST_URL+'?'+query); + let query = `userinfor=${encodeURIComponent(JSON.stringify(userinfor))}×tamp=${Date.now()}`; + uni.setStorageSync('SHARELINK', 'http://10.210.254.176:8090'+'/privilege/pages/restaurant/home/shop_home/shop_home?'+query); - // 清除 - const url = new URL(window.location.href); - url.search = ''; // 移除所有查询参数 - window.history.replaceState(null, '', url.href); + // 清除url + // const url = new URL(window.location.href); + // url.search = ''; // 移除所有查询参数 + // window.history.replaceState(null, '', url.href); } }, onShow: function() { console.log('App Show'); - // 全局初始化参数中存在isWechat属性则代表就是从小程序跳入 + // 全局初始化参数中存在isWechat属性则代表就是从小程序跳入 if (this['globalData']['parameters']?.isWechat) { store.commit('SetcityInfor', this['globalData']['parameters']['cityInfor']); - if (this['globalData']['parameters']['token']) { - store.commit('SetToken', this['globalData']['parameters']['token']); + if (getUrlParams(window.location.href)['token']) { // 优先登录后token + store.commit('SETTOKEN', decodeURIComponent(getUrlParams(window.location.href)['token'])); + } else if (this['globalData']['parameters']['token']) { // 跳入token + store.commit('SETTOKEN', this['globalData']['parameters']['token']); } } else { // 反之则代表从APP进入H5 diff --git a/pages/restaurant/home/shop_home/shop_home.vue b/pages/restaurant/home/shop_home/shop_home.vue index c10d664..7f67271 100644 --- a/pages/restaurant/home/shop_home/shop_home.vue +++ b/pages/restaurant/home/shop_home/shop_home.vue @@ -83,7 +83,8 @@ import { menuQueryAPI, getStoreInfoAPI, - wxconfig + wxconfig, + Myspread } from '@/request/restaurant/index.js'; // 配置文件 import config from '@/static/js/config.js'; @@ -92,8 +93,8 @@ RXrestaurant, XBKSharing } from '@/static/js/share.js' - import wx from 'weixin-js-sdk' - + import wx from 'weixin-js-sdk' + import { mapGetters, mapMutations } from 'vuex'; let self; export default { @@ -158,7 +159,10 @@ } }, }, - computed: { + computed: { + ...mapGetters({ + GetSpread: 'GetSpread', + }), deviceOS() { const userAgent = navigator.userAgent || navigator.vendor || window.opera; @@ -174,7 +178,7 @@ onLoad(param) { self = this; this.handleWechatShare(); - console.log(param['brand_id'], 'onLoad参数'); + console.log(param, 'onLoad参数ss'); const isWechat = getApp()['globalData']['parameters']?.isWechat; console.log(isWechat, getApp()['globalData']['parameters']?.brand_id, '是否需要分享'); if (isWechat && getApp()['globalData']['parameters']?.brand_id) { @@ -493,9 +497,8 @@ const res = await wxconfig({ url: this.getUrl() }) - let wxConfig = { - debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 + debug: false, appId: res.data.appId, // 必填,公众号的唯一标识 timestamp: res.data.timestamp || res.data.timestamp, // 必填,生成签名的时间戳 nonceStr: res.data.nonceStr, // 必填,生成签名的随机串 @@ -503,23 +506,24 @@ jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 必填,需要使用的JS接口列表 } - // 2、注入权限验证信息,初始化权限信息(目的是为了能够调用微信的相关api) - wx.config(wxConfig) - - // 3、初始化微信自定义分享信息(目的是为了在用户点击右上角分享的时候,把分享的内容从链接 变成 自定义内容的卡片) - this.initWechatShareData() + wx.config(wxConfig) + + Myspread().then(res => { + this.initWechatShareData(res.data.uid) + }) }, - initWechatShareData() { + initWechatShareData(uid) { // 分享链接参数 - let url = uni.getStorageSync('SHARELINK'); + let shareUrl = uni.getStorageSync('SHARELINK'); + console.log(shareUrl + '&spread=' + uid, '分享链接') wx.ready(() => { // 自定义分享朋友信息 wx.updateAppMessageShareData({ shareInfo: { desc: '欢迎来到白马精选', title: '白马精选', - link: window.location.href, + link: shareUrl + '&spread=' + uid, imgUrl: 'https://imgs.agrimedia.cn/shop/logo.jpg' } }) @@ -527,8 +531,8 @@ wx.updateTimelineShareData({ shareInfo: { desc: '欢迎来到白马精选', - title: '白马精选', - link: window.location.href, + title: '白马精选', + link: shareUrl + '&spread=' + this.GetSpread, imgUrl: 'https://imgs.agrimedia.cn/shop/logo.jpg' } }) diff --git a/pages/restaurant/order/orders-settlement/settlement.vue b/pages/restaurant/order/orders-settlement/settlement.vue index 8b3e294..b2092f8 100644 --- a/pages/restaurant/order/orders-settlement/settlement.vue +++ b/pages/restaurant/order/orders-settlement/settlement.vue @@ -312,7 +312,6 @@ }, onShow() { const value = uni.getStorageSync('isWechatStorage'); - this.init(); }, methods: { init() { diff --git a/request/request.js b/request/request.js index 63d1efe..f6a4962 100644 --- a/request/request.js +++ b/request/request.js @@ -93,7 +93,6 @@ class Request { * @param {String} url请求地址 */ Request(config = {}) { - console.log(config, '23333') // 是否存在url try { if (!config['url']) { @@ -122,7 +121,6 @@ class Request { }; config['complete'] = (infor) => { this.responseintercept(infor); - console.log(infor, 'wwwwwwwwww') if (infor.data['status'] == 200 || infor.statusCode == 200) { // arraybuffer格式返回是不带code的 // 判断是否是arraybuffer @@ -134,7 +132,7 @@ class Request { if (infor['data']['status'] != 200 && infor['data']['code'] != 7777) { // #ifdef H5 if (infor['data']['status'] == 110002) { - window.location.href = `${HTTP_REQUEST_URL}/JXH5/pages/users/h5_login/index`; + window.location.href = `${HTTP_REQUEST_URL}/JXH5/pages/users/h5_login/index&redirect_uri=${window.location.protocol + "//" + window.location.host}/privilege/pages/restaurant/home/shop_home/shop_home`; } // #endif @@ -206,7 +204,7 @@ class Request { }) console.log(cityInfor, '定位信息头') - if (cityInfor?.city) { + if (cityInfor?.adcode) { // config['header']['city'] = encodeURIComponent(cityInfor['city']); config['header']['city'] = encodeURIComponent(cityInfor['province']); config['header']['address'] = encodeURIComponent(cityInfor['province']); @@ -221,8 +219,6 @@ class Request { config['header']['lat'] = ''; config['header']['adcode'] = ''; }; - // config['header']['ApiToken'] = - // 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NjM4MTYzMTAsIm5iZiI6MTY2MzgxNjMxMCwiZXhwIjoxNjY2NDA4MzEwLCJkYXRhIjp7ImNsaWVudF9pZCI6MX19.db_hFkDJ2dogkvDkhaBj5W5gti3bFHWWRCVf3-PyF-E'; // config['header']['token'] ='123456' //chwl 123456 @@ -230,11 +226,9 @@ class Request { // // 微信跳转H5后的逻辑为必须携带token const isWechat = getApp()['globalData']['parameters']?.isWechat; - console.log(isWechat, '222222222') if (isWechat) { - config['header']['authori-zation'] = getApp()['globalData']['parameters']['token']; + config['header']['authori-zation'] = state['getters']['GetToken']; } - // 测试标识 // 测试时不需要显示在线上的打开 // config['header']['test1'] = 1; @@ -246,20 +240,16 @@ class Request { config['header']['env'] = 1; // config['header']['bm_id'] = bm_id; // console.log(loginAPI,'loginAPI'); - console.log(config, '请求拦截器'); return config } // 响应拦截 responseintercept(infor) { - console.log(infor, '响应拦截'); // const isWechat = getApp()['globalData']['parameters']?.isWech'at; // console.log(isWechat,process.env.NODE_ENV,'isWechat1'); // IOS端不经行任何处理 - console.log(isSafari && process.env.NODE_ENV !== 'development','是否测试环境111'); let isSafari = (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)); if (isSafari && process.env.NODE_ENV !== 'development') return; - console.log(infor['statusCode'],'是否测试环境11221'); // 响应拦截逻辑开始 // if (infor['statusCode'] != 200) { if (infor.data['status'] != 200) { @@ -273,7 +263,6 @@ class Request { if (infor['data']['code'] == 7777) { // 微信中进入H5后会携带token,但是如果微信进入H5后token过期则提示用户返回小程序重新登录 const isWechat = getApp()['globalData']['parameters']?.isWechat; - console.log(isWechat, 'isWechat1'); if (isWechat) { uni.showToast({ title: '登录过期请刷新微信小程序', @@ -282,7 +271,6 @@ class Request { }); return } else { - console.log(process.env.NODE_ENV,'是否测试环境'); if (process.env.NODE_ENV == 'development') { loginAPI({ // 剑南白马ID diff --git a/request/restaurant/index.js b/request/restaurant/index.js index 594fa1e..89d3586b 100644 --- a/request/restaurant/index.js +++ b/request/restaurant/index.js @@ -110,3 +110,10 @@ export const createFoodOrder = parameters => request.Request({ url: "/api/client */ export const wxconfig = parameters => request.Request({ url: "/api/wechat/config", parameters }); + +// 邀请人绑定 +export const spread = parameters => request.Request({ url: "/api/user/spread", parameters, method:'POST' }); + + +// 我的邀请码 +export const Myspread = parameters => request.Request({ url: "/api/user", parameters }); diff --git a/store/index.js b/store/index.js index 898ac3e..d4ecfbb 100644 --- a/store/index.js +++ b/store/index.js @@ -5,7 +5,9 @@ Vue.use(Vuex); import { SETRUSERAREA, SETCITYCODE, - SETFILMDATA + SETFILMDATA, + SETSPREAD, + SETTOKEN } from './mutation-types.js' import card from './module/card'; // import brand from './module/brand'; @@ -61,7 +63,8 @@ const store = new Vuex.Store({ regionName: "", // 区名 regionId: "" // 区ID }, - token: '' + token: '', + spread: '' }, getters: { // 获取操作端 @@ -75,18 +78,26 @@ const store = new Vuex.Store({ // 获取电影城市数据 GetFilmData: state => state['FilmCityDate'], - GetToken: state => state['token'] + GetToken: state => state['token'], + GetSpread: state => state['spread'] }, mutations: { // 用户自主选择位置之后 [SETRUSERAREA](state, data) { - console.log(data, '233333333333333') + console.log(data, '用户自主选择位置之后') state['Locationtext'] = data; }, // 设置城市code [SETCITYCODE](state, code) { state['AraeCityCode'] = code; console.log('设置城市code', state['AraeCityCode']); + }, + [SETSPREAD](state, code) { + state['spread'] = code; + console.log('设置邀请码code', state['spread']); + }, + [SETTOKEN](state, data) { + state['token'] = data; }, // 设置电影城市数据 SETFILMDATA(state, data) { @@ -110,9 +121,6 @@ const store = new Vuex.Store({ */ GetState(state) { // uni.setStorageSync('VUEXSTATE', JSON.stringify(store)); - }, - SetToken(state, data) { - state['token'] = data; } }, modules: { @@ -125,7 +133,6 @@ const store = new Vuex.Store({ // 定制 diy }, - }); window.addEventListener("beforeunload", () => { uni.setStorageSync('VUEXSTATE', JSON.stringify(store['state'])); diff --git a/store/mutation-types.js b/store/mutation-types.js index 72018d7..b729b4f 100644 --- a/store/mutation-types.js +++ b/store/mutation-types.js @@ -8,6 +8,7 @@ export const REDUCE_CART = 'REDUCE_CART'; export const SETRUSERAREA = 'SETRUSERAREA'; // 订餐模块设置用户城市CODE export const SETCITYCODE = 'SETCITYCODE'; +export const SETSPREAD = 'SETSPREAD'; // 订餐模块设置用户选择品牌 export const SETBRANDINFOR = 'SETBRANDINFOR'; // 订餐模块设置用户选择餐厅信息 @@ -25,4 +26,6 @@ export const SETREPLACE = 'SETREPLACE'; export const SETNAVINDEX = 'SETNAVINDEX'; export const SETINFOR = 'SETINFOR'; // 设置下单手机号 -export const SETPHONE = 'SETPHONE'; \ No newline at end of file +export const SETPHONE = 'SETPHONE'; +export const SETTOKEN = 'SETTOKEN'; +