Commit d44f798a by 杨北旺

提交

1 parent f8ca9b35
import { preReleaseAppId } from '~/config' import { preReleaseAppId } from '~/config'
const target = ['ip', 'dev', 'uat', 'prod', 'preRelease'] const target = ['ip', 'dev', 'uat', 'prod', 'preRelease']
let index = 2 let index = 1
/** /**
* *
......
...@@ -3,11 +3,9 @@ ...@@ -3,11 +3,9 @@
import sentryInit from "~/utils/sentryConfig/sentryInit"; import sentryInit from "~/utils/sentryConfig/sentryInit";
sentryInit(); sentryInit();
import api from "./api/index"; import api from "./api/index";
// import { router } from "./router/index"; import { router } from "./router/index";
import router from "./router/index.js";
// 判断小程序是否需要更新 // 判断小程序是否需要更新
import { getUpdateManager } from "./lib/index"; import { getUpdateManager } from "./lib/index";
import {IMG_URL} from '~/config'
import utils from "./utils/index"; import utils from "./utils/index";
// 埋点 有需要再引入 // 埋点 有需要再引入
import TRACK from './utils/track/Track' import TRACK from './utils/track/Track'
...@@ -24,18 +22,8 @@ App({ ...@@ -24,18 +22,8 @@ App({
router, router,
storage: new utils.cache.Storage(), storage: new utils.cache.Storage(),
$Track: new TRACK(options), $Track: new TRACK(options),
IMGURL:IMG_URL
}; };
// console.log(wx.p); console.log(wx.p);
// const {
// scene,
// query,
// query: {
// pageType
// }
// } = wx.getEnterOptionsSync()
// console.log(scene,query,pageType,'二次扫码');
// 存储设备信息 // 存储设备信息
utils.cache.storageApi.setSystem_info(); utils.cache.storageApi.setSystem_info();
}, },
......
...@@ -114,18 +114,7 @@ ...@@ -114,18 +114,7 @@
"pages/index/index" "pages/index/index"
], ],
"plugins": { "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({ ...@@ -111,8 +111,9 @@ Page({
}, },
onLoad(options) { onLoad(options) {
let system = wx.getSystemInfoSync() let system = wx.getSystemInfoSync()
// const merchantId = wx.$storage.get('srcm_shopmall_merchant_id') const {
const merchantId = wx.$merchant_id merchantId
} = wx.p.storage.get('merchant_info')
let newMerchantId = merchantId || defaultMerchantId let newMerchantId = merchantId || defaultMerchantId
if (options && options.scene) { if (options && options.scene) {
......
...@@ -16,7 +16,7 @@ Page({ ...@@ -16,7 +16,7 @@ Page({
}, },
onRoute(e) { onLoad(e) {
let { titleList } = this.data let { titleList } = this.data
if (e && e.title) { if (e && e.title) {
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
......
...@@ -15,7 +15,10 @@ Page({ ...@@ -15,7 +15,10 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
this.getHomeConfig(wx.$merchant_id) const {
merchantId
} = wx.p.storage.get('merchant_info')
this.getHomeConfig(merchantId)
this.getAllMerchantList() this.getAllMerchantList()
}, },
getHomeConfig(merchantId) { getHomeConfig(merchantId) {
...@@ -74,7 +77,9 @@ Page({ ...@@ -74,7 +77,9 @@ Page({
}) })
}, },
getAllMerchantList() { getAllMerchantList() {
let merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = { let para = {
merchantId merchantId
} }
......
...@@ -53,7 +53,9 @@ Page({ ...@@ -53,7 +53,9 @@ Page({
}, },
getAllMerchantList() { getAllMerchantList() {
let merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = { let para = {
merchantId merchantId
} }
......
...@@ -396,7 +396,7 @@ Page({ ...@@ -396,7 +396,7 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onRoute: function (options) { onLoad: function (options) {
// debugger // debugger
console.log(options,'options'); console.log(options,'options');
if(options&&options.openId){ if(options&&options.openId){
......
...@@ -66,8 +66,9 @@ Page({ ...@@ -66,8 +66,9 @@ Page({
}) })
}, },
getMerchantCouponList(){ getMerchantCouponList(){
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id') const {
const merchantId = wx.$merchant_id merchantId
} = wx.p.storage.get('merchant_info')
couponsApi.getMerchantCouponsListApi({merchantId,discoverGoodsType:this.options.discoverGoodsType}).then(res => { couponsApi.getMerchantCouponsListApi({merchantId,discoverGoodsType:this.options.discoverGoodsType}).then(res => {
if(res?.length) { if(res?.length) {
res.forEach(item =>{ res.forEach(item =>{
...@@ -80,8 +81,9 @@ Page({ ...@@ -80,8 +81,9 @@ Page({
}) })
}, },
receiveCoupon(){ receiveCoupon(){
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id') const {
const merchantId = wx.$merchant_id merchantId
} = wx.p.storage.get('merchant_info')
let couponIds = this.data.couponList?.map(item => item.couponId) let couponIds = this.data.couponList?.map(item => item.couponId)
wx.p.wxApi.showLoading() wx.p.wxApi.showLoading()
couponsApi.batchGetMerchantCouponsApi({merchantId,couponIds,discoverGoodsType:this.options.discoverGoodsType}).then(res => { couponsApi.batchGetMerchantCouponsApi({merchantId,couponIds,discoverGoodsType:this.options.discoverGoodsType}).then(res => {
...@@ -114,8 +116,9 @@ Page({ ...@@ -114,8 +116,9 @@ Page({
}, 1 * 1000) }, 1 * 1000)
}, },
JumpDiscoverPage(){ JumpDiscoverPage(){
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id') const {
const merchantId = wx.$merchant_id merchantId
} = wx.p.storage.get('merchant_info')
const channel = this.options.discoverGoodsType==1 ? 5 : 6 const channel = this.options.discoverGoodsType==1 ? 5 : 6
wx.$router.reLaunch(`/packageDiscovery/pages/index/index?merchantId=${merchantId}&channel=${channel}`, { notIntercept: true }) wx.$router.reLaunch(`/packageDiscovery/pages/index/index?merchantId=${merchantId}&channel=${channel}`, { notIntercept: true })
}, },
...@@ -152,8 +155,9 @@ Page({ ...@@ -152,8 +155,9 @@ Page({
this.setData({ this.setData({
sessionId: '', sessionId: '',
}) })
// const merchantId = wx.p.storage.get('srcm_shopmall_merchant_id') const {
const merchantId = wx.$merchant_id merchantId
} = wx.p.storage.get('merchant_info')
couponsApi.getMerchantCouponsListApi({merchantId,discoverGoodsType:this.options.discoverGoodsType}).then(res => { couponsApi.getMerchantCouponsListApi({merchantId,discoverGoodsType:this.options.discoverGoodsType}).then(res => {
if(res?.length) { if(res?.length) {
this.receiveCoupon() this.receiveCoupon()
......
...@@ -12,7 +12,7 @@ Page({ ...@@ -12,7 +12,7 @@ Page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onRoute(options) { onLoad(options) {
this.setData({ this.setData({
goodsInfo: options goodsInfo: options
}) })
......
...@@ -84,8 +84,9 @@ Page({ ...@@ -84,8 +84,9 @@ Page({
}) })
}, },
getAllMerchantList() { getAllMerchantList() {
// let merchantId = wx.p.storage.get('srcm_shopmall_merchant_id') const {
let merchantId = wx.$merchant_id merchantId
} = wx.p.storage.get('merchant_info')
let para = { let para = {
merchantId merchantId
} }
......
import { IMG_URL } from '~/config';
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
IMGURL:IMG_URL,
isOpen: false, isOpen: false,
openingStatus: false openingStatus: false
}, },
// 获取门店会员卡信息 // 获取门店会员卡信息
getMemberCardData() { getMemberCardData() {
const merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = { let para = {
merchantId: merchantId merchantId: merchantId
} }
......
...@@ -6,7 +6,11 @@ Page({ ...@@ -6,7 +6,11 @@ Page({
}, },
onLoad(options) { 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.firstEnter = true
this.getStrategyDetail(options.id); this.getStrategyDetail(options.id);
// 触发埋点 // 触发埋点
...@@ -15,20 +19,9 @@ Page({ ...@@ -15,20 +19,9 @@ Page({
item_type: 6, item_type: 6,
view: 1 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) { getStrategyDetail(id) {
wx.p.api.strategyApi wx.p.api.strategyApi
...@@ -39,6 +32,8 @@ Page({ ...@@ -39,6 +32,8 @@ Page({
Util.setNavigationBarTitle(res.strategyName); Util.setNavigationBarTitle(res.strategyName);
this.setData({ this.setData({
strategyDetailObj: res, strategyDetailObj: res,
}, () => {
this.handlerShareQuery()
}); });
}); });
}, },
...@@ -53,7 +48,9 @@ Page({ ...@@ -53,7 +48,9 @@ Page({
const { id, item_type, view } = query; const { id, item_type, view } = query;
const userInfo = wx.p.cache.userInfo.getUserInfo() || {}, const userInfo = wx.p.cache.userInfo.getUserInfo() || {},
{ openId } = await USERAPI.getWXUserInfo(); { openId } = await USERAPI.getWXUserInfo();
console.log(wx.$merchant_id, "======="); const {
merchantId
} = wx.p.storage.get('merchant_info')
let data = { let data = {
open_id: openId || null, open_id: openId || null,
create_time: this.firstEnter create_time: this.firstEnter
...@@ -66,7 +63,7 @@ Page({ ...@@ -66,7 +63,7 @@ Page({
item_id: id, item_id: id,
business_type: 1, business_type: 1,
add_way: 104, add_way: 104,
merchant_id: wx.$merchant_id, merchant_id: merchantId,
guest_no: wx.p.$Track.getGuestNo(), //游客ID, guest_no: wx.p.$Track.getGuestNo(), //游客ID,
user_open_id: this.shareOpenId || "", user_open_id: this.shareOpenId || "",
}; };
...@@ -95,28 +92,28 @@ Page({ ...@@ -95,28 +92,28 @@ Page({
// wx.$util.customerbehavior(2); // wx.$util.customerbehavior(2);
}, },
/** handlerShareQuery() {
* 用户点击右上角分享 const {
*/ merchantId
onShareAppMessage: function () { } = wx.p.storage.get('merchant_info')
const merchantId = wx.$merchant_id;
const userInfo = wx.p.cache.userInfo.getUserInfo(); const userInfo = wx.p.cache.userInfo.getUserInfo();
let { strategyDetailObj } = this.data, let { strategyDetailObj } = this.data,
open_id = ""; open_id = "";
console.log(strategyDetailObj, '9999999999');
this.trackQuery.view = 4;
this.addTrack(this.trackQuery);
if (userInfo) open_id = userInfo.openId; if (userInfo) open_id = userInfo.openId;
let title = strategyDetailObj.strategyName;
let path = `${this.route}?id=${strategyDetailObj.id}&openId=${open_id}`; let path = `id=${strategyDetailObj.id}&openId=${open_id}`;
let imageUrl = strategyDetailObj.strategyImg;
if (merchantId) path = `${path}&merchantId=${merchantId}`; if (merchantId) path = `${path}&merchantId=${merchantId}`;
console.log(path); this.shareTitle = strategyDetailObj.strategyName;
console.log(imageUrl, title); this.shareImage = strategyDetailObj.strategyImg
return { this.shareQuery = path
imageUrl, this.trackQuery.view = 4;
title, this.shareFun = () => {
path, this.addTrack(this.trackQuery);
}; }
}, },
onShareAppMessage: function () {
}
}); });
...@@ -26,7 +26,12 @@ Page({ ...@@ -26,7 +26,12 @@ Page({
async login(options = {}) { async login(options = {}) {
console.log(options, 'options.merchantId') console.log(options, 'options.merchantId')
// wx.p.router.goHome() // 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 { try {
const { code, data, message } = await wx.p.api.userApi.login() const { code, data, message } = await wx.p.api.userApi.login()
wx.$LoginStatus = code != 0 wx.$LoginStatus = code != 0
......
...@@ -133,7 +133,9 @@ Page({ ...@@ -133,7 +133,9 @@ Page({
) )
}, },
getAllMerchantList() { getAllMerchantList() {
let merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
let para = { let para = {
merchantId merchantId
} }
......
...@@ -89,9 +89,12 @@ Page({ ...@@ -89,9 +89,12 @@ Page({
// 门店切换 // 门店切换
changeStore(e) { changeStore(e) {
const index = +e.detail.value const index = +e.detail.value
const {storeList} = this.data const { storeList } = this.data
const currentStore = storeList[index] const currentStore = storeList[index]
wx.$merchant_id = currentStore.merchantId wx.$merchant_id = currentStore.merchantId
wx.p.storage.set('merchant_info', {
merchantId: currentStore.merchantId,
})
this.setData({ this.setData({
currentStore currentStore
}) })
...@@ -102,16 +105,19 @@ Page({ ...@@ -102,16 +105,19 @@ Page({
getMerchantList() { getMerchantList() {
const merchantObj = { const merchantObj = {
'develop': [44211227, 44209845], 'develop': [44211227, 44209845],
'test': [44212577,44210895, 44212578,44210956], 'test': [44212577, 44210895, 44212578, 44210956],
'beta': [], 'beta': [],
'production': [44209566, 44209565], 'production': [44209566, 44209565],
} }
const MerchantList = merchantObj[env] const MerchantList = merchantObj[env]
console.log(MerchantList,'MerchantList'); console.log(MerchantList, 'MerchantList');
let storeList = [],index = 0 let storeList = [], index = 0
MerchantList.forEach((el,i) => { MerchantList.forEach((el, i) => {
wx.$merchant_id = el 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 { let {
merchantName, merchantName,
noticeContent noticeContent
...@@ -122,18 +128,21 @@ Page({ ...@@ -122,18 +128,21 @@ Page({
merchantName, merchantName,
noticeContent, noticeContent,
bannerList, bannerList,
merchantId:el merchantId: el
}) })
if(storeList.length==2){ if (storeList.length == 2) {
storeList.forEach((ele,i)=>{ storeList.forEach((ele, i) => {
console.log(i,this.defaultMerchant); console.log(i, this.defaultMerchant);
if( this.defaultMerchant==i){ if (this.defaultMerchant == i) {
index = i index = i
} }
}) })
const currentStore = storeList[index] const currentStore = storeList[index]
console.log(currentStore,index,'currentStore'); console.log(currentStore, index, 'currentStore');
wx.$merchant_id = currentStore.merchantId wx.$merchant_id = currentStore.merchantId
wx.p.storage.set('merchant_info', {
merchantId: currentStore.merchantId,
})
this.setData({ this.setData({
storeList, storeList,
currentStore currentStore
......
...@@ -71,7 +71,9 @@ Component({ ...@@ -71,7 +71,9 @@ Component({
}, },
//获取分类 //获取分类
getCategoryList() { getCategoryList() {
const merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
const _params = { const _params = {
merchantId, merchantId,
categoryType: '2' categoryType: '2'
...@@ -90,7 +92,9 @@ Component({ ...@@ -90,7 +92,9 @@ Component({
}, },
//获取商品列表 //获取商品列表
async getCategoryGoodsList(categoryId) { async getCategoryGoodsList(categoryId) {
const merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
let _para = { let _para = {
merchantId, merchantId,
categoryId, categoryId,
...@@ -212,7 +216,9 @@ Component({ ...@@ -212,7 +216,9 @@ Component({
async getBuyCarList() { async getBuyCarList() {
const B_userInfo = wx.p.storage.get('userInfo') const B_userInfo = wx.p.storage.get('userInfo')
if (B_userInfo && B_userInfo.userType) return; 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({ const res = await shopmallApi.getShoppingcartList({
cartType: 4, cartType: 4,
merchantId merchantId
...@@ -246,7 +252,9 @@ Component({ ...@@ -246,7 +252,9 @@ Component({
} }
}, },
getCarOwnerCouponList(){ getCarOwnerCouponList(){
const merchantId = wx.$merchant_id const {
merchantId
} = wx.p.storage.get('merchant_info')
couponsApi.getMerchantCouponsListApi({merchantId, discoverGoodsType: 2}).then(res => { couponsApi.getMerchantCouponsListApi({merchantId, discoverGoodsType: 2}).then(res => {
if(res?.length){ if(res?.length){
this.setData({ this.setData({
......
...@@ -10,9 +10,9 @@ Page({ ...@@ -10,9 +10,9 @@ Page({
let { let {
merchantId merchantId
} = this.data } = this.data
let newMerchantId = wx.$merchant_id const merchantInfo = wx.p.storage.get('merchant_info')
// debugger let newMerchantId = merchantInfo.merchantId
console.log(newMerchantId, 'wx.$merchant_id');
if (newMerchantId != merchantId && newMerchantId ) { if (newMerchantId != merchantId && newMerchantId ) {
this.setData({ this.setData({
merchantId: newMerchantId merchantId: newMerchantId
......
...@@ -29,17 +29,16 @@ Page({ ...@@ -29,17 +29,16 @@ Page({
pageNum: 1, pageNum: 1,
pageSize: 100 pageSize: 100
}).then(res => { }).then(res => {
console.log(res);
this.setData({ this.setData({
strategyList: res.list strategyList: res.list
}) })
}); });
}, },
selectStrategy(e) { selectStrategy(e) {
console.log(e);
const {id} = e.currentTarget.dataset.item const {id} = e.currentTarget.dataset.item
wx.p.router.go('/packageStrategy/pages/strategyDetail/index', { 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 \ 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 \ 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 { class Router {
[_query] = {}; constructor(router) {}
[_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;
}
/**获取页面对象实例 */ /**获取页面对象实例 */
getPageInstance = (size = 1) => { getPageInstance = (size = 1) => {
const pages = getCurrentPages(); const pages = getCurrentPages();
return pages[pages.length - size]; return pages[pages.length - size];
}; };
checkRouter(route, events) { /**跳转至H5 */
// console.log(this[_routerList]) jumpH5(url, notIntercept) {
// debugger if (notIntercept) wx.navigateTo({
// this[_query] = events || {} url: `/pages/webView/webView?url=${encodeURIComponent(url)}`,
// const [_parent, _name, last_name] = route.split('.') })
// let name = route else this.intercept(url).then((response) => {
// let [parent] = this.getPageInstance().__route__.split('/') if (response) return;
// let query = '' wx.navigateTo({
// // let routerMapItem = {} url: `/pages/webView/webView?url=${encodeURIComponent(url)}`,
// 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',
}); });
}
/**页面跳转
*
*/
jump(e) {
const item = e.currentTarget.dataset;
this.go(item.url, item);
} }
/** /**
* 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 || * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面 ||
...@@ -149,31 +25,33 @@ class Router { ...@@ -149,31 +25,33 @@ class Router {
this._to( this._to(
route, route,
events, events,
"navigateTo", 'navigateTo',
(res) => events && res.eventChannel.emit("getData", events) (res) => events && res.eventChannel.emit('getData', events)
); );
} }
/**关闭所有页面,打开到应用内的某个页面 */ /**关闭所有页面,打开到应用内的某个页面 */
reLaunch(route, events) { reLaunch(route, events = {}) {
this._to(route, events, "reLaunch"); this._to(route, events, 'reLaunch');
} }
/**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */ /**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */
redirectTo(route, events) { redirectTo(route, events = {}) {
this._to(route, events, "redirectTo"); this._to(route, events, 'redirectTo');
} }
_to(route, events, to, success) { /**
const appEnter = wx.getEnterOptionsSync() * 跳转到switchTab
if (appEnter.scene === 1154) { */
return wx.$eventbus.emit('showTimeLineToast') switchTab(route, events = {}) {
this._to(route, events, 'switchTab');
} }
this[_query] = events || {}; _to(route, events, to, success) {
if (this[_query].notIntercept) { getApp().globalData.ROUTE_QUERY = events
if (events.notIntercept) {
wx[to]({ wx[to]({
url: route, url: route,
success success
}); });
} else { } else {
this.intercept(route).then((result) => { this.intercept().then((result) => {
!result && wx[to]({ !result && wx[to]({
url: route, url: route,
success success
...@@ -186,7 +64,7 @@ class Router { ...@@ -186,7 +64,7 @@ class Router {
* callBack返回上prevPageSize页对象 */ * callBack返回上prevPageSize页对象 */
back(callBack, prevPageSize = 1) { back(callBack, prevPageSize = 1) {
let prevPage = this.getPageInstance(Number(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({ wx.navigateBack({
delta: prevPageSize, delta: prevPageSize,
}).catch((err) => { }).catch((err) => {
...@@ -198,38 +76,12 @@ class Router { ...@@ -198,38 +76,12 @@ class Router {
url: '/pages/tab/index/index', 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) { getData(callBack) {
const data = this.getPageInstance().getOpenerEventChannel(); const data = this.getPageInstance().getOpenerEventChannel();
if (Object.keys(data).length !== 0) 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 {*} auto 是否自动跳转到登录,默认自动跳转
...@@ -248,4 +100,4 @@ class Router { ...@@ -248,4 +100,4 @@ class Router {
} }
} }
export default Router;
\ No newline at end of file \ No newline at end of file
export default new Router();
\ No newline at end of file \ 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 \ 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 \ 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!