//首页 <template> <view class="index"> <TabBar></TabBar> <view class="menu"> <button v-for="item in menu" :key="item.id" class="menu-item" @click="handleClick(item.id)" >{{ item.name }} </button> </view> <!-- 获取手机号popup组件 --> <GetPhonePopup :popShow="popShow" @closePop="closePop"/> </view> </template> <script> import { mapMutations } from "vuex"; import TabBar from "@/components/tabBar/tabBar.vue"; import { getLogin, getUserProfile } from "@/utils/auth.js"; import { verifyPhone } from "@/api/index.js"; import { getLocationParams } from "@/common/utils.js"; import GetPhonePopup from "@/components/base/getphonePopup.vue"; import { subscription } from "@/utils/common.js" export default { components: { TabBar, GetPhonePopup }, data() { return { currentPagePath: "", menu: [ { id: "submit", name: "访客信息提交", }, { id: "check", name: "物联设备状态查看", }, ], phone: "", popShow: false, //控制授权手机号弹出框 active: "", //点击的是哪个按钮 }; }, mounted() { uni.showShareMenu({ withShareTicket: true, menus: ["shareAppMessage"] }); this.phone = uni.getStorageSync("registerPhone"); getLogin(); }, //分享好友 onShareAppMessage() { return { title: '环市东院区安防小程序', imageUrl: '../../static/share.jpg', }; }, //分享朋友圈 // onShareTimeline() { // return { // title: '安防平台小程序', // } // }, onShow() { let pages = getCurrentPages(); const curPage = pages[pages.length - 1]; this.currentPagePath = curPage.route; uni.setStorageSync("currentPagePath", this.currentPagePath); }, methods: { // ...mapMutations(['setNavRect']) async handleClick(id) { // subscription(); this.active = id; const sessionId = uni.getStorageSync("sessionId"); //如果this.phone为空,先弹出获取手机号,得到手机号之后验证此人是都注册过 if (!sessionId) { await getLogin(); } if(id === 'submit') { this.phone = uni.getStorageSync("registerPhone"); if (this.phone) { this.checkphone(); } else { //弹获取手机号 this.popShow = true; } } else { uni.showToast({ title: '敬请期待', icon: 'none' }); } }, //通过手机号检查是否存在这个用户 async checkphone() { const res = await verifyPhone(this.phone); if (res === "用户未注册") { wx.reLaunch({ url: "/pages/register/register", }); } else { uni.setStorageSync("registerPhone", this.phone); await getUserProfile(); if (uni.getStorageSync("userInfo")) { const userInfo = JSON.parse(uni.getStorageSync("userInfo")); if (userInfo.salt === "物业人员") { subscription(); } } if (this.active === "submit") { wx.navigateTo({ url: `/pages/information/information?id=${this.active}`, }); } } }, closePop() { this.popShow = false; } }, }; </script> <style lang="scss" scoped> .index { padding: 0 20rpx; padding-top: 40rpx; .menu{ display: flex; justify-content: space-around; } .menu-item { display: flex; justify-content: center; align-items: center; flex: 1; height: 320rpx; border-radius: 10rpx; color: #000; background-color: #eee; border: 1px solid gray; margin-right: 20rpx; line-height: 44rpx; &:last-child { margin-right: 0; } } } </style> <style lang="scss"> .index { .u-popup__content { padding: 30rpx 40rpx; // padding-bottom: 0; } } </style>