feat 页面访问记录

develop
GJW200011 4 years ago
parent 01708bce28
commit 89a4b28f76

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

@ -4,20 +4,29 @@
* *
* @param {*} Page 原生Page * @param {*} Page 原生Page
*/ */
import {http,httpUtil} from './utils/util' import { http, httpUtil, getRouter, location_city } from './utils/util'
const pageExtend = Page => { const pageExtend = Page => {
return object => { return object => {
// 导出原生Page传入的object参数中的生命周期函数 // 导出原生Page传入的object参数中的生命周期函数
// 由于命名冲突所以将onLoad生命周期函数命名成了onLoaded // 由于命名冲突所以将onLoad生命周期函数命名成了onLoaded
const { const {
onLoad onLoad
} = object } = object
// 公共的onLoad生命周期函数 // 公共的onLoad生命周期函数
object.onLoad = function (options) { 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中执行的代码 // 在onLoad中执行的代码
console.log(getCurrentPages()[getCurrentPages().length-1].route,'拦截页面参数:')
console.log(getCurrentPages()[getCurrentPages().length - 1].route, '拦截页面参数:')
console.log(options) console.log(options)
if (options.cps) { if (options.cps) {
let cps = wx.getStorageSync("cps") || null let cps = wx.getStorageSync("cps") || null
@ -28,16 +37,16 @@ const pageExtend = Page => {
}, { }, {
vTime: vTime vTime: vTime
}) })
if(getApp().globalData.uid){ if (getApp().globalData.uid) {
http('/api/v1/save-cps','get',{cps:options.cps,route:getCurrentPages()[getCurrentPages().length-1].route}).then(res=>{ http('/api/v1/save-cps', 'get', { cps: options.cps, route: getCurrentPages()[getCurrentPages().length - 1].route }).then(res => {
wx.setStorageSync('cps', cps) wx.setStorageSync('cps', cps)
}) })
}else{ } else {
httpUtil('/api/v1/save-cps','get',{cps:options.cps,route:getCurrentPages()[getCurrentPages().length-1].route}).then(res=>{ httpUtil('/api/v1/save-cps', 'get', { cps: options.cps, route: getCurrentPages()[getCurrentPages().length - 1].route }).then(res => {
wx.setStorageSync('cps', cps) wx.setStorageSync('cps', cps)
}) })
} }
} }
} }
@ -45,8 +54,24 @@ const pageExtend = Page => {
if (typeof onLoad === 'function') { if (typeof onLoad === 'function') {
onLoad.call(this, options) 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) return Page(object)
} }
} }
@ -54,4 +79,4 @@ const pageExtend = Page => {
// 获取原生Page // 获取原生Page
const originalPage = Page const originalPage = Page
// 定义一个新的Page将原生Page传入Page扩展函数 // 定义一个新的Page将原生Page传入Page扩展函数
Page = pageExtend(originalPage) Page = pageExtend(originalPage)

@ -39,7 +39,7 @@
"minifyWXSS": true "minifyWXSS": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.17.3", "libVersion": "2.20.0",
"appid": "wx35bc60d481961c1d", "appid": "wx35bc60d481961c1d",
"projectname": "miniprogram2", "projectname": "miniprogram2",
"debugOptions": { "debugOptions": {

@ -1,6 +1,18 @@
import { import {
host host
} from '../Gdata' } 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 formatTime = date => {
const year = date.getFullYear() const year = date.getFullYear()
const month = date.getMonth() + 1 const month = date.getMonth() + 1
@ -137,7 +149,7 @@ const login_check = n => {
// url: '/pages/user/user_index/user' // url: '/pages/user/user_index/user'
// }) // })
wx.navigateTo({ wx.navigateTo({
url: '/pages/user/login/login', url: '/pages/user/login/login',
}) })
} }
setTimeout(gologin, 2000); setTimeout(gologin, 2000);
@ -156,7 +168,7 @@ const login_check = n => {
// }) // })
wx.navigateTo({ wx.navigateTo({
url: '/pages/user/login/login', url: '/pages/user/login/login',
}) })
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消') console.log('用户点击取消')
} }
@ -177,7 +189,7 @@ const location_city = function () {
httpUtil("/api/v1/get-city", "get", { httpUtil("/api/v1/get-city", "get", {
latitude, latitude,
longitude, longitude,
type:1 type: 1
}).then(res1 => { }).then(res1 => {
resolve(res1) resolve(res1)
}) })
@ -192,7 +204,7 @@ const location_city = function () {
httpUtil("/api/v1/get-city", "get", { httpUtil("/api/v1/get-city", "get", {
longitude: res.longitude, longitude: res.longitude,
latitude: res.latitude, latitude: res.latitude,
type:1 type: 1
}).then(res1 => { }).then(res1 => {
resolve(res1) resolve(res1)
}) })
@ -222,7 +234,7 @@ const setting = function () {
// url: '/pages/index/index/index', // url: '/pages/index/index/index',
// }) // })
wx.navigateBack({ wx.navigateBack({
delta: 0, delta: 0,
}) })
} else { } else {
wx.showToast({ wx.showToast({
@ -249,7 +261,7 @@ const setting = function () {
showCancel: false, showCancel: false,
content: '请在系统设置中打开微信定位服务', content: '请在系统设置中打开微信定位服务',
confirmText: '确定', confirmText: '确定',
success: function (res) {} success: function (res) { }
}) })
} }
} }
@ -262,5 +274,6 @@ module.exports = {
httpUtil, httpUtil,
http, http,
login_check, login_check,
location_city location_city,
getRouter
} }

Loading…
Cancel
Save