import { getAppInstance } from '../../utils/app' import { getCustomerData, getSupplierData } from '../../utils/index' const app = getAppInstance() Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ async onLoad() { this.calcInputWidth(); const deviceCode = wx.getStorageSync('deviceCode'); if (!deviceCode) { const newCode = this.generateRandomString(32); //32位设备码 wx.setStorageSync('deviceCode',newCode); } // setTimeout(() => { const userInfo = wx.getStorageSync('userInfo') if (userInfo && userInfo.id) { await getCustomerData(); await getSupplierData(); wx.switchTab({url: '/pages/cardBoardOrder/cardBoardOrder'}) // wx.switchTab({url: '/pages/cardBoardDeliveryOrder/cardBoardDeliveryOrder'}) }else { wx.navigateTo({url: '/pages/login/login'}) } // }, 1000); }, // 生成随机码 :设备码 generateRandomString(length:Number) { let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; }, // 获取input宽度 calcInputWidth() { try { // 1. 获取系统信息(屏幕宽度) const systemInfo = wx.getSystemInfoSync() const screenWidth = systemInfo.screenWidth // 屏幕宽度(px) // 2. 计算屏幕85%的宽度(保留1位小数,避免像素偏差) const targetWidth = (screenWidth * 0.85).toFixed(1); const targetWidthW = (screenWidth * 0.95).toFixed(1); app.globalData.inputWidth = Number(targetWidth); app.globalData.inputWidthW = Number(targetWidthW); // const rect = wx.getMenuButtonBoundingClientRect() // wx.getSystemInfo({ // success: res => { // app.globalData.safeAreaTop = res.safeArea.top + 56 // } // }) } catch (err) { // 异常默认值(300px) app.globalData.inputWidth = 300; app.globalData.inputWidthW = 330; console.error('获取屏幕宽度失败:', err); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })