import * as UTIL from '../../utils/util.js'; import * as API from '../../utils/API.js'; Page({ /** * 页面的初始数据 */ data: { //底部自定义tabbar isSHowZDYTabBar: true, //底部弹框显示 showDownTS: true, //顶部胶囊按钮位置信息rect CustomMenuButton: null, BarMarginLeft: 0, BarWidth: 0, list: [], isIPhoneX:false }, /** * 计算bar 高度 */ computeBarLocation() { var that = this; let CustomMenuButton = wx.getMenuButtonBoundingClientRect(); let CustomMenuButton_margin_right = wx.getSystemInfoSync().windowWidth - CustomMenuButton.right; let bar_margin_left = CustomMenuButton_margin_right + CustomMenuButton.width; let bar_width = wx.getSystemInfoSync().windowWidth - CustomMenuButton_margin_right * 2 - CustomMenuButton.width * 2; console.log("bar宽:" + bar_width + ";窗口宽度" + wx.getSystemInfoSync().windowWidth); that.setData({ CustomMenuButton: CustomMenuButton, BarMarginLeft: bar_margin_left, BarWidth: bar_width }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; that.simulativeData(); that.computeBarLocation(); that.setData({ isIPhoneX:UTIL.isIPhoneX() }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, onItemClickMethod: function (e) { var that = this; var num = parseInt(e.currentTarget.id); console.log(num) switch (num) { case 0: //更新机制 break; case 1: //网络访问 that.httpTestMethod(); break; case 4: //获取地理位置 that.getLocationInfo(); break; case 5: //全局loading that.showLoadingIcon(); break; case 6: that.showModalConentMethod(); break; case 7: that.showModalAllMethod(); break; } }, /** * 获取地理位置 */ getLocationInfo() { UTIL.getLocationFromWX( { success: (res) => { UTIL.showToastNoneIcon("当前经纬度:" + getApp().globalData.setInfo.latitude + "," + getApp().globalData.setInfo.longitude) } , fail: (res) => { // wx.navigateTo({ // url: '/pages/wxAuth/wxAuth', // }) } } ); } , /** * loading小图标 */ showLoadingIcon() { UTIL.showLoadingHaveMask('数据加载中...'); setTimeout(function () { UTIL.hideLoadingHaveMask(); }, 2000) } , /** * 显示提示框 */ showModalConentMethod() { UTIL.showModalNoneCancel('温馨提示', '这是一个按钮的弹框', '知道了'); }, /** * 显示完整提示框 并监听 */ showModalAllMethod() { UTIL.showModalOnClick('提示', '两个按钮并回调', 'OK', 'NO', { confirm() { UTIL.showToastNoneIcon('点击了OK'); } , cancel() { UTIL.showToastNoneIcon('点击了NO'); } }); } , //底部弹框允许 okOnClick(e) { console.log("底部弹框-允许"); UTIL.showToastNoneIcon("底部弹框-允许"); this.setData({ showDownTS: true }) }, /** * 底部弹框-黑色背景点击 */ blackOnClick() { this.setData({ showDownTS: true }) } , /** * 底部弹框拒绝 */ refuseOnClick() { console.log("底部弹框-拒绝"); UTIL.showToastNoneIcon("底部弹框-拒绝"); this.setData({ showDownTS: true }) }, bindgetUserProfile(e) { UTIL.getUserInfoFomWX({ success(res){ UTIL.showToastNoneIcon("获取到昵称:"+getApp().globalData.wxUserInfo.nickName); } }); } , /** * 网络访问 */ httpTestMethod() { let sendData = { centerShopId: 10000, centerWarehouseId: 10051, channel: 220, channelType: 22, memberId: 24892, rows: 40, shopId: 10005, token: "LWXAPP1636599316684iv6qkhyqhr4izg", v: 3, warehouseId: 10005 } // UTIL.httpRequest(API.URL_ZB_RECOMMEND_LIST, sendData, // { // success: (res) => { // if (res._code == API.SUCCESS_CODE) { // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条"); // } else { // UTIL.showToastNoneIcon(res._msg) // } // }, // fail: (res) => { // UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP) // }, // complete: (res) => { // } // }); } , /** * 模拟数据 */ simulativeData() { let list = [ { title: '更新机制(已嵌入)', },{ title: '网络访问(点击获取)' },{ title: '自动申请微信地理授权(已嵌入)' },{ title: '获取微信OPenId(已嵌入)' },{ title: '获取微信地理位置(点击获取)', tapBtn: 'getLocationInfo' },{ title: 'loading小图标', tapBtn: 'showLoadingIcon' },{ title: 'Modal弹框仅提示', tapBtn: 'showModalConentMethod', },{ title: 'Modal两个按钮并监听', tapBtn: 'showModalAllMethod' } ]; this.setData({ list: list, }) } })