Commit d44f798a by 杨北旺

提交

1 parent f8ca9b35
import { preReleaseAppId } from '~/config'
const target = ['ip', 'dev', 'uat', 'prod', 'preRelease']
let index = 2
let index = 1
/**
*
......
......@@ -3,11 +3,9 @@
import sentryInit from "~/utils/sentryConfig/sentryInit";
sentryInit();
import api from "./api/index";
// import { router } from "./router/index";
import router from "./router/index.js";
import { router } from "./router/index";
// 判断小程序是否需要更新
import { getUpdateManager } from "./lib/index";
import {IMG_URL} from '~/config'
import utils from "./utils/index";
// 埋点 有需要再引入
import TRACK from './utils/track/Track'
......@@ -24,18 +22,8 @@ App({
router,
storage: new utils.cache.Storage(),
$Track: new TRACK(options),
IMGURL:IMG_URL
};
// console.log(wx.p);
// const {
// scene,
// query,
// query: {
// pageType
// }
// } = wx.getEnterOptionsSync()
// console.log(scene,query,pageType,'二次扫码');
console.log(wx.p);
// 存储设备信息
utils.cache.storageApi.setSystem_info();
},
......
......@@ -114,18 +114,7 @@
"pages/index/index"
],
"plugins": {
"ticketPlugin": {
"version": "2.0.2",
"provider": "wxd5b8312c3a09901a"
},
"express-plugin": {
"version": "1.2.0",
"provider": "wx1b1f66316b427c74"
},
"collectionPlugin": {
"version": "1.2.0",
"provider": "wx5e90fdd843841356"
}
}
},
{
......
......@@ -111,8 +111,9 @@ Page({
},
onLoad(options) {
let system = wx.getSystemInfoSync()
// const merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let newMerchantId = merchantId || defaultMerchantId
if (options && options.scene) {
......
......@@ -16,7 +16,7 @@ Page({
},
onRoute(e) {
onLoad(e) {
let { titleList } = this.data
if (e && e.title) {
wx.setNavigationBarTitle({
......
......@@ -15,7 +15,10 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getHomeConfig(wx.$merchant_id)
const {
merchantId
} = wx.p.storage.get('merchant_info')
this.getHomeConfig(merchantId)
this.getAllMerchantList()
},
getHomeConfig(merchantId) {
......@@ -74,7 +77,9 @@ Page({
})
},
getAllMerchantList() {
let merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
......
......@@ -53,7 +53,9 @@ Page({
},
getAllMerchantList() {
let merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
......
......@@ -396,7 +396,7 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onRoute: function (options) {
onLoad: function (options) {
// debugger
console.log(options,'options');
if(options&&options.openId){
......
......@@ -66,8 +66,9 @@ Page({
})
},
getMerchantCouponList(){
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id')
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
couponsApi.getMerchantCouponsListApi({merchantId,discoverGoodsType:this.options.discoverGoodsType}).then(res => {
if(res?.length) {
res.forEach(item =>{
......@@ -80,8 +81,9 @@ Page({
})
},
receiveCoupon(){
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id')
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let couponIds = this.data.couponList?.map(item => item.couponId)
wx.p.wxApi.showLoading()
couponsApi.batchGetMerchantCouponsApi({merchantId,couponIds,discoverGoodsType:this.options.discoverGoodsType}).then(res => {
......@@ -114,8 +116,9 @@ Page({
}, 1 * 1000)
},
JumpDiscoverPage(){
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id')
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
const channel = this.options.discoverGoodsType==1 ? 5 : 6
wx.$router.reLaunch(`/packageDiscovery/pages/index/index?merchantId=${merchantId}&channel=${channel}`, { notIntercept: true })
},
......@@ -152,8 +155,9 @@ Page({
this.setData({
sessionId: '',
})
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id')
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
couponsApi.getMerchantCouponsListApi({merchantId,discoverGoodsType:this.options.discoverGoodsType}).then(res => {
if(res?.length) {
this.receiveCoupon()
......
......@@ -12,7 +12,7 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onRoute(options) {
onLoad(options) {
this.setData({
goodsInfo: options
})
......
......@@ -84,8 +84,9 @@ Page({
})
},
getAllMerchantList() {
// let merchantId = wx.p.storage.get('srcm_shopmall_merchant_id')
let merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
......
import { IMG_URL } from '~/config';
Page({
/**
* 页面的初始数据
*/
data: {
IMGURL:IMG_URL,
isOpen: false,
openingStatus: false
},
// 获取门店会员卡信息
getMemberCardData() {
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId: merchantId
}
......
......@@ -6,7 +6,11 @@ Page({
},
onLoad(options) {
this.data.enter_time =new Date().format('yyyy-MM-dd hh:mm:ss')
console.log(options);
if(options&&options.openId){
this.shareOpenId = options.openId
}
this.data.enter_time = new Date().format('yyyy-MM-dd hh:mm:ss')
this.firstEnter = true
this.getStrategyDetail(options.id);
// 触发埋点
......@@ -15,20 +19,9 @@ Page({
item_type: 6,
view: 1
})
this
},
onRoute: function (options) {
console.log(options, "000000");
this.data.enter_time =new Date().format('yyyy-MM-dd hh:mm:ss')
this.firstEnter = true
this.getStrategyDetail(options.id);
// 触发埋点
this.heartbeatFn({
id: options.id,
item_type: 6,
view: 1,
});
},
getStrategyDetail(id) {
wx.p.api.strategyApi
......@@ -39,6 +32,8 @@ Page({
Util.setNavigationBarTitle(res.strategyName);
this.setData({
strategyDetailObj: res,
}, () => {
this.handlerShareQuery()
});
});
},
......@@ -53,7 +48,9 @@ Page({
const { id, item_type, view } = query;
const userInfo = wx.p.cache.userInfo.getUserInfo() || {},
{ openId } = await USERAPI.getWXUserInfo();
console.log(wx.$merchant_id, "=======");
const {
merchantId
} = wx.p.storage.get('merchant_info')
let data = {
open_id: openId || null,
create_time: this.firstEnter
......@@ -66,7 +63,7 @@ Page({
item_id: id,
business_type: 1,
add_way: 104,
merchant_id: wx.$merchant_id,
merchant_id: merchantId,
guest_no: wx.p.$Track.getGuestNo(), //游客ID,
user_open_id: this.shareOpenId || "",
};
......@@ -95,28 +92,28 @@ Page({
// wx.$util.customerbehavior(2);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
const merchantId = wx.$merchant_id;
handlerShareQuery() {
const {
merchantId
} = wx.p.storage.get('merchant_info')
const userInfo = wx.p.cache.userInfo.getUserInfo();
let { strategyDetailObj } = this.data,
open_id = "";
console.log(strategyDetailObj, '9999999999');
this.trackQuery.view = 4;
this.addTrack(this.trackQuery);
if (userInfo) open_id = userInfo.openId;
let title = strategyDetailObj.strategyName;
let path = `${this.route}?id=${strategyDetailObj.id}&openId=${open_id}`;
let imageUrl = strategyDetailObj.strategyImg;
let path = `id=${strategyDetailObj.id}&openId=${open_id}`;
if (merchantId) path = `${path}&merchantId=${merchantId}`;
console.log(path);
console.log(imageUrl, title);
return {
imageUrl,
title,
path,
};
this.shareTitle = strategyDetailObj.strategyName;
this.shareImage = strategyDetailObj.strategyImg
this.shareQuery = path
this.trackQuery.view = 4;
this.shareFun = () => {
this.addTrack(this.trackQuery);
}
},
onShareAppMessage: function () {
}
});
......@@ -26,7 +26,12 @@ Page({
async login(options = {}) {
console.log(options, 'options.merchantId')
// wx.p.router.goHome()
if (options.merchantId) wx.$merchant_id = options.merchantId
if (options.merchantId){
wx.$merchant_id = options.merchantId
wx.p.storage.set('merchant_info', {
merchantId: options.merchantId,
})
}
try {
const { code, data, message } = await wx.p.api.userApi.login()
wx.$LoginStatus = code != 0
......
......@@ -133,7 +133,9 @@ Page({
)
},
getAllMerchantList() {
let merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = {
merchantId
}
......
......@@ -89,29 +89,35 @@ Page({
// 门店切换
changeStore(e) {
const index = +e.detail.value
const {storeList} = this.data
const { storeList } = this.data
const currentStore = storeList[index]
wx.$merchant_id = currentStore.merchantId
wx.p.storage.set('merchant_info', {
merchantId: currentStore.merchantId,
})
this.setData({
currentStore
})
},
// 获取门店列表
getMerchantList() {
const merchantObj = {
'develop': [44211227, 44209845],
'test': [44212577,44210895, 44212578,44210956],
'test': [44212577, 44210895, 44212578, 44210956],
'beta': [],
'production': [44209566, 44209565],
}
const MerchantList = merchantObj[env]
console.log(MerchantList,'MerchantList');
let storeList = [],index = 0
MerchantList.forEach((el,i) => {
console.log(MerchantList, 'MerchantList');
let storeList = [], index = 0
MerchantList.forEach((el, i) => {
wx.$merchant_id = el
wx.p.api.homeApi.getHomeConfig({merchantId:el}).then(data => {
wx.p.storage.set('merchant_info', {
merchantId: el,
})
wx.p.api.homeApi.getHomeConfig({ merchantId: el }).then(data => {
let {
merchantName,
noticeContent
......@@ -122,18 +128,21 @@ Page({
merchantName,
noticeContent,
bannerList,
merchantId:el
merchantId: el
})
if(storeList.length==2){
storeList.forEach((ele,i)=>{
console.log(i,this.defaultMerchant);
if( this.defaultMerchant==i){
if (storeList.length == 2) {
storeList.forEach((ele, i) => {
console.log(i, this.defaultMerchant);
if (this.defaultMerchant == i) {
index = i
}
})
const currentStore = storeList[index]
console.log(currentStore,index,'currentStore');
console.log(currentStore, index, 'currentStore');
wx.$merchant_id = currentStore.merchantId
wx.p.storage.set('merchant_info', {
merchantId: currentStore.merchantId,
})
this.setData({
storeList,
currentStore
......
......@@ -71,7 +71,9 @@ Component({
},
//获取分类
getCategoryList() {
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
const _params = {
merchantId,
categoryType: '2'
......@@ -90,7 +92,9 @@ Component({
},
//获取商品列表
async getCategoryGoodsList(categoryId) {
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
let _para = {
merchantId,
categoryId,
......@@ -212,7 +216,9 @@ Component({
async getBuyCarList() {
const B_userInfo = wx.p.storage.get('userInfo')
if (B_userInfo && B_userInfo.userType) return;
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
const res = await shopmallApi.getShoppingcartList({
cartType: 4,
merchantId
......@@ -246,7 +252,9 @@ Component({
}
},
getCarOwnerCouponList(){
const merchantId = wx.$merchant_id
const {
merchantId
} = wx.p.storage.get('merchant_info')
couponsApi.getMerchantCouponsListApi({merchantId, discoverGoodsType: 2}).then(res => {
if(res?.length){
this.setData({
......
......@@ -10,9 +10,9 @@ Page({
let {
merchantId
} = this.data
let newMerchantId = wx.$merchant_id
// debugger
console.log(newMerchantId, 'wx.$merchant_id');
const merchantInfo = wx.p.storage.get('merchant_info')
let newMerchantId = merchantInfo.merchantId
if (newMerchantId != merchantId && newMerchantId ) {
this.setData({
merchantId: newMerchantId
......
......@@ -29,17 +29,16 @@ Page({
pageNum: 1,
pageSize: 100
}).then(res => {
console.log(res);
this.setData({
strategyList: res.list
})
});
},
selectStrategy(e) {
console.log(e);
const {id} = e.currentTarget.dataset.item
wx.p.router.go('/packageStrategy/pages/strategyDetail/index', {
id
id,
notIntercept: true
})
}
});
import Router from './router.js'
import routes from './routers.js'
export default new Router(routes)
\ No newline at end of file
import router from "./router.js";
import routerBefore from './routerBefore'
module.exports={
router,
routerBefore
}
\ No newline at end of file
const _routeHooks = Symbol("_routeHooks");
const _query = Symbol("_query");
const _routerList = Symbol("_routerList");
import {
generateRoutList
} from "./wxOnAppRoute.js";
// import { getUserInfo } from '~/utils/cache/userInfo'
import util from "~/utils/util";
// import wxApi from '../utils/utils_wx'
class Router {
[_query] = {};
[_routeHooks] = [];
[_routerList] = [];
constructor(router) {
// console.log(router, 'router')
this[_routerList] = generateRoutList(router);
// console.log(this[_routerList])
wx.onAppRoute &&
wx.onAppRoute((e) => {
let thisPage = this.getPageInstance();
const rootName = this.getRootName();
// console.log(rootName)
if (thisPage) {
if (Object.keys(this[_query]).length)
thisPage.options = {
...thisPage.options,
...this[_query],
};
thisPage.setData({
IMGURL: wx.$imgUrl,
});
// this.setNavigationBarTitleText(thisPage, rootName);
let onRoute = thisPage.onRoute;
typeof thisPage.onRoute === "function" && onRoute(typeof this[_query] == 'object' ? thisPage.options : this[_query]);
// thisPage.$query = this[_query]
thisPage.rootName = rootName;
// let userInfo = util.getUserInfo();
// if (userInfo && userInfo?.phone) {
// if (wx.$authStatus) {
// thisPage.setData({
// userInfo: null,
// });
// } else {
// thisPage.setData({
// userInfo,
// });
// if (thisPage.init) thisPage.init(userInfo);
// }
// }
}
this[_routeHooks].forEach((fn) => {
try {
typeof fn === "function" && fn(e, this[_query], this[_routerList]);
} catch (err) {
console.log(err);
}
});
this[_query] = {};
});
}
/**获取路由列表 */
getRouterList() {
return this[_routerList];
}
/**获取当前分包名 */
getRootName() {
// debugger
let router = `/${this.getPageInstance().__route__}`;
let {
parent
} = this.getRouterList().find((item) => router === item.url);
return parent;
}
constructor(router) {}
/**获取页面对象实例 */
getPageInstance = (size = 1) => {
const pages = getCurrentPages();
return pages[pages.length - size];
};
checkRouter(route, events) {
// console.log(this[_routerList])
// debugger
// this[_query] = events || {}
// const [_parent, _name, last_name] = route.split('.')
// let name = route
// let [parent] = this.getPageInstance().__route__.split('/')
// let query = ''
// // let routerMapItem = {}
// if (route.includes('?')) {
// let [_name_, _query_] = route.split('?')
// query = `?${_query_}`
// name = _name_
// }
// const routerMapItem = {}
// routerMapItem.url = route
// return {
// routerMapItem,
// query
// }
// if (_parent && _name) {
// name = _name.split('?')[0]
// parent = _parent
// }
// /**只传页面名 默认跳转当前包下的页面,相同名称默认第一个 */
// if (!_name && !last_name) {
// name = _parent
// parent = this.getRootName() || parent
// }
// console.log(name)
// console.log(parent)
// // {url: "/packageShopmall/packageEquity/pages/road/index/index", name: "index", parent: "packageShopmall", subPages: "packageEquity"}
// // debugger
// const routerMapItem = this[_routerList].find(item => {
// if (route.includes('/')) {
// return item.url === route
// } else {
// if (last_name) {
// return item.parent === parent && item.name === last_name && item.subPages === name
// } else {
// return item.parent === parent && item.name === name
// }
// }
// })
// if (!routerMapItem) {
// console.error('找不到路由')
// return
// }
}
goHome() {
wx.reLaunch({
url: '/pages/tab/index/index',
/**跳转至H5 */
jumpH5(url, notIntercept) {
if (notIntercept) wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}`,
})
else this.intercept(url).then((response) => {
if (response) return;
wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}`,
});
});
}
/**页面跳转
*
*/
jump(e) {
const item = e.currentTarget.dataset;
this.go(item.url, item);
}
/**
* 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 ||
* 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 $router.back() 可以返回到原页面。小程序中页面栈最多十层
......@@ -149,31 +25,33 @@ class Router {
this._to(
route,
events,
"navigateTo",
(res) => events && res.eventChannel.emit("getData", events)
'navigateTo',
(res) => events && res.eventChannel.emit('getData', events)
);
}
/**关闭所有页面,打开到应用内的某个页面 */
reLaunch(route, events) {
this._to(route, events, "reLaunch");
reLaunch(route, events = {}) {
this._to(route, events, 'reLaunch');
}
/**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */
redirectTo(route, events) {
this._to(route, events, "redirectTo");
redirectTo(route, events = {}) {
this._to(route, events, 'redirectTo');
}
/**
* 跳转到switchTab
*/
switchTab(route, events = {}) {
this._to(route, events, 'switchTab');
}
_to(route, events, to, success) {
const appEnter = wx.getEnterOptionsSync()
if (appEnter.scene === 1154) {
return wx.$eventbus.emit('showTimeLineToast')
}
this[_query] = events || {};
if (this[_query].notIntercept) {
getApp().globalData.ROUTE_QUERY = events
if (events.notIntercept) {
wx[to]({
url: route,
success
});
} else {
this.intercept(route).then((result) => {
this.intercept().then((result) => {
!result && wx[to]({
url: route,
success
......@@ -186,7 +64,7 @@ class Router {
* callBack返回上prevPageSize页对象 */
back(callBack, prevPageSize = 1) {
let prevPage = this.getPageInstance(Number(prevPageSize) + 1);
if (callBack && "function" === typeof callBack) callBack(prevPage);
if (callBack && 'function' === typeof callBack) callBack(prevPage);
wx.navigateBack({
delta: prevPageSize,
}).catch((err) => {
......@@ -198,39 +76,13 @@ class Router {
url: '/pages/tab/index/index',
});
}
/**
* 跳转到switchTab
*/
switchTab(route, events = {}) {
this._to(route, events, 'switchTab');
}
/**跳转至H5 */
jumpH5(url, notIntercept) {
if (notIntercept) wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}`,
})
else this.intercept(url).then((response) => {
if (response) return;
wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}`,
});
});
}
/**获取上一个页面传的数据 */
getData(callBack) {
const data = this.getPageInstance().getOpenerEventChannel();
if (Object.keys(data).length !== 0)
data.on("getData", (res) => callBack(res));
data.on('getData', (res) => callBack(res));
}
onRoute(fn) {
this[_routeHooks].push(fn);
return () => {
const i = list.indexOf(fn);
if (i > -1) list.splice(i, 1);
};
}
/**
/**
*
* @param {*} auto 是否自动跳转到登录,默认自动跳转
* @param {*} callBack true未登录 false已登录
......@@ -248,4 +100,4 @@ class Router {
}
}
export default Router;
\ No newline at end of file
export default new Router();
\ No newline at end of file
class RouterBefore {
constructor(options) {
console.log('---------------- 路由初始化 ----------------')
this.initPageProxy()
}
/**监听页面 */
pageLeaveProxy(thisPage) {
let onLoad = thisPage.onLoad,
onShow = thisPage.onShow
thisPage.onLoad = function () {
const event = getApp().globalData.ROUTE_QUERY
const userInfo = wx.p.storage.get('userInfo')
let options = {
...event,
...arguments[0]
}
getApp().globalData.ROUTE_QUERY = {}
this.setData({
userInfo
})
onLoad && onLoad.apply(this, [options]), (this.options = options)
}
thisPage.onShow = function () {
const userInfo = wx.p.storage.get('userInfo')
onShow && onShow.apply(this, arguments), (this.setData({
userInfo
}))
}
}
/**全局注册事件 */
initPageProxy() {
let thisPage = Page
let _this = this
Page = function (el) {
try {
el || (el = {}), _this.pageLeaveProxy(el), thisPage.apply(this, arguments)
} catch (el) {
thisPage.apply(this, arguments)
}
}
}
}
export default new RouterBefore()
\ No newline at end of file
export default __wxConfig.pages.map(item => ({
url: `/${item}`,
name: item.split('/').pop(),
parent: item.split('/')[0]
}))
\ No newline at end of file
// import util from '../utils/util.js'
// import {
// getUserInfo
// } from '~/utils/cache/userInfo'
/**
* wx.onAppRoute钩子方法,
* 所有的参数都是路由类上的参数
* @param {*} obj.query
* @param {*} obj.routeHooks
* @param {*} obj.routerList
* @param {*} obj.getPageInstance
* @param {*} obj.getRootName
* @param {*} obj.setNavigationBarTitleText
* @param {*} obj.getRouterList
*/
/**
* 生成特定格式路由
*
* @param {*} routerList 路由参数
* @returns
*/
export const generateRoutList = routerList => {
let _routerList = routerList
try {
__wxConfig &&
__wxConfig.tabBar &&
__wxConfig.tabBar.list &&
(_routerList = routerList.map(item => {
let obj = {
...item
}
if (item.parent != '__plugin__') {
if (item.parent !== 'pages') {
// debugger
// console.log(__wxConfig)
let parentList = item.url.split(`/`)
// console.log(parentList)
if (parentList.length > 3) {
item.url = item.url.replace(/\/__plugin__\/[a-z0-9A-Z]+/, '')
// debugger
// console.log(item.url.split(`/${item.parent}/pages/`))
// console.log(item.url.split(`/${item.parent}/pages/`)[1])
// console.log(item.url.split(`/${item.parent}/pages/`)[1].split('/'))
obj.subPages = item.url.split('/')[2]
// console.log(obj.subPages)
}
}
}
return obj
}))
} catch (err) {}
return _routerList
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!