feat: 点餐分享

This commit is contained in:
whitechiina 2025-09-19 10:17:41 +08:00
parent b1ff9a68e4
commit 892d6f3707
7 changed files with 154 additions and 96 deletions

146
App.vue
View File

@ -23,6 +23,8 @@
} }
import store from '@/store/index'; 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 { export default {
globalData: { globalData: {
// FPT // FPT
@ -38,9 +40,8 @@
// }, // },
parameters: {} parameters: {}
}, },
onLaunch: function(parameters = {}) {
console.log(navigator.userAgent,'userAgent'); onLaunch: function(parameters = {}) {
// scriptwxjs // scriptwxjs
var script = document.createElement('script'); var script = document.createElement('script');
script.src = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js"; 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 basurl = uri(decodeURIComponent(window.location.href))
let querys = basurl.query(true); 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(Object.keys(querys)['length'] > 0){
if(querys?.para){ if(querys?.para){
// URL // URL
@ -61,10 +74,8 @@
// //
if (typeof _para == 'object' && _para['para'] != undefined) { if (typeof _para == 'object' && _para['para'] != undefined) {
console.log('存在参数');
// URL // URL
var URLpara = decodeURIComponent(getUrlParams(window.location.href)['para']); var URLpara = decodeURIComponent(getUrlParams(window.location.href)['para']);
console.log(JSON.parse(URLpara),'*****');
try{ try{
// URLJSON#/使JSON.parse#/ // URLJSON#/使JSON.parse#/
var _r = URLpara.substr(0, URLpara.lastIndexOf("#/")); var _r = URLpara.substr(0, URLpara.lastIndexOf("#/"));
@ -89,15 +100,36 @@
console.log(JSON.stringify(this['globalData']['parameters'],null,10), 'App Launch'); console.log(JSON.stringify(this['globalData']['parameters'],null,10), 'App Launch');
}else{ }else{
console.log('存在参数1997', !querys.token)
if (!querys.token) {
for(let key in querys){ for(let key in querys){
console.log(querys); const value = querys[key];
querys[key] = JSON.parse(querys[key]) querys[key] = JSON.parse(value);
}; }
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'])});
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 // JIN
store.commit('shopping/SETSHOPDETAIL', { store.commit('shopping/SETSHOPDETAIL', {
city_name: this['globalData']['parameters'].cityInfor.city, city_name: this['globalData']['parameters'].cityInfor.city,
@ -113,11 +145,13 @@
special: false, special: false,
distance: this['globalData']['parameters'].distance 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(); this.clearUrlParams();
return; return;
@ -142,44 +176,58 @@
}, },
methods: { 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() { clearUrlParams() {
// //
// let basurl = uri(decodeURIComponent(window.location.href)) let basurl = uri(decodeURIComponent(window.location.href))
// let querys = basurl.query(true); let querys = basurl.query(true);
// for(let key in querys){ if (querys.token) return; //
// querys[key] = JSON.parse(querys[key])
// };
// let parameters = { ...querys['userinfor'], ...querys['query']};
// parameters.token = '';
// const safeDecode = (value) => { for(let key in querys){
// if (value == null) return ''; // querys[key] = JSON.parse(querys[key])
// 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,
// };
// let query = `userinfor=${encodedUserInfor}&timestamp=${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, ''); let query = `userinfor=${encodeURIComponent(JSON.stringify(userinfor))}&timestamp=${Date.now()}`;
// uni.setStorageSync('SHARELINK', HTTP_REQUEST_URL+'?'+query); uni.setStorageSync('SHARELINK', 'http://10.210.254.176:8090'+'/privilege/pages/restaurant/home/shop_home/shop_home?'+query);
// // url
const url = new URL(window.location.href); // const url = new URL(window.location.href);
url.search = ''; // // url.search = ''; //
window.history.replaceState(null, '', url.href); // window.history.replaceState(null, '', url.href);
} }
}, },
@ -188,8 +236,10 @@
// isWechat // isWechat
if (this['globalData']['parameters']?.isWechat) { if (this['globalData']['parameters']?.isWechat) {
store.commit('SetcityInfor', this['globalData']['parameters']['cityInfor']); store.commit('SetcityInfor', this['globalData']['parameters']['cityInfor']);
if (this['globalData']['parameters']['token']) { if (getUrlParams(window.location.href)['token']) { // token
store.commit('SetToken', this['globalData']['parameters']['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 { } else {
// APPH5 // APPH5

View File

@ -83,7 +83,8 @@
import { import {
menuQueryAPI, menuQueryAPI,
getStoreInfoAPI, getStoreInfoAPI,
wxconfig wxconfig,
Myspread
} from '@/request/restaurant/index.js'; } from '@/request/restaurant/index.js';
// //
import config from '@/static/js/config.js'; import config from '@/static/js/config.js';
@ -93,7 +94,7 @@
XBKSharing XBKSharing
} from '@/static/js/share.js' } from '@/static/js/share.js'
import wx from 'weixin-js-sdk' import wx from 'weixin-js-sdk'
import { mapGetters, mapMutations } from 'vuex';
let self; let self;
export default { export default {
@ -159,6 +160,9 @@
}, },
}, },
computed: { computed: {
...mapGetters({
GetSpread: 'GetSpread',
}),
deviceOS() { deviceOS() {
const userAgent = navigator.userAgent || navigator.vendor || window.opera; const userAgent = navigator.userAgent || navigator.vendor || window.opera;
@ -174,7 +178,7 @@
onLoad(param) { onLoad(param) {
self = this; self = this;
this.handleWechatShare(); this.handleWechatShare();
console.log(param['brand_id'], 'onLoad参数'); console.log(param, 'onLoad参数ss');
const isWechat = getApp()['globalData']['parameters']?.isWechat; const isWechat = getApp()['globalData']['parameters']?.isWechat;
console.log(isWechat, getApp()['globalData']['parameters']?.brand_id, '是否需要分享'); console.log(isWechat, getApp()['globalData']['parameters']?.brand_id, '是否需要分享');
if (isWechat && getApp()['globalData']['parameters']?.brand_id) { if (isWechat && getApp()['globalData']['parameters']?.brand_id) {
@ -493,9 +497,8 @@
const res = await wxconfig({ const res = await wxconfig({
url: this.getUrl() url: this.getUrl()
}) })
let wxConfig = { let wxConfig = {
debug: false, // ,apialertpclogpc debug: false,
appId: res.data.appId, // appId: res.data.appId, //
timestamp: res.data.timestamp || res.data.timestamp, // timestamp: res.data.timestamp || res.data.timestamp, //
nonceStr: res.data.nonceStr, // nonceStr: res.data.nonceStr, //
@ -503,23 +506,24 @@
jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 使JS jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 使JS
} }
// 2api
wx.config(wxConfig) wx.config(wxConfig)
// 3 Myspread().then(res => {
this.initWechatShareData() 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.ready(() => {
// //
wx.updateAppMessageShareData({ wx.updateAppMessageShareData({
shareInfo: { shareInfo: {
desc: '欢迎来到白马精选', desc: '欢迎来到白马精选',
title: '白马精选', title: '白马精选',
link: window.location.href, link: shareUrl + '&spread=' + uid,
imgUrl: 'https://imgs.agrimedia.cn/shop/logo.jpg' imgUrl: 'https://imgs.agrimedia.cn/shop/logo.jpg'
} }
}) })
@ -528,7 +532,7 @@
shareInfo: { shareInfo: {
desc: '欢迎来到白马精选', desc: '欢迎来到白马精选',
title: '白马精选', title: '白马精选',
link: window.location.href, link: shareUrl + '&spread=' + this.GetSpread,
imgUrl: 'https://imgs.agrimedia.cn/shop/logo.jpg' imgUrl: 'https://imgs.agrimedia.cn/shop/logo.jpg'
} }
}) })

View File

@ -312,7 +312,6 @@
}, },
onShow() { onShow() {
const value = uni.getStorageSync('isWechatStorage'); const value = uni.getStorageSync('isWechatStorage');
this.init();
}, },
methods: { methods: {
init() { init() {

View File

@ -93,7 +93,6 @@ class Request {
* @param {String} url请求地址 * @param {String} url请求地址
*/ */
Request(config = {}) { Request(config = {}) {
console.log(config, '23333')
// 是否存在url // 是否存在url
try { try {
if (!config['url']) { if (!config['url']) {
@ -122,7 +121,6 @@ class Request {
}; };
config['complete'] = (infor) => { config['complete'] = (infor) => {
this.responseintercept(infor); this.responseintercept(infor);
console.log(infor, 'wwwwwwwwww')
if (infor.data['status'] == 200 || infor.statusCode == 200) { if (infor.data['status'] == 200 || infor.statusCode == 200) {
// arraybuffer格式返回是不带code的 // arraybuffer格式返回是不带code的
// 判断是否是arraybuffer // 判断是否是arraybuffer
@ -134,7 +132,7 @@ class Request {
if (infor['data']['status'] != 200 && infor['data']['code'] != 7777) { if (infor['data']['status'] != 200 && infor['data']['code'] != 7777) {
// #ifdef H5 // #ifdef H5
if (infor['data']['status'] == 110002) { 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 // #endif
@ -206,7 +204,7 @@ class Request {
}) })
console.log(cityInfor, '定位信息头') console.log(cityInfor, '定位信息头')
if (cityInfor?.city) { if (cityInfor?.adcode) {
// config['header']['city'] = encodeURIComponent(cityInfor['city']); // config['header']['city'] = encodeURIComponent(cityInfor['city']);
config['header']['city'] = encodeURIComponent(cityInfor['province']); config['header']['city'] = encodeURIComponent(cityInfor['province']);
config['header']['address'] = encodeURIComponent(cityInfor['province']); config['header']['address'] = encodeURIComponent(cityInfor['province']);
@ -221,8 +219,6 @@ class Request {
config['header']['lat'] = ''; config['header']['lat'] = '';
config['header']['adcode'] = ''; config['header']['adcode'] = '';
}; };
// config['header']['ApiToken'] =
// 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NjM4MTYzMTAsIm5iZiI6MTY2MzgxNjMxMCwiZXhwIjoxNjY2NDA4MzEwLCJkYXRhIjp7ImNsaWVudF9pZCI6MX19.db_hFkDJ2dogkvDkhaBj5W5gti3bFHWWRCVf3-PyF-E';
// config['header']['token'] ='123456' // config['header']['token'] ='123456'
//chwl 123456 //chwl 123456
@ -230,11 +226,9 @@ class Request {
// //
// 微信跳转H5后的逻辑为必须携带token // 微信跳转H5后的逻辑为必须携带token
const isWechat = getApp()['globalData']['parameters']?.isWechat; const isWechat = getApp()['globalData']['parameters']?.isWechat;
console.log(isWechat, '222222222')
if (isWechat) { if (isWechat) {
config['header']['authori-zation'] = getApp()['globalData']['parameters']['token']; config['header']['authori-zation'] = state['getters']['GetToken'];
} }
// 测试标识 // 测试标识
// 测试时不需要显示在线上的打开 // 测试时不需要显示在线上的打开
// config['header']['test1'] = 1; // config['header']['test1'] = 1;
@ -246,20 +240,16 @@ class Request {
config['header']['env'] = 1; config['header']['env'] = 1;
// config['header']['bm_id'] = bm_id; // config['header']['bm_id'] = bm_id;
// console.log(loginAPI,'loginAPI'); // console.log(loginAPI,'loginAPI');
console.log(config, '请求拦截器');
return config return config
} }
// 响应拦截 // 响应拦截
responseintercept(infor) { responseintercept(infor) {
console.log(infor, '响应拦截');
// const isWechat = getApp()['globalData']['parameters']?.isWech'at; // const isWechat = getApp()['globalData']['parameters']?.isWech'at;
// console.log(isWechat,process.env.NODE_ENV,'isWechat1'); // console.log(isWechat,process.env.NODE_ENV,'isWechat1');
// IOS端不经行任何处理 // IOS端不经行任何处理
console.log(isSafari && process.env.NODE_ENV !== 'development','是否测试环境111');
let isSafari = (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)); let isSafari = (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent));
if (isSafari && process.env.NODE_ENV !== 'development') return; if (isSafari && process.env.NODE_ENV !== 'development') return;
console.log(infor['statusCode'],'是否测试环境11221');
// 响应拦截逻辑开始 // 响应拦截逻辑开始
// if (infor['statusCode'] != 200) { // if (infor['statusCode'] != 200) {
if (infor.data['status'] != 200) { if (infor.data['status'] != 200) {
@ -273,7 +263,6 @@ class Request {
if (infor['data']['code'] == 7777) { if (infor['data']['code'] == 7777) {
// 微信中进入H5后会携带token,但是如果微信进入H5后token过期则提示用户返回小程序重新登录 // 微信中进入H5后会携带token,但是如果微信进入H5后token过期则提示用户返回小程序重新登录
const isWechat = getApp()['globalData']['parameters']?.isWechat; const isWechat = getApp()['globalData']['parameters']?.isWechat;
console.log(isWechat, 'isWechat1');
if (isWechat) { if (isWechat) {
uni.showToast({ uni.showToast({
title: '登录过期请刷新微信小程序', title: '登录过期请刷新微信小程序',
@ -282,7 +271,6 @@ class Request {
}); });
return return
} else { } else {
console.log(process.env.NODE_ENV,'是否测试环境');
if (process.env.NODE_ENV == 'development') { if (process.env.NODE_ENV == 'development') {
loginAPI({ loginAPI({
// 剑南白马ID // 剑南白马ID

View File

@ -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 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 });

View File

@ -5,7 +5,9 @@ Vue.use(Vuex);
import { import {
SETRUSERAREA, SETRUSERAREA,
SETCITYCODE, SETCITYCODE,
SETFILMDATA SETFILMDATA,
SETSPREAD,
SETTOKEN
} from './mutation-types.js' } from './mutation-types.js'
import card from './module/card'; import card from './module/card';
// import brand from './module/brand'; // import brand from './module/brand';
@ -61,7 +63,8 @@ const store = new Vuex.Store({
regionName: "", // 区名 regionName: "", // 区名
regionId: "" // 区ID regionId: "" // 区ID
}, },
token: '' token: '',
spread: ''
}, },
getters: { getters: {
// 获取操作端 // 获取操作端
@ -75,12 +78,13 @@ const store = new Vuex.Store({
// 获取电影城市数据 // 获取电影城市数据
GetFilmData: state => state['FilmCityDate'], GetFilmData: state => state['FilmCityDate'],
GetToken: state => state['token'] GetToken: state => state['token'],
GetSpread: state => state['spread']
}, },
mutations: { mutations: {
// 用户自主选择位置之后 // 用户自主选择位置之后
[SETRUSERAREA](state, data) { [SETRUSERAREA](state, data) {
console.log(data, '233333333333333') console.log(data, '用户自主选择位置之后')
state['Locationtext'] = data; state['Locationtext'] = data;
}, },
// 设置城市code // 设置城市code
@ -88,6 +92,13 @@ const store = new Vuex.Store({
state['AraeCityCode'] = code; state['AraeCityCode'] = code;
console.log('设置城市code', state['AraeCityCode']); 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) { SETFILMDATA(state, data) {
console.log(data, 'vuex设置电影城市数据') console.log(data, 'vuex设置电影城市数据')
@ -110,9 +121,6 @@ const store = new Vuex.Store({
*/ */
GetState(state) { GetState(state) {
// uni.setStorageSync('VUEXSTATE', JSON.stringify(store)); // uni.setStorageSync('VUEXSTATE', JSON.stringify(store));
},
SetToken(state, data) {
state['token'] = data;
} }
}, },
modules: { modules: {
@ -125,7 +133,6 @@ const store = new Vuex.Store({
// 定制 // 定制
diy diy
}, },
}); });
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
uni.setStorageSync('VUEXSTATE', JSON.stringify(store['state'])); uni.setStorageSync('VUEXSTATE', JSON.stringify(store['state']));

View File

@ -8,6 +8,7 @@ export const REDUCE_CART = 'REDUCE_CART';
export const SETRUSERAREA = 'SETRUSERAREA'; export const SETRUSERAREA = 'SETRUSERAREA';
// 订餐模块设置用户城市CODE // 订餐模块设置用户城市CODE
export const SETCITYCODE = 'SETCITYCODE'; export const SETCITYCODE = 'SETCITYCODE';
export const SETSPREAD = 'SETSPREAD';
// 订餐模块设置用户选择品牌 // 订餐模块设置用户选择品牌
export const SETBRANDINFOR = 'SETBRANDINFOR'; export const SETBRANDINFOR = 'SETBRANDINFOR';
// 订餐模块设置用户选择餐厅信息 // 订餐模块设置用户选择餐厅信息
@ -26,3 +27,5 @@ export const SETNAVINDEX = 'SETNAVINDEX';
export const SETINFOR = 'SETINFOR'; export const SETINFOR = 'SETINFOR';
// 设置下单手机号 // 设置下单手机号
export const SETPHONE = 'SETPHONE'; export const SETPHONE = 'SETPHONE';
export const SETTOKEN = 'SETTOKEN';