diff --git a/config.js b/config.js new file mode 100644 index 0000000..050532d --- /dev/null +++ b/config.js @@ -0,0 +1,145 @@ +const router_list = [ + { + id: 1, + router_name: "pages/index/index/index", + }, + { + id: 2, + router_name: "pages/user/login/login", + }, + { + id: 3, + router_name: "pages/user/user_index/user", + + }, + { + id: 4, + router_name: "pages/opera/activity_topics/topics", + }, + { + id: 5, + router_name: "pages/make_order/choose_sit/choose_sit", + }, + { + id: 6, + router_name: "pages/make_order/coupon/coupon", + }, + { + id: 7, + router_name: "pages/opera/opera/opera_IP", + }, + { + id: 8, + router_name: "pages/user/my_show/finished_show/finished_show", + }, + { + id: 9, + router_name: "pages/user/my_show/wanted_show/wanted_show", + }, + { + id: 10, + router_name: "pages/user/my_order/my_order", + }, + { + id: 11, + router_name: "pages/user/order_detail/order_detail", + }, + { + id: 12, + router_name: "pages/opera/IP_more/IP_more", + }, + { + id: 13, + router_name: "pages/opera/IP_detail/IP_detail", + }, + { + id: 14, + router_name: "pages/make_order/make_order/make_order", + }, + { + id: 15, + router_name: "pages/make_order/random_sit/random_sit", + }, + { + id: 16, + router_name: "pages/opera/show/show_detail", + }, + { + id: 17, + router_name: "pages/index/search/search", + }, + { + id: 18, + router_name: "pages/user/invoice/invoice_index/invoice_index", + }, + { + id: 19, + router_name: "pages/user/invoice/invoice_edit/invoice_edit_newMake", + }, + { + id: 20, + router_name: "pages/user/invoice/invoice_edit/invoice_edit_content", + }, + { + id: 21, + router_name: "pages/user/invoice/invoice_edit/invoice_edit", + }, + { + id: 22, + router_name: "pages/user/invoice/invoice_history/invoice_history", + }, + { + id: 23, + router_name: "pages/user/invoice/my_invoice/my_invoice", + }, + { + id: 24, + router_name: "pages/user/invoice/make_invoice/make_invoice", + }, + { + id: 25, + router_name: "pages/user/discount/discount/discount", + }, + { + id: 26, + router_name: "pages/user/discount/coupons/coupons", + }, + { + id: 27, + router_name: "pages/user/discount/discount_ex/discount_ex", + }, + { + id: 28, + router_name: "pages/user/discount/discount_avilable/discount_avilable", + }, + { + id: 29, + router_name: "pages/user/auto_service/auto_service", + }, + { + id: 30, + router_name: "pages/user/wallet/wallet/wallet", + }, + { + id: 31, + router_name: "pages/user/wallet/code_exchange/code_exchange", + }, + { + id: 32, + router_name: "pages/user/viewer_list/viewer_list", + }, + { + id: 33, + router_name: "pages/index/calendar/calendar", + + }, + { + id: 34, + router_name: "pages/index/city/selectcity" + + + }, +] +module.exports = { + router_list +} \ No newline at end of file diff --git a/page-extend.js b/page-extend.js index cc2a3b9..6a303c6 100644 --- a/page-extend.js +++ b/page-extend.js @@ -4,20 +4,29 @@ * * @param {*} Page 原生Page */ -import {http,httpUtil} from './utils/util' +import { http, httpUtil, getRouter, location_city } from './utils/util' const pageExtend = Page => { return object => { - + // 导出原生Page传入的object参数中的生命周期函数 // 由于命名冲突,所以将onLoad生命周期函数命名成了onLoaded const { onLoad } = object - + // 公共的onLoad生命周期函数 object.onLoad = function (options) { + wx.getStorageSync('xid') ? "" : this.getxid() + if (!getApp().globalData.city_id) { + location_city().then(res => { + this.getroutermi(options, res.city_info.city_id) + }) + } else { + this.getroutermi(options, getApp().globalData.city_id) + } // 在onLoad中执行的代码 - console.log(getCurrentPages()[getCurrentPages().length-1].route,'拦截页面参数:') + + console.log(getCurrentPages()[getCurrentPages().length - 1].route, '拦截页面参数:') console.log(options) if (options.cps) { let cps = wx.getStorageSync("cps") || null @@ -28,16 +37,16 @@ const pageExtend = Page => { }, { vTime: vTime }) - if(getApp().globalData.uid){ - http('/api/v1/save-cps','get',{cps:options.cps,route:getCurrentPages()[getCurrentPages().length-1].route}).then(res=>{ + if (getApp().globalData.uid) { + http('/api/v1/save-cps', 'get', { cps: options.cps, route: getCurrentPages()[getCurrentPages().length - 1].route }).then(res => { wx.setStorageSync('cps', cps) }) - }else{ - httpUtil('/api/v1/save-cps','get',{cps:options.cps,route:getCurrentPages()[getCurrentPages().length-1].route}).then(res=>{ + } else { + httpUtil('/api/v1/save-cps', 'get', { cps: options.cps, route: getCurrentPages()[getCurrentPages().length - 1].route }).then(res => { wx.setStorageSync('cps', cps) }) } - + } } @@ -45,8 +54,24 @@ const pageExtend = Page => { if (typeof onLoad === 'function') { onLoad.call(this, options) } - } + } + object.getroutermi = function (option, cityId) { + let xid = wx.getStorageSync('xid') + if (new Date().getTime() > xid.substring(0, xid.length - 4) - 0 + 1200000) { + this.getxid() + } + let data = { xid:wx.getStorageSync('xid'),action_id:getRouter(getCurrentPages()[getCurrentPages().length - 1].route),city_id:cityId-0,mini_type:1,...option} + http('/api/v1/user-behavior', 'post', data).then(res => { + console.log(res,'res'); + }) + } + object.getxid = function () { + // console.log(new Date().getTime(),'min'); + // console.log(new Date().getTime()+(Math.floor(Math.random()*(9999-1000))+1000).toString(),'min'); + let xid = new Date().getTime() + (Math.floor(Math.random() * (9999 - 1000)) + 1000).toString() + wx.setStorageSync('xid', xid) + } return Page(object) } } @@ -54,4 +79,4 @@ const pageExtend = Page => { // 获取原生Page const originalPage = Page // 定义一个新的Page,将原生Page传入Page扩展函数 -Page = pageExtend(originalPage) +Page = pageExtend(originalPage) \ No newline at end of file diff --git a/project.config.json b/project.config.json index ef3c20c..bf1aae0 100644 --- a/project.config.json +++ b/project.config.json @@ -39,7 +39,7 @@ "minifyWXSS": true }, "compileType": "miniprogram", - "libVersion": "2.17.3", + "libVersion": "2.20.0", "appid": "wx35bc60d481961c1d", "projectname": "miniprogram2", "debugOptions": { diff --git a/utils/util.js b/utils/util.js index 2586848..96ef124 100644 --- a/utils/util.js +++ b/utils/util.js @@ -1,6 +1,18 @@ import { host } from '../Gdata' +import { router_list } from '../config' +const getRouter = function () { + var pages = getCurrentPages() //获取加载的页面 + var currentPage = pages[pages.length - 1] //获取当前页面的对象 + let id = '' + router_list.forEach(item => { + if (item.router_name == currentPage.route) { + id = item.id + } + }) + return id +} const formatTime = date => { const year = date.getFullYear() const month = date.getMonth() + 1 @@ -137,7 +149,7 @@ const login_check = n => { // url: '/pages/user/user_index/user' // }) wx.navigateTo({ - url: '/pages/user/login/login', + url: '/pages/user/login/login', }) } setTimeout(gologin, 2000); @@ -156,7 +168,7 @@ const login_check = n => { // }) wx.navigateTo({ url: '/pages/user/login/login', - }) + }) } else if (res.cancel) { console.log('用户点击取消') } @@ -177,7 +189,7 @@ const location_city = function () { httpUtil("/api/v1/get-city", "get", { latitude, longitude, - type:1 + type: 1 }).then(res1 => { resolve(res1) }) @@ -192,7 +204,7 @@ const location_city = function () { httpUtil("/api/v1/get-city", "get", { longitude: res.longitude, latitude: res.latitude, - type:1 + type: 1 }).then(res1 => { resolve(res1) }) @@ -222,7 +234,7 @@ const setting = function () { // url: '/pages/index/index/index', // }) wx.navigateBack({ - delta: 0, + delta: 0, }) } else { wx.showToast({ @@ -249,7 +261,7 @@ const setting = function () { showCancel: false, content: '请在系统设置中打开微信定位服务', confirmText: '确定', - success: function (res) {} + success: function (res) { } }) } } @@ -262,5 +274,6 @@ module.exports = { httpUtil, http, login_check, - location_city + location_city, + getRouter }