Newer
Older
gdtMimiProgram / pages / index / index.vue
dutingting on 17 Mar 2023 5 KB bug修复
//首页
<template>
  <view class="index">
    <!-- <TabBar></TabBar> -->
		<view class="top">
			<image src="../../static/logo.png" style="width: 167rpx;height: 150rpx;"></image>
			<view class="top-title">
				<text>欢迎使用</text>
				<text class="bottom-text">环市东院区安防小程序</text>
			</view>
		</view>
    <view class="menu">
    	<button
    	  v-for="item in menu"
    	  :key="item.id"
    	  class="menu-item"
    	  @click="handleClick(item.id)"
    	  >
				<image :src="item.imgUrl" style="width: 240rpx;height: 230rpx;margin-top:-70rpx;z-index: 2;"></image>
				<text>{{ item.name }}</text>
				
			</button>
    </view>
		<image src="../../static/index/architecture.png" class="bottom-img"></image>
		<!-- 获取手机号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 {getUserJurisdiction} from '@/api/user.js'
import { getLocationParams, debounce } 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: "访客信息提交",
					imgUrl: '../../static/index/submit.png'
        },
        {
          id: "check",
          name: "物联网安全监测",
					imgUrl: '../../static/index/test.png'
        },
      ],
      phone: "",
	  uid:'',
      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: {
		handleClick(id) {
			debounce(this.handleClick1(id))
		},
    async handleClick1(id) {
      this.active = id;
      const sessionId = uni.getStorageSync("sessionId");
      //如果this.phone为空,先弹出获取手机号,得到手机号之后验证此人是都注册过
      if (!sessionId) {
        await getLogin();
      }
			this.phone = uni.getStorageSync("registerPhone");
			if (this.phone) {
				this.checkphone();
			} else {
				//弹获取手机号
				this.popShow = true;
			}
    },
		
		//通过手机号检查是否存在这个用户
    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"));
					this.uid = userInfo.id
					if (userInfo.salt === "物业人员") {
					if(this.active === "submit") {
						subscription();
					}
			  } 
			}
			if (this.active === "submit") {
				wx.navigateTo({
					url: `/pages/information/information?id=${this.active}`,
				});
			} else {
			// 判断是否有这个路径
			const res = await getUserJurisdiction({uid:this.uid})
			if(res.indexOf('/pages/check/check') !== -1) {
				wx.navigateTo({
				  url: '/pages/check/check',
				});
			}else {
				uni.showToast({
					title: '非业务管理员无权访问',
					icon: 'none'
				});
			}
		}
      }
    },
		
		closePop() {
			this.popShow = false;
		}
  },
};
</script>

<style lang="scss" scoped>
.index {
	position: relative;
	padding: 0 20rpx;
  padding-top: 40rpx;
	background: linear-gradient(#e7c0c1 0%, #fff 100%);
  height: 100%;
	box-sizing: border-box;
	z-index: 0;
	.top {
		display: flex;
		padding: 40rpx 32rpx;
		.top-title {
			display: flex;
			flex-direction: column;
			justify-content: center;
			margin-left: 38rpx;
			font-size: 42rpx;
			margin-top: 10rpx;
			color: #3b3937;
			.bottom-text {
				font-size: 44rpx;
				font-weight: 600;
				margin-top: 6rpx;
				color: #323332;
			}
		}
	}
	.menu{
		display: flex;
		flex-direction: column;
		justify-content: space-around;  
		padding: 32rpx;
		margin-top: 60rpx;
		z-index: 2;
		.menu-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 60rpx 0 24rpx;
			font-size: 42rpx;
			color: #323332;
			font-weight: 600;
			height: 240rpx;
			width: 100%;
		  background-color: #fff;
			box-shadow: 10rpx 16rpx 16rpx #d6c6c6;
			border-radius: 20rpx;
			overflow: visible;
			&:last-child {
				margin-top: 64rpx;
			}
			&::after{
				border:none;
			}
		}
  }
	.bottom-img {
		position: absolute;
		bottom: 20rpx;
		left: 0;
		width: 100%;
		height: 220rpx;
		z-index: 1;
	}
}
</style>
<style lang="scss">
.index {
  .u-popup__content {
    padding: 30rpx 40rpx;
		// padding-bottom: 0;
  }
}
</style>